#include "geoslib_old_f.h"
#include "Calculators/CalcMigrate.hpp"
#include "Variogram/Vario.hpp"
#include "Basic/Utilities.hpp"
#include "Basic/OptDbg.hpp"
#include "Model/Model.hpp"
#include "Neigh/ANeigh.hpp"
#include "Db/Db.hpp"
#include "Db/DbGrid.hpp"
#include "Basic/Memory.hpp"
#include "Core/Keypair.hpp"
#include <math.h>
Classes | |
struct | LMlayers |
Functions | |
static LMlayers * | lmlayers_free (LMlayers *lmlayers) |
static int | st_get_number_drift (int irf_rank, int flag_ext) |
static LMlayers * | lmlayers_alloc (int flag_same, int flag_vel, int flag_cumul, int flag_ext, int flag_z, int colrefd, int colreft, int colrefb, int irf_rank, int match_time, int nlayers) |
static void | lmlayers_print (LMlayers *lmlayers) |
static int | st_locate_sample_in_output (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, int iech, int *igrid) |
static void | st_check_layer (const char *string, LMlayers *lmlayers, int ilayer0) |
static int | st_get_props_result (LMlayers *lmlayers, Db *dbout, int iech, int ilayer0, VectorDouble &props) |
static int | st_get_props_data (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, int iech, int ilayer0, VectorDouble &props) |
static double | st_get_drift_result (LMlayers *lmlayers, Db *dbout, int iech, int ilayer0) |
static double | st_get_drift_data (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, int iech, int ilayer0) |
static void | st_covariance_c00 (LMlayers *lmlayers, Model *model, const VectorDouble &prop1, MatrixSquareGeneral &covtab, double *c00) |
static double | st_cij (LMlayers *lmlayers, Model *model, int ilayer, const VectorDouble &prop1, int jlayer, const VectorDouble &prop2, const double *dd, MatrixSquareGeneral &covtab) |
static double | st_ci0 (LMlayers *lmlayers, Model *model, int ilayer, const VectorDouble &prop1, int jlayer, const double *dd, MatrixSquareGeneral &covtab) |
static int | st_drift (LMlayers *lmlayers, const double *coor, double propval, double drext, int *ipos_loc, VectorDouble &b) |
static int | st_lhs_one (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, Model *model, VectorInt &seltab, int iech0, int ilayer0, double *coor, VectorDouble &prop0, VectorDouble &prop2, MatrixSquareGeneral &covtab, VectorDouble &b) |
static int | st_rhs (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, Model *model, double *coor, VectorInt &seltab, int iechout, int ilayer0, VectorDouble &prop0, VectorDouble &prop2, MatrixSquareGeneral &covtab, VectorDouble &b) |
static int | st_lhs (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, Model *model, VectorInt &seltab, VectorDouble &prop1, VectorDouble &prop2, MatrixSquareGeneral &covtab, double *a, double *acov) |
static void | st_data_vector (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, VectorInt &seltab, VectorDouble &zval) |
static int | st_subtract_optimal_drift (LMlayers *lmlayers, int verbose, Db *dbin, DbGrid *dbout, VectorInt &seltab, VectorDouble &zval) |
static int | st_get_close_sample (LMlayers *lmlayers, Db *dbin, int iech0, const double *coor) |
static int | st_collocated_prepare (LMlayers *lmlayers, int iechout, double *coor, Db *dbin, DbGrid *dbout, Model *model, VectorInt &seltab, double *a, VectorDouble &zval, VectorDouble &prop1, VectorDouble &prop2, MatrixSquareGeneral &covtab, double *b2, VectorDouble &baux, double *ratio) |
static void | st_estimate_regular (LMlayers *lmlayers, int flag_std, double c00, double *a, VectorDouble &b, double *dual, double *wgt, double *estim, double *stdev) |
static void | st_estimate_bayes (LMlayers *lmlayers, int flag_std, double c00, const double *acov, VectorDouble &zval, VectorDouble &b, double *wgt, double *post_mean, double *a0, double *cc, double *ss, const double *gs, double *estim, double *stdev) |
static void | st_estimate (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, Model *model, VectorInt &seltab, int flag_bayes, int flag_std, double *a, VectorDouble &zval, double *dual, VectorDouble &prop1, VectorDouble &prop2, MatrixSquareGeneral &covtab, VectorDouble &b, double *b2, VectorDouble &baux, double *wgt, double *c00, VectorDouble &, double *a0, double *cc, double *ss, double *gs, double *, double *post_mean) |
static int | st_check_auxiliary_variables (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, VectorInt &seltab) |
static void | st_convert_results (LMlayers *lmlayers, Db *dbout, int flag_std) |
static int | st_drift_data (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, VectorInt &seltab, VectorDouble &prop1, VectorDouble &fftab) |
static int | st_drift_bayes (LMlayers *lmlayers, int verbose, double *prior_mean, const double *prior_vars, double *acov, VectorDouble &zval, VectorDouble &fftab, double *a0, double *cc, double *ss, double *gs, double *post_mean, double *post_S) |
int | multilayers_kriging (Db *dbin, DbGrid *dbout, Model *model, ANeigh *neigh, int flag_same, int flag_z, int flag_vel, int flag_cumul, int flag_ext, int flag_std, int flag_bayes, int irf_rank, int match_time, int dim_prior, double *prior_mean, double *prior_vars, int colrefd, int colreft, int colrefb, int verbose) |
static int | st_evaluate_lag (LMlayers *lmlayers, Db *dbin, DbGrid *dbout, Vario_Order *vorder, int nlayers, int ifirst, int ilast, VectorDouble &zval, int *nval, double *distsum, int *stat, VectorDouble &phia, VectorDouble &phib, double *atab, double *btab) |
static int | st_varioexp_chh (LMlayers *lmlayers, int verbose, Db *dbin, DbGrid *dbout, Vario_Order *vorder, VectorDouble &zval, int idir, Vario *vario) |
int | multilayers_vario (Db *dbin, DbGrid *dbout, Vario *vario, int nlayers, int flag_vel, int flag_ext, int irf_rank, int match_time, int colrefd, int colreft, int verbose) |
static int | st_get_prior (int nech, int npar, VectorDouble &zval, VectorDouble &fftab, double *mean, double *vars) |
int | multilayers_get_prior (Db *dbin, DbGrid *dbout, Model *model, int flag_same, int flag_vel, int flag_ext, int irf_rank, int match_time, int colrefd, int colreft, int colrefb, int verbose, int *npar_arg, double **mean, double **vars) |
|
static |
Allocate the Multi-Layers internal structure
[in] | flag_same | 1 if input and output files coincide |
[in] | flag_vel | 1 if work is performed in Velocity, 0 for Depth |
[in] | flag_cumul | 1 if work must be done on Depth; 0 on Thickness |
[in] | flag_ext | 1 if external drift must be used; 0 otherwise |
[in] | flag_z | 1 if the output must be provided in depth |
[in] | colrefd | Rank of the reference depth variable |
[in] | colreft | Rank of the reference Time variable in Dbout |
[in] | colrefb | Rank of the reference Bottom Depth variable |
[in] | irf_rank | Rank of the Intrinsic Random Function (0 or 1) |
[in] | match_time | Pointer to the Time pointer (1 if defined as ELoc::F or 0 for ELoc::TIME) |
[in] | nlayers | Number of layers |
Free the Multi-Layers internal structure
[in] | lmlayers | Pointer to the LMlayers structure to be freed |
|
static |
Print the Multi-Layers internal structure
[in] | lmlayers | Pointer to the LMlayers structure |
int multilayers_get_prior | ( | Db * | dbin, |
DbGrid * | dbout, | ||
Model * | model, | ||
int | flag_same, | ||
int | flag_vel, | ||
int | flag_ext, | ||
int | irf_rank, | ||
int | match_time, | ||
int | colrefd, | ||
int | colreft, | ||
int | colrefb, | ||
int | verbose, | ||
int * | npar_arg, | ||
double ** | mean, | ||
double ** | vars | ||
) |
Multi-layers get the mean and prior matrices for Bayesian prior
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | model | Model structure |
[in] | flag_same | 1 if input and output files coincide |
[in] | flag_vel | 1 if work is performed in Velocity, 0 for Depth |
[in] | flag_ext | 1 if external drift must be used; 0 otherwise |
[in] | irf_rank | Rank of the Intrinsic Random Function (0 or 1) |
[in] | match_time | 1 if external drift matches time; 0 otherwise |
[in] | colrefd | Rank of the reference Depth variable in Dbout |
[in] | colreft | Rank of the reference Time variable in Dbout |
[in] | colrefb | Rank of the Bottom Depth variable in Dbout (or -1) |
[in] | verbose | Verbose option |
[out] | npar_arg | Number of drift terms |
[out] | mean | Array of means |
[out] | vars | Array of variances |
int multilayers_kriging | ( | Db * | dbin, |
DbGrid * | dbout, | ||
Model * | model, | ||
ANeigh * | neigh, | ||
int | flag_same, | ||
int | flag_z, | ||
int | flag_vel, | ||
int | flag_cumul, | ||
int | flag_ext, | ||
int | flag_std, | ||
int | flag_bayes, | ||
int | irf_rank, | ||
int | match_time, | ||
int | dim_prior, | ||
double * | prior_mean, | ||
double * | prior_vars, | ||
int | colrefd, | ||
int | colreft, | ||
int | colrefb, | ||
int | verbose | ||
) |
Multi-layers architecture estimation
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | model | Model structure |
[in] | neigh | ANeigh structure |
[in] | flag_same | 1 if input and output files coincide |
[in] | flag_z | 1 if the output must be converted back into depth |
[in] | flag_vel | 1 if work is performed in Velocity, 0 for Depth |
[in] | flag_cumul | 1 if work is performed in Depth; 0 in Thickness |
[in] | flag_ext | 1 if external drift must be used; 0 otherwise |
[in] | flag_std | 1 if the estimation error must be calculated |
[in] | flag_bayes | 1 if the Bayesian hypothesis is used on drift coeffs |
[in] | irf_rank | Rank of the Intrinsic Random Function (0 or 1) |
[in] | match_time | 1 if external drift matches time; 0 otherwise |
[in] | dim_prior | Dimension of the prior information (for verification) |
[in] | prior_mean | Vector of prior means for drift coefficients |
[in] | prior_vars | Vector of prior variances for drift coefficients |
[in] | colrefd | Rank of the reference Depth variable in Dbout |
[in] | colreft | Rank of the reference Time variable in Dbout |
[in] | colrefb | Rank of the Bottom Depth variable in Dbout (or -1) |
[in] | verbose | Verbose option |
int multilayers_vario | ( | Db * | dbin, |
DbGrid * | dbout, | ||
Vario * | vario, | ||
int | nlayers, | ||
int | flag_vel, | ||
int | flag_ext, | ||
int | irf_rank, | ||
int | match_time, | ||
int | colrefd, | ||
int | colreft, | ||
int | verbose | ||
) |
Multi-layers architecture experimental variogram
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | vario | Vario structure |
[in] | nlayers | Number of layers |
[in] | flag_vel | 1 if work is performed in Velocity, 0 for Depth |
[in] | flag_ext | 1 if external drift must be used; 0 otherwise |
[in] | irf_rank | Rank of the Intrinsic Random Function (0 or 1) |
[in] | match_time | 1 if external drift matches time; 0 otherwise |
[in] | colrefd | Rank of the reference Depth variable in Dbout |
[in] | colreft | Rank of the reference Time variable in Dbout |
[in] | verbose | 1 for a verbose option |
|
static |
Check if the target layer rank is consistent
[in] | string | Name of the calling procedure |
[in] | lmlayers | LMlayers structure |
[in] | ilayer0 | Rank of the target layer (starting from 1) |
|
static |
Calculate the covariance between data and target
[in] | lmlayers | LMlayers structure |
[in] | model | Model |
[in] | ilayer | Layer of interest (data point). Starting from 1 |
[in] | prop1 | Working array at data point (Dimension: nlayers) |
[in] | jlayer | Layer of interest (target point). Starting from 1 |
[in] | dd | Distance vector (or NULL for zero-distance) |
[out] | covtab | Working array (Dimension = nlayers * nlayers) |
|
static |
Calculate the covariance between data and data
[in] | lmlayers | Pointer to the LMlayers structure to be freed |
[in] | model | Model |
[in] | ilayer | Layer of interest (first point). Starting from 1 |
[in] | prop1 | Working array at first point (Dimension: nlayers) |
[in] | jlayer | Layer of interest (second point). Starting from 1 |
[in] | prop2 | Working array at second point (Dimension: nlayers) |
[in] | dd | Distance vector (or NULL for zero-distance) |
[out] | covtab | Working array (Dimension = nlayers * nlayers) |
|
static |
Perform the per-calculation for estimation with collocated option
[in] | lmlayers | LMlayers structure |
[in] | iechout | Rank of the target |
[in] | coor | Coordinates of the target |
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | model | Model |
[in] | seltab | Number of sample definition (0, 1 or 2) |
[in] | a | L.H.S. (square) inverted matrix |
[in] | zval | Data vector (extended) |
[out] | prop1 | Working array (Dimension: nlayers) |
[out] | prop2 | Working array (Dimension: nlayers) |
[out] | covtab | Working array (Dimension = nlayers * nlayers) |
[out] | b2 | Working vector (Dimension = neq) |
[out] | baux | Working vector (Dimension = neq) |
[out] | ratio | Ratio value |
Convert the results in the Depth scale
[in] | lmlayers | LMlayers structure |
[in] | dbout | Output Db structure |
[in] | flag_std | 1 if the estimation error must be calculated |
|
static |
Calculate the array of covariances for zero distance
[in] | lmlayers | Pointer to the LMlayers structure to be freed |
[in] | model | Model |
[in] | prop1 | Working array at first point (Dimension: nlayers) |
[out] | covtab | Working array (Dimension = nlayers * nlayers) |
[out] | c00 | Returned array (Dimension = nlayers) |
|
static |
|
static |
Calculate the drift terms
[in] | lmlayers | Pointer to the LMlayers structure to be freed |
[in] | coor | Array of coordinates |
[in] | propval | Value for the proportion (used if flag_cumul=TRUE) |
[in] | drext | Value of the external drift |
[in,out] | ipos_loc | Address for the first drift term. On output, address for the next term after the drift |
[out] | b | Array for storing the drift |
|
static |
Calculate the posterior mean and variances in Bayesian case
|
static |
Fill the array of drift values at data points
|
static |
Perform the estimation at the grid nodes
[in] | lmlayers | LMlayers structure |
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | model | Model |
[in] | seltab | Number of sample definition (0, 1 or 2) |
[in] | flag_bayes | 1 if the Bayesian hypothesis is used on drift coeffs |
[in] | flag_std | 1 if the estimation error must be calculated |
[in] | a | L.H.S. (square) inverted matrix |
[in] | zval | Data vector (extended) |
[in] | dual | Dual vector |
[out] | prop1 | Working array (Dimension: nlayers) |
[out] | prop2 | Working array (Dimension: nlayers) |
[out] | covtab | Working array (Dimension = nlayers * nlayers) |
[out] | b | Working vector (Dimension = neq) |
[out] | b2 | Working vector (Dimension = neq) |
[out] | baux | Working vector (Dimension = neq) |
[out] | wgt | Working array (Dimension = neq) |
[out] | c00 | Working array (Dimension = nlayers) |
[out] | a0 | Constant term |
[out] | cc | Output value |
[out] | ss | Output value |
[out] | gs | Output value |
[out] | post_mean | Array of posterior mean |
|
static |
Perform the estimation at the grid nodes in the bayesian case
[in] | lmlayers | LMlayers structure |
[in] | flag_std | 1 if the estimation error must be calculated |
[in] | c00 | Variance at target |
[in] | acov | L.H.S. (square) inverted matrix |
[in] | zval | Data vector |
[in] | b | Working vector (Dimension = neq) |
[in] | wgt | Working array (Dimension = neq) |
[out] | post_mean | Array of posterior mean |
[out] | a0 | Constant term |
[out] | cc | Output value |
[out] | ss | Output value |
[out] | gs | Output value |
[out] | estim | Estimated value |
[out] | stdev | Standard deviation of estimation error |
|
static |
Perform the estimation at the grid nodes in regular case
[in] | lmlayers | LMlayers structure |
[in] | flag_std | 1 if the estimation error must be calculated |
[in] | c00 | Variance for target |
[in] | a | L.H.S. (square) inverted matrix |
[in] | b | Working vector (Dimension = neq) |
[in] | dual | Dual vector |
[in] | wgt | Working array (Dimension = neq) |
[out] | estim | Estimated value |
[out] | stdev | Standard deviation of estimation error |
|
static |
Evaluate the sill matrix for a given lag
[in] | lmlayers | LMlayers structure |
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | vorder | Vario_Order structure |
[in] | nlayers | Number of layers |
[in] | ifirst | Index of the first pair (included) |
[in] | ilast | Index of the last pair (excluded) |
[in] | zval | Array containing the sample values |
[out] | nval | Number of relevant pairs |
[out] | distsum | Average distance |
[out] | stat | Working array (Dimension: nlayers * nlayers) |
[out] | phia | Working array for proportions (Dimension: nlayers) |
[out] | phib | Working array for proportions (Dimension: nlayers) |
[out] | atab | Working array (Dimension: nhalf * nhalf) |
[out] | btab | Working array (Dimension: nhalf) |
|
static |
Return the external drift value at an input location for a target layer
|
static |
Returns the number of drift functions
[in] | irf_rank | Rank of the Intrinsic Random Function (0 or 1) |
[in] | flag_ext | 1 if external drift must be used; 0 otherwise |
|
static |
Determine the mean and variance of drift coefficients
|
static |
Fill the proportion vector at a data location, up to the target layer
|
static |
Fill the proportion vector at a output location, up to the target layer
|
static |
Calculates the Kriging L.H.S.
[in] | lmlayers | LMlayers structure |
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | model | Model |
[in] | seltab | Number of sample definition (0, 1 or 2) |
[out] | prop1 | Working array (Dimension: nlayers) |
[out] | prop2 | Working array (Dimension: nlayers) |
[out] | covtab | Working array (Dimension = nlayers * nlayers) |
[out] | a | L.H.S. (square) matrix |
[out] | acov | L.H.S. (square) covariance matrix |
|
static |
Calculates the L.H.S. for one data
[in] | lmlayers | LMlayers structure |
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | model | Model |
[in] | seltab | Number of sample definition (0, 1 or 2) |
[in] | iech0 | Rank of the target sample (used for ext. drift) |
[in] | ilayer0 | Rank of the layer of interest (Starting from 1) |
[in] | coor | Coordinates of the data |
[in] | prop0 | Working array at first point (Dimension: nlayers) |
[out] | prop2 | Working array (Dimension: nlayers) |
[out] | covtab | Working array (Dimension = nlayers * nlayers) |
[out] | b | R.H.S. vector (Dimension = neq) |
|
static |
Returns the absolute grid node absolute index which is the closest to a given sample of a Db In the case of same input and output file, simply return 'iech'
|
static |
Calculates the Kriging R.H.S.
[in] | lmlayers | LMlayers structure |
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | model | Model |
[in] | coor | Coordinates of the target sample |
[in] | seltab | Number of sample definition (0, 1 or 2) |
[in] | iechout | Rank of the target sample |
[in] | ilayer0 | Rank of the layer of interest (Starting from 1) |
[out] | prop0 | Working array (Dimension: nlayers) |
[out] | prop2 | Working array (Dimension: nlayers) |
[out] | covtab | Working array (Dimension = nlayers * nlayers) |
[out] | b | R.H.S. vector (Dimension = neq) |
|
static |
Calculate the Drift and subtract it from the Data
[in] | lmlayers | LMlayers structure |
[in] | verbose | 1 for a verbose option |
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | seltab | Number of sample definition (0, 1 or 2) |
[out] | zval | The data vector (Dimension: neq) |
|
static |
Calculate the variogram for each lag per direction
[in] | lmlayers | LMlayers structure |
[in] | verbose | 1 for a verbose option |
[in] | dbin | Input Db structure |
[in] | dbout | Output Db structure |
[in] | vorder | Vario_Order structure |
[in] | zval | Data vector |
[in] | idir | Rank of the Direction |
[out] | vario | Vario structure |