1 | /*!\file InterpFromGridToMesh.c
|
---|
2 | * \brief: data interpolation from a list of (x,y,values) into mesh vertices
|
---|
3 |
|
---|
4 | InterpFromGridToMesh.c
|
---|
5 |
|
---|
6 | usage:
|
---|
7 | data_mesh=InterpFromGridToMesh(x,y,data,x_mesh,y_mesh);
|
---|
8 |
|
---|
9 | where:
|
---|
10 |
|
---|
11 | input:
|
---|
12 | x,y: coordinates of matrix data
|
---|
13 | data - matrix holding the data to be interpolated onto the mesh.
|
---|
14 | x_mesh,y_mesh: coordinates of the mesh vertices onto which we interpolate.
|
---|
15 |
|
---|
16 | output:
|
---|
17 | data_mesh: vector of mesh interpolated data.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "./InterpFromGridToMesh.h"
|
---|
21 |
|
---|
22 | void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
|
---|
23 |
|
---|
24 | int i,j;
|
---|
25 |
|
---|
26 | /*input: */
|
---|
27 | double* x=NULL;
|
---|
28 | double* y=NULL;
|
---|
29 | int x_rows,y_rows;
|
---|
30 | double* data=NULL;
|
---|
31 | int data_rows,data_cols;
|
---|
32 | double* x_mesh=NULL;
|
---|
33 | double* y_mesh=NULL;
|
---|
34 | int x_mesh_rows,y_mesh_rows;
|
---|
35 | double default_value;
|
---|
36 | int interpolationenum;
|
---|
37 |
|
---|
38 | /* output: */
|
---|
39 | Vector<double>* data_mesh=NULL;
|
---|
40 |
|
---|
41 | /*Boot module: */
|
---|
42 | MODULEBOOT();
|
---|
43 |
|
---|
44 | /*checks on arguments on the matlab side: */
|
---|
45 | //CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InterpFromGridToMeshUsage);
|
---|
46 | if((nlhs!=NLHS) || (nrhs!=6 && nrhs!=7)){
|
---|
47 | InterpFromGridToMeshUsage();
|
---|
48 | _error_("usage. See above");
|
---|
49 | }
|
---|
50 |
|
---|
51 | /*Input datasets: */
|
---|
52 | FetchData(&x,&x_rows,NULL,XHANDLE);
|
---|
53 | FetchData(&y,&y_rows,NULL,YHANDLE);
|
---|
54 | FetchData(&data,&data_rows,&data_cols,DATAHANDLE);
|
---|
55 | FetchData(&x_mesh,&x_mesh_rows,NULL,XMESHHANDLE);
|
---|
56 | FetchData(&y_mesh,&y_mesh_rows,NULL,YMESHHANDLE);
|
---|
57 | FetchData(&default_value,DEFAULTHANDLE);
|
---|
58 |
|
---|
59 | /* Run core computations: */
|
---|
60 | if(nrhs==7){
|
---|
61 | FetchData(&interpolationenum,INTERPENUM);
|
---|
62 | InterpFromGridToMeshx(&data_mesh, x, x_rows, y, y_rows, data, data_rows,data_cols, x_mesh, y_mesh, x_mesh_rows,default_value,interpolationenum);
|
---|
63 | }
|
---|
64 | else{
|
---|
65 | InterpFromGridToMeshx(&data_mesh, x, x_rows, y, y_rows, data, data_rows,data_cols, x_mesh, y_mesh, x_mesh_rows,default_value);
|
---|
66 | }
|
---|
67 |
|
---|
68 | /*Write data: */
|
---|
69 | WriteData(DATAMESH,data_mesh);
|
---|
70 |
|
---|
71 | /*end module: */
|
---|
72 | MODULEEND();
|
---|
73 | }
|
---|
74 |
|
---|
75 | void InterpFromGridToMeshUsage(void)
|
---|
76 | {
|
---|
77 | _pprintLine_("INTERPFROMGRIDTOMESH - interpolation from a grid onto a list of points");
|
---|
78 | _pprintLine_("");
|
---|
79 | _pprintLine_(" This function is a multi-threaded mex file that interpolates a field");
|
---|
80 | _pprintLine_(" defined on a grid onto a list of points");
|
---|
81 | _pprintLine_("");
|
---|
82 | _pprintLine_(" Usage:");
|
---|
83 | _pprintLine_(" data_mesh=InterpFromGridToMesh(x,y,data,x_mesh,y_mesh,default_value);");
|
---|
84 | _pprintLine_("");
|
---|
85 | _pprintLine_(" data: matrix holding the data to be interpolated onto the mesh.");
|
---|
86 | _pprintLine_(" x,y: coordinates of matrix data. (x and y must be in increasing order)");
|
---|
87 | _pprintLine_(" x_mesh,y_mesh: coordinates of the points onto which we interpolate.");
|
---|
88 | _pprintLine_(" default_value: default value if no data is found (holes).");
|
---|
89 | _pprintLine_(" data_mesh: vector of mesh interpolated data.");
|
---|
90 | _pprintLine_("");
|
---|
91 | _pprintLine_(" Example:");
|
---|
92 | _pprintLine_(" load('velocities.mat');");
|
---|
93 | _pprintLine_(" md.inversion.vx_obs=InterpFromGridToMesh(x_n,y_m,vx,md.mesh.x,md.mesh.y,0);");
|
---|
94 | _pprintLine_("");
|
---|
95 | }
|
---|