Commit 213ebdce authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

added new program sehefixx

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: 4915
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 37ff0230
......@@ -46,9 +46,8 @@
# sesoc set the source coordinate in an SFF data file
# sesot set the source time in an SFF data file
# tijerasxx extract portions of time series (windowing - not tapering)
#
# To compile this code with the rules given below, you need the f2c compiler
# from Netlib.
# sehefixx sets trace header fields and operates on all data formats
# supported by libdatrwxx
#
# To link the programs, you need libraries provided in packages that can be
# downloaded from the place, you obtained this package from. You will need the
......@@ -72,12 +71,13 @@
# 17/01/2011 V1.3 migrated to new SVN scheme
# implemented offlix and chacox
# 03/03/2012 V1.4 added tijerasxx (damb)
# 07/01/2013 V1.5 added sehefixx
#
# ============================================================================
#
PROGRAMS=sehefi coma epi chaco sesoc offli sesot merse cooset \
offlix chacox tijerasxx
offlix chacox tijerasxx sehefixx
.PHONY: all
all: install
......@@ -143,7 +143,7 @@ offlix: %x: %.o
$(FC) -o $@ $< -ltf -lsffu -ltime_trad \
-lfapidxx -ldatrwxx -lsffxx -lgsexx -ltime++ -laff -L$(LOCLIBDIR)
tijerasxx: %: %.o
sehefixx tijerasxx: %: %.o
$(CXX) -o $@ $^ -I$(LOCINCLUDEDIR) -ldatrwxx \
-lsffxx -ltime++ -lgsexx -laff -ltfxx \
-L$(LOCLIBDIR) $(CXXFLAGS) $(FLAGS) $(LDFLAGS)
......
/*! \file sehefixx.cc
* \brief set header field
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 07/01/2013
*
* set header field
*
* Copyright (c) 2013 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 07/01/2013 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define SEHEFIXX_VERSION \
"SEHEFIXX V1.0 set header field"
#define SEHEFIXX_CVSID \
"$Id$"
#include <iostream>
#include <fstream>
#include <string>
#include <tfxx/commandline.h>
#include <tfxx/error.h>
#include <datrwxx/readany.h>
#include <datrwxx/writeany.h>
#include <datrwxx/datatypes.h>
using std::cout;
using std::cerr;
using std::endl;
/*----------------------------------------------------------------------*/
struct Options {
std::string itype, otype;
bool verbose, overwrite, debug, integer, single;
std::string newchannel, newstation, newinstype, newauxid;
bool setchannel, setstation, setinstype, setauxid;
}; // struct Options
/*----------------------------------------------------------------------*/
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
SEHEFIXX_VERSION "\n"
"usage: sehefixx infile outfile [-verbose] [-overwrite] [-itype] [-otype]" "\n"
" [-ss station] [-sc channel] [-si instype]\n"
" [-sa auxid]\n"
" [-integer] [-float]\n"
" or: sehefixx --help|-h" "\n"
};
// define full help text
char help_text[]=
{
SEHEFIXX_CVSID
"\n"
"infile name of input data file\n"
"outfile name of output data file\n"
"\n"
"-verbose be verbose\n"
"-overwrite overwrite existing output file\n"
"-itype input file data format type\n"
"-otype output file data format type\n"
"-integer use integer sample values rather than double\n"
"-float use single precision sample values rather than double\n"
"-ss station set station header field to \'station\'\n"
"-ss channel set channel header field to \'channel\'\n"
"-ss instype set instype header field to \'instype\'\n"
"-ss auxid set auxid header field to \'auxid\'\n"
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: verbose mode
{"verbose",arg_no,"-"},
// 2: overwrite output
{"overwrite",arg_no,"-"},
// 3: input file type
{"itype",arg_yes,"sff"},
// 4: output file type
{"otype",arg_yes,"sff"},
// 5: set station
{"sstaion",arg_yes,"-"},
// 6: set channel
{"schannel",arg_yes,"-"},
// 7: set instype
{"sinstype",arg_yes,"-"},
// 8: set auxid
{"sauxid",arg_yes,"-"},
// 9: extra help
{"xhelp",arg_no,"-"},
// 10: integer values
{"integer",arg_no,"-"},
// 11: single precision values
{"float",arg_no,"-"},
{NULL}
};
// 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(9))
{
cerr << usage_text << endl;
cerr << help_text << endl;
datrw::supported_data_types(cerr);
if (cmdline.optset(9))
{
cerr << endl;
datrw::online_help(cerr);
}
exit(0);
}
// extract command line options
Options opt;
opt.debug=false;
opt.verbose=cmdline.optset(1);
opt.overwrite=cmdline.optset(2);
opt.itype=cmdline.string_arg(3);
opt.otype=cmdline.string_arg(4);
opt.setstation=cmdline.optset(5);
opt.newstation=cmdline.string_arg(5);
opt.setchannel=cmdline.optset(6);
opt.newchannel=cmdline.string_arg(6);
opt.setinstype=cmdline.optset(7);
opt.newinstype=cmdline.string_arg(7);
opt.setauxid=cmdline.optset(8);
opt.newauxid=cmdline.string_arg(8);
opt.integer=cmdline.optset(10);
opt.single=cmdline.optset(11);
TFXX_assert(cmdline.extra(), "missing input file name");
std::string infile=cmdline.next();
TFXX_assert(cmdline.extra(), "missing output file name");
std::string outfile=cmdline.next();
/*----------------------------------------------------------------------*/
// full action!
// check whether output file exists
if (opt.verbose)
{
cout << "open output file " << outfile
<< " with format " << opt.otype << endl;
}
if (!opt.overwrite) { datrw::abort_if_exists(outfile); }
std::ofstream ofs(outfile.c_str(),
datrw::oanystream::openmode(opt.otype));
datrw::oanystream os(ofs, opt.otype, opt.debug);
if (opt.verbose)
{
cout << "open input file " << infile
<< " of format " << opt.itype << endl;
}
std::ifstream ifs(infile.c_str(),
datrw::ianystream::openmode(opt.itype));
datrw::ianystream is(ifs, opt.itype, opt.debug);
/*----------------------------------------------------------------------*/
// pass file header data
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 (is.hassrce())
{
if (os.handlessrce())
{
sff::SRCE srceline;
is >> srceline;
os << srceline;
}
else
{
if (opt.verbose)
{
cout << " SRCE line is discarded." << endl;
}
}
}
int itrace=0;
while (is.good())
{
++itrace;
if (opt.verbose) { std::cout << " edit trace #" << itrace << std::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())
datrw::Tiseries iseries;
datrw::Tfseries fseries;
datrw::Tdseries dseries;
// 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;
if (opt.setstation) { wid2.station=opt.newstation; }
if (opt.setchannel) { wid2.channel=opt.newchannel; }
if (opt.setinstype) { wid2.instype=opt.newinstype; }
if (opt.setauxid) { wid2.auxid=opt.newauxid; }
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;
freeblock.append("Edited with: ");
freeblock.append(SEHEFIXX_VERSION);
freeblock.append(SEHEFIXX_CVSID);
os << freeblock;
}
else
{
if (opt.verbose)
{
cout << " trace FREE block is discarded." << endl;
}
}
}
// write time series
if (opt.integer)
{
os << iseries;
}
else if (opt.single)
{
os << fseries;
}
else
{
os << dseries;
}
}
}
/* ----- END OF sehefixx.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