DATRW++ library: seismic data I/O with multiple formats
datread.cc
Go to the documentation of this file.
1 /*! \file datrw.cc
2  * \brief abstract base class to read seismic data (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 30/03/2004
8  *
9  * abstract base class to read seismic data (implementation)
10  *
11  * ----
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25  * ----
26  *
27  * Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
28  *
29  * REVISIONS and CHANGES
30  * - 30/03/2004 V1.0 Thomas Forbriger
31  * - 17/09/2004 V1.1 make most fields private
32  * - 18/11/2016 V1.2 provide debug flag in base class
33  * and produce debug output
34  * - 19/04/2017 V1.3 fix: do not reset Msrceset upon reading new trace
35  * SRCE data is a file property not a trace property
36  *
37  * ============================================================================
38  */
39 #define DATRW_DATRW_CC_VERSION \
40  "DATRW_DATRW_CC V1.3"
41 
42 #include <datrwxx/datread.h>
43 #include <datrwxx/debug.h>
44 
45 namespace datrw {
46 
47  /*! constructor (must be called by derived class
48  *
49  * \param is C++ input stream
50  * \param providesd \c true, if stream provides \c double type series
51  * \param providesf \c true, if stream provides \c float type series
52  * \param providesi \c true, if stream provides \c int type series
53  * \param debug \c true, to select debug mode on a base class level
54  */
55  idatstream::idatstream(std::istream& is,
56  const bool& providesd,
57  const bool& providesf,
58  const bool& providesi,
59  const bool& debug)
60  : Mis(is), Mdebug(debug), Mwid2set(false), Msrceset(false), Minfoset(false),
61  Mtracefreeset(false), Mfilefreeset(false), Mlast(false),
62  Mprovidesd(providesd), Mprovidesf(providesf), Mprovidesi(providesi)
63  {
64  DATRW_debug(this->Mdebug,
65  "idatstream::idatstream",
66  "create new input stream");
67  DATRW_assert(is.good(), "input stream is not good!");
68  } // idatstream::idatstream
69 
70  /*----------------------------------------------------------------------*/
71 
72  bool idatstream::hasfree() const
73  {
74  if (Mwid2set) { return(Mtracefreeset); } else { return(Mfilefreeset); }
75  }
76 
77  /*----------------------------------------------------------------------*/
78 
79  sff::FREE idatstream::free() const
80  {
81  if (Mwid2set)
82  {
83  DATRW_debug(this->Mdebug, "idatstream::free",
84  DATRW_value(Mtracefree.lines.size()));
85  return(Mtracefree);
86  }
87  else
88  {
89  DATRW_debug(this->Mdebug, "idatstream::free",
90  DATRW_value(Mfilefree.lines.size()));
91  return(Mfilefree);
92  }
93  }
94 
95  /*----------------------------------------------------------------------*/
96 
97  void idatstream::setfilefree(const sff::FREE& free)
98  {
99  Mfilefreeset=true;
100  Mfilefree=free;
101  }
102 
103  /*----------------------------------------------------------------------*/
104 
105  void idatstream::settracefree(const sff::FREE& free)
106  {
107  Mtracefreeset=true;
109  }
110 
111  /*----------------------------------------------------------------------*/
112 
113  void idatstream::setwid2(const sff::WID2& wid2)
114  {
115  Mwid2set=true;
116  Mwid2=wid2;
117  }
118 
119  /*----------------------------------------------------------------------*/
120 
121  void idatstream::setinfo(const sff::INFO& info)
122  {
123  Minfoset=true;
124  Minfo=info;
125  }
126 
127  /*----------------------------------------------------------------------*/
128 
129  void idatstream::setsrce(const sff::SRCE& srce)
130  {
131  Msrceset=true;
132  Msrce=srce;
133  }
134 
135  /*----------------------------------------------------------------------*/
136 
138  {
139  Mlast=true;
140  }
141 
142  /*----------------------------------------------------------------------*/
143 
145  {
146  Mtracefreeset=false;
147  Mwid2set=false;
148  Minfoset=false;
149  }
150 
151  /*----------------------------------------------------------------------*/
152 
153  void idatstream::help(std::ostream& os, const char* name)
154  {
155  os << "Class " << name << " provides no help text." << std::endl;
156  }
157 
158  /* ====================================================================== */
159  // input operators implemented here to provide debug output
160 
161  idatstream& operator>>(idatstream& is, sff::WID2& wid2)
162  {
163  wid2=is.wid2();
164  DATRW_debug(is.debug(), "operator>>(idatstream& is, sff::WID2& wid2)",
165  DATRW_value(wid2.line().substr(0,50)));
166  return(is);
167  } // idatstream& operator>>(idatstream& is, sff::WID2& wid2)
168 
169  /* ---------------------------------------------------------------------- */
170 
171  idatstream& operator>>(idatstream& is, sff::SRCE& srce)
172  {
173  srce=is.srce();
174  DATRW_debug(is.debug(), "operator>>(idatstream& is, sff::SRCE& srce)",
175  DATRW_value(srce.line().substr(0,50)));
176  return(is);
177  } // idatstream& operator>>(idatstream& is, sff::SRCE& srce)
178 
179  /* ---------------------------------------------------------------------- */
180 
181  idatstream& operator>>(idatstream& is, sff::INFO& info)
182  {
183  info=is.info();
184  DATRW_debug(is.debug(), "operator>>(idatstream& is, sff::INFO& info)",
185  DATRW_value(info.line().substr(0,50)));
186  return(is);
187  } // idatstream& operator>>(idatstream& is, sff::INFO& info)
188 
189  /* ---------------------------------------------------------------------- */
190 
191  idatstream& operator>>(idatstream& is, sff::FREE& free)
192  {
193  free=is.free();
194  DATRW_debug(is.debug(), "operator>>(idatstream& is, sff::FREE& free)",
195  DATRW_value(free.lines.size()));
196  return(is);
197  } // idatstream& operator>>(idatstream& is, sff::FREE& free)
198 
199  /* ---------------------------------------------------------------------- */
200 
202  {
203  series=is.dseries();
204  DATRW_debug(is.debug(), "operator>>(idatstream& is, Tdseries& series)",
205  DATRW_value(series.f()) << ", " << DATRW_value(series.l()));
206  return(is);
207  } // idatstream& operator>>(idatstream& is, Tdseries& series)
208 
209  /* ---------------------------------------------------------------------- */
210 
212  {
213  series=is.fseries();
214  DATRW_debug(is.debug(), "operator>>(idatstream& is, Tfseries& series)",
215  DATRW_value(series.f()) << ", " << DATRW_value(series.l()));
216  return(is);
217  } // idatstream& operator>>(idatstream& is, Tfseries& series)
218 
219  /* ---------------------------------------------------------------------- */
220 
222  {
223  series=is.iseries();
224  DATRW_debug(is.debug(), "operator>>(idatstream& is, Tiseries& series)",
225  DATRW_value(series.f()) << ", " << DATRW_value(series.l()));
226  return(is);
227  } // idatstream& operator>>(idatstream& is, Tiseries& series)
228 
229 } // namespace datrw
230 
231 /* ----- END OF datrw.cc ----- */
sff::FREE Mfilefree
Definition: datread.h:141
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
bool Mtracefreeset
Definition: datread.h:142
macro function for debugging output (prototypes)
sff::INFO Minfo
Definition: datread.h:139
void setinfo(const sff::INFO &info)
Definition: datread.cc:121
aff::Series< float > Tfseries
Definition: types.h:46
sff::WID2 wid2() const
Definition: datread.h:111
void setfilefree(const sff::FREE &free)
Definition: datread.cc:97
sff::WID2 Mwid2
Definition: datread.h:137
static void help(std::ostream &os=std::cout, const char *name="idatsream")
print some info about data conversion.
Definition: datread.cc:153
void setsrce(const sff::SRCE &srce)
Definition: datread.cc:129
aff::Series< double > Tdseries
Definition: types.h:45
virtual Tiseries iseries()
Definition: datread.h:86
bool hasfree() const
Definition: datread.cc:72
void setwid2(const sff::WID2 &wid2)
Definition: datread.cc:113
bool debug()
indicate debug mode
Definition: datread.h:116
sff::INFO info() const
Definition: datread.h:110
idatstream(std::istream &is, const bool &providesd=false, const bool &providesf=false, const bool &providesi=false, const bool &debug=false)
Definition: datread.cc:55
Root namespace of library.
Definition: aalibdatrwxx.cc:16
sff::SRCE srce() const
Definition: datread.h:109
sff::FREE free() const
Definition: datread.cc:79
sff::FREE Mtracefree
Definition: datread.h:140
virtual Tdseries dseries()
Definition: datread.h:84
void settracefree(const sff::FREE &free)
Definition: datread.cc:105
sff::SRCE Msrce
Definition: datread.h:138
aff::Series< int > Tiseries
Definition: types.h:47
#define DATRW_debug(C, N, M)
produce debug output
Definition: debug.h:50
#define DATRW_value(V)
report value
Definition: debug.h:65
virtual Tfseries fseries()
Definition: datread.h:85
idatstream & operator>>(idatstream &is, sff::WID2 &wid2)
Definition: datread.cc:161