DATRW++ library: seismic data I/O with multiple formats
HOWTO read data of any supported format

Here I provide an example on how to read seismic data using datrw::ianystream and writing it to a different file via sff::SFFostream. Consider the names of input files given in

std::list<std::string> infiles;

and the name of the output file given in

std::string outfile;

The type of the input files are given in

which can be created from a string specifier

std::string type;

through

format=datrw::anyID(type);

We assume that a file FREE block

sff::FREE filefree;

was already prepared to be written.

Reading an writing of data will than take place like in the code example given here:

// create an output file stream
std::ofstream ofs(outfile.c_str());
// create an interfacing SFF output stream
sff::SFFostream<Tseries> os(ofs, opt.debug);
// write the file FREE block to the output file
os << filefree;
// here we could also write an SRCE line
// create iterator to browse list of input files
std::list<std::string>::const_iterator infile=infiles.begin();
while( infile!=infiles.end())
{
// open input stream for reading next file, use correct open mode
std::ifstream ifs(infile->c_str(), datrw::ianystream::openmode(format));
// create an interface to the input stream
datrw::ianystream is(ifs, format);
// cycle through all traces while input stream provides data
while(is.good())
{
// create a double precision series container
// read and write the series
is >> series;
os << series;
// create a WID2 line structure
sff::WID2 wid2;
// read and write the WID2 header
is >> wid2;
os << wid2;
// read and write INFO line and trace FREE block is present
if (is.hasinfo()) { sff::INFO info; is >> info; os << info; }
if (is.hasfree()) { sff::FREE free; is >> free; os << free; }
}
// next file
++infile;
}
See also
Description of reading operation
Date
11/2010