DATRW++ library: seismic data I/O with multiple formats

◆ file_magic_test()

Emagic_type datrw::util::file_magic_test ( std::istream &  is,
const char *const  cmagic,
const bool &  fortranmode = false 
)

check magic number in file

Check for magic number in file.

,

Parameters
isinput stream to read from
cmagic4-byte character sequence representing magic number (most restrictive: pass a const pointer to a const char) is pointer to character array of size sizeof(int)
fortranmodeuse Fortran binary I/O if true
Returns
The return value tells whether the file matches

The function may have the following return values

  • magic_match The file has the requested magic number and the bytesex of the data matches that of the system
  • magic_swap The file has the requested magic number but byte swapping is required for input data
  • magic_nomatch The requested magic number was not found in the file

Definition at line 105 of file bytesex.cc.

References datrw::util::IOUnion< T >::bytes, magic(), magic_match, magic_nomatch, magic_swap, swap(), and datrw::util::IOUnion< T >::value.

Referenced by datrw::binary::ibinstream::ibinstream().

107  {
108  Emagic_type result=magic_nomatch;
109  IOUnion<int> req_magic, in_magic;
110  // create requested magic number
111  req_magic.value=magic(cmagic);
112  // skip Fortran block size
113  if (fortranmode) is.read(in_magic.bytes, sizeof(int));
114  // read magic number and compare
115  is.read(in_magic.bytes, sizeof(int));
116  if (in_magic.value == req_magic.value)
117  { result=magic_match; }
118  else if (in_magic.value == swap(req_magic.value))
119  { result=magic_swap; }
120  // skip Fortran block size
121  if (fortranmode) is.read(in_magic.bytes, sizeof(int));
122  return(result);
123  } // file_magic_test()
The bytesex of the file matches this machine.
Definition: bytesex.h:100
The magic number does match the file.
Definition: bytesex.h:104
T swap(const T &value)
How to swap any generic type.
Definition: bytesex.h:118
The bytesex of the file must be swapped to match this machine.
Definition: bytesex.h:102
int magic(const char *const cmagic)
function to create the magic number
Definition: bytesex.cc:52
Emagic_type
Define bytesex indicator for magic number test.
Definition: bytesex.h:98
Here is the call graph for this function:
Here is the caller graph for this function: