DATRW++ library: seismic data I/O with multiple formats
sacread.h
Go to the documentation of this file.
1 /*! \file sacread.h
2  * \brief decode sac files (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 21/12/2004
8  *
9  * decode sac files (prototypes)
10  *
11  * ----
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25  * ----
26  *
27  * Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
28  *
29  * REVISIONS and CHANGES
30  * - 21/12/2004 V1.0 Thomas Forbriger
31  * - 18/01/2008 V1.1 changed declaration of SAC structure
32  * long is now int; this should provide 4 byte
33  * integers on 32bit and 64bit systems as well
34  *
35  * ============================================================================
36  */
37 
38 // include guard
39 #ifndef DATRW_SACREAD_H_VERSION
40 
41 #define DATRW_SACREAD_H_VERSION \
42  "DATRW_SACREAD_H V1.1"
43 
44 #include<istream>
45 #include<aff/series.h>
46 
47 namespace datrw {
48 
49  /*! \brief all the stuff to read SAC binary data
50  *
51  * \defgroup group_sac Reading module for: SAC binary data
52  */
53 
54  /*! \brief all the stuff to read SAC binary data
55  *
56  * \ingroup group_sac
57  */
58  namespace sac {
59 
60 /*======================================================================*/
61 
62  /*! \brief header structure for SAC binary data
63  *
64  * \ingroup group_sac
65  * \code
66  *
67  * this file comes along with the source of rdseed5.0 from IRIS DMC
68  * rdseed is distributed unter the
69  * GNU Lesser General Public License, Version 2.1, February 1999
70  *
71  *===========================================================================*
72  * SEED reader | sac.h | header file *
73  *===========================================================================*
74  *
75  Name: sac.h
76  Purpose: structure for header of a SAC (Seismic Analysis Code) data file
77  Usage: #include "sac.h"
78  Input: not applicable
79  Output: not applicable
80  Warnings: not applicable
81  Errors: not applicable
82  Called by: output_data
83  Calls to: none
84  Algorithm: not applicable
85  Notes: Key to comment flags describing each field:
86  Column 1:
87  R = required by SAC
88  = (blank) optional
89  Column 2:
90  A = settable from a priori knowledge
91  D = available in data
92  F = available in or derivable from SEED fixed data header
93  T = available in SEED header tables
94  = (blank) not directly available from SEED data, header
95  tables, or elsewhere
96  Problems: none known
97  References: O'Neill, D. (1987). IRIS Interim Data Distribution Format
98  (SAC ASCII), Version 1.0 (12 November 1987). Incorporated
99  Research Institutions for Seismology, 1616 North Fort Myer
100  Drive, Suite 1440, Arlington, Virginia 22209. 11 pp.
101  Tull, J. (1987). SAC User's Manual, Version 10.2, October 7,
102  1987. Lawrence Livermore National Laboratory, L-205,
103  Livermore, California 94550. ??? pp.
104  Language: C, hopefully ANSI standard
105  Author: Dennis O'Neill
106  Revisions:07/15/88 Dennis O'Neill Initial preliminary release 0.9
107  11/21/88 Dennis O'Neill Production release 1.0
108  09/19/89 Dennis O'Neill corrected length of char strings
109 
110  18/01/2008 modified long to int declaration
111 
112  \endcode
113 */
114  struct SACheader
115  {
116  public:
117  float delta; //!< RF time increment, sec
118  float depmin; //!< minimum amplitude
119  float depmax; //!< maximum amplitude
120  float scale; //!< amplitude scale factor
121  float odelta; //!< observed time inc
122  float b; //!< RD initial value, ampl.
123  float e; //!< RD final value, amplitude
124  float o; //!< event start, sec > 0
125  float a; //!< 1st arrival time
126  float internal1; //!< internal use
127  float t0; //!< user-defined time pick
128  float t1; //!< user-defined time pick
129  float t2; //!< user-defined time pick
130  float t3; //!< user-defined time pick
131  float t4; //!< user-defined time pick
132  float t5; //!< user-defined time pick
133  float t6; //!< user-defined time pick
134  float t7; //!< user-defined time pick
135  float t8; //!< user-defined time pick
136  float t9; //!< user-defined time pick
137  float f; //!< event end, sec > 0
138  float resp0; //!< instrument respnse parm
139  float resp1; //!< instrument respnse parm
140  float resp2; //!< instrument respnse parm
141  float resp3; //!< instrument respnse parm
142  float resp4; //!< instrument respnse parm
143  float resp5; //!< instrument respnse parm
144  float resp6; //!< instrument respnse parm
145  float resp7; //!< instrument respnse parm
146  float resp8; //!< instrument respnse parm
147  float resp9; //!< instrument respnse parm
148  float stla; //!< T station latititude
149  float stlo; //!< T station longitude
150  float stel; //!< T station elevation, m
151  float stdp; //!< T station depth, m
152  float evla; //!< event latitude
153  float evlo; //!< event longitude
154  float evel; //!< event elevation
155  float evdp; //!< event depth
156  float unused1; //!< reserved for future use
157  float user0; //!< available to user
158  float user1; //!< available to user
159  float user2; //!< available to user
160  float user3; //!< available to user
161  float user4; //!< available to user
162  float user5; //!< available to user
163  float user6; //!< available to user
164  float user7; //!< available to user
165  float user8; //!< available to user
166  float user9; //!< available to user
167  float dist; //!< stn-event distance, km
168  float az; //!< event-stn azimuth
169  float baz; //!< stn-event azimuth
170  float gcarc; //!< stn-event dist, degrees
171  float internal2; //!< internal use
172  float internal3; //!< internal use
173  float depmen; //!< mean value, amplitude
174  float cmpaz; //!< T component azimuth
175  float cmpinc; //!< T component inclination
176  float unused2; //!< reserved for future use
177  float unused3; //!< reserved for future use
178  float unused4; //!< reserved for future use
179  float unused5; //!< reserved for future use
180  float unused6; //!< reserved for future use
181  float unused7; //!< reserved for future use
182  float unused8; //!< reserved for future use
183  float unused9; //!< reserved for future use
184  float unused10; //!< reserved for future use
185  float unused11; //!< reserved for future use
186  float unused12; //!< reserved for future use
187  int nzyear; //!< F zero time of file, yr
188  int nzjday; //!< F zero time of file, day
189  int nzhour; //!< F zero time of file, hr
190  int nzmin; //!< F zero time of file, min
191  int nzsec; //!< F zero time of file, sec
192  int nzmsec; //!< F zero time of file, msec
193  int internal4; //!< internal use
194  int internal5; //!< internal use
195  int internal6; //!< internal use
196  int npts; //!< RF number of samples
197  int internal7; //!< internal use
198  int internal8; //!< internal use
199  int unused13; //!< reserved for future use
200  int unused14; //!< reserved for future use
201  int unused15; //!< reserved for future use
202  int iftype; //!< RA type of file
203  int idep; //!< type of amplitude
204  int iztype; //!< zero time equivalence
205  int unused16; //!< reserved for future use
206  int iinst; //!< recording instrument
207  int istreg; //!< stn geographic region
208  int ievreg; //!< event geographic region
209  int ievtyp; //!< event type
210  int iqual; //!< quality of data
211  int isynth; //!< synthetic data flag
212  int unused17; //!< reserved for future use
213  int unused18; //!< reserved for future use
214  int unused19; //!< reserved for future use
215  int unused20; //!< reserved for future use
216  int unused21; //!< reserved for future use
217  int unused22; //!< reserved for future use
218  int unused23; //!< reserved for future use
219  int unused24; //!< reserved for future use
220  int unused25; //!< reserved for future use
221  int unused26; //!< reserved for future use
222  int leven; //!< RA data-evenly-spaced flag
223  int lpspol; //!< station polarity flag
224  int lovrok; //!< overwrite permission
225  int lcalda; //!< calc distance, azimuth
226  int unused27; //!< reserved for future use
227  char kstnm[8]; //!< F station name
228  char kevnm[16]; //!< event name
229  char khole[8]; //!< man-made event name
230  char ko[8]; //!< event origin time id
231  char ka[8]; //!< 1st arrival time ident
232  char kt0[8]; //!< time pick 0 ident
233  char kt1[8]; //!< time pick 1 ident
234  char kt2[8]; //!< time pick 2 ident
235  char kt3[8]; //!< time pick 3 ident
236  char kt4[8]; //!< time pick 4 ident
237  char kt5[8]; //!< time pick 5 ident
238  char kt6[8]; //!< time pick 6 ident
239  char kt7[8]; //!< time pick 7 ident
240  char kt8[8]; //!< time pick 8 ident
241  char kt9[8]; //!< time pick 9 ident
242  char kf[8]; //!< end of event ident
243  char kuser0[8]; //!< available to user
244  char kuser1[8]; //!< available to user
245  char kuser2[8]; //!< available to user
246  char kcmpnm[8]; //!< F component name
247  char knetwk[8]; //!< network name
248  char kdatrd[8]; //!< date data read
249  char kinst[8]; //!< instrument name
250  }; // struct SACheader
251 
252 /*======================================================================*/
253 
254  /*! \brief binary SAC sample type
255  *
256  * \ingroup group_sac
257  */
258  typedef float Tvalue;
259 
260  /*! ief SAC sample array type
261  *
262  * \ingroup group_sac
263  */
264  typedef aff::Series<Tvalue> Tseries;
265 
266 /*======================================================================*/
267 // functions
268 
269  /*! \brief read SAC header from stream
270  *
271  * \ingroup group_sac
272  */
273  SACheader read_sac_header(std::istream& is);
274 
275  /*! \brief print information about file decoding
276  *
277  * \ingroup group_sac
278  */
279  void help(std::ostream& os);
280 
281  /*! \brief read samples from file
282  *
283  * \ingroup group_sac
284  */
285  Tseries read_sac_data(std::istream& is, const int& nsamples);
286 
287  } // namespace sac
288 
289 } // namespace datrw
290 
291 #endif // DATRW_SACREAD_H_VERSION (includeguard)
292 
293 /* ----- END OF sacread.h ----- */
float baz
stn-event azimuth
Definition: sacread.h:169
float resp5
instrument respnse parm
Definition: sacread.h:143
char kt4[8]
time pick 4 ident
Definition: sacread.h:236
float t8
user-defined time pick
Definition: sacread.h:135
float o
event start, sec > 0
Definition: sacread.h:124
float resp9
instrument respnse parm
Definition: sacread.h:147
float t4
user-defined time pick
Definition: sacread.h:131
float resp7
instrument respnse parm
Definition: sacread.h:145
float resp2
instrument respnse parm
Definition: sacread.h:140
int nzmsec
F zero time of file, msec.
Definition: sacread.h:192
float unused7
reserved for future use
Definition: sacread.h:181
int iztype
zero time equivalence
Definition: sacread.h:204
int internal5
internal use
Definition: sacread.h:194
char kevnm[16]
event name
Definition: sacread.h:228
int unused25
reserved for future use
Definition: sacread.h:220
int npts
RF number of samples.
Definition: sacread.h:196
float resp0
instrument respnse parm
Definition: sacread.h:138
int unused24
reserved for future use
Definition: sacread.h:219
float cmpaz
T component azimuth.
Definition: sacread.h:174
float resp8
instrument respnse parm
Definition: sacread.h:146
float b
RD initial value, ampl.
Definition: sacread.h:122
int unused18
reserved for future use
Definition: sacread.h:213
float delta
RF time increment, sec.
Definition: sacread.h:117
float unused5
reserved for future use
Definition: sacread.h:179
float t0
user-defined time pick
Definition: sacread.h:127
char kt6[8]
time pick 6 ident
Definition: sacread.h:238
float user5
available to user
Definition: sacread.h:162
float user9
available to user
Definition: sacread.h:166
int internal8
internal use
Definition: sacread.h:198
SACheader read_sac_header(std::istream &is)
read SAC header from stream
Definition: sacread.cc:45
int nzyear
F zero time of file, yr.
Definition: sacread.h:187
char kt3[8]
time pick 3 ident
Definition: sacread.h:235
int internal7
internal use
Definition: sacread.h:197
char knetwk[8]
network name
Definition: sacread.h:247
float internal2
internal use
Definition: sacread.h:171
int unused17
reserved for future use
Definition: sacread.h:212
float f
event end, sec > 0
Definition: sacread.h:137
int unused21
reserved for future use
Definition: sacread.h:216
char kdatrd[8]
date data read
Definition: sacread.h:248
float stel
T station elevation, m.
Definition: sacread.h:150
char kt2[8]
time pick 2 ident
Definition: sacread.h:234
float user6
available to user
Definition: sacread.h:163
char ka[8]
1st arrival time ident
Definition: sacread.h:231
int unused19
reserved for future use
Definition: sacread.h:214
char kstnm[8]
F station name.
Definition: sacread.h:227
float stla
T station latititude.
Definition: sacread.h:148
float user1
available to user
Definition: sacread.h:158
float evdp
event depth
Definition: sacread.h:155
float gcarc
stn-event dist, degrees
Definition: sacread.h:170
float evla
event latitude
Definition: sacread.h:152
float internal1
internal use
Definition: sacread.h:126
float resp4
instrument respnse parm
Definition: sacread.h:142
Tseries read_sac_data(std::istream &is, const int &nsamples)
read samples from file
Definition: sacread.cc:72
const int nsamples
number of samples per minute block and channel
Definition: hpmodata.h:51
float unused11
reserved for future use
Definition: sacread.h:185
float stlo
T station longitude.
Definition: sacread.h:149
float a
1st arrival time
Definition: sacread.h:125
float evlo
event longitude
Definition: sacread.h:153
int lovrok
overwrite permission
Definition: sacread.h:224
int iftype
RA type of file.
Definition: sacread.h:202
char kuser1[8]
available to user
Definition: sacread.h:244
float user2
available to user
Definition: sacread.h:159
char kt1[8]
time pick 1 ident
Definition: sacread.h:233
float unused6
reserved for future use
Definition: sacread.h:180
int unused15
reserved for future use
Definition: sacread.h:201
char khole[8]
man-made event name
Definition: sacread.h:229
int lpspol
station polarity flag
Definition: sacread.h:223
float scale
amplitude scale factor
Definition: sacread.h:120
float t9
user-defined time pick
Definition: sacread.h:136
char kf[8]
end of event ident
Definition: sacread.h:242
int unused27
reserved for future use
Definition: sacread.h:226
int iinst
recording instrument
Definition: sacread.h:206
int nzsec
F zero time of file, sec.
Definition: sacread.h:191
float t6
user-defined time pick
Definition: sacread.h:133
float evel
event elevation
Definition: sacread.h:154
float t1
user-defined time pick
Definition: sacread.h:128
int unused22
reserved for future use
Definition: sacread.h:217
float unused9
reserved for future use
Definition: sacread.h:183
char ko[8]
event origin time id
Definition: sacread.h:230
float depmen
mean value, amplitude
Definition: sacread.h:173
float t5
user-defined time pick
Definition: sacread.h:132
Root namespace of library.
Definition: aalibdatrwxx.cc:16
void help(std::ostream &os)
print information about file decoding
Definition: sacread.cc:56
int lcalda
calc distance, azimuth
Definition: sacread.h:225
header structure for SAC binary data
Definition: sacread.h:114
float unused4
reserved for future use
Definition: sacread.h:178
char kinst[8]
instrument name
Definition: sacread.h:249
char kt0[8]
time pick 0 ident
Definition: sacread.h:232
char kuser0[8]
available to user
Definition: sacread.h:243
float depmax
maximum amplitude
Definition: sacread.h:119
int iqual
quality of data
Definition: sacread.h:210
int leven
RA data-evenly-spaced flag.
Definition: sacread.h:222
float az
event-stn azimuth
Definition: sacread.h:168
float t2
user-defined time pick
Definition: sacread.h:129
char kt5[8]
time pick 5 ident
Definition: sacread.h:237
char kuser2[8]
available to user
Definition: sacread.h:245
char kt8[8]
time pick 8 ident
Definition: sacread.h:240
float user3
available to user
Definition: sacread.h:160
char kcmpnm[8]
F component name.
Definition: sacread.h:246
float user4
available to user
Definition: sacread.h:161
int nzmin
F zero time of file, min.
Definition: sacread.h:190
float unused10
reserved for future use
Definition: sacread.h:184
float odelta
observed time inc
Definition: sacread.h:121
int unused13
reserved for future use
Definition: sacread.h:199
int istreg
stn geographic region
Definition: sacread.h:207
int unused23
reserved for future use
Definition: sacread.h:218
char kt7[8]
time pick 7 ident
Definition: sacread.h:239
int nzhour
F zero time of file, hr.
Definition: sacread.h:189
int internal6
internal use
Definition: sacread.h:195
float resp3
instrument respnse parm
Definition: sacread.h:141
float user7
available to user
Definition: sacread.h:164
float unused12
reserved for future use
Definition: sacread.h:186
float internal3
internal use
Definition: sacread.h:172
int idep
type of amplitude
Definition: sacread.h:203
float cmpinc
T component inclination.
Definition: sacread.h:175
int ievreg
event geographic region
Definition: sacread.h:208
float unused1
reserved for future use
Definition: sacread.h:156
aff::Series< Tvalue > Tseries
Definition: sacread.h:264
int unused20
reserved for future use
Definition: sacread.h:215
float user8
available to user
Definition: sacread.h:165
int isynth
synthetic data flag
Definition: sacread.h:211
int ievtyp
event type
Definition: sacread.h:209
float resp6
instrument respnse parm
Definition: sacread.h:144
float resp1
instrument respnse parm
Definition: sacread.h:139
float stdp
T station depth, m.
Definition: sacread.h:151
float user0
available to user
Definition: sacread.h:157
int unused14
reserved for future use
Definition: sacread.h:200
int internal4
internal use
Definition: sacread.h:193
float unused8
reserved for future use
Definition: sacread.h:182
int unused16
reserved for future use
Definition: sacread.h:205
float unused3
reserved for future use
Definition: sacread.h:177
float e
RD final value, amplitude.
Definition: sacread.h:123
float dist
stn-event distance, km
Definition: sacread.h:167
float unused2
reserved for future use
Definition: sacread.h:176
int unused26
reserved for future use
Definition: sacread.h:221
float t7
user-defined time pick
Definition: sacread.h:134
float t3
user-defined time pick
Definition: sacread.h:130
float Tvalue
binary SAC sample type
Definition: sacread.h:258
float depmin
minimum amplitude
Definition: sacread.h:118
int nzjday
F zero time of file, day.
Definition: sacread.h:188
char kt9[8]
time pick 9 ident
Definition: sacread.h:241