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

◆ readheader()

FileHeader datrw::thiesdl1::readheader ( std::istream &  is)

Read and parse a file header.

Definition at line 114 of file thiesdl1file.cc.

References datrw::thiesdl1::FileHeader::creationdate, DATRW_assert, DATRW_report_assert, datrw::thiesdl1::FileHeader::earliestdate, datrw::thiesdl1::FileHeader::expectedfinaldataline, datrw::thiesdl1::FileHeader::expectedinitialdataline, datrw::thiesdl1::FileHeader::initialdataline, datrw::thiesdl1::FileHeader::latestdate, datrw::thiesdl1::FileHeader::lines, and datrw::thiesdl1::FileHeader::readsuccessfully.

Referenced by datrw::ithiesdl1stream::ithiesdl1stream(), main(), and datrw::thiesdl1::File::readwithheader().

115  {
116  FileHeader retval;
117  retval.readsuccessfully=false;
118  struct Found {
119  Found():
120  initial(false),
121  final(false),
122  earliest(false),
123  latest(false),
124  creation(false)
125  { }
126  bool initial,
127  final,
128  earliest,
129  latest,
130  creation;
131  }; // Found
132  Found found;
133  std::string line;
134  DATRW_assert(getline(is, line), "ERROR: reading file");
135  while (line.substr(0,2) == "# ")
136  {
137  retval.lines.append(line.substr(2));
138  if (line.substr(2,15) == "earliest date: ")
139  {
140  retval.earliestdate=
141  libtime::TAbsoluteTime(line.substr(27,4)+":"+
142  line.substr(24,2)+":"+
143  line.substr(21,2)+":"+
144  line.substr(32,15));
145  // std::cout << retval.earliestdate.timestring() << std::endl;
146  found.earliest=true;
147  }
148  else if (line.substr(2,15) == "latest date: ")
149  {
150  retval.latestdate=
151  libtime::TAbsoluteTime(line.substr(27,4)+":"+
152  line.substr(24,2)+":"+
153  line.substr(21,2)+":"+
154  line.substr(32,15));
155  // std::cout << retval.latestdate.timestring() << std::endl;
156  found.latest=true;
157  }
158  else if (line.substr(2,15) == "creation date: ")
159  {
160  retval.creationdate=
161  libtime::TAbsoluteTime(line.substr(27,4)+":"+
162  line.substr(24,2)+":"+
163  line.substr(21,2)+":"+
164  line.substr(32,15));
165  // std::cout << retval.creationdate.timestring() << std::endl;
166  found.creation=true;
167  }
168  else if (line.substr(2,15) == "initial line: ")
169  {
170  retval.expectedinitialdataline=line.substr(17);
171  // std::cout << retval.expectedinitialdataline << std::endl;
172  found.initial=true;
173  }
174  else if (line.substr(2,15) == "final line: ")
175  {
176  retval.expectedfinaldataline=line.substr(17);
177  // std::cout << retval.expectedfinaldataline << std::endl;
178  found.final=true;
179  }
180  // read next line
181  DATRW_assert(getline(is, line), "ERROR: reading file");
182  } // while (line.substr(0,2) == "# ")
183  DATRW_assert(found.initial &&
184  found.final &&
185  found.earliest &&
186  found.latest &&
187  found.creation,
188  "ERROR: could not extract full header data");
189  DATRW_report_assert(line == retval.expectedinitialdataline,
190  "initial data line is not matsching"
191  "\n expected: "
192  << retval.expectedinitialdataline <<
193  "\n found: "
194  << line);
195  DATRW_assert(line == retval.expectedinitialdataline,
196  "ERROR: missing expected initial data line");
197  DATRW_assert(retval.earliestdate<=retval.latestdate,
198  "ERROR: inconsistent date values in data header");
199  DATRW_assert(retval.latestdate<=retval.creationdate,
200  "ERROR: inconsistent date values in data header");
201  retval.initialdataline=line;
202  retval.readsuccessfully=true;
203  return(retval);
204  } // FileHeader readheader(std::istream & is)
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
#define DATRW_report_assert(C, M)
Check an assertion and report only.
Definition: error.h:120
Here is the caller graph for this function: