Changeset 23649


Ignore:
Timestamp:
01/22/19 16:03:51 (6 years ago)
Author:
Mathieu Morlighem
Message:

CHG: now options only have size[2] for simplicity

Location:
issm/trunk-jpl/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/IoModel.cpp

    r23580 r23649  
    14361436                                                option->value = scalar;
    14371437                                                option->name  = optionname;
    1438                                                 option->numel = 1;
    1439                                                 option->ndims = 1;
    1440                                                 option->size  = NULL;
     1438                                                option->size[0] = 1;
     1439                                                option->size[1] = 1;
    14411440                                                options->AddOption(option);
    14421441                                          }
     
    14671466                                        option->value = string;
    14681467                                        option->name  = optionname;
    1469                                         option->numel = 1;
    1470                                         option->ndims = 1;
    1471                                         option->size  = NULL;
     1468                                        option->size[0] = 1;
     1469                                        option->size[1] = 1;
    14721470                                        options->AddOption(option);
    14731471
     
    15031501                                                        option->value = scalar;
    15041502                                                        option->name  = optionname;
    1505                                                         option->numel = 1;
    1506                                                         option->ndims = 1;
    1507                                                         option->size  = NULL;
     1503                                                        option->size[0] = 1;
     1504                                                        option->size[1] = 1;
    15081505                                                        options->AddOption(option);
    15091506                                                  }
     
    15341531                                                option->value = string;
    15351532                                                option->name  = optionname;
    1536                                                 option->numel = 1;
    1537                                                 option->ndims = 1;
    1538                                                 option->size  = NULL;
     1533                                                option->size[0] = 1;
     1534                                                option->size[1] = 1;
    15391535                                                options->AddOption(option);
    15401536                                                  }
  • issm/trunk-jpl/src/c/classes/Options/GenericOption.h

    r23254 r23649  
    2323
    2424        public:
    25 
    2625                char       *name;
    2726                OptionType  value;
    28 
    29                 int         numel;   //in case OptionType is an array
    30                 int         ndims;   //in case OptionType is a multi-dimensional array: */
    31                 int        *size;
     27                int         size[2];
    3228
    3329                /*GenericOption constructors, destructors*/
    3430                GenericOption(){ /*{{{*/
    35 
    36                         name   = NULL;
    37                         numel  = 0;
    38                         ndims  = 0;
    39                         size   = NULL;
    40 
     31                        name = NULL;
     32                        size[0] = 0;
     33                        size[1] = 0;
    4134                } /*}}}*/
    4235                ~GenericOption(){ /*{{{*/
    43 
    44                         if(name)   xDelete<char>(name);
    45                         if(size)   xDelete<int>(size);
    46 
     36                        if(name) xDelete<char>(name);
    4737                } /*}}}*/
    4838
     
    5242                };/*}}}*/
    5343                void DeepEcho(){ /*{{{*/
    54 
    5544                        char  indent[81]="";
    5645                        this->DeepEcho(indent);
    57 
    5846                } /*}}}*/
    5947                void DeepEcho(char* indent){ /*{{{*/
    6048
    6149                        char  cstr[81];
    62                         bool  flag=true;
    6350
    64                         if(flag) _printf0_(indent << "         name: \"" << name << "\"\n");
    65                         if(flag) _printf0_(indent << "         numel: " << numel << "\n");
    66                         if(flag) _printf0_(indent << "         ndims: " << ndims << "\n");
    67                         if(size){
    68                                 StringFromSize(cstr,size,ndims);
    69                                 if(flag) _printf0_(indent << "          size: " << cstr << "\n");
    70                         }
    71                         else if(flag) _printf0_(indent << "          size: [empty]\n");
    72                         _printf_(indent << "         value: " << value << "\n");;
     51                        _printf_(indent << "          name: \"" << name << "\"\n");
     52                        _printf_(indent << "          size: " << size[0] <<"x"<<size[1]<< "\n");
     53                        _printf_(indent << "         value: " << value << "\n");
    7354                } /*}}}*/
    7455                void Echo(){ /*{{{*/
    75 
    7656                        this->DeepEcho();
    77 
    7857                } /*}}}*/
    7958                int  Id(){/*{{{*/
     
    9170                        return name;
    9271                };/*}}}*/
    93                 int   NDims(){/*{{{*/
    94                         return ndims;
    95                 };/*}}}*/
    96                 int   NumEl(){/*{{{*/
    97                         return numel;
    98                 };/*}}}*/
    99                 int*  Size(){/*{{{*/
    100                         return size;
    101                 };/*}}}*/
    10272};
    10373
     
    10777
    10878        /*Copy vector*/
    109         IssmPDouble* outvalue=xNew<IssmPDouble>(this->NumEl());
    110         for(int i=0;i<this->NumEl();i++) outvalue[i]=this->value[i];
     79        int numel = this->size[0]*this->size[1];
     80        IssmPDouble* outvalue=xNew<IssmPDouble>(numel);
     81        for(int i=0;i<numel;i++) outvalue[i]=this->value[i];
    11182
    11283        /*Assign output pointer*/
     
    11788
    11889        /*Copy vector*/
    119         IssmDouble* outvalue=xNew<IssmDouble>(this->NumEl());
    120         for(int i=0;i<this->NumEl();i++) outvalue[i]=this->value[i];
     90        int numel = this->size[0]*this->size[1];
     91        IssmDouble* outvalue=xNew<IssmDouble>(numel);
     92        for(int i=0;i<numel;i++) outvalue[i]=this->value[i];
    12193
    12294        /*Assign output pointer*/
     
    135107/*Special destructors when there is a pointer*/
    136108template <> inline GenericOption<char*>::~GenericOption(){ /*{{{*/
    137 
    138         if(name)   xDelete<char>(name);
    139         if(size)   xDelete<int>(size);
    140         if(value)  xDelete<char>(value);
     109        if(name)  xDelete<char>(name);
     110        if(value) xDelete<char>(value);
    141111}
    142112/*}}}*/
  • issm/trunk-jpl/src/c/classes/Options/Option.h

    r20827 r23649  
    2525                virtual void  Echo()= 0;
    2626                int           Id(){_error_("Not implemented yet"); };
    27                 void Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ _error_("not implemented yet!"); };
    28                 int           ObjectEnum(){return OptionEnum;              };
     27                void          Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ _error_("not implemented yet!"); };
     28                int           ObjectEnum(){return OptionEnum;};
    2929
    3030
    3131                /*virtual functions: */
    3232                virtual char* Name()=0;
    33                 virtual int   NDims()=0;
    34                 virtual int   NumEl()=0;
    35                 virtual int*  Size()=0;
    3633
    3734};
  • issm/trunk-jpl/src/c/cores/transient_core.cpp

    r23501 r23649  
    152152                memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));
    153153                odouble->value=+9999.;
    154                 odouble->numel=1;
    155                 odouble->ndims=1;
    156                 odouble->size=NULL;
     154                odouble->size[0]=1;
     155                odouble->size[1]=1;
    157156                options->AddOption(odouble);
    158157                InterpFromMeshToMesh2dx(&icebase_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice,
     
    169168                memcpy(odouble2->name,name2,(strlen(name2)+1)*sizeof(char));
    170169                odouble2->value=+1.;
    171                 odouble2->numel=1;
    172                 odouble2->ndims=1;
    173                 odouble2->size=NULL;
     170                odouble2->size[0]=1;
     171                odouble2->size[1]=1;
    174172                options2->AddOption(odouble2);
    175173                InterpFromMeshToMesh2dx(&icemask_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice,
     
    294292                        memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));
    295293                        odouble->value=+9999.;
    296                         odouble->numel=1;
    297                         odouble->ndims=1;
    298                         odouble->size=NULL;
     294                        odouble->size[0]=1;
     295                        odouble->size[1]=1;
    299296                        options->AddOption(odouble);
    300297                        InterpFromMeshToMesh2dx(&icebase_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice,
     
    310307                        memcpy(odouble2->name,name2,(strlen(name2)+1)*sizeof(char));
    311308                        odouble2->value=+1.;
    312                         odouble2->numel=1;
    313                         odouble2->ndims=1;
    314                         odouble2->size=NULL;
     309                        odouble2->size[0]=1;
     310                        odouble2->size[1]=1;
    315311                        options2->AddOption(odouble2);
    316312                        InterpFromMeshToMesh2dx(&icemask_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice,
  • issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp

    r22671 r23649  
    1313
    1414/*Primitive data types*/
    15 /*FUNCTION FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/
    16 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){
     15void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){/*{{{*/
    1716
    1817        double*  outmatrix=NULL;
     
    5655}
    5756/*}}}*/
    58 /*FUNCTION FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/
    59 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
    60 
    61         int     outmatrix_numel,outmatrix_ndims;
    62         double *outmatrix       = NULL;
    63         int    *outmatrix_size  = NULL;
    64 
    65         if(mxIsEmpty(dataref) ){
    66                 /*Nothing to pick up. Just initialize matrix pointer to NULL: */
    67                 outmatrix_numel = 0;
    68                 outmatrix_ndims = 0;
    69                 outmatrix_size  = NULL;
    70                 outmatrix       = NULL;
    71         }
    72         else if( mxIsClass(dataref,"double") ||
    73                                 mxIsClass(dataref,"single") ||
    74                                 mxIsClass(dataref,"int16") ||
    75                                 mxIsClass(dataref,"int8") ||
    76                                 mxIsClass(dataref,"uint8")){
    77 
    78                 /*Check dataref is not pointing to NaN: */
    79                 if (mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1)){
    80                         outmatrix_numel = 0;
    81                         outmatrix_ndims = 0;
    82                         outmatrix_size  = NULL;
    83                         outmatrix       = NULL;
    84                 }
    85                 else{
    86                         if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){
    87                                 _printf_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'\n");
    88                         }
    89                         /*Convert matlab n-dim array to double* matrix: */
    90                         _error_("not supported");
    91                         //MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
    92                 }
    93         }
    94         else{
    95                 /*This is an error: we don't have the correct input!: */
    96                 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    97         }
    98 
    99         /*Assign output pointers:*/
    100         *pmatrix=outmatrix;
    101         if (pnumel)*pnumel=outmatrix_numel;
    102         if (pndims)*pndims=outmatrix_ndims;
    103         if (psize )*psize =outmatrix_size;
    104         else xDelete<int>(outmatrix_size);
    105 
    106 }
    107 /*}}}*/
    108 /*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/
    109 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){
     57void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){/*{{{*/
    11058
    11159        int     i,outmatrix_rows,outmatrix_cols;
     
    154102}
    155103/*}}}*/
    156 /*FUNCTION FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/
    157 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){
     104void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){/*{{{*/
    158105
    159106        int     i,outmatrix_rows,outmatrix_cols;
     
    196143}
    197144/*}}}*/
    198 /*FUNCTION FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/
    199 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
    200 
    201         int      i;
    202         int      outmatrix_numel,outmatrix_ndims;
    203         int*     outmatrix_size=NULL;
    204         double*  doublematrix=NULL;
    205         bool*    outmatrix=NULL;
    206 
    207         if(mxIsEmpty(dataref) ){
    208                 /*Nothing to pick up. Just initialize matrix pointer to NULL: */
    209                 outmatrix_numel=0;
    210                 outmatrix_ndims=0;
    211                 outmatrix_size =NULL;
    212                 outmatrix=NULL;
    213         }
    214         else if (mxIsClass(dataref,"logical") ){
    215 
    216                 /*Check dataref is not pointing to NaN: */
    217                 if ( mxIsNaN(*((bool*)mxGetData(dataref))) && (mxGetNumberOfElements(dataref)==1) ){
    218                         outmatrix_numel=0;
    219                         outmatrix_ndims=0;
    220                         outmatrix_size =NULL;
    221                         outmatrix=NULL;
    222                 }
    223                 else{
    224 
    225                         /*Convert matlab n-dim array to bool* matrix: */
    226                         _error_("not supported");
    227                         //MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
    228                 }
    229         }
    230         else if (mxIsClass(dataref,"double") ){
    231 
    232                 /*Check dataref is not pointing to NaN: */
    233                 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1) ){
    234                         outmatrix_numel=0;
    235                         outmatrix_ndims=0;
    236                         outmatrix_size =NULL;
    237                         outmatrix=NULL;
    238                 }
    239                 else{
    240 
    241                         /*Convert matlab n-dim array to double* matrix: */
    242                         _error_("not supported");
    243                         //MatlabNArrayToNArray(&doublematrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
    244 
    245                         /*Convert double matrix into bool matrix: */
    246                         outmatrix=xNew<bool>(outmatrix_numel);
    247                         for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i];
    248                         xDelete<double>(doublematrix);
    249                 }
    250         }
    251         else{
    252                 /*This is an error: we don't have the correct input!: */
    253                 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    254         }
    255 
    256         /*Assign output pointers:*/
    257         *pmatrix=outmatrix;
    258         if (pnumel)*pnumel=outmatrix_numel;
    259         if (pndims)*pndims=outmatrix_ndims;
    260         if (psize )*psize =outmatrix_size;
    261         else xDelete<int>(outmatrix_size);
    262 
    263 }
    264 /*}}}*/
    265 /*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{*/
    266 void FetchData(double** pvector,int* pM,const mxArray* dataref){
     145void FetchData(double** pvector,int* pM,const mxArray* dataref){/*{{{*/
    267146
    268147        double* outvector=NULL;
     
    285164}
    286165/*}}}*/
    287 /*FUNCTION FetchData(int** pvector,int* pM,const mxArray* dataref){{{*/
    288 void FetchData(int** pvector,int* pM,const mxArray* dataref){
     166void FetchData(int** pvector,int* pM,const mxArray* dataref){/*{{{*/
    289167
    290168        int    i;
     
    317195}
    318196/*}}}*/
    319 /*FUNCTION FetchData(bool** pvector,int* pM,const mxArray* dataref){{{*/
    320 void FetchData(bool** pvector,int* pM,const mxArray* dataref){
     197void FetchData(bool** pvector,int* pM,const mxArray* dataref){/*{{{*/
    321198
    322199        int    i;
     
    349226}
    350227/*}}}*/
    351 /*FUNCTION FetchData(float** pvector,int* pM,const mxArray* dataref){{{*/
    352 void FetchData(float** pvector,int* pM,const mxArray* dataref){
     228void FetchData(float** pvector,int* pM,const mxArray* dataref){/*{{{*/
    353229
    354230        int    i;
     
    381257}
    382258/*}}}*/
    383 /*FUNCTION FetchData(char** pstring,const mxArray* dataref){{{*/
    384 void FetchData(char** pstring,const mxArray* dataref){
     259void FetchData(char** pstring,const mxArray* dataref){/*{{{*/
    385260
    386261        char* outstring=NULL;
     
    402277        *pstring=outstring;
    403278}/*}}}*/
    404 /*FUNCTION FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/
    405 void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
    406 
    407         int      outmatrix_numel,outmatrix_ndims;
    408         int*     outmatrix_size=NULL;
    409         char*    outmatrix=NULL;
    410 
    411         if(mxIsEmpty(dataref) ){
    412                 /*Nothing to pick up. Just initialize matrix pointer to NULL: */
    413                 outmatrix_numel=0;
    414                 outmatrix_ndims=0;
    415                 outmatrix_size =NULL;
    416                 outmatrix=NULL;
    417         }
    418         else if (mxIsClass(dataref,"char") ){
    419 
    420                 /*Convert matlab n-dim array to char* matrix: */
    421                 _error_("not supported");
    422                 //MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
    423         }
    424         else{
    425                 /*This is an error: we don't have the correct input!: */
    426                 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    427         }
    428 
    429         /*Assign output pointers:*/
    430         *pmatrix=outmatrix;
    431         if (pnumel)*pnumel=outmatrix_numel;
    432         if (pndims)*pndims=outmatrix_ndims;
    433         if (psize )*psize =outmatrix_size;
    434         else xDelete<int>(outmatrix_size);
    435 
    436 }
    437 /*}}}*/
    438 /*FUNCTION FetchData(double* pscalar,const mxArray* dataref){{{*/
    439 void FetchData(double* pscalar,const mxArray* dataref){
     279void FetchData(double* pscalar,const mxArray* dataref){/*{{{*/
    440280
    441281        double scalar;
     
    453293}
    454294/*}}}*/
    455 /*FUNCTION FetchData(int* pinteger,const mxArray* dataref){{{*/
    456 void FetchData(int* pinteger,const mxArray* dataref){
     295void FetchData(int* pinteger,const mxArray* dataref){/*{{{*/
    457296
    458297        int integer;
     
    470309}
    471310/*}}}*/
    472 /*FUNCTION FetchData(bool* pboolean,const mxArray* dataref){{{*/
    473 void FetchData(bool* pboolean,const mxArray* dataref){
     311void FetchData(bool* pboolean,const mxArray* dataref){/*{{{*/
    474312
    475313        bool* mxbool_ptr=NULL;
     
    489327
    490328/*ISSM objects*/
    491 /*FUNCTION FetchData(BamgGeom** pbamggeom,const mxArray* dataref){{{*/
    492 void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){
     329void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){/*{{{*/
    493330
    494331        /*Initialize output*/
     
    508345}
    509346/*}}}*/
    510 /*FUNCTION FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){{{*/
    511 void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){
     347void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){/*{{{*/
    512348
    513349        /*Initialize output*/
     
    528364}
    529365/*}}}*/
    530 /*FUNCTION FetchData(BamgOpts** pbamgopts,const mxArray* dataref){{{*/
    531 void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){
     366void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){/*{{{*/
    532367
    533368        /*Initialize output*/
     
    570405}
    571406/*}}}*/
    572 /*FUNCTION FetchData(Options** poptions,const mxArray** pdataref){{{*/
    573 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){
     407void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){/*{{{*/
    574408
    575409        char   *name   = NULL;
     
    595429}
    596430/*}}}*/
    597 /*FUNCTION FetchData(Contours** pcontours,const mxArray* dataref){{{*/
    598 void FetchData(Contours** pcontours,const mxArray* dataref){
     431void FetchData(Contours** pcontours,const mxArray* dataref){/*{{{*/
    599432
    600433        int             numcontours,index,test1,test2;
     
    674507
    675508/*Toolkit*/
    676 /*FUNCTION MatlabMatrixToDoubleMatrix {{{*/
    677 int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){
    678 
    679         int        i,j,count,rows,cols;
    680 
    681         /*output: */
    682         double* matrix=NULL;
    683 
    684         /*matlab indices: */
    685         mwIndex*    ir=NULL;
    686         mwIndex*    jc=NULL;
    687 
    688         /*Ok, first check if we are dealing with a sparse or full matrix: */
    689         if (mxIsSparse(mxmatrix)){
     509int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){/*{{{*/
     510
     511        /*Get Matrix size*/
     512        int rows=mxGetM(mxmatrix);
     513        int cols=mxGetN(mxmatrix);
     514
     515        /*Return of Matrix is empty*/
     516        if(rows*cols == 0){
     517                *pmatrix      = NULL;
     518                *pmatrix_rows = rows;
     519                *pmatrix_cols = cols;
     520                return 1;
     521        }
     522
     523   /*Initialize output*/
     524   double* matrix=xNewZeroInit<double>(rows*cols);
     525
     526        /*First check if we are dealing with a sparse matrix: */
     527        if(mxIsSparse(mxmatrix)){
    690528
    691529                /*Dealing with sparse matrix: recover size first: */
    692530                double* pmxmatrix=(double*)mxGetPr(mxmatrix);
    693                 rows=mxGetM(mxmatrix);
    694                 cols=mxGetN(mxmatrix);
    695 
    696                 if(rows*cols){
    697                         matrix=xNewZeroInit<double>(rows*cols);
    698 
    699                         /*Now, get ir,jc and pr: */
    700                         ir=mxGetIr(mxmatrix);
    701                         jc=mxGetJc(mxmatrix);
    702 
    703                         /*Now, start inserting data into double* matrix: */
    704                         count=0;
    705                         for(i=0;i<cols;i++){
    706                                 for(j=0;j<(jc[i+1]-jc[i]);j++){
    707                                         matrix[rows*ir[count]+i]=pmxmatrix[count];
    708                                         count++;
    709                                 }
    710                         }
    711                 }
    712 
    713         }
     531
     532      /*Now, get ir,jc and pr: */
     533      mwIndex* ir=mxGetIr(mxmatrix);
     534      mwIndex* jc=mxGetJc(mxmatrix);
     535
     536      /*Now, start inserting data into double* matrix: */
     537      int count=0;
     538      for(int i=0;i<cols;i++){
     539         for(int j=0;j<(jc[i+1]-jc[i]);j++){
     540            matrix[rows*ir[count]+i]=pmxmatrix[count];
     541            count++;
     542         }
     543      }
     544   }
    714545        else if(mxIsClass(mxmatrix,"double")){
    715                 /*Dealing with dense matrix: recover pointer and size: */
    716546                double* pmxmatrix=(double*)mxGetPr(mxmatrix);
    717                 rows=mxGetM(mxmatrix);
    718                 cols=mxGetN(mxmatrix);
    719 
    720                 /*Create serial matrix: */
    721                 if(rows*cols){
    722                         matrix=xNewZeroInit<double>(rows*cols);
    723 
    724                         for(i=0;i<rows;i++){
    725                                 for(j=0;j<cols;j++){
    726                                         matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    727                                 }
    728                         }
    729                 }
     547      for(int i=0;i<rows;i++) for(int j=0;j<cols;j++) matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    730548        }
    731549        else if(mxIsClass(mxmatrix,"single")){
    732                 /*Dealing with dense matrix: recover pointer and size: */
    733550                float *pmxmatrix=(float*)mxGetPr(mxmatrix);
    734                 rows=mxGetM(mxmatrix);
    735                 cols=mxGetN(mxmatrix);
    736 
    737                 /*Create serial matrix: */
    738                 if(rows*cols){
    739                         matrix=xNewZeroInit<double>(rows*cols);
    740 
    741                         for(i=0;i<rows;i++){
    742                                 for(j=0;j<cols;j++){
    743                                         matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    744                                 }
    745                         }
    746                 }
     551      for(int i=0;i<rows;i++) for(int j=0;j<cols;j++) matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    747552        }
    748553        else if(mxIsClass(mxmatrix,"int16")){
    749                 /*Dealing with dense matrix: recover pointer and size: */
    750554                short int *pmxmatrix=(short*)mxGetPr(mxmatrix);
    751                 rows=mxGetM(mxmatrix);
    752                 cols=mxGetN(mxmatrix);
    753 
    754                 /*Create serial matrix: */
    755                 if(rows*cols){
    756                         matrix=xNewZeroInit<double>(rows*cols);
    757 
    758                         for(i=0;i<rows;i++){
    759                                 for(j=0;j<cols;j++){
    760                                         matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    761                                 }
    762                         }
    763                 }
     555      for(int i=0;i<rows;i++) for(int j=0;j<cols;j++) matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    764556        }
    765557        else if(mxIsClass(mxmatrix,"uint8")){
    766                 /*Dealing with dense matrix: recover pointer and size: */
    767                 char *pmxmatrix=(char*)mxGetPr(mxmatrix);
    768                 rows=mxGetM(mxmatrix);
    769                 cols=mxGetN(mxmatrix);
    770 
    771                 /*Create serial matrix: */
    772                 if(rows*cols){
    773                         matrix=xNewZeroInit<double>(rows*cols);
    774 
    775                         for(i=0;i<rows;i++){
    776                                 for(j=0;j<cols;j++){
    777                                         matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    778                                 }
    779                         }
    780                 }
    781         }
    782         else{
    783                 _error_("Matlab matrix type Not implemented yet");
     558      char *pmxmatrix=(char*)mxGetPr(mxmatrix);
     559      for(int i=0;i<rows;i++) for(int j=0;j<cols;j++) matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
     560        }
     561        else{
     562                _error_("Matlab matrix type "<<mxGetClassName(mxmatrix)<<" Not implemented yet");
    784563        }
    785564
     
    791570        return 1;
    792571}/*}}}*/
    793 /*FUNCTION mxGetAssignedField{{{*/
    794 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){
     572mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){/*{{{*/
    795573
    796574        /*Output*/
     
    825603}/*}}}*/
    826604
    827 GenericOption<double>* OptionDoubleParse( char* name, const mxArray* prhs[]){ /*{{{*/
    828 
    829         GenericOption<double> *odouble = NULL;
    830 
    831         /*check and parse the name  */
    832         odouble=new GenericOption<double>();
    833         odouble->name =xNew<char>(strlen(name)+1);
    834         memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));
    835         FetchData(&odouble->value,prhs[0]);
    836         odouble->numel=1;
    837         odouble->ndims=1;
    838         odouble->size=NULL;
    839 
    840         return(odouble);
     605/*Options*/
     606Option* OptionParse(char* name, const mxArray* prhs[]){ /*{{{*/
     607
     608        /*Initialize output*/
     609        Option  *option = NULL;
     610
     611        /*parse the value according to the matlab data type  */
     612        if (mxIsClass(prhs[0],"double")  && (mxGetNumberOfElements(prhs[0])==1)){
     613                option=(Option*)OptionDoubleParse(name,prhs);
     614        }
     615        else if(mxIsClass(prhs[0],"double")  && (mxGetNumberOfElements(prhs[0])>1)){
     616                option=(Option*)OptionDoubleArrayParse(name,prhs);
     617        }
     618        else if(mxIsClass(prhs[0],"char")){
     619                option=(Option*)OptionCharParse(name,prhs);
     620        }
     621        else {
     622                _error_("Second argument value of option \""<< name <<"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<"\".");
     623        }
     624
     625        return option;
    841626}/*}}}*/
    842 GenericOption<double*>* OptionDoubleArrayParse( char* name, const mxArray* prhs[]){ /*{{{*/
    843 
    844         GenericOption<double*> *odouble = NULL;
    845 
    846         /*check and parse the name  */
    847         odouble=new GenericOption<double*>();
    848         odouble->name =xNew<char>(strlen(name)+1);
    849         memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));
     627GenericOption<double>*  OptionDoubleParse(char* name, const mxArray* prhs[]){ /*{{{*/
     628
     629        /*Initialize option*/
     630        GenericOption<double>* option=new GenericOption<double>();
     631
     632        /*Copy name*/
     633        option->name =xNew<char>(strlen(name)+1);
     634        memcpy(option->name,name,(strlen(name)+1)*sizeof(char));
     635
     636        /*Fetch data and initialize size*/
     637        FetchData(&option->value,prhs[0]);
     638   option->size[0] = 1;
     639        option->size[1] = 1;
     640
     641        return option;
     642}/*}}}*/
     643GenericOption<double*>* OptionDoubleArrayParse(char* name, const mxArray* prhs[]){ /*{{{*/
     644
     645        /*Initialize option*/
     646        GenericOption<double*> * option=new GenericOption<double*>();
     647
     648        /*Copy name*/
     649        option->name =xNew<char>(strlen(name)+1);
     650        memcpy(option->name,name,(strlen(name)+1)*sizeof(char));
    850651
    851652        /*check and parse the value  */
    852653        if (!mxIsClass(prhs[0],"double")){
    853                 _error_("Value of option \"" << odouble->name  << "\" must be class \"double\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
    854         }
    855         FetchData(&odouble->value,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]);
    856 
    857         return(odouble);
     654                _error_("Value of option \"" << option->name  << "\" must be class \"double\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
     655        }
     656
     657        /*Fetch data and initialize size*/
     658   FetchData(&option->value,&option->size[0],&option->size[1],prhs[0]);
     659
     660        return option;
    858661}/*}}}*/
    859 GenericOption<bool*>* OptionLogicalParse( char* name, const mxArray* prhs[]){ /*{{{*/
    860 
    861         GenericOption<bool*> *ological = NULL;
    862 
    863         /*check and parse the name  */
    864         ological=new GenericOption<bool*>();
    865         ological->name =xNew<char>(strlen(name)+1);
    866         memcpy(ological->name,name,(strlen(name)+1)*sizeof(char));
     662GenericOption<char*>*   OptionCharParse(char* name, const mxArray* prhs[]){ /*{{{*/
     663
     664        /*Initialize option*/
     665        GenericOption<char*>* option=new GenericOption<char*>();
     666
     667        /*Copy name*/
     668        option->name =xNew<char>(strlen(name)+1);
     669        memcpy(option->name,name,(strlen(name)+1)*sizeof(char));
    867670
    868671        /*check and parse the value  */
    869         if (!mxIsClass(prhs[0],"logical")){
    870                 _error_("Value of option \"" << ological->name  << "\" must be class \"logical\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
    871         }
    872         FetchData(&ological->value,&ological->numel,&ological->ndims,&ological->size,prhs[0]);
    873 
    874         return(ological);
    875 }/*}}}*/
    876 GenericOption<char*>* OptionCharParse( char* name, const mxArray* prhs[]){ /*{{{*/
    877 
    878         /*check and parse the name  */
    879         GenericOption<char*>* ochar=new GenericOption<char*>();
    880         ochar->name =xNew<char>(strlen(name)+1);
    881         memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char));
    882 
    883         /*check and parse the value  */
    884         if (!mxIsClass(prhs[0],"char")){
    885                 _error_("Value of option \"" << ochar->name  << "\" must be class \"char\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
    886         }
    887         //FetchData(&ochar->value,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]);
    888         FetchData(&ochar->value,prhs[0]);
    889         ochar->numel = strlen(name);
    890         ochar->ndims = 2;
    891         ochar->size = xNew<int>(2);
    892         ochar->size[0] = ochar->numel;
    893         ochar->size[1] = 1;
    894 
    895         return(ochar);
    896 }/*}}}*/
    897 Option* OptionParse(char* name, const mxArray* prhs[]){ /*{{{*/
    898 
    899         Option  *option = NULL;
    900         mxArray *lhs[1];
    901 
    902         /*parse the value according to the matlab data type  */
    903         if     (mxIsClass(prhs[0],"double")  && (mxGetNumberOfElements(prhs[0])==1))
    904          option=(Option*)OptionDoubleParse(name,prhs);
    905         else if(mxIsClass(prhs[0],"double")  && (mxGetNumberOfElements(prhs[0])!=1))
    906          option=(Option*)OptionDoubleArrayParse(name,prhs);
    907         else if(mxIsClass(prhs[0],"logical"))
    908          option=(Option*)OptionLogicalParse(name,prhs);
    909         else if(mxIsClass(prhs[0],"char"))
    910          option=(Option*)OptionCharParse(name,prhs);
    911         else {
    912                 _error_("Second argument value of option \""<< name <<"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<"\".");
    913         }
     672        if(!mxIsClass(prhs[0],"char")){
     673                _error_("Value of option \"" << option->name  << "\" must be class \"char\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
     674        }
     675
     676        /*Fetch data and initialize size*/
     677        FetchData(&option->value,prhs[0]);
     678        option->size[0] = strlen(name);
     679        option->size[1] = 1;
    914680
    915681        return(option);
  • issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h

    r22671 r23649  
    3636
    3737void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref);
    38 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);
    3938void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref);
    4039void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref);
    41 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);
    4240void FetchData(int** pvector,int* pM,const mxArray* dataref);
    4341void FetchData(float** pvector,int* pM,const mxArray* dataref);
     
    4543void FetchData(bool** pvector,int* pM,const mxArray* dataref);
    4644void FetchData(char** pstring,const mxArray* dataref);
    47 void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);
    4845void FetchData(double* pscalar,const mxArray* dataref);
    4946void FetchData(int* pinteger,const mxArray* dataref);
     
    5754
    5855Option* OptionParse(char* name, const mxArray* prhs[]);
    59 GenericOption<double>*    OptionDoubleParse( char* name, const mxArray* prhs[]);
    60 GenericOption<double*>*   OptionDoubleArrayParse( char* name, const mxArray* prhs[]);
    61 GenericOption<bool*>*     OptionLogicalParse( char* name, const mxArray* prhs[]);
    62 GenericOption<char*>*     OptionCharParse( char* name, const mxArray* prhs[]);
     56GenericOption<double>*  OptionDoubleParse(char* name, const mxArray* prhs[]);
     57GenericOption<double*>* OptionDoubleArrayParse(char* name, const mxArray* prhs[]);
     58GenericOption<char*>*   OptionCharParse(char* name, const mxArray* prhs[]);
    6359
    6460mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field);
Note: See TracChangeset for help on using the changeset viewer.