#define FORTRANIOTEST_VERSION \
"FORTRANIOTEST V1.2 C++ part of the Fortran I/O test routines"
#include <iostream>
#include <cassert>
#include <tfxx/commandline.h>
#include <tfxx/fortranio.h>
#include <tfxx/complexio.h>
using std::cout;
using std::cerr;
using std::endl;
template<class T>
{
T v1,v2;
const int nbytes=sizeof(T);
char charpool[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char charresult[26];
assert(nbytes<26);
for (int i=0; i<nbytes; i++)
{
charresult[i]=charpool[i];
}
charresult[nbytes]='\0';
cout << "in: ";
cout.width(10);
cout << charresult;
for (int i=0; i<nbytes; i++)
{
charresult[i]=u2.
bytes[i];
}
charresult[nbytes]='\0';
cout << " out: ";
cout.width(12);
cout << charresult << endl;
}
#define SWAPIT( T ) \
cout.width(40); \
cout << " swap test with \'" #T "\': "; \
test_swap<T>();
{
cout << "We are running on an Intel type CPU" << endl;
break;
cout << "We are running on a Motorola type CPU" << endl;
break;
cout << "The type of this CPU is unknown" << endl;
break;
default:
cerr << "ERROR: illegal return value from " <<
"tfxx::ioswap::cpu()" << endl;
abort();
}
}
void write_data(
const std::string& name,
const bool& verbose=
false)
{
if (verbose) cout << "write data to \'" << name << "\'" << endl;
std::ofstream os(name.c_str());
const int nval=10;
fo << nval;
cout << "nval: " << nval << endl;
for (int i=0; i<nval; i++)
{
int val1=(i+1)*4;
int val2=100*val1;
fo << val1 << val2;
cout << " val1/2: " << val1 << ", " << val2 << endl;
}
fo.end_block();
for (int i=0; i<nval; i++)
{
double val=(i+1)*15.;
cout << " val: " << val << endl;
fo << val;
}
fo.end_block();
long long int llint=1551;
long int lint=2662;
std::complex<double> dcplx(4.5,5.4);
std::complex<float> scplx(14.5,15.4);
fo << llint << lint << dcplx << scplx;
cout << "extra: " << llint << ", " << lint << ", "
<< dcplx << ", " << scplx << endl;;
}
void read_data(
const std::string& name,
const bool& verbose=
false)
{
if (verbose) cout << "read data from \'" << name << "\'" << endl;
std::ifstream is(name.c_str());
if (verbose) {
switch(match) {
cout << "Bytesex matches" << endl;
break;
cout << "Magic number found, byte data has to be swapped" << endl;
break;
cout << "Magic number not found" << endl;
break;
default:
cerr << "ERROR: illegal return value from " <<
"tfxx::ioswap::file_magic_test()" << endl;
break;
}
}
{
int nval;
fi >> nval;
cout << "nval: " << nval << endl;
for (int i=0; i<nval; i++)
{
int val1,val2;
fi >> val1 >> val2;
cout << " val1/2: " << val1 << ", " << val2 << endl;
}
for (int i=0; i<nval; i++)
{
double val;
fi >> val;
cout << " val: " << val << endl;
}
long long int llint;
long int lint;
std::complex<double> dcplx;
std::complex<float> scplx;
fi >> llint >> lint >> dcplx >> scplx;
cout << "extra: " << llint << ", " << lint << ", "
<< dcplx << ", " << scplx << endl;;
}
}
int main(
int iargc,
char* argv[])
{
char usage_text[]=
{
"usage: fortraniotest [-v] [-c] [-s] [-C]" "\n"
" [-w [file]] [-r [file]]" "\n"
" or: fortraniotest --help|-h" "\n"
};
char help_text[]=
{
" " "\n"
"-v be verbose" "\n"
"-c check byte size of data types" "\n"
"-s test byte swapping" "\n"
"-C tell us about the CPU model" "\n"
"-w [file] write to file" "\n"
"-r [file] read from file" "\n"
FORTRANIOTEST_CVSID
};
{
{NULL}
};
if (iargc<2)
{
cerr << usage_text << endl;
exit(0);
}
if (cmdline.optset(0))
{
cerr << usage_text << endl;
cerr << help_text << endl;
exit(0);
}
bool verbose=cmdline.optset(1);
bool check_size=cmdline.optset(2);
bool byte_swapping=cmdline.optset(3);
bool tell_CPU=cmdline.optset(4);
bool write_file=cmdline.optset(5);
std::string outfile=cmdline.string_arg(5);
bool read_file=cmdline.optset(6);
std::string infile=cmdline.string_arg(6);
if (check_size)
{
cout << "NOTICE: check_assumed_size() no longer exists!"
<< endl
<< " and the even better news: there is no need for it"
<< endl;
}
if (byte_swapping)
{
}
}