Commit c9dadaf3 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger

great coordinate setting program

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: 1541
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent b032420c
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.4 2002-03-14 10:46:38 forbrig Exp $
# $Id: Makefile,v 1.5 2004-09-08 14:30:58 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -14,7 +14,7 @@
all:
flist: Makefile $(wildcard *.f)
flist: Makefile $(wildcard *.f *.cc)
echo $^ | tr ' ' '\n' | sort > $@
.PHONY: edit
......@@ -32,6 +32,10 @@ LIBTF=-ltf -L$(LOCLIBDIR)
CC=gcc
CFLAGS=-O2
F2CFLAGS=-f -u
CXXFLAGS=-Wall $(FLAGS)
LDFLAGS=-L$(LOCLIBDIR)
CPPFLAGS=-I$(LOCINCLUDEDIR) $(FLAGS)
.f.o:
f2c $(F2CFLAGS) $<
......@@ -46,4 +50,9 @@ offli sesot merse: %: %.o
$(CC) -o $@ $< $(LIBTF) -lsffu -ltime_trad $(LIBSFF) $(F2CLIB)
newprog $@
cooset: %: %.o
$(CXX) -o $@ $^ -I$(LOCINCLUDEDIR) -lsffxx -ltime++ -lgsexx -laff \
-ltfxx -L$(LOCLIBDIR) $(CXXFLAGS) $(FLAGS)
newprog $@
# ----- END OF Makefile -----
/*! \file cooset.cc
* \brief set coordinates
*
* ----------------------------------------------------------------------------
*
* $Id: cooset.cc,v 1.1 2004-09-08 14:30:58 tforb Exp $
* \author Thomas Forbriger
* \date 08/09/2004
*
* set coordinates
*
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 08/09/2004 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define COOSET_VERSION \
"COOSET V1.0 set coordinates"
#define COOSET_CVSID \
"$Id: cooset.cc,v 1.1 2004-09-08 14:30:58 tforb Exp $"
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <sffxx.h>
#include <sffostream.h>
#include <aff/series.h>
#include <aff/subarray.h>
#include <libtime++.h>
#include <tfxx/commandline.h>
#include <tfxx/error.h>
using std::cout;
using std::cerr;
using std::endl;
struct Options {
bool verbose, overwrite, dostations, debug;
std::string stationsystem, stationfile, sourcetime, sourcecoo;
bool sesot, sesoc;
}; // struct Options
// structure to hold station coordinates
struct Station {
std::string id;
double x,y,z;
}; // struct Station
// vector of stations
typedef std::vector<Station> Tvecofstations;
// container to handle samples
typedef aff::Series<double> Tseries;
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
COOSET_VERSION "\n"
"usage: cooset [-stc s] [-stf file] [-soc \"C x y z\"] [-sot date]" "\n"
" [-v] [-o] infile outfile" "\n"
" or: cooset --help|-h" "\n"
};
// define full help text
char help_text[]=
{
"set source and station coordinates" "\n"
"\n"
"-stc s station coordinates system" "\n"
"-stf file station coordinates file" "\n"
"-soc C,x,y,z source coordinates" "\n"
"-sot date source time" "\n"
"-v be verbose" "\n"
"-o overwrite" "\n"
COOSET_CVSID
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: overwrite mode
{"o",arg_no,"-"},
// 3: station coordinates system
{"stc",arg_yes,"S"},
// 4: station coordinates file
{"stf",arg_yes,"-"},
// 5: source coordinates
{"soc",arg_yes,"-"},
// 6: source time
{"sot",arg_yes,"-"},
// 7: debug mode
{"D",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))
{
cerr << usage_text << endl;
cerr << help_text << endl;
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; }
*/
/*----------------------------------------------------------------------*/
// read command line
Options opt;
opt.verbose=cmdline.optset(1);
opt.overwrite=cmdline.optset(2);
opt.stationsystem=cmdline.string_arg(3);
opt.stationfile=cmdline.string_arg(4);
opt.dostations=cmdline.optset(4);
opt.sourcecoo=cmdline.string_arg(5);
opt.sesoc=cmdline.optset(5);
opt.sourcetime=cmdline.string_arg(6);
opt.sesot=cmdline.optset(6);
opt.debug=cmdline.optset(7);
TFXX_assert(cmdline.extra(),"ERROR: missing input file name!");
std::string infile=cmdline.next();
TFXX_assert(cmdline.extra(),"ERROR: missing output file name!");
std::string outfile=cmdline.next();
/*----------------------------------------------------------------------*/
// read station file if needed
Tvecofstations station;
if (opt.dostations)
{
if (opt.verbose) { cout << "read station list" << endl;}
std::ifstream is(opt.stationfile.c_str());
Station nextstation;
is >> nextstation.id;
while(is.good())
{
is >> nextstation.x >> nextstation.y >> nextstation.z;
station.push_back(nextstation);
if (opt.verbose)
{
cout << nextstation.id << " "
<< nextstation.x << " "
<< nextstation.y << " "
<< nextstation.z << endl;
}
is >> nextstation.id;
}
}
/*----------------------------------------------------------------------*/
// open files
if (opt.verbose) { cout << "open input file" << endl; }
std::ifstream is(infile.c_str());
TFXX_assert(is.good(),"ERROR: opening input file");
if (!opt.overwrite)
{
std::ifstream check(outfile.c_str());
TFXX_assert(!check,"ERROR: output file exists");
}
std::ofstream ofs(outfile.c_str());
TFXX_assert(ofs.good(),"ERROR: opening output file");
sff::SFFostream<Tseries> os(ofs, opt.debug);
/*----------------------------------------------------------------------*/
// modify file header
sff::FileHeader fileheader(is);
fileheader.appendfree(COOSET_VERSION);
fileheader.appendfree(COOSET_CVSID);
sff::SRCE filesrce=fileheader.srce();
if (fileheader.hassrce())
{ fileheader.appendfree("input file has SRCE line"); }
if (opt.sesot)
{
fileheader.appendfree("set source time");
libtime::TAbsoluteTime newsot(opt.sourcetime);
filesrce.date=newsot;
fileheader.setsrce(filesrce);
}
if (opt.sesoc)
{
fileheader.appendfree("set source coordinates");
std::istringstream socospec(opt.sourcecoo);
char syst;
double x,y,z;
socospec >> syst >> x >> y >> z;
std::ostringstream message;
message << "new coordinates: " << syst << ","
<< x << "," << y << "," << z;
filesrce.cs=sff::coosysID(syst);
filesrce.cx=x;
filesrce.cy=y;
filesrce.cz=z;
fileheader.appendfree(message.str());
fileheader.setsrce(filesrce);
}
if (opt.verbose)
{
cout << endl << "output file FREE block:" << endl;
cout << fileheader.free();
}
os << fileheader;
/*----------------------------------------------------------------------*/
// handle traces
bool last=false;
while (!last)
{
if (opt.verbose) { cout << endl << "read next trace:" << endl; }
sff::InputWaveform<Tseries> inputwaveform(is,opt.debug);
sff::TraceHeader traceheader(inputwaveform.header());
last=traceheader.last();
sff::INFO newinfo(traceheader.info());
const sff::WID2& wid2(traceheader.wid2());
if (opt.verbose) { cout << "station: " << wid2.station << endl; }
bool infoset=false;
if (opt.dostations)
{
Station thestation;
for (unsigned int i=0; i<station.size(); ++i)
{
thestation=station[i];
if (thestation.id == wid2.station)
{
infoset=true;
char syst=opt.stationsystem[0];
std::ostringstream message;
message << "new coordinates: " << syst << ","
<< thestation.x << "," << thestation.y << "," << thestation.z;
newinfo.cs=sff::coosysID(syst);
newinfo.cx=thestation.x;
newinfo.cy=thestation.y;
newinfo.cz=thestation.z;
traceheader.appendfree(message.str());
i=station.size();
}
}
if (infoset)
{
if (opt.verbose)
{
cout << traceheader.free() << endl;
}
}
else
{
cerr << "could not find station " << wid2.station << endl;
traceheader.appendfree("could not find station!");
}
}
os << traceheader;
if (infoset) { os << newinfo; }
os << inputwaveform.series();
}
}
/* ----- END OF cooset.cc ----- */
c this is <sesoc.f>
c ----------------------------------------------------------------------------
c ($Id: sesoc.f,v 1.1 2002-03-14 10:46:38 forbrig Exp $)
c ($Id: sesoc.f,v 1.2 2004-09-08 14:30:58 tforb Exp $)
c
c Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
c
......@@ -44,8 +44,8 @@ c
if (iargc().eq.1) call getarg(1, argument)
if ((argument(1:5).eq.'-help').or.(iargc().ne.3)) then
print *,version
print *,'Usage: sesot C,x,y,z infile outfile'
print *,' or: sesot -help'
print *,'Usage: sesoc C,x,y,z infile outfile'
print *,' or: sesoc -help'
if (argument(1:5).ne.'-help') stop 'ERROR: wrong number of arguments'
print *,' '
print *,'SEt SOurce Coordinate'
......
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