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

improved SRCE and INFO reading

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: 1626
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 14867035
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.10 2005-01-17 14:48:09 tforb Exp $
# $Id: Makefile,v 1.11 2005-01-26 17:14:27 tforb Exp $
#
# Copyright (c) 2003 by Thomas Forbriger (BFO Schiltach)
#
......@@ -93,8 +93,9 @@ doxyview: doxyfullview doxybrief
# test code
# ---------
sfftest: sfftest.cc
sfftest: sfftest.cc all
$(CXX) -o $@ $< -I$(LOCINCLUDEDIR) -lsffxx -ltime++ -lgsexx -laff \
-ltfxx \
-L$(LOCLIBDIR) $(CXXFLAGS) $(FLAGS)
tests: sfftest; $<; rm -fv $<
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sfftest.cc,v 1.6 2003-12-30 17:18:53 tforb Exp $
* $Id: sfftest.cc,v 1.7 2005-01-26 17:14:27 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -19,7 +19,7 @@
#define SFFTEST_VERSION \
"SFFTEST V1.0 test library modules"
#define SFFTEST_CVSID \
"$Id: sfftest.cc,v 1.6 2003-12-30 17:18:53 tforb Exp $"
"$Id: sfftest.cc,v 1.7 2005-01-26 17:14:27 tforb Exp $"
#include <fstream>
#include <iostream>
......@@ -215,7 +215,7 @@ void test_write_file()
/*----------------------------------------------------------------------*/
void test_read_file()
void test_read_file(const bool& debug)
{
char infile[]="junk.sff";
char outfile[]="junk2.sff";
......@@ -235,6 +235,10 @@ void test_read_file()
std::ofstream os(outfile);
os << fhd;
if (fhd.hasfree())
{
cout << "FREE: " << std::endl << fhd.free() << endl;
}
if (fhd.hassrce())
{
cout << "SRCEtime: " << fhd.srce().date.timestring() << endl;
......@@ -243,7 +247,7 @@ void test_read_file()
bool last=false;
while (!last)
{
sff::InputWaveform<Tseries> iwf;
sff::InputWaveform<Tseries> iwf(debug);
try {
is >> iwf;
} catch (GSE2::Terror) {
......@@ -314,13 +318,65 @@ void test_skip_trace()
/*----------------------------------------------------------------------*/
struct Options {
bool debug;
}; // struct Options
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
"usage: sfftest -D" "\n"
" or: sfftest --help|-h" "\n"
};
// define full help text
char help_text[]=
{
"-D produce debug output" "\n"
"notice: you have to pass at least one dummy argument to make" "\n"
"the program run" "\n"
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: debug mode
{"D",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.debug=cmdline.optset(1);
test_line_functions(); cout << endl;
test_write_wrappers(); cout << endl;
test_waveform_normalizer(); cout << endl;
test_write_file(); cout << endl;
test_read_file(); cout << endl;
test_read_file(opt.debug); cout << endl;
test_skip_trace(); cout << endl;
}
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.cc,v 1.12 2004-12-23 11:59:29 tforb Exp $
* $Id: sffxx.cc,v 1.13 2005-01-26 17:14:27 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -19,13 +19,14 @@
* - provide debug output
* - correct reading of FREE block
* - 23/12/2004 V1.3 added full block append to FREE
* - 26/01/2004 V1.4 SRCE reading and INFO reading was not satisfactory
*
* ============================================================================
*/
#define TF_SFFXX_CC_VERSION \
"TF_SFFXX_CC V1.3"
"TF_SFFXX_CC V1.4"
#define TF_SFFXX_CC_CVSID \
"$Id: sffxx.cc,v 1.12 2004-12-23 11:59:29 tforb Exp $"
"$Id: sffxx.cc,v 1.13 2005-01-26 17:14:27 tforb Exp $"
#include<sstream>
#include <sffxx.h>
......@@ -117,12 +118,9 @@ namespace sff {
void STAT::read(std::istream& fis)
{
std::string theline("");
const int bufsize=81;
char inputline[bufsize];
fis.getline(inputline,bufsize);
theline=inputline;
std::istringstream is(inputline);
std::string theline;
std::getline(fis, theline);
std::istringstream is(theline);
std::string lineID;
is >> lineID;
if (!helper::IDmatch<STAT>(lineID)) throw
......@@ -169,8 +167,11 @@ namespace sff {
return(retval);
} // SRCE::line()
void SRCE::read(std::istream& is)
void SRCE::read(std::istream& fis)
{
std::string theline;
std::getline(fis, theline);
std::istringstream is(theline);
std::string lineID;
is >> lineID;
if (!helper::IDmatch<SRCE>(lineID)) throw
......@@ -230,14 +231,17 @@ namespace sff {
void DAST::read(std::istream& fis, const bool& debug)
{
std::string theline("");
const int bufsize=81;
char inputline[bufsize];
fis.getline(inputline,bufsize);
theline=inputline;
std::istringstream is(inputline);
if (debug)
{
std::cerr << "DEBUG (DAST::read):" << std::endl;
}
std::string theline;
std::getline(fis, theline);
std::istringstream is(theline);
if (debug) { std::cerr << theline << std::endl; }
std::string lineID;
is >> lineID;
if (debug) { std::cerr << lineID << std::endl; }
if (!helper::IDmatch<DAST>(lineID)) throw
GSE2::Terror("ERROR (DAST::read): missing DAST ID!");
is >> nchar;
......@@ -371,8 +375,11 @@ namespace sff {
return(retval);
} // INFO::line()
void INFO::read(std::istream& is)
void INFO::read(std::istream& fis)
{
std::string theline;
std::getline(fis, theline);
std::istringstream is(theline);
std::string lineID;
is >> lineID;
if (!helper::IDmatch<INFO>(lineID)) throw
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.h,v 1.20 2005-01-17 14:48:10 tforb Exp $
* $Id: sffxx.h,v 1.21 2005-01-26 17:14:27 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -30,7 +30,7 @@
#define TF_SFFXX_H_VERSION \
"TF_SFFXX_H V1.3"
#define TF_SFFXX_H_CVSID \
"$Id: sffxx.h,v 1.20 2005-01-17 14:48:10 tforb Exp $"
"$Id: sffxx.h,v 1.21 2005-01-26 17:14:27 tforb Exp $"
#include<string>
#include<cmath>
......@@ -38,6 +38,7 @@
#include<iostream>
#include<libtime++.h>
#include<aff/iterator.h>
#include<tfxx/commandline.h>
#include<gsexx.h>
/*! \brief all SFF modules
......@@ -287,7 +288,8 @@ namespace sff {
class InputWaveform {
public:
typedef C Tcontainer;
InputWaveform(): Mvalid(false) { }
InputWaveform(const bool& debug=false):
Mvalid(false), Mdebug(debug) { }
InputWaveform(std::istream& is, const bool& debug=false):
Mdebug(debug) { this->read(is); }
void read(std::istream& is);
......@@ -400,6 +402,12 @@ namespace sff {
void InputWaveform<C>::read(std::istream& is)
{
typedef typename C::Tvalue Tvalue;
if (Mdebug)
{
std::cerr << "DEBUG (InputWaveform<C>::read): " << std::endl
<< " calling function readheader() of member Mheader."
<< std::endl;
}
Mheader.setdebug(Mdebug);
Mheader.readheader(is);
int nsamples=Mheader.wid2().nsamples;
......
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