DATRW++ library: seismic data I/O with multiple formats

◆ read()

Tiseries datrw::imseedstream::read ( const bool &  skipdata = false)
private

read file

read next trace from file.

All reading is controlled within this function...

File reading always is one record ahead. The record being read in advance is stored in member field imseedstream::Mrecord. This type of operation is necessary, since data data contiguity can only be checked after the next record has been read. If this record is not contiguous, it must be stored for the next read request, where it will provide the first samples of the next trace.

Reading is done as follows:

  1. Data records are read from input as long as the next record read is contiguous to the previous one. They are intermediately stored in a vector.
  2. After having read all contiguous records, the total number of samples in the trace is established and data samples can be collected in a series container.

Definition at line 194 of file imseedstream.cc.

References datrw::mseed::key::data, datrw::mseed::Record::data, DATRW_assert, DATRW_debug, datrw::hpmo::dt(), Mchecks, datrw::idatstream::Mdebug, Mdumpascii, MestimateNframes, datrw::idatstream::Mis, Mrecord, Mttolerance, datrw::hpmo::nsamples, datrw::mseed::Record::read(), datrw::idatstream::setlast(), datrw::idatstream::setwid2(), datrw::mseed::Record::valid, datrw::mseed::Record::wid2, and datrw::mseed::Record::xm1.

Referenced by dseries(), fseries(), iseries(), and skipseries().

195  {
196  DATRW_debug(Mdebug, "imseedstream::read", "entered reading function");
197 
198  // define vector of records, where input data are collected
199  typedef std::vector<Tiseries> Tvecofrecorddata;
200  Tvecofrecorddata vecofrecorddata;
201 
202  // abort is last record recently read from file is not valid
203  // this indicates that the last reading operation arrived at the end of
204  // file
206  "invalid record; passed end of file?");
207 
208  /* The record present in this->Mrecord form the beginning of the next
209  * trace. Its WID2 header defines the trace to be read. Only records
210  * matching this header may be added to the current trace. The this as a
211  * base.
212  */
213  sff::WID2 wid2line=Mrecord.wid2;
214  libtime::TRelativeTime dt=libtime::double2time(wid2line.dt);
215 
216  /* Define a WID2 comparison instance to check whether WID headers of
217  * subsequent record match the header of the total trace being assembled.
218  */
219  sff::WID2compare wid2areequal(sff::Fdate
220  | sff::Fstation
221  | sff::Fchannel
222  | sff::Fauxid
223  | sff::Fdt
224  | sff::Fcalib
225  | sff::Fcalper
226  | sff::Finstype
227  | sff::Fhang
228  | sff::Fvang);
229  // set date tolerance
230  wid2areequal.setdatetolerance(this->Mttolerance*1.e-6/wid2line.dt);
231 
232  /* collect data
233  * ------------
234  * Read record sequentially from file and check whether the recently read
235  * record is part of the trace. Count the number of samples while doing
236  * this.
237  */
238  DATRW_debug(Mdebug, "imseedstream::read", "collect data");
239 
240  sff::WID2 nextwid2=wid2line;
241 
242  int nsamples=0;
243  bool contiguous=true;
244 
245  while(Mrecord.valid && Mis.good() && contiguous)
246  {
247  DATRW_debug(Mdebug, "imseedstream::read",
248  "save data from record ("
249  << Mrecord.data.size() << " samples)");
250 
252  if (!skipdata) { vecofrecorddata.push_back(data.copyout()); }
253 
254  DATRW_debug(Mdebug, "imseedstream::read", "last data index " <<
255  data.last());
256 
257  /*
258  * Remember value of last sample in previous record to be compared to
259  * retrospect value derived from the succeeding record. A mismatch will
260  * indicate non-contiguous data.
261  */
262  int xm1=data(data.last());
263  nsamples += Mrecord.wid2.nsamples;
264  nextwid2.date=wid2line.date+dt*nsamples;
265 
266  DATRW_debug(Mdebug, "imseedstream::read", "read next");
267 
269 
270  DATRW_debug(Mdebug, "imseedstream::read", "compare next");
271  DATRW_debug(Mdebug, "imseedstream::read", "expected wid2: " <<
272  nextwid2.line());
273  DATRW_debug(Mdebug, "imseedstream::read", " this wid2: " <<
274  Mrecord.wid2.line());
275 
276  if (Mrecord.valid)
277  {
278  if (! (wid2areequal(Mrecord.wid2, nextwid2) && (xm1 == Mrecord.xm1)))
279  {
280  contiguous=false;
281  DATRW_debug(Mdebug, "imseedstream::read", "non-contiguous data");
282  }
283  else
284  {
285  DATRW_debug(Mdebug, "imseedstream::read", "data is still contiguous");
286  }
287  }
288  else
289  {
290  // reading has met the end of file
291  contiguous=false;
292  this->setlast();
293  }
294  }
295  wid2line.nsamples=nsamples;
296 
297  // extract data samples
298  DATRW_debug(Mdebug, "imseedstream::read", "extract data");
299  Tiseries series;
300  if (!skipdata)
301  {
302  DATRW_debug(Mdebug, "imseedstream::read", "do not skip");
303  Tvecofrecorddata::const_iterator I(vecofrecorddata.begin());
304  DATRW_debug(Mdebug, "imseedstream::read", "create buffer");
305  series=Tiseries(0,nsamples-1);
306  nsamples=0;
307  DATRW_debug(Mdebug, "imseedstream::read", "cycle vector");
308  while (I != vecofrecorddata.end())
309  {
310  DATRW_debug(Mdebug, "imseedstream::read", "create dest");
311  Tiseries dest=aff::subarray(series)(nsamples,nsamples+I->size()-1);
312  DATRW_debug(Mdebug, "imseedstream::read", "copy to dest");
313  dest.copyin(*I);
314  DATRW_debug(Mdebug, "imseedstream::read", "step nsamples");
315  nsamples += I->size();
316  ++I;
317  }
318  }
319 
320  // set headers
321  this->setwid2(wid2line);
322  return (series);
323  } // Tiseries imseedstream::read(const bool& skipdata)
bool Mdumpascii
dump ASCII data if true
Definition: mseed.h:182
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
datrw::mseed::Record Mrecord
data read ahead
Definition: mseed.h:180
datrw::mseed::ConsistencyChecks Mchecks
Definition: mseed.h:186
libtime::TRelativeTime dt()
return sampling interval of HPMO data acquisition (i.e. 5 sec)
Definition: readhpmo.cc:83
void read(std::istream &is, const bool &dumpascii=false, const bool &estimateNframes=false, const ConsistencyChecks &checks=ConsistencyChecks(true, true))
read and decode a record to SFF
const int nsamples
number of samples per minute block and channel
Definition: hpmodata.h:51
std::istream & Mis
Definition: datread.h:126
void setwid2(const sff::WID2 &wid2)
Definition: datread.cc:113
const char *const data
keywords for consistency checks
Tiseries data
Definition: mseed.h:146
::sff::WID2 wid2
Definition: mseed.h:144
bool MestimateNframes
estimate frame count flags controlling consistency checks
Definition: mseed.h:184
double Mttolerance
timing tolerance in microseconds
Definition: mseed.h:183
aff::Series< int > Tiseries
Definition: types.h:47
#define DATRW_debug(C, N, M)
produce debug output
Definition: debug.h:50
Here is the call graph for this function:
Here is the caller graph for this function: