DATRW++ library: seismic data I/O with multiple formats
gseread.cc
Go to the documentation of this file.
1 /*! \file gseread.cc
2  * \brief raw GSE reading module (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 19/09/2007
8  *
9  * raw GSE reading module (implementation)
10  *
11  * Copyright (c) 2007 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  *
30  * REVISIONS and CHANGES
31  * - 19/09/2007 V1.0 Thomas Forbriger
32  *
33  * ============================================================================
34  */
35 #define DATRW_GSEREAD_CC_VERSION \
36  "DATRW_GSEREAD_CC V1.0 "
37 
38 #include <datrwxx/gseread.h>
39 #include <datrwxx/error.h>
40 #include <sffxx.h>
41 #include <gsexx.h>
42 #include <sstream>
43 
44 namespace datrw {
45 
46  namespace gse {
47 
48  // find next WID2 line
49  sff::WID2 next_wid2(std::istream& is)
50  {
51  sff::WID2 retval;
52  std::string theline;
53  bool hot=true;
54  while (hot)
55  {
56  DATRW_assert(is.good(), "input stream is not good");
57  std::getline(is, theline);
58  std::istringstream iss(theline);
59  hot=false;
60  try
61  {
62  retval.read(iss);
63  }
64  catch (...)
65  {
66  hot=true;
67  }
68  }
69  return(retval);
70  } // sff::WID2 next_wid2(std::istream& is)
71 
72  /*----------------------------------------------------------------------*/
73 
74  // print info about GSE reading
75  void help(std::ostream& os)
76  {
77  os <<
78  std::endl <<
79  "GSE reading functions" << std::endl <<
80  "---------------------" << std::endl <<
81  DATRW_GSEREAD_CC_VERSION << std::endl <<
82  std::endl <<
83  "This module is designed to read raw GSE files." << std::endl <<
84  "Only one trace per file can be handled." << std::endl <<
85  "All additional line (prior to WID2 and after CHK2) are ignored."
86  << std::endl;
87  } // void help(std::ostream& os)
88 
89  /*----------------------------------------------------------------------*/
90 
91  //! read samples from file
92  Tiseries read_gse_data(std::istream& is, const int& nsamples)
93  {
94  Tiseries retval;
95  typedef Tiseries::Tvalue Tvalue;
96  try
97  {
98  retval=Tiseries(nsamples);
99  }
100  catch(...)
101  {
102  std::cerr << "ERROR (datrw::gse::read_gse_data): "
103  << "allocating series for "
104  << nsamples << " samples!" << std::endl;
105  throw;
106  }
107  // WID2 reading checks for CM6 subformat
108  // (only subformat supported so far)
109  GSE2::waveform::TDAT2readCM6 freader(nsamples);
110  for(aff::Iterator<Tiseries> i(retval); i.valid(); ++i)
111  { (*i) = Tvalue(freader(is)); }
112  return(retval);
113  }
114 
115  } // namespace gse
116 
117 } // namespace datrw
118 
119 /* ----- END OF gseread.cc ----- */
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
sff::WID2 next_wid2(std::istream &is)
find next WID2 line
Definition: gseread.cc:49
#define DATRW_GSEREAD_CC_VERSION
Definition: gseread.cc:35
aff::Series< Tivalue > Tiseries
Definition: gseread.h:63
const int nsamples
number of samples per minute block and channel
Definition: hpmodata.h:51
exception class declaration for libdatrwxx (prototypes)
Tiseries read_gse_data(std::istream &is, const int &nsamples)
read samples from file
Definition: gseread.cc:92
int Tvalue
Definition: pdasread.h:75
Root namespace of library.
Definition: aalibdatrwxx.cc:16
void help(std::ostream &os)
print info about GSE reading
Definition: gseread.cc:75