Commit 83526e66 authored by Daniel Armbruster's avatar Daniel Armbruster 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/branches/libdatreadxx.tfascii
SVN Revision: 3261
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 0fcf42b4
......@@ -211,7 +211,7 @@ PACKAGE=libdatreadxx
# test code
# ---------
sactest hpmotest mseedtest pdastest \
sactest hpmotest mseedtest pdastest tfasciitest\
tsofttest sfftest: %: tests/%.o libdatreadxx.a
$(CXX) $(FLAGS) -o $@ $< -I$(LOCINCLUDEDIR) \
-ldatreadxx -lsffxx -lgsexx -ltsxx -ltfxx -laff -ltime++ \
......
/*! \file tfasciitest.cc
* \brief
* \brief test tfascii reading
*
* ----------------------------------------------------------------------------
*
......@@ -7,7 +7,7 @@
* \author Daniel Armbruster
* \date 14/10/2010
*
* Purpose:
* Purpose: test tfascii reading
*
* ----
* This file is part of libdatreadxx.
......@@ -33,7 +33,131 @@
*
* ============================================================================
*/
#define TFASCIITEST_VERSION \
"TFASCIITEST V1.0 test tfascii reading"
#define TFASCIITEST_CVSID \
"$Id: $"
#include <iostream>
#include <fstream>
#include <tfxx/commandline.h>
#include <datreadxx/error.h>
#include <datreadxx/tfascii.h>
#include <datreadxx/readany.h>
using std::cout;
using std::cerr;
using std::endl;
/* ----- END OF tfasciitest.cc ----- */
\ No newline at end of file
struct Options {
bool verbose, stage1, stage2, stage3, skip;
}; // struct Options
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
TFASCIITEST_VERSION "\n"
"usage: tfasciitest [-v] [-s1] [-s2] filename" "\n"
" or: tfasciitest --help" "\n"
};
// define full help text
char help_text[]=
{
TFASCIITEST_CVSID
"filename file to read" "\n"
"-v be verbose" "\n"
"-s1 test reading functions of stage 1" "\n"
"-s2 test reading functions of stage 2" "\n"
"-s3 test reading functions of stage 3" "\n"
"-skip test skip series" "\n"
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: test stage 1
{"s1",arg_no,"-"},
// 3: test stage 2
{"s2",arg_no,"-"},
// 4: test stage 3
{"s3",arg_no,"-"},
// 5: test stage 4
{"skip",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);
}
Options opt;
opt.verbose=cmdline.optset(1);
opt.stage1=cmdline.optset(2);
opt.stage2=cmdline.optset(3);
opt.stage3=cmdline.optset(4);
opt.skip=cmdline.optset(5);
DATREAD_assert(cmdline.extra(), "missing filename!");
/*----------------------------------------------------------------------*/
if (opt.stage1)
{
if (opt.verbose)
{
cout << endl << "TEST: stage 1" << endl
<< "=============" << endl;
}
while (cmdline.extra())
{
std::string infile=cmdline.next();
if (opt.verbose) { cout << "reading file " << infile << endl; }
std::ifstream ifs(infile.c_str());
DATREAD_assert(ifs.good(), "invalid file!");
datread::itfasciistream is(ifs);
//datread::Tdseries dseries;
if (opt.skip)
{
is.skipseries();
}
else
{
//is >> dseries;
}
if (opt.verbose)
{
// print header
cout << is.srce().line() << endl;
cout << is.wid2().line() << endl;
cout << is.info().line() << endl;
// print series
}
}
}
}
/* ----- END OF tfasciitest.cc ----- */
......@@ -89,8 +89,8 @@ namespace datread {
static void help(std::ostream& os=std::cout)
{ Tbase::help(os, const_cast<char*>("itfasciistream")); }
private:
//! pointer to a tfascii trace
datread::tfascii::TfasciiContainer *tfasciitrace;
//! tfascii trace container
datread::tfascii::TfasciiContainer Mtfasciitrace;
//! set the header data
void set_header();
}; // class itfasciistream
......
......@@ -46,9 +46,9 @@
"$Id: readtfascii.h 3242 2010-10-12 03:36:59Z damb $"
#include<iostream>
#include<utility>
#include<string>
#include<sffxx.h>
#include<aff/series.h>
#include<datreadxx/util.h>
namespace datread {
......@@ -57,13 +57,12 @@ namespace datread {
* \defgroup tfascii Read file format defined by T. Forbriger
*/
/*! \brief all functions, classes, etc. to read T. Forbriger data format
/*! \brief all functions, classes, etc. to read T. Forbrigers data format
* \brief of any2ascii.cc
*
* \ingroup tfascii
*/
namespace tfascii {
//! we read the data to a vector
typedef aff::Series<double> Tseries;
struct Header {
bool hastracefree, hasfilefree, hasinfo, hassrce, haswid2;
......@@ -87,22 +86,18 @@ namespace datread {
\return header of this trace
*/
tfascii::Header get_header(std::istream& is);
//! member function
//! member function to return the series
/*!
\param is the input stream
\return the trace
*/
template<class T> T get_series(std::istream& is);
template<class C> C get_series(std::istream& is);
private:
datread::tfascii::Header *Mheader;
datread::tfascii::Header Mheader;
//! if the header was readed from the file
bool Mheaderset;
//! detect SFF blocks
/*!
\param is the input stream
\param verbose for verbose output or not
*/
void detectblocks(std::istream& is, const bool& verbose = false);
//! name of the stream
std::string Mtitle;
//! split given string
/*!
This function will split a line after the following scheme:\n
......@@ -114,6 +109,11 @@ namespace datread {
\param unit if a value has a unit or not
*/
void extractvalue(std::string& line, bool unit = false);
//! split given string whitch contains a time value
/*!
\param line string which contains time value
*/
void extracttime(std::string& line);
//! read the complete trace header
/*!
\param is the input stream
......@@ -121,11 +121,24 @@ namespace datread {
*/
void readheader(std::istream& is, const bool& verbose = false);
};
// template is placed here because of linker problem
template<class C>
C TfasciiContainer::get_series(std::istream& is) {
if(Mheaderset) {
return datread::util::readany<C>(is, Mheader.wid2.nsamples, Mtitle);
}
else
{
throw datread::Exception("First read the header data!");
}
}
} // namespace tfascii
} // namespace datread
#endif // DATREAD_READTFASCII_H_VERSION (includeguard)
......
......@@ -40,18 +40,17 @@
"$Id: tfascii.cc 3242 2010-10-12 03:36:59Z damb $"
#include <datreadxx/tfascii.h>
#include<datreadxx/error.h>
namespace datread {
// constructor
itfasciistream::itfasciistream(std::istream& is): Tbase(is, true, true, true)
{
tfasciitrace = new datread::tfascii::TfasciiContainer();
}
// destructor
itfasciistream::~itfasciistream()
{
delete tfasciitrace;
}
// put this stuff into the datread::tfascii::Trace class
......@@ -63,26 +62,26 @@ namespace datread {
Tdseries itfasciistream::dseries() {
set_header();
return(tfasciitrace->get_series<Tdseries>(Mis));
return Mtfasciitrace.get_series<Tdseries>(Mis);
}
Tfseries itfasciistream::fseries() {
set_header();
return(tfasciitrace->get_series<Tfseries>(Mis));
return Mtfasciitrace.get_series<Tfseries>(Mis);
}
Tiseries itfasciistream::iseries() {
set_header();
return(tfasciitrace->get_series<Tiseries>(Mis));
return(Mtfasciitrace.get_series<Tiseries>(Mis));
}
/*----------------------------------------------------------------------*/
// private functions
void itfasciistream::set_header() {
datread::tfascii::Header header = tfasciitrace->get_header(Mis);
datread::tfascii::Header header = Mtfasciitrace.get_header(Mis);
this->newtrace();
this->setlast();
this->setwid2(header.wid2);
......
......@@ -34,6 +34,7 @@
*/
#include<iostream>
#include<string>
#include<datreadxx/error.h>
// include guard
......@@ -71,19 +72,20 @@ namespace datread {
/*!
\param is the input stream
\param nsamples the number of samples
\param streamname name of the stream for Exceptions
\return the trace
*/
template<class T>
T readany(std::istream& is, const int nsamples)
template<class C>
C readany(std::istream& is, const int nsamples, const std::string& streamname)
{
T series(nsamples);
C series(nsamples);
double inval;
std::string errorstr = "ERROR ("+streamname+"::?series): bad stream!";
for (int i = 0; i < nsamples; ++i)
{
DATREAD_assert(is.good(),"ERROR (itfasciistream::?series): "
"bad stream!");
DATREAD_assert(is.good(), errorstr.c_str());
is >> inval;
series(i) = typename T::Tvalue(inval);
series(i) = typename C::Tvalue(inval);
}
return series;
}
......
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