Changeset 13395 for issm/trunk/src/c/matlab/io/FetchMatlabData.cpp
- Timestamp:
- 09/19/12 09:32:34 (12 years ago)
- Location:
- issm/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk
- Property svn:ignore
-
old new 1 projects 1 2 autom4te.cache 2 3 aclocal.m4
-
- Property svn:mergeinfo changed
/issm/trunk-jpl merged: 12710-12871,12873-12877,12881-12896,12898-12900,12902-12916,12920-12935,12937-12945,12948-13100,13107-13110,13112-13116,13119-13393
- Property svn:ignore
-
issm/trunk/src
-
Property svn:mergeinfo
set to
/issm/branches/trunk-jpl-damage/src merged eligible /issm/trunk-jpl/src merged eligible
-
Property svn:mergeinfo
set to
-
issm/trunk/src/c/matlab/io/FetchMatlabData.cpp
r12706 r13395 48 48 else{ 49 49 /*This is an error: we don't have the correct input!: */ 50 _error 2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");50 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 51 51 } 52 52 … … 61 61 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ 62 62 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){{{*/ 110 void 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){{{*/ 158 void 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){{{*/ 200 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ 201 202 int i; 64 203 int outmatrix_numel,outmatrix_ndims; 65 204 int* outmatrix_size=NULL; 205 double* doublematrix=NULL; 206 bool* outmatrix=NULL; 66 207 67 208 if(mxIsEmpty(dataref) ){ … … 71 212 outmatrix_size =NULL; 72 213 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 } 73 229 } 74 230 else if (mxIsClass(dataref,"double") ){ … … 84 240 85 241 /*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"); 92 253 } 93 254 … … 101 262 } 102 263 /*}}}*/ 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 /*}}}*/252 264 /*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{*/ 253 265 void FetchData(double** pvector,int* pM,const mxArray* dataref){ … … 269 281 else{ 270 282 /*This is an error: we don't have the correct input!: */ 271 _error 2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");283 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 272 284 } 273 285 … … 301 313 else{ 302 314 /*This is an error: we don't have the correct input!: */ 303 _error 2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");315 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 304 316 } 305 317 … … 333 345 else{ 334 346 /*This is an error: we don't have the correct input!: */ 335 _error 2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");347 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 336 348 } 337 349 … … 365 377 else{ 366 378 /*This is an error: we don't have the correct input!: */ 367 _error 2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");379 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 368 380 } 369 381 … … 381 393 /*Ok, the string should be coming directly from the matlab workspace: */ 382 394 if (!mxIsClass(dataref,"char")){ 383 _error 2_("input data_type is not a string!");395 _error_("input data_type is not a string!"); 384 396 } 385 397 else{ … … 416 428 else{ 417 429 /*This is an error: we don't have the correct input!: */ 418 _error 2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");430 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 419 431 } 420 432 … … 434 446 435 447 if (!mxIsClass(dataref,"double")){ 436 _error 2_("input data_type is not a double!");448 _error_("input data_type is not a double!"); 437 449 } 438 450 else{ … … 451 463 452 464 if (!mxIsClass(dataref,"double")){ 453 _error 2_("input data_type is not a scalar!");465 _error_("input data_type is not a scalar!"); 454 466 } 455 467 else{ … … 468 480 469 481 if (mxIsClass(dataref,"logical")){ 470 if(mxGetM(dataref)!=1) _error 2_("input data is not of size 1x1");471 if(mxGetN(dataref)!=1) _error 2_("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"); 472 484 mxbool_ptr=mxGetLogicals(dataref); 473 485 } 474 486 else{ 475 _error 2_("input data_type is not a bool!");487 _error_("input data_type is not a bool!"); 476 488 } 477 489 … … 481 493 482 494 /*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){{{*/ 496 void FetchData(Matrix<double>** pmatrix,const mxArray* dataref){ 497 498 Matrix<double>* outmatrix=NULL; 487 499 int dummy=0; 488 500 … … 495 507 else{ 496 508 /*This is an error: we don't have the correct input!: */ 497 _error 2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");509 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 498 510 } 499 511 … … 502 514 } 503 515 /*}}}*/ 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){{{*/ 517 void FetchData(Vector<double>** pvector,const mxArray* dataref){ 518 519 Vector<double>* vector=NULL; 508 520 int dummy; 509 521 510 522 if(mxIsEmpty(dataref)){ 511 523 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 512 vector=new Vector (0);524 vector=new Vector<double>(0); 513 525 } 514 526 else if (mxIsClass(dataref,"double") ){ … … 519 531 else{ 520 532 /*This is an error: we don't have the correct input!: */ 521 _error 2_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");533 _error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet"); 522 534 } 523 535 … … 609 621 } 610 622 /*}}}*/ 611 /*FUNCTION FetchData(Options** poptions,const mxArray* 623 /*FUNCTION FetchData(Options** poptions,const mxArray** pdataref){{{*/ 612 624 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){ 613 625 … … 620 632 /*Fetch all options*/ 621 633 for (int i=istart; i<nrhs; i=i+2){ 622 if (!mxIsClass(pdataref[i],"char")) _error 2_("Argument " << i+1 << " must be name of option");634 if (!mxIsClass(pdataref[i],"char")) _error_("Argument " << i+1 << " must be name of option"); 623 635 624 636 FetchData(&name,pdataref[i]); 625 if(i+1 == nrhs) _error 2_("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 << "\"."); 626 638 627 639 option=(Option*)OptionParse(name,&pdataref[i+1]); … … 634 646 } 635 647 /*}}}*/ 648 /*FUNCTION FetchData(DataSet** pcontours,const mxArray* dataref){{{*/ 649 void 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.