Ignore:
Timestamp:
08/06/10 14:48:41 (15 years ago)
Author:
Eric.Larour
Message:

Added InterpFromMesh2d module, from ISSM2.0, to go around some of Bamg
error messages. We'll get rid of it later, when bugs are addressed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/mex/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp

    r4981 r5032  
    55
    66void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
     7
     8        int i;
    79
    810        /*input: */
     
    2628        int     y_interp_rows;
    2729
    28         double default_value;
     30        double* default_values=NULL;
     31        int     num_default_values=0;
     32
     33        //contours
     34        mxArray*  matlabstructure=NULL;
     35        Contour** contours=NULL;
     36        int       numcontours;
     37        Contour*  contouri=NULL;
    2938
    3039        /*Intermediary*/
     
    4150
    4251        /*checks on arguments on the matlab side: */
    43         CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InterpFromMeshToMesh2dUsage);
     52        if(nlhs!=NLHS){
     53                InterpFromMeshToMesh2dUsage();
     54                ISSMERROR("InterpFromMeshToMesh2dUsage usage error");
     55        }
     56        if((nrhs!=6) & (nrhs!=8)){
     57                InterpFromMeshToMesh2dUsage();
     58                ISSMERROR("InterpFromMeshToMesh2dUsage usage error");
     59        }
    4460
    4561        /*Input datasets: */
     
    5167        FetchData(&x_interp,&x_interp_rows,NULL,XINTERPHANDLE);
    5268        FetchData(&y_interp,&y_interp_rows,NULL,YINTERPHANDLE);
    53         FetchData(&default_value,DEFAULTHANDLE);
     69
     70        if(nrhs==8){
     71               
     72                /*Call expread on filename to build a contour array in the matlab workspace: */
     73                mexCallMATLAB( 1, &matlabstructure, 1, (mxArray**)&FILENAME, "expread");
     74
     75                /*default values: */
     76                FetchData(&default_values,&num_default_values,DEFAULTHANDLE);
     77
     78                /*contours: */
     79                numcontours=mxGetNumberOfElements(matlabstructure);
     80                contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
     81                for(i=0;i<numcontours;i++){
     82                        //allocate
     83                        contouri=(Contour*)xmalloc(sizeof(Contour));
     84                        //retrieve dimension of this contour.
     85                        contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
     86                        //set pointers.
     87                        contouri->x=mxGetPr(mxGetField(matlabstructure,i,"x"));
     88                        contouri->y=mxGetPr(mxGetField(matlabstructure,i,"y"));
     89                        *(contours+i)=contouri;
     90                }
     91
     92                /* Debugging of contours :{{{1*/
     93                /*for(i=0;i<numcontours;i++){
     94                  printf("\nContour echo: contour number  %i / %i\n",i+1,numcontours);
     95                  contouri=*(contours+i);
     96                  printf("   Number of grids %i\n",contouri->nods);
     97                  for (j=0;j<contouri->nods;j++){
     98                  printf("   %lf %lf\n",*(contouri->x+j),*(contouri->y+j));
     99                  }
     100                  }*/
     101                /*}}}*/
     102        }
     103        else{
     104                num_default_values=0;
     105                default_values=NULL;
     106                numcontours=0;
     107                contours=NULL;
     108        }
    54109
    55110        /*some checks*/
     
    71126        /* Run core computations: */
    72127        if (verbose) printf("Call core\n");
    73         InterpFromMeshToMesh2dx(&data_interp,index,x_data,y_data,nods_data,nels_data,data,data_rows,data_cols,x_interp,y_interp,nods_interp,default_value);
     128        InterpFromMeshToMesh2dx(&data_interp,index,x_data,y_data,nods_data,nels_data,data,data_rows,data_cols,x_interp,y_interp,nods_interp,default_values,num_default_values,contours,numcontours);
    74129
    75130        /*Write data: */
     
    88143        _printf_("\n");
    89144        _printf_("   Usage:\n");
    90         _printf_("      data_interp=InterpFromMeshToMesh2d(index,x,y,data,x_interp,y_interp,default_value);\n");
     145        _printf_("         data_interp=InterpFromMeshToMesh2d(index,x,y,data,x_interp,y_interp);\n");
     146        _printf_("      or data_interp=InterpFromMeshToMesh2d(index,x,y,data,x_interp,y_interp,default_value,contourname);\n");
    91147        _printf_("\n");
    92148        _printf_("      index: index of the mesh where data is defined\n");
     
    94150        _printf_("      data: matrix holding the data to be interpolated onto the mesh. (one column per field)\n");
    95151        _printf_("      x_interp,y_interp: coordinates of the points onto which we interpolate.\n");
    96         _printf_("      default_value: default value if no data is found (holes).\n");
     152        _printf_("      if default_value and contourname not specified: linear interpolation will happen on all x_interp,y_interp.\n");
     153        _printf_("      if (default_value,contourname) specified: linear interpolation will happen on all x_interp,y_interp inside the contour, default value will be adopted on the rest of the mesh.\n");
     154        _printf_("      note that default_value is either a scalar, or a vector of size  length(x_interp)\n");
    97155        _printf_("      data_interp: vector of mesh interpolated data.\n");
    98156        _printf_("\n");
Note: See TracChangeset for help on using the changeset viewer.