Commit bf105f8c authored by Daniel Armbruster's avatar Daniel Armbruster Committed by thomas.forbriger
Browse files

first compilable version - though not tested anything yet

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4656
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent ca399e4c
......@@ -70,12 +70,13 @@
# 13/12/2007 V1.2 g77 is the standard Fortran compiler now
# 17/01/2011 V1.3 migrated to new SVN scheme
# implemented offlix and chacox
# 03/03/2012 V1.4 added tijerasxx (damb)
#
# ============================================================================
#
PROGRAMS=sehefi coma epi chaco sesoc offli sesot merse cooset \
offlix chacox
offlix chacox tijerasxx
.PHONY: all
all: install
......@@ -139,6 +140,10 @@ offlix: %x: %.o
$(FC) -o $@ $< -ltf -lsffu -ltime_trad \
-lfapidxx -ldatrwxx -lsffxx -lgsexx -ltime++ -laff -L$(LOCLIBDIR)
tijerasxx: %: %.o
$(CXX) -o $@ $^ -I$(LOCINCLUDEDIR) -ldatrwxx \
-lsffxx -ltime++ -lgsexx -laff -ltfxx \
-L$(LOCLIBDIR) $(CXXFLAGS) $(FLAGS) $(LDFLAGS)
#======================================================================
# create package
# --------------
......
......@@ -32,6 +32,456 @@
* ============================================================================
*/
#define TIJERASXX_VERSION \
"TIJERASXX V0.1 simply cut off timeseries data"
#define TIJERASXX_SVNID \
"$Id$"
#include <iostream>
#include <fstream>
#include <tfxx/commandline.h>
#include <tfxx/xcmdline.h>
#include <tfxx/error.h>
#include <tfxx/misc.h>
#include <tfxx/rangestring.h>
#include <tfxx/rangelist.h>
#include <datrwxx/readany.h>
#include <datrwxx/writeany.h>
#include <datrwxx/datatypes.h>
#include <libtime++.h>
using std::cout;
using std::cerr;
using std::endl;
struct Options {
bool verbose, overwrite, debug, integer, single;
unsigned int firstsamples, lastsamples;
int durationsamples;
std::string inputformat, outputformat;
}; // struct Options
/*======================================================================*/
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
TIJERASXX_VERSION "\n"
"usage: tijerasxx [--verbose] [--overwrite] [--integer] [--single]" "\n"
" [--iformat T] [--oformat T] [--samplesf N]" "\n"
" [--samplesl N] OUTFILE INFILE [t:T] [f:F]" "\n"
" [INFILE [t:T] [f:F] ... ]" "\n"
" or: tijerasxx --help|-h" "\n"
" or: tijerasxx --xhelp" "\n"
};
// define full help text
char help_text[]=
{
TIJERASXX_SVNID "\n"
"\n"
"Options may be abbreviated to a short string as long as they" "\n"
"remain unique. \"-v\" is identical to \"--verbose\"." "\n"
"\n"
"--verbose be verbose" "\n"
"--overwrite overwrite OUTFILE if file already exists" "\n"
"--integer use integer values for copying" "\n"
"--single use single precision floats for copying" "\n"
" default data type for copying is double presicion floats\n"
"--iformat T standard format of input file(s) (see below)" "\n"
"--oformat T data format of OUTFILE (see below)" "\n"
"\n"
"Data selection:" "\n"
"--samplesf N cut off N samples from the beginning of the timeseries\n"
"--samplesl N cut off N samples from the end of the timeseries\n"
"--samplesd N cut off after N samples beginning from '--samplesf'\n"
"Note that tijerasxx always will select the smallest subset passed by" "\n"
"the arguments above." "\n"
"\n"
"OUTFILE output data file name" "\n"
"INFILE(s) input data file name(s)" "\n"
"\n"
"File specific options:" "\n"
"t:T select specfic traces from INFILE" "\n"
" T can be a list of traces like \"1,4,5\" or" "\n"
" a range like \"6-19\" or mixed like \"5,8,12-17,20\"" "\n"
"f:F specify file format (overrides --iformat setting)" "\n"
"\n"
"The output format might not be able to store all header information" "\n"
"from the input data." "\n"
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: print extended help
{"xhelp",arg_no,"-"},
// 2: verbose mode
{"verbose",arg_no,"-"},
// 3: overwrite output
{"overwrite",arg_no,"-"},
// 4: overwrite output
{"iformat",arg_yes,"sff"},
// 5: overwrite output
{"oformat",arg_yes,"sff"},
// 6: overwrite output
{"DEBUG",arg_no,"-"},
// 7: read integer data
{"integer",arg_no,"-"},
// 8: read single precision data
{"single",arg_no,"-"},
// 9: cut off N samples from the beginning
{"samplesf",arg_yes,"0"},
// 10: cut off N samples from the end
{"samplesl",arg_yes,"0"},
// 11: cut off after N samples beginning from samplesf
{"samplesd",arg_yes,"-1"},
{NULL}
};
//! key to select traces
const char* const tracekey="t";
//! key to select file format
const char* const formatkey="f";
//! list of keys for filename specific parameters
static const char* cmdlinekeys[]={
//! select traces
tracekey,
//! set file format
formatkey,
0
}; // const char* keys[]
// no arguments? print usage...
if (iargc < 2)
{
cerr << usage_text << endl;
exit(0);
}
// collect options from commandline
Commandline cmdline(iargc, argv, options);
// help requested? print full help text ...
if (cmdline.optset(0) || cmdline.optset(1))
{
cout << usage_text << endl;
cout << help_text << endl;
datrw::supported_data_types(cerr);
if (cmdline.optset(1))
{
cout << endl;
datrw::online_help(cerr);
}
exit(0);
}
// extract command line options
Options opt;
opt.verbose=cmdline.optset(2);
opt.overwrite=cmdline.optset(3);
opt.inputformat=cmdline.string_arg(4);
opt.outputformat=cmdline.string_arg(5);
opt.debug=cmdline.optset(6);
opt.integer=cmdline.optset(7);
opt.single=cmdline.optset(8);
opt.firstsamples=cmdline.int_arg(9);
opt.lastsamples=cmdline.int_arg(10);
opt.durationsamples=cmdline.int_arg(11);
// extract commandline arguments
TFXX_assert(cmdline.extra(), "missing output file");
std::string outfile=cmdline.next();
TFXX_assert(cmdline.extra(), "missing input file");
tfxx::cmdline::Tparsed arguments=parse_cmdline(cmdline, cmdlinekeys);
if ((arguments.size()>1) && opt.verbose)
{
cout << "NOTICE: file specific information (SRCE line and file FREE)\n"
<< " of the second and subsequent files might get lost!\n";
}
/*----------------------------------------------------------------------*/
// full action!
// check whether output file exists
if (opt.verbose)
{
cout << "open output file " << outfile
<< " with format " << opt.outputformat << endl;
}
if (!opt.overwrite) { datrw::abort_if_exists(outfile); }
std::ofstream ofs(outfile.c_str(),
datrw::oanystream::openmode(opt.outputformat));
datrw::oanystream os(ofs, opt.outputformat, opt.debug);
if (opt.verbose) {
cout << "file data is stored in ";
// report output data format
switch (os.seriestype()) {
case datrw::Fint:
cout << "integer";
break;
case datrw::Ffloat:
cout << "single precision floating point";
break;
case datrw::Fdouble:
cout << "double precision floating point";
break;
case datrw::Fall:
cout << "any desired";
break;
default:
TFXX_abort("output stream uses unknown variable type!");
} // switch (os.seriestype())
cout << " variable type" << endl;
}
// cycle through all input files
// -----------------------------
bool firstfile=true;
tfxx::cmdline::Tparsed::const_iterator infile=arguments.begin();
while (infile != arguments.end())
{
// open input file
std::string inputformat=opt.inputformat;
if (infile->haskey(formatkey))
{ inputformat=infile->value(formatkey); }
if (opt.verbose)
{
cout << "open input file " << infile->name
<< " of format " << inputformat << endl;
}
std::ifstream ifs(infile->name.c_str(),
datrw::ianystream::openmode(inputformat));
datrw::ianystream is(ifs, inputformat, opt.debug);
/*----------------------------------------------------------------------*/
// pass file header data
// handle file header
if (firstfile)
{
if (is.hasfree())
{
if (os.handlesfilefree())
{
sff::FREE filefree;
is >> filefree;
os << filefree;
}
else
{
if (opt.verbose)
{
cout << " file FREE block is discarded." << endl;
}
}
} // if (is.hasfree())
} // if (firstfile)
if (is.hassrce())
{
if (os.handlessrce())
{
sff::SRCE srceline;
is >> srceline;
os << srceline;
}
else
{
if (opt.verbose)
{
cout << " SRCE line is discarded." << endl;
}
}
}
/*----------------------------------------------------------------------*/
// cycle through traces of input file
// ----------------------------------
// setup trace selection
typedef tfxx::RangeList<int> Trangelist;
bool doselect=infile->haskey(tracekey);
Trangelist traceranges=
tfxx::string::rangelist<Trangelist::Tvalue>(infile->value(tracekey));
int itrace=0;
while (is.good())
{
++itrace;
if ((!doselect) || traceranges.contains(itrace))
{
if (opt.verbose)
{ std::cout << " edit trace #" << itrace << std::endl; }
datrw::Tfseries fseries;
datrw::Tdseries dseries;
datrw::Tiseries iseries;
// read time series
if (opt.integer)
{
TFXX_assert(is.providesi(),
"ERROR: input data is not provided as integer values");
is >> iseries;
}
else if (opt.single)
{
TFXX_assert(is.providesf(),
"ERROR: input data is not provided as "
"single precision floats");
is >> fseries;
}
else
{
TFXX_assert(is.providesd(),
"ERROR: input data is not provided as "
"double precision floats");
is >> dseries;
}
// pass WID2
sff::WID2 wid2;
is >> wid2;
// compute smallest subset to cut off the series
unsigned int nsamples = wid2.nsamples;
if (0 < opt.firstsamples)
{
TFXX_assert(0 < (nsamples-opt.firstsamples),
"ERROR: Timeseries of zero length selected.")
nsamples -= opt.firstsamples;
double seconds = wid2.dt*opt.firstsamples;
int sec = static_cast<int>(seconds);
int milsec = static_cast<int>(seconds-sec);
libtime::TRelativeTime t(0,0,0,0,sec,milsec);
wid2.date += t;
}
if (0 < opt.durationsamples &&
opt.durationsamples < (nsamples-opt.lastsamples))
{
wid2.nsamples = opt.durationsamples;
} else
{
TFXX_assert(0 < (nsamples-opt.lastsamples),
"ERROR: Negative range or timeseries of zero length.")
wid2.nsamples = nsamples-opt.lastsamples;
}
os << wid2;
TFXX_debug(opt.debug, "tijerasxx: trace header data availability",
" is.hasinfo(): " << is.hasinfo() <<
" is.hasfree(): " << is.hasfree());
// pass INFO
if (is.hasinfo())
{
if (os.handlesinfo())
{
sff::INFO infoline;
is >> infoline;
os << infoline;
TFXX_debug(opt.debug, "tijerasxx: INFO data",
infoline.line());
}
else
{
if (opt.verbose)
{
cout << " INFO line is discarded." << endl;
}
}
}
// pass trace FREE
if (is.hasfree())
{
if (os.handlestracefree())
{
sff::FREE freeblock;
is >> freeblock;
freeblock.append("Edited with: ");
freeblock.append(TIJERASXX_VERSION);
freeblock.append(TIJERASXX_SVNID);
os << freeblock;
}
else
{
if (opt.verbose)
{
cout << " trace FREE block is discarded." << endl;
}
}
}
// check output data format
switch (os.seriestype()) {
case datrw::Fint:
if (!opt.integer)
{
cout << " WARNING: converting floating point data to integer!"
<< endl;
}
break;
case datrw::Ffloat:
if (!(opt.single || opt.integer))
{
cout << " WARNING: "
"converting double precision to single precision data!"
<< endl;
}
break;
case datrw::Fdouble:
// that's just fine
break;
case datrw::Fall:
// that's just fine
break;
default:
TFXX_abort("output stream uses unknown variable type!");
} // switch (os.seriestype())
// write output
if (opt.integer)
{
datrw::Tiseries result_series(iseries(opt.firstsamples),
iseries(opt.firstsamples+wid2.nsamples));
os << result_series;
}
else if (opt.single)
{
datrw::Tfseries result_series(fseries(opt.firstsamples),
fseries(opt.firstsamples+wid2.nsamples));
os << result_series;
}
else
{
datrw::Tdseries result_series(dseries(opt.firstsamples),
dseries(opt.firstsamples+wid2.nsamples));
os << result_series;
}
} // if ((!doselect) || traceranges.contains(itrace))
else
{
if (opt.verbose)
{ std::cout << " skip trace #" << itrace << std::endl; }
is.skipseries();
} // if ((!doselect) || traceranges.contains(itrace))
// end of this trace
} // while (is.good())
// end of this file
++infile;
} // while (infile != arguments.end())
}
/* ----- END OF tijerasxx.cc ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment