Changeset 12043


Ignore:
Timestamp:
04/18/12 07:58:33 (13 years ago)
Author:
Mathieu Morlighem
Message:

Fixed Fetch and Write for Bamg objects

Location:
issm/trunk-jpl/src/c
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/Makefile.am

    r12022 r12043  
    748748                                    ./matlab/io/MatlabMatrixToMatrix.cpp\
    749749                                    ./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
    765759#}}}
    766760#Modules sources{{{1
  • issm/trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp

    r12013 r12043  
    1414#include "./matlabio.h"
    1515
     16/*Primitive data types*/
    1617/*FUNCTION FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){{{1*/
    1718void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){
     
    242243}
    243244/*}}}*/
    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 /*}}}*/
    265245/*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{1*/
    266246void FetchData(double** pvector,int* pM,const mxArray* dataref){
     
    384364        *pvector=outvector;
    385365        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;
    410366}
    411367/*}}}*/
     
    526482}
    527483/*}}}*/
     484
     485/*ISSM objects*/
     486/*FUNCTION FetchData(Matrix** pmatrix,const mxArray* dataref){{{1*/
     487void 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*/
     508void 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*/
     532void 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*/
     551void 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*/
     571void 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  
    1515#include <mex.h>
    1616
     17
     18/*Primitive data types*/
     19/*FUNCTION WriteData(mxArray** pdataref,double* matrix, int M,int N){{{1*/
     20void 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*/
     45void 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*/
     72void 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*/
     95void WriteData(mxArray** pdataref,double scalar){
     96
     97        *pdataref=mxCreateDoubleScalar(scalar);
     98}
     99/*}}}*/
     100/*FUNCTION WriteData(mxArray** pdataref,int integer){{{1*/
     101void WriteData(mxArray** pdataref,int integer){
     102
     103                *pdataref=mxCreateDoubleScalar((double)integer);
     104
     105}
     106/*}}}*/
     107/*FUNCTION WriteData(mxArray** pdataref,int boolean){{{1*/
     108void WriteData(mxArray** pdataref,bool boolean){
     109
     110        *pdataref=mxCreateDoubleScalar((double)boolean);
     111
     112}
     113/*}}}*/
     114/*FUNCTION WriteData(mxArray** pdataref,char* string){{{1*/
     115void WriteData(mxArray** pdataref,char* string){
     116
     117                *pdataref=mxCreateString(string);
     118}
     119/*}}}*/
     120
     121/*ISSM objects*/
     122/*FUNCTION WriteData(mxArray** pdataref,BamgGeom* bamggeom){{{1*/
     123void 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*/
     163void 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/*}}}*/
    17220/*FUNCTION WriteData(mxArray** pdataref,Matrix* matrix){{{1*/
    18221void WriteData(mxArray** pdataref,Matrix* matrix){
    19222               
    20         int i,j;
    21         mxArray* dataref=NULL;
    22         double*  matrix_ptr=NULL;
     223        int      i,j;
    23224        int      rows,cols;
    24         double*  tmatrix_ptr=NULL;
     225        mxArray *dataref     = NULL;
     226        double  *matrix_ptr  = NULL;
     227        double  *tmatrix_ptr = NULL;
    25228       
    26229        if(matrix){
     
    93296}
    94297/*}}}*/
    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*/
     301void 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];
    107314                        }
    108315                }
    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  
    2727void WriteData(mxArray** pdataref,double scalar);
    2828void WriteData(mxArray** pdataref,char* string);
     29void WriteData(mxArray** pdataref,BamgGeom* bamggeom);
     30void WriteData(mxArray** pdataref,BamgMesh* bamgmesh);
    2931
    3032void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref);
     
    4446void FetchData(int* pinteger,const mxArray* dataref);
    4547void FetchData(bool* pbool,const mxArray* dataref);
     48void FetchData(BamgGeom** bamggeom,const mxArray* dataref);
     49void FetchData(BamgMesh** bamgmesh,const mxArray* dataref);
     50void FetchData(BamgOpts** bamgopts,const mxArray* dataref);
    4651
    4752Option* OptionParse(char* name, const mxArray* prhs[]);
     
    5358
    5459mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field);
     60void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);
    5561int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void ));
    5662
  • issm/trunk-jpl/src/c/objects/Bamg/BamgGeom.h

    r12011 r12043  
    2626
    2727                BamgGeom();
    28                 BamgGeom(void* module_struct);
    2928                ~BamgGeom();
    30 
    31                 void SetStructureFields(void* matlab_struct);
    32                 void SetStructureField(void* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);
    3329};
    3430
  • issm/trunk-jpl/src/c/objects/Bamg/BamgMesh.cpp

    r12011 r12043  
    1818        this->CrackedEdgesSize[0]=0,              this->CrackedEdgesSize[1]=0;             this->CrackedEdges=NULL;
    1919
    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;
    2323
    2424        this->IssmEdgesSize[0]=0,                 this->IssmEdgesSize[1]=0;                this->IssmEdges=NULL;
     
    2828        this->NodalConnectivitySize[0]=0,         this->NodalConnectivitySize[1]=0;        this->NodalConnectivity=NULL;
    2929        this->NodalElementConnectivitySize[0]=0,  this->NodalElementConnectivitySize[1]=0; this->NodalElementConnectivity=NULL;
    30 
    31 
    3230}
    3331/*}}}*/
  • issm/trunk-jpl/src/c/objects/Bamg/BamgMesh.h

    r12011 r12043  
    4747
    4848                BamgMesh();
    49                 BamgMesh(void* module_struct);
    5049                ~BamgMesh();
    51 
    52                 void SetStructureFields(void* module_struct);
    53                 void SetStructureField(void* module_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);
    54 
    5550};
    5651
  • issm/trunk-jpl/src/c/objects/Bamg/BamgOpts.h

    r12011 r12043  
    5050
    5151                BamgOpts();
    52                 BamgOpts(void* module_struct);
    5352                ~BamgOpts();
    5453
Note: See TracChangeset for help on using the changeset viewer.