Changeset 13586


Ignore:
Timestamp:
10/10/12 13:46:23 (12 years ago)
Author:
Mathieu Morlighem
Message:

CHG: rewriting TriMeshProcessRifts so that it looks more like a module

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/modules/BamgMesher/BamgMesher.h

    r13236 r13586  
    11/*
    2         BamgMesherUsage.h
     2        BamgMesher.h
    33*/
    44
  • issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp

    r13236 r13586  
    3535        mwSize          dimensions[2] = {1,1};
    3636        double* pair=NULL;
    37 
    3837       
    3938        /* input: */
    40         double *tindex_in = NULL;
    4139        double *index_in  = NULL;
    4240        int     nel;
    43         double *x_inm = NULL; //matlab vector
    4441        double *x_in  = NULL; //copy of matlab vector
    4542        int     nods;
    46         double *y_inm              = NULL; //matlab vector
    4743        double *y_in               = NULL; //copy of matlab vector
    48         double *tsegments_in       = NULL;
    4944        double *segments_in        = NULL;
    50         double *tsegmentmarkers_in = NULL;
    5145        double *segmentmarkers_in  = NULL;
    5246
     
    5953        int     numrifts;
    6054
    61         /* verify correct usage: */
    62         if (nlhs==0 && nrhs==0){
    63                 /* special case: */
    64                 TriMeshProcessRiftsUsage();
    65                 return;
    66         }
    67        
    68         if (!(  (nlhs==6) || (nrhs==5))){
    69                 mexPrintf("   %s format error.\n", __FUNCT__);
    70                 TriMeshProcessRiftsUsage();
    71                 _error_("bad usage");
    72         }
     55        /*Boot module*/
     56        MODULEBOOT();
    7357
    74         /*Fetch index_in: */
    75         if(mxIsDouble(prhs[0])){
    76                 nel=mxGetM(prhs[0]);
    77                 tindex_in=mxGetPr(prhs[0]);
    78                 index_in=xNew<double>(nel*3);
    79                 for (i=0;i<nel;i++){
    80                         for (j=0;j<3;j++){
    81                                 *(index_in+3*i+j)=*(tindex_in+nel*j+i);
    82                         }
    83                 }
    84         }
    85         else{
    86                 _error_("first argument should be the element list");
    87         }
     58        /*checks on arguments on the matlab side: */
     59        CHECKARGUMENTS(NLHS,NRHS,&TriMeshProcessRiftsUsage);
    8860
    89         /*Fetch x_in: */
    90         if(mxIsDouble(prhs[1])){
    91                 nods=mxGetM(prhs[1]);
    92                 x_inm=mxGetPr(prhs[1]);
    93                 x_in=xNew<double>(nods);
    94                 for (i=0;i<nods;i++){
    95                         x_in[i]=x_inm[i];
    96                 }
    97         }
    98         else{
    99                 _error_("second argument should be the x corrdinate list");
    100         }
    101 
    102         /*Fetch y_in: */
    103         if(mxIsDouble(prhs[2])){
    104                 y_inm=mxGetPr(prhs[2]);
    105                 y_in=xNew<double>(nods);
    106                 for (i=0;i<nods;i++){
    107                         y_in[i]=y_inm[i];
    108                 }
    109         }
    110         else{
    111                 _error_("third argument should be the y corrdinate list");
    112         }       
    113 
    114         /*Fetch segments_in: */
    115         if(mxIsDouble(prhs[3])){
    116                 num_seg=mxGetM(prhs[3]);
    117                 tsegments_in=mxGetPr(prhs[3]);
    118                 segments_in=xNew<double>(num_seg*3);
    119                 for (i=0;i<num_seg;i++){
    120                         for (j=0;j<3;j++){
    121                                 *(segments_in+3*i+j)=*(tsegments_in+num_seg*j+i);
    122                         }
    123                 }
    124         }
    125         else{
    126                 _error_("fourth argument should be the segments list");
    127         }
    128 
    129         /*Fetch segment markers: */
    130         if(mxIsDouble(prhs[4])){
    131                 tsegmentmarkers_in=mxGetPr(prhs[4]);
    132                 segmentmarkers_in=xNew<double>(num_seg);
    133                 for (i=0;i<num_seg;i++){
    134                         segmentmarkers_in[i]=tsegmentmarkers_in[i];
    135                 }
    136         }
    137         else{
    138                 _error_("fourth argument should be the segmentmarkers list");
    139         }
     61        /*Fetch data */
     62        FetchData(&index_in,&nel,NULL,INDEXIN);
     63        FetchData(&x_in,&nods,XIN);
     64        FetchData(&y_in,NULL,YIN);
     65        FetchData(&segments_in,&num_seg,NULL,SEGMENTSIN);
     66        FetchData(&segmentmarkers_in,NULL,SEGMENTMARKERSIN);
    14067
    14168        /*First, do some fixing on the existing mesh: we do not want any element belonging entirely to the segment list (ie:
     
    17198
    17299        /*Output : */
    173         WriteData(&plhs[0],index_in,nel,3);
    174         WriteData(&plhs[1],x_in,nods,1);
    175         WriteData(&plhs[2],y_in,nods,1);
    176         WriteData(&plhs[3],segments_in,num_seg,3);
    177         WriteData(&plhs[4],segmentmarkers_in,num_seg,1);
     100        WriteData(INDEXOUT,index_in,nel,3);
     101        WriteData(XOUT,x_in,nods,1);
     102        WriteData(YOUT,y_in,nods,1);
     103        WriteData(SEGMENTSOUT,segments_in,num_seg,3);
     104        WriteData(SEGMENTMARKERSOUT,segmentmarkers_in,num_seg,1);
    178105
    179106        if(riftflag){
     
    191118
    192119                dimensions[0]=out_numrifts;
    193 
    194120                pmxa_array=mxCreateStructArray( ndim,dimensions,10,fnames);
    195121               
     
    249175        plhs[5]=pmxa_array;
    250176
    251         return;
     177        /*end module: */
     178        MODULEEND();
    252179}
  • issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.h

    r13236 r13586  
    1 /*!\file:  TriMeshProcessRifts.h
    2  * \brief header prototype
     1/*
     2 * TriMeshProcessRifts.h
    33 */
    44
     
    66#define _TRIMESH_PROCESSRIFTS_H_
    77
    8 #include "mex.h"
    9 #include "triangle.h"
    10 #include "string.h"
     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
     13
     14/*For python modules: needs to come before header files inclusion*/
     15#ifdef _HAVE_PYTHON_
     16#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
     17#endif
     18
    1119#include "../../c/include/globals.h"
    1220#include "../../c/modules/modules.h"
     
    1422#include "../../c/shared/shared.h"
    1523#include "../../c/issm-binding.h"
    16 #include "../../c/EnumDefinitions/EnumDefinitions.h"
    1724
    1825#undef __FUNCT__
    19 #define __FUNCT__ "TriMeshProcessRifts"
     26#define __FUNCT__  "TriMeshProcessRifts"
     27
     28#ifdef _HAVE_MATLAB_MODULES_
     29/* serial input macros: */
     30#define INDEXIN          prhs[0]
     31#define XIN              prhs[1]
     32#define YIN              prhs[2]
     33#define SEGMENTSIN       prhs[3]
     34#define SEGMENTMARKERSIN prhs[4]
     35/* serial output macros: */
     36#define INDEXOUT          (mxArray**)&plhs[0]
     37#define XOUT              (mxArray**)&plhs[1]
     38#define YOUT              (mxArray**)&plhs[2]
     39#define SEGMENTSOUT       (mxArray**)&plhs[3]
     40#define SEGMENTMARKERSOUT (mxArray**)&plhs[4]
     41#define RIFTSTRUCTOUT     (mxArray**)&plhs[5]
     42#endif
     43
     44#ifdef _HAVE_PYTHON_MODULES_
     45/* serial input macros: */
     46#define INDEXIN          PyTuple_GetItem(args,0)
     47#define XIN              PyTuple_GetItem(args,1)
     48#define YIN              PyTuple_GetItem(args,2)
     49#define SEGMENTSIN       PyTuple_GetItem(args,3)
     50#define SEGMENTSMARKERSIN PyTuple_GetItem(args,4)
     51/* serial output macros: */
     52#define INDEXOUT          output,0
     53#define XOUT              output,1
     54#define YOUT              output,2
     55#define SEGMENTSOUT       output,3
     56#define SEGMENTMARKERSOUT output,4
     57#define RIFTSTRUCTOUT     output,5
     58#endif
     59
     60/* serial arg counts: */
     61#undef NLHS
     62#define NLHS  6
     63#undef NRHS
     64#define NRHS  5
    2065
    2166#endif
Note: See TracChangeset for help on using the changeset viewer.