DATRW++ library: seismic data I/O with multiple formats
writeany.cc
Go to the documentation of this file.
1 /*! \file writeany.cc
2  * \brief common interface for all data types (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 17/02/2010
8  *
9  * common interface for all data types (implementation)
10  *
11  * Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach)
12  *
13  * ----
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27  * ----
28  *
29  * REVISIONS and CHANGES
30  * - 17/02/2010 V1.0 Thomas Forbriger
31  * - 08/12/2010 V1.1 provide SU writing
32  * - 29/07/2011 V1.2 support format modifiers
33  * - 02/09/2011 V1.3 support seife format
34  * - 06/09/2011 V1.4 make non-subformat constructor deprecated
35  * - 07/09/2011 V1.5 more string type format ID support: openmode
36  * - 05/11/2011 V1.6 provide ASCII output
37  * - 19/11/2011 V1.7 provide binary output
38  * - 21/11/2011 V1.8 sff output stream takes modifiers
39  * - 21/01/2012 V1.9 prepared osustream to take modifiers
40  * - 23/08/2012 V1.10 ASCII output supports modifiers
41  * - 18/11/2016 V1.11 set debug mode in base class
42  *
43  * ============================================================================
44  */
45 #define DATRW_WRITEANY_CC_VERSION \
46  "DATRW_WRITEANY_CC V1.11"
47 
48 #include <datrwxx/writeany.h>
49 #include <datrwxx/error.h>
50 #include <datrwxx/sff.h>
51 #include <datrwxx/su.h>
52 #include <datrwxx/seife.h>
53 #include <datrwxx/ascii.h>
54 #include <datrwxx/binary.h>
55 #include <datrwxx/formatmodifier.h>
56 #include <datrwxx/util.h>
57 #include <datrwxx/report.h>
58 
59 namespace datrw {
60 
61  oanystream::oanystream(std::ostream& os, const Eformat& format,
62  const bool& debug)
63  {
64  datrw::util::report_deprecated("oanystream::oanystream(std::ostream& os, "
65  "const Eformat& format)",
66  "this constructor does not support format modifiers");
67  std::string fm(anyID(format));
68  this->open(os, fm, debug);
69  }
70 
71  /*----------------------------------------------------------------------*/
72 
73  oanystream::oanystream(std::ostream& os, const std::string& format,
74  const bool& debug)
75  {
76  this->open(os, format, debug);
77  }
78 
79  /*----------------------------------------------------------------------*/
80 
81  void oanystream::open(std::ostream& os, std::string format,
82  const bool& debug)
83  {
84  std::string formatstring=util::clipstring(format);
85  std::string& modifiers=format;
86  Mformat=anyID(formatstring);
87  if (Mformat==Fsff)
88  {
89  Mos=new osffstream(os, modifiers);
90  }
91  else if (Mformat==Fgse)
92  {
94  Mos=new ogsestream(os);
95  }
96  else if (Mformat==Fsu)
97  {
98  Mos=new osustream(os, modifiers);
99  }
100  else if (Mformat==Fseife)
101  {
102  Mos=new oseifestream(os, modifiers);
103  }
104  else if (Mformat==Fascii)
105  {
106  Mos=new oasciistream(os, modifiers);
107  }
108  else if (Mformat==Fbinary)
109  {
111  Mos=new obinarystream(os);
112  }
113  else
114  {
115  DATRW_abort("ERROR (oanystream): unsupported format!");
116  }
117  Mos->debug(debug);
118  }
119 
120  /*----------------------------------------------------------------------*/
121 
123  {
124  delete Mos;
125  }
126 
127  /*----------------------------------------------------------------------*/
128 
129  /*! return appropriate file stream open mode for selected format
130  */
131  std::ios_base::openmode oanystream::openmode(const std::string& format)
132  {
133  return(oanystream::openmode(anyID(format)));
134  } // std::ios_base::openmode oanystream::openmode(std::string format)
135 
136  /*----------------------------------------------------------------------*/
137 
138  /*! return appropriate file stream open mode for selected format
139  */
140  std::ios_base::openmode oanystream::openmode(const Eformat& format)
141  {
142  std::ios_base::openmode retval;
143  if (format==Fsff) { retval=osffstream::openmode; }
144  else if (format==Fgse) { retval=ogsestream::openmode; }
145  else if (format==Fsu) { retval=osustream::openmode; }
146  else if (format==Fseife) { retval=oseifestream::openmode; }
147  else if (format==Fascii) { retval=oasciistream::openmode; }
148  else if (format==Fbinary) { retval=obinarystream::openmode; }
149  else
150  { DATRW_abort("ERROR (openmode): unknown format!"); }
151  return(retval);
152  } // std::ios_base::openmode oanystream::openmode(const Eformat& format)
153 
154 } // namespace datrw
155 
156 /*! \page page_formats Supported formats
157  *
158 
159  Currently supported \b output \b formats are:
160  - sff: Stuttgart File Format
161  - gse: raw GSE format
162  - su: SeismicUn*x format
163  - seife: seife format (E. Wielandt), see: \ref page_seife_format
164  - ascii: ASCII one column
165  - bin: binary data dumped from memory to disk
166  */
167 
168 /* ----- END OF writeany.cc ----- */
datrw::Eformat Mformat
Definition: writeany.h:111
seife reading and writing module (prototypes)
provide format modifiers (prototypes)
static const std::ios_base::openmode openmode
Definition: seife.h:96
void report_deprecated(const std::string &function, const std::string &reason)
report deprecated function
Definition: report.cc:113
Eformat anyID(std::string formatstring)
convert identifier from and to string representation
Definition: formats.cc:68
static const std::ios_base::openmode openmode
Definition: su.h:108
write raw binary data (prototypes)
datrw::odatstream * Mos
Definition: writeany.h:110
static const std::ios_base::openmode openmode
Definition: ascii.h:113
read sff data (prototypes)
class to write SFF data
Definition: sff.h:98
exception class declaration for libdatrwxx (prototypes)
oanystream(std::ostream &, const Eformat &format, const bool &debug=false)
deprecated constructor, not taking format modifier
Definition: writeany.cc:61
bool debug()
indicate debug mode
Definition: datwrite.h:145
Root namespace of library.
Definition: aalibdatrwxx.cc:16
bool debug()
indicate debug mode
Definition: writeany.h:99
utilities used by more than one type of data reader (prototypes)
common interface for all data types (prototypes)
#define DATRW_abort(M)
Abort and give a message.
Definition: error.h:101
static const std::ios_base::openmode openmode
Definition: sff.h:106
void open(std::ostream &os, std::string format, const bool &debug=false)
actually open stream (to be called by constructor)
Definition: writeany.cc:81
std::string clipstring(std::string &s, const std::string &delim)
strip substringStrips off first substring up to given delimiter. The string is passed as a reference ...
Definition: util.cc:105
class to write seife data
Definition: seife.h:88
#define DATRW_expect_no_modifier(F, M)
Issue warning if modifiers are passed but not evaluated.
class to write binary
Definition: binary.h:130
read Seismic Unix data (prototypes)
Eformat
Definition: formats.h:54
class to write GSE data
Definition: sff.h:136
static const std::ios_base::openmode openmode
Definition: binary.h:136
class to write ascii data
Definition: ascii.h:105
class to write SU data
Definition: su.h:100
interface to write ASCII data (prototypes)
report errors and warnings (prototypes)