Changeset 1174


Ignore:
Timestamp:
06/30/09 09:51:45 (16 years ago)
Author:
Mathieu Morlighem
Message:

added default value as an argument

Location:
issm/trunk/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/InterpFromGridx/InterpFromGridx.cpp

    r1172 r1174  
    1111int findindices(int* pm,int* pn,double* x,int x_rows, double* y,int y_rows, double xgrid,double ygrid);
    1212
    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) {
     13int 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) {
    1414
    1515
     
    2121        double* y=NULL;
    2222        int i,m,n;
    23         int ind;
    24         double dis;
    2523        double x_grid,y_grid;
    2624        double xi,eta;
     
    116114                        }
    117115
    118                         /*Treat NANs: take the closest non nan value avomg neighbors*/
     116                        /*Treat NANs*/
    119117                        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;
    135119                        }
    136120                }
    137121                else{
    138                         data_value=-9999;
     122                        data_value=default_value;
    139123                }
    140                 VecSetValues(data_mesh,1,&i,&data_value,INSERT_VALUES);
     124                VecSetValue(data_mesh,i,data_value,INSERT_VALUES);
    141125        }
    142126
  • issm/trunk/src/c/InterpFromGridx/InterpFromGridx.h

    r1172 r1174  
    88#include "../toolkits/toolkits.h"
    99
    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);
     10int 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);
    1111
    1212#endif /* _INTERPFROMGRIDX_H */
  • issm/trunk/src/m/classes/public/plugvelocities.m

    r278 r1174  
    1 function md=plugvelocities(md,filename)
     1function md=plugvelocities(md,filename,default_value)
    22%PLUGVELOCITIES - load velocities on a model
    33%
     
    77%
    88%   Usage:
    9 %      md=plugvelocities(md,filename)
     9%      md=plugvelocities(md,filename,default_value)
    1010%
    1111%   Example:
    12 %      md=plugvelocities(md,'velocityfile.mat');
     12%      md=plugvelocities(md,'velocityfile.mat',0);
    1313%
    14 %   See also: PLUGDATA, GRIDDATA, GRIDDATA_MESH_TO_MESH, DATAINTERP
     14%   See also: INTERPFROMFILE, GRIDDATA
    1515
    1616%some checks
    17 if nargin~=2 | nargout~=1
     17if nargin~=3 | nargout~=1
    1818        help plugvelocities
    1919        error('plugvelocities error message: bad usage');
     
    9494
    9595%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
     96md.vx_obs=InterpFromGrid(x,y,vx,md.x,md.y,default_value);
     97md.vy_obs=InterpFromGrid(x,y,vy,md.x,md.y,default_value);
    10498md.vx=md.vx_obs;
    10599md.vy=md.vy_obs;
  • issm/trunk/src/m/utils/Interp/InterpFromFile.m

    r1173 r1174  
    1 function data_out=InterpFromFile(x,y,filename)
     1function data_out=InterpFromFile(x,y,filename,default_value)
    22%INTERPFROMFILE - load data and interpolate on the given nodes
    33%
     
    1616%
    1717%   Usage:
    18 %      data=InterpFromFile(x,y,filename);
     18%      data=InterpFromFile(x,y,filename,default_value);
    1919%
    2020%   Example:
    21 %      md.surface=InterpFromFile(md.x,md.y,'surfacefile.mat');
     21%      md.surface=InterpFromFile(md.x,md.y,'surfacefile.mat',0);
    2222%
    2323%   See also: PLUGVELOCITIES, INTERPFROMGRID, INTERPFROMMESH2D, INTERPFROMMESH3D
    2424
    2525%some checks
    26 if nargin~=3 | nargout~=1
     26if nargin~=4 | nargout~=1
    2727        help InterpFromFile
    2828        error('plugdata error message: bad usage');
     
    200200
    201201        %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);
    203203
    204204else
     
    218218
    219219        %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);
     221end
  • issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.cpp

    r1172 r1174  
    2727        /*input: */
    2828        double* x=NULL;
     29        double* y=NULL;
     30
    2931        int     x_rows;
    30        
    31         double* y=NULL;
    3232        int     y_rows;
    3333
     
    4040        int     x_mesh_rows;
    4141        int     y_mesh_rows;
     42
     43        double default_value;
    4244
    4345        /* output: */
     
    5658        FetchData((void**)&x_mesh,&x_mesh_rows,NULL,XMESHHANDLE,"Matrix","Mat");
    5759        FetchData((void**)&y_mesh,&y_mesh_rows,NULL,YMESHHANDLE,"Matrix","Mat");
     60        FetchData((void**)&default_value,NULL,NULL,DEFAULTHANDLE,"Scalar",NULL);
    5861
    5962        /* 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);
    6164
    6265        /*Write data: */
     
    7073{
    7174        _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");
    7376        _printf_("   where:\n");
    7477        _printf_("      x,y: coordinates of matrix data\n");
    7578        _printf_("      data - matrix holding the data to be interpolated onto the mesh.\n");
    7679        _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");
    7781        _printf_("      data_mesh:  vector of mesh interpolated data.\n");
    7882        _printf_("\n");
  • issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.h

    r1172 r1174  
    2424#define XMESHHANDLE prhs[3]
    2525#define YMESHHANDLE prhs[4]
     26#define DEFAULTHANDLE prhs[5]
    2627
    2728/* serial output macros: */
     
    3233#define NLHS  1
    3334#undef NRHS
    34 #define NRHS  5
     35#define NRHS  6
    3536
    3637#endif  /* _INTERPFROMGRId_H */
  • issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.cpp

    r1172 r1174  
    4343        int     y_prime_rows;
    4444
     45        double default_value;
     46
    4547        /*Intermediary*/
    4648        int i,j;
     
    7173        FetchData((void**)&x_prime,&x_prime_rows,NULL,XPRIMEHANDLE,"Matrix","Mat");
    7274        FetchData((void**)&y_prime,&y_prime_rows,NULL,YPRIMEHANDLE,"Matrix","Mat");
     75        FetchData((void**)&default_value,NULL,NULL,DEFAULTHANDLE,"Scalar",NULL);
    7376
    7477        /* Run core computations: */
     
    7679
    7780        /*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        }
    7884        if (x_data_rows!=y_data_rows){
    7985                throw ErrorException(__FUNCT__,"vectors x and y should have the same length!");
     
    151157                                        data_value=data[i];
    152158                                }
     159                                if isnan(data_value) data_value=default_value;
    153160
    154161                                /*insert value and go to the next point*/
     
    169176{
    170177        _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");
    172179        _printf_("   where:\n");
    173180        _printf_("      x,y: coordinates of the nodes where data is defined\n");
     
    175182        _printf_("      data - vector holding the data to be interpolated onto the points.\n");
    176183        _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");
    177185        _printf_("      data_prime:  vector of prime interpolated data.\n");
    178186        _printf_("\n");
  • issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.h

    r1172 r1174  
    2525#define XPRIMEHANDLE prhs[4]
    2626#define YPRIMEHANDLE prhs[5]
     27#define DEFAULTHANDLE prhs[6]
    2728
    2829/* serial output macros: */
     
    3334#define NLHS  1
    3435#undef NRHS
    35 #define NRHS  6
     36#define NRHS  7
    3637
    37 #endif  /* _DATAINTERP2_H */
     38#endif  /* _INTERPFROMMESH2D_H */
  • issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.cpp

    r1172 r1174  
    4646        int     y_prime_rows;
    4747        int     z_prime_rows;
     48
     49        double  default_value;
    4850
    4951        /*Intermediary*/
     
    7880        FetchData((void**)&y_prime,&y_prime_rows,NULL,YPRIMEHANDLE,"Matrix","Mat");
    7981        FetchData((void**)&z_prime,&z_prime_rows,NULL,ZPRIMEHANDLE,"Matrix","Mat");
     82        FetchData((void**)&default_value,NULL,NULL,DEFAULTHANDLE,"Scalar",NULL);
    8083
    8184        /*some checks*/
     
    166169                                                data_value=data[i];
    167170                                        }
     171                                        if isnan(data_value) data_value=default_value;
    168172
    169173                                        /*insert value and go to the next point*/
     
    185189{
    186190        _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");
    188192        _printf_("   where:\n");
    189193        _printf_("      x,y,z: coordinates of the nodes where data is defined\n");
     
    191195        _printf_("      data - vector holding the data to be interpolated onto the points.\n");
    192196        _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");
    193198        _printf_("      data_prime:  vector of prime interpolated data.\n");
    194199        _printf_("\n");
  • issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.h

    r1172 r1174  
    2727#define YPRIMEHANDLE prhs[6]
    2828#define ZPRIMEHANDLE prhs[7]
     29#define DEFAULTHANDLE prhs[8]
    2930
    3031/* serial output macros: */
     
    3536#define NLHS  1
    3637#undef NRHS
    37 #define NRHS  8
     38#define NRHS  9
    3839
    3940#endif  /* _INTERPFROMMESH3D_H */
Note: See TracChangeset for help on using the changeset viewer.