1 | /*!\file InterpFromMesh2d.c
|
---|
2 | * \brief: data interpolation from a list of (x,y,values) into mesh grids
|
---|
3 |
|
---|
4 | InterpFromMesh2d.c
|
---|
5 |
|
---|
6 | usage:
|
---|
7 | data_mesh=InterpFromMesh2d(index,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 grids onto which we interpolate.
|
---|
15 |
|
---|
16 | output:
|
---|
17 | data_mesh: vector of mesh interpolated data.
|
---|
18 |
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "./InterpFromMesh2d.h"
|
---|
22 |
|
---|
23 | void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
|
---|
24 |
|
---|
25 | /*input: */
|
---|
26 | double* index_data=NULL;
|
---|
27 | int index_data_rows;
|
---|
28 |
|
---|
29 | double* x_data=NULL;
|
---|
30 | int x_data_rows;
|
---|
31 |
|
---|
32 | double* y_data=NULL;
|
---|
33 | int y_data_rows;
|
---|
34 |
|
---|
35 | double* data=NULL;
|
---|
36 | int data_rows;
|
---|
37 | int data_cols;
|
---|
38 |
|
---|
39 | double* x_prime=NULL;
|
---|
40 | double* y_prime=NULL;
|
---|
41 |
|
---|
42 | int x_prime_rows;
|
---|
43 | int y_prime_rows;
|
---|
44 |
|
---|
45 | double default_value;
|
---|
46 |
|
---|
47 | /*Intermediary*/
|
---|
48 | int nods_data;
|
---|
49 | int nels_data;
|
---|
50 | int nods_prime;
|
---|
51 |
|
---|
52 | /* output: */
|
---|
53 | Vec data_prime=NULL;
|
---|
54 |
|
---|
55 | /*Boot module: */
|
---|
56 | MODULEBOOT();
|
---|
57 |
|
---|
58 | /*checks on arguments on the matlab side: */
|
---|
59 | CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InterpFromMesh2dUsage);
|
---|
60 |
|
---|
61 | /*Input datasets: */
|
---|
62 | FetchData((void**)&index_data,&index_data_rows,NULL,INDEXHANDLE,"Matrix","Mat");
|
---|
63 | FetchData((void**)&x_data,&x_data_rows,NULL,XHANDLE,"Matrix","Mat");
|
---|
64 | FetchData((void**)&y_data,&y_data_rows,NULL,YHANDLE,"Matrix","Mat");
|
---|
65 | FetchData((void**)&data,&data_rows,&data_cols,DATAHANDLE,"Matrix","Mat");
|
---|
66 | FetchData((void**)&x_prime,&x_prime_rows,NULL,XPRIMEHANDLE,"Matrix","Mat");
|
---|
67 | FetchData((void**)&y_prime,&y_prime_rows,NULL,YPRIMEHANDLE,"Matrix","Mat");
|
---|
68 | FetchData((void**)&default_value,NULL,NULL,DEFAULTHANDLE,"Scalar",NULL);
|
---|
69 |
|
---|
70 | /*some checks*/
|
---|
71 | if (x_data_rows!=y_data_rows){
|
---|
72 | throw ErrorException(__FUNCT__,"vectors x and y should have the same length!");
|
---|
73 | }
|
---|
74 | if (x_prime_rows!=y_prime_rows){
|
---|
75 | throw ErrorException(__FUNCT__,"vectors x_prime and y_prime should have the same length!");
|
---|
76 | }
|
---|
77 |
|
---|
78 | /*get number of elements and number of nodes in the data*/
|
---|
79 | nels_data=index_data_rows;
|
---|
80 | nods_data=x_data_rows;
|
---|
81 | nods_prime=x_prime_rows;
|
---|
82 |
|
---|
83 | /* Run core computations: */
|
---|
84 | InterpFromMesh2dx(&data_prime,index_data,x_data,y_data,nods_data,nels_data,data,data_rows,x_prime,y_prime,nods_prime,default_value);
|
---|
85 |
|
---|
86 | /*Write data: */
|
---|
87 | WriteData(DATAPRIME,data_prime,0,0,"Vector",NULL);
|
---|
88 |
|
---|
89 | /*end module: */
|
---|
90 | MODULEEND();
|
---|
91 | }
|
---|
92 |
|
---|
93 | void InterpFromMesh2dUsage(void)
|
---|
94 | {
|
---|
95 | _printf_(" usage:\n");
|
---|
96 | _printf_(" data_prime=InterpFromMesh2d(index,x,y,data,x_prime,y_prime,default_value);\n\n");
|
---|
97 | _printf_(" where:\n");
|
---|
98 | _printf_(" x,y: coordinates of the nodes where data is defined\n");
|
---|
99 | _printf_(" index: index of the mesh where data is defined\n");
|
---|
100 | _printf_(" data - vector holding the data to be interpolated onto the points.\n");
|
---|
101 | _printf_(" x_prime,y_prime: coordinates of the mesh grids onto which we interpolate.\n");
|
---|
102 | _printf_(" default_value - default value if no interpolation is found.\n");
|
---|
103 | _printf_(" data_prime: vector of prime interpolated data.\n");
|
---|
104 | _printf_("\n");
|
---|
105 | }
|
---|