Changeset 11675
- Timestamp:
- 03/09/12 10:05:33 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/io/Matlab/FetchMatlabData.cpp
r11670 r11675 60 60 outmatrix=NULL; 61 61 } 62 else if (mxIsClass(dataref,"double") ){ 63 62 else if(mxIsClass(dataref,"double") || mxIsClass(dataref,"single")){ 64 63 /*Check dataref is not pointing to NaN: */ 65 64 if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){ … … 69 68 } 70 69 else{ 71 72 70 /*Convert matlab matrix to double* matrix: */ 73 71 MatlabMatrixToDoubleMatrix(&outmatrix,&outmatrix_rows,&outmatrix_cols,dataref); -
issm/trunk-jpl/src/c/toolkits/petsc/patches/MatlabMatrixToDoubleMatrix.cpp
r9320 r11675 25 25 int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ 26 26 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; 31 30 32 31 /*output: */ … … 36 35 mwIndex* ir=NULL; 37 36 mwIndex* jc=NULL; 38 double* pr=NULL;39 int count;40 int nnz;41 int nz;42 37 43 38 /*Ok, first check if we are dealing with a sparse or full matrix: */ … … 45 40 46 41 /*Dealing with sparse matrix: recover size first: */ 47 mxmatrix_ptr=(double*)mxGetPr(mxmatrix);42 pmxdoublematrix=(double*)mxGetPr(mxmatrix); 48 43 rows=mxGetM(mxmatrix); 49 44 cols=mxGetN(mxmatrix); 50 nnz=mxGetNzmax(mxmatrix);51 nz=(int)((double)nnz/(double)rows);52 53 45 matrix=(double*)xcalloc(rows*cols,sizeof(double)); 54 46 55 47 /*Now, get ir,jc and pr: */ 56 pr=mxGetPr(mxmatrix);57 48 ir=mxGetIr(mxmatrix); 58 49 jc=mxGetJc(mxmatrix); … … 62 53 for(i=0;i<cols;i++){ 63 54 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]; 65 56 count++; 66 57 } … … 68 59 69 60 } 70 else{ 71 72 61 else if(mxIsClass(mxmatrix,"double")){ 73 62 /*Dealing with dense matrix: recover pointer and size: */ 74 mxmatrix_ptr=(double*)mxGetPr(mxmatrix);63 pmxdoublematrix=(double*)mxGetPr(mxmatrix); 75 64 rows=mxGetM(mxmatrix); 76 65 cols=mxGetN(mxmatrix); 77 78 66 79 67 /*Create serial matrix: */ … … 82 70 for(i=0;i<rows;i++){ 83 71 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]; 85 73 } 86 74 } 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"); 88 93 } 89 94
Note:
See TracChangeset
for help on using the changeset viewer.