DATRW++ library: seismic data I/O with multiple formats
seedstructdump.cc
Go to the documentation of this file.
1 /*! \file seedstructdump.cc
2  * \brief dump SEED structs in human readable form (implementation)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 15/03/2006
8  *
9  * dump SEED structs in human readable form (implementation)
10  *
11  * ----
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25  * ----
26  *
27  * Copyright (c) 2006 by Thomas Forbriger (BFO Schiltach)
28  *
29  * REVISIONS and CHANGES
30  * - 15/03/2006 V1.0 Thomas Forbriger
31  *
32  * ============================================================================
33  */
34 #define DATRW_SEEDSTRUCTDUMP_CC_VERSION \
35  "DATRW_SEEDSTRUCTDUMP_CC V1.0 "
36 
37 #include<string>
38 #include<iomanip>
39 #include<datrwxx/seedstructdump.h>
40 #include<datrwxx/mseedread.h>
41 
42 namespace datrw {
43 
44  namespace mseed {
45 
46  namespace SEED {
47 
48  namespace util {
49 
50  void print_field_name(const char* f, std::ostream& os)
51  {
52  os.width(30);
53  os.fill(' ');
54  os << f << ": ";
55  } // void print_field_name(const char* f, std::ostream& os)
56 
57  void print_hex(const unsigned short int& f, std::ostream& os)
58  {
59  std::ostream::fmtflags flags=os.flags();
60  os.setf(std::ios_base::hex, std::ios_base::basefield);
61  os.setf(std::ios_base::showbase);
62  os << f;
63  os.flags(flags);
64  } // void print_address(const unsigned short int& f, std::ostream& os)
65 
66  } // namespace util
67 
68  void dump(const ControlHeader& s, std::ostream& os)
69  {
70  os << "Control Header:" << std::endl;
71  util::print_field_name("sequence no", os);
72  os << std::string(s.seqno, 6);
73  os << std::endl;
74  util::print_field_name("type", os);
75  os << s.type;
76  os << std::endl;
77  util::print_field_name("cont", os);
78  os << s.cont;
79  os << std::endl;
80  } // void dump(const ControlHeader& s, std::ostream& os)
81 
82  /*----------------------------------------------------------------------*/
83 
84  void dump(const BlocketteHeader& s, std::ostream& os)
85  {
86  } // void dump(const BlocketteHeader& s, std::ostream& os)
87 
88  /*----------------------------------------------------------------------*/
89 
90  void dump(const BTIME& s, std::ostream& os)
91  {
92  libtime::TAbsoluteTime thetime=convert(s);
93  os << thetime.timestring();
94  } // void dump(const BTIME& s, std::ostream& os)
95 
96  /*----------------------------------------------------------------------*/
97 
98  void dump(const DataExtensionBlockette& s, std::ostream& os)
99  {
100  os << "Data Extension Blockette:" << std::endl;
101  dump(s.blocketteheader, os);
102  util::print_field_name("timing quality", os);
103  os << s.itquality() << std::endl;
104  util::print_field_name("microseconds", os);
105  os << s.iusec() << std::endl;
106  util::print_field_name("reserved", os);
107  os << int(s.reserved) << std::endl;
108  util::print_field_name("frame count", os);
109  os << s.ifcount() << std::endl;
110  } // void dump(const DataExtensionBlockette& s, std::ostream& os)
111 
112  /*----------------------------------------------------------------------*/
113 
114  void dump(const DataOnlySEEDBlockette& s, std::ostream& os)
115  {
116  os << "Data Only SEED Blockette:" << std::endl;
117  dump(s.blocketteheader, os);
118  util::print_field_name("encoding format", os);
119  dump(EEncodingFormat(s.format), os);
120  os << " (" << int(s.format) << ")" << std::endl;
121  util::print_field_name("word order", os);
122  dump(EByteOrder(s.bytesex), os);
123  os << " (" << s.ibytesex() << ")" << std::endl;
124  util::print_field_name("data record length", os);
125  os << s.reclenbytes()
126  << " bytes (" << s.ireclen() << ")" << std::endl;
127  util::print_field_name("reserved", os);
128  os << int(s.reserved) << std::endl;
129  } // void dump(const DataOnlySEEDBlockette& s, std::ostream& os)
130 
131  /*----------------------------------------------------------------------*/
132 
133  void dump(const DataRecordBlocketteHeader& s, std::ostream& os)
134  {
135  os << "Data Record Blockette Header:" << std::endl;
136  util::print_field_name("blockette type", os);
137  os << s.type << std::endl;
138  util::print_field_name("address of next blockette", os);
139  util::print_hex(s.next, os); os << std::endl;
140  } // void dump(const DataRecordBlocketteHeader& s, std::ostream& os)
141 
142  /*----------------------------------------------------------------------*/
143 
144  void dump(const FixedDataRecordHeader& s, std::ostream& os)
145  {
146  os << "Fixed Data Record Header:" << std::endl;
147  dump(s.controlheader, os);
148  util::print_field_name("station identifier code", os);
149  os << datrw::mseed::util::extractstring(s.stat, 5) << std::endl;
150  util::print_field_name("location identifier", os);
151  os << datrw::mseed::util::extractstring(s.loc, 2) << std::endl;
152  util::print_field_name("channel identifier", os);
153  os << datrw::mseed::util::extractstring(s.chan, 3) << std::endl;
154  util::print_field_name("network code", os);
155  os << datrw::mseed::util::extractstring(s.net, 2) << std::endl;
156  util::print_field_name("record start time", os);
157  os << convert(s.stime).timestring() << std::endl;
158  util::print_field_name("number of samples", os);
159  os << s.nsamp << std::endl;
160  util::print_field_name("sample rate factor", os);
161  os << s.srate << std::endl;
162  util::print_field_name("sample rate multiplier", os);
163  os << s.srmult << std::endl;
164  util::print_field_name("activity flags", os);
165  util::print_hex(s.aflags, os);
166  os << std::endl;
167  dump_aflags(s.aflags, os);
168  util::print_field_name("i/o and clock flags", os);
169  util::print_hex(s.ioflags, os);
170  os << std::endl;
171  dump_ioflags(s.ioflags, os);
172  util::print_field_name("data quality flags", os);
173  util::print_hex(s.qflags, os);
174  os << std::endl;
175  dump_qflags(s.qflags, os);
176  util::print_field_name("number of blockettes", os);
177  os << int(s.numblock) << std::endl;
178  util::print_field_name("time correction", os);
179  os << s.tcorr << std::endl;
180  util::print_field_name("beginning of data", os);
181  util::print_hex(s.dbeg, os);
182  os << std::endl;
183  util::print_field_name("first blockette", os);
184  util::print_hex(s.fblock, os);
185  os << std::endl;
186  } // void dump(const FixedDataRecordHeader& s, std::ostream& os)
187 
188  /*----------------------------------------------------------------------*/
189 
190  void dump_aflags(const unsigned char& s, std::ostream& os)
191  {
192  if (int(s) > 0) { dump(datrw::mseed::SEED::ActivityFlags(s), os); }
193  } // void dump_aflags(const unsigned char& s, std::ostream& os)
194 
195  void dump_qflags(const unsigned char& s, std::ostream& os)
196  {
197  if (int(s) > 0) { dump(datrw::mseed::SEED::QualityFlags(s), os); }
198  } // void dump_qflags(const unsigned char& s, std::ostream& os)
199 
200  void dump_ioflags(const unsigned char& s, std::ostream& os)
201  {
202  if (int(s) > 0) { dump(datrw::mseed::SEED::IOFlags(s), os); }
203  } // void dump_ioflags(const unsigned char& s, std::ostream& os)
204 
205  /*----------------------------------------------------------------------*/
206 
207  void dump(const datrw::mseed::SEED::ActivityFlags& f, std::ostream& os)
208  {
209  os << "Activity Flags:" << std::endl;
210  if (f.calpres)
211  { os << " calibration signals present" << std::endl; }
212  if (f.tcorrapp) { os << " time correction applied" << std::endl; }
213  if (f.begevent) { os << " beginning of event" << std::endl; }
214  if (f.endevent) { os << " end of event" << std::endl; }
215  if (f.posleap)
216  { os << " a positive leap second happened" << std::endl; }
217  if (f.negleap)
218  { os << " a negative leap second happened" << std::endl; }
219  if (f.event) { os << " event in progress" << std::endl; }
220  } // void dump(const ActivityFlags& f, std::ostream& os)
221 
222  /*----------------------------------------------------------------------*/
223 
224  void dump(const datrw::mseed::SEED::QualityFlags& f, std::ostream& os)
225  {
226  os << "Quality Flags:" << std::endl;
227  if (f.ampsat)
228  { os << " amplifier saturation detected" << std::endl; }
229  if (f.clip) { os << " digitizer clipping detected" << std::endl; }
230  if (f.spike) { os << " spike detected" << std::endl; }
231  if (f.glitch) { os << " glitches detected" << std::endl; }
232  if (f.miss)
233  { os << " missing/padded data present" << std::endl; }
234  if (f.telsynch)
235  { os << " telemetry synchronization error" << std::endl; }
236  if (f.charging)
237  { os << " a digital filter may be charging" << std::endl; }
238  if (f.time) { os << " time tag is questionable" << std::endl; }
239  } // void dump(const QualityFlags& s, std::ostream& os)
240 
241  /*----------------------------------------------------------------------*/
242 
243  void dump(const datrw::mseed::SEED::IOFlags& f, std::ostream& os)
244  {
245  os << "I/O Flags:" << std::endl;
246  if (f.parityerr)
247  {
248  os << " station volume parity error possibly present"
249  << std::endl;
250  }
251  if (f.longrec) { os << " long record read" << std::endl; }
252  if (f.shortrec) { os << " short record read" << std::endl; }
253  if (f.start) { os << " start of time series" << std::endl; }
254  if (f.end) { os << " end of time series" << std::endl; }
255  if (f.locked) { os << " clock locked" << std::endl; }
256  } // void dump(const IOFlags& s, std::ostream& os)
257 
258  /*----------------------------------------------------------------------*/
259 
260  void dump(const EEncodingFormat& s, std::ostream& os)
261  {
262  switch (s) {
263  case ascii:
264  os << "ASCII"; break;
265  case int16:
266  os << "16 bit integer"; break;
267  case int24:
268  os << "24 bit integer"; break;
269  case int32:
270  os << "32 bit integer"; break;
271  case ieeefp:
272  os << "IEEE floating point"; break;
273  case ieeedp:
274  os << "IEEE double precision floating point"; break;
275  case steim1:
276  os << "Steim (1) compression"; break;
277  case steim2:
278  os << "Steim (2) compression"; break;
279  case geoscope24:
280  os << "GEOSCOPE multiplexed 24 bit integer"; break;
281  case geoscope163:
282  os << "GEOSCOPE multiplexed 16 bit gain ranged 3 bit exponent";
283  break;
284  case geoscope164:
285  os << "GEOSCOPE multiplexed 16 bit gain ranged 4 bit exponent";
286  break;
287  case us:
288  os << "US national network compression"; break;
289  case cdsn:
290  os << "CDSN 16 bit gain ranged"; break;
291  case grf:
292  os << "Graefenberg 16 bit gain ranged"; break;
293  case ipg:
294  os << "IPG Strasbourg 16 bit gain ranged"; break;
295  case steim3:
296  os << "Steim (3) compression"; break;
297  case sro:
298  os << "SRO format"; break;
299  case hglp:
300  os << "HGLP format"; break;
301  case dwwssn:
302  os << "DWWSSN gain ranged"; break;
303  case rstn:
304  os << "RSTN 16 bit gain ranged"; break;
305  default:
306  os << "unknown";
307  }
308  } // void dump(const EEncodingFormat& s, std::ostream& os)
309 
310  /*----------------------------------------------------------------------*/
311 
312  void dump(const EByteOrder& s, std::ostream& os)
313  {
314  switch (s) {
315  case vax8086:
316  os << "VAX or 8086";
317  break;
318  case sparc68000:
319  os << "SPARC or 68000";
320  break;
321  default:
322  os << "unknown";
323  }
324  } // void dump(const EByteOrder& s, std::ostream& os)
325 
326  /*----------------------------------------------------------------------*/
327 
328  void dump(Steim1Frame f, std::ostream& os)
329  {
330  os << "Steim 1 Frame:" << std::endl;
331  os << " control word: 0x";
332  std::ostream::fmtflags flags=os.flags();
333  os.setf(std::ios_base::hex, std::ios_base::basefield);
334  // os.setf(std::ios_base::showbase);
335  os.width(8);
336  os.fill('0');
337  os << f.control();
338  os.flags(flags);
339  os << std::endl;
340  /*
341  for (int i=0; i<Steim1Frame::nelements; ++i)
342  {
343  os << " ctrl #";
344  os.width(2);
345  os.fill('0');
346  os << i << ": " << f.ctrl(i) << std::endl;
347  }
348  */
349  os << " data: " << std::endl;
350  for (int i=0; i<Steim1Frame::nwords; ++i)
351  {
352  Steim1Word w;
353  w.fw=f.word(i);
354  switch (f.ctrl(i)) {
356  os << " #";
357  os.width(2);
358  os.fill('0');
359  os << i << " special (" << f.ctrl(i) << "): "
360  << w.fw << std::endl;
361  break;
362  case Steim1Frame::Fbyte:
363  for (int j=0; j<4; ++j)
364  {
365  os << " #";
366  os.width(2);
367  os.fill('0');
368  os << i << " byte (" << f.ctrl(i) << ") #" << j << ": "
369  << int(w.byte[j]) << std::endl;
370  }
371  break;
372  case Steim1Frame::Fhw:
373  for (int j=0; j<2; ++j)
374  {
375  os << " #";
376  os.width(2);
377  os.fill('0');
378  os << i << " halfword (" << f.ctrl(i) << ") #" << j << ": "
379  << w.hw[j] << std::endl;
380  }
381  break;
382  case Steim1Frame::Ffw:
383  os << " #";
384  os.width(2);
385  os.fill('0');
386  os << i << " fullword (" << f.ctrl(i) << "): "
387  << w.fw << std::endl;
388  break;
389  }
390  }
391  } // void dump(Steim1Frame f, std::ostream& os)
392 
393  /*----------------------------------------------------------------------*/
394 
395  void dump(Steim2Frame f, std::ostream& os)
396  {
397  os << "Steim 2 Frame:" << std::endl;
398  os << " control word: 0x";
399  std::ostream::fmtflags flags=os.flags();
400  os.setf(std::ios_base::hex, std::ios_base::basefield);
401  // os.setf(std::ios_base::showbase);
402  os.width(8);
403  os.fill('0');
404  os << f.control();
405  os.flags(flags);
406  os << std::endl;
407  /*
408  for (int i=0; i<Steim1Frame::nelements; ++i)
409  {
410  os << " ctrl #";
411  os.width(2);
412  os.fill('0');
413  os << i << ": " << f.ctrl(i) << std::endl;
414  }
415  */
416  os << " data: " << std::endl;
417  for (int i=0; i<Steim2Frame::nwords; ++i)
418  {
419  Steim1Word w;
420  w.fw=f.word(i);
421  switch (f.ctrl(i)) {
423  os << " #";
424  os.width(2);
425  os.fill('0');
426  os << i << " special (" << f.ctrl(i) << "): "
427  << w.fw << std::endl;
428  break;
429  case Steim2Frame::Fbyte:
430  for (int j=0; j<4; ++j)
431  {
432  os << " #";
433  os.width(2);
434  os.fill('0');
435  os << i << " byte (" << f.ctrl(i) << ") #" << j << ": "
436  << int(w.byte[j]) << std::endl;
437  }
438  break;
439  case Steim1Frame::Fdnib1:
440  case Steim1Frame::Fdnib2:
442  for (int j=0; j<word.nval(); ++j)
443  {
444  os << " #";
445  os.width(2);
446  os.fill('0');
447  os << i;
448  os << " c=";
449  os.width(2);
450  os.fill(' ');
451  os << f.ctrl(i);
452  os << " dnib=";
453  os.width(2);
454  os.fill(' ');
455  os << word.dnib();
456  os << " #" << j << ": "
457  << word.value(j) << std::endl;
458  }
459  break;
460  }
461  }
462  } // void dump(Steim2Frame f, std::ostream& os)
463 
464  /*----------------------------------------------------------------------*/
465 
466  void dump(SteimFrame& f, std::ostream& os)
467  {
468  os << "Steim Frame:" << std::endl;
469  os << " control word: 0x";
470  std::ostream::fmtflags flags=os.flags();
471  os.setf(std::ios_base::hex, std::ios_base::basefield);
472  // os.setf(std::ios_base::showbase);
473  os.width(8);
474  os.fill('0');
475  os << f.control();
476  os.flags(flags);
477  os << std::endl;
478  /*
479  for (int i=0; i<Steim1Frame::nelements; ++i)
480  {
481  os << " ctrl #";
482  os.width(2);
483  os.fill('0');
484  os << i << ": " << f.ctrl(i) << std::endl;
485  }
486  */
487  os << " data: " << std::endl;
488  f.reset();
489  while (f.valid())
490  {
491  os << " (" << f.iword() << "," << f.idiff() << ") "
492  << f.diff() << std::endl;
493  f.next();
494  }
495  } // void dump(SteimFrame f, std::ostream& os)
496 
497  } // namespace SEED
498 
499  } // namespace mseed
500 
501 } // namespace datrw
502 
503 /* ----- END OF seedstructdump.cc ----- */
int idiff() const
return current difference index
Definition: seedstructs.h:517
int fw
1 4-byte difference (fullword)
Definition: seedstructs.h:396
DWWSSN gain ranged.
Definition: seedstructs.h:114
bool end
end of time series
Definition: seedstructs.h:262
int iword() const
return current word index
Definition: seedstructs.h:515
GEOSCOPE multiplexed 16 bit gain ranged 3 bit exp.
Definition: seedstructs.h:105
void dump_aflags(const unsigned char &s, std::ostream &os)
Steim (1) compression.
Definition: seedstructs.h:102
unsigned short int dbeg
beginning of data
Definition: seedstructs.h:320
short int srate
sample rate factor
Definition: seedstructs.h:312
int nval() const
return number of values in this word
Definition: seedstructs.cc:267
unsigned short int fblock
first blockette
Definition: seedstructs.h:321
bool event
event in progress
Definition: seedstructs.h:244
void reset()
step to first difference value
Definition: seedstructs.cc:162
void dump_ioflags(const unsigned char &s, std::ostream &os)
char chan[3]
channel identifier
Definition: seedstructs.h:308
unsigned int control() const
return control word
Definition: seedstructs.h:490
Steim (3) compression.
Definition: seedstructs.h:111
bool shortrec
short record read
Definition: seedstructs.h:260
US national network compression.
Definition: seedstructs.h:107
bool calpres
calibration signals present
Definition: seedstructs.h:238
short int srmult
sample rate multiplier
Definition: seedstructs.h:313
int dnib() const
return dnib
Definition: seedstructs.cc:260
bool negleap
a negative leap second happend
Definition: seedstructs.h:243
unsigned short int nsamp
number of samples
Definition: seedstructs.h:311
std::string extractstring(const char *s, const int &l)
Return a maximum of l characters.
Definition: mseedread.cc:141
CDSN 16 bit gain ranged.
Definition: seedstructs.h:108
void print_field_name(const char *f, std::ostream &os)
bool posleap
a positive leap second happend
Definition: seedstructs.h:242
bool ampsat
amplifier saturation detected
Definition: seedstructs.h:278
short int hw[2]
2 2-byte differences (halfword)
Definition: seedstructs.h:395
IEEE floating point.
Definition: seedstructs.h:100
bool time
time tag is questionable
Definition: seedstructs.h:285
unsigned short int next
Next blockette&#39;s byte number.
Definition: seedstructs.h:337
char stat[5]
station identifier code
Definition: seedstructs.h:306
GEOSCOPE multiplexed 16 bit gain ranged 4 bit exp.
Definition: seedstructs.h:106
ControlHeader controlheader
control header with sequence number
Definition: seedstructs.h:305
char loc[2]
location identifier
Definition: seedstructs.h:307
Root namespace of library.
Definition: aalibdatrwxx.cc:16
four 8-bit differences (byte)
Definition: seedstructs.h:470
bool locked
clock locked
Definition: seedstructs.h:263
unsigned char aflags
activity flags
Definition: seedstructs.h:314
libtime::TAbsoluteTime convert(const SEED::BTIME &t)
convert BTIME structure to libtime structure
Definition: mseedread.cc:166
DataRecordBlocketteHeader blocketteheader
Definition: seedstructs.h:354
Steim (2) compression.
Definition: seedstructs.h:103
bool telsynch
telemetry synchronization error
Definition: seedstructs.h:283
DataRecordBlocketteHeader blocketteheader
Definition: seedstructs.h:379
bool spike
spikes detected
Definition: seedstructs.h:280
void dump_qflags(const unsigned char &s, std::ostream &os)
one 32-bit difference (fullword)
Definition: seedstructs.h:472
bool longrec
long record read
Definition: seedstructs.h:259
contains non-data information, like headers
Definition: seedstructs.h:469
bool begevent
beginning of event
Definition: seedstructs.h:240
void dump(const ControlHeader &s, std::ostream &os)
IEEE double precision floating point.
Definition: seedstructs.h:101
IPG Strasbourg 16 bit gain ranged.
Definition: seedstructs.h:110
unsigned char format
Encoding Format.
Definition: seedstructs.h:355
unsigned char ioflags
i/o and clock flags
Definition: seedstructs.h:315
bool parityerr
station volume parity error possibly present
Definition: seedstructs.h:258
bool clip
digitizer clipping detected
Definition: seedstructs.h:279
GEOSCOPE multiplexed 24 bit integer.
Definition: seedstructs.h:104
unsigned short int type
Blockette type.
Definition: seedstructs.h:336
void print_hex(const unsigned short int &f, std::ostream &os)
bool glitch
glitches detected
Definition: seedstructs.h:281
bool miss
missing/padded data present
Definition: seedstructs.h:282
Graefenberg 16 bit gain ranged.
Definition: seedstructs.h:109
void next()
step to next difference value
Definition: seedstructs.cc:172
bool tcorrapp
time correction applied
Definition: seedstructs.h:239
virtual int diff() const =0
return current difference value
SPARC or 68000 byte order.
Definition: seedstructs.h:127
unsigned char qflags
data quality flags
Definition: seedstructs.h:316
bool valid() const
we are still inside the frame
Definition: seedstructs.h:506
bool start
start of time series
Definition: seedstructs.h:261
bool charging
a digital filter may be charging
Definition: seedstructs.h:284
static const int nwords
numer of words to process
Definition: seedstructs.h:463
int word(const int &i) const
return data word i
Definition: seedstructs.h:494
unsigned char bytesex
Word order.
Definition: seedstructs.h:356
RSTN 16 bit gain ranged.
Definition: seedstructs.h:115
char byte[4]
4 1-byte differences
Definition: seedstructs.h:394
unsigned char numblock
number of blockettes that follow
Definition: seedstructs.h:317
ESteimControl ctrl(const int &i) const
return control code for word i
Definition: seedstructs.cc:95
int value(const int &i) const
Definition: seedstructs.cc:317
two 16-bit differences (halfword)
Definition: seedstructs.h:471
VAX or 8086 byte order.
Definition: seedstructs.h:126