DATRW++ library: seismic data I/O with multiple formats
seifeio.h
Go to the documentation of this file.
1 /*! \file seifeio.h
2  * \brief seife input/output (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 14/02/2011
8  *
9  * seife input/output (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  *
30  * REVISIONS and CHANGES
31  * - 14/02/2011 V1.0 Thomas Forbriger
32  *
33  * ============================================================================
34  */
35 
36 // include guard
37 #ifndef DATRW_SEIFEIO_H_VERSION
38 
39 #define DATRW_SEIFEIO_H_VERSION \
40  "DATRW_SEIFEIO_H V1.0 "
41 
42 #include<string>
43 #include<iostream>
44 #include<sffxx.h>
45 #include<libtime++.h>
46 #include<aff/series.h>
47 
48 namespace datrw {
49 
50  namespace seife {
51 
52  /*! \brief Standard parameters used for seife output
53  * \defgroup group_seife_standard_parameters Standard parameters used for seife output
54  * \ingroup group_seife
55  * @{
56  */
57  extern const char* const seife_standard_format;
58  extern const unsigned int seife_standard_precision;
59  extern const unsigned int seife_standard_width;
60  extern const unsigned int seife_standard_columns;
61  /**@}*/
62 
63  /*----------------------------------------------------------------------*/
64 
65  /*! \brief seife format header parameter line
66  * \ingroup group_seife
67  * \sa \ref sec_seife_formatdefinition
68  */
69  class ParameterLine {
70  public:
71  //! default constructor
73  Mdebug(false),
74  Mnsamples(0),
76  Mdt(1.),
77  Mtime(0,0)
78  { }
79  //! create header from string
80  ParameterLine(const std::string& line, const bool& debug=false):
81  Mdebug(debug)
82  { this->set(line); }
83  //! set values from line
84  void set(const std::string& line);
85  //! create line for output from values
86  std::string line() const;
87 
88  /*! \name query functions
89  */
90  ///@{
91  //! return number of samples
92  unsigned int nsamples() const { return Mnsamples; }
93  //! return Fortran data format
94  std::string format() const { return Mformat; }
95  //! return sumpling interval
96  double dt() const { return Mdt; }
97  //! return time of first sample as offset from midnight
98  libtime::TRelativeTime time() const { return Mtime; }
99  ///@}
100 
101  /*! \name set functions
102  */
103  ///@{
104  //! return number of samples
105  void nsamples(const unsigned int& n) { Mnsamples=n; }
106  //! return Fortran data format
107  void format(const std::string& f) { Mformat=f; }
108  //! return sumpling interval
109  void dt(const double& d) { Mdt=d; }
110  //! return time of first sample as offset from midnight
111  void time(const libtime::TRelativeTime& t) { Mtime=t; }
112  ///@}
113  private:
114  //! request debug output
115  bool Mdebug;
116  //! number of samples
117  unsigned int Mnsamples;
118  //! Fortran data format
119  std::string Mformat;
120  //! sampling interval
121  double Mdt;
122  //! time of first sample
123  libtime::TRelativeTime Mtime;
124  }; // class ParameterLine
125 
126  /*----------------------------------------------------------------------*/
127 
128  /*! \brief class to hold complete seife header
129  * \ingroup group_seife
130  * \sa \ref sec_seife_formatdefinition
131  */
132  class Header {
133  public:
134  //! read header from input
135  Header(std::istream& is) { this->read(is); }
136  //! default constructor
137  Header() { }
138  //! create header with empty comments
139  Header(const ParameterLine& pl):
140  Mparameters(pl)
141  {
142  Mfree.lines.clear();
143  }
144  //! read header from input
145  void read(std::istream& is);
146  ///! write header to stream
147  void write(std::ostream& os) const;
148  //! set comments
149  void set(const ::sff::FREE& free) { Mfree=free; }
150  //! set parameters
152  //! return comments
153  ::sff::FREE comments() const { return Mfree; }
154  //! return parameters
156  private:
157  //! numerical header parameters
159  //! comments
160  ::sff::FREE Mfree;
161  }; // class Header
162 
163  /*----------------------------------------------------------------------*/
164 
165  //! \brief standard sample type
166  typedef double Tsample;
167 
168  //! \brief standard time series type
169  typedef aff::Series<Tsample> Tseries;
170 
171  /*! \brief write samples to file
172  * \param os output stream to write to
173  * \param s series to be written
174  */
175  void write_series(std::ostream& os, const Tseries::Tcoc& s);
176 
177  } // namespace seife
178 
179 } // namespace datrw
180 
181 #endif // DATRW_SEIFEIO_H_VERSION (includeguard)
182 
183 /* ----- END OF seifeio.h ----- */
seife format header parameter line
Definition: seifeio.h:69
unsigned int Mnsamples
number of samples
Definition: seifeio.h:117
const unsigned int seife_standard_columns
Definition: seifeio.cc:50
libtime::TRelativeTime time() const
return time of first sample as offset from midnight
Definition: seifeio.h:98
aff::Series< Tsample > Tseries
standard time series type
Definition: seifeio.h:169
unsigned int nsamples() const
return number of samples
Definition: seifeio.h:92
void read(std::istream &is)
read header from input
Definition: seifeio.cc:141
const char *const seife_standard_format
Definition: seifeio.cc:47
ParameterLine Mparameters
numerical header parameters
Definition: seifeio.h:158
::sff::FREE Mfree
comments
Definition: seifeio.h:160
::sff::FREE comments() const
return comments
Definition: seifeio.h:153
Header()
default constructor
Definition: seifeio.h:137
void nsamples(const unsigned int &n)
return number of samples
Definition: seifeio.h:105
const unsigned int seife_standard_width
Definition: seifeio.cc:49
ParameterLine(const std::string &line, const bool &debug=false)
create header from string
Definition: seifeio.h:80
bool Mdebug
request debug output
Definition: seifeio.h:115
const unsigned int seife_standard_precision
Definition: seifeio.cc:48
Root namespace of library.
Definition: aalibdatrwxx.cc:16
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
Header(std::istream &is)
read header from input
Definition: seifeio.h:135
void time(const libtime::TRelativeTime &t)
return time of first sample as offset from midnight
Definition: seifeio.h:111
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
Header(const ParameterLine &pl)
create header with empty comments
Definition: seifeio.h:139
void format(const std::string &f)
return Fortran data format
Definition: seifeio.h:107
std::string Mformat
Fortran data format.
Definition: seifeio.h:119
double Mdt
sampling interval
Definition: seifeio.h:121
libtime::TRelativeTime Mtime
time of first sample
Definition: seifeio.h:123
ParameterLine parameters() const
return parameters
Definition: seifeio.h:155
void dt(const double &d)
return sumpling interval
Definition: seifeio.h:109
ParameterLine()
default constructor
Definition: seifeio.h:72
double Tsample
standard sample type
Definition: seifeio.h:166
std::string line() const
create line for output from values
Definition: seifeio.cc:112