SFF++ library: reading and writing SFF from C++
sffverbose.cc
Go to the documentation of this file.
1 
34 #define TF_SFFVERBOSE_CC_VERSION \
35  "TF_SFFVERBOSE_CC V1.0 "
36 
37 #include <iomanip>
38 #include <sffxx.h>
39 
40 namespace sff {
41 
42  namespace helper {
43  // my output format
44  struct MyFormat {
45  int width;
46  int precision;
47  bool scientific;
48  bool showpos;
49  bool showpoint;
51  width(15), precision(4), scientific(true),
52  showpos(true), showpoint(true)
53  { }
54  MyFormat operator()(const int& w, const int& p, const bool& s=true) const
55  {
56  MyFormat retval=*this;
57  retval.width=w;
58  retval.precision=p;
59  retval.scientific=s;
60  return retval;
61  }
62  }; // struct MyFormat
63 
64  /*----------------------------------------------------------------------*/
65 
66  // use MyFormat as output manipulator
67  std::ostream& operator<<(std::ostream& os, const MyFormat& format)
68  {
69  os << std::setw(format.width);
70  os << std::setprecision(format.precision);
71  if (format.scientific) { os << std::scientific; }
72  else { os << std::fixed; }
73  if (format.showpos) { os << std::showpos; }
74  else { os << std::noshowpos; }
75  if (format.showpoint) { os << std::showpoint; }
76  else { os << std::noshowpoint; }
77  return os;
78  } // std::ostream& operator<<(std::ostream& os, const MyFormat& format)
79 
80  /*----------------------------------------------------------------------*/
81 
82  // yes/no
83  void yesno(std::ostream& os, const bool& f)
84  {
85  if (f) { os << "YES"; } else { os << "NO"; }
86  os << std::endl;
87  } // void yesno(std::ostream& os, const bool& f)
88 
89  } // namespace helper
90 
91  /*======================================================================*/
92 
93  void verbose(std::ostream& os, const WID2& wid2)
94  {
95  sff::helper::MyFormat format;
96  sff::helper::MyFormat npformat;
97  npformat.showpos=false;
98  os << "contents of SFF WID2 line:" << std::endl;
99  os << " date and time of first sample: "
100  << wid2.date.timestring() << std::endl;
101  os << " station code: "
102  << wid2.station << std::endl;
103  os << " channel code: "
104  << wid2.channel << std::endl;
105  os << " auxilliary code: "
106  << wid2.auxid << std::endl;
107  os << " instrument code: "
108  << wid2.instype << std::endl;
109  os << " number of samples: "
110  << npformat(11,7,false) << wid2.nsamples << std::endl;
111  os << " sampling interval: "
112  << npformat(11,7,false) << wid2.dt << " s" << std::endl;
113  os << " calibration factor: "
114  << format(10,7,false) << wid2.calib << std::endl;
115  os << " calibration period: "
116  << format(10,7,false) << wid2.calper << std::endl;
117  os << " horizontal orientation clockwise from north (hang): "
118  << format(10,7,false) << wid2.hang << " deg" << std::endl;
119  os << " vertical orientation from vertical (vang): "
120  << format(19,7,false) << wid2.vang << " deg" << std::endl;
121  } // void verbose(std::ostream& os, const WID2& wid2)
122 
123  /*----------------------------------------------------------------------*/
124 
125  void verbose(std::ostream& os, const SRCE& srce)
126  {
127  sff::helper::MyFormat format;
128  os << "contents of SFF SRCE line:" << std::endl;
129  os << " type of source (type): "
130  << srce.type << std::endl;
131  os << " coordinate system (cs): ";
132  switch (srce.cs) {
133  case CS_cartesian:
134  os << "cartesian";
135  break;
136  case CS_spherical:
137  os << "spherical";
138  break;
139  }
140  os << std::endl;
141  switch (srce.cs) {
142  case CS_cartesian:
143  os << " X-coordinate (c1):"
144  << format(19,8) << srce.cx << " m" << std::endl;;
145  os << " Y-coordinate (c2):"
146  << format(19,8) << srce.cy << " m" << std::endl;;
147  os << " Z-coordinate (c3):"
148  << format(19,8) << srce.cz << " m" << std::endl;;
149  break;
150  case CS_spherical:
151  os << "spherical";
152  os << " latitude (c1): "
153  << format(19,8) << srce.cx << " deg" << std::endl;;
154  os << " longitude (c2):"
155  << format(19,8) << srce.cy << " deg" << std::endl;;
156  os << " height (c3): "
157  << format(19,8) << srce.cz << " m" << std::endl;;
158  break;
159  }
160  os << " source date and time: "
161  << srce.date.timestring() << std::endl;
162  } // void verbose(std::ostream& os, const SRCE& srce)
163 
164  /*----------------------------------------------------------------------*/
165 
166  void verbose(std::ostream& os, const DAST& dast)
167  {
168  sff::helper::MyFormat format;
169  os << "contents of SFF DAST line:" << std::endl;
170  os << " number of characters in encoded data set (nchar):"
171  << format(8,8) << dast.nchar << std::endl;
172  os << " scaling factor (ampfac):"
173  << format(20,10) << dast.ampfac << std::endl;
174  os << " trace has FREE block (code):" << format(8,10);
175  helper::yesno(os, dast.hasfree);
176  os << " trace has INFO line (code):" << format(9,10);
177  helper::yesno(os, dast.hasinfo);
178  os << " is last trace in file (code):" << format(7,10);
179  helper::yesno(os, dast.last);
180  } // void verbose(std::ostream& os, const DAST& dast)
181 
182  /*----------------------------------------------------------------------*/
183 
184  void verbose(std::ostream& os, const INFO& info)
185  {
186  sff::helper::MyFormat format;
187  os << "contents of SFF INFO line:" << std::endl;
188  os << " coordinate system (cs): ";
189  switch (info.cs) {
190  case CS_cartesian:
191  os << "cartesian";
192  break;
193  case CS_spherical:
194  os << "spherical";
195  break;
196  }
197  os << std::endl;
198  switch (info.cs) {
199  case CS_cartesian:
200  os << " X-coordinate (c1):"
201  << format(19,8) << info.cx << " m" << std::endl;;
202  os << " Y-coordinate (c2):"
203  << format(19,8) << info.cy << " m" << std::endl;;
204  os << " Z-coordinate (c3):"
205  << format(19,8) << info.cz << " m" << std::endl;;
206  break;
207  case CS_spherical:
208  os << "spherical";
209  os << " latitude (c1): "
210  << format(19,8) << info.cx << " deg" << std::endl;;
211  os << " longitude (c2):"
212  << format(19,8) << info.cy << " deg" << std::endl;;
213  os << " height (c3): "
214  << format(19,8) << info.cz << " m" << std::endl;;
215  break;
216  }
217  os << " number of stacks (nstacks):"
218  << format(8,5) << info.nstacks << std::endl;
219  } // void verbose(std::ostream& os, const INFO& info)
220 
221  /*----------------------------------------------------------------------*/
222 
223  void verbose(std::ostream& os, const FREE& free)
224  {
225  os << "contents of SFF FREE block:" << std::endl;
226  sff::FREE::Tlines::const_iterator I=free.lines.begin();
227  while (I != free.lines.end())
228  {
229  os << " " << *I << std::endl;;
230  ++I;
231  }
232  } // void verbose(std::ostream& os, const FREE& free)
233 
234  /*----------------------------------------------------------------------*/
235 
236  void verbose(std::ostream& os, const STAT& stat)
237  {
238  sff::helper::MyFormat format;
239  os << "contents of SFF STAT line:" << std::endl;
240  os << " time stamp: "
241  << stat.timestamp << std::endl;
242  os << " file has FREE block (code):" << format(4,3);
243  helper::yesno(os, stat.hasfree);
244  os << " file has SRCE line (code):" << format(5,3);
245  helper::yesno(os, stat.hassrce);
246  } // void verbose(std::ostream& os, const STAT& stat)
247 
248  /*----------------------------------------------------------------------*/
249 
250  void verbose(std::ostream& os, const FileHeader& fh)
251  {
252  os << "contents of SFF file header:" << std::endl;
253  verbose(os,fh.stat());
254  if (fh.hassrce()) { verbose(os,fh.srce()); }
255  else { os << "file header contains no SRCE line" << std::endl; }
256  if (fh.hasfree()) { verbose(os,fh.free()); }
257  else { os << "file header contains no FREE block" << std::endl; }
258  } // void verbose(std::ostream& os, const FileHeader& fh)
259 
260  /*----------------------------------------------------------------------*/
261 
262  void verbose(std::ostream& os, const TraceHeader& th)
263  {
264  os << "contents of SFF trace header:" << std::endl;
265  verbose(os,th.dast());
266  verbose(os,th.wid2());
267  if (th.hasinfo()) { verbose(os,th.info()); }
268  else { os << "trace header contains no INFO line" << std::endl; }
269  if (th.hasfree()) { verbose(os,th.free()); }
270  else { os << "trace header contains no FREE block" << std::endl; }
271  } // void verbose(std::ostream& os, const TraceHeader& th)
272 
273 } // namespace sff
274 
275 /* ----- END OF sffverbose.cc ----- */
std::string timestamp
Definition: sffxx.h:148
SFF trace header elements.
Definition: sffxx.h:282
all SFF modules
Definition: offset.cc:42
std::string auxid
Auxiliary identification code.
Definition: sffxx.h:218
Tlines lines
Definition: sffxx.h:163
double calper
calibration reference period
Definition: sffxx.h:222
double cz
Definition: sffxx.h:176
const bool & hasfree() const
Definition: sffxx.h:311
bool last
Definition: sffxx.h:190
const INFO & info() const
Definition: sffxx.h:308
double cy
Definition: sffxx.h:202
const bool & hasfree() const
Definition: sffxx.h:253
std::string station
Station code.
Definition: sffxx.h:216
const FREE & free() const
Definition: sffxx.h:250
const STAT & stat() const
Definition: sffxx.h:249
void yesno(std::ostream &os, const bool &f)
Definition: sffverbose.cc:83
std::string instype
instrument type
Definition: sffxx.h:223
double cx
Definition: sffxx.h:202
std::string channel
FDSN channel code.
Definition: sffxx.h:217
int nsamples
number of samples
Definition: sffxx.h:219
libtime::TAbsoluteTime date
time of first sample
Definition: sffxx.h:215
std::ostream & operator<<(std::ostream &os, const MyFormat &format)
Definition: sffverbose.cc:67
std::string type
Definition: sffxx.h:173
const bool & hasinfo() const
Definition: sffxx.h:310
double cz
Definition: sffxx.h:202
double calib
calibration factor
Definition: sffxx.h:221
Ecoosys cs
Definition: sffxx.h:175
MyFormat operator()(const int &w, const int &p, const bool &s=true) const
Definition: sffverbose.cc:54
libtime::TAbsoluteTime date
time of source
Definition: sffxx.h:174
Waveform Header.
Definition: sffxx.h:209
double vang
veritcal orientation
Definition: sffxx.h:225
const WID2 & wid2() const
Definition: sffxx.h:305
double ampfac
Definition: sffxx.h:187
double cx
Definition: sffxx.h:176
double cy
Definition: sffxx.h:176
int nchar
Definition: sffxx.h:186
bool hasinfo
Definition: sffxx.h:189
const FREE & free() const
Definition: sffxx.h:307
Ecoosys cs
Definition: sffxx.h:201
bool hasfree
Definition: sffxx.h:149
int nstacks
Definition: sffxx.h:203
double dt
sampling interval (sec)
Definition: sffxx.h:220
const bool & hassrce() const
Definition: sffxx.h:252
bool hassrce
Definition: sffxx.h:150
const SRCE & srce() const
Definition: sffxx.h:251
bool hasfree
Definition: sffxx.h:188
double hang
horizontal orientation
Definition: sffxx.h:224
SFF library (prototypes)
SFF file header elements.
Definition: sffxx.h:232
void verbose(std::ostream &os, const WID2 &wid2)
Definition: sffverbose.cc:93
const DAST & dast() const
Definition: sffxx.h:306