95 #define TF_SFFXX_CC_VERSION \ 110 bool IDmatch(
const std::string& line,
const bool& debug=
false)
114 std::cerr <<
"DEBUG: IDmatch: " 115 << line.substr(0,4) <<
"=?=" << std::string(C::LINEID)
118 return(line.substr(0,4)==std::string(C::LINEID));
151 GSE2::Terror(
"ERROR (sff::coosysID): library inconsistency!");
161 GSE2::Terror(
"ERROR (sff::coosysID): unknown coordinate system key!");
206 int yeardigits, century;
207 century=int(date.year()/100);
208 yeardigits=date.year()-100*century;
209 sprintf(stamp,
"%2.2d%2.2d%2.2d.%2.2d%2.2d%2.2d",
210 static_cast<int>(yeardigits), static_cast<int>(date.month()),
211 static_cast<int>(date.day()), static_cast<int>(date.hour()),
212 static_cast<int>(date.minute()), static_cast<int>(date.second()));
222 std::string code(
"");
223 if (this->
hasfree) { code.append(
"F"); }
224 if (this->
hassrce) { code.append(
"S"); }
225 sprintf(charline,
"%-4s %6.2f %-13s %-10s\n",
229 code.substr(0,10).c_str());
230 std::string retval(charline);
238 if (debug) { std::cerr <<
"DEBUG (STAT::read):" << std::endl; }
241 std::getline(fis, theline);
243 if (debug) { std::cerr << theline << std::endl; }
244 std::string lineID=theline.substr(0,4);
245 if (debug) { std::cerr << lineID << std::endl; }
246 if (!helper::IDmatch<STAT>(lineID))
throw 247 GSE2::Terror(
"ERROR (STAT::read): missing STAT ID!");
249 double inlibversion=atof(theline.substr(5,7).c_str());
252 std::cerr <<
"ERROR (STAT::read): " 253 <<
"data file has format version " 254 << inlibversion << std::endl;
255 std::cerr <<
"ERROR (STAT::read): " 256 <<
"library can decode formats up to version " 259 GSE2::Terror(
"ERROR (STAT::read): file library version too large!");
267 std::cerr <<
"ERROR (STAT::read): " 268 <<
"data file has format version " 269 << inlibversion << std::endl;
270 std::cerr <<
"ERROR (STAT::read): " 271 <<
"library can decode formats from version " 276 GSE2::Terror(
"ERROR (STAT::read): incompatible SFF version!");
281 std::string code=theline.substr(27,10);
283 this->
hasfree=(code.find(
'F')!=std::string::npos);
284 this->
hassrce=(code.find(
'S')!=std::string::npos);
288 { std::cerr <<
"DEBUG (STAT::read): has FREE block" << std::endl; }
290 { std::cerr <<
"DEBUG (STAT::read): has SRCE line" << std::endl; }
291 std::cerr <<
"DEBUG (STAT::read): finished" << std::endl;
352 type(
"NSP"), date(libtime::now()),
360 int yeardigits, century;
361 century=int(
date.year()/100);
362 yeardigits=
date.year()-100*century;
363 sprintf(charline,
"%-4s %-20s %1c %15.6f%15.6f%15.6f " 364 "%2.2i%2.2i%2.2i %2.2i%2.2i%2.2i.%3.3i\n",
366 type.substr(0,20).c_str(),
368 yeardigits,
static_cast<int>(
date.month()), static_cast<int>(
date.day()),
369 static_cast<int>(
date.hour()), static_cast<int>(
date.minute()),
370 static_cast<int>(
date.second()), static_cast<int>(
date.milsec()));
371 std::string retval(charline);
380 std::getline(fis, theline);
382 std::string lineID=theline.substr(0,4);
383 if (!helper::IDmatch<SRCE>(lineID))
throw 384 GSE2::Terror(
"ERROR (SRCE::read): missing SRCE ID!");
386 this->
type=theline.substr(5,20);
388 { std::cerr <<
"DEBUG (SRCE::read): type: " <<
type << std::endl; }
390 this->
cs=
coosysID(*theline.substr(26,1).c_str());
391 this->
cx=atof(theline.substr(28,15).c_str());
392 this->
cy=atof(theline.substr(43,15).c_str());
393 this->
cz=atof(theline.substr(58,15).c_str());
396 std::cerr <<
"DEBUG (SRCE::read): cs,cx,cy,cz: " 400 std::string datestring,timestring;
401 datestring=theline.substr(74,6);
402 timestring=theline.substr(81,10);
405 std::cerr <<
"DEBUG (SRCE::read): datestring: " 406 << datestring << std::endl;
407 std::cerr <<
"DEBUG (SRCE::read): timestring: " 408 << timestring << std::endl;
410 std::string fulldate(
"");
411 fulldate+=datestring.substr(0,2);
413 fulldate+=datestring.substr(2,2);
415 fulldate+=datestring.substr(4,2);
417 fulldate+=timestring.substr(0,2);
419 fulldate+=timestring.substr(2,2);
421 fulldate+=timestring.substr(4,6);
424 std::cerr <<
"DEBUG (SRCE::read): convert string: " 425 << fulldate << std::endl;
427 this->
date=libtime::TAbsoluteTime(fulldate);
430 std::cerr <<
"DEBUG (SRCE::read): time: " 431 <<
date.timestring() << std::endl;
488 nchar(-1), ampfac(1.), hasfree(false),
489 hasinfo(false), last(false) { }
496 std::string code(
"");
497 if (this->
hasfree) { code.append(
"F"); }
498 if (this->
hasinfo) { code.append(
"I"); }
499 if (!this->
last) { code.append(
"D"); }
501 sprintf(charline,
"%-4s %10i %16.6E %-10s\n",
503 -1,
ampfac, code.substr(0,10).c_str());
504 std::string retval(charline);
514 std::cerr <<
"DEBUG (DAST::read):" << std::endl;
517 std::getline(fis, theline);
518 if (debug) { std::cerr << theline << std::endl; }
520 std::string lineID=theline.substr(0,4);
521 if (debug) { std::cerr << lineID << std::endl; }
522 if (!helper::IDmatch<DAST>(lineID))
throw 523 GSE2::Terror(
"ERROR (DAST::read): missing DAST ID!");
525 this->
nchar=atoi(theline.substr(6,10).c_str());
526 this->
ampfac=atof(theline.substr(17,16).c_str());
528 std::string code=theline.substr(34,10);
531 std::cerr <<
"DEBUG (DAST): read nchar=" <<
nchar 532 <<
" ampfac=" <<
ampfac <<
" code=" << code << std::endl;
534 this->
hasinfo=(code.find(
'I')!=std::string::npos);
535 this->
hasfree=(code.find(
'F')!=std::string::npos);
536 this->
last=(code.find(
'D')==std::string::npos);
568 for(Tlines::const_iterator I=
lines.begin();
569 I !=
lines.end(); I++)
570 { os << *I << std::endl; }
582 { std::cerr <<
"DEBUG (FREE): lineID=" << lineID << std::endl; }
583 if (!helper::IDmatch<FREE>(lineID.substr(0,4), debug))
throw 584 GSE2::Terror(
"ERROR (FREE::read): missing FREE ID!");
588 if (debug) { std::cerr <<
"FREE " << lineID << std::endl; }
589 if (debug) { std::cerr <<
"ID \"" << lineID.substr(0,4) <<
"\"" << std::endl; }
590 while (!helper::IDmatch<FREE>(lineID.substr(0,4), debug))
592 lines.push_back(lineID);
601 Tlines::const_iterator I(newlines.begin());
602 while (I != newlines.end())
651 date(libtime::now()), station(
"NSP"), channel(
"NSP"), auxid(
"NSP"),
652 nsamples(-1), dt(-1.), calib(-1.), calper(-1.), instype(
"NSP"),
653 hang(-1.),vang(-1.) { }
659 GSE2::waveform::TWID2 wid2line;
661 libtime::TAbsoluteTime rnddate(
date.year(),
date.month(),
665 if (
date.micsec()>499) { rnddate += libtime::TRelativeTime(0,0,0,0,1); }
666 wid2line.Fyear=rnddate.year();
667 wid2line.Fmonth=rnddate.month();
668 wid2line.Fday=rnddate.day();
669 wid2line.Fhour=rnddate.hour();
670 wid2line.Fminute=rnddate.minute();
671 wid2line.Fmilsec=rnddate.second()*1000+rnddate.milsec();
674 wid2line.Fauxid=
auxid;
676 wid2line.Fsamprate=1./
dt;
677 wid2line.Fcalib=
calib;
682 return(wid2line.line());
690 std::getline(is,
line);
697 std::istringstream iss(
line);
698 GSE2::waveform::TWID2 wid2line;
700 int second=int(wid2line.Fmilsec/1000);
701 int milsec=wid2line.Fmilsec-1000*second;
702 date=libtime::TAbsoluteTime(wid2line.Fyear,
708 this->
station=wid2line.Fstation;
709 this->
channel=wid2line.Fchannel;
710 this->
auxid=wid2line.Fauxid;
712 this->
dt=1./wid2line.Fsamprate;
713 this->
calib=wid2line.Fcalib;
714 this->
calper=wid2line.Fcalper;
715 this->
instype=wid2line.Finstype;
716 this->
hang=wid2line.Fhang;
717 this->
vang=wid2line.Fvang;
750 cs(
CS_cartesian), cx(0.), cy(0.), cz(0.), nstacks(0) { }
757 sprintf(charline,
"%-4s %1c %15.6f%15.6f%15.6f %4i\n",
760 std::string retval(charline);
769 std::getline(fis, theline);
771 std::string lineID=theline.substr(0,4);
772 if (!helper::IDmatch<INFO>(lineID))
throw 773 GSE2::Terror(
"ERROR (INFO::read): missing INFO ID!");
775 this->
cs=
coosysID(*theline.substr(5,1).c_str());
776 this->
cx=atof(theline.substr(7,15).c_str());
777 this->
cy=atof(theline.substr(22,15).c_str());
778 this->
cz=atof(theline.substr(37,15).c_str());
779 this->
nstacks=atoi(theline.substr(53,4).c_str());
786 return ((info.
cs==this->cs) &&
787 (info.
cx==this->cx) &&
788 (info.
cy==this->cy) &&
789 (info.
cz==this->cz) &&
790 (info.
nstacks==this->nstacks));
824 { std::cerr <<
"DEBUG (FileHeader::read): file FREE read" << std::endl; }
830 { std::cerr <<
"DEBUG (FileHeader::read): SRCE line read" << std::endl; }
833 { std::cerr <<
"DEBUG (FileHeader::read): finished" << std::endl; }
851 if (
Mdebug) { std::cerr <<
"DEBUG: write DAST line" << std::endl; }
853 if (
Mdebug) { std::cerr <<
"DEBUG: write WID2 line" << std::endl; }
863 if (
Mdebug) { std::cerr <<
"DEBUG: write FREE block" << std::endl; }
868 if (
Mdebug) { std::cerr <<
"DEBUG: write INFO line" << std::endl; }
877 if (
Mdebug) { std::cerr <<
"DEBUG: read DAST line" << std::endl; }
879 if (
Mdebug) { std::cerr <<
"DEBUG: read WID2 line" << std::endl; }
887 if (
Mdebug) { std::cerr <<
"DEBUG: read trace trailer" << std::endl; }
890 if (
Mdebug) { std::cerr <<
"DEBUG: read FREE block" << std::endl; }
896 if (
Mdebug) { std::cerr <<
"DEBUG: read INFO line" << std::endl; }
916 const double& maxval):
917 Mmaxval(maxval), Mnorm(nm)
924 GSE2::Terror(
"ERROR (sff::WaveformNormalizer::scan): " 925 "dynamic range to large for non-normalizing mode");
943 GSE2::Terror(
"ERROR (sff::WaveformNormalizer::scan): " 944 "library inconsistency!");
955 GSE2::waveform::TDAT2readCM6 freader(nsamples);
957 for (
int i=0; i<nsamples; i++)
958 { idata=freader(is); }
void read(std::istream &is, const bool &debug=false)
char coosysID(const Ecoosys &csid)
std::string auxid
Auxiliary identification code.
void write(std::ostream &os) const
bool IDmatch(const std::string &line, const bool &debug=false)
Check GSE identifier at beginning of line.
void read(std::istream &is, const bool &debug=false)
void read(std::istream &is)
double calper
calibration reference period
void read(std::istream &is, const bool &debug=false)
std::string station
Station code.
std::string instype
instrument type
std::string channel
FDSN channel code.
int nsamples
number of samples
libtime::TAbsoluteTime date
time of first sample
static const char *const LINEID
std::string WIDXline(const sff::WID2 &wid2, const bool &debug=false)
write WID2 information in extended format
Ecoosys
valid coordinate systems
double calib
calibration factor
scale if largest amplitude larger than limit
void setstamp(const libtime::TAbsoluteTime &date) const
const char *const WIDXID
ID for extended WID2 format.
libtime::TAbsoluteTime date
time of source
void read(std::istream &is, const bool &debug=false)
static const double decode_libversion
double vang
veritcal orientation
std::list< std::string > Tlines
static const char *const LINEID
void append(const std::string &line)
static const char *const LINEID
static const char *const LINEID
void read(std::istream &is)
static const double libversion
Fortran library version (to ensure compatibility)
bool operator==(const INFO &info) const
double dt
sampling interval (sec)
scale for maximum dynamic range
double hang
horizontal orientation
static const char *const LINEID