Commit 8220b7fa authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

haaa, proceeding...

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: 1405
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 7e80031d
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.5 2003-06-24 07:45:54 tforb Exp $
# $Id: Makefile,v 1.6 2003-12-15 07:53:33 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -95,6 +95,6 @@ doxyview: doxyfullview doxybrief
gsexx_tests: gsexx_tests.cc
$(CXX) -o $@ $< -I$(LOCINCLUDEDIR) -lgsexx -L$(LOCLIBDIR)
tests: gsexx_tests; $<
tests: gsexx_tests; $<; rm -fv $<
# ----- END OF Makefile -----
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: gsexx.h,v 1.8 2003-06-26 20:54:59 tforb Exp $
* $Id: gsexx.h,v 1.9 2003-12-15 07:53:34 tforb Exp $
* \author Thomas Forbriger
* \date 16/03/2002
*
......@@ -23,7 +23,7 @@
#define TF_GSEXX_H_VERSION \
"TF_GSEXX_H V1.0 "
#define TF_GSEXX_H_CVSID \
"$Id: gsexx.h,v 1.8 2003-06-26 20:54:59 tforb Exp $"
"$Id: gsexx.h,v 1.9 2003-12-15 07:53:34 tforb Exp $"
// #include <libtime++.h>
#include<string>
......@@ -76,41 +76,41 @@ enum Esubformat
*/
//! A class to hold and manage the WID2-line.
class TWID2 {
//! This is a struct - because it is a simple collection of fields
//! together with a few formatting functions
struct TWID2 {
public:
//! GSE line idetifier
static const char* const GSEID;
//! default constructor sets default values
TWID2();
//! minimum constructor with many defaults
TWID2(const int& samps, const double& samprate,
const int& year=2002, const int& month=4,
const int& day=5, const int& hour=0,
const int& minute=0, const double& seconds=0.,
const string& station="NSP", const string& channel="NSP",
const string& auxid="NSP", const string& instype="NSP",
const double& calib=-1., const double& calper=-1.,
const double& hang=-1., const double& vang=-1.,
const Esubformat& subformat=SF_CM6);
TWID2() { this->defaults(); }
//! return subformat ID string
std::string subformat() const;
//! write the WID2 line
std::string line() const;
//! read a WID2 line from a stream
void read(std::istream& is);
//! set the values to defaults
void defaults();
public:
int Myear; //!< year of date
int Mmonth; //!< month of date
int Mday; //!< day of date
int Mhour; //!< hour of time
int Mminute; //!< minute of time
double Mseconds; //!< seconds of time
std::string Mstation; //!< Station code
std::string Mchannel; //!< FDSN channel code
std::string Mauxid; //!< Auxiliary identification code
Esubformat Msubformat; //!< GSE2 waveform subformat
int Msamps; //!< number of samples
double Msamprate; //!< sampling rate (Hz)
double Mcalib; //!< calibration factor
double Mcalper; //!< calibration reference period
std::string Minstype; //!< instrument type
double Mhang; //!< horizontal orientation
double Mvang; //!< veritcal orientation
}; // class TWID2
int Fyear; //!< year of date
int Fmonth; //!< month of date
int Fday; //!< day of date
int Fhour; //!< hour of time
int Fminute; //!< minute of time
double Fseconds; //!< seconds of time
std::string Fstation; //!< Station code
std::string Fchannel; //!< FDSN channel code
std::string Fauxid; //!< Auxiliary identification code
Esubformat Fsubformat; //!< GSE2 waveform subformat
int Fsamps; //!< number of samples
double Fsamprate; //!< sampling rate (Hz)
double Fcalib; //!< calibration factor
double Fcalper; //!< calibration reference period
std::string Finstype; //!< instrument type
double Fhang; //!< horizontal orientation
double Fvang; //!< veritcal orientation
}; // struct TWID2
/*======================================================================*/
/*
......@@ -139,8 +139,14 @@ class TCHK2 {
TCHK2(): Msum(0) { }
//! Add a value to the checksum.
void add(const intT& value);
//! initialize for new waveform
void init() { set(0); }
//! Return the checksum value.
intT value() const { return(Msum); }
//! write CHK2 line to string
std::string write() const;
//! read CHK2 line from istream
void read(std::istream& is);
//! GSE line idetifier
static const char* const GSEID;
private:
......@@ -149,14 +155,6 @@ class TCHK2 {
intT Msum; //!< checksum value
}; // class TCHK2
/*----------------------------------------------------------------------*/
//! Output TCHK2 object to stream.
std::ostream& operator<<(std::ostream&, const TCHK2& chk2);
//! Input TCHK2 object from stream.
std::istream& operator>>(std::istream&, TCHK2& chk2);
/*======================================================================*/
/*
* modules to apply and remove differnces must be declared here
......@@ -244,6 +242,13 @@ typedef differences::Tdiff_operator<2, differences::Tremove_diff>
//! Handle checksum and sample count
class TDAT2sum {
public:
//! initialize for another set
void init(const intT& msamp)
{
Mmsamp=msamp;
Mnsamp=0;
Mchecksum=TCHK2();
}
//! return the checksum
const TCHK2& checksum() const { return(Mchecksum); }
//! return the number of samples read
......@@ -282,31 +287,25 @@ class TDAT2read: public TDAT2sum
{
public:
//! get another value from the stream
intT get();
intT get(std::istream& is);
protected:
//! constructor to be called from implementation class
TDAT2read(istream& is, const intT& msamp):
TDAT2sum(msamp), Mis(is) { }
TDAT2read(const intT& msamp):
TDAT2sum(msamp) { }
private:
//! get from stream: user must define
virtual intT get_from_stream() = 0;
virtual intT convert(std::istream& is) = 0;
protected:
//! reference to stream we read from
istream& Mis;
}; // TDAT2read
// inline get wrapper function
inline intT TDAT2read::get()
inline intT TDAT2read::get(std::istream& is)
{
intT retval=get_from_stream();
intT retval=convert(is);
add(retval);
return(retval);
}
//! Read from TDAT2read object
TDAT2read& operator>>(TDAT2read& in, intT& val)
{ val=in.get(); return(in); }
/*----------------------------------------------------------------------*/
//! Abstract base class for writing %GSE2 %waveform data.
......@@ -314,39 +313,27 @@ class TDAT2write: public TDAT2sum
{
public:
//! write another value to the stream
void put(const intT& value);
std::string operator()(const intT& value);
//! initialize to start an new write session
void init(const intT& msamp)
{
this->TDAT2sum::init(msamp);
Mcpos=0;
}
protected:
//! constructor to be called from implementation class
TDAT2write(ostream& os, const intT& msamp, const intT& linelength):
TDAT2sum(msamp), Mos(os), Mlinelength(linelength), Mcpos(0) { }
TDAT2write(const intT& msamp, const intT& linelength):
TDAT2sum(msamp), Mlinelength(linelength), Mcpos(0) { }
private:
//! put to stream: user must define
virtual void put_to_stream(const intT& value) = 0;
virtual std::string convert(const intT& value) = 0;
protected:
//! reference to stream we write to
ostream& Mos;
//! linelength in output file
intT Mlinelength;
//! character position in line
intT Mcpos;
}; // TDAT2write
// inline put wrapper function
inline void TDAT2write::put(const intT& value)
{
if (!TDAT2sum::hot()) throw
Terror("ERROR (TDAT2write): writing more samples than specified!");
add(value);
put_to_stream(value);
if (!TDAT2sum::hot()) {
Mos << TDAT2sum::checksum();
}
}
//! Write to TDAT2write object
TDAT2write& operator<<(TDAT2write& out, const intT& val)
{ out.put(val); return(out); }
/*----------------------------------------------------------------------*/
//! Derived class for reading %CM6 subformat data.
......@@ -354,11 +341,11 @@ class TDAT2readCM6: public TDAT2read
{
public:
//! constructor of implementation class
TDAT2readCM6(istream& is, const intT& msamp):
TDAT2read(is, msamp) { }
TDAT2readCM6(const intT& msamp):
TDAT2read(msamp) { }
private:
//! get from stream: user must define
virtual intT get_from_stream() = 0;
virtual intT convert(std::istream& is) = 0;
private:
//! only compression formats apply differences.
remove2nddiffT Mremovediff;
......@@ -371,11 +358,11 @@ class TDAT2writeCM6:public TDAT2write
{
public:
//! constructor of implementation class
TDAT2writeCM6(ostream& os, const intT& msamp, const intT& linelength=80):
TDAT2write(os, msamp, linelength) { }
TDAT2writeCM6(const intT& msamp, const intT& linelength=80):
TDAT2write(msamp, linelength) { }
private:
//! put to stream: user must define
virtual void put_to_stream(const intT& value);
std::string convert(const intT& value);
private:
//! only compression formats apply differences.
apply2nddiffT Mapplydiff;
......@@ -393,8 +380,8 @@ class TDAT2writeCM6:public TDAT2write
//! Check GSE identifier at beginning of line.
template<class C>
bool GSEIDmatch(const string& line)
{ return(line.substr(0,4)==string(C.GSEID)); }
bool GSEIDmatch(const std::string& line)
{ return(line.substr(0,4)==string(C::GSEID)); }
} // namespace GSE2
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: gsexx_TCHK2.cc,v 1.2 2002-04-03 15:28:58 forbrig Exp $
* $Id: gsexx_TCHK2.cc,v 1.3 2003-12-15 07:53:34 tforb Exp $
* \author Thomas Forbriger
* \date 29/03/2002
*
......@@ -19,19 +19,20 @@
#define TF_GSEXX_TCHK2_CC_VERSION \
"TF_GSEXX_TCHK2_CC V1.0 "
#define TF_GSEXX_TCHK2_CC_CVSID \
"$Id: gsexx_TCHK2.cc,v 1.2 2002-04-03 15:28:58 forbrig Exp $"
"$Id: gsexx_TCHK2.cc,v 1.3 2003-12-15 07:53:34 tforb Exp $"
#include<cmath>
#include <gsexx.h>
#include <sstream>
namespace GSE2 {
namespace waveform {
/*! \class TCHK2
*
* This class allows the cumulative calculation of checksums. The code is take
* from the Appendix A.1 from the Conference Room Paper/243 of the Group of
* Scientific Experts.
* This class allows the cumulative calculation of checksums. The code is
* taken from the Appendix A.1 from the Conference Room Paper/243 of the Group
* of Scientific Experts.
*/
//! GSE line identifier
......@@ -71,12 +72,13 @@ void TCHK2::add(const intT& value)
/*! \relates TCHK2
* Write a checksum CHK2-line to a GSE data file.
*/
std::ostream& operator<<(std::ostream& os, const TCHK2& chk2)
std::string TCHK2::write() const
{
os.width(4); os << "CHK2 ";
os.width(8); os << chk2.value();
os << endl;
return(os);
std::string retval("CHK2 ");
char cvalue[10];
std::sprintf(cvalue, "%8i\n", this->value());
retval.append(cvalue);
return(retval);
}
/*----------------------------------------------------------------------*/
......@@ -84,13 +86,12 @@ std::ostream& operator<<(std::ostream& os, const TCHK2& chk2)
/*! \relates TCHK2
* Read a checksum CHK2-line from a GSE data file.
*/
std::istream& operator>>(std::istream& is, TCHK2& chk2)
void TCHK2::read(std::istream& is)
{
cerr << "std::istream& operator>>(std::istream& os, TCHK2& chk2)"
<< endl
<< "not yet defined!" << endl;
std::cerr << "std::istream& operator>>(std::istream& os, TCHK2& chk2)"
<< std::endl
<< "not yet defined!" << std::endl;
abort();
return(is);
}
} // namespace waveform
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: gsexx_TDAT2.cc,v 1.2 2002-04-03 15:28:58 forbrig Exp $
* $Id: gsexx_TDAT2.cc,v 1.3 2003-12-15 07:53:34 tforb Exp $
* \author Thomas Forbriger
* \date 29/03/2002
*
......@@ -19,7 +19,7 @@
#define TF_GSEXX_TDAT2_CC_VERSION \
"TF_GSEXX_TDAT2_CC V1.0 "
#define TF_GSEXX_TDAT2_CC_CVSID \
"$Id: gsexx_TDAT2.cc,v 1.2 2002-04-03 15:28:58 forbrig Exp $"
"$Id: gsexx_TDAT2.cc,v 1.3 2003-12-15 07:53:34 tforb Exp $"
#include <gsexx.h>
#include "gsexx_TDAT2.h"
......@@ -144,6 +144,26 @@ const char* const TDAT2sum::GSEID="DAT2";
* \param linelength line length for the encoded waveform data in the file
*/
// inline conversion wrapper function
std::string TDAT2write::operator()(const intT& value)
{
std::string retval;
if (this->TDAT2sum::nread() == 0)
{
retval+=TDAT2sum::GSEID;
retval+='\n';
}
if (!this->TDAT2sum::hot()) throw
Terror("ERROR (TDAT2write): writing more samples than specified!");
this->TDAT2sum::add(value);
retval+=convert(value);
if (!TDAT2sum::hot()) {
retval+='\n';
retval+=this->TDAT2sum::checksum().write();
}
return(retval);
}
/*======================================================================*/
/*
......@@ -190,10 +210,10 @@ const char* const TDAT2sum::GSEID="DAT2";
*
* \return integer value (not difference value) read from stream.
*/
intT TDAT2readCM6::get_from_stream()
intT TDAT2readCM6::convert(std::istream& is)
{
// it's simple :-)
return(Mremovediff(CM6::decode(Mis)));
return(Mremovediff(CM6::decode(is)));
}
/*======================================================================*/
......@@ -234,21 +254,23 @@ intT TDAT2readCM6::get_from_stream()
*
* \param value integer value (not difference value) to write.
*/
void TDAT2writeCM6::put_to_stream(const intT& value)
std::string TDAT2writeCM6::convert(const intT& value)
{
string charcode=CM6::encode(Mapplydiff(value));
std::string charcode=CM6::encode(Mapplydiff(value));
std::string retval;
// iterate through all characters
for (string::iterator c=charcode.begin(); c!=charcode.end(); c++)
for (std::string::const_iterator c=charcode.begin(); c!=charcode.end(); c++)
{
// next line if full
if (Mlinelength <= Mcpos)
{
Mos << endl;
retval+='\n';
Mcpos=0;
}
Mos << *c;
retval+=*c;
Mcpos++;
}
return(retval);
}
} // namespace waveform
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: gsexx_TDAT2.h,v 1.2 2002-04-01 21:48:34 forbrig Exp $
* $Id: gsexx_TDAT2.h,v 1.3 2003-12-15 07:53:35 tforb Exp $
* \author Thomas Forbriger
* \date 29/03/2002
*
......@@ -30,7 +30,7 @@
#define TF_GSEXX_TDAT2_H_VERSION \
"TF_GSEXX_TDAT2_H V1.0 "
#define TF_GSEXX_TDAT2_H_CVSID \
"$Id: gsexx_TDAT2.h,v 1.2 2002-04-01 21:48:34 forbrig Exp $"
"$Id: gsexx_TDAT2.h,v 1.3 2003-12-15 07:53:35 tforb Exp $"
#include <gsexx.h>
#include <string>
......@@ -43,10 +43,10 @@ namespace waveform {
namespace CM6 {
//! %CM6 subformat encoding function.
string encode(const intT& value);
std::string encode(const intT& value);
//! %CM6 subformat decoding function.
intT decode(istream& is);
intT decode(std::istream& is);
} // namespace cm6
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: gsexx_TWID2.cc,v 1.2 2002-04-03 15:28:58 forbrig Exp $
* $Id: gsexx_TWID2.cc,v 1.3 2003-12-15 07:53:35 tforb Exp $
* \author Thomas Forbriger
* \date 29/03/2002
*
......@@ -19,8 +19,9 @@
#define TF_GSEXX_TWID2_CC_VERSION \
"TF_GSEXX_TWID2_CC V1.0 "
#define TF_GSEXX_TWID2_CC_CVSID \
"$Id: gsexx_TWID2.cc,v 1.2 2002-04-03 15:28:58 forbrig Exp $"
"$Id: gsexx_TWID2.cc,v 1.3 2003-12-15 07:53:35 tforb Exp $"
#include <ctime>
#include <gsexx.h>
namespace GSE2 {
......@@ -34,6 +35,61 @@ namespace waveform {
//! GSE line identifier
const char* const TWID2::GSEID="WID2";
//! return subformat string
std::string TWID2::subformat() const
{
std::string retval("NSP");
if (Fsubformat == SF_CM6) retval="CM6";
return(retval);
}
//! write the WID2 line
std::string TWID2::line() const
{
std::string datatype=subformat();
char wid2line[135];
sprintf(wid2line, "%4s %4.4i/%2.2i/%2.2i %2.2i:%2.2i:%6.3f "
"%5s %3s %4s %3s %8i %11.6f %10.2e %7.3f %6s %5.1f %4.1f\n",
TWID2::GSEID, Fyear, Fmonth, Fday,
Fhour, Fminute, Fseconds,
Fstation.substr(0,5).c_str(),
Fchannel.substr(0,3).c_str(),
Fauxid.substr(0,4).c_str(),
datatype.substr(0,3).c_str(),
Fsamps, Fsamprate, Fcalib, Fcalper,
Finstype.substr(0,6).c_str(),
Fhang, Fvang);
std::string retval(wid2line);
return(retval);
}
//! read a WID2 line from a stream
//void TWID2::read(std::istream& is);
//! set the values to defaults
void TWID2::defaults()
{
std::time_t nowtime=std::time(NULL);
std::tm *now=std::localtime(&nowtime);
Fyear=now->tm_year+1900;
Fmonth=now->tm_mon;
Fday=now->tm_mday;
Fhour=now->tm_hour;
Fminute=now->tm_min;
Fseconds=double(now->tm_sec);
Fstation="NSP";
Fchannel="NSP";
Fauxid="NSP";
Fsubformat=SF_CM6;
Fsamps=-1;
Fsamprate=-1.;
Fcalib=-1.;
Fcalper=-1.;
Finstype="NSP";
Fhang=-1.;
Fvang=-1.;
}
/*----------------------------------------------------------------------*/
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: gsexx_cm6.cc,v 1.3 2003-06-24 07:45:54 tforb Exp $
* $Id: gsexx_cm6.cc,v 1.4 2003-12-15 07:53:36 tforb Exp $
* \author Thomas Forbriger
* \date 29/03/2002
*
......@@ -19,7 +19,7 @@
#define TF_GSEXX_CM6_CC_VERSION \
"TF_GSEXX_CM6_CC V1.0 "
#define TF_GSEXX_CM6_CC_CVSID \
"$Id: gsexx_cm6.cc,v 1.3 2003-06-24 07:45:54 tforb Exp $"
"$Id: gsexx_cm6.cc,v 1.4 2003-12-15 07:53:36 tforb Exp $"
#include <gsexx.h>
#include "gsexx_TDAT2.h"
......@@ -51,10 +51,10 @@ namespace CM6 {
*
* \sa GSE2::waveform::TDAT2writeCM6
*/
string encode(const intT& value)
std::string encode(const intT& invalue)
{
// string variable to store return value
string retval;
std::string retval;
// The original version of the core of this function was coded by Stefan
// Stange. The code (compress_6b) can be found in gse_functions.c in is
......@@ -73,6 +73,8 @@ string encode(const intT& value)
St. Stange, 28.4.1998
*********************************************************************/
// copy of value to be manipulated
intT value=invalue;
// this defines the value to character mapping
char achar[] =
" +-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
......@@ -88,7 +90,7 @@ string encode(const intT& value)
// internal values
int nflag;
int mflag = 32;
long jc, si;
long jc;
int case_expo;
nflag = 1;
......@@ -101,7 +103,7 @@ string encode(const intT& value)
// the original code clipped at 2**27 -1
// we consider a number that large to be illegal
if (value >= expo_2[6])
throw GSE::Terror("ERROR (CM6::encode): illegal value");
throw Terror("ERROR (CM6::encode): illegal value");
// compute the exponent base 2
std::frexp (double(value), &case_expo);
......@@ -110,21 +112,21 @@ string encode(const intT& value)
// check value
if (case_expo > 5 || case_expo < 0)
throw GSE::Terror("ERROR (CM6::encode): illegal exponent");
throw Terror("ERROR (CM6::encode): illegal exponent");
for ( ; case_expo > 0; case_expo--)
{
// create one character per turn
jc = value/expo_2[case_expo] + nflag + mflag;
/*if (jc > 64 || jc < 1) return jc;*/
retval.append(achar[jc]);
retval+=achar[jc];
value = value & expo_2m1_o[case_expo];
nflag = 1;
}
// one character to go
jc = value + nflag;
retval.append(achar[jc]);
retval+=achar[jc];
return(retval);
}
......