Changeset 11675


Ignore:
Timestamp:
03/09/12 10:05:33 (13 years ago)
Author:
Mathieu Morlighem
Message:

Added support for 'single' matlab format

Location:
issm/trunk-jpl/src/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/io/Matlab/FetchMatlabData.cpp

    r11670 r11675  
    6060                outmatrix=NULL;
    6161        }
    62         else if (mxIsClass(dataref,"double") ){
    63 
     62        else if(mxIsClass(dataref,"double") || mxIsClass(dataref,"single")){
    6463                /*Check dataref is not pointing to NaN: */
    6564                if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
     
    6968                }
    7069                else{
    71 
    7270                        /*Convert matlab matrix to double* matrix: */
    7371                        MatlabMatrixToDoubleMatrix(&outmatrix,&outmatrix_rows,&outmatrix_cols,dataref);
  • issm/trunk-jpl/src/c/toolkits/petsc/patches/MatlabMatrixToDoubleMatrix.cpp

    r9320 r11675  
    2525int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){
    2626
    27         int rows, cols;
    28         double* mxmatrix_ptr=NULL;
    29         int ierr;
    30         int i,j;
     27        int     i,j,count,rows,cols;
     28        double *pmxdoublematrix = NULL;
     29        float  *pmxsinglematrix = NULL;
    3130
    3231        /*output: */
     
    3635        mwIndex*    ir=NULL;
    3736        mwIndex*    jc=NULL;
    38         double* pr=NULL;
    39         int     count;
    40         int     nnz;
    41         int     nz;
    4237
    4338        /*Ok, first check if we are dealing with a sparse or full matrix: */
     
    4540
    4641                /*Dealing with sparse matrix: recover size first: */
    47                 mxmatrix_ptr=(double*)mxGetPr(mxmatrix);
     42                pmxdoublematrix=(double*)mxGetPr(mxmatrix);
    4843                rows=mxGetM(mxmatrix);
    4944                cols=mxGetN(mxmatrix);
    50                 nnz=mxGetNzmax(mxmatrix);
    51                 nz=(int)((double)nnz/(double)rows);
    52 
    5345                matrix=(double*)xcalloc(rows*cols,sizeof(double));
    5446
    5547                /*Now, get ir,jc and pr: */
    56                 pr=mxGetPr(mxmatrix);
    5748                ir=mxGetIr(mxmatrix);
    5849                jc=mxGetJc(mxmatrix);
     
    6253                for(i=0;i<cols;i++){
    6354                        for(j=0;j<(jc[i+1]-jc[i]);j++){
    64                                 *(matrix+rows*ir[count]+i)=pr[count];
     55                                matrix[rows*ir[count]+i]=pmxdoublematrix[count];
    6556                                count++;
    6657                        }
     
    6859
    6960        }
    70         else{
    71 
    72 
     61        else if(mxIsClass(mxmatrix,"double")){
    7362                /*Dealing with dense matrix: recover pointer and size: */
    74                 mxmatrix_ptr=(double*)mxGetPr(mxmatrix);
     63                pmxdoublematrix=(double*)mxGetPr(mxmatrix);
    7564                rows=mxGetM(mxmatrix);
    7665                cols=mxGetN(mxmatrix);
    77 
    7866               
    7967                /*Create serial matrix: */
     
    8270                for(i=0;i<rows;i++){
    8371                        for(j=0;j<cols;j++){
    84                                 *(matrix+cols*i+j)=*(mxmatrix_ptr+rows*j+i);
     72                                matrix[cols*i+j]=(double)pmxdoublematrix[rows*j+i];
    8573                        }
    8674                }
    87                
     75        }
     76        else if(mxIsClass(mxmatrix,"single")){
     77                /*Dealing with dense matrix: recover pointer and size: */
     78                pmxsinglematrix=(float*)mxGetPr(mxmatrix);
     79                rows=mxGetM(mxmatrix);
     80                cols=mxGetN(mxmatrix);
     81
     82                /*Create serial matrix: */
     83                matrix=(double*)xcalloc(rows*cols,sizeof(double));
     84
     85                for(i=0;i<rows;i++){
     86                        for(j=0;j<cols;j++){
     87                                matrix[cols*i+j]=(double)pmxsinglematrix[rows*j+i];
     88                        }
     89                }
     90        }
     91        else{
     92                _error_("Matlab matrix type Not implemented yet");
    8893        }
    8994
Note: See TracChangeset for help on using the changeset viewer.