Ignore:
Timestamp:
09/19/12 09:32:34 (12 years ago)
Author:
Mathieu Morlighem
Message:

merged trunk-jpl and trunk for revision 13393

Location:
issm/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk

  • issm/trunk/src

  • issm/trunk/src/c/matlab/io/FetchMatlabData.cpp

    r12706 r13395  
    4848        else{
    4949                /*This is an error: we don't have the correct input!: */
    50                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     50                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    5151        }
    5252                       
     
    6161void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
    6262
    63         double*  outmatrix=NULL;
     63        int     outmatrix_numel,outmatrix_ndims;
     64        double *outmatrix       = NULL;
     65        int    *outmatrix_size  = NULL;
     66
     67        if(mxIsEmpty(dataref) ){
     68                /*Nothing to pick up. Just initialize matrix pointer to NULL: */
     69                outmatrix_numel = 0;
     70                outmatrix_ndims = 0;
     71                outmatrix_size  = NULL;
     72                outmatrix       = NULL;
     73        }
     74        else if( mxIsClass(dataref,"double") ||
     75                                mxIsClass(dataref,"single") ||
     76                                mxIsClass(dataref,"int16") ||
     77                                mxIsClass(dataref,"int8") ||
     78                                mxIsClass(dataref,"uint8")){
     79
     80                /*Check dataref is not pointing to NaN: */
     81                if (mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1)){
     82                        outmatrix_numel = 0;
     83                        outmatrix_ndims = 0;
     84                        outmatrix_size  = NULL;
     85                        outmatrix       = NULL;
     86                }
     87                else{
     88                        if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){
     89                                _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'");
     90                        }
     91                        /*Convert matlab n-dim array to double* matrix: */
     92                        MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
     93                }
     94        }
     95        else{
     96                /*This is an error: we don't have the correct input!: */
     97                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     98        }
     99                       
     100        /*Assign output pointers:*/
     101        *pmatrix=outmatrix;
     102        if (pnumel)*pnumel=outmatrix_numel;
     103        if (pndims)*pndims=outmatrix_ndims;
     104        if (psize )*psize =outmatrix_size;
     105        else xDelete<int>(outmatrix_size);
     106
     107}
     108/*}}}*/
     109/*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/
     110void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){
     111
     112        int     i,outmatrix_rows,outmatrix_cols;
     113        double *doublematrix=NULL;
     114        int    *outmatrix=NULL;
     115
     116        if(mxIsEmpty(dataref) ){
     117                /*Nothing to pick up. Just initialize matrix pointer to NULL: */
     118                outmatrix_rows=0;
     119                outmatrix_cols=0;
     120                outmatrix=NULL;
     121        }
     122        else if( mxIsClass(dataref,"double") ||
     123                                mxIsClass(dataref,"single") ||
     124                                mxIsClass(dataref,"int16") ||
     125                                mxIsClass(dataref,"int8") ||
     126                                mxIsClass(dataref,"uint8")){
     127
     128                /*Check dataref is not pointing to NaN: */
     129                if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
     130                        outmatrix_rows=0;
     131                        outmatrix_cols=0;
     132                        outmatrix=NULL;
     133                }
     134                else{
     135                        if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){
     136                                _printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'");
     137                        }
     138                        /*Convert matlab matrix to double* matrix: */
     139                        MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);
     140
     141                        /*Convert double matrix into integer matrix: */
     142                        outmatrix=xNew<int>(outmatrix_rows*outmatrix_cols);
     143                        for(i=0;i<outmatrix_rows*outmatrix_cols;i++)outmatrix[i]=(int)doublematrix[i];
     144                }
     145        }
     146        else{
     147                /*This is an error: we don't have the correct input!: */
     148                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     149        }
     150
     151        /*Assign output pointers:*/
     152        *pmatrix=outmatrix;
     153        if (pM)*pM=outmatrix_rows;
     154        if (pN)*pN=outmatrix_cols;
     155}
     156/*}}}*/
     157/*FUNCTION FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/
     158void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){
     159
     160        int     i,outmatrix_rows,outmatrix_cols;
     161        double *doublematrix=NULL;
     162        bool   *outmatrix=NULL;
     163
     164        if(mxIsEmpty(dataref) ){
     165                /*Nothing to pick up. Just initialize matrix pointer to NULL: */
     166                outmatrix_rows=0;
     167                outmatrix_cols=0;
     168                outmatrix=NULL;
     169        }
     170        else if (mxIsClass(dataref,"double") ){
     171
     172                /*Check dataref is not pointing to NaN: */
     173                if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
     174                        outmatrix_rows=0;
     175                        outmatrix_cols=0;
     176                        outmatrix=NULL;
     177                }
     178                else{
     179
     180                        /*Convert matlab matrix to double* matrix: */
     181                        MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);
     182
     183                        /*Convert double matrix into integer matrix: */
     184                        outmatrix=xNew<bool>(outmatrix_rows*outmatrix_cols);
     185                        for(i=0;i<outmatrix_rows;i++)outmatrix[i]=(bool)doublematrix[i];
     186                }
     187        }
     188        else{
     189                /*This is an error: we don't have the correct input!: */
     190                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     191        }
     192
     193        /*Assign output pointers:*/
     194        *pmatrix=outmatrix;
     195        if (pM)*pM=outmatrix_rows;
     196        if (pN)*pN=outmatrix_cols;
     197}
     198/*}}}*/
     199/*FUNCTION FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/
     200void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
     201
     202        int      i;
    64203        int      outmatrix_numel,outmatrix_ndims;
    65204        int*     outmatrix_size=NULL;
     205        double*  doublematrix=NULL;
     206        bool*    outmatrix=NULL;
    66207
    67208        if(mxIsEmpty(dataref) ){
     
    71212                outmatrix_size =NULL;
    72213                outmatrix=NULL;
     214        }
     215        else if (mxIsClass(dataref,"logical") ){
     216
     217                /*Check dataref is not pointing to NaN: */
     218                if ( mxIsNaN(*((bool*)mxGetData(dataref))) && (mxGetNumberOfElements(dataref)==1) ){
     219                        outmatrix_numel=0;
     220                        outmatrix_ndims=0;
     221                        outmatrix_size =NULL;
     222                        outmatrix=NULL;
     223                }
     224                else{
     225
     226                        /*Convert matlab n-dim array to bool* matrix: */
     227                        MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
     228                }
    73229        }
    74230        else if (mxIsClass(dataref,"double") ){
     
    84240
    85241                        /*Convert matlab n-dim array to double* matrix: */
    86                         MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
    87                 }
    88         }
    89         else{
    90                 /*This is an error: we don't have the correct input!: */
    91                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     242                        MatlabNArrayToNArray(&doublematrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
     243
     244                        /*Convert double matrix into bool matrix: */
     245                        outmatrix=xNew<bool>(outmatrix_numel);
     246                        for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i];
     247                        xDelete<double>(doublematrix);
     248                }
     249        }
     250        else{
     251                /*This is an error: we don't have the correct input!: */
     252                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    92253        }
    93254                       
     
    101262}
    102263/*}}}*/
    103 /*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/
    104 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){
    105 
    106         int     i,outmatrix_rows,outmatrix_cols;
    107         double *doublematrix=NULL;
    108         int    *outmatrix=NULL;
    109 
    110         if(mxIsEmpty(dataref) ){
    111                 /*Nothing to pick up. Just initialize matrix pointer to NULL: */
    112                 outmatrix_rows=0;
    113                 outmatrix_cols=0;
    114                 outmatrix=NULL;
    115         }
    116         else if (mxIsClass(dataref,"double") ){
    117 
    118                 /*Check dataref is not pointing to NaN: */
    119                 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
    120                         outmatrix_rows=0;
    121                         outmatrix_cols=0;
    122                         outmatrix=NULL;
    123                 }
    124                 else{
    125 
    126                         /*Convert matlab matrix to double* matrix: */
    127                         MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);
    128 
    129                         /*Convert double matrix into integer matrix: */
    130                         outmatrix=xNew<int>(outmatrix_rows*outmatrix_cols);
    131                         for(i=0;i<outmatrix_rows*outmatrix_cols;i++)outmatrix[i]=(int)doublematrix[i];
    132                 }
    133         }
    134         else{
    135                 /*This is an error: we don't have the correct input!: */
    136                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    137         }
    138 
    139         /*Assign output pointers:*/
    140         *pmatrix=outmatrix;
    141         if (pM)*pM=outmatrix_rows;
    142         if (pN)*pN=outmatrix_cols;
    143 }
    144 /*}}}*/
    145 /*FUNCTION FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/
    146 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){
    147 
    148         int     i,outmatrix_rows,outmatrix_cols;
    149         double *doublematrix=NULL;
    150         bool   *outmatrix=NULL;
    151 
    152         if(mxIsEmpty(dataref) ){
    153                 /*Nothing to pick up. Just initialize matrix pointer to NULL: */
    154                 outmatrix_rows=0;
    155                 outmatrix_cols=0;
    156                 outmatrix=NULL;
    157         }
    158         else if (mxIsClass(dataref,"double") ){
    159 
    160                 /*Check dataref is not pointing to NaN: */
    161                 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
    162                         outmatrix_rows=0;
    163                         outmatrix_cols=0;
    164                         outmatrix=NULL;
    165                 }
    166                 else{
    167 
    168                         /*Convert matlab matrix to double* matrix: */
    169                         MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);
    170 
    171                         /*Convert double matrix into integer matrix: */
    172                         outmatrix=xNew<bool>(outmatrix_rows*outmatrix_cols);
    173                         for(i=0;i<outmatrix_rows;i++)outmatrix[i]=(bool)doublematrix[i];
    174                 }
    175         }
    176         else{
    177                 /*This is an error: we don't have the correct input!: */
    178                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    179         }
    180 
    181         /*Assign output pointers:*/
    182         *pmatrix=outmatrix;
    183         if (pM)*pM=outmatrix_rows;
    184         if (pN)*pN=outmatrix_cols;
    185 }
    186 /*}}}*/
    187 /*FUNCTION FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/
    188 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
    189 
    190         int      i;
    191         int      outmatrix_numel,outmatrix_ndims;
    192         int*     outmatrix_size=NULL;
    193         double*  doublematrix=NULL;
    194         bool*    outmatrix=NULL;
    195 
    196         if(mxIsEmpty(dataref) ){
    197                 /*Nothing to pick up. Just initialize matrix pointer to NULL: */
    198                 outmatrix_numel=0;
    199                 outmatrix_ndims=0;
    200                 outmatrix_size =NULL;
    201                 outmatrix=NULL;
    202         }
    203         else if (mxIsClass(dataref,"logical") ){
    204 
    205                 /*Check dataref is not pointing to NaN: */
    206                 if ( mxIsNaN(*((bool*)mxGetData(dataref))) && (mxGetNumberOfElements(dataref)==1) ){
    207                         outmatrix_numel=0;
    208                         outmatrix_ndims=0;
    209                         outmatrix_size =NULL;
    210                         outmatrix=NULL;
    211                 }
    212                 else{
    213 
    214                         /*Convert matlab n-dim array to bool* matrix: */
    215                         MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
    216                 }
    217         }
    218         else if (mxIsClass(dataref,"double") ){
    219 
    220                 /*Check dataref is not pointing to NaN: */
    221                 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1) ){
    222                         outmatrix_numel=0;
    223                         outmatrix_ndims=0;
    224                         outmatrix_size =NULL;
    225                         outmatrix=NULL;
    226                 }
    227                 else{
    228 
    229                         /*Convert matlab n-dim array to double* matrix: */
    230                         MatlabNArrayToNArray(&doublematrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
    231 
    232                         /*Convert double matrix into bool matrix: */
    233                         outmatrix=xNew<bool>(outmatrix_numel);
    234                         for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i];
    235                         xDelete<double>(doublematrix);
    236                 }
    237         }
    238         else{
    239                 /*This is an error: we don't have the correct input!: */
    240                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    241         }
    242                        
    243         /*Assign output pointers:*/
    244         *pmatrix=outmatrix;
    245         if (pnumel)*pnumel=outmatrix_numel;
    246         if (pndims)*pndims=outmatrix_ndims;
    247         if (psize )*psize =outmatrix_size;
    248         else xDelete<int>(outmatrix_size);
    249 
    250 }
    251 /*}}}*/
    252264/*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{*/
    253265void FetchData(double** pvector,int* pM,const mxArray* dataref){
     
    269281        else{
    270282                /*This is an error: we don't have the correct input!: */
    271                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     283                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    272284        }
    273285
     
    301313        else{
    302314                /*This is an error: we don't have the correct input!: */
    303                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     315                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    304316        }
    305317
     
    333345        else{
    334346                /*This is an error: we don't have the correct input!: */
    335                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     347                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    336348        }
    337349
     
    365377        else{
    366378                /*This is an error: we don't have the correct input!: */
    367                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     379                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    368380        }
    369381
     
    381393        /*Ok, the string should be coming directly from the matlab workspace: */
    382394        if (!mxIsClass(dataref,"char")){
    383                 _error2_("input data_type is not a string!");
     395                _error_("input data_type is not a string!");
    384396        }
    385397        else{
     
    416428        else{
    417429                /*This is an error: we don't have the correct input!: */
    418                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     430                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    419431        }
    420432                       
     
    434446
    435447        if (!mxIsClass(dataref,"double")){
    436                 _error2_("input data_type is not a double!");
     448                _error_("input data_type is not a double!");
    437449        }
    438450        else{
     
    451463
    452464        if (!mxIsClass(dataref,"double")){
    453                 _error2_("input data_type is not a scalar!");
     465                _error_("input data_type is not a scalar!");
    454466        }
    455467        else{
     
    468480
    469481        if (mxIsClass(dataref,"logical")){
    470                 if(mxGetM(dataref)!=1) _error2_("input data is not of size 1x1");
    471                 if(mxGetN(dataref)!=1) _error2_("input data is not of size 1x1");
     482                if(mxGetM(dataref)!=1) _error_("input data is not of size 1x1");
     483                if(mxGetN(dataref)!=1) _error_("input data is not of size 1x1");
    472484                mxbool_ptr=mxGetLogicals(dataref);
    473485        }
    474486        else{
    475                 _error2_("input data_type is not a bool!");
     487                _error_("input data_type is not a bool!");
    476488        }
    477489
     
    481493
    482494/*ISSM objects*/
    483 /*FUNCTION FetchData(Matrix** pmatrix,const mxArray* dataref){{{*/
    484 void FetchData(Matrix** pmatrix,const mxArray* dataref){
    485 
    486         Matrix* outmatrix=NULL;
     495/*FUNCTION FetchData(Matrix<double>** pmatrix,const mxArray* dataref){{{*/
     496void FetchData(Matrix<double>** pmatrix,const mxArray* dataref){
     497
     498        Matrix<double>* outmatrix=NULL;
    487499        int dummy=0;
    488500
     
    495507        else{
    496508                /*This is an error: we don't have the correct input!: */
    497                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     509                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    498510        }
    499511
     
    502514}
    503515/*}}}*/
    504 /*FUNCTION FetchData(Vector** pvector,const mxArray* dataref){{{*/
    505 void FetchData(Vector** pvector,const mxArray* dataref){
    506 
    507         Vector* vector=NULL;
     516/*FUNCTION FetchData(Vector<double>** pvector,const mxArray* dataref){{{*/
     517void FetchData(Vector<double>** pvector,const mxArray* dataref){
     518
     519        Vector<double>* vector=NULL;
    508520        int dummy;
    509521
    510522        if(mxIsEmpty(dataref)){
    511523                /*Nothing to pick up. Just initialize matrix pointer to NULL: */
    512                 vector=new Vector(0);
     524                vector=new Vector<double>(0);
    513525        }
    514526        else if (mxIsClass(dataref,"double") ){
     
    519531        else{
    520532                /*This is an error: we don't have the correct input!: */
    521                 _error2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
     533                _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
    522534        }
    523535
     
    609621}
    610622/*}}}*/
    611 /*FUNCTION FetchData(Options** poptions,const mxArray* dataref){{{*/
     623/*FUNCTION FetchData(Options** poptions,const mxArray** pdataref){{{*/
    612624void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){
    613625
     
    620632        /*Fetch all options*/
    621633        for (int i=istart; i<nrhs; i=i+2){
    622                 if (!mxIsClass(pdataref[i],"char")) _error2_("Argument " << i+1 << " must be name of option");
     634                if (!mxIsClass(pdataref[i],"char")) _error_("Argument " << i+1 << " must be name of option");
    623635
    624636                FetchData(&name,pdataref[i]);
    625                 if(i+1 == nrhs) _error2_("Argument " << i+2 << " must exist and be value of option \"" << name << "\".");
     637                if(i+1 == nrhs) _error_("Argument " << i+2 << " must exist and be value of option \"" << name << "\".");
    626638
    627639                option=(Option*)OptionParse(name,&pdataref[i+1]);
     
    634646}
    635647/*}}}*/
     648/*FUNCTION FetchData(DataSet** pcontours,const mxArray* dataref){{{*/
     649void FetchData(DataSet** pcontours,const mxArray* dataref){
     650
     651        int              numcontours,index,test1,test2;
     652        char            *contourname = NULL;
     653        DataSet         *contours    = NULL;
     654        Contour<double> *contouri    = NULL;
     655
     656        if (mxIsClass(dataref,"char")){
     657                FetchData(&contourname,dataref);
     658                contours=DomainOutlineRead<double>(contourname);
     659        }
     660        else if(mxIsClass(dataref,"struct")){
     661
     662                contours=new DataSet(0);
     663                numcontours=mxGetNumberOfElements(dataref);
     664
     665                for(int i=0;i<numcontours;i++){
     666
     667                        contouri=xNew<Contour<double> >(1);
     668
     669                        index = mxGetFieldNumber(dataref,"nods");
     670                        if(index==-1) _error_("input structure does not have a 'nods' field");
     671                        FetchData(&contouri->nods,mxGetFieldByNumber(dataref,i,index));
     672
     673                        index = mxGetFieldNumber(dataref,"x");
     674                        if(index==-1) _error_("input structure does not have a 'x' field");
     675                        FetchData(&contouri->x,&test1,&test2,mxGetFieldByNumber(dataref,i,index));
     676                        if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<<contouri->nods<<" 1]");
     677
     678                        index = mxGetFieldNumber(dataref,"y");
     679                        if(index==-1) _error_("input structure does not have a 'y' field");
     680                        FetchData(&contouri->y,&test1,&test2,mxGetFieldByNumber(dataref,i,index));
     681                        if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<<contouri->nods<<" 1]");
     682
     683                        contours->AddObject(contouri);
     684                }
     685        }
     686        else{
     687                _error_("Contour is neither a string nor a structure and cannot be loaded ("<<mxGetClassName(dataref)<<" not supported)");
     688        }
     689
     690        /*clean-up and assign output pointer*/
     691        xDelete<char>(contourname);
     692        *pcontours=contours;
     693}
     694/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.