Commit 304e347b authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

first version that produces SFF output

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: 2180
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 4be6b88f
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.2 2006-11-17 16:46:50 tforb Exp $
# $Id: Makefile,v 1.3 2006-11-20 10:05:59 tforb Exp $
#
# Copyright (c) 2006 by Thomas Forbriger (BFO Schiltach)
#
......@@ -33,7 +33,7 @@ CPPFLAGS=-I$(LOCINCLUDEDIR) $(FLAGS)
mgm2sff: %: %.o
$(CXX) -o $@ $^ -I$(LOCINCLUDEDIR) \
-lsffxx -ltime++ -lgsexx -laff \
-lsffxx -ltime++ -lgsexx -laff -ltsxx -ldatreadxx \
-ltfxx -L$(LOCLIBDIR) $(CXXFLAGS) $(FLAGS)
/bin/cp -vpd $@ $(LOCBINDIR)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mgm2sff.cc,v 1.3 2006-11-17 16:51:43 tforb Exp $
* $Id: mgm2sff.cc,v 1.4 2006-11-20 10:06:00 tforb Exp $
* \author Thomas Forbriger
* \date 13/11/2006
*
......@@ -115,7 +115,7 @@
#define MGM2SFF_VERSION \
"MGM2SFF V1.0 Convert Monschau data to SFF"
#define MGM2SFF_CVSID \
"$Id: mgm2sff.cc,v 1.3 2006-11-17 16:51:43 tforb Exp $"
"$Id: mgm2sff.cc,v 1.4 2006-11-20 10:06:00 tforb Exp $"
#include <iostream>
#include <fstream>
......@@ -124,6 +124,10 @@
#include <tfxx/commandline.h>
#include <tfxx/error.h>
#include <libtime++.h>
#include <sffxx.h>
#include <sffostream.h>
#include <tsxx/sffheaders.h>
using std::cout;
using std::cerr;
......@@ -133,6 +137,8 @@ using std::endl;
typedef float Tvalue;
typedef aff::Series<Tvalue> Tseries;
typedef ts::sff::SFFTimeSeries<Tseries> TSFFseries;
typedef TSFFseries::Theader Theader;
/*======================================================================*/
/*
......@@ -179,7 +185,7 @@ class GeoDatFile {
* =======
*/
struct Options {
bool verbose, readinf, readdat;
bool verbose, readinf, readdat, overwrite, debug;
std::string inffile, datfile;
};
......@@ -308,7 +314,7 @@ int main(int iargc, char* argv[])
char usage_text[]=
{
MGM2SFF_VERSION "\n"
"usage: mgm2sff [-v] [-inf file] [-dat file] " "\n"
"usage: mgm2sff [-v] [-o] [-inf file] [-dat file] inbase outfile" "\n"
" or: mgm2sff --help|-h" "\n"
};
......@@ -317,8 +323,12 @@ int main(int iargc, char* argv[])
{
MGM2SFF_CVSID "\n"
"-v be verbose" "\n"
"-o overwrite existing output file" "\n"
"-inf file read inf file and dump" "\n"
"-dat file read dat file and dump" "\n"
"inbase basename for input data" "\n"
" inbase.inf and inbase.dat will be read" "\n"
"outfile filename for SFF output" "\n"
};
// define commandline options
......@@ -333,6 +343,10 @@ int main(int iargc, char* argv[])
{"inf",arg_yes,"-"},
// 3: read dat file and dump
{"dat",arg_yes,"-"},
// 4: overwrite existing output
{"o",arg_no,"-"},
// 5: debug mode
{"D",arg_no,"-"},
{NULL}
};
......@@ -354,39 +368,25 @@ int main(int iargc, char* argv[])
exit(0);
}
// dummy operation: print option settings
/*
for (int iopt=0; iopt<2; iopt++)
{
cout << "option: '" << options[iopt].opt_string << "'" << endl;
if (cmdline.optset(iopt)) { cout << " option was set"; }
else { cout << "option was not set"; }
cout << endl;
cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
cout << " argument (bool): '";
if (cmdline.bool_arg(iopt))
{ cout << "true"; } else { cout << "false"; }
cout << "'" << endl;
}
while (cmdline.extra()) { cout << cmdline.next() << endl; }
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }
*/
Options opt;
opt.verbose=cmdline.optset(1);
opt.readinf=cmdline.optset(2);
opt.inffile=cmdline.string_arg(2);
opt.readdat=cmdline.optset(3);
opt.datfile=cmdline.string_arg(3);
opt.overwrite=cmdline.optset(4);
opt.debug=cmdline.optset(5);
TFXX_assert(cmdline.extra(), "ERROR: missing input basename");
std::string inbase=cmdline.next();
TFXX_assert(cmdline.extra(), "ERROR: missing output filename");
std::string outfile=cmdline.next();
if (opt.readinf)
{
/*----------------------------------------------------------------------*/
/* read inf and dump */
if (opt.verbose)
{
cout << "read inf file " << opt.inffile
......@@ -401,6 +401,9 @@ int main(int iargc, char* argv[])
}
else if (opt.readdat)
{
/*----------------------------------------------------------------------*/
/* read dat and dump */
if (opt.verbose)
{
cout << "read dat file " << opt.datfile
......@@ -423,7 +426,182 @@ int main(int iargc, char* argv[])
<< " seconds."
<< endl;
}
else
{
/*----------------------------------------------------------------------*/
/* read data files and convert to SFF */
/* ================================== */
std::string ininf=inbase+".inf";
std::string indat=inbase+".dat";
const libtime::TRelativeTime onesecond(0,0,0,1);
const libtime::TRelativeTime nominalsampling(0,0,0,0,62,500);
if (opt.verbose)
{
cout << "reading from files: "
<< ininf << " and " << indat << endl;
cout << "writing to file " << outfile << endl;
}
/*----------------------------------------------------------------------*/
/* extract time range from inf file */
GeoInfFile gif;
{
std::ifstream ifs(ininf.c_str());
typedef char * pchar;
ifs.read(pchar(&gif), sizeof(GeoInfFile));
}
unsigned long int expectedsamples=
(((gif.last()-gif.first())+onesecond)/nominalsampling);
if (opt.verbose)
{
cout << "first sample at " << gif.first().timestring() << endl;
cout << "last sample at " << gif.last().timestring() << endl;
cout << "nominal sampling is: "
<< onesecond/nominalsampling << " samples per"
<< onesecond.timestring() << endl;
cout << "file is expected to contain "
<< expectedsamples << " samples." << endl;
}
/*----------------------------------------------------------------------*/
/* extract samples from dat file */
std::ifstream ifs(indat.c_str());
GeoDatFile gdf(ifs);
if (opt.verbose)
{
cout << "index range of series: " << endl;
cout << "ch 1: " << gdf.series(1).f()
<< " - " << gdf.series(1).l() << endl;
cout << "ch 2: " << gdf.series(2).f()
<< " - " << gdf.series(2).l() << endl;
cout << "ch 3: " << gdf.series(3).f()
<< " - " << gdf.series(3).l() << endl;
cout << "marks: " << gdf.timemark().f()
<< " - " << gdf.timemark().l() << endl;
cout << "Assuming 16Hz sampling, " << gdf.timemark().l()+2
<< " intervals span a time of "
<< double(gdf.timemark().l()+2)/16.
<< " seconds."
<< endl;
}
TFXX_assert(gdf.series(1).size() == expectedsamples,
"channel 1 size does not meet expectation");
TFXX_assert(gdf.series(2).size() == expectedsamples,
"channel 2 size does not meet expectation");
TFXX_assert(gdf.series(3).size() == expectedsamples,
"channel 3 size does not meet expectation");
TFXX_assert(gdf.timemark().size() == expectedsamples,
"timemark size does not meet expectation");
/*----------------------------------------------------------------------*/
/* write SFF data */
// check if output file exists and open
if (!opt.overwrite)
{
std::ifstream file(outfile.c_str(),std::ios_base::in);
TFXX_assert((!file.good()),"ERROR: output file exists!");
}
std::ofstream ofs(outfile.c_str());
sff::SFFostream<Tseries> os(ofs, opt.debug);
// prepare file free block
sff::FREE filefree;
filefree.append(MGM2SFF_VERSION);
filefree.append(MGM2SFF_CVSID);
filefree.append("input was read from files:");
filefree.append(ininf+" and "+indat);
filefree.append("files contain data for");
filefree.append(gif.first().timestring()+" - "+gif.last().timestring());
os << filefree;
if (opt.verbose)
{
cout << endl << "file FREE block:" << endl;
filefree.write(cout);
}
/* prepare traces and write to output */
TSFFseries sffseries;
Theader& header(sffseries.header);
sff::WID2 wid2line;
wid2line.date=gif.first();
wid2line.station="MGM";
wid2line.nsamples=expectedsamples;
wid2line.dt=libtime::time2double(nominalsampling);
{
sffseries=gdf.series(3);
wid2line.channel="Z";
sff::FREE tracefree;
tracefree.append("data from file "+indat);
tracefree.append("contains vertical (UD) component");
header.free(tracefree);
header.wid2(wid2line);
if (opt.verbose)
{
cout << endl << "trace header:" << endl;
cout << wid2line.line();
tracefree.write(cout);
}
os << sffseries;
}
{
sffseries=gdf.series(1);
wid2line.channel="N";
sff::FREE tracefree;
tracefree.append("data from file "+indat);
tracefree.append("contains north-south (NS) component");
header.free(tracefree);
header.wid2(wid2line);
if (opt.verbose)
{
cout << endl << "trace header:" << endl;
cout << wid2line.line();
tracefree.write(cout);
}
os << sffseries;
}
{
sffseries=gdf.series(2);
wid2line.channel="E";
sff::FREE tracefree;
tracefree.append("data from file "+indat);
tracefree.append("contains east-west (EW) component");
header.free(tracefree);
header.wid2(wid2line);
if (opt.verbose)
{
cout << endl << "trace header:" << endl;
cout << wid2line.line();
tracefree.write(cout);
}
os << sffseries;
}
{
sffseries=gdf.timemark();
wid2line.channel="TIM";
sff::FREE tracefree;
tracefree.append("data from file "+indat);
tracefree.append("contains time marks");
header.free(tracefree);
header.wid2(wid2line);
if (opt.verbose)
{
cout << endl << "trace header:" << endl;
cout << wid2line.line();
tracefree.write(cout);
}
os << sffseries;
}
}
}
/* ----- END OF mgm2sff.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