DATRW++ library: seismic data I/O with multiple formats
itsoftstream.cc
Go to the documentation of this file.
1 /*! \file itsoftstream.cc
2  * \brief actual TSOFT to SFF code (implementation)
3  * \ingroup group_tsoft
4  *
5  * ----------------------------------------------------------------------------
6  *
7  * \author Thomas Forbriger
8  * \date 11/11/2009
9  *
10  * actual TSOFT to SFF code (implementation)
11  *
12  * Copyright (c) 2009 by Thomas Forbriger (BFO Schiltach)
13  *
14  * ----
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28  * ----
29  *
30  * REVISIONS and CHANGES
31  * - 11/11/2009 V1.0 Thomas Forbriger
32  * - 23/11/2010 V1.1 introduced static member data
33  * - 05/12/2011 V1.2 implemented format modifiers to handle gaps
34  * - 07/01/2013 V1.3 fix problem with improper detection of end of file
35  * for single trace data
36  * - 18/11/2016 V1.4 use debug flag in base class
37  *
38  * ============================================================================
39  */
40 #define DATRW_TSOFT_CC_VERSION \
41  "DATRW_TSOFT_CC V1.4"
42 
43 #include <datrwxx/tsoft.h>
44 #include <datrwxx/util.h>
45 #include <datrwxx/channeltranslation.h>
46 #include <datrwxx/formatmodifier.h>
47 
48 namespace datrw {
49 
50  const std::ios_base::openmode itsoftstream::openmode=std::ios_base::in;
51 
52  //@{
53  /*! \brief Format properties
54  * \ingroup group_tsoft
55  */
56  const bool tsoft::isbinary=false;
57  const char* const tsoft::streamID="tsoft";
58  //@}
59 
60  /*----------------------------------------------------------------------*/
61 
62  namespace tsoft {
63  //@{
64  /*! \brief Format modifier keys
65  * \ingroup group_tsoft
66  */
67  const char* const key_keepundetval="keepundetval";
68  const char* const key_replaceundetval="replaceundetval";
69  const char* const key_bridgetime="bridgetime";
70  const char* const key_flagbridged="flagbridged";
71  //@}
72  } // namespace tsoft
73 
74  /*----------------------------------------------------------------------*/
75 
76  itsoftstream::itsoftstream(std::istream& is, const bool& debug):
77  Tbase(is, true, true, false, debug)
78  {
79  this->read(is);
80  } // itsoftstream::itsoftstream(std::istream& is, const bool& debug)
81 
82  /*----------------------------------------------------------------------*/
83 
84  itsoftstream::itsoftstream(std::istream& is,
85  const std::string& modifier,
86  const bool& debug):
87  Tbase(is, true, true, false, debug)
88  {
89  datrw::Subformat subformat(modifier);
90  subformat(tsoft::key_replaceundetval, "9000.")
91  >> this->Mreaderconfig.flagvalue;
95  =subformat.isset(tsoft::key_keepundetval);
97  =subformat.isset(tsoft::key_bridgetime);
99  =libtime::TAbsoluteTime(subformat.value(tsoft::key_bridgetime,
100  "1/1/1/1/1/1"));
102  =subformat.isset(tsoft::key_flagbridged);
103  subformat(tsoft::key_flagbridged, "-9000.")
105  DATRW_assert_modifiers_are_recognized(subformat, "itsoftstream");
106  this->read(is);
107  } // itsoftstream::itsoftstream(std::istream& is, const bool& debug)
108 
109  /*----------------------------------------------------------------------*/
110 
111  void itsoftstream::read(std::istream& is)
112  {
114  Mitrace=this->Mfile.Mtraces.first();
115  this->setfilefree(Mfile.Mfree);
116  if (Mfile.Mtraces.size()<1) { this->setlast(); }
117  } // void itsoftstream::read(std::istream& is)
118 
119  /*----------------------------------------------------------------------*/
120 
122  {
123  this->newtrace();
124  DATRW_assert(Mitrace<=this->Mfile.Mtraces.last(),
125  "reading beyond end of file");
126  if (Mitrace==this->Mfile.Mtraces.last()) { this->setlast(); }
128  this->setwid2(trace.Mwid2);
129  this->settracefree(trace.Mfree);
130  ++Mitrace;
131  return(trace.Mseries);
132  } // Tdseries itsoftstream::dseries()
133 
134  /*----------------------------------------------------------------------*/
135 
137  { return(datrw::util::convert<Tdseries, Tfseries>(this->dseries())); }
138 
139  /*----------------------------------------------------------------------*/
140 
142  {
143  DATRW_assert(Mitrace<=this->Mfile.Mtraces.last(),
144  "reading beyond end of file");
145  if (Mitrace==this->Mfile.Mtraces.last()) { this->setlast(); }
147  this->setwid2(trace.Mwid2);
148  this->settracefree(trace.Mfree);
149  ++Mitrace;
150  } // void itsoftstream::skipseries()
151 
152  /*----------------------------------------------------------------------*/
153 
154  void itsoftstream::help(std::ostream& os)
155  {
156  os << std::endl;
157  os << "TSOFT data reading functions" << std::endl;
158  os << "----------------------------" << std::endl;
159  os << DATRW_TSOFT_CC_VERSION << std::endl;
160  os << DATRW_TSOFT_H_VERSION << std::endl;
161  os << "TSOFT format is defined by the TSOFT software:\n"
162  << " http://seismologie.oma.be/TSOFT/tsoft.html" << std::endl;
163  os << "It is the standard data storage format of the UIPC " << std::endl
164  << "data acquisition of GWR superconducting gravimeters." << std::endl;
165  os << "This reading module is tailored to handle data recorded\n"
166  << "for the SG056 at BFO.\n";
167  os << std::endl;
169  os << std::endl;
172  "TSOFT translation table is not unique");
173  os << std::endl;
174  os
175  << "The TSOFT reading module supports format modifiers to handle\n"
176  << "gaps in the otherwise continuous input data:\n";
177  os << " " << tsoft::key_keepundetval << "\n";
178  os
179  << " Samples of the value defined as \"UNDETVAL\" in the TSOFT\n"
180  << " header are usually regarded as non-existent and for this\n"
181  << " reason produce a gap in the data. If this flag is set,\n"
182  << " these sample values are simply passed to the output.\n";
183  os << " " << tsoft::key_replaceundetval << "=value\n";
184  os
185  << " Samples of the value defined as \"UNDETVAL\" in the TSOFT\n"
186  << " header are set to \"value\".\n";
187  os << " " << tsoft::key_bridgetime << "=YYYY/MM/DD/hh/mm/ss\n";
188  os
189  << " The UIPC data acquisition system of SG056 occasionally\n"
190  << " produces data lines with unreasonable data times. The\n"
191  << " typical time on these lines is\n"
192  << " 0001 01 01 01 01 01\n"
193  << " These entries produce gaps in the output data. If this\n"
194  << " modifier is passed and the line is not the first line\n"
195  << " in the input data line, lines with sample time defined\n"
196  << " by the modifier parameter are replaced by the expected\n"
197  << " time for this line and sample values are included in\n"
198  << " the output data stream.\n";
199  os << " " << tsoft::key_flagbridged << "=value\n";
200  os
201  << " If this flag is set, sample values of lines with originally\n"
202  << " unreasonable sample time being bridge by the reader are\n"
203  << " flagged with sample value being replaced by \"value\".\n";
204  } // void itsoftstream::help(std::ostream& os)
205 
206 } // namespace datrw
207 
208 /* ----- END OF itsoftstream.cc ----- */
aff::Tsubscript Mitrace
index of next trace to be passed
Definition: tsoft.h:80
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
provide format modifiers (prototypes)
datrw::tsoft::File Mfile
container for complete file
Definition: tsoft.h:78
aff::Series< float > Tfseries
Definition: types.h:46
const bool isbinary
Format properties.
Definition: itsoftstream.cc:56
void reporttranslation(std::ostream &os)
report translation table
datrw::Tdseries Mseries
samples
void setfilefree(const sff::FREE &free)
Definition: datread.cc:97
contents for one trace of data
const char *const streamID
Format properties.
Definition: itsoftstream.cc:57
virtual void skipseries()
tsoft::ReaderConfig Mreaderconfig
TSOFT reader configuration.
Definition: tsoft.h:84
::sff::FREE Mfree
free comment lines
itsoftstream(std::istream &is, const bool &debug=false)
Definition: itsoftstream.cc:76
aff::Series< double > Tdseries
Definition: types.h:45
#define DATRW_TSOFT_CC_VERSION
Definition: itsoftstream.cc:40
const char *const key_keepundetval
Format modifier keys.
Definition: itsoftstream.cc:67
bool translationisunique(const bool &verbose)
check uniqueness of translation table
const char *const key_replaceundetval
Format modifier keys.
Definition: itsoftstream.cc:68
void setwid2(const sff::WID2 &wid2)
Definition: datread.cc:113
#define DATRW_assert_modifiers_are_recognized(S, F)
abort if user passed unused modifiers
virtual Tfseries fseries()
File readfile(std::istream &is, const ReaderConfig &rc)
read complete file
Root namespace of library.
Definition: aalibdatrwxx.cc:16
utilities used by more than one type of data reader (prototypes)
void settracefree(const sff::FREE &free)
Definition: datread.cc:105
const char *const key_bridgetime
Format modifier keys.
Definition: itsoftstream.cc:69
Class to handle format modifiersThis class is used to parse a format modifier string. Detailed instructions will be given upon request. For some hints have a look at tests/libdatrwxxtests.c.
void read(std::istream &is)
read file to buffer
::sff::FREE Mfree
free comment lines
bool isset(const std::string &k) const
check if user provided this key
::sff::WID2 Mwid2
header
#define DATRW_TSOFT_H_VERSION
Definition: tsoft.h:41
Ttraceseries Mtraces
all traces in file
static void help(std::ostream &os=std::cout)
classes for TSOFT in SFF (prototypes)
std::string value(const std::string &k, const std::string &dev="false") const
function operator returns string
const char *const key_flagbridged
Format modifier keys.
Definition: itsoftstream.cc:70
libtime::TAbsoluteTime bridgetime
Definition: tsoftconfig.h:82
virtual Tdseries dseries()
#define DATRW_report_assert(C, M)
Check an assertion and report only.
Definition: error.h:120
static const std::ios_base::openmode openmode
Definition: tsoft.h:75
void reportdatacomments(std::ostream &os)
report comments from 1s files