DATRW++ library: seismic data I/O with multiple formats
isacstream.cc
Go to the documentation of this file.
1 /*! \file isacstream.cc
2  * \brief read SAC files (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 21/12/2004
8  *
9  * read SAC files (implementation)
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  * - 03/05/2010 V1.1 sac provides debugging option
32  * - 23/11/2010 V1.2 introduced static member data
33  * - 18/11/2016 V1.3 use debug flag in base class
34  *
35  * ============================================================================
36  */
37 #define DATRW_ISACSTREAM_CC_VERSION \
38  "DATRW_ISACSTREAM_CC V1.3"
39 
40 #include <string>
41 #include <sstream>
42 #include <datrwxx/sac.h>
43 #include <datrwxx/sacread.h>
44 #include <datrwxx/error.h>
45 #include <datrwxx/util.h>
46 #include <datrwxx/debug.h>
47 
48 namespace datrw {
49 
50  const std::ios_base::openmode
51  isacstream::openmode=std::ios_base::in|std::ios_base::binary;
52 
53  //@{
54  /*! \brief Format properties
55  * \ingroup group_sac
56  */
57  const bool sac::isbinary=true;
58  const char* const sac::streamID="sac";
59  //@}
60 
61  /*----------------------------------------------------------------------*/
62 
63  isacstream::isacstream(std::istream& is, const bool& debug):
64  Tbase(is, true, true, true, debug)
65  { }
66 
67  /*----------------------------------------------------------------------*/
68 
70  {
71  return(datrw::util::convert<Tfseries, Tdseries>(this->fseries()));
72  }
73 
74  /*----------------------------------------------------------------------*/
75 
77  {
78  this->readheader();
79  return(datrw::sac::read_sac_data(this->Mis, this->wid2().nsamples));
80  }
81 
82  /*----------------------------------------------------------------------*/
83 
85  {
86  return(datrw::util::convert<Tfseries, Tiseries>(this->fseries()));
87  }
88 
89  /*----------------------------------------------------------------------*/
90 
92  {
93  DATRW_debug(this->Mdebug, "isacstream::skipseries()",
94  "entered function: call this->readheader()");
95  this->readheader();
96  DATRW_debug(this->Mdebug, "isacstream::skipseries()",
97  "finished; return from function");
98  }
99 
100  /*----------------------------------------------------------------------*/
101 
103  {
104  DATRW_debug(this->Mdebug, "isacstream::readheader()",
105  "start reading header");
106  this->newtrace();
107  sff::FREE free;
108  sff::WID2 wid2;
109  sff::INFO info;
110  std::ostringstream oss;
111  DATRW_debug(this->Mdebug, "isacstream::readheader()",
112  "calling datrw::sac::read_sac_header");
114  DATRW_debug(this->Mdebug, "isacstream::readheader()",
115  "returned from datrw::sac::read_sac_header");
116 
117  oss << "location: ";
118  if (hd.stla>0) { oss << hd.stla << "°N; "; }
119  else { oss << -hd.stla << "°S; "; }
120  if (hd.stlo>0) { oss << hd.stlo << "°E; "; }
121  else { oss << -hd.stlo << "°W"; }
122  free.append(oss.str());
123  DATRW_debug(this->Mdebug, "isacstream::readheader()", oss.str());
124  free.append("values from SAC binary header "
125  "that do not fit into SFF trace header");
126  wid2.dt=hd.delta;
127  oss.str("");
128  oss << "initial index: " << hd.b;
129  oss << "; final index: " << hd.e;
130  free.append(oss.str());
131  info.cs=sff::CS_spherical;
132  info.cx=hd.stla;
133  info.cy=hd.stlo;
134  info.cz=hd.stel;
135  oss.str("");
136  oss << hd.stdp;
137  free.append("station depth: " + oss.str() + " m");
138  wid2.hang=hd.cmpaz;
139  wid2.vang=hd.cmpinc;
140  wid2.date=libtime::TAbsoluteTime(hd.nzyear, 1, 1, hd.nzhour,
141  hd.nzmin, hd.nzsec, hd.nzmsec);
142  wid2.date.setdoy(hd.nzjday);
143  wid2.nsamples=hd.npts;
144  wid2.station=std::string(hd.kstnm,8);
145  wid2.channel=std::string(hd.kcmpnm,8);
146  wid2.auxid=std::string(hd.khole,8);
147  free.append("network name: " + std::string(hd.knetwk, 8));
148  DATRW_assert(hd.iftype==1, "unexpected file type");
149  DATRW_assert(hd.leven==1, "uneven sampling");
150  this->setwid2(wid2);
151  this->setinfo(info);
152  this->settracefree(free);
153  this->setlast();
154 
155  DATRW_debug(this->Mdebug, "isacstream::readheader()",
156  "finished; return from function");
157  }
158 
159  /*----------------------------------------------------------------------*/
160 
161  void isacstream::help(std::ostream& os)
162  { datrw::sac::help(os); }
163 
164 } // namespace datrw
165 
166 /* ----- END OF isacstream.cc ----- */
int nzmsec
F zero time of file, msec.
Definition: sacread.h:192
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
int npts
RF number of samples.
Definition: sacread.h:196
float cmpaz
T component azimuth.
Definition: sacread.h:174
float b
RD initial value, ampl.
Definition: sacread.h:122
macro function for debugging output (prototypes)
void setinfo(const sff::INFO &info)
Definition: datread.cc:121
aff::Series< float > Tfseries
Definition: types.h:46
float delta
RF time increment, sec.
Definition: sacread.h:117
sff::WID2 wid2() const
Definition: datread.h:111
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 knetwk[8]
network name
Definition: sacread.h:247
static const std::ios_base::openmode openmode
Definition: sac.h:71
float stel
T station elevation, m.
Definition: sacread.h:150
char kstnm[8]
F station name.
Definition: sacread.h:227
read SAC files (prototypes)
float stla
T station latititude.
Definition: sacread.h:148
aff::Series< double > Tdseries
Definition: types.h:45
const char *const streamID
Format properties.
Definition: isacstream.cc:58
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
exception class declaration for libdatrwxx (prototypes)
float stlo
T station longitude.
Definition: sacread.h:149
int iftype
RA type of file.
Definition: sacread.h:202
std::istream & Mis
Definition: datread.h:126
char khole[8]
man-made event name
Definition: sacread.h:229
void setwid2(const sff::WID2 &wid2)
Definition: datread.cc:113
int nzsec
F zero time of file, sec.
Definition: sacread.h:191
sff::INFO info() const
Definition: datread.h:110
Root namespace of library.
Definition: aalibdatrwxx.cc:16
void help(std::ostream &os)
print information about file decoding
Definition: sacread.cc:56
const bool isbinary
Format properties.
Definition: isacstream.cc:57
utilities used by more than one type of data reader (prototypes)
header structure for SAC binary data
Definition: sacread.h:114
sff::FREE free() const
Definition: datread.cc:79
virtual Tdseries dseries()
Definition: isacstream.cc:69
int leven
RA data-evenly-spaced flag.
Definition: sacread.h:222
void settracefree(const sff::FREE &free)
Definition: datread.cc:105
aff::Series< int > Tiseries
Definition: types.h:47
char kcmpnm[8]
F component name.
Definition: sacread.h:246
int nzmin
F zero time of file, min.
Definition: sacread.h:190
virtual Tfseries fseries()
Definition: isacstream.cc:76
#define DATRW_debug(C, N, M)
produce debug output
Definition: debug.h:50
isacstream(std::istream &is, const bool &debug=false)
Definition: isacstream.cc:63
int nzhour
F zero time of file, hr.
Definition: sacread.h:189
virtual void skipseries()
Definition: isacstream.cc:91
static void help(std::ostream &os=std::cout)
Definition: isacstream.cc:161
float cmpinc
T component inclination.
Definition: sacread.h:175
float stdp
T station depth, m.
Definition: sacread.h:151
float e
RD final value, amplitude.
Definition: sacread.h:123
virtual Tiseries iseries()
Definition: isacstream.cc:84
int nzjday
F zero time of file, day.
Definition: sacread.h:188