42 #define FORTRANIOTEST_VERSION \ 43 "FORTRANIOTEST V1.2 C++ part of the Fortran I/O test routines" 47 #include <tfxx/commandline.h> 48 #include <tfxx/fortranio.h> 49 #include <tfxx/complexio.h> 75 const int nbytes=
sizeof(T);
76 char charpool[]=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
79 for (
int i=0; i<nbytes; i++)
81 u1.
bytes[i]=charpool[i];
82 charresult[i]=charpool[i];
84 charresult[nbytes]=
'\0';
92 for (
int i=0; i<nbytes; i++)
94 charresult[i]=u2.
bytes[i];
96 charresult[nbytes]=
'\0';
99 cout << charresult << endl;
107 #define SWAPIT( T ) \ 109 cout << " swap test with \'" #T "\': "; \ 119 cout <<
"We are running on an Intel type CPU" << endl;
122 cout <<
"We are running on a Motorola type CPU" << endl;
125 cout <<
"The type of this CPU is unknown" << endl;
128 cerr <<
"ERROR: illegal return value from " <<
129 "tfxx::ioswap::cpu()" << endl;
139 void write_data(
const std::string& name,
const bool& verbose=
false)
141 if (verbose) cout <<
"write data to \'" << name <<
"\'" << endl;
142 std::ofstream os(name.c_str());
148 cout <<
"nval: " << nval << endl;
149 for (
int i=0; i<nval; i++)
154 cout <<
" val1/2: " << val1 <<
", " << val2 << endl;
157 for (
int i=0; i<nval; i++)
159 double val=(i+1)*15.;
160 cout <<
" val: " << val << endl;
164 long long int llint=1551;
166 std::complex<double> dcplx(4.5,5.4);
167 std::complex<float> scplx(14.5,15.4);
168 fo << llint << lint << dcplx << scplx;
169 cout <<
"extra: " << llint <<
", " << lint <<
", " 170 << dcplx <<
", " << scplx << endl;;
176 void read_data(
const std::string& name,
const bool& verbose=
false)
178 if (verbose) cout <<
"read data from \'" << name <<
"\'" << endl;
179 std::ifstream is(name.c_str());
185 cout <<
"Bytesex matches" << endl;
188 cout <<
"Magic number found, byte data has to be swapped" << endl;
191 cout <<
"Magic number not found" << endl;
194 cerr <<
"ERROR: illegal return value from " <<
195 "tfxx::ioswap::file_magic_test()" << endl;
205 cout <<
"nval: " << nval << endl;
206 for (
int i=0; i<nval; i++)
210 cout <<
" val1/2: " << val1 <<
", " << val2 << endl;
212 for (
int i=0; i<nval; i++)
216 cout <<
" val: " << val << endl;
220 std::complex<double> dcplx;
221 std::complex<float> scplx;
222 fi >> llint >> lint >> dcplx >> scplx;
223 cout <<
"extra: " << llint <<
", " << lint <<
", " 224 << dcplx <<
", " << scplx << endl;;
237 int main(
int iargc,
char* argv[])
244 "usage: fortraniotest [-v] [-c] [-s] [-C]" "\n" 245 " [-w [file]] [-r [file]]" "\n" 246 " or: fortraniotest --help|-h" "\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" 286 cerr << usage_text << endl;
296 cerr << usage_text << endl;
297 cerr << help_text << endl;
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);
307 bool read_file=cmdline.
optset(6);
313 cout <<
"NOTICE: check_assumed_size() no longer exists!" 315 <<
" and the even better news: there is no need for it" 329 if (read_file)
read_data(infile, verbose);
write FORTRAN binary data ,This class writes FORTRAN binary data. FORTRAN binary data is always writt...
void write_data(const std::string &name, const bool &verbose=false)
write test data
Emagic_type file_magic_test(std::istream &is, const char *const cmagic, const bool &fortranmode=false)
Check for magic number in file.
void end_block()
finish data block
bool optset(const int &iopt) const
true if option # iopt was set on commandline
T swap(const T &value)
How to swap any generic type.
The bytesex of the file matches this machine.
The bytesex of the file must be swapped to match this machine.
Ecpu_type cpu()
Check CPU model. ,.
int main(int iargc, char *argv[])
Main program.
Emagic_type
Define bytesex indicator for magic number test.
#define FORTRANIOTEST_VERSION
#define SWAPIT(T)
Macro function to preform easy to use swap check.
void test_swap()
Function template to test dry byte swapping.
Namespace containing all components of module commandline. ,.
Evaluates commandline by calling long_getopt. ,You may instantiate a Commandline object by passing th...
option may have an optional argument
The magic number does match the file.
struct to define options ,This struct is used to define a list of options. An example is: ...
void file_magic_write(std::ostream &os, const char *const cmagic, const bool &fortranmode=false)
Write magic number to file. ,.
std::string string_arg(const int &iopt) const
return argument of option # iopt as string value
void cpu_type()
Ask for CPU type and print result.
void read_data(const std::string &name, const bool &verbose=false)
read test data