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

◆ readsamples()

template<typename T >
std::string datrw::ascii::anonymous_namespace{iasciistream.cc}::readsamples ( std::istream &  is,
const unsigned int &  n,
const std::string &  firstline,
typename aff::Series< T > &  series,
const bool &  nonfatal 
)

read a sequence of samples

Read a sequence of samples being regarded as a contiguous trace.

Parameters
Ttype of sample value (double, float, int)
isinput stream to read from
nexpected number of samples
firstlinefirst line from input, which is already read
seriescontainer to write samples to
nonfatalerrors are made nonfatal if true
Returns
next input line

Definition at line 318 of file iasciistream.cc.

References DATRW_nonfatal_assert, datrw::mseed::key::nonfatal, and datrw::hpmo::nsamples.

Referenced by readany().

323  {
324  typedef typename aff::Series<T> Tmyseries;
325  std::string line=firstline;
326  if (n==0)
327  {
328  // we do not expect a specific number of samples
329  // read as many samples as can be found
330  typedef typename std::vector<Tmyseries> Tvecofrecorddata;
331  Tvecofrecorddata vecofrecorddata;
332  unsigned int nsamples=0;
333  unsigned int i=0;
334  const unsigned int bufsize=5000;
335  Tmyseries buffer(0,bufsize-1);
336  buffer=0;
337  // read data
338  while ((!(line.substr(0,1)=="#")) && is.good())
339  {
340  if (i==bufsize)
341  {
342  vecofrecorddata.push_back(buffer.copyout());
343  buffer=0;
344  i=0;
345  }
346  std::istringstream iss(line);
347  iss >> buffer(i);
348  std::getline(is, line);
349  ++i;
350  ++nsamples;
351  }
352  if (i>0)
353  {
354  vecofrecorddata.push_back(aff::subarray(buffer)(0,i-1));
355  }
356  // data read: now copy fragments to series container
357  typename Tvecofrecorddata::const_iterator I(vecofrecorddata.begin());
358  series=Tmyseries(0,nsamples-1);
359  nsamples=0;
360  while (I != vecofrecorddata.end())
361  {
362  Tmyseries dest
363  =aff::subarray(series)(nsamples,nsamples+I->size()-1);
364  dest.copyin(*I);
365  nsamples += I->size();
366  ++I;
367  }
368  }
369  else
370  {
371  // we expect a specfied number of samples
372  series=Tmyseries(n);
373  series=0;
374  unsigned int i=0;
375  while ((!(line.substr(0,1)=="#")) && is.good() && (i<n))
376  {
377  std::istringstream iss(line);
378  iss >> series(series.f()+i);
379  std::getline(is, line);
380  ++i;
381  }
383  (i==n),
384  "readsamples (ASCII): "
385  "found less samples than expected\n"
386  "expected: " << n << " " <<
387  "found: " << i);
388  }
389  return(line);
390  } // readsamples
const int nsamples
number of samples per minute block and channel
Definition: hpmodata.h:51
#define DATRW_nonfatal_assert(F, C, M)
Macro to distinguish between fatal and non fatal assertions.
Definition: error.h:138
const char *const nonfatal
keywords for format modifiers
Here is the caller graph for this function: