Commit 2989f72e authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

use desired scale value if possible

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.

SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 3835
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 14aaa6d0
......@@ -43,11 +43,13 @@
* - check actual round-off error rather than scale
* and issue a warning in cases where round-off error
* exceed 0.1%
* - 29/03/2011 V1.2 - search for the smallest possible power larger or
* equal a desired value
*
* ============================================================================
*/
#define DATRW_SUCOMANAGER_CC_VERSION \
"DATRW_SUCOMANAGER_CC V1.0"
"DATRW_SUCOMANAGER_CC V1.2"
#define DATRW_SUCOMANAGER_CC_CVSID \
"$Id$"
......@@ -60,8 +62,14 @@ namespace datrw {
namespace su {
/*======================================================================*/
/*! some local helpers
*/
namespace helper {
/*! \brief output format modifier for debug output
*/
class MyOutputFormat {
public:
void set_output_format(std::ostream& os) const
......@@ -71,22 +79,31 @@ namespace datrw {
}
}; // class MyOutputFormat {
/*----------------------------------------------------------------------*/
/*! \brief output operator to apply output format modifier
*/
std::ostream& operator<<(std::ostream& os, const MyOutputFormat& f)
{
f.set_output_format(os);
return(os);
} // std::ostream& operator<<(std::ostream& os, const MyOutputFormat& f)
}; // namespace helper
/*======================================================================*/
// constants to support coordinate scaling
double ScalCoo::effectivezero=1.e-12;
int ScalCoo::maxnsigdigits=4;
/*----------------------------------------------------------------------*/
//! set from header fields
/*! set from header fields
*
* checked 29.3.2011
*/
void ScalCoo::set(const short& sin, const int& c)
{
/*
......@@ -118,7 +135,8 @@ namespace datrw {
* 10 to a power larger than 4 cannot be represented by a short int
*/
DATRW_assert((sabs<5),
"ERROR (ScalCoo::set): scale is too large");
"ERROR (ScalCoo::set): "
"scale value does not fit in short int field");
this->scale= s > 0 ? std::pow(10,sabs) : -std::pow(10,sabs);
}
else
......@@ -218,7 +236,10 @@ namespace datrw {
/*----------------------------------------------------------------------*/
//! return decimal power of scaling factor
/*! return decimal power of scaling factor
*
* tested 29.3.2011
*/
int ScalCoo::power() const
{
int sabs=this->scale > 0 ? this->scale : -this->scale;
......@@ -262,7 +283,14 @@ namespace datrw {
/*----------------------------------------------------------------------*/
//! adjust scale to optimal representation of significant digits
/*! \brief adjust scale to optimal representation of significant digits
*
* This function removes trailing zeroes from the ScalCoo::coo value, by
* chosing an appropriate scale value.
* Upon return from this function the scale power is as large as possible.
* Any increase in the power of the scale value will result in truncation
* of the coordinate value.
*/
void ScalCoo::adjustscale()
{
int p=this->power();
......@@ -282,6 +310,32 @@ namespace datrw {
DATRW_assert(this-scale != 0,
"ERROR (ScalCoo::scaletopower): illegal scale value!");
} // void ScalCoo::adjustscaling()
/*----------------------------------------------------------------------*/
/*! \brief return smallest power possible without truncation
*/
int ScalCoo::smallestpower(const int desired)
{
// limiting power values
int lp=desired >= -4 ? desired : -4;
lp = lp <= 4 ? lp : 4;
// initial power
int p=this->power();
// value and compare value
ScalCoo v1, v2;
v1.coo=this->coo;
v2.coo=std::floor(v1.coo*10)/10;
do {
if ((v1.coo==v2.coo) && (p>lp))
{
--p;
v1.coo *= 10;
v2.coo=std::floor(v1.coo*10)/10;
}
} while ((v1.coo==v2.coo) && (p>lp));
return(p);
} // int ScalCoo::smallestpower()
/*----------------------------------------------------------------------*/
......@@ -355,17 +409,27 @@ namespace datrw {
"scales on entry"
<< " gelev.scale " << this->gelev.scale
<< " sdepth.scale " << this->sdepth.scale);
/* is not required when search for the smallest possible power
this->sx.adjustscale();
this->sy.adjustscale();
this->gx.adjustscale();
this->gy.adjustscale();
int psx=this->sx.power();
int psy=this->sy.power();
int pgx=this->gx.power();
int pgy=this->gy.power();
int pnew = psx < psy ? psx : psy;
pnew = pnew < pgx ? pnew : pgx;
pnew = pnew < pgy ? pnew : pgy;
*/
// search for smallest possible power
int psx=this->sx.smallestpower();
int psy=this->sy.smallestpower();
int pgx=this->gx.smallestpower();
int pgy=this->gy.smallestpower();
int pnew = psx > psy ? psx : psy;
pnew = pnew > pgx ? pnew : pgx;
pnew = pnew > pgy ? pnew : pgy;
// check against largest possible power
/* is not necessary
pnew = pnew < sx.power() ? pnew : sx.power();
pnew = pnew < sy.power() ? pnew : sy.power();
pnew = pnew < gx.power() ? pnew : gx.power();
pnew = pnew < gy.power() ? pnew : gy.power();
*/
this->sx.scaletopower(pnew);
this->sy.scaletopower(pnew);
this->gx.scaletopower(pnew);
......@@ -375,15 +439,21 @@ namespace datrw {
(this->gx.scale==this->gy.scale)),
"ERROR: inconsistent coordinate scaling");
// adjust vertical coordinates
/* is not required when scaling with the smallest possible power
this->sdepth.adjustscale();
this->gelev.adjustscale();
DATRW_debug(debug, "Coordinates::equalizescaling",
"scales after adjust"
<< " gelev.scale " << this->gelev.scale
<< " sdepth.scale " << this->sdepth.scale);
int psdepth=this->sdepth.power();
int pgelev=this->gelev.power();
pnew = psdepth < pgelev ? psdepth : pgelev;
*/
int psdepth=this->sdepth.smallestpower();
int pgelev=this->gelev.smallestpower();
pnew = psdepth > pgelev ? psdepth : pgelev;
/* is not necessary
pnew = pnew < sdepth.power() ? pnew : sdepth.power();
pnew = pnew < gelev.power() ? pnew : gelev.power();
*/
this->sdepth.scaletopower(pnew);
this->gelev.scaletopower(pnew);
DATRW_assert((this->sdepth.scale==this->gelev.scale),
......
......@@ -48,14 +48,19 @@ namespace datrw {
namespace su {
//! scaled coordinate
/*! \brief scaled coordinate.
*
* This struct holds one coordinate together with a scale value.
* It provides functions to support appropriate scaling and to explore
* dynamic range.
*/
struct ScalCoo {
//! constructor
ScalCoo(const bool& debug=false)
: scale(1), coo(0), Mdebug(debug)
{ }
/*! lower limit of values
/*! \brief lower limit of values
*
* Coordinate values smaller than this will be regarded as zero.
* They cannot be represented, since the scaling limits the exponential
......@@ -66,7 +71,7 @@ namespace datrw {
*/
static double effectivezero;
/*! maximum number of significant digits to be used
/*! \brief maximum number of significant digits to be used
*
* Floating point number representation and conversion easily leads to
* cases where 0.01 becomes 0.00999999977648 which is not intended.
......@@ -82,6 +87,8 @@ namespace datrw {
int power() const;
//! scale to given scaling factor as defined by decimal power
void scaletopower(const int& p);
//! smallest possible power larger or equal desired
int smallestpower(const int desired=-2);
//! return coordinate value
double value() const;
//! adjust scale to optimal representation of significant digits
......@@ -97,7 +104,14 @@ namespace datrw {
/*----------------------------------------------------------------------*/
//! horizontal coordinates
/*! \brief full set of coordinates.
*
* This struct holds a full set of coordinates for a SEG-Y trace header.
* It provides functions to read the values from a given trace header and
* to set values in a trace header. Further it provides a function to
* chose equal scaling values for horizontal coordinates on one hand and
* vertical coordinates on the other hand.
*/
struct Coordinates {
//! constructor
Coordinates(const bool& debug=false)
......
......@@ -29,6 +29,7 @@
*
* REVISIONS and CHANGES
* - 19/11/2010 V1.0 Thomas Forbriger
* - 29/03/2011 V1.1 test of ScalCoo::power()
*
* ============================================================================
*/
......@@ -233,8 +234,26 @@ int main(int iargc, char* argv[])
<< "==========================\n\n";
cout << "Test module ::datrw::su::ScalCoo\n"
<< "--------------------------------\n" << endl;
cout << "coordinate value: " << opt.coordinate << endl;
cout << "check specific functions\n";
::datrw::su::ScalCoo co;
for (int i=-4; i<5; ++i)
{
if (i<0)
{
co.set(-std::pow(10, -i), 1);
}
else
{
co.set(std::pow(10, i), 1);
}
cout << "i: " << i << "; co.scale " << co.scale
<< "; co.coo " << co.coo
<< "; co.power() " << co.power()
<< endl;
}
cout << "check module\n";
cout << "coordinate value: " << opt.coordinate << endl;
co.set(opt.coordinate);
cout << "scale in ScalCoo: " << co.scale << endl;
cout << "coordinate in ScalCoo: " << co.coo << endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment