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

◆ readfileheader()

FileHeader datrw::tfascii::readfileheader ( std::istream &  is,
const bool &  verbose = false 
)

read the complete fileheader

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

Definition at line 78 of file readtfascii.cc.

References DATRW_assert, datrw::tfascii::helper::extract(), datrw::tfascii::helper::extractvalue(), datrw::tfascii::FileHeader::filefree, datrw::tfascii::FileHeader::hasfilefree, datrw::tfascii::FileHeader::hassrce, and datrw::tfascii::FileHeader::srce.

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

79  {
80  std::string line;
81  bool hot = true;
82  FileHeader fileheader;
83  fileheader.hasfilefree = false;
84  fileheader.hassrce = false;
85 
86  while (hot && is.good())
87  {
88  getline(is, line);
89  // get SRCE line if available
90  if (line == "contents of SFF SRCE line:")
91  {
92  fileheader.hassrce = true;
93  if (verbose)
94  {
95  std::cout << "SFF SRCE line detected." << std::endl;
96  }
97  DATRW_assert(getline(is, line), "ERROR: reading file");
98  helper::extract(line);
99  fileheader.srce.type = line;
100  DATRW_assert(getline(is, line), "ERROR: reading file");
101  helper::extractvalue(line);
102  if (line == "cartesian")
103  {
104  fileheader.srce.cs = sff::CS_cartesian;
105  }
106  else
107  {
108  fileheader.srce.cs = sff::CS_spherical;
109  }
110  DATRW_assert(getline(is, line), "ERROR: reading file");
111  helper::extractvalue(line, true);
112  fileheader.srce.cx = std::atof(line.c_str());
113  DATRW_assert(getline(is, line), "ERROR: reading file");
114  helper::extractvalue(line, true);
115  fileheader.srce.cy = std::atof(line.c_str());
116  DATRW_assert(getline(is, line), "ERROR: reading file");
117  helper::extractvalue(line, true);
118  fileheader.srce.cz = std::atof(line.c_str());
119  DATRW_assert(getline(is, line), "ERROR: reading file");
120  helper::extract(line);
121  std::istringstream iss(line);
122  char c;
123  int doy, day, month, year, hour, minute, secs, micsecs;
124  iss >> doy;
125  iss >> day >> c >> month >> c >> year;
126  iss >> hour >> c >> minute >> c >> secs >> c >> micsecs;
127  fileheader.srce.date = libtime::TAbsoluteTime(year,
128  month,
129  day,
130  hour,
131  minute,
132  secs,
133  0,
134  micsecs);
135  DATRW_assert(doy == fileheader.srce.date.doy(),
136  "ERROR: inconsistent date values");
137  }
138  // get fileFREE if available
139  if (line == "contents of SFF FREE block:")
140  {
141  fileheader.hasfilefree = true;
142  if (verbose)
143  {
144  std::cout << "file FREE block detected." << std::endl;
145  }
146  while (getline(is, line))
147  {
148  // break if stream reaches a empty line
149  if (line.empty())
150  {
151  hot = false;
152  break;
153  }
154  fileheader.filefree.append(line);
155  }
156  } else
157  if (line == "file header contains no FREE block")
158  { hot = false; }
159  }
160 
161  return fileheader;
162  } // function readfileheader
#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: