DATRW++ library: seismic data I/O with multiple formats
tsoftdata.h
Go to the documentation of this file.
1 /*! \file tsoftdata.h
2  * \brief class to store TSOFT data (prototypes)
3  * \ingroup group_tsoft
4  *
5  * ----------------------------------------------------------------------------
6  *
7  * \author Thomas Forbriger
8  * \date 16/09/2009
9  *
10  * class to store TSOFT data (prototypes)
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  * - 16/09/2009 V1.0 Thomas Forbriger
32  * - 02/12/2011 V1.1 prepared for input stream modifiers;
33  * provides ReaderConfig
34  * V1.2 moved ReaderConfig to tsoftconfig.h
35  *
36  * ============================================================================
37  */
38 
39 // include guard
40 #ifndef DATRW_TSOFTDATA_H_VERSION
41 
42 #define DATRW_TSOFTDATA_H_VERSION \
43  "DATRW_TSOFTDATA_H V1.2"
44 
45 #include<iostream>
46 #include<string>
47 #include<vector>
48 #include<list>
49 #include<libtime++.h>
50 #include<datrwxx/error.h>
51 #include<datrwxx/datread.h>
52 #include<datrwxx/tsoftconfig.h>
53 
54 namespace datrw {
55 
56 
57  /*! \brief All classes and functions to extract data from TSOFT files
58  *
59  * TSOFT is available from
60  * http://seismologie.oma.be/TSOFT/tsoft.html
61  *
62  * \defgroup group_tsoft Reading module for: TSOFT data
63  */
64 
65  /*! \brief All classes and functions to extract data from TSOFT files
66  *
67  * \ingroup group_tsoft
68  */
69  namespace tsoft {
70 
71  /*! \brief string constants
72  *
73  * \defgroup group_tsoftconst TSOFT string constants
74  * @{
75  * \ingroup group_tsoft
76  */
77  //! \brief first character of TSOFT tag
78  extern const char* tagbegin;
79  //! \brief last character of TSOFT tag
80  extern const char* tagend;
81 
82  //! \brief TSOFT data tag
83  extern const char* tagdata;
84  //! \brief TSOFT channels tag
85  extern const char* tagchannels;
86  //! \brief TSOFT units tag
87  extern const char* tagunits;
88  //! \brief TSOFT fileid tag
89  extern const char* tagfileid;
90  //! \brief TSOFT timeformat tag
91  extern const char* tagtimeformat;
92  //! \brief TSOFT increment tag
93  extern const char* tagincrement;
94  //! \brief TSOFT undetval tag
95  extern const char* tagundetval;
96 
97  //! \brief value not specified
98  extern const char* NSP;
99  //@}
100 
101  /*! \brief vector of strings.
102  *\ingroup group_tsoft
103  */
104  typedef std::vector<std::string> Tvos;
105  /*! \brief list of strings.
106  *\ingroup group_tsoft
107  */
108  typedef std::list<std::string> Tlos;
109  /*! \brief vector of doubles.
110  *\ingroup group_tsoft
111  */
112  typedef std::vector<double> Tvod;
113 
114  /*----------------------------------------------------------------------*/
115 
116  /*! \brief helper function stringtok
117  * \ingroup group_tsoft
118  */
119  Tvos stringtovec(const std::string& line,
120  const std::string& delimiter=":");
121 
122  /*----------------------------------------------------------------------*/
123 
124  /*! \brief helper function trimws
125  * \ingroup group_tsoft
126  */
127  void trimws(std::string& line);
128 
129  /*----------------------------------------------------------------------*/
130 
131  /*! \brief helper function getDOSline
132  * \ingroup group_tsoft
133  */
134  std::string getDOSline(std::istream& is);
135 
136  /*----------------------------------------------------------------------*/
137 
138  /*! \brief contains takes one line and splits it into tag and information.
139  * \ingroup group_tsoft
140  */
141  class Line {
142  public:
143  //! constructor: swallow line
144  Line(const std::string &line);
145  //! return line
146  std::string theline() const { return Mline; }
147  //! return tag
148  std::string thetag() const { return Mtag; }
149  //! return content
150  std::string thecontent() const { return Mcontent; }
151  //! check whether this line has a tag
152  bool hastag() const { return Mhastag; }
153  //! check whether this line has a content
154  bool hascontent() const { return Mhascontent; }
155  private:
156  //! the actual line
157  std::string Mline;
158  //! the tag part of the line
159  std::string Mtag;
160  //! the content part of the line
161  std::string Mcontent;
162  //! true if this line contains a tag
163  bool Mhastag;
164  //! true if this line has a content
166  }; // class Line
167 
168  /*----------------------------------------------------------------------*/
169 
170  /*! \brief contains channel info.
171  * \ingroup group_tsoft
172  */
173  class Channelinfo {
174  public:
175  //! standard constructor
176  Channelinfo();
177  //! set channel info
178  void setchannelinfo(const std::string& line);
179  //! set unit info
180  void setunits(const std::string& line)
181  {
182  Munits=line;
183  trimws(Munits);
184  }
185  //! return location
186  const std::string& thelocation() const { return Mlocation; }
187  //! return instrument
188  const std::string& theinstrument() const { return Minstrument; }
189  //! return datatype
190  const std::string& thedatatype() const { return Mdatatype; }
191  //! return units
192  const std::string& theunits() const { return Munits; }
193  private:
194  //! location field in channel name
195  std::string Mlocation;
196  //! instrument field in channel name
197  std::string Minstrument;
198  //! data type field in channel name
199  std::string Mdatatype;
200  //! units
201  std::string Munits;
202  }; // class Channelinfo
203 
204  /*----------------------------------------------------------------------*/
205 
206  /*! \brief vector of channel info.
207  * \ingroup group_tsoft
208  */
209  typedef std::vector<Channelinfo> Tvoci;
210 
211  /*----------------------------------------------------------------------*/
212 
213  /*! \brief contains one data line.
214  * \ingroup group_tsoft
215  */
216  class Dataline {
217  public:
218  //! swallow a line
219  Dataline(const std::string& line);
220  //! return time
221  libtime::TAbsoluteTime time() const { return Mtime; }
222  //! return vector of samples
223  Tvod vectorofsamples() const { return Msamples; }
224  //! return number of samples in line
225  int nsamples() const { return Msamples.size(); }
226  //! return specific sample
227  double sample(const int& i) const;
228  private:
229  //! the data line
230  std::string Mline;
231  //! time
232  libtime::TAbsoluteTime Mtime;
233  //! vector of data values
235  }; // class Dataline
236 
237  /*----------------------------------------------------------------------*/
238 
239  /*! \brief trace of contiguous data.
240  * \ingroup group_tsoft
241  */
242  class Datatrace {
243  public:
244  //! set time of first sample
245  void date(const libtime::TAbsoluteTime d) { Mdate=d; }
246  //! set sampling interval
247  void interval(const libtime::TRelativeTime i) { Minterval=i; }
248  //! set series
249  void series(const Tdseries& s) { Mseries=s; }
250  //! return time of first sample
251  libtime::TAbsoluteTime date() const { return Mdate; }
252  //! return sampling interval
253  libtime::TRelativeTime interval() const { return Minterval; }
254  //! return series
255  Tdseries series() const { return Mseries; }
256  private:
257  //! samples
259  //! time of first sample
260  libtime::TAbsoluteTime Mdate;
261  //! sampling interval
262  libtime::TRelativeTime Minterval;
263  }; // class Datatrace
264 
265  /*----------------------------------------------------------------------*/
266 
267  /*! \brief sequence of contiguous data.
268  * \ingroup group_tsoft
269  */
270  class Datasequence {
271  public:
272  //! initialize
273  Datasequence();
274  //! append sample
275  void append(const double& v) { Msamples.push_back(v); }
276  //! set time of first sample
277  void date(const libtime::TAbsoluteTime d) { Mdate=d; }
278  //! set sampling interval
279  void interval(const libtime::TRelativeTime i) { Minterval=i; }
280  //! return sample
281  double sample(const unsigned int& i) const
282  {
283  DATRW_assert(((i<Msamples.size()) && (i>=0)),
284  "illegal sample index");
285  return Msamples[i];
286  }
287  //! return number of samples
288  int nsamples() const { return Msamples.size(); }
289  //! return time of first sample
290  libtime::TAbsoluteTime date() const { return Mdate; }
291  //! return time of next sample after last samples
292  libtime::TAbsoluteTime timeofnextsample(const bool& debug=false) const;
293  //! return sampling interval
294  libtime::TRelativeTime interval() const { return Minterval; }
295  //! initialize data sequence
296  void initialize();
297  //! return samples in a series container
298  Tdseries series() const;
299  private:
300  //! samples
302  //! time of first sample
303  libtime::TAbsoluteTime Mdate;
304  //! sampling interval
305  libtime::TRelativeTime Minterval;
306  }; // class Datasequence
307 
308  /*----------------------------------------------------------------------*/
309 
310  /*! \brief vector of sequences.
311  * \ingroup group_tsoft
312  */
313  typedef std::vector<Datatrace> Tvodt;
314 
315  /*----------------------------------------------------------------------*/
316 
317  /*! \brief date for one channel.
318  * \ingroup group_tsoft
319  */
320  class Channeldata {
321  public:
322  //! constructor to initialize
323  Channeldata();
324  //! push a sample
325  void push_sample(const libtime::TAbsoluteTime& time,
326  const double& value,
327  const double& undetval,
328  const libtime::TRelativeTime& dt,
329  const ReaderConfig& rc,
330  const bool& debug=false);
331  //! return data trace
332  const Datatrace& trace(const unsigned int& i) const
333  {
334  DATRW_assert(((i<Mtraces.size()) && (i>=0)),
335  "illegal trace index");
336  return Mtraces[i];
337  }
338  //! return data trace
339  Datatrace& trace(const unsigned int& i)
340  {
341  DATRW_assert(((i<Mtraces.size()) && (i>=0)),
342  "illegal trace index");
343  return Mtraces[i];
344  }
345  //! set channel info
346  void chinfo(const Channelinfo& ci) { Mchannelinfo=ci; }
347  //! return channel info
348  const Channelinfo& chinfo() const { return(Mchannelinfo); }
349  //! return channel info
351  //! number of data traces
352  int ntraces() const { return Mtraces.size(); }
353  //! function to flush collector to vector of sequences
354  void flushcollector();
355  private:
356  //! function to reset collector
357  void resetcollector();
358  //! data traces
360  //! vector of samples to collect from file
362  //! channel info
364  }; // class Channeldata
365 
366  /*----------------------------------------------------------------------*/
367 
368  /*! \brief prepare free comment block from channel info.
369  * \ingroup group_tsoft
370  */
371  Tlos channelinfofree(const Channelinfo& ci);
372 
373  /*----------------------------------------------------------------------*/
374 
375  /*! \brief vector of channels.
376  * \ingroup group_tsoft
377  */
378  typedef std::vector<Channeldata> Tvocd;
379 
380  /*----------------------------------------------------------------------*/
381 
382  /*! \brief data container.
383  * \ingroup group_tsoft
384  */
386  public:
387  //! Default constructor
389  //! Config constructor
391  //! push a data line
392  void push_data(const std::string& line,
393  const double& undetval,
394  const libtime::TRelativeTime& dt,
395  const bool& debug=false);
396  //! return data for specific channel
397  Channeldata& channel(const unsigned int& i,
398  const bool& debug=false)
399  {
400  this->resizetoindex(i);
401  return(Mchannels[i]);
402  }
403  //! return data for specific channel
404  const Channeldata& channel(const unsigned int& i,
405  const bool& debug=false) const
406  {
407  this->checkindex(i);
408  return(Mchannels[i]);
409  }
410  //! return data for specific channel
411  Channeldata& operator[](const unsigned int& i)
412  {
413  return (this->channel(i));
414  }
415  //! return data for specific channel
416  const Channeldata& operator[](const unsigned int& i) const
417  {
418  return (this->channel(i));
419  }
420  //! return number of channels
421  int nchannels() const { return Mchannels.size(); }
422  //! flush all channels
423  void flushchannels();
424  private:
425  //! resize to index
426  void resizetoindex(const unsigned int& i)
427  {
428  if (i>=Mchannels.size())
429  {
430  Mchannels.resize(i+1);
431  }
432  this->checkindex(i);
433  }
434  //! check index
435  void checkindex(const unsigned int& i) const
436  {
437  DATRW_assert(((i<Mchannels.size()) && (i>=0)),
438  "illegal channel index");
439  }
440  //! reader configuration
442  //! data sequences
444  }; // class Datacontainer
445 
446  } // namespace tsoft
447 
448 } // namespace datrw
449 
450 #endif // DATRW_TSOFTDATA_H_VERSION (includeguard)
451 
452 /* ----- END OF tsoftdata.h ----- */
void append(const double &v)
append sample
Definition: tsoftdata.h:275
config parameters for data extractionThese parameters control the way gaps in the input data are hand...
Definition: tsoftconfig.h:57
void push_sample(const libtime::TAbsoluteTime &time, const double &value, const double &undetval, const libtime::TRelativeTime &dt, const ReaderConfig &rc, const bool &debug=false)
push a sample
Definition: tsoftdata.cc:228
libtime::TAbsoluteTime timeofnextsample(const bool &debug=false) const
return time of next sample after last samples
Definition: tsoftdata.cc:164
contains channel info.
Definition: tsoftdata.h:173
Tdseries Mseries
samples
Definition: tsoftdata.h:258
Channelinfo & chinfo()
return channel info
Definition: tsoftdata.h:350
std::vector< Channelinfo > Tvoci
vector of channel info.
Definition: tsoftdata.h:209
ReaderConfig Mreaderconfig
reader configuration
Definition: tsoftdata.h:441
std::string thetag() const
return tag
Definition: tsoftdata.h:148
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
std::list< std::string > Tlos
list of strings.
Definition: tsoftdata.h:108
std::string Mcontent
the content part of the line
Definition: tsoftdata.h:161
Tvod Msamples
vector of data values
Definition: tsoftdata.h:234
Tvocd Mchannels
data sequences
Definition: tsoftdata.h:443
std::vector< Datatrace > Tvodt
vector of sequences.
Definition: tsoftdata.h:313
int ntraces() const
number of data traces
Definition: tsoftdata.h:352
Channeldata()
constructor to initialize
Definition: tsoftdata.cc:206
const char * tagdata
TSOFT data tag.
Definition: tsoftdata.cc:54
std::string Mline
the data line
Definition: tsoftdata.h:230
trace of contiguous data.
Definition: tsoftdata.h:242
contains takes one line and splits it into tag and information.
Definition: tsoftdata.h:141
const std::string & thedatatype() const
return datatype
Definition: tsoftdata.h:190
libtime::TRelativeTime Minterval
sampling interval
Definition: tsoftdata.h:305
void setunits(const std::string &line)
set unit info
Definition: tsoftdata.h:180
Tvodt Mtraces
data traces
Definition: tsoftdata.h:359
bool Mhascontent
true if this line has a content
Definition: tsoftdata.h:165
libtime::TAbsoluteTime time() const
return time
Definition: tsoftdata.h:221
const std::string & theunits() const
return units
Definition: tsoftdata.h:192
std::string Munits
units
Definition: tsoftdata.h:201
std::vector< std::string > Tvos
vector of strings.
Definition: tsoftdata.h:104
libtime::TRelativeTime dt()
return sampling interval of HPMO data acquisition (i.e. 5 sec)
Definition: readhpmo.cc:83
std::string Minstrument
instrument field in channel name
Definition: tsoftdata.h:197
const char * tagbegin
first character of TSOFT tag
Definition: tsoftdata.cc:51
Line(const std::string &line)
constructor: swallow line
Definition: tsoftdata.cc:68
void series(const Tdseries &s)
set series
Definition: tsoftdata.h:249
double sample(const int &i) const
return specific sample
Definition: tsoftdata.cc:145
libtime::TRelativeTime interval() const
return sampling interval
Definition: tsoftdata.h:253
Dataline(const std::string &line)
swallow a line
Definition: tsoftdata.cc:122
data container.
Definition: tsoftdata.h:385
int nsamples() const
return number of samples in line
Definition: tsoftdata.h:225
const char * tagtimeformat
TSOFT timeformat tag.
Definition: tsoftdata.cc:58
bool Mhastag
true if this line contains a tag
Definition: tsoftdata.h:163
aff::Series< double > Tdseries
Definition: types.h:45
libtime::TAbsoluteTime Mdate
time of first sample
Definition: tsoftdata.h:260
int nsamples() const
return number of samples
Definition: tsoftdata.h:288
int nchannels() const
return number of channels
Definition: tsoftdata.h:421
std::vector< double > Tvod
vector of doubles.
Definition: tsoftdata.h:112
const Datatrace & trace(const unsigned int &i) const
return data trace
Definition: tsoftdata.h:332
sequence of contiguous data.
Definition: tsoftdata.h:270
Tdseries series() const
return samples in a series container
Definition: tsoftdata.cc:190
exception class declaration for libdatrwxx (prototypes)
std::string Mline
the actual line
Definition: tsoftdata.h:157
libtime::TRelativeTime Minterval
sampling interval
Definition: tsoftdata.h:262
libtime::TAbsoluteTime Mdate
time of first sample
Definition: tsoftdata.h:303
void trimws(std::string &line)
helper function trimws
Definition: tsoftdata.cc:375
void interval(const libtime::TRelativeTime i)
set sampling interval
Definition: tsoftdata.h:279
libtime::TRelativeTime interval() const
return sampling interval
Definition: tsoftdata.h:294
libtime::TAbsoluteTime date() const
return time of first sample
Definition: tsoftdata.h:290
Tdseries series() const
return series
Definition: tsoftdata.h:255
std::string thecontent() const
return content
Definition: tsoftdata.h:150
void resizetoindex(const unsigned int &i)
resize to index
Definition: tsoftdata.h:426
std::string Mtag
the tag part of the line
Definition: tsoftdata.h:159
const char * tagunits
TSOFT units tag.
Definition: tsoftdata.cc:56
libtime::TAbsoluteTime Mtime
time
Definition: tsoftdata.h:232
const char * tagincrement
TSOFT increment tag.
Definition: tsoftdata.cc:59
const std::string & theinstrument() const
return instrument
Definition: tsoftdata.h:188
Root namespace of library.
Definition: aalibdatrwxx.cc:16
void chinfo(const Channelinfo &ci)
set channel info
Definition: tsoftdata.h:346
const Channeldata & operator[](const unsigned int &i) const
return data for specific channel
Definition: tsoftdata.h:416
const char * tagend
last character of TSOFT tag
Definition: tsoftdata.cc:52
const Channelinfo & chinfo() const
return channel info
Definition: tsoftdata.h:348
void initialize()
initialize data sequence
Definition: tsoftdata.cc:180
Channelinfo()
standard constructor
Definition: tsoftdata.cc:100
Tlos channelinfofree(const Channelinfo &ci)
prepare free comment block from channel info
Definition: tsoftdata.cc:403
void setchannelinfo(const std::string &line)
set channel info
Definition: tsoftdata.cc:108
Tvos stringtovec(const std::string &line, const std::string &delimiters)
helper function stringtok
Definition: tsoftdata.cc:341
libtime::TAbsoluteTime date() const
return time of first sample
Definition: tsoftdata.h:251
Datacontainer()
Default constructor.
Definition: tsoftdata.h:388
std::string Mlocation
location field in channel name
Definition: tsoftdata.h:195
const std::string & thelocation() const
return location
Definition: tsoftdata.h:186
const char * NSP
value not specified
Definition: tsoftdata.cc:62
Datatrace & trace(const unsigned int &i)
return data trace
Definition: tsoftdata.h:339
void flushcollector()
function to flush collector to vector of sequences
Definition: tsoftdata.cc:213
void checkindex(const unsigned int &i) const
check index
Definition: tsoftdata.h:435
Channeldata & operator[](const unsigned int &i)
return data for specific channel
Definition: tsoftdata.h:411
std::vector< Channeldata > Tvocd
vector of channels.
Definition: tsoftdata.h:378
Datacontainer(const ReaderConfig &rc)
Config constructor.
Definition: tsoftdata.h:390
date for one channel.
Definition: tsoftdata.h:320
void date(const libtime::TAbsoluteTime d)
set time of first sample
Definition: tsoftdata.h:245
Datasequence Mcollector
vector of samples to collect from file
Definition: tsoftdata.h:361
const char * tagfileid
TSOFT fileid tag.
Definition: tsoftdata.cc:57
void push_data(const std::string &line, const double &undetval, const libtime::TRelativeTime &dt, const bool &debug=false)
push a data line
Definition: tsoftdata.cc:297
void flushchannels()
flush all channels
Definition: tsoftdata.cc:329
void resetcollector()
function to reset collector
void date(const libtime::TAbsoluteTime d)
set time of first sample
Definition: tsoftdata.h:277
const char * tagchannels
TSOFT channels tag.
Definition: tsoftdata.cc:55
const Channeldata & channel(const unsigned int &i, const bool &debug=false) const
return data for specific channel
Definition: tsoftdata.h:404
contains one data line.
Definition: tsoftdata.h:216
double sample(const unsigned int &i) const
return sample
Definition: tsoftdata.h:281
std::string Mdatatype
data type field in channel name
Definition: tsoftdata.h:199
Tvod vectorofsamples() const
return vector of samples
Definition: tsoftdata.h:223
Channeldata & channel(const unsigned int &i, const bool &debug=false)
return data for specific channel
Definition: tsoftdata.h:397
void interval(const libtime::TRelativeTime i)
set sampling interval
Definition: tsoftdata.h:247
bool hascontent() const
check whether this line has a content
Definition: tsoftdata.h:154
bool hastag() const
check whether this line has a tag
Definition: tsoftdata.h:152
std::string getDOSline(std::istream &is)
helper function getDOSline
Definition: tsoftdata.cc:423
const char * tagundetval
TSOFT undetval tag.
Definition: tsoftdata.cc:60
std::string theline() const
return line
Definition: tsoftdata.h:146
Channelinfo Mchannelinfo
channel info
Definition: tsoftdata.h:363