DATRW++ library: seismic data I/O with multiple formats
datwrite.h
Go to the documentation of this file.
1 /*! \file datwrite.h
2  * \brief generic interface definition (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 11/04/2006
8  *
9  * generic interface definition (prototypes)
10  *
11  * Copyright (c) 2006 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  *
30  * REVISIONS and CHANGES
31  * - 11/04/2006 V1.0 Thomas Forbriger
32  * - 07/06/2011 V1.1 promise constness of series samples
33  * - 29/07/2011 V1.2 support property query
34  * - 18/11/2016 V1.3 provide debug flag in base class
35  *
36  * ============================================================================
37  */
38 
39 // include guard
40 #ifndef DATRW_DATWRITE_H_VERSION
41 
42 #define DATRW_DATWRITE_H_VERSION \
43  "DATRW_DATWRITE_H V1.3"
44 
45 #include<string>
46 #include<iostream>
47 #include<aff/series.h>
48 #include<sffxx.h>
49 #include<datrwxx/error.h>
50 #include<datrwxx/formats.h>
51 #include<datrwxx/properties.h>
52 #include<datrwxx/types.h>
53 
54 namespace datrw {
55 
56  /*----------------------------------------------------------------------*/
57 
58  /*! check for existing output fil
59  *
60  * aborts, if file with given filename exists
61  */
62  void abort_if_exists(const std::string& filename);
63 
64  /*----------------------------------------------------------------------*/
65 
66  /*! output stream to write seismic data (abstract base)
67  *
68  * The concept is based on SFF data contents and we will make use of SFF
69  * structures.
70  *
71  * \note
72  * Design considerations:
73  * For most data types it would be convenient to flush data traces to file
74  * upon a call to odatstream::writeseries().
75  * For this reason trace data fill be collected by setwid2, setfree, and
76  * setinfo and will be flushed to file upon a call to writeseries.
77  * Prior to writing the first trace functions odatstream::setsrce() and
78  * odatstream::setfree() can be used to write file specific data.
79  * This file header will be flushed to file upon calling
80  * odatstream::flushfileheader() or upon the first call to
81  * odatstream::setwid2().
82  * No file header fields can be written after the first call to
83  * odatstream::setwid2().
84  * odatstream::setwid2() must be called for each trace.
85  * The other fields are optional.
86  *
87  * \note
88  * Design considerations:
89  * Functions handlesfilefree(), handlessrce(), handlestracefree(),
90  * handlesinfo(), seriestype() contain constant and static
91  * functionality only. They could replaced by a static const member, like is
92  * done with openmode in derived classes. However, since it is useful to
93  * have these functions inherintance transparent, such that we cann call
94  * them from oanystream, they are implemented as ordinary members and
95  * provide data through a mechanism like is used for idatream::providesd().
96  *
97  * \note
98  * All derived classes have to provide an openmode field.
99  * This cannot be provided through the function interface, since the field
100  * is requested prior to creating an instance of the class.
101  *
102  * \note
103  * Due to the design descision just made, a copy of the series will be kept
104  * until the next trace will be written, since trace data is flushed in
105  * libsffxx upon writing the wid2 data for the next trace.
106  */
107  class odatstream {
108  public:
109  virtual ~odatstream() { }
110  void setfree(const sff::FREE& free);
111  void setwid2(const sff::WID2& wid2);
112  void setsrce(const sff::SRCE& srce);
113  void setinfo(const sff::INFO& info);
114  //! write double data
115  void writeseries(const Tdseries::Tcoc& series);
116  //! write single precision float data
117  void writeseries(const Tfseries::Tcoc& series);
118  //! write integer data
119  void writeseries(const Tiseries::Tcoc& series);
120  //! flush file header to file
121  void flushfileheader();
122  //! true if file FREE block can be handled
123  bool handlesfilefree() const { return(Mhandlesfilefree); }
124  //! true if SRCE data can be handled
125  bool handlessrce() const { return(Mhandlessrce); }
126  //! true if trace FREE block can be handled
127  bool handlestracefree() const { return(Mhandlestracefree); }
128  //! true if INFO data can be handled
129  bool handlesinfo() const { return(Mhandlesinfo); }
130  /*! indicate type of series data
131  * \deprecated
132  * The use of Edatatype flags is deprecated and will be replaced by
133  * a more verbose class or struct which can be extended in the future
134  */
135  Edatatype seriestype() const { return(Mdatatype); }
136 
137  //! \brief query properties
138  Properties properties() const;
139 
140  //! print some info about data conversion.
141  static void help(std::ostream& os=std::cout,
142  const char* name="idatsream");
143 
144  //! indicate debug mode
145  bool debug() { return Mdebug; }
146  //! set debug mode
147  void debug(const bool& debug) { Mdebug=debug; }
148  protected:
149  //! constructor is protected: do not create an instance of this class
150  odatstream(std::ostream& os,
151  const Edatatype& datatype,
152  const bool& handlesfilefree=false,
153  const bool& handlestracefree=false,
154  const bool& handlessrce=false,
155  const bool& handlesinfo=false,
156  const bool& debug=false);
157  //! write double data
158  virtual void writetrace(const Tdseries::Tcoc& series) { DATRW_illegal; }
159  //! write single precision float data
160  virtual void writetrace(const Tfseries::Tcoc& series) { DATRW_illegal; }
161  //! write integer data
162  virtual void writetrace(const Tiseries::Tcoc& series) { DATRW_illegal; }
163  //! actually write the file header
164  virtual void writefileheader() { DATRW_illegal; }
165  //! clear trace header flags
166  void cleartraceheader();
167 
168  //! return WID2 data
169  sff::WID2 wid2() const { return(Mwid2); }
170  //! return SRCE data
171  sff::SRCE srce() const { return(Msrce); }
172  //! return SRCE data
173  sff::INFO info() const { return(Minfo); }
174  //! return FREE data
175  sff::FREE free() const { return(Mfree); }
176 
177  //! wid2 is available
178  bool haswid2() const { return(Mwid2set); }
179  //! srce is available
180  bool hassrce() const { return(Msrceset); }
181  //! info is available
182  bool hasinfo() const { return(Minfoset); }
183  //! free is available
184  bool hasfree() const { return(Mfreeset); }
185 
186  /*! tell the specific data type used
187  * \deprecated
188  * The use of Edatatype flags is deprecated and will be replaced by
189  * a more verbose class or struct which can be extended in the future
190  */
191  void setdatatype(const Edatatype& daty) { Mdatatype=daty; }
192 
193  //! output stream to be used by this class
194  std::ostream& Mos;
195 
196  //! global debug flag
197  bool Mdebug;
198  private:
203  /*! the specific internal data type
204  * \deprecated
205  * The use of Edatatype flags is deprecated and will be replaced by
206  * a more verbose class or struct which can be extended in the future
207  */
209  sff::WID2 Mwid2;
210  sff::SRCE Msrce;
211  sff::INFO Minfo;
212  sff::FREE Mfree;
213  }; // class odatstream
214 
215  /*----------------------------------------------------------------------*/
216 
217  inline odatstream& operator<<(odatstream& os, const sff::WID2& wid2)
218  { os.setwid2(wid2); return(os); }
219 
220  inline odatstream& operator<<(odatstream& os, const sff::SRCE& srce)
221  { os.setsrce(srce); return(os); }
222 
223  inline odatstream& operator<<(odatstream& os, const sff::INFO& info)
224  { os.setinfo(info); return(os); }
225 
226  inline odatstream& operator<<(odatstream& os, const sff::FREE& free)
227  { os.setfree(free); return(os); }
228 
229  inline odatstream& operator<<(odatstream& os, const Tdseries::Tcoc& series)
230  { os.writeseries(series); return(os); }
231 
232  inline odatstream& operator<<(odatstream& os, const Tfseries::Tcoc& series)
233  { os.writeseries(series); return(os); }
234 
235  inline odatstream& operator<<(odatstream& os, const Tiseries::Tcoc& series)
236  { os.writeseries(series); return(os); }
237 
238 } // namespace datrw
239 
240 #endif // DATRW_DATWRITE_H_VERSION (includeguard)
241 
242 /* ----- END OF datrw.h ----- */
odatstream(std::ostream &os, const Edatatype &datatype, const bool &handlesfilefree=false, const bool &handlestracefree=false, const bool &handlessrce=false, const bool &handlesinfo=false, const bool &debug=false)
constructor is protected: do not create an instance of this class
Definition: datwrite.cc:87
void abort_if_exists(const std::string &filename)
Definition: datwrite.cc:49
Edatatype seriestype() const
Definition: datwrite.h:135
internal data types (prototypes)
bool hasinfo() const
info is available
Definition: datwrite.h:182
void writeseries(const Tdseries::Tcoc &series)
write double data
Definition: datwrite.cc:195
void debug(const bool &debug)
set debug mode
Definition: datwrite.h:147
void cleartraceheader()
clear trace header flags
Definition: datwrite.cc:186
properties base class.
Definition: properties.h:58
Properties properties() const
query properties
void setwid2(const sff::WID2 &wid2)
Definition: datwrite.cc:130
void setdatatype(const Edatatype &daty)
Definition: datwrite.h:191
bool hassrce() const
srce is available
Definition: datwrite.h:180
Edatatype
Definition: formats.h:84
static void help(std::ostream &os=std::cout, const char *name="idatsream")
print some info about data conversion.
Definition: datwrite.cc:228
void setfree(const sff::FREE &free)
Definition: datwrite.cc:110
sff::WID2 wid2() const
return WID2 data
Definition: datwrite.h:169
std::ostream & Mos
output stream to be used by this class
Definition: datwrite.h:194
bool haswid2() const
wid2 is available
Definition: datwrite.h:178
void setinfo(const sff::INFO &info)
Definition: datwrite.cc:141
sff::SRCE Msrce
Definition: datwrite.h:210
exception class declaration for libdatrwxx (prototypes)
sff::INFO info() const
return SRCE data
Definition: datwrite.h:173
bool debug()
indicate debug mode
Definition: datwrite.h:145
sff::INFO Minfo
Definition: datwrite.h:211
bool handlesfilefree() const
true if file FREE block can be handled
Definition: datwrite.h:123
void flushfileheader()
flush file header to file
Definition: datwrite.cc:167
Root namespace of library.
Definition: aalibdatrwxx.cc:16
sff::SRCE srce() const
return SRCE data
Definition: datwrite.h:171
void setsrce(const sff::SRCE &srce)
Definition: datwrite.cc:154
bool handlesinfo() const
true if INFO data can be handled
Definition: datwrite.h:129
virtual ~odatstream()
Definition: datwrite.h:109
sff::FREE free() const
return FREE data
Definition: datwrite.h:175
virtual void writetrace(const Tdseries::Tcoc &series)
write double data
Definition: datwrite.h:158
sff::FREE Mfree
Definition: datwrite.h:212
odatstream & operator<<(odatstream &os, const sff::WID2 &wid2)
Definition: datwrite.h:217
describe data properties (prototypes)
virtual void writefileheader()
actually write the file header
Definition: datwrite.h:164
bool Mdebug
global debug flag
Definition: datwrite.h:197
bool handlessrce() const
true if SRCE data can be handled
Definition: datwrite.h:125
bool Mhandlesfilefree
Definition: datwrite.h:201
virtual void writetrace(const Tfseries::Tcoc &series)
write single precision float data
Definition: datwrite.h:160
bool hasfree() const
free is available
Definition: datwrite.h:184
sff::WID2 Mwid2
Definition: datwrite.h:209
common description of formats (prototypes)
bool handlestracefree() const
true if trace FREE block can be handled
Definition: datwrite.h:127
#define DATRW_illegal
Definition: error.h:108
Edatatype Mdatatype
Definition: datwrite.h:208
virtual void writetrace(const Tiseries::Tcoc &series)
write integer data
Definition: datwrite.h:162
bool Mhandlestracefree
Definition: datwrite.h:201