DATRW++ library: seismic data I/O with multiple formats
tracereader.h
Go to the documentation of this file.
1 /*! \file tracereader.h
2  * \brief provide more efficient reading of sequential traces (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 08/07/2008
8  *
9  * provide more efficient reading of sequential traces (prototypes)
10  *
11  * Copyright (c) 2008 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  * - 08/07/2008 V1.0 Thomas Forbriger
31  * - 07/09/2011 V1.1 support format modifier strings
32  * - 29/11/2011 V1.2 delegate to ianystream not idatstream
33  * - 29/11/2011 V1.3 introduced assertopen; query functions must not be
34  * called with no file being open
35  *
36  * ============================================================================
37  */
38 
39 // include guard
40 #ifndef DATRW_TRACEREADER_H_VERSION
41 
42 #define DATRW_TRACEREADER_H_VERSION \
43  "DATRW_TRACEREADER_H V1.3"
44 
45 #include <datrwxx/readany.h>
46 #include <fstream>
47 
48 namespace datrw {
49 
50  /*! \brief Sequential trace reader
51  *
52  * \ingroup group_readany
53  *
54  * this is a wrapper for ianystream reading
55  *
56  * You can select a specific trace for a given filename. The reader keeps
57  * track of the position within the file. If the previous reading operation
58  * was for the same file and the selected trace is a successor of the
59  * current trace the reader will only skip to the new trace and provide it
60  * through its interface. Only if the selected file is not yet open or if
61  * the trace is a predecessor of the selected trace, the file read from the
62  * beginning.
63  *
64  * The trace reader must provide an explicite interface to the underlying
65  * ianyread object. This is necessary to keep track of reading operations.
66  * This class provides the same access interface that idatstream provides,
67  * including input operators. You can easily replace instances if ianystream
68  * and idatstream in your code with instances of sequentialtracereader.
69  */
71  public:
72  //! constructor
73  sequentialtracereader(const bool& debug=false):
74  Mdebug(debug), Mopen(false) { }
75  //! destructor
77  /*! select a specific trace from a given file
78  *
79  * return true if successful
80  */
81  bool select(const std::string& filename,
82  const int& itrace,
83  const Eformat& format);
84  bool select(const std::string& filename,
85  const int& itrace,
86  const std::string& format);
87  bool last() const { this->assertopen(); return(MPias->last()); }
88  bool good() const { this->assertopen(); return(MPias->good()); }
89  bool hasfree() const { this->assertopen(); return(MPias->hasfree()); }
90  bool hassrce() const { this->assertopen(); return(MPias->hassrce()); }
91  bool hasinfo() const { this->assertopen(); return(MPias->hasinfo()); }
92  bool providesd() const { this->assertopen(); return(MPias->providesd()); }
93  bool providesf() const { this->assertopen(); return(MPias->providesf()); }
94  bool providesi() const { this->assertopen(); return(MPias->providesi()); }
95  sff::FREE free() const { this->assertopen(); return(MPias->free()); }
96  sff::SRCE srce() const { this->assertopen(); return(MPias->srce()); }
97  sff::INFO info() const { this->assertopen(); return(MPias->info()); }
98  sff::WID2 wid2() const { this->assertopen(); return(MPias->wid2()); }
99  void skipseries()
100  { this->assertopen(); ++Mindex; return(MPias->skipseries()); }
102  { this->assertopen(); ++Mindex; return(MPias->dseries()); }
104  { this->assertopen(); ++Mindex; return(MPias->fseries()); }
106  { this->assertopen(); ++Mindex; return(MPias->iseries()); }
107  private:
108  // assert that file is open
109  void assertopen() const;
110  // operate in debug mode
111  bool Mdebug;
112  // is there an open file?
113  bool Mopen;
114  // input stream
115  std::istream* MPis;
116  // series input stream
118  // name of open file
119  std::string Mfilename;
120  // index of current trace
121  int Mindex;
122  }; // class sequentialtracereader
123 
124  /*----------------------------------------------------------------------*/
125 
126  //@{
127  /*! \brief explicite input operator for sequentialtracereader
128  * \ingroup group_readany
129  */
131  sff::WID2& wid2)
132  { wid2=is.wid2(); return(is); }
133 
134  //! \ingroup group_readany
136  sff::SRCE& srce)
137  { srce=is.srce(); return(is); }
138 
139  //! \ingroup group_readany
141  sff::INFO& info)
142  { info=is.info(); return(is); }
143 
144  //! \ingroup group_readany
146  sff::FREE& free)
147  { free=is.free(); return(is); }
148 
149  //! \ingroup group_readany
151  Tdseries& series)
152  { series=is.dseries(); return(is); }
153 
154  //! \ingroup group_readany
156  Tfseries& series)
157  { series=is.fseries(); return(is); }
158 
159  //! \ingroup group_readany
161  Tiseries& series)
162  { series=is.iseries(); return(is); }
163  //@}
164 
165 } // namespace datrw
166 
167 #endif // DATRW_TRACEREADER_H_VERSION (includeguard)
168 
169 /* ----- END OF tracereader.h ----- */
provides all specific data reading classes (prototypes)
sff::FREE free() const
Definition: tracereader.h:95
aff::Series< float > Tfseries
Definition: types.h:46
Sequential trace reader.
Definition: tracereader.h:70
aff::Series< double > Tdseries
Definition: types.h:45
~sequentialtracereader()
destructor
Definition: tracereader.cc:47
Class to read any type of data file.
Definition: readany.h:82
sff::INFO info() const
Definition: tracereader.h:97
Root namespace of library.
Definition: aalibdatrwxx.cc:16
aff::Series< int > Tiseries
Definition: types.h:47
datrw::ianystream * MPias
Definition: tracereader.h:117
bool select(const std::string &filename, const int &itrace, const Eformat &format)
Definition: tracereader.cc:163
sequentialtracereader(const bool &debug=false)
constructor
Definition: tracereader.h:73
sff::WID2 wid2() const
Definition: tracereader.h:98
sff::SRCE srce() const
Definition: tracereader.h:96
Eformat
Definition: formats.h:54
idatstream & operator>>(idatstream &is, sff::WID2 &wid2)
Definition: datread.cc:161