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

◆ readheader()

void datrw::iasciistream::readheader ( )
private

this function reads all header lines until the next trace data is found

Definition at line 121 of file iasciistream.cc.

References datrw::util::clipstring(), DATRW_nonfatal_assert, DATRW_report_assert, datrw::ascii::keyauxid, datrw::ascii::keycalib, datrw::ascii::keycalper, datrw::ascii::keychannel, datrw::ascii::keydata, datrw::ascii::keydate, datrw::ascii::keydouble, datrw::ascii::keydt, datrw::ascii::keyhang, datrw::ascii::keyinstype, datrw::ascii::keynsamples, datrw::ascii::keynstacks, datrw::ascii::keyRECVCS, datrw::ascii::keyRECVX, datrw::ascii::keyRECVY, datrw::ascii::keyRECVZ, datrw::ascii::keySRCECS, datrw::ascii::keySRCEdate, datrw::ascii::keySRCEtype, datrw::ascii::keySRCEX, datrw::ascii::keySRCEY, datrw::ascii::keySRCEZ, datrw::ascii::keystation, datrw::ascii::keyvang, Mcurrentfree, Mcurrentinfo, Mcurrentline, Mcurrentsrce, Mcurrentwid2, Mdatatype, Mdefaultinfo, Mdefaultsrce, Mdefaultwid2, datrw::idatstream::Mis, Mnonfatal, Mnsamples, Mreadfree, Mreadinfo, Mreadsrce, and datrw::util::trimws().

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

122  {
123  // set defaults of header fields
124  this->Mcurrentwid2=this->Mdefaultwid2;
125  this->Mcurrentinfo=this->Mdefaultinfo;
126  this->Mcurrentsrce=this->Mdefaultsrce;
127 
128  this->Mcurrentfree.lines.clear();
129 
131 
132  this->Mnsamples=0;
133 
134  this->Mreadinfo=false;
135  this->Mreadfree=false;
136  this->Mreadsrce=false;
137  // scan input lines until data is found
138  while ((this->Mcurrentline.substr(0,1)=="#") && Mis.good())
139  {
140  if (this->Mcurrentline.substr(0,2)=="##")
141  {
142  this->Mreadfree=true;
143  this->Mcurrentfree.append(util::trimws(this->Mcurrentline.substr(2)));
144  }
145  else
146  {
147  std::string value=this->Mcurrentline.substr(1);
148  std::string key=util::clipstring(value, ":");
149  value=util::trimws(value);
150  key=util::trimws(key);
151  if (key==ascii::keydate)
152  {
153  this->Mcurrentwid2.date=libtime::TAbsoluteTime(value);
154  }
155  else if (key==ascii::keystation)
156  {
157  this->Mcurrentwid2.station=value;
158  }
159  else if (key==ascii::keychannel)
160  {
161  this->Mcurrentwid2.channel=value;
162  }
163  else if (key==ascii::keyauxid)
164  {
165  this->Mcurrentwid2.auxid=value;
166  }
167  else if (key==ascii::keyinstype)
168  {
169  this->Mcurrentwid2.instype=value;
170  }
171  else if (key==ascii::keyRECVCS)
172  {
173  this->Mreadinfo=true;
174  this->Mcurrentinfo.cs=::sff::coosysID(value.c_str()[0]);
175  }
176  else if (key==ascii::keySRCEdate)
177  {
178  this->Mreadsrce=true;
179  this->Mcurrentsrce.date=libtime::TAbsoluteTime(value);
180  }
181  else if (key==ascii::keySRCEtype)
182  {
183  this->Mreadsrce=true;
184  this->Mcurrentsrce.type=value;
185  }
186  else if (key==ascii::keySRCECS)
187  {
188  this->Mreadsrce=true;
189  this->Mcurrentsrce.cs=::sff::coosysID(value.c_str()[0]);
190  }
191  else if (key==ascii::keydata)
192  {
193  this->Mdatatype=value;
194  }
195  else
196  {
197  std::istringstream iss(value);
198  if (key==ascii::keynsamples)
199  {
200  iss >> this->Mcurrentwid2.nsamples;
201  }
202  else if (key==ascii::keydt)
203  {
204  iss >> this->Mcurrentwid2.dt;
205  }
206  else if (key==ascii::keyhang)
207  {
208  iss >> this->Mcurrentwid2.hang;
209  }
210  else if (key==ascii::keyvang)
211  {
212  iss >> this->Mcurrentwid2.vang;
213  }
214  else if (key==ascii::keycalib)
215  {
216  iss >> this->Mcurrentwid2.calib;
217  }
218  else if (key==ascii::keycalper)
219  {
220  iss >> this->Mcurrentwid2.calper;
221  }
222  else if (key==ascii::keynstacks)
223  {
224  this->Mreadinfo=true;
225  iss >> this->Mcurrentinfo.nstacks;
226  }
227  else if (key==ascii::keyRECVX)
228  {
229  this->Mreadinfo=true;
230  iss >> this->Mcurrentinfo.cx;
231  }
232  else if (key==ascii::keyRECVY)
233  {
234  this->Mreadinfo=true;
235  iss >> this->Mcurrentinfo.cy;
236  }
237  else if (key==ascii::keyRECVZ)
238  {
239  this->Mreadinfo=true;
240  iss >> this->Mcurrentinfo.cz;
241  }
242  else if (key==ascii::keySRCEX)
243  {
244  this->Mreadsrce=true;
245  iss >> this->Mcurrentsrce.cx;
246  }
247  else if (key==ascii::keySRCEY)
248  {
249  this->Mreadsrce=true;
250  iss >> this->Mcurrentsrce.cy;
251  }
252  else if (key==ascii::keySRCEZ)
253  {
254  this->Mreadsrce=true;
255  iss >> this->Mcurrentsrce.cz;
256  }
257  else
258  {
259  if (key.length()==0)
260  {
261  DATRW_report_assert(key.length()>0,
262  "keyword is missing in header line\n" <<
263  "input line: " << Mcurrentline << "\n" <<
264  "key: " << key);
265  }
266  else
267  {
268  if (!Mnonfatal)
269  {
270  std::cerr << "Illegal keyword: " << key << std::endl;
271  }
272  // was not recognoized
274  false,
275  "iasciistream: header key not recognized\n"
276  "input line: " << Mcurrentline << "\n" <<
277  "key: " << key);
278  }
279  }
280  }
281  }
282  std::getline(Mis, this->Mcurrentline);
283  } // while ((this->Mcurrentline.substr(0,1)=="#") && Mis.good())
284  } // void iasciistream::readheader()
const char *const keyinstype
key for WID2 line header field
Definition: ascii.cc:51
const char *const keySRCEtype
key for SRCE line header field
Definition: ascii.cc:58
const char *const keydouble
key for DATA type header field
Definition: ascii.cc:73
const char *const keySRCEY
key for SRCE line header field
Definition: ascii.cc:60
::sff::INFO Mdefaultinfo
Definition: ascii.h:92
const char *const keyRECVY
key for INFO line header field
Definition: ascii.cc:65
std::string Mcurrentline
Definition: ascii.h:84
const char *const keydt
key for WID2 line header field
Definition: ascii.cc:46
const char *const keyRECVCS
key for INFO line header field
Definition: ascii.cc:67
const char *const keyhang
key for WID2 line header field
Definition: ascii.cc:54
::sff::SRCE Mcurrentsrce
Definition: ascii.h:96
std::string Mdatatype
Definition: ascii.h:85
std::istream & Mis
Definition: datread.h:126
const char *const keycalib
key for WID2 line header field
Definition: ascii.cc:52
const char *const keyauxid
key for WID2 line header field
Definition: ascii.cc:50
const char *const keychannel
key for WID2 line header field
Definition: ascii.cc:49
std::string trimws(std::string s)
remove leading and trailing whitespace
Definition: util.cc:129
::sff::WID2 Mdefaultwid2
Definition: ascii.h:87
::sff::FREE Mcurrentfree
Definition: ascii.h:90
const char *const keydate
key for WID2 line header field
Definition: ascii.cc:45
const char *const keynstacks
key for INFO line header field
Definition: ascii.cc:68
::sff::INFO Mcurrentinfo
Definition: ascii.h:93
const char *const keySRCEdate
key for SRCE line header field
Definition: ascii.cc:57
const char *const keyRECVX
key for INFO line header field
Definition: ascii.cc:64
::sff::SRCE Mdefaultsrce
Definition: ascii.h:95
std::string clipstring(std::string &s, const std::string &delim)
strip substringStrips off first substring up to given delimiter. The string is passed as a reference ...
Definition: util.cc:105
const char *const keycalper
key for WID2 line header field
Definition: ascii.cc:53
#define DATRW_nonfatal_assert(F, C, M)
Macro to distinguish between fatal and non fatal assertions.
Definition: error.h:138
const char *const keynsamples
key for WID2 line header field
Definition: ascii.cc:47
::sff::WID2 Mcurrentwid2
Definition: ascii.h:88
const char *const keySRCEX
key for SRCE line header field
Definition: ascii.cc:59
unsigned int Mnsamples
Definition: ascii.h:86
const char *const keyRECVZ
key for INFO line header field
Definition: ascii.cc:66
const char *const keySRCECS
key for SRCE line header field
Definition: ascii.cc:62
const char *const keyvang
key for WID2 line header field
Definition: ascii.cc:55
const char *const keystation
key for WID2 line header field
Definition: ascii.cc:48
#define DATRW_report_assert(C, M)
Check an assertion and report only.
Definition: error.h:120
const char *const keydata
key for DATA type header field
Definition: ascii.cc:70
const char *const keySRCEZ
key for SRCE line header field
Definition: ascii.cc:61
Here is the call graph for this function:
Here is the caller graph for this function: