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

◆ read_data()

void read_data ( const std::string &  name,
const bool &  verbose = false 
)

read test data

Examples:
tests/fortraniotest.cc.

Definition at line 176 of file fortraniotest.cc.

References tfxx::ioswap::file_magic_test(), tfxx::ioswap::magic_match, tfxx::ioswap::magic_nomatch, tfxx::ioswap::magic_swap, and mymagic.

Referenced by main().

177 {
178  if (verbose) cout << "read data from \'" << name << "\'" << endl;
179  std::ifstream is(name.c_str());
181  match=tfxx::ioswap::file_magic_test(is, mymagic, true);
182  if (verbose) {
183  switch(match) {
185  cout << "Bytesex matches" << endl;
186  break;
188  cout << "Magic number found, byte data has to be swapped" << endl;
189  break;
191  cout << "Magic number not found" << endl;
192  break;
193  default:
194  cerr << "ERROR: illegal return value from " <<
195  "tfxx::ioswap::file_magic_test()" << endl;
196  break;
197  }
198  }
199  if ((match==tfxx::ioswap::magic_match)
200  || (match==tfxx::ioswap::magic_swap))
201  {
203  int nval;
204  fi >> nval;
205  cout << "nval: " << nval << endl;
206  for (int i=0; i<nval; i++)
207  {
208  int val1,val2;
209  fi >> val1 >> val2;
210  cout << " val1/2: " << val1 << ", " << val2 << endl;
211  }
212  for (int i=0; i<nval; i++)
213  {
214  double val;
215  fi >> val;
216  cout << " val: " << val << endl;
217  }
218  long long int llint;
219  long int lint;
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;;
225  }
226 }
Emagic_type file_magic_test(std::istream &is, const char *const cmagic, const bool &fortranmode=false)
Check for magic number in file.
Definition: ioswap.cc:112
The bytesex of the file matches this machine.
Definition: bytesex.h:116
The bytesex of the file must be swapped to match this machine.
Definition: bytesex.h:118
Emagic_type
Define bytesex indicator for magic number test.
Definition: bytesex.h:114
read FORTRAN binary data ,This class reads FORTRAN binary data. FORTRAN binary data is always written...
Definition: fortranio.h:137
The magic number does match the file.
Definition: bytesex.h:120
const char mymagic[]
Here is the call graph for this function:
Here is the caller graph for this function: