mseedtest.cc 17.5 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file mseedtest.cc
 * \brief test mini-SEED reading
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id: mseedtest.cc,v 1.20 2006-07-07 09:54:01 tforb Exp $
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
 * \author Thomas Forbriger
 * \date 15/07/2004
 * 
 * test mini-SEED reading
thomas.forbriger's avatar
thomas.forbriger committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * ----
 * 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
27
28
29
30
31
 * 
 * Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach) 
 * 
 * REVISIONS and CHANGES 
 *  - 15/07/2004   V1.0   Thomas Forbriger
thomas.forbriger's avatar
thomas.forbriger committed
32
 *  - 04/04/2006   V1.1   handle special EDL data features
thomas.forbriger's avatar
thomas.forbriger committed
33
 *  - 09/05/2006   V1.2   support Steim 2 too
thomas.forbriger's avatar
thomas.forbriger committed
34
 *  - 11/05/2006   V1.3   generic frame dump
thomas.forbriger's avatar
thomas.forbriger committed
35
 *  - 07/07/2006   V1.4   provide non fatal scan mode
thomas.forbriger's avatar
thomas.forbriger committed
36
37
38
39
 * 
 * ============================================================================
 */
#define MSEEDTEST_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
40
  "MSEEDTEST   V1.4   test MiniSEED reading"
thomas.forbriger's avatar
thomas.forbriger committed
41
#define MSEEDTEST_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
42
  "$Id: mseedtest.cc,v 1.20 2006-07-07 09:54:01 tforb Exp $"
thomas.forbriger's avatar
thomas.forbriger committed
43
44
45
46

#include <fstream>
#include <iostream>
#include <tfxx/commandline.h>
thomas.forbriger's avatar
thomas.forbriger committed
47
#include<tfxx/bytesex.h>
thomas.forbriger's avatar
thomas.forbriger committed
48
49
#include <datreadxx/error.h>
#include <datreadxx/mseedread.h>
thomas.forbriger's avatar
thomas.forbriger committed
50
#include <datreadxx/seedstructdump.h>
thomas.forbriger's avatar
thomas.forbriger committed
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <datreadxx/mseed.h>

using std::cout;
using std::cerr;
using std::endl;

int main(int iargc, char* argv[])
{

  // define usage information
  char usage_text[]=
  {
    MSEEDTEST_VERSION "\n"
thomas.forbriger's avatar
thomas.forbriger committed
64
    "usage: mseedtest [-v] [-raw] [-reader] [-skip] [-stream]" "\n"
thomas.forbriger's avatar
thomas.forbriger committed
65
    "                 [-nfinconsist]" "\n"
thomas.forbriger's avatar
thomas.forbriger committed
66
    "                 file [file...]" "\n"
thomas.forbriger's avatar
thomas.forbriger committed
67
68
69
70
71
72
    "   or: mseedtest --help|-h" "\n"
  };

  // define full help text
  char help_text[]=
  {
thomas.forbriger's avatar
thomas.forbriger committed
73
74
75
76
    MSEEDTEST_CVSID "\n"
    "-v           verbose mode" "\n"
    "-raw         use raw reading functions from mseedstruct" "\n"
    "-reader      use reading functions from mseedread" "\n"
thomas.forbriger's avatar
thomas.forbriger committed
77
    "-skip        skip data samples" "\n"
thomas.forbriger's avatar
thomas.forbriger committed
78
    "-stream      read data through stream" "\n"
thomas.forbriger's avatar
thomas.forbriger committed
79
    "-generic     use generic frame dump during raw test" "\n"
thomas.forbriger's avatar
thomas.forbriger committed
80
    "-nfinconsist make inconsistencies non fatal errors" "\n"
thomas.forbriger's avatar
thomas.forbriger committed
81
82
83
84
85
86
87
88
89
90
  };

  // define commandline options
  using namespace tfxx::cmdline;
  static Declare options[]= 
  {
    // 0: print help
    {"help",arg_no,"-"},
    // 1: verbose mode
    {"v",arg_no,"-"},
thomas.forbriger's avatar
thomas.forbriger committed
91
92
93
94
    // 2: raw mode
    {"raw",arg_no,"-"},
    // 3: reader mode
    {"reader",arg_no,"-"},
thomas.forbriger's avatar
thomas.forbriger committed
95
96
    // 4: skip mode
    {"skip",arg_no,"-"},
thomas.forbriger's avatar
thomas.forbriger committed
97
98
    // 5: stream mode
    {"stream",arg_no,"-"},
thomas.forbriger's avatar
thomas.forbriger committed
99
100
    // 6: stream mode
    {"generic",arg_no,"-"},
thomas.forbriger's avatar
thomas.forbriger committed
101
102
    // 7: stream mode
    {"nfinconsist",arg_no,"-"},
thomas.forbriger's avatar
thomas.forbriger committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    {NULL}
  };

  // no arguments? print usage...
  if (iargc<2) 
  {
    cerr << usage_text << endl;
    exit(0);
  }

  // collect options from commandline
  Commandline cmdline(iargc, argv, options);

  // help requested? print full help text...
  if (cmdline.optset(0))
  {
    cerr << usage_text << endl;
    cerr << help_text << endl;
    exit(0);
  }

  // dummy operation: print option settings
thomas.forbriger's avatar
thomas.forbriger committed
125
  /*
thomas.forbriger's avatar
thomas.forbriger committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  for (int iopt=0; iopt<2; iopt++)
  {
    cout << "option: '" << options[iopt].opt_string << "'" << endl;
    if (cmdline.optset(iopt)) {  cout << "  option was set"; }
    else { cout << "option was not set"; }
    cout << endl;
    cout << "  argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
    cout << "     argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
    cout << "    argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
    cout << "   argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
    cout << "  argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
    cout << "    argument (bool): '";
    if (cmdline.bool_arg(iopt))
    { cout << "true"; } else { cout << "false"; }
    cout << "'" << endl;
  }
thomas.forbriger's avatar
thomas.forbriger committed
142
  */ 
thomas.forbriger's avatar
thomas.forbriger committed
143

thomas.forbriger's avatar
thomas.forbriger committed
144
145
146
  bool verbosemode=cmdline.optset(1);
  bool rawmode=cmdline.optset(2);
  bool readermode=cmdline.optset(3);
thomas.forbriger's avatar
thomas.forbriger committed
147
  bool skipmode=cmdline.optset(4);
thomas.forbriger's avatar
thomas.forbriger committed
148
  bool streammode=cmdline.optset(5);
thomas.forbriger's avatar
thomas.forbriger committed
149
  bool genericframedump=cmdline.optset(6);
thomas.forbriger's avatar
thomas.forbriger committed
150

thomas.forbriger's avatar
thomas.forbriger committed
151
152
153
154
155
156
157
158
159
160
161
  datread::mseed::Debug MiniSEEDdebug;
  MiniSEEDdebug.inconsistencies_are_not_fatal=cmdline.optset(7);

  if (verbosemode) 
  { 
    cout << MSEEDTEST_VERSION << endl;
    cout << MSEEDTEST_CVSID << endl;
    cout << "in verbose mode" << endl; 
  }
  if (MiniSEEDdebug.inconsistencies_are_not_fatal)
  { cout << "inconsistencies are made non fatal" << endl; }
thomas.forbriger's avatar
thomas.forbriger committed
162

thomas.forbriger's avatar
thomas.forbriger committed
163
164
165
166
167
  while (cmdline.extra()) 
  {
    std::cout << std::endl;
    std::string filename=cmdline.next();
    std::cout << "file: " << filename << std::endl;
168
169
170
    std::cout << "using standard input block size of "
      << datread::mseed::MiniSEEDblock::standard_block_size
      << " bytes" << endl;
thomas.forbriger's avatar
thomas.forbriger committed
171

thomas.forbriger's avatar
thomas.forbriger committed
172
173
174
175
176
177
178
179
    /*======================================================================*/

    if (rawmode)
    {
    cout << endl;
    cout << "raw mode" << endl;
    cout << "========" << endl;

thomas.forbriger's avatar
thomas.forbriger committed
180
181
    std::ifstream ifs(filename.c_str());
    int iblock=0;
thomas.forbriger's avatar
thomas.forbriger committed
182
183
    datread::mseed::MiniSEEDblock block;
    ifs >> block;
thomas.forbriger's avatar
thomas.forbriger committed
184
185
186
    while (ifs.good())
    {
      iblock++;
187
188
      cout << endl << "BLOCK #" << iblock << endl
                   << "===========" << endl;
thomas.forbriger's avatar
thomas.forbriger committed
189
190
191
192
193
194
195
196
197
198
      // SEED defines Motorola (big-endian) to be the standard byte order
      // for all headers
      // check our CPU type
      tfxx::ioswap::Ecpu_type mysex=tfxx::ioswap::cpu();
      DATREAD_assert((mysex != tfxx::ioswap::cpu_unknown),
                       "ERROR (reading MiniSEED record): "
                       "cannot identify CPU type");
      bool doswap = (mysex == tfxx::ioswap::cpu_Intel);
      if (doswap) { cout << "swap bytes, when reading header" << endl; }
      else { cout << "do not swap bytes, when reading header" << endl; }
thomas.forbriger's avatar
thomas.forbriger committed
199
200
201
202
      datread::mseed::SEED::ControlHeader controlheader(block.block());
      if (controlheader.type == 'D')
      {
        datread::mseed::SEED::FixedDataRecordHeader
thomas.forbriger's avatar
thomas.forbriger committed
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
          dataheader(block.block(),doswap);
        if (dataheader.fblock > block.bytesize())
        {
          // try it the other way
          cout << "Could not find first Blockette!" << endl;
          cout << "Trying different byte order..." << endl;
          doswap = !doswap;
          dataheader=datread::mseed::SEED::FixedDataRecordHeader(block.block(),
                                                                 doswap);
          DATREAD_assert((dataheader.fblock < block.bytesize()),
                         "ERROR (reading MiniSEED record): "
                         "cannot find first blockette");
          cout << "Apparently we are reading raw data written by an "
            << "EarthDataLogger (EDL) :-)" << endl;
          if (doswap) { cout << "Hence"; }
          else { cout << "Hence do not"; }
          cout << " swap bytes, when reading header!" << endl; 
        }
thomas.forbriger's avatar
thomas.forbriger committed
221
        datread::mseed::SEED::dump(dataheader, cout);
thomas.forbriger's avatar
thomas.forbriger committed
222
223
        int nblockettes(dataheader.numblock);
        unsigned int blocketteadr(dataheader.fblock);
thomas.forbriger's avatar
thomas.forbriger committed
224
225
226
227
228
        // scan blockettes
        bool foundBlockette1000=false;
        bool foundBlockette1001=false;
        datread::mseed::SEED::DataOnlySEEDBlockette blockette1000;
        datread::mseed::SEED::DataExtensionBlockette blockette1001;
thomas.forbriger's avatar
thomas.forbriger committed
229
230
231
        for (int i=0; i<nblockettes; i++)
        {
          datread::mseed::SEED::DataRecordBlocketteHeader
thomas.forbriger's avatar
thomas.forbriger committed
232
            bh(block.block(blocketteadr), doswap);
thomas.forbriger's avatar
thomas.forbriger committed
233
234
235
236
          cout << "Blockette #" << i<< endl;
          if (bh.type == 1000)
          {
            datread::mseed::SEED::DataOnlySEEDBlockette
thomas.forbriger's avatar
thomas.forbriger committed
237
              bck(block.block(blocketteadr), doswap);
thomas.forbriger's avatar
thomas.forbriger committed
238
            datread::mseed::SEED::dump(bck, cout);
thomas.forbriger's avatar
thomas.forbriger committed
239
240
            blockette1000=bck;
            foundBlockette1000=true;
thomas.forbriger's avatar
thomas.forbriger committed
241
242
243
244
          }
          else if (bh.type == 1001)
          {
            datread::mseed::SEED::DataExtensionBlockette
thomas.forbriger's avatar
thomas.forbriger committed
245
              bck(block.block(blocketteadr), doswap);
thomas.forbriger's avatar
thomas.forbriger committed
246
            datread::mseed::SEED::dump(bck, cout);
thomas.forbriger's avatar
thomas.forbriger committed
247
248
            blockette1001=bck;
            foundBlockette1001=true;
thomas.forbriger's avatar
thomas.forbriger committed
249
250
251
252
253
254
255
          }
          else
          {
            datread::mseed::SEED::dump(bh, cout);
          }
          blocketteadr=bh.next;
        }
thomas.forbriger's avatar
thomas.forbriger committed
256
257
258
        // prepare frame reading
        if (foundBlockette1000)
        {
thomas.forbriger's avatar
thomas.forbriger committed
259
260
261
262
263
264
          // For SEED data (not header fields) the byte order my differ from
          // file to file. Use the byte order defined in the Data Only SEED
          // Blockette.
          bool dodataswap=datread::mseed::needswap(blockette1000.bytesex);
          if (!dodataswap) { cout << "do not "; }
          cout << "swap bytes, when reading data" << endl; 
thomas.forbriger's avatar
thomas.forbriger committed
265
266
          if ((blockette1000.format == datread::mseed::SEED::steim1) ||
              (blockette1000.format == datread::mseed::SEED::steim2))
thomas.forbriger's avatar
thomas.forbriger committed
267
          {
thomas.forbriger's avatar
thomas.forbriger committed
268
            unsigned int isamples=0;
thomas.forbriger's avatar
thomas.forbriger committed
269
            int nframes=(blockette1000.reclenbytes()-dataheader.dbeg)/
thomas.forbriger's avatar
thomas.forbriger committed
270
              datread::mseed::SEED::SteimFrame::blocksize;
thomas.forbriger's avatar
thomas.forbriger committed
271
272
            cout << "total number of possible frames in record: "
              << nframes << endl;
thomas.forbriger's avatar
thomas.forbriger committed
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
            if (foundBlockette1001)
            {
              /*
              cerr.flush();
              cout.flush();
              cout << "nframes: " << nframes << std::endl;
              cout << "blockette1001.fcount: " 
                << blockette1001.ifcount() << std::endl;
              cout << "blockette1000.reclenbytes:"
                << blockette1000.reclenbytes() << std::endl;
              cout << "dataheader.dbeg:"
                << dataheader.dbeg << std::endl;
              cout << "datread::mseed::SEED::Steim1Frame::blocksize:"
                << datread::mseed::SEED::Steim1Frame::blocksize << std::endl;
              */
thomas.forbriger's avatar
thomas.forbriger committed
288
289
              /*
              DATREAD_assert((nframes == blockette1001.ifcount()),
thomas.forbriger's avatar
thomas.forbriger committed
290
                             "unexpected number of frames");
thomas.forbriger's avatar
thomas.forbriger committed
291
                             */
thomas.forbriger's avatar
thomas.forbriger committed
292
293
              cout << "number of frames specified in Blockette 1001: "
                << blockette1001.ifcount() << endl;
thomas.forbriger's avatar
thomas.forbriger committed
294
295
            }
            // read frames
thomas.forbriger's avatar
thomas.forbriger committed
296
            unsigned int pframe=dataheader.dbeg;
thomas.forbriger's avatar
thomas.forbriger committed
297
            for (unsigned int i=0; int(i)<nframes; ++i)
thomas.forbriger's avatar
thomas.forbriger committed
298
            {
thomas.forbriger's avatar
thomas.forbriger committed
299
300
301
302
303
304
305
306
              if (pframe >= block.bytesize())
              {
                ifs >> block;
                pframe=0;
                iblock++;
                cout << endl << "BLOCK #" << iblock << endl
                             << "===========" << endl;
              }
thomas.forbriger's avatar
thomas.forbriger committed
307
              if (isamples < dataheader.nsamp)
thomas.forbriger's avatar
thomas.forbriger committed
308
309
310
              { cout << "decode"; }
              else { cout << "ignore"; }
              cout << " frame #" << i+1 << "/" << nframes;
thomas.forbriger's avatar
thomas.forbriger committed
311
312
313
314
315
316
317
318
319
              cout << " at 0x";
              std::ostream::fmtflags flags=cout.flags();
              cout.setf(std::ios_base::hex, std::ios_base::basefield);
              // cout.setf(std::ios_base::showbase);
              cout.width(4);
              cout.fill('0');
              cout << pframe;
              cout.flags(flags);
              cout << std::endl;
thomas.forbriger's avatar
thomas.forbriger committed
320
              if (isamples < dataheader.nsamp)
thomas.forbriger's avatar
thomas.forbriger committed
321
              {
thomas.forbriger's avatar
thomas.forbriger committed
322
                if (blockette1000.format == datread::mseed::SEED::steim1) 
thomas.forbriger's avatar
thomas.forbriger committed
323
                {
thomas.forbriger's avatar
thomas.forbriger committed
324
325
                  datread::mseed::SEED::Steim1Frame frame(block.block(pframe),
                                                          dodataswap);
thomas.forbriger's avatar
thomas.forbriger committed
326
327
328
329
330
331
332
333
334
                  if (genericframedump)
                  {
                    datread::mseed::SEED::SteimFrame& gframe=frame;
                    datread::mseed::SEED::dump(gframe, cout);
                  }
                  else
                  {
                    datread::mseed::SEED::dump(frame, cout);
                  }
thomas.forbriger's avatar
thomas.forbriger committed
335
336
337
338
339
340
341
342
343
344
345
                  frame.reset();
                  while (frame.valid())
                  {
                    ++isamples;
                    frame.next();
                  }
                }
                else
                {
                  datread::mseed::SEED::Steim2Frame frame(block.block(pframe),
                                                          dodataswap);
thomas.forbriger's avatar
thomas.forbriger committed
346
347
348
349
350
351
352
353
354
                  if (genericframedump)
                  {
                    datread::mseed::SEED::SteimFrame& gframe=frame;
                    datread::mseed::SEED::dump(gframe, cout);
                  }
                  else
                  {
                    datread::mseed::SEED::dump(frame, cout);
                  }
thomas.forbriger's avatar
thomas.forbriger committed
355
356
357
358
359
360
                  frame.reset();
                  while (frame.valid())
                  {
                    ++isamples;
                    frame.next();
                  }
thomas.forbriger's avatar
thomas.forbriger committed
361
                }
thomas.forbriger's avatar
thomas.forbriger committed
362
              }
thomas.forbriger's avatar
thomas.forbriger committed
363
              pframe += datread::mseed::SEED::SteimFrame::blocksize;
thomas.forbriger's avatar
thomas.forbriger committed
364
365
366
367
            }
          }
          else
          {
thomas.forbriger's avatar
thomas.forbriger committed
368
            cout << "Not steim1 or steim2 format!" << std::endl;
thomas.forbriger's avatar
thomas.forbriger committed
369
370
371
372
373
374
          }
        }
        else
        {
          cout << "No Blockette 1000 available!" << std::endl;
        }
thomas.forbriger's avatar
thomas.forbriger committed
375
      }
376
377
378
379
380
381
382
383
384
385
      else
      {
        std::string seqnum(controlheader.seqno, 6);
        cout << "seqno: #" << seqnum << "#" 
          << controlheader.type 
          << "-"
          << controlheader.cont 
          << endl;
        datread::mseed::SEED::dump(controlheader, cout);
      }
thomas.forbriger's avatar
thomas.forbriger committed
386
      ifs >> block;
thomas.forbriger's avatar
thomas.forbriger committed
387
    }
thomas.forbriger's avatar
thomas.forbriger committed
388
389
390
391
392
393
394
395
396
397
398
    } // end raw mode

    /*======================================================================*/

    if (readermode)
    {
      cout << endl;
      cout << "reader mode" << endl;
      cout << "===========" << endl;

      std::ifstream ifs(filename.c_str());
thomas.forbriger's avatar
thomas.forbriger committed
399
      datread::mseed::MiniSEEDRecord record(MiniSEEDdebug);
thomas.forbriger's avatar
thomas.forbriger committed
400
401
402
403
404
405
406
      int irecord=0;
      while (ifs.good())
      {
        ++irecord;
        cout << endl;
        cout << "RECORD #" << irecord << endl;
        cout << "===========" << endl;
thomas.forbriger's avatar
thomas.forbriger committed
407
408
409
410
411
412
413
414
415
416
        if (skipmode) 
        { 
          if (verbosemode) { cout << "read record by skipping samples" << endl; }
          record.skipdata(ifs); 
        }
        else 
        { 
          if (verbosemode) { cout << "read record header and samples" << endl; }
          ifs >> record; 
        }
thomas.forbriger's avatar
thomas.forbriger committed
417
418
        if (record.valid())
        {
thomas.forbriger's avatar
thomas.forbriger committed
419
420
421
422
423
          if (!skipmode)
          {
            cout << "  last sample of previous record: " 
              << record.xm1() << endl << endl;
          }
thomas.forbriger's avatar
thomas.forbriger committed
424
425
426
427
428
429
430
431
432
          datread::mseed::SEED::dump(record.recordheader(), cout);
          cout << endl;
          datread::mseed::SEED::dump(record.blockette1000(), cout);
          cout << endl;
          if (record.hasblockette1001())
          { 
            datread::mseed::SEED::dump(record.blockette1001(), cout); 
            cout << endl;
          }
thomas.forbriger's avatar
thomas.forbriger committed
433
434
435
436
          if (!skipmode)
          {
            cout << "data:" << endl;
            datread::mseed::MiniSEEDRecord::Tseries data(record.data());
thomas.forbriger's avatar
thomas.forbriger committed
437
438
            cout << "       number of samples in data: " 
              << data.size() << endl;
thomas.forbriger's avatar
thomas.forbriger committed
439
440
441
442
443
444
445
            cout << "  last sample of previous record: " 
              << record.xm1() << endl;
            cout << "                    first sample: " 
              << data(data.f()) << endl;
            cout << "                     last sample: " 
              << data(data.l()) << endl;
          }
thomas.forbriger's avatar
thomas.forbriger committed
446
447
448
449
450
          {
            cout << endl;
            libtime::TRelativeTime dt
              =libtime::double2time(record.dt());
            libtime::TRelativeTime length=dt*(record.nsamples()-1);
thomas.forbriger's avatar
thomas.forbriger committed
451
452
            libtime::TAbsoluteTime date=record.date();
            libtime::TAbsoluteTime next=(date+dt+length);
thomas.forbriger's avatar
thomas.forbriger committed
453
454
455
456
            cout << "               sampling interval: " 
              << dt.timestring() << endl;
            cout << "                length of record: " 
              << length.timestring() << endl;
thomas.forbriger's avatar
thomas.forbriger committed
457
458
            cout << "            start of this record: " 
              << date.timestring() << endl;
thomas.forbriger's avatar
thomas.forbriger committed
459
460
461
            cout << "   expected start of next record: " 
              << next.timestring() << endl;
          }
thomas.forbriger's avatar
thomas.forbriger committed
462
463
464
465
466
467
468
        }
        else
        {
          cout << "record is invalid!" << endl;
        }
      }
    } // end reader mode
thomas.forbriger's avatar
thomas.forbriger committed
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526

    /*======================================================================*/

    if (streammode)
    {
      cout << endl;
      cout << "stream mode" << endl;
      cout << "===========" << endl;

      std::ifstream ifs(filename.c_str());
      datread::imseedstream is(ifs, verbosemode);

      int itrace=0;
      while (ifs.good() && is.good() && (!is.last()))
      {
        datread::Tiseries series;
        if (skipmode) { is.skipseries(); }
        else { is >> series; }
        ++itrace;
        cout << endl;
        cout << "TRACE #" << itrace << endl;
        cout << "=========" << endl;
        if (is.last())
        { cout << "(is the last trace in the file)" << endl; }

        sff::WID2 wid2line;
        is >> wid2line;
        cout << wid2line.line() << endl;

        if (skipmode)
        {
          cout << "data samples were skipped" << endl;
        }
        else
        {
          cout << "series contains " << series.size() 
            << " samples" << endl;
          cout << "first (" << series.f() << ") sample: " 
            << series(series.f()) << endl;
          cout << "last (" << series.l() << ") sample: " 
            << series(series.l()) << endl;
        }

        if (is.hasinfo())
        {
          sff::INFO infoline;
          is >> infoline;
          cout << infoline.line() << endl;;
        }

        if (is.hasfree())
        {
          sff::FREE freeblock;
          is >> freeblock;
          cout << freeblock;
        }
      }
    } // end stream mode
thomas.forbriger's avatar
thomas.forbriger committed
527
  }
thomas.forbriger's avatar
thomas.forbriger committed
528
529
530
}

/* ----- END OF mseedtest.cc ----- */