DATRW++ library: seismic data I/O with multiple formats
ibonjerstream.cc
Go to the documentation of this file.
1 /*! \file ibonjerstream.cc
2  * \brief read bonjers ASCII data (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 30/03/2004
8  *
9  * read bonjers ASCII data (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  * - 30/03/2004 V1.0 Thomas Forbriger
31  * - 31/10/2010 V1.1 pass station value to station header field
32  * - 23/11/2010 V1.2 introduced static members
33  *
34  * ============================================================================
35  */
36 #define DATRW_BONJER_CC_VERSION \
37  "DATRW_BONJER_CC V1.2"
38 
39 #include <datrwxx/bonjer.h>
40 #include <datrwxx/readbonjer.h>
41 
42 namespace datrw {
43 
44  const std::ios_base::openmode ibonjerstream::openmode=std::ios_base::in;
45 
46  //@{
47  /*! \brief Format properties
48  * \ingroup group_bonjer
49  */
50  const bool bonjer::isbinary=false;
51  const char* const bonjer::streamID="bonjer";
52  //@}
53 
54  /*----------------------------------------------------------------------*/
55 
56  ibonjerstream::ibonjerstream(std::istream& is): Tbase(is, true, true, true)
57  { }
58 
59  namespace helper {
60 
61  template<class C>
62  C readany(std::istream& is, const int& n)
63  {
64  C retval(n);
65  double inval;
66  for (int i=0; i<n; ++i)
67  {
68  DATRW_assert(is.good(),"ERROR (ibonjerstream::?series): "
69  "bad stream!");
70  is >> inval;
71  retval(i)=typename C::Tvalue(inval);
72  }
73  return(retval);
74  }
75 
76  } // namespace helper
77 
78  /*----------------------------------------------------------------------*/
79 
81  {
82  readheader();
83  return(helper::readany<Tdseries>(Mis, this->wid2().nsamples));
84  }
85 
86  /*----------------------------------------------------------------------*/
87 
89  {
90  readheader();
91  return(helper::readany<Tfseries>(Mis, this->wid2().nsamples));
92  }
93 
94  /*----------------------------------------------------------------------*/
95 
97  {
98  readheader();
99  return(helper::readany<Tiseries>(Mis, this->wid2().nsamples));
100  }
101 
102  /*----------------------------------------------------------------------*/
103 
105  {
107  sff::FREE tracefree;
108  sff::WID2 wid2;
109  this->newtrace();
110  wid2.station=hd.station;
111  tracefree.append("station: " + hd.station);
112  wid2.nsamples=hd.nsamples;
113  tracefree.append("file: " + hd.filename);
114  wid2.auxid=hd.component;
115  wid2.channel=hd.component.substr(4);
116  tracefree.append("component: " + hd.component);
117  wid2.date=hd.date;
118  tracefree.append("date: " + hd.date.timestring());
119  wid2.dt=1./hd.rate;
120  tracefree.append("sensitivity: " + hd.sensitivity);
121  tracefree.append("units: " + hd.units);
122  this->setlast();
123  this->settracefree(tracefree);
124  this->setwid2(wid2);
125  }
126 
127 } // namespace datrw
128 
129 /* ----- END OF ibonjerstream.cc ----- */
std::string station
Definition: readbonjer.h:60
virtual Tiseries iseries()
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
virtual Tfseries fseries()
aff::Series< float > Tfseries
Definition: types.h:46
static const std::ios_base::openmode openmode
Definition: bonjer.h:74
sff::WID2 wid2() const
Definition: datread.h:111
ibonjerstream(std::istream &is)
C readany(std::istream &is, const int &n)
aff::Series< double > Tdseries
Definition: types.h:45
const bool isbinary
Format properties.
const int nsamples
number of samples per minute block and channel
Definition: hpmodata.h:51
std::string filename
Definition: readbonjer.h:62
std::istream & Mis
Definition: datread.h:126
void setwid2(const sff::WID2 &wid2)
Definition: datread.cc:113
libtime::TAbsoluteTime date
Definition: readbonjer.h:64
int Tvalue
Definition: pdasread.h:75
Root namespace of library.
Definition: aalibdatrwxx.cc:16
const char *const streamID
Format properties.
void settracefree(const sff::FREE &free)
Definition: datread.cc:105
read bonjers ASCII data (prototypes)
std::string sensitivity
Definition: readbonjer.h:66
aff::Series< int > Tiseries
Definition: types.h:47
hold file header contents
Definition: readbonjer.h:59
header readheader(std::istream &is, const bool &verbose)
function to read the file header
Definition: readbonjer.cc:76
std::string units
Definition: readbonjer.h:67
std::string component
Definition: readbonjer.h:63
virtual Tdseries dseries()