DATRW++ library: seismic data I/O with multiple formats
pdasread.h
Go to the documentation of this file.
1 /*! \file pdasread.h
2  * \brief read pdas file (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 30/03/2004
8  *
9  * read pdas file (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  * - 30/03/2004 V1.0 Thomas Forbriger
31  * - 10/09/2004 V1.1 support long format
32  * - 20/10/2004 V1.2 support scaling for floating point types
33  *
34  * ============================================================================
35  */
36 
37 // include guard
38 #ifndef DATRW_PDASREAD_H_VERSION
39 
40 #define DATRW_PDASREAD_H_VERSION \
41  "DATRW_PDASREAD_H V1.2 "
42 
43 #include<vector>
44 #include<istream>
45 #include<datrwxx/pdasflags.h>
46 #include<datrwxx/error.h>
47 #include<libtime++.h>
48 
49 namespace datrw {
50 
51  /*! \brief all functions, classes etc. to read PDAS data.
52  *
53  * \defgroup group_pdas Reading module for: PDAS data
54  */
55 
56  /*! \brief all functions, classes etc. to read PDAS data.
57  *
58  * \ingroup group_pdas
59  */
60  namespace pdas {
61 
62  //! struct to hold content of header line
63  struct HeaderLine {
64  std::string line, token, value;
65  }; // struct HeaderLine
66 
67  //! struct to hold complete header
68  struct Header {
69  std::string dataset, version, signal, date, time, interval;
70  std::string vertunits, horzunits, comment;
72  std::vector<std::string> lines;
73  }; // struct Header
74 
75  typedef int Tvalue;
76  typedef std::vector<Tvalue> Tdata;
77 
78  //! function to read the file header line
79  HeaderLine readline(std::istream& is, const bool& verbose=false);
80  //! function to read the file header
81  Header readheader(std::istream& is, const bool& verbose=false);
82  /*! function to read the file data
83  * passes vector by reference to avoid deep copy
84  */
85  void readdata(std::istream& is, Tdata& data, const Etype& type=FtypeINT);
86  //! function to skip the file data but count the samples
87  int countdata(std::istream& is, const Etype& type=FtypeINT);
88  //! function to read one sample
89  Tvalue readsample(std::istream& is, const Etype& type=FtypeINT);
90 
91  //! function to convert data
92  template<class C>
93  C convert(const Tdata& data)
94  {
95  int nsamples=data.size();
96  C retval(nsamples);
97  typedef typename C::Tvalue Toutvalue;
98  for (int i=0; i<nsamples; ++i)
99  {
100  Tvalue sample=data[i];
101  retval(i)=Toutvalue(sample);
102  }
103  return(retval);
104  }
105 
106  //! function to scale data
107  template<class C>
108  C convertandscale(const Tdata& data, const Etype& type)
109  {
110  long unsigned int factor;
111  if (type==FtypeINT)
112  { factor=0x8000; }
113  else if (type==FtypeLONG)
114  { factor=0x80000000; }
115  else if (type==FtypeGAINRANGED)
116  { factor=0x10000000; }
117  else
118  { DATRW_abort("illegal data type"); }
119  typedef typename C::Tvalue Tcontfactor;
120  Tcontfactor cfactor=Tcontfactor(factor);
121  return(datrw::pdas::convert<C>(data) / cfactor);
122  }
123 
124  //! function to print online help
125  void help(std::ostream& os=std::cout);
126 
127  } // namespace pdas
128 
129 } // namespace datrw
130 
131 #endif // DATRW_PDASREAD_H_VERSION (includeguard)
132 
133 /* ----- END OF pdasread.h ----- */
C convertandscale(const Tdata &data, const Etype &type)
function to scale data
Definition: pdasread.h:108
std::string vertunits
Definition: pdasread.h:70
std::string token
Definition: pdasread.h:64
std::string value
Definition: pdasread.h:64
std::string interval
Definition: pdasread.h:69
C convert(const Tdata &data)
function to convert data
Definition: pdasread.h:93
std::string version
Definition: pdasread.h:69
Etype
define pdas data types
Definition: pdasflags.h:47
const int nsamples
number of samples per minute block and channel
Definition: hpmodata.h:51
exception class declaration for libdatrwxx (prototypes)
const char *const data
keywords for consistency checks
std::string signal
Definition: pdasread.h:69
Tvalue readsample(std::istream &is, const Etype &type)
function to read one sample
Definition: pdasread.cc:182
std::string time
Definition: pdasread.h:69
int Tvalue
Definition: pdasread.h:75
Root namespace of library.
Definition: aalibdatrwxx.cc:16
std::vector< std::string > lines
Definition: pdasread.h:72
void readdata(std::istream &is, Tdata &data, const Etype &type)
Definition: pdasread.cc:150
std::string dataset
Definition: pdasread.h:69
HeaderLine readline(std::istream &is, const bool &verbose)
function to read the file header line
Definition: pdasread.cc:55
struct to hold content of header line
Definition: pdasread.h:63
#define DATRW_abort(M)
Abort and give a message.
Definition: error.h:101
struct to hold complete header
Definition: pdasread.h:68
std::string line
Definition: pdasread.h:64
void help(std::ostream &os)
function to print online help
Definition: pdasread.cc:262
Header readheader(std::istream &is, const bool &verbose)
function to read the file header
Definition: pdasread.cc:82
std::string date
Definition: pdasread.h:69
std::string horzunits
Definition: pdasread.h:70
std::string comment
Definition: pdasread.h:70
int countdata(std::istream &is, const Etype &type)
function to skip the file data but count the samples
Definition: pdasread.cc:166
std::vector< Tvalue > Tdata
Definition: pdasread.h:76