DATRW++ library: seismic data I/O with multiple formats
isustream.cc
Go to the documentation of this file.
1 /*! \file isustream.cc
2  * \brief read Seismic Unix data (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 19/11/2010
8  *
9  * read Seismic Unix data (implementation)
10  *
11  * Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach)
12  *
13  * ----
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27  * ----
28  *
29  * REVISIONS and CHANGES
30  * - 19/11/2010 V1.0 Thomas Forbriger
31  * - 23.12.2010 V1.1 use stream buffer seekg() function to skip series
32  * - 21/01/2012 V1.2
33  * - prepared isustream to take modifiers
34  * - use SUHeaderControl to store format modifier values
35  * - pass control parameters to SUheader
36  * - bestrict is bundled with spatial sampling control
37  * parameters
38  * - 18/11/2016 V1.3 use debug flag in base class
39  *
40  * ============================================================================
41  */
42 #define DATRW_SU_CC_VERSION \
43  "DATRW_SU_CC V1.3"
44 
45 #include <datrwxx/su.h>
46 #include <datrwxx/util.h>
47 #include <datrwxx/error.h>
48 #include <datrwxx/debug.h>
49 #include <datrwxx/suformat.h>
50 #include <datrwxx/formatmodifier.h>
51 
52 namespace datrw {
53 
54  const std::ios_base::openmode
55  isustream::openmode=std::ios_base::in|std::ios_base::binary;
56 
57  /*----------------------------------------------------------------------*/
58 
59  isustream::isustream(std::istream& is,
60  const std::string& modifier,
61  const bool& debug):
62  Tbase(is, true, true, false, debug),
63  Mnextheader(Mheadercontrol, debug)
64  {
65  DATRW_debug(Mdebug, "isustream::isustream","entering constructor");
66  // evaluate format modifiers
68 
69  // read first (next) trace header
70  DATRW_assert(is.good(),
71  "ERROR (isustream::isustream): input stream is bad");
73  Mnextheader.read(is);
74  this->setsrce(Mnextheader.srce());
75  DATRW_debug(Mdebug, "isustream::isustream", "finished constructor");
76  }
77 
78  /*----------------------------------------------------------------------*/
79 
81  {
82  return(datrw::util::convert<Tfseries, Tdseries>(this->fseries()));
83  } // Tdseries isustream::dseries()
84 
85  /*----------------------------------------------------------------------*/
86 
88  {
89  DATRW_debug(Mdebug, "isustream::fseries","entering function");
91  char *ipointer=reinterpret_cast<char *>(series.pointer());
92  DATRW_Xassert(Mis.read(ipointer, series.size()*sizeof(float)),
93  "ERROR (isustream::fseries): reading SU samples",
95  DATRW_debug(Mdebug, "isustream::fseries",
96  "read " << series.size() << " samples"
97  << " which are " << (series.size()*sizeof(float))
98  << " characters");
99  this->readheader();
100  DATRW_debug(Mdebug, "isustream::fseries",
101  this->wid2().line() << "\n" << this->info().line());
102  DATRW_debug(Mdebug, "isustream::fseries","leaving function");
103  return(series);
104  } // Tiseries isustream::fseries()
105 
106  /*----------------------------------------------------------------------*/
107 
109  {
110  Mis.seekg(sizeof(float)*Mnextheader.Mheader.ns,
111  std::ios_base::cur);
112  DATRW_Xassert(Mis.good(),
113  "ERROR (isustream::skipseries): calling seekg()",
115  this->readheader();
116  } // void isustream::skipseries()
117 
118  /*----------------------------------------------------------------------*/
119 
121  {
122  DATRW_debug(Mdebug, "isustream::readheader","entering function");
123  DATRW_assert(this->good(),
124  "ERROR (isustream::readheader): reached end of file");
125  this->newtrace();
126  this->setwid2(Mnextheader.wid2());
127  this->setinfo(Mnextheader.info());
128  DATRW_assert(((this->srce().date == Mnextheader.srce().date)
129  && (this->srce().cs == Mnextheader.srce().cs)
130  && (this->srce().cx == Mnextheader.srce().cx)
131  && (this->srce().cy == Mnextheader.srce().cy)
132  && (this->srce().cz == Mnextheader.srce().cz)),
133  "ERROR (isustream::readheader): "
134  "current source differs from previous");
137  try {
140  {
141  this->setlast();
142  } catch (datrw::Exception E)
143  {
145  E.report();
146  throw(E);
147  }
149  DATRW_debug(Mdebug, "isustream::readheader","leave function");
150  } // void isustream::readheader()
151 
152  /*----------------------------------------------------------------------*/
153 
154  void isustream::help(std::ostream& os)
155  {
156  os <<
157  std::endl <<
158  "SeismicUn*x reading functions" << std::endl <<
159  "-----------------------------" << std::endl <<
160  DATRW_SU_CC_VERSION << std::endl <<
161  std::endl <<
162  "This module provides reading of SeismicUn*x binary data files."
163  << std::endl;
164  os << std::endl;
166  os << std::endl;
167  os <<
168  "Valid format modifiers are:\n";
169  formatmodifiers::ModifierHelp mh(os, 14);
171  "Abort if scalco violates the definition of SeismicUn*x.\n";
172  mh() << "The default is to tolerate spatial sampling\n";
173  mh() << "scaling factors being zero or being small\n";
174  mh() << "powers of ten.\n";
175  } // void isustream::help(std::ostream& os)
176 
177 } // namespace datrw
178 
179 /* ----- END OF isustream.cc ----- */
virtual Tfseries fseries()
Definition: isustream.cc:87
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
provide format modifiers (prototypes)
macro function for debugging output (prototypes)
void setinfo(const sff::INFO &info)
Definition: datread.cc:121
aff::Series< float > Tfseries
Definition: types.h:46
virtual Tdseries dseries()
Definition: isustream.cc:80
datrw::su::options::SUHeaderControl Mheadercontrol
Definition: su.h:90
sff::WID2 wid2() const
Definition: datread.h:111
::sff::INFO info() const
return INFO line
Definition: suheader.cc:292
::sff::WID2 wid2() const
return WID2 line
Definition: suheader.cc:309
options::SUHeaderControl inputmodifiers(const std::string &modifier, const bool &debug)
evaluate input stream format modifiers
Definition: suformat.cc:94
static bool report_on_construct_flag()
return report on construct flag
Definition: exception.h:93
void setsrce(const sff::SRCE &srce)
Definition: datread.cc:129
#define DATRW_Xassert(C, M, E)
Check an assertion and report by throwing an exception.
Definition: error.h:76
static void dont_report_on_construct()
Issue NO screen report on construction of exception.
Definition: exception.cc:90
bool good() const
Definition: datread.h:95
aff::Series< double > Tdseries
Definition: types.h:45
Help formatting modifier online help.
isustream(std::istream &is, const std::string &modifier="", const bool &debug=false)
Definition: isustream.cc:59
exception class declaration for libdatrwxx (prototypes)
Base class for exceptions.
Definition: exception.h:62
std::istream & Mis
Definition: datread.h:126
datrw::su::SUheader Mnextheader
Definition: su.h:91
void setwid2(const sff::WID2 &wid2)
Definition: datread.cc:113
const char *const strict
strictly interpret header as defined in SeismicUnix source
Definition: suformat.cc:65
unsigned short ns
number of samples in this trace
sff::INFO info() const
Definition: datread.h:110
static void help(std::ostream &os=std::cout)
Definition: isustream.cc:154
Root namespace of library.
Definition: aalibdatrwxx.cc:16
#define DATRW_SU_CC_VERSION
Definition: isustream.cc:42
void set(const datrw::su::options::SUHeaderControl &hc)
set control parameters
Definition: suheader.h:129
utilities used by more than one type of data reader (prototypes)
sff::SRCE srce() const
Definition: datread.h:109
static const std::ios_base::openmode openmode
Definition: su.h:87
#define DATRW_debug(C, N, M)
produce debug output
Definition: debug.h:50
::sff::SRCE srce() const
return SRCE line
Definition: suheader.cc:275
void read(std::istream &is)
read struct from file
Definition: suheader.cc:72
virtual void report() const
Screen report.
Definition: exception.cc:96
read Seismic Unix data (prototypes)
static void help(std::ostream &os)
print online help regarding header fields and TOAST data
Definition: suheader.cc:548
virtual void skipseries()
Definition: isustream.cc:108
TraceHeaderStruct Mheader
the actual data fields are provided for public access
Definition: suheader.h:239