Changeset 12200 for issm/trunk-jpl/src/c/modules
- Timestamp:
- 05/03/12 16:14:45 (13 years ago)
- Location:
- issm/trunk-jpl/src/c/modules/Krigingx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp
r12183 r12200 11 11 #include <gsl/gsl_linalg.h> 12 12 13 #include "../../objects/Kriging/GaussianVariogram.h" 13 14 int Krigingx(double** ppredictions,double* x, double* y, double* observations, int n_obs,double* x_interp,double* y_interp,int n_interp,Options* options){ 14 15 … … 17 18 18 19 /*Intermediaries*/ 19 int i,j; 20 double numerator,denominator,ratio; 21 double *Gamma = NULL; 22 double *GinvG0 = NULL; 23 double *Ginv1 = NULL; 24 double *GinvZ = NULL; 25 double *gamma0 = NULL; 26 double *ones = NULL; 20 int i,j; 21 double numerator,denominator,ratio; 22 char *model = NULL; 23 double *Gamma = NULL; 24 double *GinvG0 = NULL; 25 double *Ginv1 = NULL; 26 double *GinvZ = NULL; 27 double *gamma0 = NULL; 28 double *ones = NULL; 29 Variogram *variogram = NULL; 27 30 28 31 /*Memory allocation*/ … … 32 35 ones =(double*)xmalloc(n_obs*sizeof(double)); 33 36 37 /*Create Semi-Variogram object*/ 38 if(options->GetOption("model")){ 39 options->Get(&model,"model"); 40 if (strcmp(model,"gaussian")==0) variogram = new GaussianVariogram(options); 41 else if(strcmp(model,"exponential")==0) variogram = new ExponentialVariogram(options); 42 else if(strcmp(model,"spherical")==0) variogram = new SphericalVariogram(options); 43 else _error_("only gaussian semivariogram models supported yet"); 44 } 45 else variogram = new GaussianVariogram(options); 46 variogram->Echo(); 47 34 48 /*First: Create semivariogram matrix for observations*/ 35 49 for(i=0;i<n_obs;i++){ 36 50 for(j=0;j<=i;j++){ 37 SemiVariogram(&Gamma[i*n_obs+j],x[i],y[i],x[j],y[j]);51 Gamma[i*n_obs+j] = variogram->SemiVariogram(x[i]-x[j],y[i]-y[j]); 38 52 Gamma[j*n_obs+i] = Gamma[i*n_obs+j]; 39 53 } … … 47 61 48 62 /*Get semivariogram vector associated to this location*/ 49 for(i=0;i<n_obs;i++) SemiVariogram(&gamma0[i],x[i],y[i],x_interp[idx],y_interp[idx]);63 for(i=0;i<n_obs;i++) gamma0[i] = variogram->SemiVariogram(x[i]-x_interp[idx],y[i]-y_interp[idx]); 50 64 51 65 /*Solve the three linear systems*/ … … 71 85 72 86 /*clean-up and Assign output pointer*/ 87 delete variogram; 73 88 xfree((void**)&Gamma); 74 89 xfree((void**)&gamma0); 75 90 xfree((void**)&ones); 91 xfree((void**)&model); 76 92 *ppredictions=predictions; 77 }78 79 void SemiVariogram(double* gamma,double x1,double y1,double x2,double y2){80 81 /*Intermediaries*/82 double a,c0,c1;83 84 /*Calculate distance*/85 double r=sqrt(pow(x1-x2,2.)+pow(y1-y2,2.));86 87 /*Switch between variogram models*/88 switch(2){89 case 1:/*Exponential*/90 c0=0.2;91 c1=0.8;92 a =1;93 *gamma = c0 + c1*(1-exp(-r/a));94 return;95 case 2:/*Gaussian*/96 c0=0.2;97 c1=0.8;98 a =1;99 *gamma = c0 + c1*(1-exp(-pow(r,2.)/pow(a,2.)));100 return;101 default:102 _error_("Not implemented yet");103 }104 93 } 105 94 -
issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.h
r12183 r12200 10 10 11 11 int Krigingx(double** ppredictions,double* x, double* y, double* observations, int n_obs,double* x_interp,double* y_interp,int n_interp,Options* options); 12 void SemiVariogram(double* gamma,double x1,double y1,double x2,double y2);13 12 void GslSolve(double** pX,double* A,double* B,int n); 14 13
Note:
See TracChangeset
for help on using the changeset viewer.