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

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: 1595
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 697010af
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.13 2004-12-21 09:34:05 tforb Exp $
# $Id: Makefile,v 1.14 2004-12-21 17:51:29 tforb Exp $
#
# Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
#
......@@ -147,7 +147,7 @@ doxyview: doxyfullview doxybrief
# test code
# ---------
mseedtest pdastest: %: tests/%.o libdatreadxx.a
hpmotest mseedtest pdastest: %: tests/%.o libdatreadxx.a
$(CXX) -o $@ $< -I$(LOCINCLUDEDIR) \
-ldatreadxx -lsffxx -lgsexx -ltsxx -ltfxx -laff -ltime++ \
-L$(LOCLIBDIR)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: readhpmo.cc,v 1.4 2004-12-21 09:34:05 tforb Exp $
* $Id: readhpmo.cc,v 1.5 2004-12-21 17:51:30 tforb Exp $
* \author Thomas Forbriger
* \date 31/03/2004
*
......@@ -19,9 +19,11 @@
#define DATREAD_READHPMO_CC_VERSION \
"DATREAD_READHPMO_CC V1.0 "
#define DATREAD_READHPMO_CC_CVSID \
"$Id: readhpmo.cc,v 1.4 2004-12-21 09:34:05 tforb Exp $"
"$Id: readhpmo.cc,v 1.5 2004-12-21 17:51:30 tforb Exp $"
#include <datreadxx/error.h>
#include <datreadxx/readhpmo.h>
#include<iostream>
namespace datread {
......@@ -30,10 +32,127 @@ namespace datread {
void Header::readheader(std::istream& is, const bool& verbose)
{
std::getline(is, this->Mline);
if (Mline.length() != 45) { throw NoHeaderException(); }
if (verbose) { std::cout << Mline << std::endl; }
std::string secstring=Mline.substr(17,2);
DATREAD_assert((secstring=="57"), "illegal second!");
std::string timestring;
timestring=Mline.substr.
const std::string sep("/");
timestring=Mline.substr(6,4)+sep+Mline.substr(0,2)+sep+
Mline.substr(3,2)+sep+Mline.substr(11,8);
if (verbose) { std::cout << timestring << std::endl; }
Mtime=libtime::TAbsoluteTime(timestring);
if (verbose) { std::cout << Mtime.timestring() << std::endl; }
std::string timezone=Mline.substr(23,3);
if (verbose) { std::cout << timezone << std::endl; }
DATREAD_assert((timezone == std::string("UTC")),
"unexpected time code string!");
std::string errorcode=Mline.substr(34,1);
if (verbose) { std::cout << errorcode << std::endl; }
Merrorflag=atoi(errorcode.c_str());
if (verbose) { std::cout << Merrorflag << std::endl; }
} // Header::readheader(std::istream& is)
/*----------------------------------------------------------------------*/
std::string Header::errorstring() const
{
std::string retval;
if (Merrorflag == 0) { retval=std::string("OK"); }
if (Merrorflag == 1) { retval=std::string("bad DCF reception"); }
if (Merrorflag == 2) { retval=std::string("dummy block (2.999999 V)"); }
if (Merrorflag == 3) { retval=std::string("bad DCF reception and ")+
retval=std::string("dummy block (2.999999 V)"); }
if (Merrorflag == 4) { retval=std::string("RS-232 error"); }
if (Merrorflag == 8) { retval=std::string("possibly error in PC clock"); }
if (Merrorflag == 16) { retval=std::string("invalid header"); }
return(retval);
} // std::string Header::errorstring() const
/*----------------------------------------------------------------------*/
void Header::dump(std::ostream& os) const
{
os << "Header: " << this->headerline() << std::endl;
os << " " << this->time().timestring() << std::endl;
os << " Error flag: " << this->errorstring() << std::endl;
} // void Header::dump(std::ostream& os) const
/*----------------------------------------------------------------------*/
static libtime::TRelativeTime dt()
{
return(libtime::double2time(5.));
} // static libtime::TRelativeTime dt() const
/*----------------------------------------------------------------------*/
static libtime::TRelativeTime toffset(const int& ichannel)
{
double delay=(ichannel-1)*0.06;
delay += 0.01;
if (ichannel==1) { delay += 0.04; }
else { delay += 0.41e-3; }
return(libtime::double2time(delay));
} // static libtime::TRelativeTime toffset(const int& ichannel) const
/*======================================================================*/
Samples::Samples()
{
int ninsamples=nsamples*nchannels;
for (int i=0; i<ninsamples; i++) { Msamples[i]=0.; }
} // Samples::Samples()
/*----------------------------------------------------------------------*/
void Samples::readsamples(std::istream& is, const bool& verbose)
{
int ninsamples=nsamples*nchannels;
for (int i=0; i<ninsamples; i++)
{
is >> Msamples[i];
DATREAD_assert(is.good(), "ERROR: reading samples!");
}
std::string dummy;
std::getline(is, dummy);
} // void Samples::readsamples(std::istream& is, const bool& verbose)
/*----------------------------------------------------------------------*/
void Samples::dump(std::ostream& os) const
{
for (int ic=1; ic<=datread::hpmo::nchannels; ic++)
{
os.width(1);
os << "K";
os.setf(std::ios_base::fixed,std::ios_base::basefield);
os.width(2);
os.fill('0');
os << ic << " ";
for (int is=1; is<=datread::hpmo::nsamples/2; is++)
{
os.flags(std::ios_base::showpos);
os.setf(std::ios_base::fixed,std::ios_base::floatfield);
os.width(6);
os << this->value(ic, is) << " ";
}
os.width(4);
os << std::endl << " ";
for (int is=datread::hpmo::nsamples/2+1;
is<=datread::hpmo::nsamples; is++)
{
os.flags(std::ios_base::showpos);
os.setf(std::ios_base::fixed,std::ios_base::floatfield);
os.width(6);
os << this->value(ic, is) << " ";
}
os.unsetf(std::ios_base::showpos);
os << std::endl;
}
} // void Samples::dump(std::ostream& os) const
} // namespace hpmo
} // namespace datread
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: readhpmo.h,v 1.5 2004-12-21 09:34:05 tforb Exp $
* $Id: readhpmo.h,v 1.6 2004-12-21 17:51:30 tforb Exp $
* \author Thomas Forbriger
* \date 31/03/2004
*
......@@ -23,7 +23,7 @@
#define DATREAD_READHPMO_H_VERSION \
"DATREAD_READHPMO_H V1.0 "
#define DATREAD_READHPMO_H_CVSID \
"$Id: readhpmo.h,v 1.5 2004-12-21 09:34:05 tforb Exp $"
"$Id: readhpmo.h,v 1.6 2004-12-21 17:51:30 tforb Exp $"
#include<iostream>
#include<string>
......@@ -33,23 +33,60 @@ namespace datread {
namespace hpmo {
class NoHeaderException: public datread::Exception {
public:
NoHeaderException(): Exception("no header found!") { }
}; // class NoHeaderException
/*----------------------------------------------------------------------*/
class Header {
public:
Header(): Merrorflag(16) { }
Header(std::istream& is, const bool& verbose)
{ this->readheader(is, verbose); }
void readheader(std::istream& is, const bool& verbose);
void readheader(std::istream& is, const bool& verbose=false);
libtime::TAbsoluteTime time() const { return(Mtime); }
int errorflag() const { return(Merrorflag); }
std::string errorstring() const;
std::string headerline() const { return (Mline); }
void dump(std::ostream& os) const;
public:
static libtime::TRelativeTime dt();
static libtime::TRelativeTime toffset(const int& ichannel);
private:
libtime::TAbsoluteTime Mtime;
int Merrorflag;
std::string Mline;
}; // struct Header
}; // class Header
/*----------------------------------------------------------------------*/
const int nsamples=12;
const int nchannels=20;
class Samples {
public:
Samples();
Samples(std::istream& is, const bool& verbose)
{ this->readsamples(is, verbose); }
void readsamples(std::istream& is, const bool& verbose=false);
double value(const int& ichannel, const int& isample) const
{ return(Msamples[nchannels*(isample-1)+(ichannel-1)]); }
double operator() (const int& ichannel, const int& isample) const
{ return(value(ichannel, isample)); }
void dump(std::ostream& os) const;
private:
double Msamples[nsamples*nchannels];
}; // class Samples
/*----------------------------------------------------------------------*/
inline std::istream& operator >> (std::istream& is, Header& hd)
{ hd.readheader(is); return(is); }
std::istream& operator >> (std::istream& is, Header& hd)
{ hd.readheader(is); }
inline std::istream& operator >> (std::istream& is, Samples& data)
{ data.readsamples(is); return(is); }
} // namespace hpmo
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: hpmotest.cc,v 1.2 2004-12-21 09:34:06 tforb Exp $
* $Id: hpmotest.cc,v 1.3 2004-12-21 17:51:30 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2004
*
......@@ -19,13 +19,13 @@
#define HPMOTEST_VERSION \
"HPMOTEST V1.0 test hpmo reading functions"
#define HPMOTEST_CVSID \
"$Id: hpmotest.cc,v 1.2 2004-12-21 09:34:06 tforb Exp $"
"$Id: hpmotest.cc,v 1.3 2004-12-21 17:51:30 tforb Exp $"
#include <fstream>
#include <iostream>
#include <tfxx/commandline.h>
#include <datreadxx/error.h>
#include <datreadxx/hpmoread.h>
#include <datreadxx/readhpmo.h>
#include <datreadxx/hpmo.h>
using std::cout;
......@@ -108,7 +108,35 @@ int main(int iargc, char* argv[])
Options opt;
opt.verbose=cmdline.optset(1);
DATREAD_assert(cmdline.extra(), "missing filename!");
std::string infile=cmdline.next();
if (opt.verbose) { cout << "reading file " << infile; }
std::ifstream ifs(infile.c_str());
DATREAD_assert(ifs.good(), "invalid file!");
datread::hpmo::Header header;
datread::hpmo::Samples samples;
bool hot=true;
while (ifs.good() && hot)
{
try {
ifs >> header;
} catch (datread::hpmo::NoHeaderException)
{
cout << "End of file!" << endl;
hot=false;
}
if (hot)
{
if (opt.verbose) { header.dump(cout); }
if (ifs.good())
{
ifs >> samples;
if (opt.verbose) { samples.dump(cout); }
}
}
}
}
/* ----- END OF hpmotest.cc ----- */
Supports Markdown
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