Changeset 23649
- Timestamp:
- 01/22/19 16:03:51 (6 years ago)
- Location:
- issm/trunk-jpl/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/IoModel.cpp
r23580 r23649 1436 1436 option->value = scalar; 1437 1437 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; 1441 1440 options->AddOption(option); 1442 1441 } … … 1467 1466 option->value = string; 1468 1467 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; 1472 1470 options->AddOption(option); 1473 1471 … … 1503 1501 option->value = scalar; 1504 1502 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; 1508 1505 options->AddOption(option); 1509 1506 } … … 1534 1531 option->value = string; 1535 1532 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; 1539 1535 options->AddOption(option); 1540 1536 } -
issm/trunk-jpl/src/c/classes/Options/GenericOption.h
r23254 r23649 23 23 24 24 public: 25 26 25 char *name; 27 26 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]; 32 28 33 29 /*GenericOption constructors, destructors*/ 34 30 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; 41 34 } /*}}}*/ 42 35 ~GenericOption(){ /*{{{*/ 43 44 if(name) xDelete<char>(name); 45 if(size) xDelete<int>(size); 46 36 if(name) xDelete<char>(name); 47 37 } /*}}}*/ 48 38 … … 52 42 };/*}}}*/ 53 43 void DeepEcho(){ /*{{{*/ 54 55 44 char indent[81]=""; 56 45 this->DeepEcho(indent); 57 58 46 } /*}}}*/ 59 47 void DeepEcho(char* indent){ /*{{{*/ 60 48 61 49 char cstr[81]; 62 bool flag=true;63 50 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"); 73 54 } /*}}}*/ 74 55 void Echo(){ /*{{{*/ 75 76 56 this->DeepEcho(); 77 78 57 } /*}}}*/ 79 58 int Id(){/*{{{*/ … … 91 70 return name; 92 71 };/*}}}*/ 93 int NDims(){/*{{{*/94 return ndims;95 };/*}}}*/96 int NumEl(){/*{{{*/97 return numel;98 };/*}}}*/99 int* Size(){/*{{{*/100 return size;101 };/*}}}*/102 72 }; 103 73 … … 107 77 108 78 /*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]; 111 82 112 83 /*Assign output pointer*/ … … 117 88 118 89 /*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]; 121 93 122 94 /*Assign output pointer*/ … … 135 107 /*Special destructors when there is a pointer*/ 136 108 template <> 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); 141 111 } 142 112 /*}}}*/ -
issm/trunk-jpl/src/c/classes/Options/Option.h
r20827 r23649 25 25 virtual void Echo()= 0; 26 26 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;}; 29 29 30 30 31 31 /*virtual functions: */ 32 32 virtual char* Name()=0; 33 virtual int NDims()=0;34 virtual int NumEl()=0;35 virtual int* Size()=0;36 33 37 34 }; -
issm/trunk-jpl/src/c/cores/transient_core.cpp
r23501 r23649 152 152 memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); 153 153 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; 157 156 options->AddOption(odouble); 158 157 InterpFromMeshToMesh2dx(&icebase_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice, … … 169 168 memcpy(odouble2->name,name2,(strlen(name2)+1)*sizeof(char)); 170 169 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; 174 172 options2->AddOption(odouble2); 175 173 InterpFromMeshToMesh2dx(&icemask_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice, … … 294 292 memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); 295 293 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; 299 296 options->AddOption(odouble); 300 297 InterpFromMeshToMesh2dx(&icebase_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice, … … 310 307 memcpy(odouble2->name,name2,(strlen(name2)+1)*sizeof(char)); 311 308 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; 315 311 options2->AddOption(odouble2); 316 312 InterpFromMeshToMesh2dx(&icemask_oceangrid,index_ice,lon_ice,lat_ice,ngrids_ice,nels_ice, -
issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp
r22671 r23649 13 13 14 14 /*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){ 15 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){/*{{{*/ 17 16 18 17 double* outmatrix=NULL; … … 56 55 } 57 56 /*}}}*/ 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){ 57 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){/*{{{*/ 110 58 111 59 int i,outmatrix_rows,outmatrix_cols; … … 154 102 } 155 103 /*}}}*/ 156 /*FUNCTION FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/ 157 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){ 104 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){/*{{{*/ 158 105 159 106 int i,outmatrix_rows,outmatrix_cols; … … 196 143 } 197 144 /*}}}*/ 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){ 145 void FetchData(double** pvector,int* pM,const mxArray* dataref){/*{{{*/ 267 146 268 147 double* outvector=NULL; … … 285 164 } 286 165 /*}}}*/ 287 /*FUNCTION FetchData(int** pvector,int* pM,const mxArray* dataref){{{*/ 288 void FetchData(int** pvector,int* pM,const mxArray* dataref){ 166 void FetchData(int** pvector,int* pM,const mxArray* dataref){/*{{{*/ 289 167 290 168 int i; … … 317 195 } 318 196 /*}}}*/ 319 /*FUNCTION FetchData(bool** pvector,int* pM,const mxArray* dataref){{{*/ 320 void FetchData(bool** pvector,int* pM,const mxArray* dataref){ 197 void FetchData(bool** pvector,int* pM,const mxArray* dataref){/*{{{*/ 321 198 322 199 int i; … … 349 226 } 350 227 /*}}}*/ 351 /*FUNCTION FetchData(float** pvector,int* pM,const mxArray* dataref){{{*/ 352 void FetchData(float** pvector,int* pM,const mxArray* dataref){ 228 void FetchData(float** pvector,int* pM,const mxArray* dataref){/*{{{*/ 353 229 354 230 int i; … … 381 257 } 382 258 /*}}}*/ 383 /*FUNCTION FetchData(char** pstring,const mxArray* dataref){{{*/ 384 void FetchData(char** pstring,const mxArray* dataref){ 259 void FetchData(char** pstring,const mxArray* dataref){/*{{{*/ 385 260 386 261 char* outstring=NULL; … … 402 277 *pstring=outstring; 403 278 }/*}}}*/ 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){ 279 void FetchData(double* pscalar,const mxArray* dataref){/*{{{*/ 440 280 441 281 double scalar; … … 453 293 } 454 294 /*}}}*/ 455 /*FUNCTION FetchData(int* pinteger,const mxArray* dataref){{{*/ 456 void FetchData(int* pinteger,const mxArray* dataref){ 295 void FetchData(int* pinteger,const mxArray* dataref){/*{{{*/ 457 296 458 297 int integer; … … 470 309 } 471 310 /*}}}*/ 472 /*FUNCTION FetchData(bool* pboolean,const mxArray* dataref){{{*/ 473 void FetchData(bool* pboolean,const mxArray* dataref){ 311 void FetchData(bool* pboolean,const mxArray* dataref){/*{{{*/ 474 312 475 313 bool* mxbool_ptr=NULL; … … 489 327 490 328 /*ISSM objects*/ 491 /*FUNCTION FetchData(BamgGeom** pbamggeom,const mxArray* dataref){{{*/ 492 void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){ 329 void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){/*{{{*/ 493 330 494 331 /*Initialize output*/ … … 508 345 } 509 346 /*}}}*/ 510 /*FUNCTION FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){{{*/ 511 void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){ 347 void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){/*{{{*/ 512 348 513 349 /*Initialize output*/ … … 528 364 } 529 365 /*}}}*/ 530 /*FUNCTION FetchData(BamgOpts** pbamgopts,const mxArray* dataref){{{*/ 531 void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){ 366 void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){/*{{{*/ 532 367 533 368 /*Initialize output*/ … … 570 405 } 571 406 /*}}}*/ 572 /*FUNCTION FetchData(Options** poptions,const mxArray** pdataref){{{*/ 573 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){ 407 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){/*{{{*/ 574 408 575 409 char *name = NULL; … … 595 429 } 596 430 /*}}}*/ 597 /*FUNCTION FetchData(Contours** pcontours,const mxArray* dataref){{{*/ 598 void FetchData(Contours** pcontours,const mxArray* dataref){ 431 void FetchData(Contours** pcontours,const mxArray* dataref){/*{{{*/ 599 432 600 433 int numcontours,index,test1,test2; … … 674 507 675 508 /*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)){ 509 int 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)){ 690 528 691 529 /*Dealing with sparse matrix: recover size first: */ 692 530 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 } 714 545 else if(mxIsClass(mxmatrix,"double")){ 715 /*Dealing with dense matrix: recover pointer and size: */716 546 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]; 730 548 } 731 549 else if(mxIsClass(mxmatrix,"single")){ 732 /*Dealing with dense matrix: recover pointer and size: */733 550 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]; 747 552 } 748 553 else if(mxIsClass(mxmatrix,"int16")){ 749 /*Dealing with dense matrix: recover pointer and size: */750 554 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]; 764 556 } 765 557 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"); 784 563 } 785 564 … … 791 570 return 1; 792 571 }/*}}}*/ 793 /*FUNCTION mxGetAssignedField{{{*/ 794 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){ 572 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){/*{{{*/ 795 573 796 574 /*Output*/ … … 825 603 }/*}}}*/ 826 604 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*/ 606 Option* 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; 841 626 }/*}}}*/ 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)); 627 GenericOption<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 }/*}}}*/ 643 GenericOption<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)); 850 651 851 652 /*check and parse the value */ 852 653 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; 858 661 }/*}}}*/ 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 o logical->name =xNew<char>(strlen(name)+1);866 memcpy(o logical->name,name,(strlen(name)+1)*sizeof(char));662 GenericOption<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)); 867 670 868 671 /*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; 914 680 915 681 return(option); -
issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h
r22671 r23649 36 36 37 37 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref); 38 void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);39 38 void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref); 40 39 void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref); 41 void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);42 40 void FetchData(int** pvector,int* pM,const mxArray* dataref); 43 41 void FetchData(float** pvector,int* pM,const mxArray* dataref); … … 45 43 void FetchData(bool** pvector,int* pM,const mxArray* dataref); 46 44 void FetchData(char** pstring,const mxArray* dataref); 47 void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);48 45 void FetchData(double* pscalar,const mxArray* dataref); 49 46 void FetchData(int* pinteger,const mxArray* dataref); … … 57 54 58 55 Option* 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[]); 56 GenericOption<double>* OptionDoubleParse(char* name, const mxArray* prhs[]); 57 GenericOption<double*>* OptionDoubleArrayParse(char* name, const mxArray* prhs[]); 58 GenericOption<char*>* OptionCharParse(char* name, const mxArray* prhs[]); 63 59 64 60 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field);
Note:
See TracChangeset
for help on using the changeset viewer.