DATRW++ library: seismic data I/O with multiple formats
suheader.h
Go to the documentation of this file.
1 /*! \file suheader.h
2  * \brief handle a Seismic Unix trace header (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 19/11/2010
8  *
9  * handle a Seismic Unix trace header (prototypes)
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  * - 19/11/2010 V1.0 Thomas Forbriger
31  * - 21/01/2012 V1.1 provide online help regarding header fields
32  * - 22/01/2012 V1.2
33  * - indicate ultrasonic data
34  * - renamed absdelay -> absdelrt
35  * - 23/01/2012 V1.3
36  * - added member data Mdt and some comments
37  * - 08/07/2016 V1.4
38  * - make exception argument types match base class
39  *
40  * ============================================================================
41  */
42 
43 // include guard
44 #ifndef DATRW_SUHEADER_H_VERSION
45 
46 #define DATRW_SUHEADER_H_VERSION \
47  "DATRW_SUHEADER_H V1.4"
48 
49 #include<iostream>
50 #include<datrwxx/suformat.h>
51 #include<datrwxx/suheaderstruct.h>
52 #include<datrwxx/error.h>
53 #include<sffxx.h>
54 #include<libtime++.h>
55 
56 namespace datrw {
57 
58 
59  /*! \brief All classes and functions for Seismic Unix file data I/O
60  *
61  * Seismic Un*x is available from
62  * http://www.cwp.mines.edu/cwpcodes/
63  *
64  * \defgroup group_su I/O module for Seismic Uni*x data
65  *
66  * \section sec_su_for_TOAST Special format definition within TOAST
67  *
68  * Small sampling interval (smaller than 1 microsecond) as used in
69  * ultrasonic recordings are to be stored in SeismicUn*x data format
70  * within TOAST as follows:
71  *
72  * -# Time values for ultrasonic data will be given in nanoseconds for dt
73  * and microseconds for delrt.
74  * -# This applies to fields
75  * -# dt (byte# 117-118): sample interval
76  * -# delrt (byte# 109-110): delay recording time
77  * .
78  * -# Time units other than microseconds or nanoseconds for dt and
79  * milliseconds or microseconds for delrt are not allowed.
80  * -# Field d1 (byte# 181-184) in TOAST data will be
81  * - either zero, indicating standard seismic data with a micro seconds
82  * time scale
83  * - or provide the sampling interval in seconds, thus indicating
84  * - either standard seismic data, if d1 in seconds matches dt if
85  * the latter is taken in microseconds
86  * - or ultrasonic data, if d1 in seconds matches dt if the latter
87  * is taken in nanoseconds and delrt is taken in microseconds
88  *
89  * This way it will be possible to use SU tools to sort traces or similar
90  * or even waveform filters.
91  * The user just has to take care to pass filter frequencies in kHz rather
92  * than Hz in the case of ultrasonic data.
93  *
94  */
95 
96  /*! \brief All classes and functions to extract data from Seismic Unix files
97  *
98  * \ingroup group_su
99  */
100  namespace su {
101 
102  /*!
103  * \ingroup group_su
104  */
106  {
107  public:
108  //! Create with message, failed assertion, and code position
109  SUReadException(const std::string message,
110  const std::string file,
111  const int& line,
112  const std::string condition)
113  : ::datrw::Exception(message, file, line, condition) { }
114  //! provide explicit virtual destructor
115  virtual ~SUReadException() { }
116  }; // class SUReadException
117 
118  /*----------------------------------------------------------------------*/
119 
120  /*! \brief C++ class to handle Seismic Un*x header struct
121  * \ingroup group_su
122  */
123  class SUheader {
124  public:
125  //! constructor
127  const bool& debug=false);
128  //! set control parameters
130  { Mheadercontrol=hc; }
131  //! clear header struct
132  void clear();
133  //! set defaults to struct
134  void setdefaults();
135 
136  /*! \name in/out functions
137  */
138  ///@{
139  //! read struct from file
140  void read(std::istream& is);
141  //! write struct to file
142  void write(std::ostream& os) const;
143  ///@}
144 
145  /*! \name query functions
146  */
147  ///@{
148  //! return sampling interval
149  double dt() const;
150  //! true if header defines sampling of ultrasonic data
151  bool isultrasonic() const;
152  //! return factor defined by scalel
153  double scalelf() const;
154  //! return factor defined by scalco
155  double scalcof() const;
156  //! return date of first sample
157  libtime::TAbsoluteTime dateoffirstsample() const;
158  //! recording delay
159  libtime::TRelativeTime delay() const;
160  //! is delay positive recording delay
161  bool delayispositive() const;
162  //! absolute (always positive) delay value
163  int absdelrt() const;
164  //! return date of shot
165  libtime::TAbsoluteTime dateofshot() const;
166  //! return SRCE line
167  ::sff::SRCE srce() const;
168  //! return INFO line
169  ::sff::INFO info() const;
170  //! return WID2 line
171  ::sff::WID2 wid2() const;
172  ///@}
173 
174  /*! \name set functions
175  *
176  * Some calculations have to be redone when new information is added
177  * to the header.
178  * For this reason the set functions place part of the data in a local
179  * member data store area (see the store area ind the member data
180  * section).
181  * The function SUheader::settimes() then is called at the end of each
182  * set function body in order to coherently evaluate values collected
183  * from SRCE line and WID2 line header components.
184  */
185  ///@{
186  //! set values from SRCE line
187  void set(const ::sff::SRCE &srce);
188  //! set values from INFO line
189  void set(const ::sff::INFO &info);
190  //! set values from WID2 line
191  void set(const ::sff::WID2 &wid2);
192  //! set date
193  void set(const libtime::TAbsoluteTime &date);
194  //! set time values correctly
195  void settimes();
196  ///@}
197 
198  //! print online help regarding header fields and TOAST data
199  static void help(std::ostream& os);
200  private:
201  //! all options taken from the user
203  //! be verbose
204  bool Mdebug;
205 
206  /*! \name set functions store area
207  *
208  * Set functions receive header data from SFF header components like
209  * WID2, SRCE, and INFO.
210  * The set functions have to scale dt and delrt appropriatly for
211  * seismic and ultrasonic data, respectively.
212  * Further they have to derive the recording delay from the time
213  * interval between source and receiver time, the first being
214  * presented in SRCE, the latter being presented in WID2.
215  * Once new information is added by calling one of the set functions,
216  * some of the calculations must be redone.
217  * The original values are kept in this store area for this purpose.
218  *
219  * \note
220  * This store area is only used for setting values in the header.
221  * If header is read from file, the store area values are undefined.
222  */
223  ///@{
224  //! we received srce data
225  bool Mhassrce;
226  //! we received wid2 data
227  bool Mhaswid2;
228  //! we received info data
229  bool Mhasinfo;
230  //! date from SRCE line
231  libtime::TAbsoluteTime Msrcedate;
232  //! date from WID2 line
233  libtime::TAbsoluteTime Mwid2date;
234  //! intermediately store sampling interval from wid2 line
235  double Mwid2dt;
236  ///@}
237  public:
238  //! the actual data fields are provided for public access
240  }; // class SUheader
241 
242  } // namespace su
243 
244 } // namespace datrw
245 
246 #endif // DATRW_SUHEADER_H_VERSION (includeguard)
247 
248 /* ----- END OF suheader.h ----- */
bool Mhassrce
we received srce data
Definition: suheader.h:225
bool delayispositive() const
is delay positive recording delay
Definition: suheader.cc:230
SUReadException(const std::string message, const std::string file, const int &line, const std::string condition)
Create with message, failed assertion, and code position.
Definition: suheader.h:109
double Mwid2dt
intermediately store sampling interval from wid2 line
Definition: suheader.h:235
::sff::INFO info() const
return INFO line
Definition: suheader.cc:292
SEG-Y and SU trace header as taken from segy.h coming with SeismicUnixsegy - trace identification hea...
C++ class to handle Seismic Un*x header struct.
Definition: suheader.h:123
void clear()
clear header struct
Definition: suheader.cc:123
::sff::WID2 wid2() const
return WID2 line
Definition: suheader.cc:309
libtime::TAbsoluteTime dateoffirstsample() const
return date of first sample
Definition: suheader.cc:215
bool Mhaswid2
we received wid2 data
Definition: suheader.h:227
double dt() const
return sampling interval
Definition: suheader.cc:156
double scalelf() const
return factor defined by scalel
Definition: suheader.cc:197
datrw::su::options::SUHeaderControl Mheadercontrol
all options taken from the user
Definition: suheader.h:202
bool Mdebug
be verbose
Definition: suheader.h:204
exception class declaration for libdatrwxx (prototypes)
Base class for exceptions.
Definition: exception.h:62
int absdelrt() const
absolute (always positive) delay value
Definition: suheader.cc:238
Root namespace of library.
Definition: aalibdatrwxx.cc:16
void write(std::ostream &os) const
write struct to file
Definition: suheader.cc:96
bool isultrasonic() const
true if header defines sampling of ultrasonic data
Definition: suheader.cc:166
libtime::TAbsoluteTime Mwid2date
date from WID2 line
Definition: suheader.h:233
libtime::TRelativeTime delay() const
recording delay
Definition: suheader.cc:250
::sff::SRCE srce() const
return SRCE line
Definition: suheader.cc:275
SUheader(const datrw::su::options::SUHeaderControl &ch, const bool &debug=false)
constructor
Definition: suheader.cc:110
libtime::TAbsoluteTime dateofshot() const
return date of shot
Definition: suheader.cc:261
void settimes()
set time values correctly
Definition: suheader.cc:426
void read(std::istream &is)
read struct from file
Definition: suheader.cc:72
virtual ~SUReadException()
provide explicit virtual destructor
Definition: suheader.h:115
static void help(std::ostream &os)
print online help regarding header fields and TOAST data
Definition: suheader.cc:548
double scalcof() const
return factor defined by scalco
Definition: suheader.cc:206
libtime::TAbsoluteTime Msrcedate
date from SRCE line
Definition: suheader.h:231
bool Mhasinfo
we received info data
Definition: suheader.h:229
options to control the way header variables are handeled.
Definition: suformat.h:168
TraceHeaderStruct Mheader
the actual data fields are provided for public access
Definition: suheader.h:239
void setdefaults()
set defaults to struct
Definition: suheader.cc:135