Changeset 7860 for issm/trunk
- Timestamp:
- 04/12/11 15:37:07 (14 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Makefile.am
r7848 r7860 392 392 ./io/FetchNodeSets.cpp\ 393 393 ./io/OptionParse.cpp\ 394 ./io/MatlabNArrayToNArray.cpp\ 394 395 ./io/pfopen.cpp\ 395 396 ./io/pfclose.cpp\ -
issm/trunk/src/c/io/FetchData.cpp
r7740 r7860 87 87 } 88 88 /*}}}*/ 89 /*FUNCTION FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{1*/ 90 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ 91 92 double* outmatrix=NULL; 93 int outmatrix_numel,outmatrix_ndims; 94 int* outmatrix_size=NULL; 95 96 if(mxIsEmpty(dataref) ){ 97 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 98 outmatrix_numel=0; 99 outmatrix_ndims=0; 100 outmatrix_size =NULL; 101 outmatrix=NULL; 102 } 103 else if (mxIsClass(dataref,"double") ){ 104 105 /*Check dataref is not pointing to NaN: */ 106 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1) ){ 107 outmatrix_numel=0; 108 outmatrix_ndims=0; 109 outmatrix_size =NULL; 110 outmatrix=NULL; 111 } 112 else{ 113 114 /*Convert matlab n-dim array to double* matrix: */ 115 MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); 116 } 117 } 118 else{ 119 /*This is an error: we don't have the correct input!: */ 120 _error_("Input parameter of class %s not supported yet",mxGetClassName(dataref)); 121 } 122 123 /*Assign output pointers:*/ 124 *pmatrix=outmatrix; 125 if (pnumel)*pnumel=outmatrix_numel; 126 if (pndims)*pndims=outmatrix_ndims; 127 if (psize )*psize =outmatrix_size; 128 else xfree((void**)&outmatrix_size); 129 130 } 131 /*}}}*/ 89 132 /*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{1*/ 90 133 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){ … … 169 212 if (pM)*pM=outmatrix_rows; 170 213 if (pN)*pN=outmatrix_cols; 214 } 215 /*}}}*/ 216 /*FUNCTION FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{1*/ 217 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ 218 219 int i; 220 int outmatrix_numel,outmatrix_ndims; 221 int* outmatrix_size=NULL; 222 double* doublematrix=NULL; 223 bool* outmatrix=NULL; 224 225 if(mxIsEmpty(dataref) ){ 226 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 227 outmatrix_numel=0; 228 outmatrix_ndims=0; 229 outmatrix_size =NULL; 230 outmatrix=NULL; 231 } 232 else if (mxIsClass(dataref,"logical") ){ 233 234 /*Check dataref is not pointing to NaN: */ 235 if ( mxIsNaN(*((bool*)mxGetData(dataref))) && (mxGetNumberOfElements(dataref)==1) ){ 236 outmatrix_numel=0; 237 outmatrix_ndims=0; 238 outmatrix_size =NULL; 239 outmatrix=NULL; 240 } 241 else{ 242 243 /*Convert matlab n-dim array to bool* matrix: */ 244 MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); 245 } 246 } 247 else if (mxIsClass(dataref,"double") ){ 248 249 /*Check dataref is not pointing to NaN: */ 250 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1) ){ 251 outmatrix_numel=0; 252 outmatrix_ndims=0; 253 outmatrix_size =NULL; 254 outmatrix=NULL; 255 } 256 else{ 257 258 /*Convert matlab n-dim array to double* matrix: */ 259 MatlabNArrayToNArray(&doublematrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); 260 261 /*Convert double matrix into bool matrix: */ 262 outmatrix=(bool*)xmalloc(outmatrix_numel*sizeof(bool)); 263 for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i]; 264 xfree((void**)&doublematrix); 265 } 266 } 267 else{ 268 /*This is an error: we don't have the correct input!: */ 269 _error_("Input parameter of class %s not supported yet",mxGetClassName(dataref)); 270 } 271 272 /*Assign output pointers:*/ 273 *pmatrix=outmatrix; 274 if (pnumel)*pnumel=outmatrix_numel; 275 if (pndims)*pndims=outmatrix_ndims; 276 if (psize )*psize =outmatrix_size; 277 else xfree((void**)&outmatrix_size); 278 171 279 } 172 280 /*}}}*/ … … 366 474 /*Assign output pointers:*/ 367 475 *pstring=outstring; 476 } 477 /*FUNCTION FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{1*/ 478 void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){ 479 480 int outmatrix_numel,outmatrix_ndims; 481 int* outmatrix_size=NULL; 482 char* outmatrix=NULL; 483 484 if(mxIsEmpty(dataref) ){ 485 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 486 outmatrix_numel=0; 487 outmatrix_ndims=0; 488 outmatrix_size =NULL; 489 outmatrix=NULL; 490 } 491 else if (mxIsClass(dataref,"char") ){ 492 493 /*Check dataref is not pointing to NaN: */ 494 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1) ){ 495 outmatrix_numel=0; 496 outmatrix_ndims=0; 497 outmatrix_size =NULL; 498 outmatrix=NULL; 499 } 500 else{ 501 502 /*Convert matlab n-dim array to char* matrix: */ 503 MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref); 504 } 505 } 506 else{ 507 /*This is an error: we don't have the correct input!: */ 508 _error_("Input parameter of class %s not supported yet",mxGetClassName(dataref)); 509 } 510 511 /*Assign output pointers:*/ 512 *pmatrix=outmatrix; 513 if (pnumel)*pnumel=outmatrix_numel; 514 if (pndims)*pndims=outmatrix_ndims; 515 if (psize )*psize =outmatrix_size; 516 else xfree((void**)&outmatrix_size); 517 368 518 } 369 519 /*}}}*/ -
issm/trunk/src/c/io/OptionParse.cpp
r7761 r7860 42 42 43 43 OptionDouble *odouble = NULL; 44 const mwSize *ipt = NULL;45 44 46 45 /*check and parse the name */ … … 54 53 } 55 54 56 odouble->numel=mxGetNumberOfElements(prhs[0]); 57 odouble->ndims=mxGetNumberOfDimensions(prhs[0]); 58 ipt =mxGetDimensions(prhs[0]); 59 odouble->size =(int *) xmalloc(odouble->ndims*sizeof(int)); 60 for (int i=0; i<odouble->ndims; i++) odouble->size[i]=(int)ipt[i]; 61 62 // note that FetchData does not correctly handle ndims >= 3 63 if (odouble->ndims > 2) { 64 _printf_(true,"WARNING -- option \"%s\" of class \"%s\" has ndims=%d and will be skipped.\n",odouble->name,mxGetClassName(prhs[0]),odouble->ndims); 65 odouble->numel=0; 66 } 67 else FetchData(&odouble->values,NULL,NULL,prhs[0]); 55 FetchData(&odouble->values,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]); 68 56 69 57 return(odouble); … … 73 61 74 62 OptionLogical *ological = NULL; 75 const mwSize *ipt = NULL;76 bool btemp;77 63 78 64 /*check and parse the name */ … … 86 72 } 87 73 88 ological->numel=mxGetNumberOfElements(prhs[0]); 89 ological->ndims=mxGetNumberOfDimensions(prhs[0]); 90 ipt =mxGetDimensions(prhs[0]); 91 ological->size =(int *) xmalloc(ological->ndims*sizeof(int)); 92 for (int i=0; i<ological->ndims; i++) ological->size[i]=(int)ipt[i]; 93 94 // note that FetchData does not correctly handle non-scalar logicals 95 if (ological->ndims > 2 || ological->size[0] > 1 || ological->size[1] > 1) { 96 _printf_(true,"WARNING -- option \"%s\" of class \"%s\" is more than [1x1] and will be skipped.\n",ological->name,mxGetClassName(prhs[0])); 97 ological->numel=0; 98 } 99 else { 100 //FetchData(&ological->values,prhs[0]); 101 //could be memory leak until FetchData handles logical arrays 102 ological->values=(bool *) xmalloc(sizeof(bool)); 103 FetchData(ological->values,prhs[0]); 104 } 74 FetchData(&ological->values,&ological->numel,&ological->ndims,&ological->size,prhs[0]); 105 75 106 76 return(ological); … … 110 80 111 81 OptionChar *ochar = NULL; 112 const mwSize *ipt = NULL;113 82 114 83 /*check and parse the name */ … … 122 91 } 123 92 124 ochar->numel=mxGetNumberOfElements(prhs[0]); 125 ochar->ndims=mxGetNumberOfDimensions(prhs[0]); 126 ipt =mxGetDimensions(prhs[0]); 127 ochar->size =(int *) xmalloc(ochar->ndims*sizeof(int)); 128 for(int i=0; i<ochar->ndims; i++) ochar->size[i]=(int)ipt[i]; 129 130 //note that FetchData does not correctly handle ndims >= 2 or multiple rows 131 if (ochar->ndims > 2 || ochar->size[0] > 1) { 132 _printf_(true,"WARNING -- option \"%s\" of class \"%s\" is more than [1xn] and will be skipped.\n",ochar->name,mxGetClassName(prhs[0])); 133 ochar->numel=0; 134 } 135 else FetchData(&ochar->values,prhs[0]); 93 FetchData(&ochar->values,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]); 136 94 137 95 return(ochar); -
issm/trunk/src/c/io/io.h
r7739 r7860 33 33 void FetchData(DataSet** pdataset,const mxArray* dataref); 34 34 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref); 35 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); 35 36 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref); 36 37 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref); 38 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); 37 39 void FetchData(Mat* pmatrix,const mxArray* dataref); 38 40 void FetchData(int** pvector,int* pM,const mxArray* dataref); … … 42 44 void FetchData(Vec* pvector,const mxArray* dataref); 43 45 void FetchData(char** pstring,const mxArray* dataref); 46 void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref); 44 47 void FetchData(double* pscalar,const mxArray* dataref); 45 48 void FetchData(int* pinteger,const mxArray* dataref); … … 64 67 OptionStruct* OptionStructParse( char* name, const mxArray* prhs[]); 65 68 OptionCell* OptionCellParse( char* name, const mxArray* prhs[]); 69 70 int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); 71 int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); 72 int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix); 66 73 67 74 #endif
Note:
See TracChangeset
for help on using the changeset viewer.