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

structs have compiling reading code

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: 1430
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent f9b7b012
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.cc,v 1.5 2003-12-23 15:47:22 tforb Exp $
* $Id: sffxx.cc,v 1.6 2003-12-23 16:37:29 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -19,13 +19,20 @@
#define TF_SFFXX_CC_VERSION \
"TF_SFFXX_CC V1.0 "
#define TF_SFFXX_CC_CVSID \
"$Id: sffxx.cc,v 1.5 2003-12-23 15:47:22 tforb Exp $"
"$Id: sffxx.cc,v 1.6 2003-12-23 16:37:29 tforb Exp $"
#include <sffxx.h>
#include <gsexx.h>
namespace sff {
namespace helper {
//! Check GSE identifier at beginning of line.
template<class C>
bool IDmatch(const std::string& line)
{ return(line.substr(0,4)==std::string(C::LINEID)); }
} // namespace helper
//! Fortran library version (to ensure compatibility)
const double STAT::libversion=1.10;
const char* const STAT::LINEID="STAT";
......@@ -94,6 +101,29 @@ namespace sff {
return(retval);
} // STAT::line()
void STAT::read(std::istream& is)
{
std::string lineID;
is >> lineID;
if (!helper::IDmatch<STAT>(lineID)) throw
GSE2::Terror("ERROR (STAT::read): missing STAT ID!");
double inlibversion;
is >> inlibversion;
if (inlibversion>STAT::libversion)
{
throw
GSE2::Terror("ERROR (STAT::read): file library version too large!");
}
is >> timestamp;
std::string code;
is >> code;
this->hasfree=(code.find('F')!=std::string::npos);
this->hassrce=(code.find('S')!=std::string::npos);
} // STAT::read
/*----------------------------------------------------------------------*/
// SRCE
// ----
......@@ -119,6 +149,42 @@ namespace sff {
return(retval);
} // SRCE::line()
void SRCE::read(std::istream& is)
{
std::string lineID;
is >> lineID;
if (!helper::IDmatch<SRCE>(lineID)) throw
GSE2::Terror("ERROR (SRCE::read): missing SRCE ID!");
char intype[21];
is.get(intype, 21);
type=intype;
char cschar;
is >> cschar;
cs=coosysID(cschar);
is >> cx;
is >> cy;
is >> cz;
std::string datestring,timestring;
is >> datestring;
is >> timestring;
std::string fulldate("");
fulldate+=datestring.substr(0,1);
fulldate+="/";
fulldate+=datestring.substr(2,3);
fulldate+="/";
fulldate+=datestring.substr(4,5);
fulldate+=" ";
fulldate+=timestring.substr(0,1);
fulldate+=":";
fulldate+=timestring.substr(2,3);
fulldate+=":";
fulldate+=timestring.substr(4,9);
date=libtime::TAbsoluteTime(fulldate);
} // SRCE::read
/*----------------------------------------------------------------------*/
// DAST
// ----
......@@ -141,6 +207,21 @@ namespace sff {
return(retval);
} // DAST::line()
void DAST::read(std::istream& is)
{
std::string lineID;
is >> lineID;
if (!helper::IDmatch<DAST>(lineID)) throw
GSE2::Terror("ERROR (DAST::read): missing DAST ID!");
is >> nchar;
is >> ampfac;
std::string code;
is >> code;
this->hasinfo=(code.find('I')!=std::string::npos);
this->hasfree=(code.find('F')!=std::string::npos);
this->last=(code.find('D')==std::string::npos);
} // DAST::read
/*----------------------------------------------------------------------*/
// FREE
// ----
......@@ -156,6 +237,26 @@ namespace sff {
os << FREE::LINEID << " " << std::endl;
} // FREE::write
void FREE::read(std::istream& is)
{
std::string lineID;
is >> lineID;
if (!helper::IDmatch<DAST>(lineID)) throw
GSE2::Terror("ERROR (DAST::read): missing DAST ID!");
lines.clear();
std::string theline("");
const int bufsize=81;
char inputline[bufsize];
is.getline(inputline,bufsize);
theline=inputline;
while (!helper::IDmatch<DAST>(theline))
{
lines.push_back(theline);
is.getline(inputline,bufsize);
theline=inputline;
}
} // FREE::read
/*----------------------------------------------------------------------*/
// WID2
// ----
......@@ -188,6 +289,30 @@ namespace sff {
return(wid2line.line());
} // WID2::line()
void WID2::read(std::istream& is)
{
GSE2::waveform::TWID2 wid2line;
wid2line.read(is);
int second=int(wid2line.Fseconds);
int milsec=int(1000*(wid2line.Fseconds-double(second)));
date=libtime::TAbsoluteTime(wid2line.Fyear,
wid2line.Fmonth,
wid2line.Fday,
wid2line.Fhour,
wid2line.Fminute,
second, milsec);
this->station=wid2line.Fstation;
this->channel=wid2line.Fchannel;
this->auxid=wid2line.Fauxid;
this->nsamples=wid2line.Fsamps;
this->dt=1./wid2line.Fsamprate;
this->calib=wid2line.Fcalib;
this->calper=wid2line.Fcalper;
this->instype=wid2line.Finstype;
this->hang=wid2line.Fhang;
this->vang=wid2line.Fvang;
} // WID2::read
/*----------------------------------------------------------------------*/
// INFO
// ----
......@@ -205,6 +330,21 @@ namespace sff {
return(retval);
} // INFO::line()
void INFO::read(std::istream& is)
{
std::string lineID;
is >> lineID;
if (!helper::IDmatch<DAST>(lineID)) throw
GSE2::Terror("ERROR (DAST::read): missing DAST ID!");
char cschar;
is >> cschar;
cs=coosysID(cschar);
is >> cx;
is >> cy;
is >> cz;
is >> nstacks;
} // INFO::read
/*----------------------------------------------------------------------*/
// FileHeader
// ----------
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.h,v 1.5 2003-12-23 15:47:23 tforb Exp $
* $Id: sffxx.h,v 1.6 2003-12-23 16:37:29 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -13,6 +13,9 @@
*
* REVISIONS and CHANGES
* - 21/12/2003 V1.0 Thomas Forbriger
* - 23/12/2003 V1.1
* - first version writing SFF successfully
* - starting with reading code
*
* ============================================================================
*/
......@@ -21,9 +24,9 @@
#ifndef TF_SFFXX_H_VERSION
#define TF_SFFXX_H_VERSION \
"TF_SFFXX_H V1.0 "
"TF_SFFXX_H V1.1 "
#define TF_SFFXX_H_CVSID \
"$Id: sffxx.h,v 1.5 2003-12-23 15:47:23 tforb Exp $"
"$Id: sffxx.h,v 1.6 2003-12-23 16:37:29 tforb Exp $"
#include<string>
#include<list>
......@@ -65,7 +68,9 @@ namespace sff {
static const double libversion;
static const char* const LINEID;
STAT();
STAT(std::istream& is) { read(is); }
std::string line() const;
void read(std::istream& is);
void setstamp(const libtime::TAbsoluteTime& date) const;
public:
mutable std::string timestamp;
......@@ -77,14 +82,18 @@ namespace sff {
typedef std::list<std::string> Tlines;
static const char* const LINEID;
FREE();
FREE(std::istream& is) { read(is); }
void write(std::ostream& os) const;
void read(std::istream& is);
Tlines lines;
}; // struct FREE
struct SRCE {
static const char* const LINEID;
SRCE();
SRCE(std::istream& is) { read(is); }
std::string line() const;
void read(std::istream& is);
public:
std::string type;
libtime::TAbsoluteTime date; //!< time of source
......@@ -95,7 +104,9 @@ namespace sff {
struct DAST {
static const char* const LINEID;
DAST();
DAST(std::istream& is) { read(is); }
std::string line() const;
void read(std::istream& is);
public:
int nchar;
double ampfac;
......@@ -107,7 +118,9 @@ namespace sff {
struct INFO {
static const char* const LINEID;
INFO();
INFO(std::istream& is) { read(is); }
std::string line() const;
void read(std::istream& is);
public:
Ecoosys cs;
double cx, cy, cz;
......@@ -119,7 +132,9 @@ namespace sff {
*/
struct WID2 {
WID2();
WID2(std::istream& is) { read(is); }
std::string line() const;
void read(std::istream& is);
public:
libtime::TAbsoluteTime date; //!< time of first sample
std::string station; //!< Station code
......@@ -151,7 +166,9 @@ namespace sff {
FileHeader(const SRCE& srce, const FREE& free):
Mfree(free), Msrce(srce)
{ Mstat.hasfree=true; Mstat.hassrce=true; }
FileHeader(std::istream& is) { read(is); }
void write(std::ostream&) const;
void read(std::istream&);
private:
STAT Mstat;
FREE Mfree;
......@@ -231,7 +248,7 @@ namespace sff {
// -------------
inline std::istream& operator >> (std::istream& is, FileHeader& fh)
{ return(is); }
{ fh.read(is); return(is); }
inline std::istream& operator >> (std::istream& is, TraceHeader& th)
{ return(is); }
inline std::istream& operator >> (std::istream& is, InputWaveform& wf)
......
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