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

◆ smallestpower()

int datrw::su::ScalCoo::smallestpower ( const short &  desiredscale = datrw::su::subformat::def::scalco) const

smallest possible power larger or equal desired

return smallest power possible without truncation

Definition at line 298 of file sucomanager.cc.

References coo, power(), and datrw::su::scaletopower().

Referenced by datrw::su::Coordinates::equalizescaling(), and set().

299  {
300  // limiting power values
301  int desired=datrw::su::scaletopower(desiredscale);
302  int lp=desired >= -4 ? desired : -4;
303  lp = lp <= 4 ? lp : 4;
304  // initial power
305  int p=this->power();
306  /*
307  * code modification; 24.1.2012
308  * tests were previously done detecting overflow
309  *
310  // value and compare value
311  ScalCoo v1(Mcontrol), v2(Mcontrol);
312  v1.coo=this->coo;
313  v2.coo=std::floor(v1.coo*10)/10;
314  do {
315  if ((v1.coo==v2.coo) && (p>lp))
316  {
317  --p;
318  v1.coo *= 10;
319  v2.coo=std::floor(v1.coo*10)/10;
320  }
321  } while ((v1.coo==v2.coo) && (p>lp));
322  *
323  * I prefer to use numerical comparison
324  * increasing the scale power will decrease the coo value and vice versa;
325  * start with the optimal power as being found in this->scale
326  * decrease the power until
327  * either a further decrease would result in coo not fitting into a
328  * variable of type short
329  * or the desired scale (scale power) value is obtained
330  */
331  int c1=this->coo;
332  int c2;
333  bool hot=true;
334  do {
335  if (hot && (p>lp))
336  {
337  --p;
338  c1 *= 10;
339  }
340  c2=c1*10;
341  hot = ((c2 <= SHRT_MAX) && (c2 >= SHRT_MIN));
342  } while (hot && (p>lp));
343  return(p);
344  } // int ScalCoo::smallestpower()
int scaletopower(short s, const bool &strict)
convert a SeismicUn*x scale value to a decimal power
Definition: sucomanager.cc:485
int coo
coordinate
Definition: sucomanager.h:171
int power() const
return decimal power of scaling factor
Definition: sucomanager.cc:230
Here is the call graph for this function:
Here is the caller graph for this function: