Changeset 12118


Ignore:
Timestamp:
04/24/12 21:43:39 (13 years ago)
Author:
Eric.Larour
Message:

Adapted InterpFromMeshToMesh2d to python

Location:
issm/trunk-jpl/src/modules
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/modules/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp

    r12060 r12118  
    44#include "./InterpFromMeshToMesh2d.h"
    55
    6 void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
    76
    8         int i;
     7WRAPPER(InterpFromMeshToMesh2d){
    98
    109        /*input: */
    1110        double* index=NULL;
    1211        int     index_cols;
    13 
    1412        double* x_data=NULL;
    1513        int     x_data_rows;
    16 
    1714        double* y_data=NULL;
    1815        int     y_data_rows;
    19 
    2016        double* data=NULL;
    2117        int     data_rows;
    2218        int     data_cols;
    23 
    2419        double* x_interp=NULL;
     20        int     x_interp_rows;
    2521        double* y_interp=NULL;
    26 
    27         int     x_interp_rows;
    2822        int     y_interp_rows;
    29 
     23        char*   contourname=NULL;
    3024        double* default_values=NULL;
    3125        int     num_default_values=0;
    32 
    33         //contours
    34         mxArray*  matlabstructure=NULL;
    35         Contour** contours=NULL;
    36         int       numcontours;
    37         Contour*  contouri=NULL;
     26        DataSet *contours = NULL;
    3827
    3928        /*Intermediary*/
    40         int nods_data;
    4129        int nels_data;
    42         int nods_interp;
    43         int verbose=0;
    4430
    4531        /* output: */
     
    4935        MODULEBOOT();
    5036
    51         /*checks on arguments on the matlab side: */
     37        /*checks on output arguments on the matlab side: */
     38        #ifdef _HAVE_MATLAB_MODULES_
    5239        if(nlhs!=NLHS){
    5340                InterpFromMeshToMesh2dUsage();
    5441                _error_("InterpFromMeshToMesh2dUsage usage error");
    5542        }
     43        #endif
     44        /*check on input arguments: */
    5645        if((nrhs!=6) & (nrhs!=8)){
    5746                InterpFromMeshToMesh2dUsage();
     
    6049
    6150        /*Input datasets: */
    62         if (verbose) printf("Fetching inputs\n");
    63         FetchData(&index,&nels_data,&index_cols,INDEXHANDLE);
    64         FetchData(&x_data,&x_data_rows,NULL,XHANDLE);
    65         FetchData(&y_data,&y_data_rows,NULL,YHANDLE);
    66         FetchData(&data,&data_rows,&data_cols,DATAHANDLE);
    67         FetchData(&x_interp,&x_interp_rows,NULL,XINTERPHANDLE);
    68         FetchData(&y_interp,&y_interp_rows,NULL,YINTERPHANDLE);
     51        FetchData(&index,&nels_data,&index_cols,INDEX);
     52        FetchData(&x_data,&x_data_rows,NULL,X);
     53        FetchData(&y_data,&y_data_rows,NULL,Y);
     54        FetchData(&data,&data_rows,&data_cols,DATA);
     55        FetchData(&x_interp,&x_interp_rows,XINTERP);
     56        FetchData(&y_interp,&y_interp_rows,YINTERP);
    6957
     58        /*Figure out contours and default values: */
    7059        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 vertices %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                 /*}}}*/
     60                FetchData(&default_values,&num_default_values,DEFAULT);
     61                FetchData(&contourname,CONTOURNAME);
     62                contours=DomainOutlineRead(contourname);
    10263        }
    10364        else{
    10465                num_default_values=0;
    10566                default_values=NULL;
    106                 numcontours=0;
    107                 contours=NULL;
     67                contours=new DataSet();
    10868        }
    10969
     70
    11071        /*some checks*/
    111         if (verbose) printf("Checking inputs\n");
    11272        if (x_data_rows!=y_data_rows){
    11373                _error_("vectors x and y should have the same length!");
     
    12080        }
    12181
    122         /*get number of elements and number of nodes in the data*/
    123         nods_data=x_data_rows;
    124         nods_interp=x_interp_rows;
    125 
    12682        /* Run core computations: */
    127         if (verbose) printf("Call core\n");
    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);
     83        InterpFromMeshToMesh2dx(&data_interp,index,x_data,y_data,x_data_rows,nels_data,data,data_rows,data_cols,x_interp,y_interp,x_interp_rows,default_values,num_default_values,contours);
    12984
    13085        /*Write data: */
    131         WriteData(DATAINTERP,data_interp,nods_interp,data_cols);
     86        WriteData(DATAINTERP,data_interp,x_interp_rows,data_cols);
    13287
    13388        /*end module: */
     
    13590}
    13691
    137 void InterpFromMeshToMesh2dUsage(void)
     92void InterpFromMeshToMesh2dUsage(void)//{{{1
     93
    13894{
    13995        _printf_(true,"INTERFROMMESHTOMESH2D - interpolation from a 2d triangular mesh onto a list of point\n");
     
    161117        _printf_(true,"\n");
    162118}
     119//}}}
  • issm/trunk-jpl/src/modules/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h

    r12013 r12118  
    66#define _INTERPFROMMESHTOMESH2d_H
    77
    8 /* local prototypes: */
    9 void InterpFromMeshToMesh2dUsage(void);
     8#ifdef HAVE_CONFIG_H
     9        #include <config.h>
     10#else
     11#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
     12#endif
    1013
     14/*Very important definition in case we are compiling a python module!: needs to come before header files inclusion*/
     15#ifdef _HAVE_PYTHON_
     16#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
     17#endif
     18
     19/*Header files: */
    1120#include "../../c/include/globals.h"
     21#include "../../c/toolkits/toolkits.h"
     22#include "../../c/include/include.h"
    1223#include "../../c/modules/modules.h"
    1324#include "../../c/Container/Container.h"
    1425#include "../../c/shared/shared.h"
    1526#include "../../c/issm-binding.h"
     27#include "../../c/io/io.h"
     28#include "../../c/EnumDefinitions/EnumDefinitions.h"
     29
     30#ifdef _HAVE_MATLAB_MODULES_
     31/* serial input macros: */
     32#define INDEX prhs[0]
     33#define X prhs[1]
     34#define Y prhs[2]
     35#define DATA prhs[3]
     36#define XINTERP prhs[4]
     37#define YINTERP prhs[5]
     38#define DEFAULT prhs[6]
     39#define CONTOURNAME prhs[7]
     40
     41/* serial output macros: */
     42#define DATAINTERP (mxArray**)&plhs[0]
     43#endif
     44
     45#ifdef _HAVE_PYTHON_MODULES_
     46/* serial input macros: */
     47#define INDEX PyTuple_GetItem(args,0)
     48#define X PyTuple_GetItem(args,1)
     49#define Y PyTuple_GetItem(args,2)
     50#define DATA PyTuple_GetItem(args,3)
     51#define XINTERP PyTuple_GetItem(args,4)
     52#define YINTERP PyTuple_GetItem(args,5)
     53#define DEFAULT PyTuple_GetItem(args,6)
     54#define CONTOURNAME PyTuple_GetItem(args,7)
     55/* serial output macros: */
     56#define DATAINTERP output,0
     57#endif
    1658
    1759#undef __FUNCT__
    1860#define __FUNCT__  "InterpFromMeshToMesh2d"
    1961
    20 
    21 /* serial input macros: */
    22 #define INDEXHANDLE prhs[0]
    23 #define XHANDLE prhs[1]
    24 #define YHANDLE prhs[2]
    25 #define DATAHANDLE prhs[3]
    26 #define XINTERPHANDLE prhs[4]
    27 #define YINTERPHANDLE prhs[5]
    28 #define DEFAULTHANDLE prhs[6]
    29 #define FILENAME prhs[7]
    30 
    31 /* serial output macros: */
    32 #define DATAINTERP (mxArray**)&plhs[0]
    33 
    3462/* serial arg counts: */
    3563#undef NLHS
    3664#define NLHS  1
     65#undef NRHS
     66#define NRHS  6 //can be 8 though
     67
     68/* local prototypes: */
     69void InterpFromMeshToMesh2dUsage(void);
    3770
    3871#endif
  • issm/trunk-jpl/src/modules/python/Makefile.am

    r12112 r12118  
    33#Bin programs {{{1
    44if MODULES
    5 bin_PROGRAMS = TriMesh \
    6                            NodeConnectivity \
    7                            ElementConnectivity
     5bin_PROGRAMS = ElementConnectivity\
     6                           InterpFromMeshToMesh2d \
     7                           NodeConnectivity\
     8                           TriMesh
    89endif
    910#}}}
     
    3132                          ../ElementConnectivity/ElementConnectivity.h
    3233
     34InterpFromMeshToMesh2d_SOURCES = ../InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp\
     35                                                        ../InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h
     36
    3337NodeConnectivity_SOURCES = ../NodeConnectivity/NodeConnectivity.cpp\
    3438                                                                                ../NodeConnectivity/NodeConnectivity.h
Note: See TracChangeset for help on using the changeset viewer.