SFF++ library: reading and writing SFF from C++

◆ WIDXline() [1/2]

std::string sff::WIDXline ( const sff::WID2 wid2,
const bool &  debug 
)

write WID2 information in extended format

write WID information in extended format.

This function breaks the SFF format definition. It writes the WID2 class data to a line with identifier WIDX rather than WID2. The function is implemented within this library to provide transparent reading of WID-data. Writing will be used outside of the library only.

Reasons to implement this function are:

  1. The GSE WID2 format does not use microseconds for the time of the first sample. The information present in sff::WID2 however is precise to the level of microseconds and is also used in this way when processing e.g. MiniSEED data. It is thus desirable to read and write this information with the full available content.
  2. The GSE WID2 format restricts the sampling to be defined in terms of a sampling rate. This is inappropriate to extremely long period data with e.g. 1 Minute sampling interval (i.e. 60s). Round-off errors will lead to time residuals in these cases of more than a second within one day.
See also
WIDXline(const std::string& line)

Definition at line 115 of file widXio.cc.

References sff::WID2::auxid, sff::WID2::calib, sff::WID2::calper, sff::WID2::channel, sff::WID2::date, sff::WID2::dt, sff::WID2::hang, sff::WID2::instype, sff::WID2::nsamples, sff::helper::nsignificantdigits(), sff::WID2::station, sff::WID2::vang, and WIDXID.

Referenced by sff::WID2::read(), and test_extended_functions().

116  {
117  if (debug)
118  {
119  std::cerr << "DEBUG (WIDXline): entered function" <<
120  std::endl;
121  }
122  std::ostringstream os;
123  os << sff::WIDXID;
124  os << " " << wid2.date.hierarchicalstring();
125  os << " ";
126  os.width(5);
127  os.setf(std::ios_base::left, std::ios_base::adjustfield);
128  os << wid2.station.substr(0,5);
129  os << " ";
130  os.width(3);
131  os.setf(std::ios_base::left, std::ios_base::adjustfield);
132  os << wid2.channel.substr(0,3);
133  os << " ";
134  os.width(4);
135  os.setf(std::ios_base::left, std::ios_base::adjustfield);
136  os << wid2.auxid.substr(0,4);
137  os << " ";
138  os.width(6);
139  os.setf(std::ios_base::left, std::ios_base::adjustfield);
140  os << wid2.instype.substr(0,6);
141  os << " " << wid2.nsamples;
142  if (debug)
143  {
144  std::cerr << "DEBUG (WIDXline): partial result:" <<
145  os.str() << std::endl;
146  }
147  double rate=1./wid2.dt;
148  double value=wid2.dt;
149  if (sff::helper::nsignificantdigits(rate) < 4)
150  {
151  os << " r ";
152  value=rate;
153  }
154  else
155  {
156  os << " i ";
157  }
158  if (debug)
159  {
160  std::cerr << "DEBUG (WIDXline): partial result:" <<
161  os.str() << std::endl;
162  }
163  os.setf(std::ios_base::scientific, std::ios_base::floatfield);
164  int ndigits=sff::helper::nsignificantdigits(value, debug);
165  if (debug)
166  {
167  std::cerr << "DEBUG (WIDXline): ndigits:" <<
168  ndigits << std::endl;
169  }
170  os.precision(ndigits);
171  os.width(ndigits+6);
172  os << value;
173  os << " ";
174  os.precision(sff::helper::nsignificantdigits(wid2.calib, debug));
175  os << wid2.calib;
176  os << " ";
177  os.precision(sff::helper::nsignificantdigits(wid2.calper, debug));
178  os << wid2.calper;
179  os << " ";
180  os.precision(sff::helper::nsignificantdigits(wid2.hang, debug));
181  os << wid2.hang;
182  os << " ";
183  os.precision(sff::helper::nsignificantdigits(wid2.vang, debug));
184  os << wid2.vang;
185  if (debug)
186  {
187  std::cerr << "DEBUG (WIDXline): final result:" <<
188  os.str() << std::endl;
189  }
190  return(os.str());
191  } // std::string WIDXline(const sff::WID2& wid2)
std::string auxid
Auxiliary identification code.
Definition: sffxx.h:218
double calper
calibration reference period
Definition: sffxx.h:222
std::string station
Station code.
Definition: sffxx.h:216
std::string instype
instrument type
Definition: sffxx.h:223
std::string channel
FDSN channel code.
Definition: sffxx.h:217
int nsamples
number of samples
Definition: sffxx.h:219
libtime::TAbsoluteTime date
time of first sample
Definition: sffxx.h:215
double calib
calibration factor
Definition: sffxx.h:221
const char *const WIDXID
ID for extended WID2 format.
Definition: sffxx.h:132
double vang
veritcal orientation
Definition: sffxx.h:225
int nsignificantdigits(double v, const bool &debug=false)
return number of significant digits
Definition: widXio.cc:49
double dt
sampling interval (sec)
Definition: sffxx.h:220
double hang
horizontal orientation
Definition: sffxx.h:224
Here is the call graph for this function:
Here is the caller graph for this function: