/* Authors Martin Schlather, martin.schlather@math.uni-goettingen.de library for unconditional simulation of stationary and isotropic random fields Copyright (C) 2001 -- 2006 Martin Schlather, This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* PRINTING LEVELS =============== error messages: 1 forcation : 2 minor tracing information : 3--5 large debugging information: >10 */ /* calculate the transformation of the points only once and store the result in a register (indexed by ncov) of key, not of s->. Advantages: points have to calculated only once for several tries; if zonal anisotropy then specific methods may be called; */ #include #include #include #include #include #include "RFsimu.h" #define KRIGE_TOLERANCE -1e-10 void simpleKriging(double *tgiven, double *x, double *invcov, int *Len_x, int *NN, int *Dim, int *Rep, double *Mean, double *Res) { // kriging variance is not calculated int error, len_tgiven, dim, nn, d, i, j, r, rep, resi, len_x, divachtzig, divachtzigM1; double *cov, *dist, xx[MAXDIM], mean; // NN : length given = length cov vector to be calculated // Rep : repetition invcov // Len_x : number of points in x, length(x) = len_x * dim dim = *Dim; nn = *NN; mean = *Mean; rep = *Rep; len_x = *Len_x; len_tgiven = dim * nn; divachtzigM1 = (divachtzig = (len_x<79) ? 1 : (len_x / 79)) - 1; cov = dist =NULL; if ((cov = (double*) malloc(sizeof(double) * nn))==NULL) { error = ERRORMEMORYALLOCATION; goto ErrorHandling; } if ((dist = (double*) malloc(sizeof(double) * len_tgiven))==NULL) { error = ERRORMEMORYALLOCATION; goto ErrorHandling; } for (resi=i=0; i0 && (resi % divachtzig == divachtzigM1)) PRINTF("."); for (d=0, j=i; d 0) PRINTF("\n"); free(cov); free(dist); return; ErrorHandling: int nRes; if (cov!=NULL) free(cov); if (dist!=NULL) free(cov); nRes = len_x * rep; for (i=0; i0 && (resi % divachtzig == divachtzigM1)) PRINTF("."); for (d=0, j=i; d KRIGE_TOLERANCE); sigma2[i] = 0.0; } for (d=r=0; r 0) PRINTF("\n"); free(cov); free(lambda); free(dist); return; ErrorHandling: int nRes; if (cov!=NULL) free(cov); if (lambda!=NULL) free(lambda); if (dist!=NULL) free(dist); nRes = len_x * rep; for (i=0; i0 && (resi % divachtzig == divachtzigM1)) PRINTF("."); for (d=0, j=i; d 0) PRINTF("\n"); free(cov); free(dist); return; ErrorHandling: int nRes; if (cov!=NULL) free(cov); if (dist!=NULL) free(dist); nRes = len_x * rep; for (i=0; i0 && (resi % divachtzig ==divachtzigM1)) PRINTF("."); for (d=0, j=i; d KRIGE_TOLERANCE); sigma2[i] = 0.0; } for (d=r=0; r 0) PRINTF("\n"); free(cov); free(lambda); free(dist); return; ErrorHandling: int nRes; if (cov!=NULL) free(cov); if (lambda!=NULL) free(lambda); if (dist!=NULL) free(dist); nRes = len_x * rep; for (i=0; i