This program is an example on writing data with libdatrwxx.
#define WRITETEST_VERSION \
"WRITETEST V1.0 test writing a file"
#include <iostream>
#include <fstream>
#include <tfxx/commandline.h>
using std::cout;
using std::cerr;
using std::endl;
};
int main(
int iargc,
char* argv[])
{
char usage_text[]=
{
"usage: writetest [-v] [-D] [-sff n] [-gse n] [-any n]" "\n"
" [-t type] [-A amp] [-o] [-digits v]" "\n"
" or: writetest --help|-h" "\n"
" or: writetest --xhelp" "\n"
};
char help_text[]=
{
"\n"
"-v be verbose" "\n"
"-D enter debug mode" "\n"
"-sff n write to SFF file \"n\"" "\n"
"-gse n write to GSE file \"n\"" "\n"
"-any n write to file \"n\"" "\n"
"\n"
"options to define \"any\" test:" "\n"
"-t type select output format type for any" "\n"
"-A amp select signal amplitude" "\n"
"-o overwrite existing output file" "\n"
"-digits v test digits functions" "\n"
};
using namespace tfxx::cmdline;
static Declare options[]=
{
{"help",arg_no,"-"},
{"v",arg_no,"-"},
{"D",arg_no,"-"},
{"sff",arg_yes,"-"},
{"gse",arg_yes,"-"},
{"any",arg_yes,"-"},
{"t",arg_yes,"sff"},
{"A",arg_yes,"1."},
{"o",arg_no,"-"},
{"digits",arg_yes,"1."},
{"xhelp",arg_no,"-"},
{NULL}
};
if (iargc<2)
{
cerr << usage_text << endl;
exit(0);
}
Commandline cmdline(iargc, argv, options);
if (cmdline.optset(0) || cmdline.optset(10))
{
cerr << usage_text << endl;
cerr << help_text << endl;
if (cmdline.optset(10))
{
}
exit(0);
}
opt.
debug=cmdline.optset(2);
opt.
format=cmdline.string_arg(6);
{
{ cout <<
"SFF test: write to file " << opt.
sfffilename << endl; }
sff::FREE free;
free.append("my file comment");
sff::SRCE srce;
os << free;
os << srce;
{
sff::WID2 wid2;
wid2.dt=10;
wid2.channel="LIN";
wid2.station="THOF";
{
sff::FREE tracefree;
tracefree.append("linear integer trace");
sff::INFO info;
for (int i=s.f(); i<=s.l(); ++i)
{
s(i)=i;
}
os << wid2;
os << tracefree;
os << info;
os << s;
}
{
sff::FREE tracefree;
tracefree.append("double sine trace");
for (int i=s.f(); i<=s.l(); ++i)
{
s(i)=5.e4*sin(2*3.14159265358979311599*i/(s.size()-1));
}
wid2.dt=1.;
wid2.channel="SIN";
os << wid2;
os << tracefree;
os << s;
}
{
sff::FREE tracefree;
tracefree.append("float cosine trace");
for (int i=s.f(); i<=s.l(); ++i)
{
s(i)=6.e-12*cos(2*3.14159265358979311599*i/(s.size()-1));
}
wid2.dt=.1;
wid2.channel="COS";
os << wid2;
os << tracefree;
os << s;
}
}
}
{
{ cout <<
"GSE test: write to file " << opt.
gsefilename << endl; }
sff::FREE free;
free.append("my file comment");
sff::SRCE srce;
os << free;
os << srce;
{
sff::WID2 wid2;
wid2.dt=10;
wid2.channel="LIN";
wid2.station="THOF";
{
sff::FREE tracefree;
tracefree.append("linear integer trace");
sff::INFO info;
for (int i=s.f(); i<=s.l(); ++i)
{
s(i)=i/5-10;
}
os << wid2;
os << tracefree;
os << info;
os << s;
}
{
sff::FREE tracefree;
tracefree.append("double sine trace");
for (int i=s.f(); i<=s.l(); ++i)
{
s(i)=30.*sin(2*3.14159265358979311599*i/(s.size()-1));
}
wid2.dt=1.;
wid2.channel="SIN";
os << wid2;
os << tracefree;
os << s;
}
{
sff::FREE tracefree;
tracefree.append("float cosine trace");
for (int i=s.f(); i<=s.l(); ++i)
{
s(i)=6.*cos(2*3.14159265358979311599*i/(s.size()-1));
}
wid2.dt=.1;
wid2.channel="COS";
os << wid2;
os << tracefree;
os << s;
}
}
}
{
{
cout <<
"ANY test: write to file " << opt.
anyfilename << endl;
cout <<
"using " << opt.
format << endl;
}
sff::FREE free;
free.append("my file comment");
sff::SRCE srce;
os << free;
os << srce;
sff::WID2 wid2;
wid2.dt=0.01;
wid2.channel="SIN";
wid2.station="THOF";
sff::FREE tracefree;
tracefree.append("double sine trace");
for (int i=s.f(); i<=s.l(); ++i)
{
s(i)=opt.
amplitude*sin(2*3.14159265358979311599*i/(s.size()-1));
}
os << wid2;
os << tracefree;
os << s;
tracefree.append("smaller sampling interval");
wid2.dt=0.002;
wid2.channel="SIN";
os << wid2;
os << tracefree;
os << s;
}
{
endl;
cout << "number of siginificant digits "
cout << "number of trailing digits "
}
}