Changeset 1174
- Timestamp:
- 06/30/09 09:51:45 (16 years ago)
- Location:
- issm/trunk/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/InterpFromGridx/InterpFromGridx.cpp
r1172 r1174 11 11 int findindices(int* pm,int* pn,double* x,int x_rows, double* y,int y_rows, double xgrid,double ygrid); 12 12 13 int InterpFromGridx( Vec* pdata_mesh,double* x_in, int x_rows, double* y_in, int y_rows, double* data, int M, int N, double* x_mesh, double* y_mesh, int nods ) {13 int InterpFromGridx( Vec* pdata_mesh,double* x_in, int x_rows, double* y_in, int y_rows, double* data, int M, int N, double* x_mesh, double* y_mesh, int nods,double default_value) { 14 14 15 15 … … 21 21 double* y=NULL; 22 22 int i,m,n; 23 int ind;24 double dis;25 23 double x_grid,y_grid; 26 24 double xi,eta; … … 116 114 } 117 115 118 /*Treat NANs : take the closest non nan value avomg neighbors*/116 /*Treat NANs*/ 119 117 if isnan(data_value){ 120 ind=m*N+n; 121 dis=pow(x[n+1]-x[n],2); 122 if ( ((pow(y_grid-y[m],2)+pow(x_grid-x[n+1],2))<dis) && (!isnan(data[m*N+n+1]))){ 123 ind=m*N+n+1; 124 dis=pow(y_grid-y[m],2)+pow(x_grid-x[n+1],2); 125 } 126 if ( ((pow(y_grid-y[m+1],2)+pow(x_grid-x[n],2))<dis) && (!isnan(data[(m+1)*N+n]))){ 127 ind=(m+1)*N+n; 128 dis=pow(y_grid-y[m+1],2)+pow(x_grid-x[n],2); 129 } 130 if ( ((pow(y_grid-y[m+1],2)+pow(x_grid-x[n+1],2))<dis) && (!isnan(data[(m+1)*N+n+1]))){ 131 ind=(m+1)*N+n+1; 132 dis=pow(y_grid-y[m+1],2)+pow(x_grid-x[n+1],2); 133 } 134 data_value=*(data+ind); 118 data_value=default_value; 135 119 } 136 120 } 137 121 else{ 138 data_value= -9999;122 data_value=default_value; 139 123 } 140 VecSetValue s(data_mesh,1,&i,&data_value,INSERT_VALUES);124 VecSetValue(data_mesh,i,data_value,INSERT_VALUES); 141 125 } 142 126 -
issm/trunk/src/c/InterpFromGridx/InterpFromGridx.h
r1172 r1174 8 8 #include "../toolkits/toolkits.h" 9 9 10 int InterpFromGridx( Vec* pdata_mesh,double* x, int x_rows, double* y, int y_rows, double* data, int M, int N, double* x_mesh, double* y_mesh, int nods );10 int InterpFromGridx( Vec* pdata_mesh,double* x, int x_rows, double* y, int y_rows, double* data, int M, int N, double* x_mesh, double* y_mesh, int nods, double default_value); 11 11 12 12 #endif /* _INTERPFROMGRIDX_H */ -
issm/trunk/src/m/classes/public/plugvelocities.m
r278 r1174 1 function md=plugvelocities(md,filename )1 function md=plugvelocities(md,filename,default_value) 2 2 %PLUGVELOCITIES - load velocities on a model 3 3 % … … 7 7 % 8 8 % Usage: 9 % md=plugvelocities(md,filename )9 % md=plugvelocities(md,filename,default_value) 10 10 % 11 11 % Example: 12 % md=plugvelocities(md,'velocityfile.mat' );12 % md=plugvelocities(md,'velocityfile.mat',0); 13 13 % 14 % See also: PLUGDATA, GRIDDATA, GRIDDATA_MESH_TO_MESH, DATAINTERP14 % See also: INTERPFROMFILE, GRIDDATA 15 15 16 16 %some checks 17 if nargin~= 2| nargout~=117 if nargin~=3 | nargout~=1 18 18 help plugvelocities 19 19 error('plugvelocities error message: bad usage'); … … 94 94 95 95 %interpolate 96 if length(x)==size(vx,2) 97 md.vx_obs=griddata(x,y,vx,md.x,md.y); 98 md.vy_obs=griddata(x,y,vy,md.x,md.y); 99 100 else 101 md.vx_obs=DataInterp(x,y,vx,md.x,md.y); 102 md.vy_obs=DataInterp(x,y,vy,md.x,md.y); 103 end 96 md.vx_obs=InterpFromGrid(x,y,vx,md.x,md.y,default_value); 97 md.vy_obs=InterpFromGrid(x,y,vy,md.x,md.y,default_value); 104 98 md.vx=md.vx_obs; 105 99 md.vy=md.vy_obs; -
issm/trunk/src/m/utils/Interp/InterpFromFile.m
r1173 r1174 1 function data_out=InterpFromFile(x,y,filename )1 function data_out=InterpFromFile(x,y,filename,default_value) 2 2 %INTERPFROMFILE - load data and interpolate on the given nodes 3 3 % … … 16 16 % 17 17 % Usage: 18 % data=InterpFromFile(x,y,filename );18 % data=InterpFromFile(x,y,filename,default_value); 19 19 % 20 20 % Example: 21 % md.surface=InterpFromFile(md.x,md.y,'surfacefile.mat' );21 % md.surface=InterpFromFile(md.x,md.y,'surfacefile.mat',0); 22 22 % 23 23 % See also: PLUGVELOCITIES, INTERPFROMGRID, INTERPFROMMESH2D, INTERPFROMMESH3D 24 24 25 25 %some checks 26 if nargin~= 3| nargout~=126 if nargin~=4 | nargout~=1 27 27 help InterpFromFile 28 28 error('plugdata error message: bad usage'); … … 200 200 201 201 %interpolate 202 data_out=InterpFromMesh2d(index_data,x_data,y_data,data,x,y );202 data_out=InterpFromMesh2d(index_data,x_data,y_data,data,x,y,default_value); 203 203 204 204 else … … 218 218 219 219 %interpolate 220 data_out=InterpFromGrid(x_data,y_data,data,x,y );221 end 220 data_out=InterpFromGrid(x_data,y_data,data,x,y,default_value); 221 end -
issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.cpp
r1172 r1174 27 27 /*input: */ 28 28 double* x=NULL; 29 double* y=NULL; 30 29 31 int x_rows; 30 31 double* y=NULL;32 32 int y_rows; 33 33 … … 40 40 int x_mesh_rows; 41 41 int y_mesh_rows; 42 43 double default_value; 42 44 43 45 /* output: */ … … 56 58 FetchData((void**)&x_mesh,&x_mesh_rows,NULL,XMESHHANDLE,"Matrix","Mat"); 57 59 FetchData((void**)&y_mesh,&y_mesh_rows,NULL,YMESHHANDLE,"Matrix","Mat"); 60 FetchData((void**)&default_value,NULL,NULL,DEFAULTHANDLE,"Scalar",NULL); 58 61 59 62 /* Run core computations: */ 60 InterpFromGridx( &data_mesh, x, x_rows, y, y_rows, data, data_rows,data_cols, x_mesh, y_mesh, x_mesh_rows );63 InterpFromGridx( &data_mesh, x, x_rows, y, y_rows, data, data_rows,data_cols, x_mesh, y_mesh, x_mesh_rows,default_value); 61 64 62 65 /*Write data: */ … … 70 73 { 71 74 _printf_(" usage:\n"); 72 _printf_(" data_mesh=InterpFromGrid(x,y,data,x_mesh,y_mesh );\n\n");75 _printf_(" data_mesh=InterpFromGrid(x,y,data,x_mesh,y_mesh,defult_value);\n\n"); 73 76 _printf_(" where:\n"); 74 77 _printf_(" x,y: coordinates of matrix data\n"); 75 78 _printf_(" data - matrix holding the data to be interpolated onto the mesh.\n"); 76 79 _printf_(" x_mesh,y_mesh: coordinates of the mesh grids onto which we interpolate.\n"); 80 _printf_(" default_value: default value if no interpolation is found.\n"); 77 81 _printf_(" data_mesh: vector of mesh interpolated data.\n"); 78 82 _printf_("\n"); -
issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.h
r1172 r1174 24 24 #define XMESHHANDLE prhs[3] 25 25 #define YMESHHANDLE prhs[4] 26 #define DEFAULTHANDLE prhs[5] 26 27 27 28 /* serial output macros: */ … … 32 33 #define NLHS 1 33 34 #undef NRHS 34 #define NRHS 535 #define NRHS 6 35 36 36 37 #endif /* _INTERPFROMGRId_H */ -
issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.cpp
r1172 r1174 43 43 int y_prime_rows; 44 44 45 double default_value; 46 45 47 /*Intermediary*/ 46 48 int i,j; … … 71 73 FetchData((void**)&x_prime,&x_prime_rows,NULL,XPRIMEHANDLE,"Matrix","Mat"); 72 74 FetchData((void**)&y_prime,&y_prime_rows,NULL,YPRIMEHANDLE,"Matrix","Mat"); 75 FetchData((void**)&default_value,NULL,NULL,DEFAULTHANDLE,"Scalar",NULL); 73 76 74 77 /* Run core computations: */ … … 76 79 77 80 /*some checks*/ 81 if (index_data_rows<1 || x_data_rows<3 || y_data_rows<3){ 82 throw ErrorException(__FUNCT__,"nothing to be done according to the mesh given in input"); 83 } 78 84 if (x_data_rows!=y_data_rows){ 79 85 throw ErrorException(__FUNCT__,"vectors x and y should have the same length!"); … … 151 157 data_value=data[i]; 152 158 } 159 if isnan(data_value) data_value=default_value; 153 160 154 161 /*insert value and go to the next point*/ … … 169 176 { 170 177 _printf_(" usage:\n"); 171 _printf_(" data_prime=InterpFromMesh2d(index,x,y,data,x_prime,y_prime );\n\n");178 _printf_(" data_prime=InterpFromMesh2d(index,x,y,data,x_prime,y_prime,default_value);\n\n"); 172 179 _printf_(" where:\n"); 173 180 _printf_(" x,y: coordinates of the nodes where data is defined\n"); … … 175 182 _printf_(" data - vector holding the data to be interpolated onto the points.\n"); 176 183 _printf_(" x_prime,y_prime: coordinates of the mesh grids onto which we interpolate.\n"); 184 _printf_(" default_value - default value if no interpolation is found.\n"); 177 185 _printf_(" data_prime: vector of prime interpolated data.\n"); 178 186 _printf_("\n"); -
issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.h
r1172 r1174 25 25 #define XPRIMEHANDLE prhs[4] 26 26 #define YPRIMEHANDLE prhs[5] 27 #define DEFAULTHANDLE prhs[6] 27 28 28 29 /* serial output macros: */ … … 33 34 #define NLHS 1 34 35 #undef NRHS 35 #define NRHS 636 #define NRHS 7 36 37 37 #endif /* _ DATAINTERP2_H */38 #endif /* _INTERPFROMMESH2D_H */ -
issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.cpp
r1172 r1174 46 46 int y_prime_rows; 47 47 int z_prime_rows; 48 49 double default_value; 48 50 49 51 /*Intermediary*/ … … 78 80 FetchData((void**)&y_prime,&y_prime_rows,NULL,YPRIMEHANDLE,"Matrix","Mat"); 79 81 FetchData((void**)&z_prime,&z_prime_rows,NULL,ZPRIMEHANDLE,"Matrix","Mat"); 82 FetchData((void**)&default_value,NULL,NULL,DEFAULTHANDLE,"Scalar",NULL); 80 83 81 84 /*some checks*/ … … 166 169 data_value=data[i]; 167 170 } 171 if isnan(data_value) data_value=default_value; 168 172 169 173 /*insert value and go to the next point*/ … … 185 189 { 186 190 _printf_(" usage:\n"); 187 _printf_(" data_prime=InterpFromMesh3d(index,x,y,z,data,x_prime,y_prime,z_prime );\n\n");191 _printf_(" data_prime=InterpFromMesh3d(index,x,y,z,data,x_prime,y_prime,z_prime,default_value);\n\n"); 188 192 _printf_(" where:\n"); 189 193 _printf_(" x,y,z: coordinates of the nodes where data is defined\n"); … … 191 195 _printf_(" data - vector holding the data to be interpolated onto the points.\n"); 192 196 _printf_(" x_prime,y_prime,z_prime: coordinates of the mesh grids onto which we interpolate.\n"); 197 _printf_(" default_value - default value if no interpolation is found.\n"); 193 198 _printf_(" data_prime: vector of prime interpolated data.\n"); 194 199 _printf_("\n"); -
issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.h
r1172 r1174 27 27 #define YPRIMEHANDLE prhs[6] 28 28 #define ZPRIMEHANDLE prhs[7] 29 #define DEFAULTHANDLE prhs[8] 29 30 30 31 /* serial output macros: */ … … 35 36 #define NLHS 1 36 37 #undef NRHS 37 #define NRHS 838 #define NRHS 9 38 39 39 40 #endif /* _INTERPFROMMESH3D_H */
Note:
See TracChangeset
for help on using the changeset viewer.