Changeset 12043
- Timestamp:
- 04/18/12 07:58:33 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/Makefile.am
r12022 r12043 748 748 ./matlab/io/MatlabMatrixToMatrix.cpp\ 749 749 ./matlab/io/MatlabVectorToVector.cpp\ 750 ./matlab/io/MatlabVectorToDoubleVector.cpp\ 751 ./matlab/io/MatlabMatrixToDoubleMatrix.cpp\ 752 ./matlab/Container/Options.cpp\ 753 ./matlab/objects/Bamg/BamgGeom.h\ 754 ./matlab/objects/Bamg/BamgGeom.cpp\ 755 ./matlab/objects/Bamg/BamgMesh.h\ 756 ./matlab/objects/Bamg/BamgMesh.cpp\ 757 ./matlab/objects/Bamg/BamgOpts.h\ 758 ./matlab/objects/Bamg/BamgOpts.cpp\ 759 ./matlab/io/MatlabMatrixToPetscMatrix.cpp\ 760 ./matlab/io/MatlabVectorToPetscVector.cpp\ 761 ./matlab/io/PetscMatrixToDoubleMatrix.cpp\ 762 ./matlab/io/PetscVectorToDoubleVector.cpp\ 763 ./matlab/io/MatlabMatrixToSeqMat.cpp\ 764 ./matlab/io/MatlabVectorToSeqVec.cpp 750 ./matlab/io/MatlabVectorToDoubleVector.cpp\ 751 ./matlab/io/MatlabMatrixToDoubleMatrix.cpp\ 752 ./matlab/Container/Options.cpp\ 753 ./matlab/io/MatlabMatrixToPetscMatrix.cpp\ 754 ./matlab/io/MatlabVectorToPetscVector.cpp\ 755 ./matlab/io/PetscMatrixToDoubleMatrix.cpp\ 756 ./matlab/io/PetscVectorToDoubleVector.cpp\ 757 ./matlab/io/MatlabMatrixToSeqMat.cpp\ 758 ./matlab/io/MatlabVectorToSeqVec.cpp 765 759 #}}} 766 760 #Modules sources{{{1 -
issm/trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp
r12013 r12043 14 14 #include "./matlabio.h" 15 15 16 /*Primitive data types*/ 16 17 /*FUNCTION FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){{{1*/ 17 18 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){ … … 242 243 } 243 244 /*}}}*/ 244 /*FUNCTION FetchData(Matrix** pmatrix,const mxArray* dataref){{{1*/245 void FetchData(Matrix** pmatrix,const mxArray* dataref){246 247 Matrix* outmatrix=NULL;248 int dummy=0;249 250 if (mxIsClass(dataref,"double") ){251 252 /*Convert matlab matrix to matrix: */253 outmatrix=MatlabMatrixToMatrix(dataref);254 255 }256 else{257 /*This is an error: we don't have the correct input!: */258 _error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));259 }260 261 /*Assign output pointers:*/262 *pmatrix=outmatrix;263 }264 /*}}}*/265 245 /*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{1*/ 266 246 void FetchData(double** pvector,int* pM,const mxArray* dataref){ … … 384 364 *pvector=outvector; 385 365 if (pM)*pM=outvector_rows; 386 }387 /*}}}*/388 /*FUNCTION FetchData(Vector** pvector,const mxArray* dataref){{{1*/389 void FetchData(Vector** pvector,const mxArray* dataref){390 391 Vector* vector=NULL;392 int dummy;393 394 if(mxIsEmpty(dataref)){395 /*Nothing to pick up. Just initialize matrix pointer to NULL: */396 vector=new Vector(0);397 }398 else if (mxIsClass(dataref,"double") ){399 400 /*Convert matlab vector to petsc vector: */401 vector=MatlabVectorToVector(dataref);402 }403 else{404 /*This is an error: we don't have the correct input!: */405 _error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));406 }407 408 /*Assign output pointers:*/409 *pvector=vector;410 366 } 411 367 /*}}}*/ … … 526 482 } 527 483 /*}}}*/ 484 485 /*ISSM objects*/ 486 /*FUNCTION FetchData(Matrix** pmatrix,const mxArray* dataref){{{1*/ 487 void FetchData(Matrix** pmatrix,const mxArray* dataref){ 488 489 Matrix* outmatrix=NULL; 490 int dummy=0; 491 492 if (mxIsClass(dataref,"double") ){ 493 494 /*Convert matlab matrix to matrix: */ 495 outmatrix=MatlabMatrixToMatrix(dataref); 496 497 } 498 else{ 499 /*This is an error: we don't have the correct input!: */ 500 _error_("Input parameter of class %s not supported yet",mxGetClassName(dataref)); 501 } 502 503 /*Assign output pointers:*/ 504 *pmatrix=outmatrix; 505 } 506 /*}}}*/ 507 /*FUNCTION FetchData(Vector** pvector,const mxArray* dataref){{{1*/ 508 void FetchData(Vector** pvector,const mxArray* dataref){ 509 510 Vector* vector=NULL; 511 int dummy; 512 513 if(mxIsEmpty(dataref)){ 514 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ 515 vector=new Vector(0); 516 } 517 else if (mxIsClass(dataref,"double") ){ 518 519 /*Convert matlab vector to petsc vector: */ 520 vector=MatlabVectorToVector(dataref); 521 } 522 else{ 523 /*This is an error: we don't have the correct input!: */ 524 _error_("Input parameter of class %s not supported yet",mxGetClassName(dataref)); 525 } 526 527 /*Assign output pointers:*/ 528 *pvector=vector; 529 } 530 /*}}}*/ 531 /*FUNCTION FetchData(BamgGeom** pbamggeom,const mxArray* dataref){{{1*/ 532 void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){ 533 534 /*Initialize output*/ 535 BamgGeom* bamggeom=new BamgGeom(); 536 537 /*Fetch all fields*/ 538 FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices")); 539 FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges")); 540 FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], mxGetAssignedField(dataref,0,"Corners")); 541 FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],mxGetAssignedField(dataref,0,"RequiredVertices")); 542 FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], mxGetAssignedField(dataref,0,"RequiredEdges")); 543 FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges")); 544 FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],mxGetAssignedField(dataref,0,"SubDomains")); 545 546 /*Assign output pointers:*/ 547 *pbamggeom=bamggeom; 548 } 549 /*}}}*/ 550 /*FUNCTION FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){{{1*/ 551 void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){ 552 553 /*Initialize output*/ 554 BamgMesh* bamgmesh=new BamgMesh(); 555 556 /*Fetch all fields*/ 557 FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices")); 558 FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges")); 559 FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], mxGetAssignedField(dataref,0,"Triangles")); 560 FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges")); 561 FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomEdge")); 562 FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomVertex")); 563 FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], mxGetAssignedField(dataref,0,"EdgesOnGeomEdge")); 564 FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],mxGetAssignedField(dataref,0,"IssmSegments")); 565 566 /*Assign output pointers:*/ 567 *pbamgmesh=bamgmesh; 568 } 569 /*}}}*/ 570 /*FUNCTION FetchData(BamgOpts** pbamgopts,const mxArray* dataref){{{1*/ 571 void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){ 572 573 /*Initialize output*/ 574 BamgOpts* bamgopts=new BamgOpts(); 575 576 /*Fetch all fields*/ 577 FetchData(&bamgopts->anisomax,mxGetField(dataref,0,"anisomax")); 578 FetchData(&bamgopts->cutoff,mxGetField(dataref,0,"cutoff")); 579 FetchData(&bamgopts->coeff,mxGetField(dataref,0,"coeff")); 580 FetchData(&bamgopts->errg,mxGetField(dataref,0,"errg")); 581 FetchData(&bamgopts->gradation,mxGetField(dataref,0,"gradation")); 582 FetchData(&bamgopts->Hessiantype,mxGetField(dataref,0,"Hessiantype")); 583 FetchData(&bamgopts->MaxCornerAngle,mxGetField(dataref,0,"MaxCornerAngle")); 584 FetchData(&bamgopts->maxnbv,mxGetField(dataref,0,"maxnbv")); 585 FetchData(&bamgopts->maxsubdiv,mxGetField(dataref,0,"maxsubdiv")); 586 FetchData(&bamgopts->Metrictype,mxGetField(dataref,0,"Metrictype")); 587 FetchData(&bamgopts->nbjacobi,mxGetField(dataref,0,"nbjacobi")); 588 FetchData(&bamgopts->nbsmooth,mxGetField(dataref,0,"nbsmooth")); 589 FetchData(&bamgopts->omega,mxGetField(dataref,0,"omega")); 590 FetchData(&bamgopts->power,mxGetField(dataref,0,"power")); 591 FetchData(&bamgopts->verbose,mxGetField(dataref,0,"verbose")); 592 593 FetchData(&bamgopts->Crack,mxGetField(dataref,0,"Crack")); 594 FetchData(&bamgopts->geometricalmetric,mxGetField(dataref,0,"geometricalmetric")); 595 FetchData(&bamgopts->KeepVertices,mxGetField(dataref,0,"KeepVertices")); 596 FetchData(&bamgopts->splitcorners,mxGetField(dataref,0,"splitcorners")); 597 598 FetchData(&bamgopts->hmin,mxGetField(dataref,0,"hmin")); 599 FetchData(&bamgopts->hmax,mxGetField(dataref,0,"hmax")); 600 FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],mxGetField(dataref,0,"hminVertices")); 601 FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],mxGetField(dataref,0,"hmaxVertices")); 602 FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],mxGetField(dataref,0,"hVertices")); 603 FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],mxGetField(dataref,0,"metric")); 604 FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],mxGetField(dataref,0,"field")); 605 FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],mxGetField(dataref,0,"err")); 606 607 /*Additional checks*/ 608 bamgopts->Check(); 609 610 /*Assign output pointers:*/ 611 *pbamgopts=bamgopts; 612 } 613 /*}}}*/ -
issm/trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp
r12041 r12043 15 15 #include <mex.h> 16 16 17 18 /*Primitive data types*/ 19 /*FUNCTION WriteData(mxArray** pdataref,double* matrix, int M,int N){{{1*/ 20 void WriteData(mxArray** pdataref,double* matrix, int M,int N){ 21 22 mxArray *dataref = NULL; 23 double *tmatrix = NULL; 24 25 if(matrix){ 26 /*create the matlab matrixwith Matlab's memory manager */ 27 tmatrix=(double*)mxMalloc(M*N*sizeof(double)); 28 for(int i=0;i<M;i++){ 29 for(int j=0;j<N;j++){ 30 tmatrix[i*N+j]=matrix[j*M+i]; 31 } 32 } 33 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 34 mxSetM(dataref,(mwSize)M); 35 mxSetN(dataref,(mwSize)N); 36 mxSetPr(dataref,(double*)tmatrix); 37 } 38 else{ 39 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 40 } 41 *pdataref=dataref; 42 } 43 /*}}}*/ 44 /*FUNCTION WriteData(mxArray** pdataref,int* matrix, int M,int N){{{1*/ 45 void WriteData(mxArray** pdataref,int* matrix, int M,int N){ 46 47 mxArray* dataref = NULL; 48 double* tmatrix = NULL; 49 50 if(matrix){ 51 52 /*convert to double matrix using Matlab's memory manager*/ 53 double* tmatrix=(double*)mxMalloc(M*N*sizeof(double)); 54 for(int i=0;i<M;i++){ 55 for(int j=0;j<N;j++){ 56 tmatrix[i*N+j]=(double)matrix[j*M+i]; 57 } 58 } 59 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 60 mxSetM(dataref,(mwSize)M); 61 mxSetN(dataref,(mwSize)N); 62 mxSetPr(dataref,(double*)tmatrix); 63 64 } 65 else{ 66 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 67 } 68 *pdataref=dataref; 69 } 70 /*}}}*/ 71 /*FUNCTION WriteData(mxArray** pdataref,double* vector, int M){{{1*/ 72 void WriteData(mxArray** pdataref,double* vector, int M){ 73 74 mxArray* dataref = NULL; 75 double* vector_matlab = NULL; 76 77 if(vector){ 78 79 /*create the matlab vector with Matlab's memory manager */ 80 vector_matlab=(double*)mxMalloc(M*sizeof(double)); 81 for(int i=0;i<M;i++) vector_matlab[i]=vector[i]; 82 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 83 mxSetM(dataref,(mwSize)M); 84 mxSetN(dataref,(mwSize)1); 85 mxSetPr(dataref,vector_matlab); 86 } 87 else{ 88 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 89 } 90 91 *pdataref=dataref; 92 } 93 /*}}}*/ 94 /*FUNCTION WriteData(mxArray** pdataref,double scalar){{{1*/ 95 void WriteData(mxArray** pdataref,double scalar){ 96 97 *pdataref=mxCreateDoubleScalar(scalar); 98 } 99 /*}}}*/ 100 /*FUNCTION WriteData(mxArray** pdataref,int integer){{{1*/ 101 void WriteData(mxArray** pdataref,int integer){ 102 103 *pdataref=mxCreateDoubleScalar((double)integer); 104 105 } 106 /*}}}*/ 107 /*FUNCTION WriteData(mxArray** pdataref,int boolean){{{1*/ 108 void WriteData(mxArray** pdataref,bool boolean){ 109 110 *pdataref=mxCreateDoubleScalar((double)boolean); 111 112 } 113 /*}}}*/ 114 /*FUNCTION WriteData(mxArray** pdataref,char* string){{{1*/ 115 void WriteData(mxArray** pdataref,char* string){ 116 117 *pdataref=mxCreateString(string); 118 } 119 /*}}}*/ 120 121 /*ISSM objects*/ 122 /*FUNCTION WriteData(mxArray** pdataref,BamgGeom* bamggeom){{{1*/ 123 void WriteData(mxArray** pdataref,BamgGeom* bamggeom){ 124 125 /*Intermediary*/ 126 int i; 127 mxArray *dataref = NULL; 128 const int numfields = 7; 129 const char *fnames[numfields]; 130 mwSize ndim = 2; 131 mwSize dimensions[2] = {1,1}; 132 133 /*Initialize field names*/ 134 i=0; 135 fnames[i++] = "Vertices"; 136 fnames[i++] = "Edges"; 137 fnames[i++] = "TangentAtEdges"; 138 fnames[i++] = "RequiredVertices"; 139 fnames[i++] = "RequiredEdges"; 140 fnames[i++] = "CrackedEdges"; 141 fnames[i++] = "SubDomains"; 142 _assert_(i==numfields); 143 144 /*Initialize Matlab structure*/ 145 dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames); 146 147 /*set each matlab each field*/ 148 i=0; 149 i++; SetStructureField(dataref,"Vertices", bamggeom->VerticesSize[0], bamggeom->VerticesSize[1], bamggeom->Vertices); 150 i++; SetStructureField(dataref,"Edges", bamggeom->EdgesSize[0], bamggeom->EdgesSize[1], bamggeom->Edges); 151 i++; SetStructureField(dataref,"TangentAtEdges", bamggeom->TangentAtEdgesSize[0], bamggeom->TangentAtEdgesSize[1], bamggeom->TangentAtEdges); 152 i++; SetStructureField(dataref,"RequiredVertices",bamggeom->RequiredVerticesSize[0],bamggeom->RequiredVerticesSize[1],bamggeom->RequiredVertices); 153 i++; SetStructureField(dataref,"RequiredEdges", bamggeom->RequiredEdgesSize[0], bamggeom->RequiredEdgesSize[1], bamggeom->RequiredEdges); 154 i++; SetStructureField(dataref,"CrackedEdges", bamggeom->CrackedEdgesSize[0], bamggeom->CrackedEdgesSize[1], bamggeom->CrackedEdges); 155 i++; SetStructureField(dataref,"SubDomains", bamggeom->SubDomainsSize[0], bamggeom->SubDomainsSize[1], bamggeom->SubDomains); 156 _assert_(i==numfields); 157 158 /*Assign output*/ 159 *pdataref=dataref; 160 } 161 /*}}}*/ 162 /*FUNCTION WriteData(mxArray** pdataref,BamgMesh* bamgmesh){{{1*/ 163 void WriteData(mxArray** pdataref,BamgMesh* bamgmesh){ 164 165 /*Intermediary*/ 166 int i; 167 mxArray *dataref = NULL; 168 const int numfields = 16; 169 const char *fnames[numfields]; 170 mwSize ndim = 2; 171 mwSize dimensions[2] = {1,1}; 172 173 /*Initialize field names*/ 174 i=0; 175 fnames[i++] = "Triangles"; 176 fnames[i++] = "Vertices"; 177 fnames[i++] = "Edges"; 178 fnames[i++] = "IssmSegments"; 179 fnames[i++] = "IssmEdges"; 180 fnames[i++] = "Quadrilaterals"; 181 fnames[i++] = "VerticesOnGeomVertex"; 182 fnames[i++] = "VerticesOnGeomEdge"; 183 fnames[i++] = "EdgesOnGeomEdge"; 184 fnames[i++] = "SubDomains"; 185 fnames[i++] = "SubDomainsFromGeom"; 186 fnames[i++] = "ElementConnectivity"; 187 fnames[i++] = "NodalConnectivity"; 188 fnames[i++] = "NodalElementConnectivity"; 189 fnames[i++] = "CrackedVertices"; 190 fnames[i++] = "CrackedEdges"; 191 _assert_(i==numfields); 192 193 /*Initialize Matlab structure*/ 194 dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames); 195 196 /*set each matlab each field*/ 197 i=0; 198 i++; SetStructureField(dataref,"Triangles", bamgmesh->TrianglesSize[0],bamgmesh->TrianglesSize[1], bamgmesh->Triangles); 199 i++; SetStructureField(dataref,"Vertices",bamgmesh->VerticesSize[0], bamgmesh->VerticesSize[1],bamgmesh->Vertices); 200 i++; SetStructureField(dataref,"Edges", bamgmesh->EdgesSize[0],bamgmesh->EdgesSize[1], bamgmesh->Edges); 201 i++; SetStructureField(dataref,"IssmSegments",bamgmesh->IssmSegmentsSize[0], bamgmesh->IssmSegmentsSize[1],bamgmesh->IssmSegments); 202 i++; SetStructureField(dataref,"IssmEdges", bamgmesh->IssmEdgesSize[0],bamgmesh->IssmEdgesSize[1], bamgmesh->IssmEdges); 203 i++; SetStructureField(dataref,"Quadrilaterals",bamgmesh->QuadrilateralsSize[0], bamgmesh->QuadrilateralsSize[1],bamgmesh->Quadrilaterals); 204 i++; SetStructureField(dataref,"VerticesOnGeomVertex",bamgmesh->VerticesOnGeomVertexSize[0],bamgmesh->VerticesOnGeomVertexSize[1], bamgmesh->VerticesOnGeomVertex); 205 i++; SetStructureField(dataref,"VerticesOnGeomEdge",bamgmesh->VerticesOnGeomEdgeSize[0],bamgmesh->VerticesOnGeomEdgeSize[1], bamgmesh->VerticesOnGeomEdge); 206 i++; SetStructureField(dataref,"EdgesOnGeomEdge", bamgmesh->EdgesOnGeomEdgeSize[0], bamgmesh->EdgesOnGeomEdgeSize[1],bamgmesh->EdgesOnGeomEdge); 207 i++; SetStructureField(dataref,"SubDomains",bamgmesh->SubDomainsSize[0], bamgmesh->SubDomainsSize[1],bamgmesh->SubDomains); 208 i++; SetStructureField(dataref,"SubDomainsFromGeom", bamgmesh->SubDomainsFromGeomSize[0], bamgmesh->SubDomainsFromGeomSize[1],bamgmesh->SubDomainsFromGeom); 209 i++; SetStructureField(dataref,"ElementConnectivity",bamgmesh->ElementConnectivitySize[0],bamgmesh->ElementConnectivitySize[1], bamgmesh->ElementConnectivity); 210 i++; SetStructureField(dataref,"NodalConnectivity",bamgmesh->NodalConnectivitySize[0],bamgmesh->NodalConnectivitySize[1], bamgmesh->NodalConnectivity); 211 i++; SetStructureField(dataref,"NodalElementConnectivity", bamgmesh->NodalElementConnectivitySize[0], bamgmesh->NodalElementConnectivitySize[1],bamgmesh->NodalElementConnectivity); 212 i++; SetStructureField(dataref,"CrackedVertices", bamgmesh->CrackedVerticesSize[0],bamgmesh->CrackedVerticesSize[1], bamgmesh->CrackedVertices); 213 i++; SetStructureField(dataref,"CrackedEdges",bamgmesh->CrackedEdgesSize[0], bamgmesh->CrackedEdgesSize[1],bamgmesh->CrackedEdges); 214 _assert_(i==numfields); 215 216 /*Assign output*/ 217 *pdataref=dataref; 218 } 219 /*}}}*/ 17 220 /*FUNCTION WriteData(mxArray** pdataref,Matrix* matrix){{{1*/ 18 221 void WriteData(mxArray** pdataref,Matrix* matrix){ 19 222 20 int i,j; 21 mxArray* dataref=NULL; 22 double* matrix_ptr=NULL; 223 int i,j; 23 224 int rows,cols; 24 double* tmatrix_ptr=NULL; 225 mxArray *dataref = NULL; 226 double *matrix_ptr = NULL; 227 double *tmatrix_ptr = NULL; 25 228 26 229 if(matrix){ … … 93 296 } 94 297 /*}}}*/ 95 /*FUNCTION WriteData(mxArray** pdataref,double* matrix, int M,int N){{{1*/ 96 void WriteData(mxArray** pdataref,double* matrix, int M,int N){ 97 98 mxArray *dataref = NULL; 99 double *tmatrix = NULL; 100 101 if(matrix){ 102 /*create the matlab matrixwith Matlab's memory manager */ 103 tmatrix=(double*)mxMalloc(M*N*sizeof(double)); 104 for(int i=0;i<M;i++){ 105 for(int j=0;j<N;j++){ 106 tmatrix[i*N+j]=matrix[j*M+i]; 298 299 /*Toolkit*/ 300 /*FUNCTION SetStructureField{{{1*/ 301 void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer){ 302 303 /*Intermediary*/ 304 int i1,i2; 305 mxArray *pfield = NULL; 306 307 /*Copy field using Matlab's API and transpose*/ 308 double* fieldcopy=NULL; 309 if (fieldrows*fieldcols){ 310 fieldcopy=(double*)mxMalloc(fieldrows*fieldcols*sizeof(double)); 311 for(i1=0;i1<fieldrows;i1++){ 312 for(i2=0;i2<fieldcols;i2++){ 313 fieldcopy[fieldcols*i1+i2]=fieldpointer[fieldrows*i2+i1]; 107 314 } 108 315 } 109 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 110 mxSetM(dataref,(mwSize)M); 111 mxSetN(dataref,(mwSize)N); 112 mxSetPr(dataref,(double*)tmatrix); 113 } 114 else{ 115 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 116 } 117 *pdataref=dataref; 118 } 119 /*}}}*/ 120 /*FUNCTION WriteData(mxArray** pdataref,int* matrix, int M,int N){{{1*/ 121 void WriteData(mxArray** pdataref,int* matrix, int M,int N){ 122 123 mxArray* dataref = NULL; 124 double* tmatrix = NULL; 125 126 if(matrix){ 127 128 /*convert to double matrix using Matlab's memory manager*/ 129 double* tmatrix=(double*)mxMalloc(M*N*sizeof(double)); 130 for(int i=0;i<M;i++){ 131 for(int j=0;j<N;j++){ 132 tmatrix[i*N+j]=(double)matrix[j*M+i]; 133 } 134 } 135 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 136 mxSetM(dataref,(mwSize)M); 137 mxSetN(dataref,(mwSize)N); 138 mxSetPr(dataref,(double*)tmatrix); 139 140 } 141 else{ 142 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 143 } 144 *pdataref=dataref; 145 } 146 /*}}}*/ 147 /*FUNCTION WriteData(mxArray** pdataref,double* vector, int M){{{1*/ 148 void WriteData(mxArray** pdataref,double* vector, int M){ 149 150 mxArray* dataref = NULL; 151 double* vector_matlab = NULL; 152 153 if(vector){ 154 155 /*create the matlab vector with Matlab's memory manager */ 156 vector_matlab=(double*)mxMalloc(M*sizeof(double)); 157 for(int i=0;i<M;i++) vector_matlab[i]=vector[i]; 158 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 159 mxSetM(dataref,(mwSize)M); 160 mxSetN(dataref,(mwSize)1); 161 mxSetPr(dataref,vector_matlab); 162 } 163 else{ 164 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 165 } 166 167 *pdataref=dataref; 168 } 169 /*}}}*/ 170 /*FUNCTION WriteData(mxArray** pdataref,double scalar){{{1*/ 171 void WriteData(mxArray** pdataref,double scalar){ 172 173 *pdataref=mxCreateDoubleScalar(scalar); 174 } 175 /*}}}*/ 176 /*FUNCTION WriteData(mxArray** pdataref,int integer){{{1*/ 177 void WriteData(mxArray** pdataref,int integer){ 178 179 *pdataref=mxCreateDoubleScalar((double)integer); 180 181 } 182 /*}}}*/ 183 /*FUNCTION WriteData(mxArray** pdataref,int boolean){{{1*/ 184 void WriteData(mxArray** pdataref,bool boolean){ 185 186 *pdataref=mxCreateDoubleScalar((double)boolean); 187 188 } 189 /*}}}*/ 190 /*FUNCTION WriteData(mxArray** pdataref,char* string){{{1*/ 191 void WriteData(mxArray** pdataref,char* string){ 192 193 *pdataref=mxCreateString(string); 194 } 195 /*}}}*/ 316 } 317 318 /*Set matlab field*/ 319 pfield=mxCreateDoubleMatrix(0,0,mxREAL); 320 mxSetM(pfield,fieldcols); 321 mxSetN(pfield,fieldrows); 322 mxSetPr(pfield,fieldcopy); 323 mxSetField(dataref,0,fieldname,pfield); 324 } 325 /*}}}*/ -
issm/trunk-jpl/src/c/matlab/io/matlabio.h
r12013 r12043 27 27 void WriteData(mxArray** pdataref,double scalar); 28 28 void WriteData(mxArray** pdataref,char* string); 29 void WriteData(mxArray** pdataref,BamgGeom* bamggeom); 30 void WriteData(mxArray** pdataref,BamgMesh* bamgmesh); 29 31 30 32 void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref); … … 44 46 void FetchData(int* pinteger,const mxArray* dataref); 45 47 void FetchData(bool* pbool,const mxArray* dataref); 48 void FetchData(BamgGeom** bamggeom,const mxArray* dataref); 49 void FetchData(BamgMesh** bamgmesh,const mxArray* dataref); 50 void FetchData(BamgOpts** bamgopts,const mxArray* dataref); 46 51 47 52 Option* OptionParse(char* name, const mxArray* prhs[]); … … 53 58 54 59 mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field); 60 void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer); 55 61 int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void )); 56 62 -
issm/trunk-jpl/src/c/objects/Bamg/BamgGeom.h
r12011 r12043 26 26 27 27 BamgGeom(); 28 BamgGeom(void* module_struct);29 28 ~BamgGeom(); 30 31 void SetStructureFields(void* matlab_struct);32 void SetStructureField(void* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);33 29 }; 34 30 -
issm/trunk-jpl/src/c/objects/Bamg/BamgMesh.cpp
r12011 r12043 18 18 this->CrackedEdgesSize[0]=0, this->CrackedEdgesSize[1]=0; this->CrackedEdges=NULL; 19 19 20 this->VerticesOnGeomVertexSize[0]=0, this->VerticesOnGeomVertexSize[1]=0;this->VerticesOnGeomVertex=NULL;21 this->VerticesOnGeomEdgeSize[0]=0, this->VerticesOnGeomEdgeSize[1]=0;this->VerticesOnGeomEdge=NULL;22 this->EdgesOnGeomEdgeSize[0]=0, this->EdgesOnGeomEdgeSize[1]=0;this->EdgesOnGeomEdge=NULL;20 this->VerticesOnGeomVertexSize[0]=0, this->VerticesOnGeomVertexSize[1]=0; this->VerticesOnGeomVertex=NULL; 21 this->VerticesOnGeomEdgeSize[0]=0, this->VerticesOnGeomEdgeSize[1]=0; this->VerticesOnGeomEdge=NULL; 22 this->EdgesOnGeomEdgeSize[0]=0, this->EdgesOnGeomEdgeSize[1]=0; this->EdgesOnGeomEdge=NULL; 23 23 24 24 this->IssmEdgesSize[0]=0, this->IssmEdgesSize[1]=0; this->IssmEdges=NULL; … … 28 28 this->NodalConnectivitySize[0]=0, this->NodalConnectivitySize[1]=0; this->NodalConnectivity=NULL; 29 29 this->NodalElementConnectivitySize[0]=0, this->NodalElementConnectivitySize[1]=0; this->NodalElementConnectivity=NULL; 30 31 32 30 } 33 31 /*}}}*/ -
issm/trunk-jpl/src/c/objects/Bamg/BamgMesh.h
r12011 r12043 47 47 48 48 BamgMesh(); 49 BamgMesh(void* module_struct);50 49 ~BamgMesh(); 51 52 void SetStructureFields(void* module_struct);53 void SetStructureField(void* module_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);54 55 50 }; 56 51 -
issm/trunk-jpl/src/c/objects/Bamg/BamgOpts.h
r12011 r12043 50 50 51 51 BamgOpts(); 52 BamgOpts(void* module_struct);53 52 ~BamgOpts(); 54 53
Note:
See TracChangeset
for help on using the changeset viewer.