DATRW++ library: seismic data I/O with multiple formats
obinarystream.cc
Go to the documentation of this file.
1 /*! \file obinarystream.cc
2  * \brief output raw binary data (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 18/10/2011
8  *
9  * output raw binary data (implementation)
10  *
11  * Copyright (c) 2011 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  * - 18/10/2011 V1.0 Thomas Forbriger
32  * - 18/11/2016 V1.1 use debug flag in base class
33  *
34  * ============================================================================
35  */
36 #define DATRW_OBINARYSTREAM_CC_VERSION \
37  "DATRW_OBINARYSTREAM_CC V1.1"
38 
39 #include<datrwxx/binary.h>
40 #include<datrwxx/debug.h>
41 
42 namespace datrw {
43 
44  const std::ios_base::openmode
45  obinarystream::openmode=std::ios_base::out|std::ios_base::binary;
46 
47  /*----------------------------------------------------------------------*/
48 
49  obinarystream::obinarystream(std::ostream& os, const bool& debug):
50  Tbase(os, Fall, true, true, true, true, debug),
51  Mobs(os, ::datrw::binary::magic, Mdebug)
52  //Mobs(os, ::datrw::binary::magic, debug)
53  {
54  DATRW_debug(Mdebug, "obinarystream::obinarystream",
55  "new stream");
56  } // obinarystream::obinarystream(std::ostream& os, const bool& debug=false)
57 
58  /*----------------------------------------------------------------------*/
59 
61  {
62  } // obinarystream::~obinarystream()
63 
64  /*----------------------------------------------------------------------*/
65 
67  {
68  DATRW_debug(Mdebug, "obinarystream::writefileheader",
69  "file version " << ::datrw::binary::version);
71  char flags=0;
72  if (this->hassrce()) { flags |= binary::Fsrce; }
73  if (this->hasfree()) { flags |= binary::Ffree; }
74  DATRW_debug(Mdebug, "obinarystream::writefileheader()",
75  "flags: " << DATRW_value( int(flags) ));
76  Mobs << flags;
77  if (this->hassrce())
78  {
79  DATRW_debug(Mdebug, "obinarystream::writefileheader",
80  "writing SRCE line");
81  Mobs << this->srce();
82  }
83  if (this->hasfree())
84  {
85  DATRW_debug(Mdebug, "ibinarystream::ibinarystream",
86  "writing file FREE block");
87  Mobs << this->free();
88  }
89  } // void obinarystream::writefileheader()
90 
91  /*----------------------------------------------------------------------*/
92 
94  const unsigned int& nsamples)
95  {
96  char flags=datatype;
97  if (this->hasinfo()) { flags |= binary::Finfo; }
98  if (this->hasfree()) { flags |= binary::Ffree; }
99  DATRW_debug(Mdebug, "obinarystream::writetraceheader()",
100  "flags: " << DATRW_value( int(flags) ));
101  Mobs << flags;
102  ::sff::WID2 wid2=this->wid2();
103  wid2.nsamples=nsamples;
104  Mobs << wid2;
105  if (this->hasinfo()) { Mobs << this->info(); }
106  if (this->hasfree()) { Mobs << this->free(); }
107  } // void obinarystream::writetraceheader()
108 
109  /*----------------------------------------------------------------------*/
110 
111  void obinarystream::writetrace(const Tdseries::Tcoc& series)
112  {
113  this->writetraceheader(binary::Fdouble, series.size());
114  Mobs.write(series);
115  } // void obinarystream::writetrace(const Tdseries& series)
116 
117  /*----------------------------------------------------------------------*/
118 
119  void obinarystream::writetrace(const Tfseries::Tcoc& series)
120  {
121  this->writetraceheader(binary::Ffloat, series.size());
122  Mobs.write(series);
123  } // void obinarystream::writetrace(const Tfseries& series)
124 
125  /*----------------------------------------------------------------------*/
126 
127  void obinarystream::writetrace(const Tiseries::Tcoc& series)
128  {
129  this->writetraceheader(binary::Fint, series.size());
130  Mobs.write(series);
131  } // oid obinarystream::writetrace(const Tiseries& series)
132 
133  /*----------------------------------------------------------------------*/
134 
135  void obinarystream::help(std::ostream& os)
136  {
137  os <<
138  std::endl <<
139  "BINARY writing functions" << std::endl <<
140  "------------------------" << std::endl <<
141  DATRW_OBINARYSTREAM_CC_VERSION << std::endl <<
142  std::endl;
143  os <<
144  "This module writes data in its simple binary representaion.\n"
145  "It is provided primarily for input/output efficiency. This format\n"
146  "does not require any output or input formatting. It also does not\n"
147  "require conversion of sample values. For this reason no round-off\n"
148  "will take place, not for the sample values and not for the sampling\n"
149  "interval. The format maps memory content to file and is lossless\n"
150  "for this reason. The file is identified by a magic number. This\n"
151  "allows the input module to perform automatic on-the-fly\n"
152  "byte-swapping if required by the CPU type in use.\n"
153  << std::endl;
154  } // void obinarystream::help(std::ostream& os)
155 
156 } // namespace datrw
157 
158 /* ----- END OF obinarystream.cc ----- */
obinarystream(std::ostream &os, const bool &debug=false)
bool hasinfo() const
info is available
Definition: datwrite.h:182
binary::obinstream Mobs
Definition: binary.h:148
#define DATRW_OBINARYSTREAM_CC_VERSION
macro function for debugging output (prototypes)
bool hassrce() const
srce is available
Definition: datwrite.h:180
trace has INFO header
Definition: binary.h:81
sff::WID2 wid2() const
return WID2 data
Definition: datwrite.h:169
write raw binary data (prototypes)
const char *const magic
magic number to identify file type and bytesex
Definition: binary.cc:53
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
sff::INFO info() const
return SRCE data
Definition: datwrite.h:173
trace has SRCE header
Definition: binary.h:79
void write(const char &v)
Definition: obinstream.cc:59
const short version
a version number for files - just in case
Definition: binary.cc:54
trace has float data
Definition: binary.h:83
Root namespace of library.
Definition: aalibdatrwxx.cc:16
sff::SRCE srce() const
return SRCE data
Definition: datwrite.h:171
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
sff::FREE free() const
return FREE data
Definition: datwrite.h:175
#define DATRW_debug(C, N, M)
produce debug output
Definition: debug.h:50
bool Mdebug
global debug flag
Definition: datwrite.h:197
void writetraceheader(const binary::Eflags &, const unsigned int &nsamples)
trace has FREE header
Definition: binary.h:80
#define DATRW_value(V)
report value
Definition: debug.h:65
bool hasfree() const
free is available
Definition: datwrite.h:184
static const std::ios_base::openmode openmode
Definition: binary.h:136