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

◆ settimes()

void datrw::su::SUheader::settimes ( )

set time values correctly

set time values

Definition at line 426 of file suheader.cc.

References datrw::su::TraceHeaderStruct::d1, DATRW_assert, DATRW_debug, datrw::su::TraceHeaderStruct::delrt, datrw::su::TraceHeaderStruct::dt, datrw::su::options::TemporalSampling::forceseismic, datrw::su::options::TemporalSampling::forceultrasonic, Mdebug, Mhassrce, Mhaswid2, Mheader, Mheadercontrol, Msrcedate, Mwid2date, Mwid2dt, and datrw::su::options::SUHeaderControl::temporalsampling.

Referenced by set().

427  {
428  // report inpu data for debugging
430  "ERROR SUheader::settimes: ",
431  "set times: Mhaswid2 " << Mhaswid2
432  << " Mhassrce " << Mhassrce);
434  "ERROR SUheader::settimes: ",
435  "WID2 time: " << Mwid2date.timestring()
436  << " WID2 dt: " << Mwid2dt);
438  "ERROR SUheader::settimes: ",
439  "SRCE time: " << Msrcedate.timestring());
440  // check whether evaluation of this function makes sense at all
442  "ERROR SUheader::settimes: "
443  "function called at wrong instance");
444 
445  // ultrasonic flag is required for setting delrt
446  bool ultrasonic=false;
447  // set sampling interval if WID2 data is present
448  // ---------------------------------------------
449  if (Mhaswid2)
450  {
451  DATRW_assert(this->Mwid2dt>0,
452  "received non-positive sampling interval");
453  // evaluate dt and check for ultrasonic data
454  double dtfactor=1.e6;
455  double scaleddt=nearbyint(dtfactor*this->Mwid2dt);
458  {
460  {
461  ultrasonic=true;
462  dtfactor=1.e9;
463  scaleddt=nearbyint(dtfactor*this->Mwid2dt);
465  "SUheader::settimes",
466  "ultrasonic scaling is forced");
467  }
468  else
469  {
471  "SUheader::settimes",
472  "seismic scaling is forced");
473  }
474  }
475  else
476  {
477  if ((!ultrasonic) && scaleddt <1.)
478  {
479  ultrasonic=true;
480  dtfactor=1.e9;
481  scaleddt=nearbyint(dtfactor*this->Mwid2dt);
483  "SUheader::settimes",
484  "ultrasonic scaling because of dt "
485  << scaleddt << "ns value");
486  }
487  else
488  {
490  "SUheader::settimes",
491  "seismic scaling because of dt "
492  << scaleddt << "us value");
493  }
494  }
495  if (scaleddt > USHRT_MAX)
496  {
497  std::cerr << "received sampling interval: " << scaleddt;
498  if (ultrasonic)
499  {
500  std::cerr << " ns";
501  }
502  else
503  {
504  std::cerr << " us";
505  }
506  std::cerr << std::endl;
507  }
508  DATRW_assert(scaleddt <= USHRT_MAX,
509  "ERROR (SUheader::set): "
510  "sampling interval cannot be represented by "
511  "a field of type unsigend short");
512  Mheader.dt=static_cast<unsigned short>(scaleddt);
513  Mheader.d1=0.;
514  if (ultrasonic)
515  { Mheader.d1=static_cast<double>(Mheader.dt)/dtfactor; }
516  }
517 
518  // set source time and trigger delay
519  // ---------------------------------
520  if (Mhaswid2 && Mhassrce)
521  {
522  libtime::TRelativeTime del=Mwid2date-Msrcedate;
523  this->set(Msrcedate);
524  double delfactor=1.e3;
525  if (ultrasonic) { delfactor=1.e6; }
526  double delvalue=std::floor(delfactor*libtime::time2double(del));
527  if (Mwid2date<Msrcedate) { delvalue *= -1.; }
528  DATRW_assert(((delvalue >= SHRT_MIN) && (delvalue <= SHRT_MAX)),
529  "ERROR (SUheader::set): "
530  "trigger delay cannot be represented by "
531  "a field of type short.");
532  this->Mheader.delrt=static_cast<short>(delvalue);
533  }
534  else if (Mhaswid2)
535  {
536  this->set(Mwid2date);
537  this->Mheader.delrt=0;
538  }
539  else if (Mhassrce)
540  {
541  this->set(Msrcedate);
542  this->Mheader.delrt=0;
543  }
544  } // void SUheader::settimes();
float d1
sample spacing for non-seismic data
bool Mhassrce
we received srce data
Definition: suheader.h:225
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
double Mwid2dt
intermediately store sampling interval from wid2 line
Definition: suheader.h:235
bool forceultrasonic
force ultrasonic headers
Definition: suformat.h:151
TemporalSampling temporalsampling
Definition: suformat.h:170
bool Mhaswid2
we received wid2 data
Definition: suheader.h:227
datrw::su::options::SUHeaderControl Mheadercontrol
all options taken from the user
Definition: suheader.h:202
bool Mdebug
be verbose
Definition: suheader.h:204
unsigned short dt
sample interval; in micro-seconds
short delrt
Delay recording time (see details).
libtime::TAbsoluteTime Mwid2date
date from WID2 line
Definition: suheader.h:233
#define DATRW_debug(C, N, M)
produce debug output
Definition: debug.h:50
libtime::TAbsoluteTime Msrcedate
date from SRCE line
Definition: suheader.h:231
TraceHeaderStruct Mheader
the actual data fields are provided for public access
Definition: suheader.h:239
bool forceseismic
force seismic headers
Definition: suformat.h:153
Here is the caller graph for this function: