66 #define DATRW_SUCOMANAGER_CC_VERSION \ 67 "DATRW_SUCOMANAGER_CC V1.7" 71 #include <datrwxx/suformat.h> 72 #include <datrwxx/sucomanager.h> 143 const bool debug=
false;
145 this->
coo=
static_cast<int>(nearbyint(
value));
154 DATRW_debug(debug,
"ScalCoo::set(const double& v)",
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)));
161 int nzero=ntrail-nsig;
162 DATRW_debug(debug,
"ScalCoo::set(const double& v)",
163 "nlead: " << nlead <<
164 " ntrail: " << ntrail <<
169 DATRW_debug(debug,
"ScalCoo::set(const double& v)",
170 "nlead: " << nlead <<
171 " ntrail: " << ntrail <<
175 DATRW_debug(debug,
"ScalCoo::set(const double& value)",
177 int s=std::pow(10,ntrail);
178 s = s > 10000 ? 10000 : s;
180 "ERROR (ScalCoo::set): scale too large");
182 this->
coo=
static_cast<int>(nearbyint(
value*s));
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)",
189 <<
" truevalue: " << truevalue
190 <<
" roundedvalue: " << roundedvalue
191 <<
" truncationerror: " << truncationerror);
193 "WARNING (ScalCoo::set) " 194 "truncation error > 0.1%\n" 197 <<
" will be truncated!" 199 <<
" scaled value: " << truevalue
200 <<
" rounded scaled value: " 205 DATRW_debug(debug,
"ScalCoo::set(const double& value)",
207 int s=std::pow(10,nlead-nsig);
208 s = s > 10000 ? 10000 : s;
210 "ERROR (ScalCoo::set): scale too large");
212 this->
coo=
static_cast<int>(nearbyint(
value/s));
217 DATRW_debug(debug,
"ScalCoo::set(const double& value)",
219 <<
" value: " <<
value 220 <<
" this->coo: " << this->
coo 221 <<
" this->scale: " << this->
scale);
240 int pd=this->
power()-p;
244 int fac=std::pow(10,-pd);
245 vnew=
static_cast<int>(std::floor(this->
coo/fac));
246 vcmp=
static_cast<int>(std::floor(vnew*fac));
250 int fac=std::pow(10,pd);
251 vnew=std::floor(this->
coo*fac);
252 vcmp=
static_cast<int>(std::floor(vnew/fac));
255 "WARNING ScalCoo::scaletopower will truncate " 259 " value will be " << vcmp);
263 "ERROR (ScalCoo::scaletopower): illegal scale value!");
282 v2=std::floor(v1/10)*10;
283 if ((v1==v2) && (p<4))
288 }
while ((v1==v2) && (p<4));
291 "ERROR (ScalCoo::scaletopower): illegal scale value!");
302 int lp=desired >= -4 ? desired : -4;
303 lp = lp <= 4 ? lp : 4;
341 hot = ((c2 <= SHRT_MAX) && (c2 >= SHRT_MIN));
342 }
while (hot && (p>lp));
351 double c=
static_cast<double>(this->
coo);
364 "values in header on entry:" 365 <<
" scalco: " << h.
scalco 366 <<
" scalel: " << h.
scalel 371 <<
" sdepth: " << h.
sdepth 372 <<
" gelev: " << h.
gelev);
397 "values in header on finish:" 398 <<
" scalco: " << h.
scalco 399 <<
" scalel: " << h.
scalel 404 <<
" sdepth: " << h.
sdepth 405 <<
" gelev: " << h.
gelev);
418 <<
" sdepth.scale " << this->sdepth.scale);
430 int pnew = psx > psy ? psx : psy;
431 pnew = pnew > pgx ? pnew : pgx;
432 pnew = pnew > pgy ? pnew : pgy;
445 (this->sy.scale==this->gx.scale) &&
446 (this->gx.scale==this->gy.scale)),
447 "ERROR: inconsistent coordinate scaling");
459 pnew = psdepth > pgelev ? psdepth : pgelev;
467 "ERROR: inconsistent coordinate scaling");
476 int pp = p < 0 ? -p : p;
477 short s=
static_cast<short>(std::pow(10,pp));
488 int sabs=s > 0 ? s : -s;
489 int retval=std::log10(sabs);
490 if (s < 0) { retval *= -1; }
506 "WARNING (ScalCoo::set): incorrect scale\n" 507 "The value for the scalco and scalel field\n" 508 "violates the SEG-Y trace header definition.\n" 509 "value: " << s <<
"; will be set to 1");
511 "Violation of SeismicUn*x format definition!");
514 int sabs=s > 0 ? s : -s;
515 if ((sabs < 10) && (s != 1))
526 "WARNING (ScalCoo::set): non-standard scale\n" 527 "The value for the scalco and scalel field\n" 528 "violates the SEG-Y trace header definition.\n" 531 "Violation of SeismicUn*x format definition!");
536 "ERROR (ScalCoo::set): " 537 "scale value does not fit in short int field");
538 s= s > 0 ? std::pow(10,sabs) : -std::pow(10,sabs);
549 double sv=
static_cast<double>(s);
550 return(s>0 ? sv : -1./sv);
datrw::su::options::SpatialSampling Mcontrol
control parameters
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
int scaletopower(short s, const bool &strict)
convert a SeismicUn*x scale value to a decimal power
void adjustscale()
adjust scale to optimal representation of significant digits
macro function for debugging output (prototypes)
ScalCoo gy
receiver y coordinate
unsigned int coodigits
maximum number of significant digits to be used
bool bestrict
if true: strictly use header definition by SeismicUnix source
ScalCoo sx
source x coordinate
short scale
scale like scalco
short scalco
preferred scalco value
exception class declaration for libdatrwxx (prototypes)
ScalCoo gx
receiver x coordinate
Root namespace of library.
ScalCoo gelev
source y coordinate
static double effectivezero
lower limit of values
utilities used by more than one type of data reader (prototypes)
ScalCoo sdepth
source z coordinate
datrw::su::options::SpatialSampling Mcontrol
control parameters
int ntrailingdigits(double v, const bool &debug)
return number of trailing digits (after decimal point)
int nsignificantdigits(double v, const bool &debug)
return number of significant digits
int smallestpower(const short &desiredscale=datrw::su::subformat::def::scalco) const
smallest possible power larger or equal desired
void equalizescaling()
equalize scaling
#define DATRW_debug(C, N, M)
produce debug output
short powertoscale(const int &p)
convert a decimal power to a SeismicUn*x scale value
void scaletopower(const int &p)
scale to given scaling factor as defined by decimal power
ScalCoo sy
source y coordinate
std::ostream & operator<<(std::ostream &os, const MyOutputFormat &f)
output operator to apply output format modifier
void set(const short &s, const int &c)
set from header fields
double value() const
return coordinate value
int power() const
return decimal power of scaling factor
#define DATRW_report_assert(C, M)
Check an assertion and report only.
void fixscalevalue(short &s, const bool &strict)
fix a SeismicUn*x scale value
void setvaluesin(TraceHeaderStruct &h)
set values in SU header
void getvaluesfrom(const TraceHeaderStruct &h)
read values from SU header
double scalefactor(short s, const bool &strict)
convert scale value to a factor to be applied