DATRW++ library: seismic data I/O with multiple formats
sacread.cc
Go to the documentation of this file.
1 /*! \file sacread.cc
2  * \brief decode sac files (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 21/12/2004
8  *
9  * decode 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  *
32  * ============================================================================
33  */
34 #define DATRW_SACREAD_CC_VERSION \
35  "DATRW_SACREAD_CC V1.0 "
36 
37 #include <datrwxx/sacread.h>
38 #include <datrwxx/error.h>
39 
40 namespace datrw {
41 
42  namespace sac {
43 
44  // read SAC header from stream
45  SACheader read_sac_header(std::istream& is)
46  {
47  SACheader retval;
48  typedef char* Pchar;
49  is.read(Pchar(&retval), sizeof(SACheader));
50  return(retval);
51  } // SACheader read_sac_header(std::istream& is)
52 
53  /*----------------------------------------------------------------------*/
54 
55  // print info about SAC reading
56  void help(std::ostream& os)
57  {
58  os <<
59  std::endl <<
60  "SAC reading functions" << std::endl <<
61  "---------------------" << std::endl <<
62  DATRW_SACREAD_CC_VERSION << std::endl <<
63  std::endl <<
64  "These functions are tuned to read binary SAC files as produced by"
65  << std::endl <<
66  "rdseed from IRIS SEED volumes." << std::endl;
67  } // void help(std::ostream& os)
68 
69  /*----------------------------------------------------------------------*/
70 
71  //! read samples from file
72  Tseries read_sac_data(std::istream& is, const int& nsamples)
73  {
74  Tseries series(nsamples);
75  DATRW_assert(is.good(),
76  "read_sac_data: input stream is not good before reading");
77  typedef char* Pchar;
78  is.read(Pchar(series.pointer()), nsamples*sizeof(Tvalue));
79  DATRW_assert(is.good(),
80  "read_sac_data: input stream is not good after reading");
81  return(series);
82  }
83 
84  } // namespace sac
85 
86 } // namespace datrw
87 
88 /* ----- END OF sacread.cc ----- */
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
SACheader read_sac_header(std::istream &is)
read SAC header from stream
Definition: sacread.cc:45
#define DATRW_SACREAD_CC_VERSION
Definition: sacread.cc:34
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)
Root namespace of library.
Definition: aalibdatrwxx.cc:16
void help(std::ostream &os)
print information about file decoding
Definition: sacread.cc:56
header structure for SAC binary data
Definition: sacread.h:114
aff::Series< Tvalue > Tseries
Definition: sacread.h:264
float Tvalue
binary SAC sample type
Definition: sacread.h:258