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