DATRW++ library: seismic data I/O with multiple formats
thiesdl1file.h
Go to the documentation of this file.
1 /*! \file thiesdl1file.h
2  * \brief handle a ThiesDL1 data file (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 13/09/2011
8  *
9  * handle a ThiesDL1 data file (prototypes)
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  * REVISIONS and CHANGES
30  * - 13/09/2011 V1.0 Thomas Forbriger
31  *
32  * ============================================================================
33  */
34 
35 // include guard
36 #ifndef DATRW_THIESDL1FILE_H_VERSION
37 
38 #define DATRW_THIESDL1FILE_H_VERSION \
39  "DATRW_THIESDL1FILE_H V1.0 "
40 
41 #include <libtime++.h>
42 #include <sffxx.h>
43 #include <datrwxx/error.h>
44 #include <datrwxx/thiesdl1line.h>
45 #include <datrwxx/types.h>
46 
47 namespace datrw {
48 
49  namespace thiesdl1 {
50 
51  //! SEED channel identifier for precipitation
52  extern const char* const precipitationID;
53 
54  //! expected sampling interval of DL1
55  extern const libtime::TRelativeTime dl1samplinginterval;
56 
57  //! \brief Exception indicating an inconsistent data line.
59  public datrw::Exception {
60  public:
61  //! Create with message, failed assertion, and code position
62  ExceptionRecordWindow(const char* message,
63  const char* file,
64  const int& line,
65  const char* condition,
66  libtime::TAbsoluteTime earliest,
67  libtime::TAbsoluteTime latest,
68  std::string dataline):
69  Exception(message, file, line, condition),
70  Mearliest(earliest),
71  Mlatest(latest),
72  Mdataline(dataline) { }
73  virtual ~ExceptionRecordWindow() { }
74  virtual void report() const;
75  private:
76  void my_report() const;
77  libtime::TAbsoluteTime Mearliest;
78  libtime::TAbsoluteTime Mlatest;
79  std::string Mdataline;
80  }; // class ExceptionInconsistentLine
81 
82  /*======================================================================*/
83 
84  /*! \brief Store the header of a data file
85  *
86  */
87  struct FileHeader {
88  public:
89  //! clear entries
90  void clear();
91  //! A collection of header lines with hash sign stripped off
92  ::sff::FREE lines;
93  //! Expected initial data line (as announced in header lines)
95  //! Expected final data line (as announced in header lines)
96  std::string expectedfinaldataline;
97  //! Initial data line
98  std::string initialdataline;
99  //! earliest date
100  libtime::TAbsoluteTime earliestdate;
101  //! latest date
102  libtime::TAbsoluteTime latestdate;
103  //! creation date
104  libtime::TAbsoluteTime creationdate;
105  //! true if header data was read successfully
107  //! return WID2 header
108  ::sff::WID2 wid2line() const;
109  //! number of samples
110  unsigned int nsamples() const;
111  }; // struct FileHeader
112 
113  /*----------------------------------------------------------------------*/
114 
115  /*! \brief Read and parse a file header
116  */
117  FileHeader readheader(std::istream & is);
118 
119  /*======================================================================*/
120 
121  /*! \brief Store a full data file.
122  *
123  * The container is filled by the read function.
124  */
125  class File {
126  public:
127  /*! The file container is just created and initial values (indicating
128  * emptyness) are set.
129  * Use the read function to actually fill the container.
130  */
131  File() { this->clear(); }
132  //! actually read file
133  void readwithheader(std::istream& is);
134  //! actually read file
135  void read(std::istream& is, const FileHeader& header);
136  //! clear container
137  void clear();
138  /*! check whether container was properly filled
139  *
140  * \param throwerrors if true, throws an error upon the first
141  * condition not properly set
142  * \return true if instance contains meaningful and consistent data
143  */
144  bool isproperlyfilled(const bool& throwerrors=false) const;
145  //! return FREE lines read from file header
146  ::sff::FREE filefree() const { return Mheader.lines; };
147  //! return FREE lines produced while reading the data
148  ::sff::FREE tracefree() const { return Mtracefree; };
149  //! return data block of values
150  Tdseries dseries() const;
151  //! return data block of values
152  Tfseries fseries() const;
153  //! return data block of counts
154  Tiseries iseries() const;
155  //! number of samples expected in this data set
156  int nsamples() const;
157  //! return WID2 header
158  ::sff::WID2 wid2line() const;
159  //! return file header
160  FileHeader header() const { return Mheader; };
161 
162  //! true if unexpected data time was found
164  { return(Mfoundunexpecteddatatime); }
165 
166  //! set tolerance for redundant samples
167  void tolerateredundant(const bool flag=true)
169  //! set tolerance for wrong time
170  void toleratewrongtime(const bool flag=true)
172  private:
173  //! drop a data line
174  void put(const DataLine& line);
175 
176  //! is this container empty and ready for reading?
178  //! true if data was read successfully
180  //! file header
182  //! number of samples
183  unsigned int Mnsamples;
184  //! found unexpected data time
186  //! prepare are series of counts
188  //! an array to keep track of samples
189  aff::Series<bool> Mfilled;
190  //! comment header lines
191  ::sff::FREE Mtracefree;
192 
193  //! mode: do not abort upon redundant samples
195  //! mode: do not abort upon wrong sample time
197  }; // class File
198 
199  } // namespace thiesdl1
200 
201 } // namespace datrw
202 
203 #endif // DATRW_THIESDL1FILE_H_VERSION (includeguard)
204 
205 /* ----- END OF thiesdl1file.h ----- */
void clear()
clear entries
internal data types (prototypes)
ExceptionRecordWindow(const char *message, const char *file, const int &line, const char *condition, libtime::TAbsoluteTime earliest, libtime::TAbsoluteTime latest, std::string dataline)
Create with message, failed assertion, and code position.
Definition: thiesdl1file.h:62
::sff::FREE filefree() const
return FREE lines read from file header
Definition: thiesdl1file.h:146
FileHeader readheader(std::istream &is)
Read and parse a file header.
Exception indicating an inconsistent data line.
Definition: thiesdl1file.h:58
aff::Series< float > Tfseries
Definition: types.h:46
Tdseries dseries() const
return data block of values
bool Mbetolerantagainstwrongtime
mode: do not abort upon wrong sample time
Definition: thiesdl1file.h:196
::sff::FREE tracefree() const
return FREE lines produced while reading the data
Definition: thiesdl1file.h:148
bool readsuccessfully
true if header data was read successfully
Definition: thiesdl1file.h:106
void toleratewrongtime(const bool flag=true)
set tolerance for wrong time
Definition: thiesdl1file.h:170
void tolerateredundant(const bool flag=true)
set tolerance for redundant samples
Definition: thiesdl1file.h:167
Store one line of data as read from DL1.
Definition: thiesdl1line.h:70
aff::Series< double > Tdseries
Definition: types.h:45
const libtime::TRelativeTime dl1samplinginterval
expected sampling interval of DL1
unsigned int Mnsamples
number of samples
Definition: thiesdl1file.h:183
unsigned int nsamples() const
number of samples
bool Mbetolerantagainstredundant
mode: do not abort upon redundant samples
Definition: thiesdl1file.h:194
FileHeader header() const
return file header
Definition: thiesdl1file.h:160
aff::Series< bool > Mfilled
an array to keep track of samples
Definition: thiesdl1file.h:189
Store a full data file.
Definition: thiesdl1file.h:125
exception class declaration for libdatrwxx (prototypes)
Tiseries Miseries
prepare are series of counts
Definition: thiesdl1file.h:187
Base class for exceptions.
Definition: exception.h:62
void readwithheader(std::istream &is)
actually read file
libtime::TAbsoluteTime latestdate
latest date
Definition: thiesdl1file.h:102
::sff::FREE lines
A collection of header lines with hash sign stripped off.
Definition: thiesdl1file.h:92
std::string initialdataline
Initial data line.
Definition: thiesdl1file.h:98
bool isproperlyfilled(const bool &throwerrors=false) const
bool Mreadyforreading
is this container empty and ready for reading?
Definition: thiesdl1file.h:177
libtime::TAbsoluteTime creationdate
creation date
Definition: thiesdl1file.h:104
bool Mfoundunexpecteddatatime
found unexpected data time
Definition: thiesdl1file.h:185
Tiseries iseries() const
return data block of counts
Root namespace of library.
Definition: aalibdatrwxx.cc:16
::sff::WID2 wid2line() const
return WID2 header
Store the header of a data file.
Definition: thiesdl1file.h:87
libtime::TAbsoluteTime Mearliest
Definition: thiesdl1file.h:77
FileHeader Mheader
file header
Definition: thiesdl1file.h:181
void read(std::istream &is, const FileHeader &header)
actually read file
::sff::FREE Mtracefree
comment header lines
Definition: thiesdl1file.h:191
void clear()
clear container
aff::Series< int > Tiseries
Definition: types.h:47
std::string expectedfinaldataline
Expected final data line (as announced in header lines)
Definition: thiesdl1file.h:96
Tfseries fseries() const
return data block of values
libtime::TAbsoluteTime earliestdate
earliest date
Definition: thiesdl1file.h:100
virtual void report() const
Screen report.
Definition: thiesdl1file.cc:79
const char *const precipitationID
SEED channel identifier for precipitation.
Definition: thiesdl1file.cc:75
int nsamples() const
number of samples expected in this data set
std::string expectedinitialdataline
Expected initial data line (as announced in header lines)
Definition: thiesdl1file.h:94
bool foundunexpecteddatatime() const
true if unexpected data time was found
Definition: thiesdl1file.h:163
bool Mreadsuccessfully
true if data was read successfully
Definition: thiesdl1file.h:179
void put(const DataLine &line)
drop a data line
::sff::WID2 wid2line() const
return WID2 header