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