testrandomu.c

Go to the documentation of this file.
00001 /* ***************************************************** */
00002 /* testrandomu Test random number GSL function.          */
00003 /* testrandomu.c                                         */
00004 /* ***************************************************** */
00005 /* Author: Christian Page, CERFACS, Toulouse, France.    */
00006 /* ***************************************************** */
00011 /* LICENSE BEGIN
00012 
00013 Copyright Cerfacs (Christian Page) (2015)
00014 
00015 christian.page@cerfacs.fr
00016 
00017 This software is a computer program whose purpose is to downscale climate
00018 scenarios using a statistical methodology based on weather regimes.
00019 
00020 This software is governed by the CeCILL license under French law and
00021 abiding by the rules of distribution of free software. You can use, 
00022 modify and/ or redistribute the software under the terms of the CeCILL
00023 license as circulated by CEA, CNRS and INRIA at the following URL
00024 "http://www.cecill.info". 
00025 
00026 As a counterpart to the access to the source code and rights to copy,
00027 modify and redistribute granted by the license, users are provided only
00028 with a limited warranty and the software's author, the holder of the
00029 economic rights, and the successive licensors have only limited
00030 liability. 
00031 
00032 In this respect, the user's attention is drawn to the risks associated
00033 with loading, using, modifying and/or developing or reproducing the
00034 software by the user in light of its specific status of free software,
00035 that may mean that it is complicated to manipulate, and that also
00036 therefore means that it is reserved for developers and experienced
00037 professionals having in-depth computer knowledge. Users are therefore
00038 encouraged to load and test the software's suitability as regards their
00039 requirements in conditions enabling the security of their systems and/or 
00040 data to be ensured and, more generally, to use and operate it in the 
00041 same conditions as regards security. 
00042 
00043 The fact that you are presently reading this means that you have had
00044 knowledge of the CeCILL license and that you accept its terms.
00045 
00046 LICENSE END */
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 #ifdef HAVE_CONFIG_H
00055 #include <config.h>
00056 #endif
00057 
00059 #define _GNU_SOURCE
00060 
00061 /* C standard includes */
00062 #ifdef HAVE_SYS_TYPES_H
00063 #include <sys/types.h>
00064 #endif
00065 #ifdef HAVE_SYS_STAT_H
00066 #include <sys/stat.h>
00067 #endif
00068 #ifdef HAVE_FCNTL_H
00069 #include <fcntl.h>
00070 #endif
00071 #ifdef HAVE_UNSTD_H
00072 #include <unistd.h>
00073 #endif
00074 #ifdef HAVE_STDIO_H
00075 #include <stdio.h>
00076 #endif
00077 #ifdef HAVE_STRING_H
00078 #include <string.h>
00079 #endif
00080 #ifdef HAVE_STDLIB_H
00081 #include <stdlib.h>
00082 #endif
00083 #ifdef HAVE_MATH_H
00084 #include <math.h>
00085 #endif
00086 #ifdef HAVE_TIME_H
00087 #include <time.h>
00088 #endif
00089 #ifdef HAVE_LIBGEN_H
00090 #  include <libgen.h>
00091 #endif
00092 
00093 #include <gsl/gsl_rng.h>
00094 #include <gsl/gsl_randist.h>
00095 
00096 #include <utils.h>
00097 
00099 void show_usage(char *pgm);
00100 
00102 int main(int argc, char **argv)
00103 {
00111   unsigned long int random_num, i;
00112 
00113   const gsl_rng_type *T;
00114   gsl_rng *rng;
00115 
00116   /* Print BEGIN banner */
00117   (void) banner(basename(argv[0]), "1.0", "BEGIN");
00118 
00119   /* Get command-line arguments and set appropriate variables */
00120   for (i=1; i<argc; i++) {
00121     if ( !strcmp(argv[i], "-h") ) {
00122       (void) show_usage(basename(argv[0]));
00123       (void) banner(basename(argv[0]), "OK", "END");
00124       return 0;
00125     }
00126     else {
00127       (void) fprintf(stderr, "%s:: Wrong arg %s.\n\n", basename(argv[0]), argv[i]);
00128       (void) show_usage(basename(argv[0]));
00129       (void) banner(basename(argv[0]), "ABORT", "END");
00130       (void) abort();
00131     }
00132   }
00133 
00134   /* Initialize random number generator */
00135   T = gsl_rng_default;
00136   rng = gsl_rng_alloc(T);
00137   (void) gsl_rng_set(rng, time(NULL));
00138   
00139   for (i=0; i<1000000; i++) {
00140     random_num = gsl_rng_uniform_int(rng, 100);  
00141     (void) fprintf(stdout,"%ld\n",random_num);
00142   }
00143 
00144   (void) gsl_rng_free(rng);
00145 
00146   /* Print END banner */
00147   (void) banner(basename(argv[0]), "OK", "END");
00148 
00149   return 0;
00150 }
00151 
00152 
00156 void show_usage(char *pgm) {
00161   (void) fprintf(stderr, "%s: usage:\n", pgm);
00162   (void) fprintf(stderr, "-h: help\n");
00163 
00164 }

Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1