1.4.0
CCC
 
Utilities.cpp File Reference
#include "Enum/EDbg.hpp"
#include "Basic/Utilities.hpp"
#include "Basic/VectorHelper.hpp"
#include "Basic/Law.hpp"
#include "Basic/Memory.hpp"
#include <cmath>
#include <map>

Macros

#define LSTACK   1000
 
#define MINI   10
 

Functions

bool isInteger (double value, double eps)
 
int getClosestInteger (double value)
 
bool isMultiple (int nbig, int nsmall)
 
bool isOdd (int number)
 
bool isEven (int number)
 
bool isZero (double value, double eps)
 
bool areEqual (double v1, double v2, double eps)
 
bool isOne (double value, double eps)
 
double getMin (double val1, double val2)
 
double getMax (double val1, double val2)
 
double getTEST ()
 
int getITEST ()
 
bool FFFF (double value)
 
bool IFFFF (int value)
 
double ut_deg2rad (double angle)
 
double ut_rad2deg (double angle)
 
void ut_sort_double (int safe, int nech, int *ind, double *value)
 
StatResults ut_statistics (int nech, const double *tab, const double *sel, const double *wgt)
 
void ut_stats_mima_print (const char *title, int nech, double *tab, double *sel)
 
void ut_facies_statistics (int nech, double *tab, double *sel, int *nval, int *mini, int *maxi)
 
void ut_classify (int nech, const double *tab, double *sel, int nclass, double start, double pas, int *nmask, int *ntest, int *nout, int *classe)
 
double ut_median (double *tab, int ntab)
 
double ut_cnp (int n, int k)
 
MatrixSquareGeneral ut_pascal (int ndim)
 
static void st_combinations (int *v, int start, int n, int k, int maxk, int *ncomb, int **comb)
 
int * ut_combinations (int n, int maxk, int *ncomb)
 
void ut_shuffle_array (int nrow, int ncol, double *tab)
 
VectorInt getListActiveToAbsolute (const VectorDouble &sel)
 
std::map< int, int > getMapAbsoluteToRelative (const VectorDouble &sel, bool verbose)
 
int getRankMapAbsoluteToRelative (const std::map< int, int > &map, int iabs)
 
int getRankMapRelativeToAbsolute (const std::map< int, int > &map, int irel)
 
operate_function operate_Identify (int oper)
 
double operate_Identity (double x)
 
double operate_Inverse (double x)
 
double operate_Square (double x)
 
double operate_InverseSquare (double x)
 
double operate_Sqrt (double x)
 
double operate_InverseSqrt (double x)
 
double modifyOperator (const EOperator &oper, double oldval, double value)
 
double roundZero (double value, double eps)
 
double truncateDecimals (double value, int ndec)
 
double truncateDigits (double value, int ndigits)
 
void setInternalDebug (bool status)
 
bool isInternalDebug ()
 
void print_range (const char *title, int ntab, const double *tab, const double *sel)
 

Variables

static EDbg _debugOptions = EDbg::DB
 
static bool _internalDebug = false
 

Macro Definition Documentation

◆ LSTACK

#define LSTACK   1000

◆ MINI

#define MINI   10

Function Documentation

◆ areEqual()

bool areEqual ( double  v1,
double  v2,
double  eps 
)

◆ FFFF()

bool FFFF ( double  value)

Checks if a double value is TEST

Returns
true if a TEST value is encountered; 0 otherwise
Parameters
[in]valueValue to be tested

◆ getClosestInteger()

int getClosestInteger ( double  value)

◆ getITEST()

int getITEST ( )

◆ getListActiveToAbsolute()

VectorInt getListActiveToAbsolute ( const VectorDouble sel)

Returns the list of absolute indices for the only active samples A sample is active if its 'sel' value is equal to 1

Parameters
selVector giving the status of all samples (Dimension: absolute)
Returns

◆ getMapAbsoluteToRelative()

std::map<int, int> getMapAbsoluteToRelative ( const VectorDouble sel,
bool  verbose 
)

Returns the map such that MAP[iabs] = iact. A sample is active if its 'sel' value is equal to 1

Parameters
selVector giving the status of all samples (Dimension: absolute)
verboseVerbose flag
Returns
The map (dimension: nrel)

◆ getMax()

double getMax ( double  val1,
double  val2 
)

◆ getMin()

double getMin ( double  val1,
double  val2 
)

◆ getRankMapAbsoluteToRelative()

int getRankMapAbsoluteToRelative ( const std::map< int, int > &  map,
int  iabs 
)

Returns the rank of the relative grid node from its absolute index using the Map

Parameters
mapThe <int,int> map
iabsAbsolute rank of the grid node
Returns
Rank of the corresponding active (relative) grid node (or -1 is not found)

◆ getRankMapRelativeToAbsolute()

int getRankMapRelativeToAbsolute ( const std::map< int, int > &  map,
int  irel 
)

◆ getTEST()

double getTEST ( )

◆ IFFFF()

bool IFFFF ( int  value)

Checks if an integer value is TEST

Returns
true if a ITEST value is encountered; 0 otherwise
Parameters
[in]valueValue to be tested

◆ isEven()

bool isEven ( int  number)

◆ isInteger()

bool isInteger ( double  value,
double  eps 
)

◆ isInternalDebug()

bool isInternalDebug ( )

◆ isMultiple()

bool isMultiple ( int  nbig,
int  nsmall 
)

◆ isOdd()

bool isOdd ( int  number)

◆ isOne()

bool isOne ( double  value,
double  eps 
)

◆ isZero()

bool isZero ( double  value,
double  eps 
)

◆ modifyOperator()

double modifyOperator ( const EOperator &  oper,
double  oldval,
double  value 
)

Update an Old by a New value according to 'oper'

Parameters
operA keywork of EOperator enum
oldvalOld value
valueNew value

◆ operate_Identify()

operate_function operate_Identify ( int  oper)

Identify the pointer to a function with following functionality: y = f(x)

Parameters
operGives the type of operation to be performed 1: returns the value itslef (no change) -1: returns its inverse 2: returns the squared value -2: returns the inverse of the squared value 3: returns its square root -3: returns the inverse of the square root
Returns
Pointer to the specified function

◆ operate_Identity()

double operate_Identity ( double  x)

◆ operate_Inverse()

double operate_Inverse ( double  x)

◆ operate_InverseSqrt()

double operate_InverseSqrt ( double  x)

◆ operate_InverseSquare()

double operate_InverseSquare ( double  x)

◆ operate_Sqrt()

double operate_Sqrt ( double  x)

◆ operate_Square()

double operate_Square ( double  x)

◆ print_range()

void print_range ( const char *  title,
int  ntab,
const double *  tab,
const double *  sel 
)

Print the range of values in an array

Parameters
[in]titleoptional title (NULL if not defined)
[in]ntabnumber of values
[in]tabarray of values
[in]sel(optional) selection

◆ roundZero()

double roundZero ( double  value,
double  eps 
)

Round off the value if close enough to zero. This ensures that the printout of a very small value does not come out with a non-significant negative sign This trick should only serve to make printouts similar on different platforms.

Parameters
valueInput value
epsTolerance to check that the value is considered as small
Returns
The value itself or a very small positive value if the input value is too small.

◆ setInternalDebug()

void setInternalDebug ( bool  status)

◆ st_combinations()

static void st_combinations ( int *  v,
int  start,
int  n,
int  k,
int  maxk,
int *  ncomb,
int **  comb 
)
static

Return all the combinations of k within n (local recursive routine)

Parameters
[in]vArray of indices to be sorted
[in]startRank of the starting index
[in]nTotal number of objects (>= 1)
[in]kStarting sorting index
[in]maxkSelected number of objects (>= 1)
[in,out]ncombCurrent number of combinations
[in,out]combCurrent array of combinations

◆ truncateDecimals()

double truncateDecimals ( double  value,
int  ndec 
)

Rounding a double to a given number of decimals (from: https://stackoverflow.com/questions/304011/truncate-a-decimal-value-in-c/304013#304013)

Parameters
valueValue to be rounded up
ndecNumber of significant decimals

◆ truncateDigits()

double truncateDigits ( double  value,
int  ndigits 
)

Rounding a double to a given number of decimals

Parameters
valueValue to be rounded up
ndigitsNumber of significant digits

◆ ut_classify()

void ut_classify ( int  nech,
const double *  tab,
double *  sel,
int  nclass,
double  start,
double  pas,
int *  nmask,
int *  ntest,
int *  nout,
int *  classe 
)

Classify the samples into integer sieves

Parameters
[in]nechNumber of samples
[in]tabArray of values
[in]selArray containing the Selection or NULL
[in]nclassNumber of sieve classes
[in]startStarting sieve value
[in]pasWidth of the sieve
[out]nmaskNumber of masked values
[out]ntestNumber of undefined values
[out]noutNumber of values outside the classes
[out]classeArray for number of samples per sieve

◆ ut_cnp()

double ut_cnp ( int  n,
int  k 
)

Compute combinations(n,k)

Returns
Return the number of combinations of 'k' objects amongst 'n'
Parameters
[in]nTotal number of objects (>= 1)
[in]kSelected number of objects (>= 1)

◆ ut_combinations()

int* ut_combinations ( int  n,
int  maxk,
int *  ncomb 
)

Return all the combinations of k within n

Returns
Return all the combinations of 'k' objects amongst 'n'
Parameters
[in]nTotal number of objects (>1)
[in]maxkSelected number of objects (1<=maxk<n)
[out]ncombNumber of combinations
Remarks
The calling function must free the returned array.

◆ ut_deg2rad()

double ut_deg2rad ( double  angle)

Translates from degree to radian

Parameters
[in]angleAngle in degrees

◆ ut_facies_statistics()

void ut_facies_statistics ( int  nech,
double *  tab,
double *  sel,
int *  nval,
int *  mini,
int *  maxi 
)

Returns the statistics of an array containing the facies

Parameters
[in]nechNumber of samples
[in]tabArray of values
[in]selArray containing the Selection or NULL
[out]nvalNumber of active values
[out]miniMinimum value
[out]maxiMaximum value

◆ ut_median()

double ut_median ( double *  tab,
int  ntab 
)

Calculate the median from a table of values

Returns
The median value
Parameters
[in]tabArray of values
[in]ntabNumber of samples

◆ ut_pascal()

MatrixSquareGeneral ut_pascal ( int  ndim)

Create the matrix containing the Pascal Triangle coefficients

Returns
A matrix (Dimension: ndim * ndim) containing the coefficients
or NULL if core allocation problem has been encountered
Parameters
[in]ndimSize of the matrix
Remarks
The calling function must free the returned matrix

◆ ut_rad2deg()

double ut_rad2deg ( double  angle)

Translates from radian to degree

Parameters
[in]angleAngle in radian

◆ ut_shuffle_array()

void ut_shuffle_array ( int  nrow,
int  ncol,
double *  tab 
)

Shuffle an array (by line)

Parameters
[in]nrowNumber of rows
[in]ncolNumber of columns
[in,out]tabArray to be suffled

◆ ut_sort_double()

void ut_sort_double ( int  safe,
int  nech,
int *  ind,
double *  value 
)

Sorts the (double) array value() and the array ind() in the ascending order of value

Parameters
[in]safe1 if the value array if preserved 0 if the value array is also sorted
[in]nechnumber of samples
[out]indoutput int array
[out]valueinput and output array
Remarks
If ind = NULL, ind is ignored

◆ ut_statistics()

StatResults ut_statistics ( int  nech,
const double *  tab,
const double *  sel,
const double *  wgt 
)

Returns the statistics of an array in a StatResults structure

Parameters
[in]nechNumber of samples
[in]tabArray of values
[in]selArray containing the Selection or NULL
[in]wgtArray containing the Weights or NULL

◆ ut_stats_mima_print()

void ut_stats_mima_print ( const char *  title,
int  nech,
double *  tab,
double *  sel 
)

Print minimum and maximum of an array

Parameters
[in]titleTitle
[in]nechNumber of samples
[in]tabArray of values
[in]selArray containing the Selection or NULL

Variable Documentation

◆ _debugOptions

EDbg _debugOptions = EDbg::DB
static

◆ _internalDebug

bool _internalDebug = false
static