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

◆ readtraceheader()

TraceHeader datrw::tfascii::readtraceheader ( std::istream &  is,
const bool &  verbose = false 
)

read the complete traceheader

Parameters
isthe input stream
verbosefor verbose output or not
Returns
the TraceHeader of the data

Definition at line 165 of file readtfascii.cc.

References DATRW_assert, datrw::tfascii::helper::extract(), datrw::tfascii::helper::extractvalue(), datrw::tfascii::TraceHeader::hasinfo, datrw::tfascii::TraceHeader::hastracefree, datrw::tfascii::TraceHeader::haswid2, datrw::tfascii::TraceHeader::info, datrw::tfascii::TraceHeader::tracefree, and datrw::tfascii::TraceHeader::wid2.

Referenced by datrw::itfasciistream::set_traceheader().

166  {
167  std::string line;
168  TraceHeader traceheader;
169  traceheader.hastracefree = false;
170  traceheader.hasinfo = false;
171  traceheader.haswid2 = false;
172 
173  while (is.good())
174  {
175  getline(is, line);
176  // get WID2 lines if available
177  if (line == "contents of SFF WID2 line:")
178  {
179  traceheader.haswid2 = true;
180  if (verbose)
181  {
182  std::cout << "SFF WID2 line detected." << std::endl;
183  }
184  DATRW_assert(getline(is, line), "ERROR: reading file");
185  helper::extract(line);
186  std::istringstream iss(line);
187  char c;
188  int doy, day, month, year, hour, minute, secs, micsecs;
189  iss >> doy;
190  iss >> day >> c >> month >> c >> year;
191  iss >> hour >> c >> minute >> c >> secs >> c >> micsecs;
192  traceheader.wid2.date = libtime::TAbsoluteTime(year,
193  month,
194  day,
195  hour,
196  minute,
197  secs,
198  0,
199  micsecs);
200  DATRW_assert(doy == traceheader.wid2.date.doy(),
201  "ERROR: inconsistent date values");
202  DATRW_assert(getline(is, line), "ERROR: reading file");
203  helper::extractvalue(line);
204  traceheader.wid2.station = line;
205  DATRW_assert(getline(is, line), "ERROR: reading file");
206  helper::extractvalue(line);
207  traceheader.wid2.channel = line;
208  DATRW_assert(getline(is, line), "ERROR: reading file");
209  helper::extractvalue(line);
210  traceheader.wid2.auxid = line;
211  DATRW_assert(getline(is, line), "ERROR: reading file");
212  helper::extractvalue(line);
213  traceheader.wid2.instype = line;
214  DATRW_assert(getline(is, line), "ERROR: reading file");
215  helper::extractvalue(line);
216  traceheader.wid2.nsamples = std::atoi(line.c_str());
217  DATRW_assert(getline(is, line), "ERROR: reading file");
218  helper::extractvalue(line, true);
219  traceheader.wid2.dt = std::atof(line.c_str());
220  DATRW_assert(getline(is, line), "ERROR: reading file");
221  helper::extractvalue(line);
222  traceheader.wid2.calib = std::atof(line.c_str());
223  DATRW_assert(getline(is, line), "ERROR: reading file");
224  helper::extractvalue(line);
225  traceheader.wid2.calper = std::atof(line.c_str());
226  DATRW_assert(getline(is, line), "ERROR: reading file");
227  helper::extractvalue(line, true);
228  traceheader.wid2.hang = std::atof(line.c_str());
229  DATRW_assert(getline(is, line), "ERROR: reading file");
230  helper::extractvalue(line, true);
231  traceheader.wid2.vang = std::atof(line.c_str());
232  }
233  // get INFO lines if available
234  if (line == "contents of SFF INFO line:")
235  {
236  traceheader.hasinfo = true;
237  if (verbose)
238  {
239  std::cout << "SFF INFO line detected." << std::endl;
240  }
241  DATRW_assert(getline(is, line), "ERROR: reading file");
242  helper::extractvalue(line);
243  if (line == "cartesian")
244  {
245  traceheader.info.cs = sff::CS_cartesian;
246  }
247  else
248  {
249  traceheader.info.cs = sff::CS_spherical;
250  }
251  DATRW_assert(getline(is, line), "ERROR: reading file");
252  helper::extractvalue(line, true);
253  traceheader.info.cx = std::atof(line.c_str());
254  DATRW_assert(getline(is, line), "ERROR: reading file");
255  helper::extractvalue(line, true);
256  traceheader.info.cy = std::atof(line.c_str());
257  DATRW_assert(getline(is, line), "ERROR: reading file");
258  helper::extractvalue(line, true);
259  traceheader.info.cz = std::atof(line.c_str());
260  DATRW_assert(getline(is, line), "ERROR: reading file");
261  helper::extractvalue(line);
262  traceheader.info.nstacks = std::atoi(line.c_str());
263  }
264  // get traceFREE block if available
265  if (line == "contents of SFF FREE block:")
266  {
267  traceheader.hastracefree = true;
268  if (verbose)
269  {
270  std::cout << "trace FREE block detected." << std::endl;
271  }
272  while (getline(is, line))
273  {
274  // break if stream reaches a empty line
275  if (line.empty()) { break; }
276  traceheader.tracefree.append(line);
277  }
278  }
279  // break if stream reaches data
280  if (line == "data:") { break; }
281  }
282 
283  return traceheader;
284  } // function readtraceheader
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
void extract(std::string &line)
splits a given string after the colon
Definition: readtfascii.cc:67
void extractvalue(std::string &line, bool unit)
split given string
Definition: readtfascii.cc:53
Here is the call graph for this function:
Here is the caller graph for this function: