sff.cc 5.81 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file sff.cc
 * \brief wrapper around SFF output stream (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
6
 * $Id: sff.cc,v 1.7 2010-04-30 19:59:35 tforb Exp $
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
11
12
 * \author Thomas Forbriger
 * \date 11/04/2006
 * 
 * wrapper around SFF output stream (implementation)
 * 
 * Copyright (c) 2006 by Thomas Forbriger (BFO Schiltach) 
thomas.forbriger's avatar
thomas.forbriger committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 *
 * ----
 * 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
 * ----
 *
thomas.forbriger's avatar
thomas.forbriger committed
30
31
32
33
34
35
 * 
 * REVISIONS and CHANGES 
 *  - 11/04/2006   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
thomas.forbriger's avatar
thomas.forbriger committed
36
#define DATWRITE_SFF_CC_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
37
  "DATWRITE_SFF_CC   V1.0   "
thomas.forbriger's avatar
thomas.forbriger committed
38
#define DATWRITE_SFF_CC_CVSID \
39
  "$Id: sff.cc,v 1.7 2010-04-30 19:59:35 tforb Exp $"
thomas.forbriger's avatar
thomas.forbriger committed
40

thomas.forbriger's avatar
thomas.forbriger committed
41
42
#include <datwritexx/sff.h>
#include <datwritexx/util.h>
thomas.forbriger's avatar
thomas.forbriger committed
43
#include <datwritexx/sffwriters.h>
thomas.forbriger's avatar
thomas.forbriger committed
44

thomas.forbriger's avatar
thomas.forbriger committed
45
namespace datwrite {
thomas.forbriger's avatar
thomas.forbriger committed
46

thomas.forbriger's avatar
thomas.forbriger committed
47
48
  osffstream::osffstream(std::ostream& os, const bool& debug):
    Tbase(os), 
thomas.forbriger's avatar
thomas.forbriger committed
49
50
51
    Mdebug(debug),
    Mwid2iswaiting(false),
    Mfreeiswaiting(false),
thomas.forbriger's avatar
thomas.forbriger committed
52
53
    Minfoiswaiting(false),
    Mnormmode(::sff::NM_maxdyn)
thomas.forbriger's avatar
thomas.forbriger committed
54
55
  {
    Mdebug=debug;
thomas.forbriger's avatar
thomas.forbriger committed
56
57
    DATWRITE_debug(Mdebug, "osffstream::osffstream",
                   "new instance established");
thomas.forbriger's avatar
thomas.forbriger committed
58
59
60
61
  } // osffstream::osffstream(std::ostream& os, const bool& debug)

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

thomas.forbriger's avatar
thomas.forbriger committed
62
  void osffstream::help(std::ostream& os)
thomas.forbriger's avatar
thomas.forbriger committed
63
  {
thomas.forbriger's avatar
thomas.forbriger committed
64
    os << "This module writes standard SFF data." << std::endl;
thomas.forbriger's avatar
thomas.forbriger committed
65
66
67
68
69
70
  } // void osffstream::help(std::ostream& os=std::cout)

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

  void osffstream::writefileheader()
  {
thomas.forbriger's avatar
thomas.forbriger committed
71
72
    DATWRITE_debug(Mdebug, "osffstream::writefileheader",
                   "write file header to file");
thomas.forbriger's avatar
thomas.forbriger committed
73
74
75
76
    ::sff::FileHeader fileheader;
    if (Msrceset) { fileheader.setsrce(Msrce); }
    if (Mfreeset) { fileheader.setfree(Mfree); }
    Mos << fileheader;
thomas.forbriger's avatar
thomas.forbriger committed
77
78
79
80
81
82
  } // void osffstream::writefileheader()

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

  void osffstream::writetrace(const Tdseries& series)
  {
thomas.forbriger's avatar
thomas.forbriger committed
83
84
    DATWRITE_debug(Mdebug, "osffstream::writefileheader",
                   "write series of type double to file");
thomas.forbriger's avatar
thomas.forbriger committed
85
86
    this->flushwaitingtrace();
    Mserieswaiting=datwrite::util::seriesreservoir(series);
thomas.forbriger's avatar
thomas.forbriger committed
87
88
89
90
91
92
  } // void osffstream::writetrace(const Tdseries& series)

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

  void osffstream::writetrace(const Tfseries& series)
  {
thomas.forbriger's avatar
thomas.forbriger committed
93
94
    DATWRITE_debug(Mdebug, "osffstream::writefileheader",
                   "write series of type float to file");
thomas.forbriger's avatar
thomas.forbriger committed
95
96
    this->flushwaitingtrace();
    Mserieswaiting=datwrite::util::seriesreservoir(series);
thomas.forbriger's avatar
thomas.forbriger committed
97
98
99
100
101
102
  } // void osffstream::writetrace(const Tfseries& series)

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

  void osffstream::writetrace(const Tiseries& series)
  {
thomas.forbriger's avatar
thomas.forbriger committed
103
104
    DATWRITE_debug(Mdebug, "osffstream::writefileheader",
                   "write series of type integer to file");
thomas.forbriger's avatar
thomas.forbriger committed
105
106
    this->flushwaitingtrace();
    Mserieswaiting=datwrite::util::seriesreservoir(series);
thomas.forbriger's avatar
thomas.forbriger committed
107
108
  } // void osffstream::writetrace(const Tiseries& series)

thomas.forbriger's avatar
thomas.forbriger committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  /*----------------------------------------------------------------------*/

  void osffstream::flushwaitingtrace(const bool& last)
  {
    DATWRITE_debug(Mdebug, "osffstream::flushwaitingtrace",
                   "flush previous trace data to file");
    // flush previous trace
    if (Mwid2iswaiting)
    {
      // prepare trace header
      ::sff::TraceHeader traceheader(Mwid2waiting, last);
      if (Mfreeiswaiting) { traceheader.setfree(Mfreewaiting); }
      if (Minfoiswaiting) { traceheader.setinfo(Minfowaiting); }
      datwrite::sff::writesfftrace(Mos,
                                   traceheader,
                                   Mserieswaiting,
thomas.forbriger's avatar
thomas.forbriger committed
125
                                   Mnormmode);
thomas.forbriger's avatar
thomas.forbriger committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    }
    else
    {
      DATWRITE_assert((!last), 
                      "file is to be closed and no data was written");
    }
    // check for current trace headers and store them
    if (!last)
    {
      DATWRITE_assert(Mwid2set, "missing trace header data");
      Mwid2iswaiting=true;
      Mwid2waiting=Mwid2;
      Mfreeiswaiting=false;
      if (Mfreeset) { Mfreeiswaiting=true; Mfreewaiting=Mfree; }
      Minfoiswaiting=false;
      if (Mfreeset) { Minfoiswaiting=true; Minfowaiting=Minfo; }
    }
  }

thomas.forbriger's avatar
thomas.forbriger committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  /*======================================================================*/

  ogsestream::ogsestream(std::ostream& os, const bool& debug):
    Tbase(os, debug)
  {
    Mnormmode=::sff::NM_one;
    DATWRITE_debug(Mdebug, "ogsestream::ogsestream",
                   "new instance established");
  } // ogsestream::ogsestream(std::ostream& os, const bool& debug)

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

  void ogsestream::help(std::ostream& os)
  {
159
    os << "This module writes standard GSE data." << std::endl;
thomas.forbriger's avatar
thomas.forbriger committed
160
161
162
163
164
165
166
    os << "Essentially SFF data is written but without normalising"
      << std::endl;
    os << "them. Notice that floating point data will by truncated to"
      << std::endl;
    os << "integers." << std::endl;
  } // void ogsestream::help(std::ostream& os=std::cout)

thomas.forbriger's avatar
thomas.forbriger committed
167
} // namespace datwrite
thomas.forbriger's avatar
thomas.forbriger committed
168
169

/* ----- END OF sff.cc ----- */