Commit 4c8436ce authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

proceeding: translation table

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: 2885
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 94812154
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.37 2009-09-18 13:03:51 tforb Exp $
# $Id: Makefile,v 1.38 2009-11-11 16:21:45 tforb Exp $
#
# Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
#
......@@ -40,7 +40,8 @@ HEADERS=datread.h bonjer.h bonjer/readbonjer.h readany.h error.h \
sff.h mseed.h mseed/mseedread.h mseed/seedstructs.h \
hpmo.h hpmo/readhpmo.h hpmo/hpmodata.h util.h sac.h sac/sacread.h \
bytesex.h debug.h gse.h gse/gseread.h tracereader.h \
tsoft/tsoftdata.h tsoft/tsoftreader.h tsoft.h
tsoft/tsoftdata.h tsoft/tsoftreader.h tsoft.h \
tsoft/channeltranslation.h tsoft/tsoftsffcontainer.h
#SRC=misc/fortranio.cc misc/commandline.cc misc/ioswap.cc misc/error.cc \
# misc/blitzfortranio.cc hacks/hack_blitztogrepg.cc
......@@ -51,7 +52,8 @@ LIBSRC=datread.cc bonjer/bonjer.cc bonjer/readbonjer.cc readany.cc error.cc \
hpmo/hpmo.cc hpmo/readhpmo.cc hpmo/hpmodata.cc \
util.cc sac/sac.cc sac/sacread.cc bytesex.cc gse/gseread.cc gse/gse.cc \
tracereader.cc \
tsoft/tsoftdata.cc tsoft/tsoftreader.cc
tsoft/tsoftdata.cc tsoft/tsoftreader.cc \
tsoft/tsoft.cc tsoft/tsoftsffcontainer.cc tsoft/channeltranslation.cc
TESTSRC=tests/hpmotest.cc tests/pdastest.cc tests/mseedtest.cc \
tests/sfftest.cc tests/sactest.cc tests/tsofttest.cc
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsofttest.cc,v 1.9 2009-11-11 09:17:08 tforb Exp $
* $Id: tsofttest.cc,v 1.10 2009-11-11 16:21:45 tforb Exp $
* \author Thomas Forbriger
* \date 17/09/2009
*
......@@ -35,7 +35,7 @@
#define TSOFTTEST_VERSION \
"TSOFTTEST V1.0 test tsoft reading"
#define TSOFTTEST_CVSID \
"$Id: tsofttest.cc,v 1.9 2009-11-11 09:17:08 tforb Exp $"
"$Id: tsofttest.cc,v 1.10 2009-11-11 16:21:45 tforb Exp $"
#include <iostream>
#include <fstream>
......@@ -43,6 +43,7 @@
#include <tfxx/commandline.h>
#include <datreadxx/tsoftdata.h>
#include <datreadxx/tsoftreader.h>
#include <datreadxx/channeltranslation.h>
using std::cout;
using std::cerr;
......@@ -51,7 +52,7 @@ using std::endl;
/*----------------------------------------------------------------------*/
struct Options {
bool verbose, test1, test2, test3, debug;
bool verbose, test1, test2, test3, debug, ttest;
}; // struct Options
/*----------------------------------------------------------------------*/
......@@ -63,7 +64,7 @@ int main(int iargc, char* argv[])
char usage_text[]=
{
TSOFTTEST_VERSION "\n"
"usage: tsofttest file [-t1] [-t2] [-t3] [-v] [-D]" "\n"
"usage: tsofttest file [-t1] [-t2] [-t3] [-t4] [-v] [-D]" "\n"
" or: tsofttest --help|-h" "\n"
};
......@@ -78,6 +79,7 @@ int main(int iargc, char* argv[])
"-t1 test individual components" "\n"
"-t2 test trimws" "\n"
"-t3 test class tsoftfile" "\n"
"-t4 test translation table" "\n"
};
// define commandline options
......@@ -96,6 +98,8 @@ int main(int iargc, char* argv[])
{"t3",arg_no,"-"},
// 5: debug mode
{"D",arg_no,"-"},
// 6: test translation table
{"t4",arg_no,"-"},
{NULL}
};
......@@ -123,6 +127,7 @@ int main(int iargc, char* argv[])
opt.test2=cmdline.optset(3);
opt.test3=cmdline.optset(4);
opt.debug=cmdline.optset(5);
opt.ttest=cmdline.optset(6);
/*
// dummy operation: print option settings
......@@ -273,6 +278,24 @@ int main(int iargc, char* argv[])
}
}
// end of test 3
/*======================================================================*/
// t test
if (opt.ttest)
{
if (opt.verbose)
{ cout << "ttest: translation table" << endl; }
datread::tsoft::reporttranslation(cout);
if (datread::tsoft::translationisunique())
{
cout << "The translation table is unique" << endl;
}
else
{
cout << "ATTENTION: The translation table is ambiguous" << endl;
}
}
// end of t test
}
/* ----- END OF tsofttest.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoft.h,v 1.3 2009-11-11 09:17:08 tforb Exp $
* $Id: tsoft.h,v 1.4 2009-11-11 16:21:45 tforb Exp $
* \author Thomas Forbriger
* \date 16/09/2009
*
......@@ -39,10 +39,42 @@
#define DATREAD_TSOFT_H_VERSION \
"DATREAD_TSOFT_H V1.0 "
#define DATREAD_TSOFT_H_CVSID \
"$Id: tsoft.h,v 1.3 2009-11-11 09:17:08 tforb Exp $"
"$Id: tsoft.h,v 1.4 2009-11-11 16:21:45 tforb Exp $"
#include<datreadxx/datread.h>
#include<datreadxx/tsoftsffcontainer.h>
namespace datread {
/*! \brief class to read TSOFT data
*
* \ingroup tsoft
*/
class itsoftstream: public idatstream {
public:
typedef idatstream Tbase;
itsoftstream(std::istream& is, const bool& debug=false);
virtual ~itsoftstream() { }
virtual Tdseries dseries();
virtual Tfseries fseries();
virtual Tiseries iseries();
virtual void skipseries();
static void help(std::ostream& os=std::cout);
private:
//! debugging mode
bool Mdebug;
//! container for complete file
datread::tsoft::File Mfile;
//! index of next trace to be passed
aff::Tsubscript Mitrace;
//! read file to buffer
Tdseries read(std::istream& is)
{
Mfile=datread::tsoft::readfile(is);
Mitrace=this->Mfile.Mtraces.first();
}
}; // class itsoftstream
} // namespace datread
#endif // DATREAD_TSOFT_H_VERSION (includeguard)
......
/*! \file channeltranslation.cc
* \brief translate TSOFT channel name (they are too long for SFF headers) (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: channeltranslation.cc,v 1.1 2009-11-11 16:21:45 tforb Exp $
* \author Thomas Forbriger
* \date 11/11/2009
*
* translate TSOFT channel name (they are too long for SFF headers) (implementation)
*
* Copyright (c) 2009 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* REVISIONS and CHANGES
* - 11/11/2009 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define DATREAD_CHANNELTRANSLATION_CC_VERSION \
"DATREAD_CHANNELTRANSLATION_CC V1.0 "
#define DATREAD_CHANNELTRANSLATION_CC_CVSID \
"$Id: channeltranslation.cc,v 1.1 2009-11-11 16:21:45 tforb Exp $"
#include <iomanip>
#include <datreadxx/error.h>
#include <datreadxx/tsoftdata.h>
#include <datreadxx/channeltranslation.h>
namespace datread {
namespace tsoft {
/*! \brief global variable: channel name translation table
* \ingroup tsoft
*/
const Channel translationtable[]={
{"BF:SG056:Grav-1", "BFO:GR1:SG056:Gra1"},
{"BF:SG056:Grav-2", "BFO:GR2:SG056:Gra2"},
{"BF:SG056:Baro-1", "BFO:BA1:SG056:Bar1"},
{"BF:SG056:LHe-Lvl", "BFO:LH1:SG056:LHeL"},
{"BF:SG056:Vstd-1", "BFO:VS1:SG056:VST1"},
{"BF:SG056:Vstd-2", "BFO:VS2:SG056:VST2"},
{"BF:SG056:AGnd", "BFO:GND:SG056:AGnd"},
{"BF:SG056:AD-1", "BFO:AD1:SG056:AD-1"},
{"BF:SG056:TREEfan", "BFO:FAN:SG056:Tfan"},
{"BF:SG056:G1-Sig", "BFO:G1S:SG056:Sig1"},
{"BF:SG056:G1-Mode", "BFO:G1M:SG056:Mod1"},
{"BF:SG056:G2-Sig", "BFO:G2S:SG056:Sig2"},
{"BF:SG056:G2-Mode", "BFO:G2M:SG056:Mod2"},
{"BF:SG056:Dewr-P", "BFO:DEP:SG056:DewP"},
{"BF:SG056:GBal-1", "BFO:G1B:SG056:GBa1"},
{"BF:SG056:TX-Pwr", "BFO:TXP:SG056:TXPw"},
{"BF:SG056:TX-Bal", "BFO:TXB:SG056:TXBa"},
{"BF:SG056:NeckT-1", "BFO:NT1:SG056:NTe1"},
{"BF:SG056:NeckT-2", "BFO:NT2:SG056:NTe2"},
{"BF:SG056:BelyT-3", "BFO:BT3:SG056:BTe3"},
{"BF:SG056:BodyT-4", "BFO:BT4:SG056:BTe4"},
{"BF:SG056:LHeLvl", "BFO:LHX:SG056:LHeX"},
{"BF:SG056:GBal-2", "BFO:G2B:SG056:GBa2"},
{"BF:SG056:TY-Pwr", "BFO:TYP:SG056:TYPw"},
{"BF:SG056:TY-Bal", "BFO:TYB:SG056:TYBa"},
{"BF:SG056:Tmp-Bal", "BFO:TBA:SG056:TBal"},
{"BF:SG056:HtrCrnt", "BFO:HCT:SG056:HCrt"},
{"BF:SG056:Temp_6K", "BFO:T6K:SG056:Te6K"},
{"BF:SG056:Temp_77", "BFO:T77:SG056:Te77"},
{"BF:SG056:FB_Mod", "BFO:FBM:SG056:FBMo"},
{"BF:SG056:P1GasCl", "BFO:P1C:SG056:P1GC"},
{"BF:SG056:P2GasRg", "BFO:P2R:SG056:P2GR"},
{"BF:SG056:P3CmpHi", "BFO:P3H:SG056:P3CH"},
{"BF:SG056:P4CmpLo", "BFO:P4L:SG056:P4CL"},
{"BF:SG056:P5CmpBl", "BFO:P5B:SG056:P5CB"},
{"BF:SG056:T1-Ext", "BFO:T1X:SG056:T1Ex"},
{"BF:SG056:T2-Ext", "BFO:T2X:SG056:T2Ex"},
{"BF:SG056:T3-Ext", "BFO:T3X:SG056:T3Ex"},
{"BF:SG056:Temp_G1", "BFO:TG1:SG056:TeG1"},
{"BF:SG056:Temp_G2", "BFO:TG2:SG056:T2G2"},
{"BF:SG056:Temp_TX", "BFO:TTX:SG056:TeTX"},
{"BF:SG056:Temp_TY", "BFO:TTY:SG056:TeTY"},
{"BF:SG056:Temp_TE", "BFO:TTE:SG056:TeTE"},
{"BF:SG056:Temp_AX", "BFO:TAX:SG056:TeAX"},
{"BF:SG056:Temp_CH", "BFO:TCH:SG056:TeCH"},
{"BF:SG056:Temp-Gt", "BFO:TGT:SG056:TeGt"},
{"BF:SG056:Dwr_Htr", "BFO:DHT:SG056:DHtr"},
{"BF:SG056:Comp_DC", "BFO:CDC:SG056:CoDC"},
{"BF:SG056:CH_DC", "BFO:CHD:SG056:CHDC"},
{"BF:SG056:Tmpr1", "BFO:TP1:SG056:Tmp1"},
{"BF:SG056:Tmpr2", "BFO:TP2:SG056:Tmp2"},
{"BF:SG056:RelHum1", "BFO:RH1:SG056:ReH1"},
{"BF:SG056:RelHum2", "BFO:RH2:SG056:ReH2"},
{NULL}
}; // Channel translationtable[]
/*======================================================================*/
// functions
TSOFTchannelid tchannelid(const Channel& ci)
{
std::string tci(ci.TSOFTname);
Tvos vos=stringtovec(tci, ":");
DATREAD_assert(vos.size()==3, "unexpected number of fields");
TSOFTchannelid retval;
retval.location=vos[0];
retval.instrument=vos[1];
retval.datatype=vos[2];
return(retval);
} // TSOFTchannelid tchannelid(const Channel& ci)
/*----------------------------------------------------------------------*/
SFFchannelid schannelid(const Channel& ci)
{
std::string sci(ci.SFFname);
Tvos vos=stringtovec(sci, ":");
DATREAD_assert(vos.size()==4, "unexpected number of fields");
SFFchannelid retval;
retval.station=vos[0];
retval.channel=vos[1];
retval.instrument=vos[2];
retval.auxid=vos[3];
return(retval);
} // SFFchannelid schannelid(const Channel& ci)
/*----------------------------------------------------------------------*/
//! \brief helper function: print fixed width field
void pfield(std::ostream& os, const std::string& s, const int& w)
{
os.width(w);
os.setf(std::ios_base::left, std::ios_base::adjustfield);
os << s.substr(0,w) << " ";
} // void pfield(std::ostream& os, const std::string& s, const int& w)
/*----------------------------------------------------------------------*/
//! \brief helper function: formatted output
void pline(std::ostream& os,
const std::string& s1,
const std::string& s2,
const std::string& s3,
const std::string& s4,
const std::string& s5,
const std::string& s6,
const std::string& s7)
{
pfield(os, s1, 8);
pfield(os, s2, 10);
pfield(os, s3, 8);
os << " --> ";
pfield(os, s4, 7);
pfield(os, s5, 7);
pfield(os, s6, 10);
pfield(os, s7, 5);
os << std::endl;
} // void pline
/*----------------------------------------------------------------------*/
void reporttranslation(std::ostream& os)
{
const Channel* pc=translationtable;
os << "translation table for TSOFT channels:" << std::endl;
pline(os, "TSOFT", "", "", "SFF", "", "", "");
pline(os, "location", "instrument", "datatype",
"station", "channel", "instrument", "auxid");
const char* line="----------";
pline(os, line, line, line, line, line, line, line);
while (pc->TSOFTname != NULL)
{
DATREAD_assert(pc->TSOFTname != NULL, "UUPS");
TSOFTchannelid tci=tchannelid(*pc);
SFFchannelid sci=schannelid(*pc);
pline(os,
tci.location,
tci.instrument,
tci.datatype,
sci.station,
sci.channel,
sci.instrument,
sci.auxid);
++pc;
}
} // void reporttranslation(std::ostream& os)
/*----------------------------------------------------------------------*/
bool translationisunique(const bool& verbose)
{
bool retval=true;
const Channel* pc1=translationtable;
while (pc1->TSOFTname != NULL)
{
TSOFTchannelid tci1=tchannelid(*pc1);
SFFchannelid sci1=schannelid(*pc1);
const Channel* pc2=pc1;
++pc2;
while (pc2->TSOFTname != NULL)
{
TSOFTchannelid tci2=tchannelid(*pc2);
SFFchannelid sci2=schannelid(*pc2);
if ((tci1.location==tci2.location)
&& (tci1.instrument==tci2.instrument)
&& (tci1.datatype==tci2.datatype))
{
std::cout << "ATTENTION: "
<< "TSOFT entry appears twice in translation table:"
<< std::endl;
std::cout << " "
<< tci1.location << ":"
<< tci1.instrument << ":"
<< tci1.datatype << std::endl;
retval=false;
}
if ((sci1.station==sci2.station)
&& (sci1.channel==sci2.channel)
&& (sci1.instrument==sci2.instrument)
&& (sci1.auxid==sci2.auxid))
{
std::cout << "ATTENTION: "
<< "SFF entry appears twice in translation table:"
<< std::endl;
std::cout << " "
<< sci1.station << ":"
<< sci1.channel << ":"
<< sci1.instrument << ":"
<< sci1.auxid << std::endl;
retval=false;
}
++pc2;
}
++pc1;
}
return(retval);
} // bool translationisunique(const bool& verbose)
} // namespace tsoft
} // namespace datread
/* ----- END OF channeltranslation.cc ----- */
/*! \file channeltranslation.h
* \brief translate TSOFT channel name (they are too long for SFF headers) (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: channeltranslation.h,v 1.1 2009-11-11 16:21:45 tforb Exp $
* \author Thomas Forbriger
* \date 11/11/2009
*
* translate TSOFT channel name (they are too long for SFF headers) (prototypes)
*
* Copyright (c) 2009 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* REVISIONS and CHANGES
* - 11/11/2009 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#include<iostream>
#include<string>
// include guard
#ifndef DATREAD_CHANNELTRANSLATION_H_VERSION
#define DATREAD_CHANNELTRANSLATION_H_VERSION \
"DATREAD_CHANNELTRANSLATION_H V1.0 "
#define DATREAD_CHANNELTRANSLATION_H_CVSID \
"$Id: channeltranslation.h,v 1.1 2009-11-11 16:21:45 tforb Exp $"
namespace datread {
namespace tsoft {
/*! \brief struct to hold a pair of channel names
* \ingroup tsoft
*/
struct Channel {
//! \brief channel description used in TSOFT
const char* TSOFTname;
//! \brief description to be used in SFF for this channel
const char* SFFname;
}; // struct Channel
/*----------------------------------------------------------------------*/
/*! \brief hold TSOFT channel description
* \ingroup tsoft
*/
struct TSOFTchannelid
{
std::string location, instrument, datatype;
}; // struct TSOFTchannelid
/*----------------------------------------------------------------------*/
/*! \brief hold SFF channel description
* \ingroup tsoft
*/
struct SFFchannelid
{
std::string station, channel, instrument, auxid;
}; // struct SFFchannelid
/*----------------------------------------------------------------------*/
/*! \brief global variable: channel name translation table
* \ingroup tsoft
*/
extern const Channel translationtable[];
/*======================================================================*/
// functions
/*! \brief split TSOFT channel description
* \ingroup tsoft
*/
TSOFTchannelid tchannelid(const Channel& ci);
/*----------------------------------------------------------------------*/
/*! \brief split SFF channel description
* \ingroup tsoft
*/
SFFchannelid schannelid(const Channel& ci);
/*----------------------------------------------------------------------*/
/*! \brief report translation table
* \ingroup tsoft
*/
void reporttranslation(std::ostream& os);
/*----------------------------------------------------------------------*/
/*! \brief check uniqueness of translation table
* \ingroup tsoft
*/
bool translationisunique(const bool& verbose=true);
} // namespace tsoft
} // namespace datread
#endif // DATREAD_CHANNELTRANSLATION_H_VERSION (includeguard)
/* ----- END OF channeltranslation.h ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoft.cc,v 1.1 2009-11-11 09:17:08 tforb Exp $
* $Id: tsoft.cc,v 1.2 2009-11-11 16:21:45 tforb Exp $
* \author Thomas Forbriger
* \date 11/11/2009
*
......@@ -32,15 +32,15 @@
*
* ============================================================================
*/
#define TF_TSOFT_CC_VERSION \
"TF_TSOFT_CC V1.0 "
#define TF_TSOFT_CC_CVSID \
"$Id: tsoft.cc,v 1.1 2009-11-11 09:17:08 tforb Exp $"
#define DATREAD_TSOFT_CC_VERSION \
"DATREAD_TSOFT_CC V1.0 "
#define DATREAD_TSOFT_CC_CVSID \
"$Id: tsoft.cc,v 1.2 2009-11-11 16:21:45 tforb Exp $"
#include <tsoft.h>
#include <datreadxx/tsoft.h>
namespace tf {
namespace datread {
}
} // namespace datread
/* ----- END OF tsoft.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsoftdata.h,v 1.11 2009-11-11 09:17:08 tforb Exp $
* $Id: tsoftdata.h,v 1.12 2009-11-11 16:21:45 tforb Exp $
* \author Thomas Forbriger
* \date 16/09/2009
*
......@@ -39,7 +39,7 @@
#define DATREAD_TSOFTDATA_H_VERSION \
"DATREAD_TSOFTDATA_H V1.0 "
#define DATREAD_TSOFTDATA_H_CVSID \
"$Id: tsoftdata.h,v 1.11 2009-11-11 09:17:08 tforb Exp $"
"$Id: tsoftdata.h,v 1.12 2009-11-11 16:21:45 tforb Exp $"
#include<iostream>
#include<string>
......@@ -50,42 +50,84 @@
namespace datread {
/*! \brief All classes and functions to extract data from TSOFT files
*
* TSOFT is available from
* http://seismologie.oma.be/TSOFT/tsoft.html
*
* \defgroup tsoft TSOFT data reading interface
*/
/*! \brief All classes and functions to extract data from TSOFT files
*
* \ingroup tsoft