sfftsfile.h 5.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*! \file sfftsfile.h
 * \brief data file container for SFF TimeSeries (prototypes)
 * 
 * ----------------------------------------------------------------------------
 * 
 * $Id: $
 * \author Thomas Forbriger
 * \since 18/07/2005
 * \date 30/01/2014
 * 
 * data file container for SFF TimeSeries (prototypes)
 * 
 * Copyright (c) 2005-2007, 2012, 2014 by Thomas Forbriger (BFO Schiltach) 
 *
 * ----
 * 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
 * ----
 *
 * REVISIONS and CHANGES 
 *  - 30/01/2014   V1.0   Thomas Forbriger (thof):
 *                        copied from sffheaders.h
 * 
 * ============================================================================
 */

// include guard
#ifndef TSIO_SFFTSFILE_H_VERSION

#define TSIO_SFFTSFILE_H_VERSION \
  "TF_SFFTSFILE_H   2014/01/30"
#define TSIO_SFFTSFILE_H_CVSID \
  "$Id: $"

46
#include<tsioxx/sfftimeseries.h>
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include<datrwxx/datread.h>
#include<tfxx/rangelist.h>
#include<vector>

/*! \brief SFF Timeseries I/O.
 *
 * \defgroup group_sffheaders SFF Timeseries I/O
 *
 * This interface is presented in sffheaders.h
 *
 * This module provides three submodules:
 *   - \ref subgroup_sffheaders_classes
 *   - \ref subgroup_sffheaders_datrwxx
 *   - \ref subgroup_sffheaders_sffxx
 */

namespace ts {

  namespace sff {

    /*! \brief hold information for a complete SFF file header
     * \ingroup group_sffheaders_classes
     */
    class FileHeader {
      public:
        FileHeader(): Mhasfree(false), Mhassrce(false) { }
        void srce(const ::sff::SRCE& s);
        void free(const ::sff::FREE& f);
        void append(const ::sff::FREE& f);
        ::sff::FREE free() const { return Mfree; }
        ::sff::SRCE srce() const { return Msrce; }
        bool hasfree() const { return Mhasfree; }
        bool hassrce() const { return Mhassrce; }
        void read(std::istream& is, const bool& verbose=false);
      private:
        ::sff::FREE Mfree;
        ::sff::SRCE Msrce;
        bool Mhasfree;
        bool Mhassrce;
    }; // struct FileHeader

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

    /*! \brief hold SFF traces with full header information
     * \ingroup group_sffheaders_classes
     */
    template<class C>
      class TraceVector: public std::vector<SFFTimeSeries<C> > {
        public:
          typedef std::vector<SFFTimeSeries<C> > Tbase;
          typedef SFFTimeSeries<C> Ttimeseries;
      }; // class TraceVector

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

    /*! \brief hold all information contained in an SFF data file
     * \ingroup group_sffheaders_classes
     *
     * Store the complete information contained in a data file
     */
    template<class C>
      struct File: public TraceVector<C> {
        public:
          typedef TraceVector<C> Tbase;
          typedef Tbase Ttracevector;
          typedef typename Tbase::Ttimeseries Ttimeseries;
113
          typedef tfxx::RangeList<int> Trangelist;
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
          void read(datrw::idatstream& is, 
                    const bool& verbose=false);
          void read(datrw::idatstream& is, 
                    const Trangelist& rl,
                    const bool& verbose=false);
          FileHeader fileheader;
      }; // struct File

/*!
 * @}
 */
    

    /*======================================================================*/
    // member functions
    
    /*! \brief Read a complete file with all traces.
     */
    template<class C>
    inline void File<C>::read(datrw::idatstream& is, const bool& verbose)
    {
      Trangelist rl;
      this->read(is, rl, verbose);
    } // TraceVector<C>::read
    
    /*----------------------------------------------------------------------*/

    
    /*! \brief Read a data file an extract selected traces.
     */
    template<class C>
      inline void File<C>::read(datrw::idatstream& is, 
                                const Trangelist& rl,
                                const bool& verbose)
    {
      is >> this->fileheader;
      int itrace=0;
      while (is.good())
      {
        ++itrace;
        if ((rl.size()==0) || rl.contains(itrace))
        {
          if (verbose)
          { std::cout << "  * read trace #" << itrace << std::endl; }
          Ttimeseries timeseries;
          is >> timeseries;
          timeseries.settraceindex(itrace);
          this->push_back(timeseries);
        }
        else
        {
          if (verbose)
          { std::cout << "    skip trace #" << itrace << std::endl; }
          is.skipseries();
        }
      }
    } // TraceVector<C>::read

  } // namespace sff
} // namespace ts
    
#endif // TSIO_SFFTSFILE_H_VERSION (includeguard)

/* ----- END OF sfftsfile.h ----- */