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

new features

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: 2149
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent e53c1531
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: error.cc,v 1.2 2006-03-28 16:07:41 tforb Exp $
* $Id: error.cc,v 1.3 2006-07-07 09:20:43 tforb Exp $
* \author Thomas Forbriger
* \date 30/03/2004
*
......@@ -29,13 +29,14 @@
*
* REVISIONS and CHANGES
* - 30/03/2004 V1.0 Thomas Forbriger
* - 07/07/2006 V1.1 added report function
*
* ============================================================================
*/
#define DATREAD_ERROR_CC_VERSION \
"DATREAD_ERROR_CC V1.0 "
"DATREAD_ERROR_CC V1.1"
#define DATREAD_ERROR_CC_CVSID \
"$Id: error.cc,v 1.2 2006-03-28 16:07:41 tforb Exp $"
"$Id: error.cc,v 1.3 2006-07-07 09:20:43 tforb Exp $"
#include <iostream>
#include <datreadxx/error.h>
......@@ -120,6 +121,19 @@ namespace datread {
}
}
/*----------------------------------------------------------------------*/
//! report violation of assertion
void report_violation(const char* message,
const char* file,
const int& line,
const char* condition)
{
std::cerr << "VIOLATION of condition: " << condition << std::endl;
std::cerr << "* in " << file << " at line " << line << std::endl;
std::cerr << "* message: " << message << std::endl;
}
} // namespace datread
/* ----- END OF error.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: error.h,v 1.5 2006-04-28 09:26:24 tforb Exp $
* $Id: error.h,v 1.6 2006-07-07 09:20:43 tforb Exp $
* \author Thomas Forbriger
* \date 30/03/2004
*
......@@ -30,6 +30,7 @@
* REVISIONS and CHANGES
* - 30/03/2004 V1.0 Thomas Forbriger
* - 28/04/2006 V1.1 provide explicit virtual destructor
* - 07/07/2006 V1.2 provide non-fatal behaviour
*
* ============================================================================
*/
......@@ -38,9 +39,9 @@
#ifndef DATREAD_ERROR_H_VERSION
#define DATREAD_ERROR_H_VERSION \
"DATREAD_ERROR_H V1.1"
"DATREAD_ERROR_H V1.2"
#define DATREAD_ERROR_H_CVSID \
"$Id: error.h,v 1.5 2006-04-28 09:26:24 tforb Exp $"
"$Id: error.h,v 1.6 2006-07-07 09:20:43 tforb Exp $"
namespace datread {
......@@ -105,6 +106,18 @@ namespace datread {
const char* Mcondition;
}; // class Exception
/*! \brief report violation of condition
*
* \ingroup group_error
* \param message message of type char*
* \param file name of source code file
* \param line source code line number
* \param condition assert condition
*/
void report_violation(const char* message,
const char* file,
const int& line,
const char* condition);
} // namespace datread
......@@ -142,6 +155,34 @@ namespace datread {
#define DATREAD_illegal DATREAD_abort("illegal call!")
/*! \brief Check an assertion and report only.
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
*/
#define DATREAD_report_assert(C,M,V) \
if (!(C)) { \
datread::report_violation(M, __FILE__, __LINE__, #C); \
std::cerr << "* comment: " << V << std::endl; \
std::cerr.flush(); \
}
/*! \brief Macro to distinguish between fatal and non fatal assertions.
*
* \ingroup group_error
* \param F true for non fatal behaviour
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
*/
#define DATREAD_nonfatal_assert(F,C,M,V) \
if (F) { DATREAD_report_assert(C,M,V) } else { DATREAD_assert(C,M) }
#endif // DATREAD_ERROR_H_VERSION (includeguard)
/* ----- END OF error.h ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mseedread.cc,v 1.21 2006-05-11 14:02:38 tforb Exp $
* $Id: mseedread.cc,v 1.22 2006-07-07 09:20:43 tforb Exp $
* \author Thomas Forbriger
* \date 15/07/2004
*
......@@ -35,13 +35,14 @@
* implementation dependent size
* - provide explicit conversion of BTIME fields
* - 09/05/2006 V1.3 use general Steim 1 and 2 code
* - 07/07/2006 V1.4 provide debug function when reading MiniSEED record
*
* ============================================================================
*/
#define TF_MSEEDREAD_CC_VERSION \
"TF_MSEEDREAD_CC V1.3"
"TF_MSEEDREAD_CC V1.4"
#define TF_MSEEDREAD_CC_CVSID \
"$Id: mseedread.cc,v 1.21 2006-05-11 14:02:38 tforb Exp $"
"$Id: mseedread.cc,v 1.22 2006-07-07 09:20:43 tforb Exp $"
#include <string>
#include <string.h>
......@@ -349,12 +350,18 @@ namespace datread {
// std::cout << "last sample: " << sum << std::endl;
// std::cout << "xn: " << xn << std::endl;
// check data integrity
DATREAD_assert((isample==nsamples),
DATREAD_nonfatal_assert(Mdebug.inconsistencies_are_not_fatal,
(isample==nsamples),
"ERROR (reading MiniSEED record): "
"missing samples");
DATREAD_assert((Mdata(isample-1)==xn),
"missing samples",
"isample=" << isample << " nsamples=" << nsamples);
DATREAD_nonfatal_assert(Mdebug.inconsistencies_are_not_fatal,
(Mdata(isample-1)==xn),
"ERROR (reading MiniSEED record): "
"data is corrupt");
"data is corrupt",
"Mdata(isample-1)=" << Mdata(isample-1)
<< " xn=" << xn
<< " isample=" << isample);
// finished successfully
if (is.good()) { Mvalid=true; }
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mseedread.h,v 1.13 2006-04-04 10:00:07 tforb Exp $
* $Id: mseedread.h,v 1.14 2006-07-07 09:20:43 tforb Exp $
* \author Thomas Forbriger
* \date 15/07/2004
*
......@@ -29,6 +29,7 @@
*
* REVISIONS and CHANGES
* - 15/07/2004 V1.0 Thomas Forbriger
* - 07/07/2006 V1.1 provide debug function when reading MiniSEED record
*
* ============================================================================
*/
......@@ -37,9 +38,9 @@
#ifndef TF_MSEEDREAD_H_VERSION
#define TF_MSEEDREAD_H_VERSION \
"TF_MSEEDREAD_H V1.0 "
"TF_MSEEDREAD_H V1.1"
#define TF_MSEEDREAD_H_CVSID \
"$Id: mseedread.h,v 1.13 2006-04-04 10:00:07 tforb Exp $"
"$Id: mseedread.h,v 1.14 2006-07-07 09:20:43 tforb Exp $"
#include<new>
#include<iostream>
......@@ -112,9 +113,36 @@ namespace datread {
std::string extractstring(const char* s, const int& l);
} // namespace util
/*----------------------------------------------------------------------*/
/*! debug modes
*
* These debug modes control the behaviour of the MiniSEEDRecord class.
* They are meant to be usefull, when testing corrupt MiniSEED files. By
* setting the flags it is possible to scan the files by preventing
* inconsitencies from being fatal.
*/
struct Debug {
//! constructor sets default values
Debug(const bool& flag=false):
inconsistencies_are_not_fatal(false)
{ }
//! make inconsistencies non fatal
bool inconsistencies_are_not_fatal;
}; // struct Debug
/*----------------------------------------------------------------------*/
/*! MiniSEED class for decoded data
*
* This class provides the interface to read one MiniSEED record
* including all data sample frames (if requested).
*
* The read or the skipdata function have to be called after
* initialization of the record object. Prior to reading data the
* object's contents are not valid, which is indicated by the return
* value of the valid function.
*
* If debug modes are requested, they have to be passed on the instance
* of creation.
*/
class MiniSEEDRecord {
public:
......@@ -122,7 +150,8 @@ namespace datread {
typedef int Tvalue;
//! type of container for sample data
typedef aff::Series<Tvalue> Tseries;
MiniSEEDRecord():
MiniSEEDRecord(const Debug& d=Debug(false)):
Mdebug(d),
Mvalid(false),
Mhasblockette1000(false),
Mhasblockette1001(false) { }
......@@ -175,6 +204,8 @@ namespace datread {
private:
//! read header and return block
MiniSEEDblock readheader(std::istream& is);
//! debug options
Debug Mdebug;
//! contains valid data
bool Mvalid;
//! Data Only SEED Blockette is present
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mseedtest.cc,v 1.18 2006-05-11 14:02:39 tforb Exp $
* $Id: mseedtest.cc,v 1.19 2006-07-07 09:20:44 tforb Exp $
* \author Thomas Forbriger
* \date 15/07/2004
*
......@@ -32,13 +32,14 @@
* - 04/04/2006 V1.1 handle special EDL data features
* - 09/05/2006 V1.2 support Steim 2 too
* - 11/05/2006 V1.3 generic frame dump
* - 07/07/2006 V1.4 provide non fatal scan mode
*
* ============================================================================
*/
#define MSEEDTEST_VERSION \
"MSEEDTEST V1.3 test mini-SEED reading"
"MSEEDTEST V1.4 test MiniSEED reading"
#define MSEEDTEST_CVSID \
"$Id: mseedtest.cc,v 1.18 2006-05-11 14:02:39 tforb Exp $"
"$Id: mseedtest.cc,v 1.19 2006-07-07 09:20:44 tforb Exp $"
#include <fstream>
#include <iostream>
......@@ -61,6 +62,7 @@ int main(int iargc, char* argv[])
{
MSEEDTEST_VERSION "\n"
"usage: mseedtest [-v] [-raw] [-reader] [-skip] [-stream]" "\n"
" [-nfinconsist]" "\n"
" file [file...]" "\n"
" or: mseedtest --help|-h" "\n"
};
......@@ -75,6 +77,7 @@ int main(int iargc, char* argv[])
"-skip skip data samples" "\n"
"-stream read data through stream" "\n"
"-generic use generic frame dump during raw test" "\n"
"-nfinconsist make inconsistencies non fatal errors" "\n"
};
// define commandline options
......@@ -95,6 +98,8 @@ int main(int iargc, char* argv[])
{"stream",arg_no,"-"},
// 6: stream mode
{"generic",arg_no,"-"},
// 7: stream mode
{"nfinconsist",arg_no,"-"},
{NULL}
};
......@@ -143,7 +148,17 @@ int main(int iargc, char* argv[])
bool streammode=cmdline.optset(5);
bool genericframedump=cmdline.optset(6);
if (verbosemode) { cout << "in verbose modes" << endl; }
datread::mseed::Debug MiniSEEDdebug;
MiniSEEDdebug.inconsistencies_are_not_fatal=cmdline.optset(7);
if (verbosemode)
{
cout << MSEEDTEST_VERSION << endl;
cout << MSEEDTEST_CVSID << endl;
cout << "in verbose mode" << endl;
}
if (MiniSEEDdebug.inconsistencies_are_not_fatal)
{ cout << "inconsistencies are made non fatal" << endl; }
while (cmdline.extra())
{
......@@ -381,16 +396,24 @@ int main(int iargc, char* argv[])
cout << "===========" << endl;
std::ifstream ifs(filename.c_str());
datread::mseed::MiniSEEDRecord record;
datread::mseed::MiniSEEDRecord record(MiniSEEDdebug);
int irecord=0;
while (ifs.good())
{
if (skipmode) { record.skipdata(ifs); }
else { ifs >> record; }
++irecord;
cout << endl;
cout << "RECORD #" << irecord << endl;
cout << "===========" << endl;
if (skipmode)
{
if (verbosemode) { cout << "read record by skipping samples" << endl; }
record.skipdata(ifs);
}
else
{
if (verbosemode) { cout << "read record header and samples" << endl; }
ifs >> record;
}
if (record.valid())
{
if (!skipmode)
......@@ -411,7 +434,8 @@ int main(int iargc, char* argv[])
{
cout << "data:" << endl;
datread::mseed::MiniSEEDRecord::Tseries data(record.data());
cout << " number of samples in data: " << data.size() << endl;
cout << " number of samples in data: "
<< data.size() << endl;
cout << " last sample of previous record: "
<< record.xm1() << endl;
cout << " first sample: "
......@@ -419,6 +443,19 @@ int main(int iargc, char* argv[])
cout << " last sample: "
<< data(data.l()) << endl;
}
{
cout << endl;
libtime::TRelativeTime dt
=libtime::double2time(record.dt());
libtime::TRelativeTime length=dt*(record.nsamples()-1);
libtime::TAbsoluteTime next=record.date()+dt+length;
cout << " sampling interval: "
<< dt.timestring() << endl;
cout << " length of record: "
<< length.timestring() << endl;
cout << " expected start of next record: "
<< next.timestring() << endl;
}
}
else
{
......
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