TF++, Miscellaneous classes and modules in C++:

◆ main()

int main ( int  iargc,
char *  argv[] 
)

Definition at line 52 of file rngtest.cc.

References tfxx::cmdline::arg_no, tfxx::cmdline::arg_yes, tfxx::numeric::RNGgaussian::comment_gsl_rng_ranlux, tfxx::cmdline::Commandline::double_arg(), tfxx::cmdline::Commandline::int_arg(), Options::listtypes, tfxx::cmdline::Commandline::long_arg(), Options::mean, Options::nsamples, tfxx::cmdline::Commandline::optset(), report(), tfxx::numeric::RNGgaussian::rng_list_types(), RNGTEST_VERSION, Options::seed, Options::seedset, tfxx::numeric::RNGgaussian::set(), Options::std, tfxx::cmdline::Commandline::string_arg(), Options::type, and Options::verbose.

53 {
54 
55  // define usage information
56  char usage_text[]=
57  {
58  RNGTEST_VERSION "\n"
59  "usage: rngtest [-l] [-v] [-t type] [-seed v] [-mean v]\n"
60  " [-std v] [-n n] [run]\n"
61  " or: rngtest --help|-h" "\n"
62  " or: rngtest --xhelp" "\n"
63  };
64 
65  // define full help text
66  char help_text[]=
67  {
68  "--xhelp print comments regarding GSL RNG implementation\n"
69  "\n"
70  "run run the program\n"
71  "-l print list of random number generators and exit\n"
72  "-v be verbose\n"
73  "-t type select random number generator of type \"type\"\n"
74  " use option -l for a list of available types\n"
75  " type \"default\" will make selection based on\n"
76  " environment variables\n"
77  "-seed v initialize RNG with seed value v\n"
78  "-mean v set mean value\n"
79  "-std v set standard deviation\n"
80  "-n n print n random numbers\n"
81  "\n"
82  "In case of no type selected or type set to \"default\" type\n"
83  "and seed value can be specified through environment variables.\n"
84  "Simply try\n"
85  "\n"
86  "GSL_RNG_TYPE=ranlux GSL_RNG_SEED=125 rngtest -v run\n"
87  };
88 
89  // define commandline options
90  using namespace tfxx::cmdline;
91  static Declare options[]=
92  {
93  // 0: print help
94  {"help",arg_no,"-"},
95  // 1: verbose mode
96  {"v",arg_no,"-"},
97  // 2: print list of random number generators
98  {"l",arg_no,"-"},
99  // 3: type of RNG
100  {"t",arg_yes,"default"},
101  // 4: seed value
102  {"seed",arg_yes,"0."},
103  // 5: mean value
104  {"mean",arg_yes,"0."},
105  // 6: standard deviation
106  {"std",arg_yes,"1."},
107  // 7: number of samples to be printed
108  {"n",arg_yes,"10"},
109  // 8: print comment text
110  {"xhelp",arg_no,"-"},
111  {NULL}
112  };
113 
114  // no arguments? print usage...
115  if (iargc<2)
116  {
117  cerr << usage_text << endl;
118  exit(0);
119  }
120 
121  // collect options from commandline
122  Commandline cmdline(iargc, argv, options);
123 
124  // help requested? print full help text...
125  if (cmdline.optset(0) || cmdline.optset(8))
126  {
127  cerr << usage_text << endl;
128  cerr << help_text << endl;
129  if (cmdline.optset(8))
130  {
131  cerr << endl;
133  }
134  exit(0);
135  }
136 
137  Options opt;
138  opt.verbose=cmdline.optset(1);
139  opt.listtypes=cmdline.optset(2);
140  opt.type=cmdline.string_arg(3);
141  opt.seedset=cmdline.optset(4);
142  opt.seed=cmdline.long_arg(4);
143  opt.mean=cmdline.double_arg(5);
144  opt.std=cmdline.double_arg(6);
145  opt.nsamples=cmdline.int_arg(7);
146 
147  if (opt.listtypes)
148  {
150  }
151  else
152  {
153  cout << RNGTEST_VERSION << endl;
154  if (opt.verbose)
155  {
156  cout << "Parameters specified on command line (maybe default):\n"
157  << " type: " << opt.type << "\n"
158  << " mean: " << opt.mean << "\n"
159  << " std: " << opt.std << "\n"
160  << " n: " << opt.nsamples << endl;
161  if (opt.seedset)
162  {
163  cout << " seed: " << opt.seed << endl;
164  }
165  else
166  {
167  cout << " no seed value specified" << endl;
168  }
169  }
170  // create RNG
171  tfxx::numeric::RNGgaussian rng(opt.std, opt.mean, opt.type.c_str());
172  if (opt.seedset) { rng.set(opt.seed); }
173  // report
174  if (opt.verbose) { report(rng); }
175 
176  cout << "\nRandom numbers:" << endl;
177  for (int i=0; i<opt.nsamples; ++i)
178  {
179  cout << i << " " << rng.value() << endl;
180  }
181 
182  cout << endl << "set new seed" << endl;
183  rng.set();
184  if (opt.verbose) { report(rng); }
185 
186  cout << "\nRandom numbers:" << endl;
187  for (int i=0; i<opt.nsamples; ++i)
188  {
189  cout << i << " " << rng.value() << endl;
190  }
191  }
192 }
double mean
Definition: rngtest.cc:32
option requires an argument
Definition: commandline.h:102
std::string type
Definition: rngtest.cc:35
static void rng_list_types(std::ostream &os)
print list of random number generators to stream.
Definition: rng.cc:122
void report(const tfxx::numeric::RNGgaussian &rng)
Definition: rngtest.cc:41
bool seedset
Definition: rngtest.cc:34
bool verbose
Definition: rngtest.cc:34
int nsamples
Definition: rngtest.cc:36
Namespace containing all components of module commandline. ,.
Definition: commandline.cc:41
Evaluates commandline by calling long_getopt. ,You may instantiate a Commandline object by passing th...
Definition: commandline.h:201
Provide random numbers with Gaussian distribution.This class is an interface to the GSL random number...
Definition: rng.h:78
unsigned long int seed
Definition: rngtest.cc:33
double std
Definition: rngtest.cc:32
static const char * comment_gsl_rng_ranlux
comment on GSL RNGs
Definition: rng.h:104
#define RNGTEST_VERSION
Definition: rngtest.cc:18
struct to define options ,This struct is used to define a list of options. An example is: ...
Definition: commandline.h:136
option has no argument
Definition: commandline.h:100
bool listtypes
Definition: rngtest.cc:34
void set(const unsigned long int &seed)
feed with seed value
Definition: rng.cc:104
Here is the call graph for this function: