DATRW++ library: seismic data I/O with multiple formats
readbonjer.cc
Go to the documentation of this file.
1 /*! \file readbonjer.cc
2  * \brief read data obtained in ASCII from K. Bonjer (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 30/03/2004
8  *
9  * read data obtained in ASCII from K. Bonjer (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  *
32  * ============================================================================
33  */
34 #define DATRW_READBONJER_CC_VERSION \
35  "DATRW_READBONJER_CC V1.0 "
36 
37 #include<cstdlib>
38 #include<sstream>
39 #include<datrwxx/readbonjer.h>
40 
41 namespace datrw {
42 
43  /*!
44  * To provide a definition of the data format, we dump
45  * the first lines of a data file example.
46  *
47  * B30815IB.001.NS.ACC.ASC:
48  * \verbatim
49 ********************************************************
50 
51 ACHTUNG: Polaritaeten und Komponentenzuordung nur dem
52 Konfigurationsfile K2parcfg_xxxx.dat entnehmen !!!
53 
54 ********************************************************
55 
56 K2 Stn: IBA
57 Event Start Time: 11/30/2002 (334) 8:15:42.000
58 Samples per second: 200
59 Number of points: 24400
60 Filename: B30815IB.001.NS.ACC.ASC
61 Component: IB1N NS
62 Sensitivity: 1.2540 V/g
63 Units: CM/S**2
64 
65  6.793764e-01
66  6.789101e-01
67  6.779776e-01
68  ...
69  \endverbatim
70  */
71  namespace bonjer {
72 
73 /*----------------------------------------------------------------------*/
74 
75  //! function to read the file header
76  header readheader(std::istream& is, const bool& verbose)
77  {
78  std::string line;
79  bool hot=true;
80  header retval;
81  int mandatory=0;
82  while (hot && is.good()) {
83  getline(is, line);
84  if (line.substr(0,7)==std::string("K2 Stn:"))
85  {
86  retval.station=line.substr(8);
87  mandatory++;
88  } else
89  if (line.substr(0,17)==std::string("Event Start Time:"))
90  {
91  std::istringstream iss(line.substr(18).c_str());
92  char c;
93  int day, month, year, hour, minute;
94  double seconds;
95  iss >> month >> c >> day >> c >> year;
96  iss >> c >> hour >> c;
97  iss >> hour >> c >> minute >> c >> seconds;
98  retval.date=libtime::TAbsoluteTime(year,month,day,hour,minute);
99  retval.date+=libtime::double2time(seconds);
100  mandatory++;
101  } else
102  if (line.substr(0,19)==std::string("Samples per second:"))
103  {
104  retval.rate=std::atof(line.substr(20).c_str());
105  mandatory++;
106  } else
107  if (line.substr(0,17)==std::string("Number of points:"))
108  {
109  retval.nsamples=std::atoi(line.substr(18).c_str());
110  mandatory++;
111  } else
112  if (line.substr(0,9)==std::string("Filename:"))
113  {
114  retval.filename=line.substr(10);
115  mandatory++;
116  } else
117  if (line.substr(0,10)==std::string("Component:"))
118  {
119  retval.component=line.substr(11);
120  mandatory++;
121  } else
122  if (line.substr(0,12)==std::string("Sensitivity:"))
123  {
124  retval.sensitivity=line.substr(13);
125  mandatory++;
126  } else
127  if (line.substr(0,6)==std::string("Units:"))
128  {
129  retval.units=line.substr(7);
130  mandatory++;
131  }
132  if (mandatory > 7) { hot=false; }
133  }
134  if (mandatory<8) throw;
135  getline(is,line);
136  if (verbose)
137  {
138  std::cout << "File: " << retval.filename << std::endl;
139  std::cout << "Station: " << retval.station << std::endl;
140  std::cout << "Component: " << retval.component << std::endl;
141  std::cout << "First: " << retval.date.timestring() << std::endl;
142  std::cout << "Rate: " << retval.rate << std::endl;
143  std::cout << "Samples: " << retval.nsamples << std::endl;
144  std::cout << "Sensitivity: " << retval.sensitivity << std::endl;
145  std::cout << "Units: " << retval.units << std::endl;
146  }
147  return(retval);
148  } // function readheader
149 
150 /*----------------------------------------------------------------------*/
151 
152  //! function to read the file data
153  Tdata readdata(std::istream& is, const header& hd)
154  {
155  Tdata retval(hd.nsamples);
156  for (int i=0; i<hd.nsamples; ++i)
157  {
158  if (!is.good()) throw;
159  is >> retval(i);
160  }
161  return(retval);
162  } // function readdata
163 
164  } // namespace bonjer
165 
166 } // namespace datrw
167 
168 /* ----- END OF readbonjer.cc ----- */
std::string station
Definition: readbonjer.h:60
Tdata readdata(std::istream &is, const header &hd)
function to read the file data
Definition: readbonjer.cc:153
std::string filename
Definition: readbonjer.h:62
libtime::TAbsoluteTime date
Definition: readbonjer.h:64
Root namespace of library.
Definition: aalibdatrwxx.cc:16
std::string sensitivity
Definition: readbonjer.h:66
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
aff::Series< double > Tdata
we read the data to a vector
Definition: readbonjer.h:71
std::string component
Definition: readbonjer.h:63