1.4.0
CCC
 
db.cpp File Reference
#include "geoslib_old_f.h"
#include "Polygon/Polygons.hpp"
#include "Basic/Utilities.hpp"
#include "Basic/Grid.hpp"
#include "Db/Db.hpp"
#include "Db/DbGrid.hpp"
#include "Basic/Memory.hpp"
#include <math.h>

Functions

int compat_NDIM (Db *db1, Db *db2)
 
void db_grid_print (Db *db)
 
int get_LOCATOR_NITEM (const Db *db, const ELoc &locatorType)
 
double distance_inter (const Db *db1, const Db *db2, int iech1, int iech2, double *dist_vect)
 
double distance_intra (const Db *db, int iech1, int iech2, double *dist_vect)
 
double distance_grid (DbGrid *db, int flag_moins1, int iech1, int iech2, double *dist_vect)
 
void db_sample_print (Db *db, int iech, int flag_ndim, int flag_nvar, int flag_nerr)
 
int db_center (Db *db, double *center)
 
int db_grid_define_coordinates (DbGrid *db)
 
int db_gradient_update (Db *db)
 
int db_selref (int ndim, const int *nx, const int *ref, const double *tabin, double *tabout)
 
int db_locator_attribute_add (Db *db, const ELoc &locatorType, int number, int r_tem, double valinit, int *iptr)
 
int db_grid_copy (DbGrid *db1, DbGrid *db2, const int *ind1, const int *ind2, int ncol, int *cols)
 
int db_grid_copy_dilate (DbGrid *db1, int iatt1, DbGrid *db2, int iatt2, int mode, const int *nshift)
 
int point_to_point (Db *db, const double *coor)
 
int point_to_grid (const DbGrid *db, const double *coor, int flag_outside, int *indg)
 
int point_to_bench (const DbGrid *db, double *coor, int flag_outside, int *indb)
 
int index_point_to_grid (const Db *dbin, int iech, int flag_outside, const DbGrid *dbout, double *coor)
 
int point_inside_grid (Db *db, int iech, const DbGrid *dbgrid)
 
void db_monostat (Db *db, int iatt, double *wtot, double *mean, double *var, double *mini, double *maxi)
 
int db_proportion (Db *db, DbGrid *dbgrid, int nfac1max, int nfac2max, int *nclout)
 
int db_merge (Db *db, int ncol, int *cols)
 
void db_locators_correct (VectorString &strings, const VectorInt &current, int flag_locnew)
 
int db_prop_read (DbGrid *db, int ix, int iy, double *props)
 
int db_prop_write (DbGrid *db, int ix, int iy, double *props)
 
double * db_distances_general (Db *db1, Db *db2, int niso, int mode, int flag_same, int *n1, int *n2, double *dmin, double *dmax)
 
int is_grid_multiple (DbGrid *db1, DbGrid *db2)
 
int db_gradient_modang_to_component (Db *db, int ang_conv, int iad_mod, int iad_ang, int iad_gx, int iad_gy)
 
int db_gradient_component_to_modang (Db *db, int verbose, int iad_gx, int iad_gy, int iad_mod, int iad_ang, double scale, double ve)
 
double get_grid_value (DbGrid *dbgrid, int iptr, VectorInt &indg, int ix, int iy, int iz)
 
void set_grid_value (DbGrid *dbgrid, int iptr, VectorInt &indg, int ix, int iy, int iz, double value)
 
DbGriddb_grid_reduce (DbGrid *db_grid, int iptr, const int *margin, const int *limmin, int flag_sel, int flag_copy, int verbose, double vmin, double vmax)
 
int db_grid_patch (DbGrid *ss_grid, DbGrid *db_grid, int iptr_ss, int iptr_db, int iptr_rank, int new_rank, int oper, int verbose)
 
int db_name_identify (Db *db, const String &string)
 
static void st_rotate (int ndim, double *rotmat, VectorDouble &coor, VectorDouble &mini, VectorDouble &maxi)
 
void db_extension_rotated (Db *db, double *rotmat, VectorDouble &mini, VectorDouble &maxi)
 
void grid_iterator_init (Grid *grid, const VectorInt &order)
 
VectorInt grid_iterator_next (Grid *grid)
 

Function Documentation

◆ compat_NDIM()

int compat_NDIM ( Db db1,
Db db2 
)

Checks if Space Dimension of the first Db is at least equal to the Space dimension of the second Db

Returns
Error return code (1 for correct and 0 otherwise).
If an error is found, a message is issued
Parameters
[in]db1first Db descriptor (usually dbin)
[in]db2second Db descriptor (usually dbout)
Remarks
This function checks that the we can perform an operation
(i.e. migration) of a 2D data set onto a 3D one.
The opposite is not correct.

◆ db_center()

int db_center ( Db db,
double *  center 
)

Returns the center of a data set

Parameters
[in]dbDb structure
[out]centerArray containing the coordinates of the center (Dimension = get_NDIM(db))

◆ db_distances_general()

double* db_distances_general ( Db db1,
Db db2,
int  niso,
int  mode,
int  flag_same,
int *  n1,
int *  n2,
double *  dmin,
double *  dmax 
)

Evaluate the array of distances between samples of two data sets Takes the selection into account (if any)

Returns
Array of distances
Parameters
[in]db1Db first descriptor
[in]db2Db second descriptor
[in]nisoNumber of variables tested for isotopy
[in]modeType of array returned 0 : extreme distances 1 : the distance to the closest sample 2 : all point-to-point distances
[in]flag_same1 if both Db coincide
[out]n1First dimension of the returned array
[out]n2Second dimension of the returned array
[out]dminMinimum distance
[out]dmaxMaximum distance
Remarks
The returned array must be freed by calling routine
When the two Dbs coincide, the distance calculation excludes
the comparison between one sample and itself

◆ db_extension_rotated()

void db_extension_rotated ( Db db,
double *  rotmat,
VectorDouble mini,
VectorDouble maxi 
)

Returns the extension of the field (after rotation) along each axis

Parameters
[in]dbDb structure
[in]rotmatRotation matrix (optional)
[out]miniArray containing the minimum (Dimension = ndim)
[out]maxiArray containing the maximum (Dimension = ndim)
Remarks
This function does nothing if:
- no rotation matrix is defined
- space dimension is 1 or larger than 3

◆ db_gradient_component_to_modang()

int db_gradient_component_to_modang ( Db db,
int  verbose,
int  iad_gx,
int  iad_gy,
int  iad_mod,
int  iad_ang,
double  scale,
double  ve 
)

Transform a set of gradients defined by (gx,gy) into (module,angle) Only defined in the 2-D case

Returns
Error return code
Parameters
[in]dbInitial Db
[in]verbose1 for the verbose option
[in]iad_gxRank of the 'gx' attribute (defined in degrees)
[in]iad_gyRank of the 'gy' attribute (defined in degrees)
[in]iad_modRank of the 'modulus' attribute
[in]iad_angRank of the 'angle' attribute (defined in degrees)
[in]scaleScaling factor for the modulus
[in]veModeration factor
Remarks
Attributes 'gx' and 'gy' may coincide with 'modulus' and 'angle'
Nothing is done (more than the conversion if scale=1 and ve=0)

◆ db_gradient_modang_to_component()

int db_gradient_modang_to_component ( Db db,
int  ang_conv,
int  iad_mod,
int  iad_ang,
int  iad_gx,
int  iad_gy 
)

Transform a set of gradients defined by (modulus,angle) into (gx,gy) Only defined in the 2-D case

Returns
Error return code
Parameters
[in]dbInitial Db
[in]ang_convConvention on the angles
  • 1: Trigonometry (From East counter-clockwise)
  • 2: From North clockwise
[in]iad_modRank of the 'modulus' attribute
[in]iad_angRank of the 'angle' attribute (defined in degrees)
[in]iad_gxRank of the 'gx' attribute (defined in degrees)
[in]iad_gyRank of the 'gy' attribute (defined in degrees)
Remarks
Attributes 'gx' and 'gy' may coincide with 'modulus' and 'angle'

◆ db_gradient_update()

int db_gradient_update ( Db db)

Update the Data Base for Kriging with Gradient components This update is limited to the 2-D Monovariate case

Returns
Error return code
Parameters
[in]dbInput/output Db
Remarks
In the case of Kriging with Gradient, the gradient components
are transformed into additional variables

◆ db_grid_copy()

int db_grid_copy ( DbGrid db1,
DbGrid db2,
const int *  ind1,
const int *  ind2,
int  ncol,
int *  cols 
)

Copy a set of variables from a grid Db to another grid Db

Returns
Error return code
Parameters
[in]db1Input Grid Db structure
[in]db2Output Grid Db structure
[in]ind1Vector of indices in the first Db
[in]ind2Vector of indices in the second Db
[in]ncolNumber of variables to be copied
[in]colsArray of input variable columns

◆ db_grid_copy_dilate()

int db_grid_copy_dilate ( DbGrid db1,
int  iatt1,
DbGrid db2,
int  iatt2,
int  mode,
const int *  nshift 
)

Copy one variable from a grid Db to another grid Db

Returns
Error return code
Parameters
[in]db1Input Grid Db structure
[in]iatt1Rank of the attribute in Db1
[in]db2Output Grid Db structure
[in]iatt2Rank of the attribute in Db2
[in]mode1 for dilation; -1 for compression
[in]nshiftVector of dilation/compression defined in cell number along each space direction

◆ db_grid_define_coordinates()

int db_grid_define_coordinates ( DbGrid db)

Define the coordinates in a Grid structure

Returns
Error return code
Parameters
[in]dbThe Db structure
Remarks
This function considers the grid characteristics and updates
the locators dedicated to coordinates
This makes sense when a new grid is generated or when the grid
characteristics have changed

◆ db_grid_patch()

int db_grid_patch ( DbGrid ss_grid,
DbGrid db_grid,
int  iptr_ss,
int  iptr_db,
int  iptr_rank,
int  new_rank,
int  oper,
int  verbose 
)

Patch a sub-grid within a main grid

Returns
Error return code
Parameters
[in]ss_gridDb sub-grid structure
[in]db_gridDb main grid structure
[in]iptr_ssRank of the attribute in the sub-grid
[in]iptr_dbRank of the attribute in the main grid
[in]iptr_rankRank of the attribute storing object rank If <0, no check is performed: always patch
[in]new_rankRank of the current object to patch in main grid
[in]oper>0 for larger; <0 for smaller
[in]verboseVerbose flag
Remarks
When 'iptr_rank' is defined (>=0), defined pixels of the current
sub-grid overwrites the corresponding pixel within the main grid
only if its rank ('new_rank') is larger (oper>0) or smaller
(oper<0)) than the rank of the same pixel in the main grid
(attribute 'iptr_rank')
When 'iptr_rank' is undefined, arguments 'new_rank', 'oper' are
useless

◆ db_grid_print()

void db_grid_print ( Db db)

Print the Summary of the Grid structure

Parameters
[in]dbPointer to the Db structure (organized as a grid)

◆ db_grid_reduce()

DbGrid* db_grid_reduce ( DbGrid db_grid,
int  iptr,
const int *  margin,
const int *  limmin,
int  flag_sel,
int  flag_copy,
int  verbose,
double  vmin,
double  vmax 
)

Extract the subgrid (from a grid) which contains the only cells where the target variable lies wuthin the target interval Selection in the input grid is taken into account

Parameters
[in]db_gridDb structure
[in]iptrRank of the column of the target variable
[in]marginArray of margins (or NULL)
[in]limminArray of minimum dimensions (or NULL)
[in]flag_selCreate the selection
[in]flag_copy1 if the selection must be copied in sub-grid
[in]verboseVerbose flag
[in]vminLower bound (included)
[in]vmaxUpper bound (excluded)

◆ db_locator_attribute_add()

int db_locator_attribute_add ( Db db,
const ELoc &  locatorType,
int  number,
int  r_tem,
double  valinit,
int *  iptr 
)

Add and initiate several attributes corresponding to a given locator

Returns
Error return code
Parameters
[in]dbDb structure
[in]locatorTypeRank of the Pointer (ELoc)
[in]numberNumber of locators to be defined
[in]r_temRank of the first item in the pointer
[in]valinitValue to be used for initialization
[out]iptrRank of the first new attribute

◆ db_locators_correct()

void db_locators_correct ( VectorString strings,
const VectorInt current,
int  flag_locnew 
)

Define the array of locators

Parameters
[in]stringsArray of locators
[in]currentArray of ranks of the last modified locator
[in]flag_locnewReset all locators
Remarks
The elements of the array current are numbered starting from 1

◆ db_merge()

int db_merge ( Db db,
int  ncol,
int *  cols 
)

Merge a set of variables in a Db

Returns
Error return code
Parameters
[in]dbDb structure
[in]ncolNumber of variables to be merged
[in]colsArray of input variable columns

◆ db_monostat()

void db_monostat ( Db db,
int  iatt,
double *  wtot,
double *  mean,
double *  var,
double *  mini,
double *  maxi 
)

Monovariate statistics

Parameters
[in]dbDb structure
[in]iattRank of the attribute
[out]wtotSum of the weights
[out]meanMean of the variable
[out]varvariance of the variable
[out]miniMinimum value
[out]maxiMaximum value

◆ db_name_identify()

int db_name_identify ( Db db,
const String string 
)

Identify the attribute by its name

Returns
Rank of the variable starting from 0 (or -1 if not found)
Parameters
[in]dbDb descriptor
[in]stringattribute name

◆ db_prop_read()

int db_prop_read ( DbGrid db,
int  ix,
int  iy,
double *  props 
)

Read the proportions per VPC

Returns
Error return code
Parameters
[in]dbDb structure
[in]ixRank of the cell along X
[in]iyRank of the cell along Y
[out]propsArray of proportions
Remarks
This procedure is meant for a 3-D grid file

◆ db_prop_write()

int db_prop_write ( DbGrid db,
int  ix,
int  iy,
double *  props 
)

Write the proportions (per VPC)

Returns
Error return code
Parameters
[in]dbDb structure
[in]ixRank of the cell along X
[in]iyRank of the cell along Y
[in]propsArray of proportions
Remarks
This procedure is meant for a 3-D grid file

◆ db_proportion()

int db_proportion ( Db db,
DbGrid dbgrid,
int  nfac1max,
int  nfac2max,
int *  nclout 
)

Calculates the proportions of facies within a grid

Returns
Error return code
Parameters
[in]dbInput Db structure
[in]dbgridOutput Grid Db structure
[in]nfac1maxMaximum number of facies for the first variable
[in]nfac2maxMaximum number of facies for the second variable
[out]ncloutTotal number of classes
Remarks
This procedure is designed for one or two Z-variables
When used for 2 variables, the proportions are for pairs of
variables

◆ db_sample_print()

void db_sample_print ( Db db,
int  iech,
int  flag_ndim,
int  flag_nvar,
int  flag_nerr 
)

Print a sample

Parameters
[in]dbDb structure
[in]iechRank of the sample
[in]flag_ndim1 if the coordinates must be printed
[in]flag_nvar1 if the variables must be printed
[in]flag_nerr1 if the error measurement variance must be printed

◆ db_selref()

int db_selref ( int  ndim,
const int *  nx,
const int *  ref,
const double *  tabin,
double *  tabout 
)

Select a 2-D grid from a Grid Db

Returns
Error returned code
Parameters
[in]ndimSpace dimension of the Db
[in]nxNumber of meshes of the grid
[in]refArray giving the indices of the reference planes
  • Grid indices are counted starting from 1
  • -1 for the directions of interest
[in]tabinInput array
[out]taboutOutput array

◆ distance_grid()

double distance_grid ( DbGrid db,
int  flag_moins1,
int  iech1,
int  iech2,
double *  dist_vect 
)

Calculates the distance between two points in the same grid Db

Returns
The calculated distance
Parameters
[in]dbDb structure
[in]flag_moins11 to use the cell center
[in]iech1rank of the first sample
[in]iech2rank of the second sample
[out]dist_vectIf the output vector is provided. Returns the distance as a vector

◆ distance_inter()

double distance_inter ( const Db db1,
const Db db2,
int  iech1,
int  iech2,
double *  dist_vect 
)

Calculates the distance between two points

Returns
The calculated distance or TEST if one coordinate not defined
Parameters
[in]db1Db structure for the first sample
[in]db2Db structure for the second sample
[in]iech1rank of the first sample
[in]iech2rank of the second sample
[out]dist_vectIf the output vector is provided. Returns the distance as a vector
Remarks
: If both Data Bases do not share the same Space Dimension
: the test is performed on their minimum.
: The returned array 'vect' must be dimension to that value

◆ distance_intra()

double distance_intra ( const Db db,
int  iech1,
int  iech2,
double *  dist_vect 
)

Calculates the distance between two points in the same Db

Returns
The calculated distance or TEST if one coordinate not defined
Parameters
[in]dbDb structure
[in]iech1rank of the first sample
[in]iech2rank of the second sample
[out]dist_vectIf the output vector is provided. Returns the distance as a vector

◆ get_grid_value()

double get_grid_value ( DbGrid dbgrid,
int  iptr,
VectorInt indg,
int  ix,
int  iy,
int  iz 
)

Returns a value from the a 3-D (maximum) grid

Returns
Returned value
Parameters
[in]dbgridDb Grid structure
[in]iptrRank of the column
[in]indgWorking index array (Dimension: get_NDIM(dbgrid))
[in]ixRank of the node along first dimension
[in]iyRank of the node along second dimension
[in]izRank of the node along third dimension

◆ get_LOCATOR_NITEM()

int get_LOCATOR_NITEM ( const Db db,
const ELoc &  locatorType 
)

Returns the number of items for a given locator in the Db

Returns
Number of items
Parameters
[in]dbDb descriptor
[in]locatorTypeRank of the pointer (ELoc)

◆ grid_iterator_init()

void grid_iterator_init ( Grid grid,
const VectorInt order 
)

Initialize the Grid iterator

◆ grid_iterator_next()

VectorInt grid_iterator_next ( Grid grid)

Returns 1 when the last element of the iteration is reached

Increment the Grid iterator

◆ index_point_to_grid()

int index_point_to_grid ( const Db dbin,
int  iech,
int  flag_outside,
const DbGrid dbout,
double *  coor 
)

Find the index of the output grid file which is the closest to the sample of the input file

Returns
Error return code
>= index of the grid node
-1 if the point is outside the grid
Parameters
[in]dbindescriptor of the input file
[in]iechIndex of the data point
[in]flag_outsidevalue returned for the point outside the grid
  • 1 the index is set to the closest grid node
  • 0 the index is set to -1
  • -1 do not correct the index
[in]dboutdescriptor of the output grid file
[out]coorWorking array (dimension: ndim)

◆ is_grid_multiple()

int is_grid_multiple ( DbGrid db1,
DbGrid db2 
)

Check if a grid is a multiple of the other grid

Returns
1 if the two grid are multiple; 0 otherwise
Parameters
[in]db1Db1 small grid structure
[in]db2Db1 coarse grid structure

◆ point_inside_grid()

int point_inside_grid ( Db db,
int  iech,
const DbGrid dbgrid 
)

Check if a sample of a Db lies within a Grid Db

Returns
1 if the point lies within the grid; 0 otherwise
Parameters
[in]dbDb structure
[in]iechRank of the target sample
[in]dbgridGrid Db structure

◆ point_to_bench()

int point_to_bench ( const DbGrid db,
double *  coor,
int  flag_outside,
int *  indb 
)

Converts from point coordinates to index of the bench to which it belongs

Returns
Error return code
0 if the point is inside the grid
1 if the point is outside the grid
-1 if one coordinate is undefined
-2 if the grid is defined in space less than 3D
Parameters
[in]dbdescriptor of the grid parameters
[in]coorarray of coordinates of the point
[in]flag_outsidevalue returned for the point outside the grid
  • 1 the index is set to the closest grid node
  • 0 the index is set to -1
  • -1 do not correct the index
[out]indbindex of the bench
Remarks
The bench corresponds to the third dimension of the grid provided
as reference

◆ point_to_grid()

int point_to_grid ( const DbGrid db,
const double *  coor,
int  flag_outside,
int *  indg 
)

Converts from point coordinates to nearest grid node indices

Returns
Error return code
0 if the point is inside the grid
1 if the point is outside the grid
-1 if one coordinate is undefined
Parameters
[in]dbdescriptor of the grid parameters
[in]coorarray of coordinates of the point
[in]flag_outsidevalue returned for the point outside the grid
  • 1 the index is set to the closest grid node
  • 0 the index is set to -1
  • -1 do not correct the index
[out]indgindices of the closest grid node

◆ point_to_point()

int point_to_point ( Db db,
const double *  coor 
)

Returns the rank of the closest isolated point

Returns
Output index
Parameters
[in]dbdescriptor of the Db
[in]coorarray of coordinates of the point

◆ set_grid_value()

void set_grid_value ( DbGrid dbgrid,
int  iptr,
VectorInt indg,
int  ix,
int  iy,
int  iz,
double  value 
)

Set the value in the a 3-D (maximum) grid

Parameters
[in]dbgridDb Grid structure
[in]iptrRank of the column
[in]indgWorking index array (Dimension: get_NDIM(dbgrid))
[in]ixRank of the node along first dimension
[in]iyRank of the node along second dimension
[in]izRank of the node along third dimension
[in]valueAssigned value

◆ st_rotate()

static void st_rotate ( int  ndim,
double *  rotmat,
VectorDouble coor,
VectorDouble mini,
VectorDouble maxi 
)
static

Update the bounding box limits due to a point

Parameters
[in]ndimSpace dimension
[in]rotmatRotation matrix (optional)
[in]coorArray of sample coordinates
[out]miniArray containing the minimum
[out]maxiArray containing the maximum
Remarks
This function is limited to the 3-D case