DATRW++ library: seismic data I/O with multiple formats
oseifestream.cc
Go to the documentation of this file.
1 /*! \file oseifestream.cc
2  * \brief writing seife data (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 30/11/2010
8  *
9  * writing seife data (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  * - 30/11/2010 V1.0 Thomas Forbriger
31  * - 08/07/2016 V1.1 make correct use of new DATRW_report_assert
32  * - 18/11/2016 V1.2 use debug flag in base class
33  *
34  * ============================================================================
35  */
36 #define DATRW_OSEIFESTREAM_CC_VERSION \
37  "DATRW_OSEIFESTREAM_CC V1.2"
38 
39 #include <datrwxx/seife.h>
40 #include <datrwxx/seifeio.h>
41 #include <datrwxx/debug.h>
42 #include <datrwxx/util.h>
43 #include <datrwxx/formatmodifier.h>
44 
45 namespace datrw {
46 
47  const std::ios_base::openmode
48  oseifestream::openmode=std::ios_base::out;
49 
50  /*----------------------------------------------------------------------*/
51 
52  oseifestream::oseifestream(std::ostream& os,
53  const std::string& modifier,
54  const bool& debug):
55  Tbase(os, Fdouble, false, true, false, false, debug),
56  Mtracewritten(false), Mmodifier(modifier)
57  {
58  DATRW_debug(Mdebug, "oseifestream::oseifestream",
59  "new instance established");
61  } // oseifestream::oseifestream
62 
63  /*----------------------------------------------------------------------*/
64 
66  {
67  DATRW_debug(Mdebug, "oseifestream::writefileheader",
68  "write file header to file");
69  // nothing to be done in the case of a seife file
70  } // void oseifestream::writefileheader()
71 
72  /*----------------------------------------------------------------------*/
73 
74  void oseifestream::writetrace(const Tdseries::Tcoc& series)
75  {
76  DATRW_debug(Mdebug, "oseifestream::writetrace",
77  "write series of type double to file");
78  this->writetraceheader(series.size());
79  datrw::seife::write_series(this->Mos, series);
80  } // void oseifestream::writetrace(const Tdseries& series)
81 
82  /*----------------------------------------------------------------------*/
83 
84  void oseifestream::writetrace(const Tfseries::Tcoc& series)
85  {
86  DATRW_debug(Mdebug, "oseifestream::writetrace",
87  "write series of type float to file");
88  this->writetraceheader(series.size());
90  datrw::util::convert<Tfseries, Tdseries>(series));
91  } // void oseifestream::writetrace(const Tfseries& series)
92 
93  /*----------------------------------------------------------------------*/
94 
95  void oseifestream::writetraceheader(const unsigned int& n)
96  {
98  "WARNING in (oseifestream::writetraceheader):\n"
99  "More than one trace will be written to the same "
100  "seife file!\n"
101  "seife format only supports single trace files.\n");
102  datrw::seife::Header header;
103  datrw::seife::ParameterLine parameters;
104  if (this->hasfree()) { header.set(this->free()); }
105  ::sff::WID2 wid2=this->wid2();
106  libtime::TAbsoluteTime theday(wid2.date.year(), wid2.date.month(),
107  wid2.date.day());
108  parameters.time(wid2.date-theday);
109  parameters.dt(wid2.dt);
110  parameters.nsamples(n);
112  header.set(parameters);
113  header.write(this->Mos);
114  this->Mtracewritten=true;
115  } // void oseifestream::writetraceheader(const unsigned int& n)
116 
117  /*----------------------------------------------------------------------*/
118 
119  void oseifestream::help(std::ostream& os)
120  {
121  os <<
122  std::endl <<
123  "seife writing functions" << std::endl <<
124  "-----------------------" << std::endl <<
125  DATRW_OSEIFESTREAM_CC_VERSION << std::endl <<
126  std::endl;
127  os <<
128  "This module writes seismic time series data in the format\n"
129  "used by programs provided by Erhard Wielandt. See his web site\n"
130  "http://www.software-for-seismometry.de for details.\n"
131  "Notice that this format only supports a single trace per file.\n"
132  "The actual number format currently is fixed to the Fortran format\n"
133  "specification " << seife::seife_standard_format << "."
134  << std::endl;
135  } // void oseifestream::help(std::ostream& os)
136 
137 } // namespace datrw
138 
139 /* ----- END OF oseifestream.cc ----- */
seife format header parameter line
Definition: seifeio.h:69
static void help(std::ostream &os=std::cout)
libtime::TRelativeTime time() const
return time of first sample as offset from midnight
Definition: seifeio.h:98
unsigned int nsamples() const
return number of samples
Definition: seifeio.h:92
seife reading and writing module (prototypes)
provide format modifiers (prototypes)
const char *const seife_standard_format
Definition: seifeio.cc:47
static const std::ios_base::openmode openmode
Definition: seife.h:96
macro function for debugging output (prototypes)
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 Mtracewritten
true, if a trace has be written
Definition: seife.h:103
void set(const ::sff::FREE &free)
set comments
Definition: seifeio.h:149
Root namespace of library.
Definition: aalibdatrwxx.cc:16
utilities used by more than one type of data reader (prototypes)
void write_series(std::ostream &os, const Tseries::Tcoc &s)
write samples to file
Definition: seifeio.cc:189
std::string format() const
return Fortran data format
Definition: seifeio.h:94
virtual void writetrace(const Tdseries::Tcoc &series)
write double data
Definition: oseifestream.cc:74
sff::FREE free() const
return FREE data
Definition: datwrite.h:175
virtual void writefileheader()
actually write the file header
Definition: oseifestream.cc:65
void write(std::ostream &os) const
! write header to stream
Definition: seifeio.cc:163
double dt() const
return sumpling interval
Definition: seifeio.h:96
class to hold complete seife header
Definition: seifeio.h:132
oseifestream(std::ostream &os, const std::string &modifier="", const bool &debug=false)
Definition: oseifestream.cc:52
void writetraceheader(const unsigned int &n)
Definition: oseifestream.cc:95
#define DATRW_debug(C, N, M)
produce debug output
Definition: debug.h:50
bool Mdebug
global debug flag
Definition: datwrite.h:197
#define DATRW_expect_no_modifier(F, M)
Issue warning if modifiers are passed but not evaluated.
#define DATRW_OSEIFESTREAM_CC_VERSION
Definition: oseifestream.cc:36
bool hasfree() const
free is available
Definition: datwrite.h:184
#define DATRW_report_assert(C, M)
Check an assertion and report only.
Definition: error.h:120