DATRW++ library: seismic data I/O with multiple formats
binary.h
Go to the documentation of this file.
1 /*! \file binary.h
2  * \brief write raw binary data (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 24/02/2010
8  *
9  * write raw binary data (prototypes)
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  *
30  * REVISIONS and CHANGES
31  * - 24/02/2010 V1.0 Thomas Forbriger
32  * - 18/11/2016 V1.1 use debug flag in base class
33  *
34  * ============================================================================
35  */
36 
37 // include guard
38 #ifndef DATRW_BINARY_H_VERSION
39 
40 #define DATRW_BINARY_H_VERSION \
41  "DATRW_BINARY_H V1.1"
42 
43 #include<datrwxx/datread.h>
44 #include<datrwxx/datwrite.h>
45 #include<datrwxx/ibinstream.h>
46 #include<datrwxx/obinstream.h>
47 
48 namespace datrw {
49 
50  /*! \brief I/O module for binary data
51  *
52  * \defgroup group_binary I/O module for binary data
53  */
54 
55  /*----------------------------------------------------------------------*/
56 
57  /*! \brief internals of the binary I/O module
58  *
59  * \ingroup group_binary
60  */
61  namespace binary {
62 
63  extern const bool isbinary;
64  extern const char* const streamID;
65 
66  /*! \brief magic number to identify file type and bytesex
67  * \ingroup group_binary
68  */
69  extern const char* const magic;
70  /*! \brief a version number for files - just in case
71  * \ingroup group_binary
72  */
73  extern const short version;
74 
75  /*! \brief indicate file or trace properties
76  * \ingroup group_binary
77  */
78  enum Eflags {
79  Fsrce= (1<<0), //!< trace has SRCE header
80  Ffree= (1<<1), //!< trace has FREE header
81  Finfo= (1<<2), //!< trace has INFO header
82  Fdouble= (1<<3), //!< trace has double data
83  Ffloat= (1<<4), //!< trace has float data
84  Fint= (1<<5) //!< trace has int data
85  }; // enum Eflags
86 
87  /*! \brief abort if file flags are inconsistent
88  * \ingroup group_binary
89  */
90  void checkfileflags(const char& flags);
91  /*! \brief abort if trace flags are inconsistent
92  * \ingroup group_binary
93  */
94  void checktraceflags(const char& flags);
95 
96  } // namespace binary
97 
98  /*----------------------------------------------------------------------*/
99 
100  /*! \brief class to read binary data
101  *
102  * \ingroup group_binary
103  */
104  class ibinarystream: public idatstream {
105  public:
106  typedef idatstream Tbase;
107  ibinarystream(std::istream& is, const bool& debug=false);
108  virtual ~ibinarystream() { }
109  virtual Tdseries dseries();
110  virtual Tfseries fseries();
111  virtual Tiseries iseries();
112  virtual void skipseries();
113  static void help(std::ostream& os=std::cout);
114  static const std::ios_base::openmode openmode;
115  private:
116  void readheader();
117  void readflags();
118  void setnsamples(const unsigned int& nsamples);
120  short Mversion;
121  char Mnextflags; //!< flags for next trace
122  }; // class ibinarystream
123 
124  /*----------------------------------------------------------------------*/
125 
126  /*! \brief class to write binary
127  *
128  * \ingroup group_binary
129  */
130  class obinarystream: public odatstream {
131  public:
132  typedef odatstream Tbase;
133  obinarystream(std::ostream& os, const bool& debug=false);
134  virtual ~obinarystream();
135  static void help(std::ostream& os=std::cout);
136  static const std::ios_base::openmode openmode;
137  protected:
138  virtual void writefileheader();
139  //! write double data
140  virtual void writetrace(const Tdseries::Tcoc& series);
141  //! write single precision float data
142  virtual void writetrace(const Tfseries::Tcoc& series);
143  //! write integer data
144  virtual void writetrace(const Tiseries::Tcoc& series);
145  private:
146  void writetraceheader(const binary::Eflags&,
147  const unsigned int& nsamples);
149  }; // class obinarystream
150 
151 } // namespace datrw
152 
153 #endif // DATRW_BINARY_H_VERSION (includeguard)
154 
155 /* ----- END OF binary.h ----- */
static void help(std::ostream &os=std::cout)
obinarystream(std::ostream &os, const bool &debug=false)
const char *const streamID
Format properties.
Definition: binary.cc:48
binary::obinstream Mobs
Definition: binary.h:148
aff::Series< float > Tfseries
Definition: types.h:46
void checktraceflags(const char &flags)
abort if trace flags are inconsistent
Definition: binary.cc:66
virtual void skipseries()
void checkfileflags(const char &flags)
abort if file flags are inconsistent
Definition: binary.cc:58
trace has INFO header
Definition: binary.h:81
virtual Tfseries fseries()
odatstream Tbase
Definition: binary.h:132
ibinarystream(std::istream &is, const bool &debug=false)
const char *const magic
magic number to identify file type and bytesex
Definition: binary.cc:53
aff::Series< double > Tdseries
Definition: types.h:45
binary output for basic types and classes
Definition: obinstream.h:56
const int nsamples
number of samples per minute block and channel
Definition: hpmodata.h:51
trace has int data
Definition: binary.h:84
static void help(std::ostream &os=std::cout)
virtual void writefileheader()
actually write the file header
idatstream Tbase
Definition: binary.h:106
static const std::ios_base::openmode openmode
Definition: binary.h:114
bool debug()
indicate debug mode
Definition: datwrite.h:145
trace has SRCE header
Definition: binary.h:79
const short version
a version number for files - just in case
Definition: binary.cc:54
bool debug()
indicate debug mode
Definition: datread.h:116
trace has float data
Definition: binary.h:83
Root namespace of library.
Definition: aalibdatrwxx.cc:16
void setnsamples(const unsigned int &nsamples)
virtual void writetrace(const Tdseries::Tcoc &series)
write double data
Eflags
indicate file or trace properties
Definition: binary.h:78
trace has double data
Definition: binary.h:82
virtual Tiseries iseries()
aff::Series< int > Tiseries
Definition: types.h:47
stream like class for binary input of basic types and classes
Definition: ibinstream.h:56
virtual Tdseries dseries()
virtual ~ibinarystream()
Definition: binary.h:108
void writetraceheader(const binary::Eflags &, const unsigned int &nsamples)
class to write binary
Definition: binary.h:130
char Mnextflags
flags for next trace
Definition: binary.h:121
trace has FREE header
Definition: binary.h:80
static const std::ios_base::openmode openmode
Definition: binary.h:136
const bool isbinary
Format properties.
Definition: binary.cc:47
binary::ibinstream Mibs
Definition: binary.h:119
class to read binary data
Definition: binary.h:104
generic interface definition (prototypes)