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

reintegrating code from branch libdatrwxx.su after implementing format

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.
modifiers and scaling of ultrasonic data parameters in SeismicUnix I/O


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4466
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 9ff2934a
...@@ -30,14 +30,17 @@ ...@@ -30,14 +30,17 @@
* *
* REVISIONS and CHANGES * REVISIONS and CHANGES
* - 28/07/2011 V1.0 Thomas Forbriger * - 28/07/2011 V1.0 Thomas Forbriger
* - 21/01/2012 V1.1 provide online help output support class
* *
* ============================================================================ * ============================================================================
*/ */
#define DATRW_FORMATMODIFIER_CC_VERSION \ #define DATRW_FORMATMODIFIER_CC_VERSION \
"DATRW_FORMATMODIFIER_CC V1.0 " "DATRW_FORMATMODIFIER_CC V1.1"
#define DATRW_FORMATMODIFIER_CC_CVSID \ #define DATRW_FORMATMODIFIER_CC_CVSID \
"$Id$" "$Id$"
#include <iostream>
#include <iomanip>
#include <datrwxx/formatmodifier.h> #include <datrwxx/formatmodifier.h>
#include <datrwxx/util.h> #include <datrwxx/util.h>
#include <algorithm> #include <algorithm>
...@@ -182,6 +185,42 @@ namespace datrw { ...@@ -182,6 +185,42 @@ namespace datrw {
} }
} // void Subformat::notchecked(std::ostream& os) const } // void Subformat::notchecked(std::ostream& os) const
/*======================================================================*/
namespace formatmodifiers {
std::ostream& ModifierHelp::operator() ()
{
Mos.width(Mwidth);
Mos << std::left << std::setfill(' ') << " " << " ";
return(Mos);
} // std::ostream& ModifierHelp::operator() ()
/*----------------------------------------------------------------------*/
std::ostream& ModifierHelp::operator() (const std::string& key)
{
Mos.width(Mwidth);
std::string keyval=key;
keyval += ": ";
Mos << std::left << std::setfill('.') << keyval << " ";
return(Mos);
} // std::ostream& ModifierHelp::operator() (key)
/*----------------------------------------------------------------------*/
std::ostream& ModifierHelp::operator() (const std::string& key,
const std::string& val)
{
Mos.width(Mwidth);
std::string keyval=key;
keyval += "=" + val + ": ";
Mos << std::left << std::setfill('.') << keyval << " ";
return(Mos);
} // std::ostream& ModifierHelp::operator() (key, val)
} // namespace formatmodifiers
} // namespace datrw } // namespace datrw
/* ----- END OF formatmodifier.cc ----- */ /* ----- END OF formatmodifier.cc ----- */
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
* *
* REVISIONS and CHANGES * REVISIONS and CHANGES
* - 28/07/2011 V1.0 Thomas Forbriger * - 28/07/2011 V1.0 Thomas Forbriger
* - 21/01/2012 V1.1 provide online help output support class
* *
* ============================================================================ * ============================================================================
*/ */
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
#ifndef DATRW_FORMATMODIFIER_H_VERSION #ifndef DATRW_FORMATMODIFIER_H_VERSION
#define DATRW_FORMATMODIFIER_H_VERSION \ #define DATRW_FORMATMODIFIER_H_VERSION \
"DATRW_FORMATMODIFIER_H V1.0 " "DATRW_FORMATMODIFIER_H V1.1"
#define DATRW_FORMATMODIFIER_H_CVSID \ #define DATRW_FORMATMODIFIER_H_CVSID \
"$Id$" "$Id$"
...@@ -130,6 +131,27 @@ namespace datrw { ...@@ -130,6 +131,27 @@ namespace datrw {
*/ */
void online_help(std::ostream& os); void online_help(std::ostream& os);
/*----------------------------------------------------------------------*/
/*! \brief Help formatting modifier online help
* \ingroup formatmodifiers
* \sa datrw::su::osustream::help()
*/
class ModifierHelp
{
public:
ModifierHelp(std::ostream& os,
const unsigned int& width):
Mos(os), Mwidth(width) { }
std::ostream& operator()(const std::string& key,
const std::string& val);
std::ostream& operator()(const std::string& key);
std::ostream& operator()();
private:
std::ostream& Mos;
unsigned int Mwidth;
}; // class ModifierHelp
} // namespace formatmodifiers } // namespace formatmodifiers
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
......
...@@ -47,11 +47,12 @@ ...@@ -47,11 +47,12 @@
* - 07/11/2011 V1.16 make ASCII input module visible * - 07/11/2011 V1.16 make ASCII input module visible
* - 19/11/2011 V1.17 provide binary input * - 19/11/2011 V1.17 provide binary input
* - 05/12/2011 V1.18 itsoftstream takes format modifiers * - 05/12/2011 V1.18 itsoftstream takes format modifiers
* - 21/01/2012 V1.19 prepared isustream to take modifiers
* *
* ============================================================================ * ============================================================================
*/ */
#define DATRW_READANY_CC_VERSION \ #define DATRW_READANY_CC_VERSION \
"DATRW_READANY_CC V1.18" "DATRW_READANY_CC V1.19"
#define DATRW_READANY_CC_CVSID \ #define DATRW_READANY_CC_CVSID \
"$Id$" "$Id$"
...@@ -210,8 +211,7 @@ namespace datrw { ...@@ -210,8 +211,7 @@ namespace datrw {
} }
else if (Mformat==Fsu) else if (Mformat==Fsu)
{ {
DATRW_expect_no_modifier(Mformat,modifiers); Mis=new isustream(is, modifiers, debug);
Mis=new isustream(is, debug);
} }
else if (Mformat==Fseife) else if (Mformat==Fseife)
{ {
......
...@@ -31,6 +31,18 @@ ...@@ -31,6 +31,18 @@
* - 19/11/2010 V1.0 Thomas Forbriger * - 19/11/2010 V1.0 Thomas Forbriger
* - 23/11/2010 V1.1 introduced static member data * - 23/11/2010 V1.1 introduced static member data
* - 07/06/2011 V1.2 promise constness of series samples * - 07/06/2011 V1.2 promise constness of series samples
* - 21/01/2012 V1.3
* - prepared isustream and osustream to take modifiers
* - use SUHeaderControl to store format modifier values
* - 24/01/2012 V1.4 there is a subtle bute relevant difference in the
* possible orders of member data fields of isustream:
* Mheadercontrol must be first, followed by
* Mnextheader. Otherwise Mnexheader is
* initialized with a non-initialized Mheadercontrol
* which contains the improper scalco value "0"; the
* wrong order results in warning messages each time
* the code is used and in an unavoidable abort if the
* strict format modifier is set
* *
* ============================================================================ * ============================================================================
*/ */
...@@ -39,13 +51,14 @@ ...@@ -39,13 +51,14 @@
#ifndef DATRW_SU_H_VERSION #ifndef DATRW_SU_H_VERSION
#define DATRW_SU_H_VERSION \ #define DATRW_SU_H_VERSION \
"DATRW_SU_H V1.2" "DATRW_SU_H V1.3"
#define DATRW_SU_H_CVSID \ #define DATRW_SU_H_CVSID \
"$Id$" "$Id$"
#include<datrwxx/datread.h> #include <datrwxx/datread.h>
#include<datrwxx/datwrite.h> #include <datrwxx/datwrite.h>
#include<datrwxx/suheader.h> #include <datrwxx/suheader.h>
#include <datrwxx/suformat.h>
namespace datrw { namespace datrw {
...@@ -65,7 +78,9 @@ namespace datrw { ...@@ -65,7 +78,9 @@ namespace datrw {
class isustream: public idatstream { class isustream: public idatstream {
public: public:
typedef idatstream Tbase; typedef idatstream Tbase;
isustream(std::istream& is, const bool& debug=false); isustream(std::istream& is,
const std::string& modifier="",
const bool& debug=false);
virtual ~isustream() { } virtual ~isustream() { }
virtual Tdseries dseries(); virtual Tdseries dseries();
virtual Tfseries fseries(); virtual Tfseries fseries();
...@@ -75,6 +90,7 @@ namespace datrw { ...@@ -75,6 +90,7 @@ namespace datrw {
private: private:
void readheader(); void readheader();
bool Mdebug; bool Mdebug;
datrw::su::options::SUHeaderControl Mheadercontrol;
datrw::su::SUheader Mnextheader; datrw::su::SUheader Mnextheader;
}; // class isustream }; // class isustream
...@@ -87,7 +103,9 @@ namespace datrw { ...@@ -87,7 +103,9 @@ namespace datrw {
class osustream: public odatstream { class osustream: public odatstream {
public: public:
typedef odatstream Tbase; typedef odatstream Tbase;
osustream(std::ostream& os, const bool& debug=false); osustream(std::ostream& os,
const std::string& modifier="",
const bool& debug=false);
inline virtual ~osustream() { } inline virtual ~osustream() { }
static void help(std::ostream& os=std::cout); static void help(std::ostream& os=std::cout);
static const std::ios_base::openmode openmode; static const std::ios_base::openmode openmode;
...@@ -99,6 +117,7 @@ namespace datrw { ...@@ -99,6 +117,7 @@ namespace datrw {
private: private:
bool Mdebug; bool Mdebug;
unsigned int Mitrace; unsigned int Mitrace;
datrw::su::options::SUHeaderControl Mheadercontrol;
}; // class osustream }; // class osustream
} // namespace datrw } // namespace datrw
......
...@@ -30,11 +30,17 @@ ...@@ -30,11 +30,17 @@
* REVISIONS and CHANGES * REVISIONS and CHANGES
* - 19/11/2010 V1.0 Thomas Forbriger * - 19/11/2010 V1.0 Thomas Forbriger
* - 23.12.2010 V1.1 use stream buffer seekg() function to skip series * - 23.12.2010 V1.1 use stream buffer seekg() function to skip series
* - 21/01/2012 V1.2
* - prepared isustream to take modifiers
* - use SUHeaderControl to store format modifier values
* - pass control parameters to SUheader
* - bestrict is bundled with spatial sampling control
* parameters
* *
* ============================================================================ * ============================================================================
*/ */
#define DATRW_SU_CC_VERSION \ #define DATRW_SU_CC_VERSION \
"DATRW_SU_CC V1.1" "DATRW_SU_CC V1.2"
#define DATRW_SU_CC_CVSID \ #define DATRW_SU_CC_CVSID \
"$Id$" "$Id$"
...@@ -42,6 +48,8 @@ ...@@ -42,6 +48,8 @@
#include <datrwxx/util.h> #include <datrwxx/util.h>
#include <datrwxx/error.h> #include <datrwxx/error.h>
#include <datrwxx/debug.h> #include <datrwxx/debug.h>
#include <datrwxx/suformat.h>
#include <datrwxx/formatmodifier.h>
namespace datrw { namespace datrw {
...@@ -50,12 +58,20 @@ namespace datrw { ...@@ -50,12 +58,20 @@ namespace datrw {
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
isustream::isustream(std::istream& is, const bool& debug): isustream::isustream(std::istream& is,
Tbase(is, true, true, false), Mdebug(debug), Mnextheader(debug) const std::string& modifier,
const bool& debug):
Tbase(is, true, true, false), Mdebug(debug),
Mnextheader(Mheadercontrol, debug)
{ {
DATRW_debug(Mdebug, "isustream::isustream","entering constructor"); DATRW_debug(Mdebug, "isustream::isustream","entering constructor");
// evaluate format modifiers
Mheadercontrol=su::inputmodifiers(modifier, Mdebug);
// read first (next) trace header
DATRW_assert(is.good(), DATRW_assert(is.good(),
"ERROR (isustream::isustream): input stream is bad"); "ERROR (isustream::isustream): input stream is bad");
Mnextheader.set(Mheadercontrol);
Mnextheader.read(is); Mnextheader.read(is);
this->setsrce(Mnextheader.srce()); this->setsrce(Mnextheader.srce());
DATRW_debug(Mdebug, "isustream::isustream", "finished constructor"); DATRW_debug(Mdebug, "isustream::isustream", "finished constructor");
...@@ -141,42 +157,25 @@ namespace datrw { ...@@ -141,42 +157,25 @@ namespace datrw {
{ {
os << os <<
std::endl << std::endl <<
"SeismicUnix reading functions" << std::endl << "SeismicUn*x reading functions" << std::endl <<
"-----------------------------" << std::endl << "-----------------------------" << std::endl <<
DATRW_SU_CC_VERSION << std::endl << DATRW_SU_CC_VERSION << std::endl <<
DATRW_SU_CC_CVSID << std::endl << DATRW_SU_CC_CVSID << std::endl <<
DATRW_SU_H_CVSID << std::endl << DATRW_SU_H_CVSID << std::endl <<
std::endl << std::endl <<
"This module provides reading of SeismicUnix binary data files." "This module provides reading of SeismicUn*x binary data files."
<< std::endl <<
"Only a few header fields are extracted:"
<< std::endl; << std::endl;
os << std::endl;
datrw::su::SUheader::help(os);
os << std::endl;
os << os <<
"wid2.nsamples = header.ns\n" "Valid format modifiers are:\n";
"wid2.dt = header.dt*1.e-6\n" formatmodifiers::ModifierHelp mh(os, 14);
"wid2.date = srce.date+header.delrt*1.e-3\n" mh(su::subformat::key::strict) <<
"wid2.channel = header.tracf\n" "Abort if scalco violates the definition of SeismicUn*x.\n";
" (tracf = Trace number within original field record)\n" mh() << "The default is to tolerate spatial sampling\n";
"wid2.station = header.tracf\n" mh() << "scaling factors being zero or being small\n";
"wid2.auxid = header.fldr\n" mh() << "powers of ten.\n";
" (fldr = Original field record number)\n";
os <<
"info.cx = header.gx*scalcof\n"
"info.cy = header.gy*scalcof\n"
"info.cz = header.gelev*scalelf\n"
"info.nstacks = header.nvs\n";
os <<
"srce.cx = header.sx*scalcof\n"
"srce.cy = header.sy*scalcof\n"
"srce.cz = header.sdepth*scalelf\n"
"srce.date = date(year,day,hour,minute,sec)\n";
os <<
"header.scalco and header.scalel are as defined for the SEG-Y "
"format:\n"
"http://www.seg.org/SEGportalWEBproject/prod/SEG-Publications/Pub-Technical-Standards/Documents/seg_y_rev1.pdf\n"
"except when their modulus is smaller than 10 and larger than 0.\n"
"In this case the scaling factors scalcof and scalelf are taken to be\n"
"10 to the power of header.scalco or header.scalel, respectively\n";
} // void isustream::help(std::ostream& os) } // void isustream::help(std::ostream& os)
} // namespace datrw } // namespace datrw
......
...@@ -30,11 +30,15 @@ ...@@ -30,11 +30,15 @@
* REVISIONS and CHANGES * REVISIONS and CHANGES
* - 03/12/2010 V1.0 Thomas Forbriger * - 03/12/2010 V1.0 Thomas Forbriger
* - 07/06/2011 V1.1 promise constness of series samples * - 07/06/2011 V1.1 promise constness of series samples
* - 21/01/2012 V1.2
* - prepared osustream to take modifiers
* - use SUHeaderControl to store format modifier values
* - 24/01/2012 V1.3 output modifiers are evaluated in dedicated function
* *
* ============================================================================ * ============================================================================
*/ */
#define DATRW_OSUSTREAM_CC_VERSION \ #define DATRW_OSUSTREAM_CC_VERSION \
"DATRW_OSUSTREAM_CC V1.1" "DATRW_OSUSTREAM_CC V1.3"
#define DATRW_OSUSTREAM_CC_CVSID \ #define DATRW_OSUSTREAM_CC_CVSID \
"$Id$" "$Id$"
...@@ -42,6 +46,9 @@ ...@@ -42,6 +46,9 @@
#include <datrwxx/error.h> #include <datrwxx/error.h>
#include <datrwxx/debug.h> #include <datrwxx/debug.h>
#include <datrwxx/util.h> #include <datrwxx/util.h>
#include <datrwxx/suformat.h>
#include <datrwxx/sucomanager.h>
#include <datrwxx/formatmodifier.h>
namespace datrw { namespace datrw {
...@@ -50,19 +57,60 @@ namespace datrw { ...@@ -50,19 +57,60 @@ namespace datrw {
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
osustream::osustream(std::ostream& os, const bool& debug): osustream::osustream(std::ostream& os,
const std::string& modifier,
const bool& debug):
Tbase(os, Ffloat, false, false, true, true), Tbase(os, Ffloat, false, false, true, true),
Mdebug(debug), Mitrace(0) Mdebug(debug), Mitrace(0)
{ {
DATRW_debug(Mdebug, "osustream::osustream", DATRW_debug(Mdebug, "osustream::osustream",
"new instance established"); "new instance established");
// evaluate format modifiers
Mheadercontrol=su::outputmodifiers(modifier, Mdebug);
} // osustream::osustream(std::ostream& os, const bool& debug) } // osustream::osustream(std::ostream& os, const bool& debug)
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
void osustream::help(std::ostream& os) void osustream::help(std::ostream& os)
{ {
os << "This module writes SeismicUn*x data." << std::endl; os <<
std::endl <<
"SeismicUn*x writing functions" << std::endl <<
"-----------------------------" << std::endl <<
DATRW_OSUSTREAM_CC_VERSION << std::endl <<
DATRW_OSUSTREAM_CC_CVSID << std::endl <<
DATRW_SU_H_CVSID << std::endl <<
std::endl <<
"This module provides writing of SeismicUn*x binary data files."
<< std::endl;
os << std::endl;
datrw::su::SUheader::help(os);
os << std::endl;
os <<
"Valid format modifiers are:\n";
formatmodifiers::ModifierHelp mh(os, 14);
mh(su::subformat::key::forceultrasonic) <<
"Force writing of ultrasonic data header\n";
mh() << "The default is to write standard SeismicUn*x\n";
mh() << "headers for seismic sampling intervals.\n";
mh(su::subformat::key::forceseismic) <<
"Force writing of seismic data header even\n";
mh() << "is sampling interval is too small.\n";
mh() << "Choosing both modifiers at once is an\n";
mh() << "inconsistency and causes abort().\n";
mh(su::subformat::key::scalco, "s") <<
"\"s\" is used as the preferred scalco and scalel value.\n";
mh() << "It is used only if it does not cause round-off truncation.\n";
mh() << "The default is "
<< su::subformat::key::scalco << "="
<< datrw::su::subformat::def::scalco << "\n";
mh(su::subformat::key::coodigits, "n") <<
"Limits the maximum number of significant digits in\n";
mh() << "spatial coordinates to \"n\". Coordinate values with\n";
mh() << "more digits will be truncated.\n";
mh() << "The default is "
<< su::subformat::key::coodigits << "="
<< datrw::su::subformat::def::coodigits << "\n";
} // void osustream::help(std::ostream& os=std::cout) } // void osustream::help(std::ostream& os=std::cout)
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
...@@ -102,7 +150,7 @@ namespace datrw { ...@@ -102,7 +150,7 @@ namespace datrw {
DATRW_debug(Mdebug, "osustream::writetrace(const Tfseries& series)", DATRW_debug(Mdebug, "osustream::writetrace(const Tfseries& series)",
"actually write trace"); "actually write trace");
++Mitrace; ++Mitrace;
::datrw::su::SUheader header(Mdebug); ::datrw::su::SUheader header(Mheadercontrol, Mdebug);
::sff::WID2 wid2=this->wid2(); ::sff::WID2 wid2=this->wid2();
wid2.nsamples=series.size(); wid2.nsamples=series.size();
header.set(wid2); header.set(wid2);
......
...@@ -45,15 +45,28 @@ ...@@ -45,15 +45,28 @@
* exceed 0.1% * exceed 0.1%
* - 29/03/2011 V1.2 - search for the smallest possible power larger or * - 29/03/2011 V1.2 - search for the smallest possible power larger or
* equal a desired value * equal a desired value
* - 22/01/2012 V1.3
* - handle control parameters
* - pass control parameters to Coordinates and ScalCoo
* - add conversion functions
* - 24/01/2012 V1.4
* - static cast of value to type float in function
* ScalCoo::set(const double&) caused terrible
* roundoff resulting in awfully many trailing
* digits. I see no reason for this cast and remove
* it.
* - reworked ScalCoo::smallestpower(const short&)
* *
* ============================================================================ * ============================================================================
*/ */
#define DATRW_SUCOMANAGER_CC_VERSION \ #define DATRW_SUCOMANAGER_CC_VERSION \
"DATRW_SUCOMANAGER_CC V1.2" "DATRW_SUCOMANAGER_CC V1.4"
#define DATRW_SUCOMANAGER_CC_CVSID \ #define DATRW_SUCOMANAGER_CC_CVSID \
"$Id$" "$Id$"
#include <cmath> #include <cmath>
#include <climits>
#include <datrwxx/suformat.h>
#include <datrwxx/sucomanager.h> #include <datrwxx/sucomanager.h>
#include <datrwxx/error.h> #include <datrwxx/error.h>
#include <datrwxx/debug.h> #include <datrwxx/debug.h>
...@@ -66,10 +79,12 @@ namespace datrw { ...@@ -66,10 +79,12 @@ namespace datrw {
/*======================================================================*/ /*======================================================================*/
/*! some local helpers /*! some local helpers
* \ingroup su
*/ */
namespace helper { namespace helper {
/*! \brief output format modifier for debug output /*! \brief output format modifier for debug output
* \ingroup su
*/ */
class MyOutputFormat { class MyOutputFormat {
public: public:
...@@ -96,8 +111,7 @@ namespace datrw { ...@@ -96,8 +111,7 @@ namespace datrw {
/*======================================================================*/ /*======================================================================*/
// constants to support coordinate scaling // constants to support coordinate scaling
double ScalCoo::effectivezero=1.e-12; double ScalCoo::effectivezero=datrw::su::subformat::def::thresholdzero;
int ScalCoo::maxnsigdigits=4;
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
...@@ -107,43 +121,10 @@ namespace datrw { ...@@ -107,43 +121,10 @@ namespace datrw {
*/ */
void ScalCoo::set(const short& sin, const int& c) void ScalCoo::set(const short& sin, const int& c)