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

◆ read()

void datrw::tsoft::TSOFTfile::read ( std::istream &  is,
const bool &  debug = false 
)

read from stream

Definition at line 96 of file tsoftreader.cc.

References datrw::tsoft::Checklist::allchecked(), datrw::tsoft::Checklist::channels, datrw::tsoft::Checklist::data, DATRW_assert, datrw::hpmo::dt(), datrw::tsoft::Checklist::fileid, datrw::tsoft::Datacontainer::flushchannels(), datrw::tsoft::getDOSline(), datrw::tsoft::Line::hascontent(), datrw::tsoft::Line::hastag(), datrw::tsoft::Checklist::increment, Mchecklist, Mdatacontainer, Mfree, Mincrement, Mundetval, datrw::tsoft::Datacontainer::push_data(), datrw::tsoft::Checklist::report(), datrw::tsoft::Channelinfo::setchannelinfo(), datrw::tsoft::Channelinfo::setunits(), datrw::tsoft::tagchannels, datrw::tsoft::tagdata, datrw::tsoft::tagfileid, datrw::tsoft::tagincrement, datrw::tsoft::tagtimeformat, datrw::tsoft::tagundetval, datrw::tsoft::tagunits, datrw::tsoft::Line::thecontent(), datrw::tsoft::Line::theline(), datrw::tsoft::Line::thetag(), datrw::tsoft::Checklist::timeformat, datrw::tsoft::TSOFTID, datrw::tsoft::Checklist::undetval, and datrw::tsoft::Checklist::units.

Referenced by TSOFTfile().

97  {
98  int count=0;
99  bool indata=false;
100  bool inchannels=false;
101  bool inunits=false;
102  std::string inputline;
103  inputline=getDOSline(is);
104  if (debug) { std::cout << "<" << inputline << ">" << endl; }
105  while (is.good())
106  {
107  datrw::tsoft::Line theline(inputline);
108  int linelength=theline.theline().length();
109  if ((!indata) && (linelength > 0))
110  { Mfree.push_back(theline.theline()); }
111  if (theline.hastag() && (linelength > 0))
112  {
113  // reset special block processing
114  indata=false;
115  inchannels=false;
116  inunits=false;
117  count=0;
118  if (theline.thetag() == datrw::tsoft::tagdata)
119  {
120  indata=true;
121  Mchecklist.data=true;
122  if (debug)
123  { cout << "found data tag " << theline.thetag() << endl; }
124  }
125  else if (theline.thetag() == datrw::tsoft::tagchannels)
126  {
127  inchannels=true;
128  Mchecklist.channels=true;
129  if (debug)
130  { cout << "found channels tag " << theline.thetag() << endl; }
131  }
132  else if (theline.thetag() == datrw::tsoft::tagunits)
133  {
134  inunits=true;
135  Mchecklist.units=true;
136  if (debug)
137  { cout << "found units tag " << theline.thetag() << endl; }
138  }
139  else if (theline.thetag() == datrw::tsoft::tagfileid)
140  {
141  Mchecklist.fileid=true;
142  DATRW_assert(theline.hascontent(),
143  "missing content in tagged line");
144  DATRW_assert(theline.thecontent() == datrw::tsoft::TSOFTID,
145  "file ID is not TSOFT or not supported");
146  if (debug)
147  { cout << "found fileid tag " << theline.thetag() << endl; }
148  }
149  else if (theline.thetag() == datrw::tsoft::tagtimeformat)
150  {
151  Mchecklist.timeformat=true;
152  DATRW_assert(theline.hascontent(),
153  "missing content in tagged line");
154  DATRW_assert(theline.thecontent() == "DATETIME",
155  "time format is not supported");
156  if (debug)
157  { cout << "found timeformat tag " << theline.thetag() << endl; }
158  }
159  else if (theline.thetag() == datrw::tsoft::tagundetval)
160  {
161  Mchecklist.undetval=true;
162  DATRW_assert(theline.hascontent(),
163  "missing content in tagged line");
164  std::istringstream iss(theline.thecontent());
165  iss >> Mundetval;
166  if (debug)
167  { cout << "found undetval tag " << theline.thetag() << endl; }
168  }
169  else if (theline.thetag() == datrw::tsoft::tagincrement)
170  {
171  Mchecklist.increment=true;
172  DATRW_assert(theline.hascontent(),
173  "missing content in tagged line");
174  // interval is provided in seconds
175  std::istringstream iss(theline.thecontent());
176  double dt;
177  iss >> dt;
178  Mincrement=libtime::double2time(dt);
179  if (debug)
180  { cout << "found increment tag " << theline.thetag() << endl; }
181  }
182  }
183  else if (indata && (linelength>0))
184  {
185  if (debug)
186  cout << "go for data line #" << count+1 << endl;
188  debug);
189  ++count;
190  }
191  else if (inchannels)
192  {
193  if (debug)
194  cout << "go for info for channel #" << count+1 << endl;
195  Channelinfo& ci=Mdatacontainer[count].chinfo();
196  if (debug)
197  {
198  cout << "have access to channelinfo for channel " << count+1 << endl;
199  cout.flush();
200  }
201  ci.setchannelinfo(inputline);
202  ++count;
203  if (debug)
204  cout << "read info for channel #" << count << endl;
205  }
206  else if (inunits)
207  {
208  Channelinfo& ci=Mdatacontainer[count].chinfo();
209  ci.setunits(inputline);
210  ++count;
211  if (debug)
212  cout << "read units for channel #" << count << endl;
213  }
214  // read next line
215  inputline=getDOSline(is);
216  if (debug) { std::cout << "<" << inputline << ">" << endl; }
217  } // while (is.good())
218  // file is read
220  // check if input is complete
221  if (!Mchecklist.allchecked())
222  {
223  std::cerr << "mandatory fields in input file are missing!"
224  << std::endl;
225  Mchecklist.report(std::cerr);
226  }
228  "mandatory fields are missed");
229  } // void TSOFTfile::read(std::istream& is)
bool allchecked() const
check whether all are checked
Definition: tsoftreader.cc:87
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
libtime::TRelativeTime Mincrement
sampling interval
Definition: tsoftreader.h:119
const char * tagdata
TSOFT data tag.
Definition: tsoftdata.cc:54
Checklist Mchecklist
my checklist
Definition: tsoftreader.h:123
Datacontainer Mdatacontainer
store channel info
Definition: tsoftreader.h:117
contains takes one line and splits it into tag and information.
Definition: tsoftdata.h:141
double Mundetval
store undetval
Definition: tsoftreader.h:121
libtime::TRelativeTime dt()
return sampling interval of HPMO data acquisition (i.e. 5 sec)
Definition: readhpmo.cc:83
const char * tagtimeformat
TSOFT timeformat tag.
Definition: tsoftdata.cc:58
const char * tagunits
TSOFT units tag.
Definition: tsoftdata.cc:56
Tlos Mfree
store header
Definition: tsoftreader.h:115
const char * tagincrement
TSOFT increment tag.
Definition: tsoftdata.cc:59
void report(std::ostream &os) const
report check status
Definition: tsoftreader.cc:63
const char * tagfileid
TSOFT fileid tag.
Definition: tsoftdata.cc:57
void push_data(const std::string &line, const double &undetval, const libtime::TRelativeTime &dt, const bool &debug=false)
push a data line
Definition: tsoftdata.cc:297
void flushchannels()
flush all channels
Definition: tsoftdata.cc:329
const char * tagchannels
TSOFT channels tag.
Definition: tsoftdata.cc:55
const char * TSOFTID
string constant to check TSOFT file id
Definition: tsoftreader.cc:51
std::string getDOSline(std::istream &is)
helper function getDOSline
Definition: tsoftdata.cc:423
const char * tagundetval
TSOFT undetval tag.
Definition: tsoftdata.cc:60
Here is the call graph for this function:
Here is the caller graph for this function: