sff.cc 4.98 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)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id: sff.cc,v 1.5 2010-02-21 12:31:33 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 \
thomas.forbriger's avatar
thomas.forbriger committed
39
  "$Id: sff.cc,v 1.5 2010-02-21 12:31:33 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
52
    Mdebug(debug),
    Mwid2iswaiting(false),
    Mfreeiswaiting(false),
    Minfoiswaiting(false)
thomas.forbriger's avatar
thomas.forbriger committed
53
54
  {
    Mdebug=debug;
thomas.forbriger's avatar
thomas.forbriger committed
55
56
    DATWRITE_debug(Mdebug, "osffstream::osffstream",
                   "new instance established");
thomas.forbriger's avatar
thomas.forbriger committed
57
58
59
60
  } // osffstream::osffstream(std::ostream& os, const bool& debug)

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

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

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

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

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

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

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

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

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

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

thomas.forbriger's avatar
thomas.forbriger committed
108
109
110
111
112
113
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
  /*----------------------------------------------------------------------*/

  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,
                                   ::sff::NM_maxdyn);
    }
    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
144
} // namespace datwrite
thomas.forbriger's avatar
thomas.forbriger committed
145
146

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