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

◆ main()

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

Main program.

This code tests reading and writing of binary data. And it performs some tests on the byte swapping facilities.

See also
I/O byte swapping facility.
FORTRAN I/O functions

Definition at line 237 of file fortraniotest.cc.

References tfxx::cmdline::arg_no, tfxx::cmdline::arg_opt, cpu_type(), FORTRANIOTEST_VERSION, tfxx::cmdline::Commandline::optset(), read_data(), tfxx::cmdline::Commandline::string_arg(), SWAPIT, and write_data().

238 {
239 
240  // define usage information
241  char usage_text[]=
242  {
244  "usage: fortraniotest [-v] [-c] [-s] [-C]" "\n"
245  " [-w [file]] [-r [file]]" "\n"
246  " or: fortraniotest --help|-h" "\n"
247  };
248 
249  // define full help text
250  char help_text[]=
251  {
252  " " "\n"
253  "-v be verbose" "\n"
254  "-c check byte size of data types" "\n"
255  "-s test byte swapping" "\n"
256  "-C tell us about the CPU model" "\n"
257  "-w [file] write to file" "\n"
258  "-r [file] read from file" "\n"
259  FORTRANIOTEST_CVSID
260  };
261 
262  // define commandline options
263  using namespace tfxx::cmdline;
264  static Declare options[]=
265  {
266  // 0: print help
267  {"help",arg_no,"-"},
268  // 1: verbose mode
269  {"v",arg_no,"-"},
270  // 2: check byte size
271  {"c",arg_no,"-"},
272  // 3: test byte swapping
273  {"s",arg_no,"-"},
274  // 4: tell about CPU
275  {"C",arg_no,"-"},
276  // 5: write to file
277  {"w",arg_opt,"junk"},
278  // 6: write to file
279  {"r",arg_opt,"junk"},
280  {NULL}
281  };
282 
283  // no arguments? print usage...
284  if (iargc<2)
285  {
286  cerr << usage_text << endl;
287  exit(0);
288  }
289 
290  // collect options from commandline
291  Commandline cmdline(iargc, argv, options);
292 
293  // help requested? print full help text...
294  if (cmdline.optset(0))
295  {
296  cerr << usage_text << endl;
297  cerr << help_text << endl;
298  exit(0);
299  }
300 
301  bool verbose=cmdline.optset(1);
302  bool check_size=cmdline.optset(2);
303  bool byte_swapping=cmdline.optset(3);
304  bool tell_CPU=cmdline.optset(4);
305  bool write_file=cmdline.optset(5);
306  std::string outfile=cmdline.string_arg(5);
307  bool read_file=cmdline.optset(6);
308  std::string infile=cmdline.string_arg(6);
309 
310  if (verbose) { cout << FORTRANIOTEST_VERSION << endl << endl; }
311  if (check_size)
312  {
313  cout << "NOTICE: check_assumed_size() no longer exists!"
314  << endl
315  << " and the even better news: there is no need for it"
316  << endl;
317  }
318  if (byte_swapping)
319  {
320  SWAPIT(char)
321  SWAPIT(int)
322  SWAPIT(long int)
323  SWAPIT(long long int)
324  SWAPIT(float)
325  SWAPIT(double)
326  }
327  if (tell_CPU) cpu_type();
328  if (write_file) write_data(outfile, verbose);
329  if (read_file) read_data(infile, verbose);
330 }
void write_data(const std::string &name, const bool &verbose=false)
write test data
#define FORTRANIOTEST_VERSION
#define SWAPIT(T)
Macro function to preform easy to use swap check.
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
option may have an optional argument
Definition: commandline.h:104
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
void cpu_type()
Ask for CPU type and print result.
void read_data(const std::string &name, const bool &verbose=false)
read test data
Here is the call graph for this function: