DATRW++ library: seismic data I/O with multiple formats
osustream.cc
Go to the documentation of this file.
1 /*! \file osustream.cc
2  * \brief SeismicUnix output stream (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 03/12/2010
8  *
9  * SeismicUnix output stream (implementation)
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  * REVISIONS and CHANGES
30  * - 03/12/2010 V1.0 Thomas Forbriger
31  * - 07/06/2011 V1.1 promise constness of series samples
32  * - 21/01/2012 V1.2
33  * - prepared osustream to take modifiers
34  * - use SUHeaderControl to store format modifier values
35  * - 24/01/2012 V1.3 output modifiers are evaluated in dedicated function
36  * - 18/11/2016 V1.4 use debug flag in base class
37  *
38  * ============================================================================
39  */
40 #define DATRW_OSUSTREAM_CC_VERSION \
41  "DATRW_OSUSTREAM_CC V1.4"
42 
43 #include <datrwxx/su.h>
44 #include <datrwxx/error.h>
45 #include <datrwxx/debug.h>
46 #include <datrwxx/util.h>
47 #include <datrwxx/suformat.h>
48 #include <datrwxx/sucomanager.h>
49 #include <datrwxx/formatmodifier.h>
50 
51 namespace datrw {
52 
53  const std::ios_base::openmode
54  osustream::openmode=std::ios_base::out|std::ios_base::binary;
55 
56  /*----------------------------------------------------------------------*/
57 
58  osustream::osustream(std::ostream& os,
59  const std::string& modifier,
60  const bool& debug):
61  Tbase(os, Ffloat, false, false, true, true, debug),
62  Mitrace(0)
63  {
64  DATRW_debug(Mdebug, "osustream::osustream",
65  "new instance established");
66  // evaluate format modifiers
68  } // osustream::osustream(std::ostream& os, const bool& debug)
69 
70  /*----------------------------------------------------------------------*/
71 
72  void osustream::help(std::ostream& os)
73  {
74  os <<
75  std::endl <<
76  "SeismicUn*x writing functions" << std::endl <<
77  "-----------------------------" << std::endl <<
78  DATRW_OSUSTREAM_CC_VERSION << std::endl <<
79  std::endl <<
80  "This module provides writing of SeismicUn*x binary data files."
81  << std::endl;
82  os << std::endl;
84  os << std::endl;
85  os <<
86  "Valid format modifiers are:\n";
89  "Force writing of ultrasonic data header\n";
90  mh() << "The default is to write standard SeismicUn*x\n";
91  mh() << "headers for seismic sampling intervals.\n";
93  "Force writing of seismic data header even\n";
94  mh() << "is sampling interval is too small.\n";
95  mh() << "Choosing both modifiers at once is an\n";
96  mh() << "inconsistency and causes abort().\n";
97  mh(su::subformat::key::scalco, "s") <<
98  "\"s\" is used as the preferred scalco and scalel value.\n";
99  mh() << "It is used only if it does not cause round-off truncation.\n";
100  mh() << "The default is "
101  << su::subformat::key::scalco << "="
104  "Limits the maximum number of significant digits in\n";
105  mh() << "spatial coordinates to \"n\". Coordinate values with\n";
106  mh() << "more digits will be truncated.\n";
107  mh() << "The default is "
110  } // void osustream::help(std::ostream& os=std::cout)
111 
112  /*----------------------------------------------------------------------*/
113 
114  /*! \brief Should write file header, but SU does not have one.
115  *
116  * Silently return from this function.
117  * The Seismic Un*x format does not have a file header.
118  */
120  {
121  DATRW_debug(Mdebug, "osustream::writefileheader()",
122  "empty function; must be provided for consistent interface");
123  } // void osustream::writefileheader()
124 
125  /*----------------------------------------------------------------------*/
126 
127  //! write double data by passing samples to float function
128  void osustream::writetrace(const Tdseries::Tcoc& series)
129  {
130  this->writetrace(::datrw::util::convert<Tdseries::Tcoc,Tfseries>(series));
131  } // void osustream::writetrace(const Tdseries& series)
132 
133  /*----------------------------------------------------------------------*/
134 
135  //! write int data by passing samples to float function
136  void osustream::writetrace(const Tiseries::Tcoc& series)
137  {
138  this->writetrace(::datrw::util::convert<Tiseries::Tcoc,Tfseries>(series));
139  } // void osustream::writetrace(const Tiseries& series)
140 
141  /*----------------------------------------------------------------------*/
142 
143  //! actually write trace data
144  void osustream::writetrace(const Tfseries::Tcoc& series)
145  {
146  DATRW_debug(Mdebug, "osustream::writetrace(const Tfseries& series)",
147  "actually write trace");
148  ++Mitrace;
150  ::sff::WID2 wid2=this->wid2();
151  wid2.nsamples=series.size();
152  header.set(wid2);
153  ::sff::SRCE srce=this->srce();
154  if (!this->hassrce())
155  {
156  // prepare SRCE data from wid2 data
157  srce.date=wid2.date;
158  }
159  ::sff::INFO info=this->info();
160  if (!this->hasinfo())
161  {
162  // prepare INFO data from
163  info.cx=static_cast<double>(Mitrace);
164  }
165  header.set(srce);
166  header.set(info);
167  header.Mheader.tracr=Mitrace;
168  header.write(Mos);
169  // write samples to file
170  Mos.write(reinterpret_cast<const char *>(series.pointer()),
171  series.size()*sizeof(Tfseries::Tvalue));
172  DATRW_debug(Mdebug, "osustream::writetrace(const Tfseries& series)",
173  "wrote " << series.size() << " samples of "
174  << sizeof(Tfseries::Tvalue) << " bytes size; "
175  << "Mos.good() returns " << Mos.good());
176  } // void osustream::writetrace(const Tfseries& series)
177 
178 } // namespace datrw
179 
180 /* ----- END OF osustream.cc ----- */
bool hasinfo() const
info is available
Definition: datwrite.h:182
unsigned int Mitrace
Definition: su.h:115
provide format modifiers (prototypes)
macro function for debugging output (prototypes)
bool hassrce() const
srce is available
Definition: datwrite.h:180
const char *const scalco
set desired scalco value
Definition: suformat.cc:64
sff::WID2 wid2() const
return WID2 data
Definition: datwrite.h:169
C++ class to handle Seismic Un*x header struct.
Definition: suheader.h:123
static const std::ios_base::openmode openmode
Definition: su.h:108
const char *const forceseismic
understand data file as seismic data file in any case
Definition: suformat.cc:61
std::ostream & Mos
output stream to be used by this class
Definition: datwrite.h:194
int tracr
Trace sequence number within SEG Y file.
Help formatting modifier online help.
#define DATRW_OSUSTREAM_CC_VERSION
Definition: osustream.cc:40
exception class declaration for libdatrwxx (prototypes)
sff::INFO info() const
return SRCE data
Definition: datwrite.h:173
virtual void writetrace(const Tdseries::Tcoc &series)
write double data by passing samples to float function
Definition: osustream.cc:128
int Tvalue
Definition: pdasread.h:75
Root namespace of library.
Definition: aalibdatrwxx.cc:16
sff::SRCE srce() const
return SRCE data
Definition: datwrite.h:171
const short scalco
default scalco value
Definition: suformat.cc:74
void set(const datrw::su::options::SUHeaderControl &hc)
set control parameters
Definition: suheader.h:129
utilities used by more than one type of data reader (prototypes)
void write(std::ostream &os) const
write struct to file
Definition: suheader.cc:96
static void help(std::ostream &os=std::cout)
Definition: osustream.cc:72
const char *const forceultrasonic
understand data file as ultrasonic data file in any case
Definition: suformat.cc:62
virtual void writefileheader()
Should write file header, but SU does not have one.
Definition: osustream.cc:119
#define DATRW_debug(C, N, M)
produce debug output
Definition: debug.h:50
bool Mdebug
global debug flag
Definition: datwrite.h:197
osustream(std::ostream &os, const std::string &modifier="", const bool &debug=false)
Definition: osustream.cc:58
datrw::su::options::SUHeaderControl Mheadercontrol
Definition: su.h:116
const char *const coodigits
maximum number of significant digits to be used
Definition: suformat.cc:63
read Seismic Unix data (prototypes)
const unsigned int coodigits
default maximum number of significant digits to be used
Definition: suformat.cc:73
static void help(std::ostream &os)
print online help regarding header fields and TOAST data
Definition: suheader.cc:548
TraceHeaderStruct Mheader
the actual data fields are provided for public access
Definition: suheader.h:239
options::SUHeaderControl outputmodifiers(const std::string &modifier, const bool &debug)
evaluate output stream format modifiers
Definition: suformat.cc:122