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

still debugging SU 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.
open issues: delrt is negative, any2sff ignores SRCE, isustream prints
exception at last trace


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/branches/libdatrwxx.su
SVN Revision: 3472
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent ddbfd8ae
......@@ -121,7 +121,7 @@ namespace datrw {
else if (Mformat==Fgse) { Mis=new igsestream(is); }
else if (Mformat==Ftsoft) { Mis=new itsoftstream(is); }
else if (Mformat==Ftfascii) { Mis=new itfasciistream(is); }
else if (Mformat==Fsu) { Mis=new isustream(is); }
else if (Mformat==Fsu) { Mis=new isustream(is, debug); }
else
{ DATRW_abort("ERROR (ianystream): unknown format!"); }
}
......
......@@ -40,6 +40,7 @@
#include <datrwxx/su.h>
#include <datrwxx/util.h>
#include <datrwxx/error.h>
#include <datrwxx/debug.h>
namespace datrw {
......@@ -57,12 +58,14 @@ namespace datrw {
/*----------------------------------------------------------------------*/
isustream::isustream(std::istream& is, const bool& debug):
Tbase(is, true, true, false), Mdebug(debug)
Tbase(is, true, true, false), Mdebug(debug), Mnextheader(debug)
{
DATRW_debug(Mdebug, "isustream::isustream","entering constructor");
DATRW_assert(is.good(),
"ERROR (isustream::isustream): input stream is bad");
Mnextheader.read(is);
this->setsrce(Mnextheader.srce());
DATRW_debug(Mdebug, "isustream::isustream", "finished constructor");
}
/*----------------------------------------------------------------------*/
......@@ -76,13 +79,21 @@ namespace datrw {
Tfseries isustream::fseries()
{
DATRW_debug(Mdebug, "isustream::fseries","entering function");
Tfseries series(Mnextheader.Mheader.ns);
this->readheader();
char *ipointer=reinterpret_cast<char *>(series.pointer());
DATRW_Xassert(Mis.read(ipointer, series.size()*sizeof(float)),
"ERROR (isustream::fseries): reading SU samples",
::datrw::su::SUReadException);
return(Tfseries(0));
DATRW_debug(Mdebug, "isustream::fseries",
"read " << series.size() << " samples"
<< " which are " << (series.size()*sizeof(float))
<< " characters");
this->readheader();
DATRW_debug(Mdebug, "isustream::fseries",
this->wid2().line() << "\n" << this->info().line());
DATRW_debug(Mdebug, "isustream::fseries","leaving function");
return(series);
} // Tiseries isustream::fseries()
/*----------------------------------------------------------------------*/
......@@ -96,6 +107,7 @@ namespace datrw {
void isustream::readheader()
{
DATRW_debug(Mdebug, "isustream::readheader","entering function");
DATRW_assert(this->good(),
"ERROR (isustream::readheader): reached end of file");
this->newtrace();
......@@ -114,6 +126,7 @@ namespace datrw {
{
this->setlast();
}
DATRW_debug(Mdebug, "isustream::readheader","leave function");
} // void isustream::readheader()
/*----------------------------------------------------------------------*/
......
......@@ -39,6 +39,7 @@
#include <datrwxx/suheader.h>
#include <datrwxx/error.h>
#include <datrwxx/debug.h>
#include <cstring>
namespace datrw {
......@@ -54,6 +55,9 @@ namespace datrw {
DATRW_Xassert(is.read(ipointer, sizeof(TraceHeaderStruct)),
"ERROR (SUheader::read): reading SU header",
SUReadException);
DATRW_debug(Mdebug, "SUheader::read",
"some fields:\n"
"trid="<<Mheader.trid<<"\n");
} // void SUheader::read(std::istream& is)
/*----------------------------------------------------------------------*/
......@@ -68,7 +72,8 @@ namespace datrw {
/*----------------------------------------------------------------------*/
//! constructor
SUheader::SUheader()
SUheader::SUheader(const bool& debug)
: Mdebug(debug)
{
this->clear();
} // SUheader::SUheader()
......@@ -160,7 +165,7 @@ namespace datrw {
//! return recording delay
libtime::TRelativeTime SUheader::delay() const
{
return(libtime::double2time(static_cast<double>(1.e-3*Mheader.delrt)));
return(libtime::double2time(1.e-3*static_cast<double>(Mheader.delrt)));
} // libtime::TRelativeTime SUheader::delay() const
/*----------------------------------------------------------------------*/
......@@ -186,7 +191,7 @@ namespace datrw {
"ERROR (SUheader::srce): coordinate units not supported");
sff::SRCE retval;
double scalcof=this->scalcof();
retval.cs=sff::CS_cartesian;
retval.cs=::sff::CS_cartesian;
retval.cx=static_cast<double>(Mheader.sx)*scalcof;
retval.cy=static_cast<double>(Mheader.sy)*scalcof;
retval.cz=-static_cast<double>(Mheader.sdepth)*this->scalelf();
......@@ -203,11 +208,12 @@ namespace datrw {
"ERROR (SUheader::info): coordinate units not supported");
sff::INFO retval;
double scalcof=this->scalcof();
retval.cs=sff::CS_cartesian;
retval.cs=::sff::CS_cartesian;
retval.cx=static_cast<double>(Mheader.gx)*scalcof;
retval.cy=static_cast<double>(Mheader.gy)*scalcof;
retval.cz=-static_cast<double>(Mheader.gelev)*this->scalelf();
retval.nstacks=Mheader.nvs;
return(retval);
} // sff::INFO SUheader::info() const
/*----------------------------------------------------------------------*/
......
......@@ -82,7 +82,7 @@ namespace datrw {
class SUheader {
public:
//! constructor
SUheader();
SUheader(const bool& debug=false);
//! clear header struct
void clear();
//! set defaults to struct
......@@ -117,6 +117,9 @@ namespace datrw {
void set(const ::sff::WID2 &wid2);
//! set date
void set(const libtime::TAbsoluteTime &date);
private:
//! be verbose
bool Mdebug;
public:
//! the actual data fields are provided for public access
TraceHeaderStruct Mheader;
......
......@@ -22,13 +22,22 @@
"$Id$"
#include <iostream>
#include <fstream>
#include <tfxx/commandline.h>
#include <datrwxx/suheaderstruct.h>
#include <datrwxx/su.h>
using std::cout;
using std::cerr;
using std::endl;
struct Options {
bool verbose, debug, streamfile, scanfile;
std::string filename, sfilename;
}; // struct Options
/*----------------------------------------------------------------------*/
int main(int iargc, char* argv[])
{
......@@ -36,7 +45,7 @@ int main(int iargc, char* argv[])
char usage_text[]=
{
SUTEST_VERSION "\n"
"usage: sutest" "\n"
"usage: sutest [-v] [-D] [-file filename] [-stream filename]" "\n"
" or: sutest --help|-h" "\n"
};
......@@ -54,6 +63,12 @@ int main(int iargc, char* argv[])
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: debug mode
{"D",arg_no,"-"},
// 3: file to scan
{"file",arg_yes,"-"},
// 4: file to scan with stream
{"stream",arg_yes,"-"},
{NULL}
};
......@@ -75,30 +90,67 @@ int main(int iargc, char* argv[])
exit(0);
}
// dummy operation: print option settings
for (int iopt=0; iopt<2; iopt++)
Options opt;
opt.verbose=cmdline.optset(1);
opt.debug=cmdline.optset(2);
opt.scanfile=cmdline.optset(3);
opt.filename=cmdline.string_arg(3);
opt.streamfile=cmdline.optset(4);
opt.sfilename=cmdline.string_arg(4);
cout << "size of TraceHeaderStruct " <<
sizeof(datrw::su::TraceHeaderStruct) << endl;
/*----------------------------------------------------------------------*/
if (opt.scanfile)
{
cout << "option: '" << options[iopt].opt_string << "'" << endl;
if (cmdline.optset(iopt)) { cout << " option was set"; }
else { cout << "option was not set"; }
cout << endl;
cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
cout << " argument (bool): '";
if (cmdline.bool_arg(iopt))
{ cout << "true"; } else { cout << "false"; }
cout << "'" << endl;
std::ifstream ifs(opt.filename.c_str(),
datrw::isustream::openmode);
datrw::su::SUheader header(opt.debug);
bool hot=true;
while (hot)
{
try {
header.read(ifs);
cout << "trid: " << header.Mheader.trid << endl;
cout << "ns: " << header.Mheader.ns << endl;
cout << "delrt: " << header.Mheader.delrt << endl;
datrw::Tfseries series(header.Mheader.ns);
char *ipointer=reinterpret_cast<char *>(series.pointer());
DATRW_Xassert(ifs.read(ipointer, series.size()*sizeof(float)),
"ERROR: reading SU samples",
::datrw::su::SUReadException);
cout << "read " << series.size() << " samples"
<< " which are " << series.size()*sizeof(float)
<< " characters" << endl;
cout << header.wid2().line() << endl;
cout << "srce date: " << header.dateofshot().timestring() << endl;
cout << "delay: " << header.delay().timestring() << endl;
cout << "time of data: " << header.dateoffirstsample().timestring() << endl;
cout << header.info().line() << endl;
cout << header.srce().line() << endl;
}
catch (...)
{
hot=false;
cout << "CAUGHT EXCEPTION" << endl;
}
}
}
while (cmdline.extra()) { cout << cmdline.next() << endl; }
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }
/*----------------------------------------------------------------------*/
cout << "size of TraceHeaderStruct " <<
sizeof(datrw::su::TraceHeaderStruct) << endl;
if (opt.streamfile)
{
std::ifstream ifs(opt.sfilename.c_str(),
datrw::isustream::openmode);
datrw::isustream is(ifs, opt.debug);
while (is.good())
{
is.skipseries();
}
}
}
/* ----- END OF sutest.cc ----- */
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