1 | /*\file Kriging.c
|
---|
2 | *\brief: best linear predictor
|
---|
3 | */
|
---|
4 | #include "./Kriging.h"
|
---|
5 |
|
---|
6 | void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
|
---|
7 |
|
---|
8 | /*Outputs*/
|
---|
9 | double *x = NULL;
|
---|
10 | double *y = NULL;
|
---|
11 | double *observations = NULL;
|
---|
12 | double *x_interp = NULL;
|
---|
13 | double *y_interp = NULL;
|
---|
14 | double *predictions = NULL;
|
---|
15 | double *error = NULL;
|
---|
16 | Options *options = NULL;
|
---|
17 | int N_interp,M_interp,M,N,n_obs;
|
---|
18 |
|
---|
19 | /*Boot module: */
|
---|
20 | MODULEBOOT();
|
---|
21 |
|
---|
22 | /*checks on arguments on the matlab side: */
|
---|
23 | if (nrhs<NRHS || nlhs>NLHS){
|
---|
24 | KrigingUsage(); _error_("Kriging usage error");
|
---|
25 | }
|
---|
26 |
|
---|
27 | /*Fetch inputs: */
|
---|
28 | FetchData(&x,&n_obs,X);
|
---|
29 | FetchData(&y,&N,Y); if(n_obs!=N) _error_("x and y should have the same size");
|
---|
30 | FetchData(&observations,&N,OBSERVATIONS); if(n_obs!=N) _error_("x and observations should have the same size");
|
---|
31 | FetchData(&x_interp,&M_interp,&N_interp,XINTERP);
|
---|
32 | FetchData(&y_interp,&M,&N,YINTERP); if(N!=N_interp || M!=M_interp) _error_("x_interp and y_interp should have the same size");
|
---|
33 | FetchData(&options,NRHS,nrhs,prhs);
|
---|
34 |
|
---|
35 | /*Call x layer*/
|
---|
36 | Krigingx(&predictions,&error,x,y,observations,n_obs,x_interp,y_interp,M_interp*N_interp,options);
|
---|
37 |
|
---|
38 | /*Generate output Matlab Structures*/
|
---|
39 | if(nlhs>=1) WriteData(PREDICTIONS,predictions,M_interp,N_interp);
|
---|
40 | if(nlhs==2) WriteData(ERROR,error,M_interp,N_interp);
|
---|
41 |
|
---|
42 | /*Free ressources: */
|
---|
43 | xfree((void**)&x);
|
---|
44 | xfree((void**)&y);
|
---|
45 | xfree((void**)&observations);
|
---|
46 | xfree((void**)&x_interp);
|
---|
47 | xfree((void**)&y_interp);
|
---|
48 | xfree((void**)&predictions);
|
---|
49 | xfree((void**)&error);
|
---|
50 |
|
---|
51 | /*end module: */
|
---|
52 | MODULEEND();
|
---|
53 | }
|
---|
54 |
|
---|
55 | void KrigingUsage(void){
|
---|
56 | _pprintLine_("");
|
---|
57 | _pprintLine_(" usage: predictions=" << __FUNCT__ << "(x,y,observations,x_interp,y_interp,'options');");
|
---|
58 | _pprintLine_(" available options:");
|
---|
59 | _pprintLine_(" -'model': Available variogram models 'gaussian' (default),'spherical','power','exponential'");
|
---|
60 | _pprintLine_(" -'nugget': nugget effect (default 0.2)");
|
---|
61 | _pprintLine_(" -'range': for gaussian, spherical and exponential models (default sqrt(3))");
|
---|
62 | _pprintLine_(" -'sill': for gaussian, spherical and exponential models (default 1)");
|
---|
63 | _pprintLine_(" -'slope': for power model (default 1)");
|
---|
64 | _pprintLine_(" -'power': for power model (default 1)");
|
---|
65 | _pprintLine_(" -'searchradius': search radius for each prediction (default is observations span)");
|
---|
66 | _pprintLine_(" -'boxlength': minimum length of quadtree boxes (useful to decrease the number of observations)");
|
---|
67 | _pprintLine_(" -'maxdata': minimum number of observations for a prediction (default is 50)");
|
---|
68 | _pprintLine_(" -'mindata': maximum number of observations for a prediction (default is 1)");
|
---|
69 | _pprintLine_(" -'maxtrimming': maximum trimming value (default is -1.e+21)");
|
---|
70 | _pprintLine_(" -'mintrimming': minimum trimming value (default is +1.e+21)");
|
---|
71 | _pprintLine_(" -'minspacing': minimum distance between observation (default is 0.01)");
|
---|
72 | _pprintLine_("");
|
---|
73 | }
|
---|