DATRW++ library: seismic data I/O with multiple formats
readany.cc
Go to the documentation of this file.
1 /*! \file readany.cc
2  * \brief read any type (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 06/04/2004
8  *
9  * read any type (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  * - 06/04/2004 V1.0 Thomas Forbriger
31  * - 16/09/2004 V1.1 activate isffstream
32  * - 23/12/2004 V1.2 activate ihpmostream
33  * - 29/06/2007 V1.3 added SAC binary format
34  * - 19/09/2007 V1.4 added raw GSE format
35  * - 12/11/2009 V1.5 added TSOFT format
36  * - 03/05/2010 V1.6 sac provides debugging
37  * - 06/10/2010 V1.7 added ASCII format of T. Forbrigers any2ascii
38  * - 23/11/2010 V1.8 use static member data
39  * - 25/11/2010 V1.9 add Seismic Unix format
40  * - 29/07/2011 V1.10 support format modifiers
41  * - 02/09/2011 V1.11 support seife format
42  * - 06/09/2011 V1.12 make non-subformat constructor deprecated
43  * - 07/09/2011 V1.13 more string type format ID support: openmode
44  * - 13/09/2011 V1.14 imseedstream now supports modifiers too
45  * - 04/11/2011 V1.15 make Thies DL1 input module visible
46  * - 07/11/2011 V1.16 make ASCII input module visible
47  * - 19/11/2011 V1.17 provide binary input
48  * - 05/12/2011 V1.18 itsoftstream takes format modifiers
49  * - 21/01/2012 V1.19 prepared isustream to take modifiers
50  * - 18/11/2016 V1.20 set debug mode in base class
51  *
52  * ============================================================================
53  */
54 #define DATRW_READANY_CC_VERSION \
55  "DATRW_READANY_CC V1.20"
56 
57 #include <datrwxx/readany.h>
58 #include <datrwxx/sff.h>
59 #include <datrwxx/pdas.h>
60 #include <datrwxx/hpmo.h>
61 #include <datrwxx/mseed.h>
62 #include <datrwxx/bonjer.h>
63 #include <datrwxx/sac.h>
64 #include <datrwxx/gse.h>
65 #include <datrwxx/tsoft.h>
66 #include <datrwxx/tfascii.h>
67 #include <datrwxx/su.h>
68 #include <datrwxx/seife.h>
69 #include <datrwxx/error.h>
70 #include <datrwxx/formatmodifier.h>
71 #include <datrwxx/util.h>
72 #include <datrwxx/thiesdl1.h>
73 #include <datrwxx/ascii.h>
74 #include <datrwxx/binary.h>
75 #include <datrwxx/report.h>
76 
77 namespace datrw {
78 
79  /*! return whether the specific format is a binary data format
80  *
81  * \param format selected data format
82  * \return \c true, if data format is binary
83  */
84  bool isbinary(const Eformat& format)
85  {
86  bool retval=false;
87  if (format==Fbonjer) { retval=bonjer::isbinary; }
88  else if (format==Fpdas) { retval=pdas::isbinary; }
89  else if (format==Fsff) { retval=sff::isbinary; }
90  else if (format==Fhpmo) { retval=hpmo::isbinary; }
91  else if (format==Fmseed) { retval=mseed::isbinary; }
92  else if (format==Fsac) { retval=sac::isbinary; }
93  else if (format==Fgse) { retval=gse::isbinary; }
94  else if (format==Ftsoft) { retval=tsoft::isbinary; }
95  else if (format==Ftfascii) { retval=tfascii::isbinary; }
96  else if (format==Fsu) { retval=su::isbinary; }
97  else if (format==Fseife) { retval=seife::isbinary; }
98  else if (format==Fthiesdl1) { retval=thiesdl1::isbinary; }
99  else if (format==Fascii) { retval=ascii::isbinary; }
100  else if (format==Fbinary) { retval=binary::isbinary; }
101  else
102  { DATRW_abort("ERROR (isbinary): unknown format!"); }
103  return(retval);
104  } // bool isbinary(const Eformat& format)
105 
106  /*----------------------------------------------------------------------*/
107 
108  /*! return appropriate file stream open mode for selected format
109  */
110  std::ios_base::openmode ianystream::openmode(const std::string& format)
111  {
112  return(ianystream::openmode(anyID(format)));
113  } // std::ios_base::openmode ianystream::openmode(std::string format)
114 
115  /*----------------------------------------------------------------------*/
116 
117  /*! return appropriate file stream open mode for selected format
118  */
119  std::ios_base::openmode ianystream::openmode(const Eformat& format)
120  {
121  std::ios_base::openmode retval;
122  if (format==Fbonjer) { retval=ibonjerstream::openmode; }
123  else if (format==Fpdas) { retval=ipdasstream::openmode; }
124  else if (format==Fsff) { retval=isffstream::openmode; }
125  else if (format==Fhpmo) { retval=ihpmostream::openmode; }
126  else if (format==Fmseed) { retval=imseedstream::openmode; }
127  else if (format==Fsac) { retval=isacstream::openmode; }
128  else if (format==Fgse) { retval=igsestream::openmode; }
129  else if (format==Ftsoft) { retval=itsoftstream::openmode; }
130  else if (format==Ftfascii) { retval=itfasciistream::openmode; }
131  else if (format==Fsu) { retval=isustream::openmode; }
132  else if (format==Fseife) { retval=iseifestream::openmode; }
133  else if (format==Fthiesdl1) { retval=ithiesdl1stream::openmode; }
134  else if (format==Fascii) { retval=iasciistream::openmode; }
135  else if (format==Fbinary) { retval=ibinarystream::openmode; }
136  else
137  { DATRW_abort("ERROR (openmode): unknown format!"); }
138  return(retval);
139  } // std::ios_base::openmode ianystream::openmode(const Eformat& format)
140 
141  /*----------------------------------------------------------------------*/
142 
143  ianystream::ianystream(std::istream& is, const Eformat& format,
144  const bool& debug)
145  {
146  datrw::util::report_deprecated("ianystream::ianystream(std::istream& is, "
147  "const Eformat& format)",
148  "this constructor does not support format modifiers");
149  this->open(is, anyID(format), debug);
150  }
151 
152  /*----------------------------------------------------------------------*/
153 
154  ianystream::ianystream(std::istream& is, const std::string& format,
155  const bool& debug)
156  {
157  this->open(is, format, debug);
158  }
159 
160  /*----------------------------------------------------------------------*/
161 
162  void ianystream::open(std::istream& is, std::string format,
163  const bool& debug)
164  {
165  std::string formatstring=util::clipstring(format);
166  std::string& modifiers=format;
167  Mformat=anyID(formatstring);
168  if (Mformat==Fbonjer)
169  {
171  Mis=new ibonjerstream(is);
172  }
173  else if (Mformat==Fpdas)
174  {
176  Mis=new ipdasstream(is);
177  }
178  else if (Mformat==Fsff)
179  {
181  Mis=new isffstream(is);
182  }
183  else if (Mformat==Fhpmo)
184  {
186  Mis=new ihpmostream(is);
187  }
188  else if (Mformat==Fmseed)
189  {
190  Mis=new imseedstream(is, modifiers);
191  }
192  else if (Mformat==Fsac)
193  {
195  Mis=new isacstream(is);
196  }
197  else if (Mformat==Fgse)
198  {
200  Mis=new igsestream(is);
201  }
202  else if (Mformat==Ftsoft)
203  {
204  Mis=new itsoftstream(is, modifiers);
205  }
206  else if (Mformat==Ftfascii)
207  {
209  Mis=new itfasciistream(is);
210  }
211  else if (Mformat==Fsu)
212  {
213  Mis=new isustream(is, modifiers);
214  }
215  else if (Mformat==Fseife)
216  {
217  Mis=new iseifestream(is, modifiers);
218  }
219  else if (Mformat==Fthiesdl1)
220  {
221  Mis=new ithiesdl1stream(is, modifiers);
222  }
223  else if (Mformat==Fascii)
224  {
225  Mis=new iasciistream(is, modifiers);
226  }
227  else if (Mformat==Fbinary)
228  {
230  Mis=new ibinarystream(is);
231  }
232  else
233  { DATRW_abort("ERROR (ianystream): unknown format!"); }
234  Mis->debug(debug);
235  }
236 
237  /*----------------------------------------------------------------------*/
238 
240  {
241  delete Mis;
242  }
243 
244 } // namespace datrw
245 
246 /*======================================================================*/
247 
248 /*! \page page_formats Supported formats
249  *
250 
251  Currently supported \b input \b formats are:
252  - mseed: MiniSEED (SeisComP, EDL, etc.), see: \subpage page_mseed
253  - pdas: PDAS100 (i.e. DaDisp)
254  - sac: SAC binary format
255  - sff: Stuttgart File Format
256  - gse: raw GSE format
257  - hpmo: HP-MO data format defined by W. Grossmann (BFO)
258  - bonjer: K2 ASCII data format (defined by K. Bonjer?)
259  - tsoft: TSOFT format (http://seismologie.oma.be/TSOFT/tsoft.html)
260  - tfascii: output data of T. Forbriger's any2ascii
261  - su: SeismicUn*x format
262  - seife: seife format (E. Wielandt), see: \subpage page_seife_format
263  - thiesdl1: Thies DL1 pluviometer at BFO, see: \subpage page_thiesdl1_format
264  - ascii: simple one column raw ASCII data
265  - bin: binary data dumped from memory to disk
266  */
267 
268 /* ----- END OF readany.cc ----- */
static const std::ios_base::openmode openmode
Definition: gse.h:69
class to read seife data
Definition: seife.h:64
provides all specific data reading classes (prototypes)
input stream to read seismic data provided by T. Forbriger&#39;s any2ascii
Definition: tfascii.h:64
static const std::ios_base::openmode openmode
Definition: pdas.h:73
class to read HPMO data
Definition: hpmo.h:61
read Thomas Forbrigers ASCII data (prototypes)
seife reading and writing module (prototypes)
provide format modifiers (prototypes)
const bool isbinary
Format properties.
Definition: itsoftstream.cc:56
static const std::ios_base::openmode openmode
Definition: mseed.h:175
static const std::ios_base::openmode openmode
Definition: bonjer.h:74
const bool isbinary
Format properties.
Definition: igsestream.cc:54
void report_deprecated(const std::string &function, const std::string &reason)
report deprecated function
Definition: report.cc:113
datrw::idatstream * Mis
Definition: readany.h:127
Eformat anyID(std::string formatstring)
convert identifier from and to string representation
Definition: formats.cc:68
static const std::ios_base::openmode openmode
Definition: sac.h:71
static const std::ios_base::openmode openmode
Definition: ascii.h:78
write raw binary data (prototypes)
read SAC files (prototypes)
class to read Thies DL1 data
Definition: thiesdl1.h:64
read sff data (prototypes)
class to read mini-SEED data
Definition: mseed.h:163
ianystream(std::istream &, const Eformat &format, const bool &debug=false)
deprecated constructor, not taking format modifier
Definition: readany.cc:143
const bool isbinary
Format properties.
class to read SFF data
Definition: sff.h:76
static const std::ios_base::openmode openmode
Definition: hpmo.h:72
const bool isbinary
Format properties.
Definition: ihpmostream.cc:54
exception class declaration for libdatrwxx (prototypes)
bool isbinary(const Eformat &format)
true, if underlying file format is binary
Definition: readany.cc:84
static const std::ios_base::openmode openmode
Definition: binary.h:114
bool debug()
indicate debug mode
Definition: readany.h:116
static const std::ios_base::openmode openmode
Definition: seife.h:76
bool debug()
indicate debug mode
Definition: datread.h:116
const bool isbinary
Format properties.
Root namespace of library.
Definition: aalibdatrwxx.cc:16
const bool isbinary
Format properties.
Definition: isacstream.cc:57
class to read TSOFT data
Definition: tsoft.h:63
read PDAS data (prototypes)
utilities used by more than one type of data reader (prototypes)
class to read SAC binary data
Definition: sac.h:61
#define DATRW_abort(M)
Abort and give a message.
Definition: error.h:101
input stream to read seismic data provided by K. Bonjer
Definition: bonjer.h:62
static const std::ios_base::openmode openmode
Definition: su.h:87
module to read ThiesDL1 data files (prototypes)
const bool isbinary
Format properties.
Definition: asciiformat.cc:46
read raw GSE data (prototypes)
const bool isbinary
Format properties.
Definition: suformat.cc:51
class to read raw GSE data
Definition: gse.h:59
const bool isbinary
Format properties.
read bonjers ASCII data (prototypes)
class to read ascii data
Definition: ascii.h:66
static const std::ios_base::openmode openmode
Definition: tfascii.h:97
std::string clipstring(std::string &s, const std::string &delim)
strip substringStrips off first substring up to given delimiter. The string is passed as a reference ...
Definition: util.cc:105
datrw::Eformat Mformat
Definition: readany.h:128
provide data from HP Mo (BFO data acquisition system) (prototypes)
provide mini-SEED data (prototypes)
static const std::ios_base::openmode openmode
Definition: sff.h:87
#define DATRW_expect_no_modifier(F, M)
Issue warning if modifiers are passed but not evaluated.
const bool isbinary
Format properties.
Definition: seifeformat.cc:52
read Seismic Unix data (prototypes)
static const std::ios_base::openmode openmode
Definition: thiesdl1.h:76
classes for TSOFT in SFF (prototypes)
const bool isbinary
Format properties.
Definition: ipdasstream.cc:55
Eformat
Definition: formats.h:54
const bool isbinary
Format properties.
Definition: imseedstream.cc:67
const bool isbinary
Format properties.
Definition: isffstream.cc:58
class to read SeismicUnix data
Definition: su.h:76
const bool isbinary
Format properties.
Definition: binary.cc:47
static const std::ios_base::openmode openmode
Definition: tsoft.h:75
class to read PDAS data
Definition: pdas.h:63
interface to write ASCII data (prototypes)
void open(std::istream &os, std::string format, const bool &debug=false)
actually open stream (to be called by constructor)
Definition: readany.cc:162
class to read binary data
Definition: binary.h:104
report errors and warnings (prototypes)