isustream.cc 4.38 KB
Newer Older
1
/*! \file isustream.cc
2
3
4
5
6
7
8
9
10
11
12
 * \brief read Seismic Unix data (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * $Id$
 * \author Thomas Forbriger
 * \date 19/11/2010
 * 
 * read Seismic Unix data (implementation)
 * 
 * Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach) 
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 *
 * ----
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
29
30
31
32
33
34
 * 
 * REVISIONS and CHANGES 
 *  - 19/11/2010   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
thomas.forbriger's avatar
thomas.forbriger committed
35
36
37
#define DATRW_SU_CC_VERSION \
  "DATRW_SU_CC   V1.0   "
#define DATRW_SU_CC_CVSID \
38
39
  "$Id$"

thomas.forbriger's avatar
thomas.forbriger committed
40
#include <datrwxx/su.h>
41
42
#include <datrwxx/util.h>
#include <datrwxx/error.h>
43

thomas.forbriger's avatar
thomas.forbriger committed
44
namespace datrw  {
45

46
  const std::ios_base::openmode
47
48
49
50
51
52
53
54
55
    isustream::openmode=std::ios_base::in|std::ios_base::binary;

  //@{
  /*! \brief Format properties
   * \ingroup su
   */
  const bool su::isbinary=true;
  const char* const su::streamID="su";
  //@}
56
57
58
59

  /*----------------------------------------------------------------------*/

  isustream::isustream(std::istream& is, const bool& debug):
60
    Tbase(is, true, true, false), Mdebug(debug)
61
  { 
62
63
    DATRW_assert(is.good(),
                 "ERROR (isustream::isustream): input stream is bad");
64
    Mnextheader.read(is);
thomas.forbriger's avatar
thomas.forbriger committed
65
    this->setsrce(Mnextheader.srce());
66
67
68
69
70
71
72
73
74
75
76
77
78
  }

  /*----------------------------------------------------------------------*/

  Tdseries isustream::dseries()
  {
    return(datrw::util::convert<Tfseries, Tdseries>(this->fseries()));
  } // Tdseries isustream::dseries()

  /*----------------------------------------------------------------------*/

  Tfseries isustream::fseries()
  {
thomas.forbriger's avatar
thomas.forbriger committed
79
80
81
82
83
84
    Tfseries series(Mnextheader.Mheader.ns);
    this->readheader();
    char *ipointer=reinterpret_cast<char *>(series.pointer());
    DATRW_Xassert(Mis.read(ipointer, series.size()*sizeof(float)),
                  "ERROR (isustream::fseries): reading SU samples",
                  ::datrw::su::SUReadException);
85
    return(Tfseries(0));
86
87
88
89
90
91
  } // Tiseries isustream::fseries()

  /*----------------------------------------------------------------------*/

  void isustream::skipseries()
  {
thomas.forbriger's avatar
thomas.forbriger committed
92
    Tfseries s=this->fseries();
93
94
95
96
97
98
  } // void isustream::skipseries()

  /*----------------------------------------------------------------------*/

  void isustream::readheader()
  {
thomas.forbriger's avatar
thomas.forbriger committed
99
100
101
102
103
    DATRW_assert(this->good(),
                 "ERROR (isustream::readheader): reached end of file");
    this->newtrace();
    this->setwid2(Mnextheader.wid2());
    this->setinfo(Mnextheader.info());
thomas.forbriger's avatar
thomas.forbriger committed
104
105
106
107
108
109
110
    DATRW_assert(((this->srce().date == Mnextheader.srce().date)
                  && (this->srce().cs == Mnextheader.srce().cs)
                  && (this->srce().cx == Mnextheader.srce().cx)
                  && (this->srce().cy == Mnextheader.srce().cy)
                  && (this->srce().cz == Mnextheader.srce().cz)),
                 "ERROR (isustream::readheader): "
                 "current source differs from previous");
thomas.forbriger's avatar
thomas.forbriger committed
111
112
113
114
115
116
    try {
      Mnextheader.read(Mis);
    } catch (datrw::su::SUReadException)
    {
      this->setlast();
    }
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  } // void isustream::readheader()

  /*----------------------------------------------------------------------*/

  void isustream::help(std::ostream& os)
  { 
    os <<
      std::endl <<
      "SeismicUnix reading functions" << std::endl <<
      "-----------------------------" << std::endl <<
      DATRW_SU_CC_VERSION << std::endl <<
      DATRW_SU_CC_CVSID << std::endl <<
      DATRW_SU_H_CVSID << std::endl <<
      std::endl <<
      "This module provides reading of SeismicUnix binary data files."
      << std::endl <<
      "Only a few header fields are extracted."
      << std::endl;
  } // void isustream::help(std::ostream& os)
136

thomas.forbriger's avatar
thomas.forbriger committed
137
} // namespace datrw
138

139
/* ----- END OF isustream.cc ----- */