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

◆ set() [2/2]

void datrw::su::ScalCoo::set ( const double &  value)

set from coordinate value in meters

set from coordinate value in meters

this functions takes the coordinate value as a floating point value in meters; it has to find the appropriate scaling to represent this value with appropriate precision in an integer variable

Definition at line 141 of file sucomanager.cc.

References coo, datrw::su::options::SpatialSampling::coodigits, DATRW_assert, DATRW_debug, DATRW_report_assert, effectivezero, Mcontrol, datrw::util::nsignificantdigits(), datrw::util::ntrailingdigits(), datrw::su::options::SpatialSampling::scalco, scale, scaletopower(), smallestpower(), and value().

142  {
143  const bool debug=false;
144  this->scale=1;
145  this->coo=static_cast<int>(nearbyint(value));
146  double v=(value>=0 ? value : -value);
148  {
149  this->scale=1;
150  this->coo=0;
151  }
152  else
153  {
154  DATRW_debug(debug, "ScalCoo::set(const double& v)",
155  "v: " << helper::MyOutputFormat() << v << "\n"
156  "log10(v): " << std::log10(v) << "\n"
157  "floor(log10(v)): " << std::floor(std::log10(v)));
158  int nlead=1+static_cast<int>(std::floor(std::log10(v)));
159  int ntrail=::datrw::util::ntrailingdigits(v);
160  int nsig=::datrw::util::nsignificantdigits(v, debug);
161  int nzero=ntrail-nsig;
162  DATRW_debug(debug, "ScalCoo::set(const double& v)",
163  "nlead: " << nlead <<
164  " ntrail: " << ntrail <<
165  " nsig: " << nsig);
166  nsig = nsig>static_cast<int>(Mcontrol.coodigits)
167  ? Mcontrol.coodigits : nsig;
168  ntrail=nsig+nzero;
169  DATRW_debug(debug, "ScalCoo::set(const double& v)",
170  "nlead: " << nlead <<
171  " ntrail: " << ntrail <<
172  " nsig: " << nsig);
173  if (ntrail>0)
174  {
175  DATRW_debug(debug, "ScalCoo::set(const double& value)",
176  "ntrail>0");
177  int s=std::pow(10,ntrail);
178  s = s > 10000 ? 10000 : s;
179  DATRW_assert(s<100000,
180  "ERROR (ScalCoo::set): scale too large");
181  this->scale=-s;
182  this->coo=static_cast<int>(nearbyint(value*s));
183  // check truncation error
184  double truevalue=value*s;
185  double roundedvalue=nearbyint(truevalue);
186  double truncationerror=fabs(1.-(truevalue/roundedvalue));
187  DATRW_debug(debug, "ScalCoo::set(const double& value)",
188  "truncation error:"
189  << " truevalue: " << truevalue
190  << " roundedvalue: " << roundedvalue
191  << " truncationerror: " << truncationerror);
192  DATRW_report_assert(truncationerror<0.001,
193  "WARNING (ScalCoo::set) "
194  "truncation error > 0.1%\n"
195  "coordinate value "
196  << helper::MyOutputFormat() << value
197  << " will be truncated!"
198  << "\n*"
199  << " scaled value: " << truevalue
200  << " rounded scaled value: "
201  << roundedvalue);
202  }
203  else if (nlead>nsig)
204  {
205  DATRW_debug(debug, "ScalCoo::set(const double& value)",
206  "nlead>nsig");
207  int s=std::pow(10,nlead-nsig);
208  s = s > 10000 ? 10000 : s;
209  DATRW_assert(s<100000,
210  "ERROR (ScalCoo::set): scale too large");
211  this->scale=s;
212  this->coo=static_cast<int>(nearbyint(value/s));
213  }
214  } // if (v<ScalCoo::effectivezero), else clause
215  // adjust scale
217  DATRW_debug(debug, "ScalCoo::set(const double& value)",
218  "value on exit:"
219  << " value: " << value
220  << " this->coo: " << this->coo
221  << " this->scale: " << this->scale);
222  } // void ScalCoo::set(const double& v)
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
unsigned int coodigits
maximum number of significant digits to be used
Definition: suformat.h:129
int coo
coordinate
Definition: sucomanager.h:171
short scale
scale like scalco
Definition: sucomanager.h:169
short scalco
preferred scalco value
Definition: suformat.h:131
static double effectivezero
lower limit of values
Definition: sucomanager.h:142
datrw::su::options::SpatialSampling Mcontrol
control parameters
Definition: sucomanager.h:173
int ntrailingdigits(double v, const bool &debug)
return number of trailing digits (after decimal point)
Definition: util.cc:97
int nsignificantdigits(double v, const bool &debug)
return number of significant digits
Definition: util.cc:49
int smallestpower(const short &desiredscale=datrw::su::subformat::def::scalco) const
smallest possible power larger or equal desired
Definition: sucomanager.cc:298
#define DATRW_debug(C, N, M)
produce debug output
Definition: debug.h:50
void scaletopower(const int &p)
scale to given scaling factor as defined by decimal power
Definition: sucomanager.cc:238
double value() const
return coordinate value
Definition: sucomanager.cc:349
#define DATRW_report_assert(C, M)
Check an assertion and report only.
Definition: error.h:120
Here is the call graph for this function: