Changeset 12594


Ignore:
Timestamp:
07/02/12 09:50:48 (13 years ago)
Author:
Mathieu Morlighem
Message:

Added support for uint8

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

Legend:

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

    r12511 r12594  
    2727                outmatrix=NULL;
    2828        }
    29         else if(mxIsClass(dataref,"double") || mxIsClass(dataref,"single") || mxIsClass(dataref,"int16")){
     29        else if( mxIsClass(dataref,"double") ||
     30                                mxIsClass(dataref,"single") ||
     31                                mxIsClass(dataref,"int16") ||
     32                                mxIsClass(dataref,"int8") ||
     33                                mxIsClass(dataref,"uint8")){
    3034                /*Check dataref is not pointing to NaN: */
    3135                if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
     
    390394        /*Assign output pointers:*/
    391395        *pstring=outstring;
    392 }
     396}/*}}}*/
    393397/*FUNCTION FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/
    394398void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
  • issm/trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp

    r12493 r12594  
    22 * \brief: convert a sparse or dense matlab matrix to a double* pointer
    33 */
    4 
    54
    65#ifdef HAVE_CONFIG_H
     
    109#endif
    1110
    12 
    1311/*Matlab includes: */
    1412#include "mex.h"
    15 
    1613#include "../../shared/shared.h"
    1714
     
    1916
    2017        int        i,j,count,rows,cols;
    21         double    *pmxdoublematrix = NULL;
    22         float     *pmxsinglematrix = NULL;
    23         short int *pmxint16matrix  = NULL;
    2418
    2519        /*output: */
     
    3428
    3529                /*Dealing with sparse matrix: recover size first: */
    36                 pmxdoublematrix=(double*)mxGetPr(mxmatrix);
     30                double* pmxmatrix=(double*)mxGetPr(mxmatrix);
    3731                rows=mxGetM(mxmatrix);
    3832                cols=mxGetN(mxmatrix);
     
    4943                        for(i=0;i<cols;i++){
    5044                                for(j=0;j<(jc[i+1]-jc[i]);j++){
    51                                         matrix[rows*ir[count]+i]=pmxdoublematrix[count];
     45                                        matrix[rows*ir[count]+i]=pmxmatrix[count];
    5246                                        count++;
    5347                                }
     
    5852        else if(mxIsClass(mxmatrix,"double")){
    5953                /*Dealing with dense matrix: recover pointer and size: */
    60                 pmxdoublematrix=(double*)mxGetPr(mxmatrix);
     54                double* pmxmatrix=(double*)mxGetPr(mxmatrix);
    6155                rows=mxGetM(mxmatrix);
    6256                cols=mxGetN(mxmatrix);
     
    6862                        for(i=0;i<rows;i++){
    6963                                for(j=0;j<cols;j++){
    70                                         matrix[cols*i+j]=(double)pmxdoublematrix[rows*j+i];
     64                                        matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    7165                                }
    7266                        }
     
    7569        else if(mxIsClass(mxmatrix,"single")){
    7670                /*Dealing with dense matrix: recover pointer and size: */
    77                 pmxsinglematrix=(float*)mxGetPr(mxmatrix);
     71                float *pmxmatrix=(float*)mxGetPr(mxmatrix);
    7872                rows=mxGetM(mxmatrix);
    7973                cols=mxGetN(mxmatrix);
     
    8579                        for(i=0;i<rows;i++){
    8680                                for(j=0;j<cols;j++){
    87                                         matrix[cols*i+j]=(double)pmxsinglematrix[rows*j+i];
     81                                        matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    8882                                }
    8983                        }
     
    9286        else if(mxIsClass(mxmatrix,"int16")){
    9387                /*Dealing with dense matrix: recover pointer and size: */
    94                 pmxint16matrix=(short*)mxGetPr(mxmatrix);
     88                short int *pmxmatrix=(short*)mxGetPr(mxmatrix);
    9589                rows=mxGetM(mxmatrix);
    9690                cols=mxGetN(mxmatrix);
     
    10296                        for(i=0;i<rows;i++){
    10397                                for(j=0;j<cols;j++){
    104                                         matrix[cols*i+j]=(double)pmxint16matrix[rows*j+i];
     98                                        matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
     99                                }
     100                        }
     101                }
     102        }
     103        else if(mxIsClass(mxmatrix,"uint8")){
     104                /*Dealing with dense matrix: recover pointer and size: */
     105                char *pmxmatrix=(char*)mxGetPr(mxmatrix);
     106                rows=mxGetM(mxmatrix);
     107                cols=mxGetN(mxmatrix);
     108
     109                /*Create serial matrix: */
     110                if(rows*cols){
     111                        matrix=xNewZeroInit<double>(rows*cols);
     112
     113                        for(i=0;i<rows;i++){
     114                                for(j=0;j<cols;j++){
     115                                        matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
    105116                                }
    106117                        }
Note: See TracChangeset for help on using the changeset viewer.