Changeset 12397


Ignore:
Timestamp:
06/09/12 17:29:22 (13 years ago)
Author:
Mathieu Morlighem
Message:

Added support for matlab int16 data

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

Legend:

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

    r12365 r12397  
    2727                outmatrix=NULL;
    2828        }
    29         else if(mxIsClass(dataref,"double") || mxIsClass(dataref,"single")){
     29        else if(mxIsClass(dataref,"double") || mxIsClass(dataref,"single") || mxIsClass(dataref,"int16")){
    3030                /*Check dataref is not pointing to NaN: */
    3131                if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
     
    3535                }
    3636                else{
     37                        if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){
     38                                printf("Warning: converting matlab data from '%s' to 'double'\n",mxGetClassName(dataref));
     39                        }
    3740                        /*Convert matlab matrix to double* matrix: */
    3841                        MatlabMatrixToDoubleMatrix(&outmatrix,&outmatrix_rows,&outmatrix_cols,dataref);
  • issm/trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp

    r12011 r12397  
    1818int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){
    1919
    20         int     i,j,count,rows,cols;
    21         double *pmxdoublematrix = NULL;
    22         float  *pmxsinglematrix = NULL;
     20        int        i,j,count,rows,cols;
     21        double    *pmxdoublematrix = NULL;
     22        float     *pmxsinglematrix = NULL;
     23        short int *pmxint16matrix  = NULL;
    2324
    2425        /*output: */
     
    8990                }
    9091        }
     92        else if(mxIsClass(mxmatrix,"int16")){
     93                /*Dealing with dense matrix: recover pointer and size: */
     94                pmxint16matrix=(short*)mxGetPr(mxmatrix);
     95                rows=mxGetM(mxmatrix);
     96                cols=mxGetN(mxmatrix);
     97
     98                /*Create serial matrix: */
     99                if(rows*cols){
     100                        matrix=(double*)xcalloc(rows*cols,sizeof(double));
     101
     102                        for(i=0;i<rows;i++){
     103                                for(j=0;j<cols;j++){
     104                                        matrix[cols*i+j]=(double)pmxint16matrix[rows*j+i];
     105                                }
     106                        }
     107                }
     108        }
    91109        else{
    92110                _error_("Matlab matrix type Not implemented yet");
Note: See TracChangeset for help on using the changeset viewer.