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

A complete example is provided in writetest.cc

You should include

to write data and

to read data.

Consider that the properties of your output file are given as

std::string outfile; // name of output file
datrw::Eformat outputformat; // format of output file
bool overwrite; // true, if existing file should be overwritten

Open the output file:

if (!overwrite) { datrw::abort_if_exists(outfile); }
std::ofstream ofs(outfile.c_str(),
datrw::oanystream::openmode(outputformat));
datrw::oanystream os(ofs, outputformat);

A way to report the data type used to store sample values:

cout << "file data is stored in ";
// report output data format
switch (os.seriestype()) {
cout << "integer";
break;
cout << "single precision floating point";
break;
cout << "double precision floating point";
break;
cout << "any desired";
break;
default:
TFXX_abort("output stream uses unknown variable type!");
} // switch (os.seriestype())
cout << " variable type" << endl;

Consider that input is copied from an

datrw::idatstream is(ifs, inputformat);

Copy file header data:

if (is.hasfree())
{
if (os.handlesfilefree())
{
sff::FREE filefree;
is >> filefree;
os << filefree;
}
else
{
cout << "file FREE block is discarded." << endl;
}
} // if (is.hasfree())
if (is.hassrce())
{
if (os.handlessrce())
{
sff::SRCE srceline;
is >> srceline;
os << srceline;
}
else
{
cout << "SRCE line is discarded." << endl;
}
}

Read the input series:

aff::Series<double> series;
is >> series;

Pass trace header data:

// pass WID2
sff::WID2 wid2;
is >> wid2;
os << wid2;
// pass INFO
if (is.hasinfo())
{
if (os.handlesinfo())
{
sff::INFO infoline;
is >> infoline;
os << infoline;
}
else
{
if (opt.verbose)
{
cout << " INFO line is discarded." << endl;
}
}
}
// pass trace FREE
if (is.hasfree())
{
if (os.handlestracefree())
{
sff::FREE freeblock;
is >> freeblock;
os << freeblock;
}
else
{
if (opt.verbose)
{
cout << " trace FREE block is discarded." << endl;
}
}
}

Write actual time series:

os << series;
Date
17.12.2010