Changeset 12434
- Timestamp:
- 06/15/12 16:43:53 (13 years ago)
- Location:
- issm/trunk-jpl/src/c/matlab/io
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp
r12397 r12434 93 93 if (pndims)*pndims=outmatrix_ndims; 94 94 if (psize )*psize =outmatrix_size; 95 else x free((void**)&outmatrix_size);95 else xDelete<int>(outmatrix_size); 96 96 97 97 } … … 124 124 125 125 /*Convert double matrix into integer matrix: */ 126 outmatrix= (int*)xmalloc(outmatrix_rows*outmatrix_cols*sizeof(int));126 outmatrix=xNew<int>(outmatrix_rows*outmatrix_cols); 127 127 for(i=0;i<outmatrix_rows*outmatrix_cols;i++)outmatrix[i]=(int)doublematrix[i]; 128 128 } … … 166 166 167 167 /*Convert double matrix into integer matrix: */ 168 outmatrix= (bool*)xmalloc(outmatrix_rows*outmatrix_cols*sizeof(bool));168 outmatrix=xNew<bool>(outmatrix_rows*outmatrix_cols); 169 169 for(i=0;i<outmatrix_rows;i++)outmatrix[i]=(bool)doublematrix[i]; 170 170 } … … 227 227 228 228 /*Convert double matrix into bool matrix: */ 229 outmatrix= (bool*)xmalloc(outmatrix_numel*sizeof(bool));229 outmatrix=xNew<bool>(outmatrix_numel); 230 230 for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i]; 231 x free((void**)&doublematrix);231 xDelete<double>(doublematrix); 232 232 } 233 233 } … … 242 242 if (pndims)*pndims=outmatrix_ndims; 243 243 if (psize )*psize =outmatrix_size; 244 else x free((void**)&outmatrix_size);244 else xDelete<int>(outmatrix_size); 245 245 246 246 } … … 292 292 293 293 /*Convert double vector into integer vector: */ 294 outvector= (int*)xmalloc(outvector_rows*sizeof(int));294 outvector=xNew<int>(outvector_rows); 295 295 for(i=0;i<outvector_rows;i++)outvector[i]=(int)doublevector[i]; 296 296 } … … 324 324 325 325 /*Convert double vector into integer vector: */ 326 outvector= (bool*)xmalloc(outvector_rows*sizeof(bool));326 outvector=xNew<bool>(outvector_rows); 327 327 for(i=0;i<outvector_rows;i++)outvector[i]=(bool)doublevector[i]; 328 328 } … … 356 356 357 357 /*Convert double vector into float vector: */ 358 outvector= (float*)xmalloc(outvector_rows*sizeof(float));358 outvector=xNew<float>(outvector_rows); 359 359 for(i=0;i<outvector_rows;i++)outvector[i]=(float)doublevector[i]; 360 360 } … … 384 384 385 385 stringlen = mxGetM(dataref)*mxGetN(dataref)+1; 386 outstring = (char*)xmalloc(sizeof(mxChar)*stringlen);386 outstring =xNew<char>(stringlen); 387 387 mxGetString(dataref,outstring,stringlen); 388 388 } … … 420 420 if (pndims)*pndims=outmatrix_ndims; 421 421 if (psize )*psize =outmatrix_size; 422 else x free((void**)&outmatrix_size);422 else xDelete<int>(outmatrix_size); 423 423 424 424 } -
issm/trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp
r12397 r12434 39 39 40 40 if(rows*cols){ 41 matrix= (double*)xcalloc(rows*cols,sizeof(double));41 matrix=xNewInit<double>(rows*cols,0.0); 42 42 43 43 /*Now, get ir,jc and pr: */ … … 64 64 /*Create serial matrix: */ 65 65 if(rows*cols){ 66 matrix= (double*)xcalloc(rows*cols,sizeof(double));66 matrix=xNewInit<double>(rows*cols,0.0); 67 67 68 68 for(i=0;i<rows;i++){ … … 81 81 /*Create serial matrix: */ 82 82 if(rows*cols){ 83 matrix= (double*)xcalloc(rows*cols,sizeof(double));83 matrix=xNewInit<double>(rows*cols,0.0); 84 84 85 85 for(i=0;i<rows;i++){ … … 98 98 /*Create serial matrix: */ 99 99 if(rows*cols){ 100 matrix= (double*)xcalloc(rows*cols,sizeof(double));100 matrix=xNewInit<double>(rows*cols,0.0); 101 101 102 102 for(i=0;i<rows;i++){ -
issm/trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp
r12013 r12434 9 9 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 10 10 #endif 11 11 #include "../../shared/shared.h" 12 12 13 13 /*Petsc includes: */ … … 19 19 #include "mex.h" 20 20 21 #include "../../shared/shared.h"22 23 21 int MatlabMatrixToPetscMatrix(Mat* pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ 24 22 25 23 int rows, cols; 26 double * mxmatrix_ptr=NULL;27 double * tmatrix=NULL;24 double *mxmatrix_ptr = NULL; 25 double *tmatrix = NULL; 28 26 int ierr; 29 27 int i,j; 30 28 31 29 /*output: */ 32 Mat matrix =NULL;30 Mat matrix = NULL; 33 31 34 32 /*matlab indices: */ 35 mwIndex * ir=NULL;36 mwIndex * jc=NULL;37 double * pr=NULL;33 mwIndex *ir = NULL; 34 mwIndex *jc = NULL; 35 double *pr = NULL; 38 36 int count; 39 37 int nnz; … … 41 39 42 40 /*petsc indices: */ 43 int * idxm=NULL;44 int * idxn=NULL;41 int *idxm = NULL; 42 int *idxn = NULL; 45 43 46 44 /*Ok, first check if we are dealing with a sparse or full matrix: */ … … 74 72 } 75 73 } 76 77 74 } 78 75 else{ 79 80 76 /*Dealing with dense matrix: recover pointer and size: */ 81 77 mxmatrix_ptr=(double*)mxGetPr(mxmatrix); … … 84 80 85 81 /*transpose, as Petsc now does not allows MAT_COLUMN_ORIENTED matrices in MatSetValues: */ 86 tmatrix= (double*)xmalloc(rows*cols*sizeof(double));82 tmatrix=xNew<double>(rows*cols); 87 83 for(i=0;i<cols;i++){ 88 84 for(j=0;j<rows;j++){ … … 95 91 96 92 /*Insert mxmatrix_ptr values into petsc matrix: */ 97 idxm= (int*)xmalloc(rows*sizeof(int));98 idxn= (int*)xmalloc(cols*sizeof(int));93 idxm=xNew<int>(rows); 94 idxn=xNew<int>(cols); 99 95 100 96 for(i=0;i<rows;i++)idxm[i]=i; … … 103 99 ierr=MatSetValues(matrix,rows,idxm,cols,idxn,tmatrix,INSERT_VALUES); CHKERRQ(ierr); 104 100 105 xfree((void**)&tmatrix); 106 101 xDelete<double>(tmatrix); 107 102 } 108 103 … … 110 105 MatAssemblyBegin(matrix,MAT_FINAL_ASSEMBLY); 111 106 MatAssemblyEnd(matrix,MAT_FINAL_ASSEMBLY); 112 113 107 114 108 /*Assign output pointer: */ -
issm/trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp
r12365 r12434 39 39 ndims=mxGetNumberOfDimensions(mxmatrix); 40 40 ipt =mxGetDimensions(mxmatrix); 41 size = (int *) xcalloc(ndims,sizeof(int));42 for (i=0; i<ndims;i++) size[i]=(int)ipt[i];41 size =xNew<int>(ndims); 42 for (i=0;i<ndims;i++) size[i]=(int)ipt[i]; 43 43 44 44 /*Ok, first check if we are dealing with a sparse or full matrix: */ … … 51 51 nz=(int)((double)nnz/(double)rows); 52 52 53 matrix= (double*)xcalloc(rows*cols,sizeof(double));53 matrix=xNewInit<double>(rows*cols,0.0); 54 54 55 55 /*Now, get ir,jc and pr: */ … … 74 74 75 75 /*Create serial matrix: */ 76 matrix= (double*)xcalloc(numel,sizeof(double));77 78 dims= (int *) xcalloc(ndims,sizeof(int));76 matrix=xNewInit<double>(numel,0.0); 77 78 dims=xNew<int>(ndims); 79 79 for(i=0;i<numel;i++){ 80 80 ColumnWiseDimsFromIndex(dims,i,size,ndims); … … 82 82 *(matrix+j)=*(mxmatrix_ptr+i); 83 83 } 84 x free((void**)&dims);84 xDelete<int>(dims); 85 85 86 86 } … … 119 119 ndims=mxGetNumberOfDimensions(mxmatrix); 120 120 ipt =mxGetDimensions(mxmatrix); 121 size = (int *) xcalloc(ndims,sizeof(int));122 for (i=0; i<ndims;i++) size[i]=(int)ipt[i];121 size =xNew<int>(ndims); 122 for (i=0;i<ndims;i++) size[i]=(int)ipt[i]; 123 123 124 124 /*Ok, first check if we are dealing with a sparse or full matrix: */ … … 131 131 nz=(int)((double)nnz/(double)rows); 132 132 133 matrix= (bool*)xcalloc(rows*cols,sizeof(bool));133 matrix=xNewInit<bool>(rows*cols,false); 134 134 135 135 /*Now, get ir,jc and pm: */ … … 154 154 155 155 /*Create serial matrix: */ 156 matrix=(bool*)xcalloc(numel,sizeof(bool)); 157 158 dims=(int *) xcalloc(ndims,sizeof(int)); 156 matrix=xNew<bool>(numel); 157 dims=xNew<int>(ndims); 159 158 for(i=0;i<numel;i++){ 160 159 ColumnWiseDimsFromIndex(dims,i,size,ndims); … … 162 161 *(matrix+j)=(bool)*(mxmatrix_ptr+i); 163 162 } 164 xfree((void**)&dims); 165 163 xDelete<int>(dims); 166 164 } 167 165 … … 199 197 ndims=mxGetNumberOfDimensions(mxmatrix); 200 198 ipt =mxGetDimensions(mxmatrix); 201 size = (int *) xcalloc(ndims,sizeof(int));202 for (i=0; i<ndims;i++) size[i]=(int)ipt[i];199 size =xNew<int>(ndims); 200 for (i=0;i<ndims;i++) size[i]=(int)ipt[i]; 203 201 204 202 /*Ok, first check if we are dealing with a sparse or full matrix: */ … … 211 209 nz=(int)((double)nnz/(double)rows); 212 210 213 matrix= (char*)xcalloc(rows*cols,sizeof(double));211 matrix=xNew<char>(rows*cols); 214 212 215 213 /*Now, get ir,jc and pm: */ … … 234 232 235 233 /*Create serial matrix: */ 236 matrix= (char*)xcalloc(numel+1,sizeof(mxChar));234 matrix=xNew<char>(numel+1); 237 235 238 236 /*looping code adapted from Matlab example explore.c: */ -
issm/trunk-jpl/src/c/matlab/io/MatlabVectorToDoubleVector.cpp
r12011 r12434 51 51 52 52 if(rows){ 53 vector= (double*)xcalloc(rows,sizeof(double));53 vector=xNewInit<double>(rows,0.0); 54 54 55 55 /*Now, get ir,jc and pr: */ … … 81 81 /*allocate and memcpy*/ 82 82 if(rows){ 83 vector= (double*)xmalloc(rows*sizeof(double));83 vector=xNew<double>(rows); 84 84 memcpy(vector,mxvector_ptr,rows*sizeof(double)); 85 85 } -
issm/trunk-jpl/src/c/matlab/io/MatlabVectorToPetscVector.cpp
r12013 r12434 79 79 80 80 /*Insert mxvector_ptr values into petsc vector: */ 81 idxm= (int*)xmalloc(rows*sizeof(int));81 idxm=xNew<int>(rows); 82 82 83 83 for(i=0;i<rows;i++)idxm[i]=i; -
issm/trunk-jpl/src/c/matlab/io/OptionParse.cpp
r12365 r12434 22 22 /*check and parse the name */ 23 23 odouble=new OptionDouble; 24 odouble->name = (char *) xmalloc((strlen(name)+1)*sizeof(char));24 odouble->name =xNew<char>(strlen(name)+1); 25 25 memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); 26 26 … … 29 29 _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",odouble->name,"double",odouble->name,mxGetClassName(prhs[0])); 30 30 } 31 32 31 FetchData(&odouble->values,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]); 33 32 … … 41 40 /*check and parse the name */ 42 41 ological=new OptionLogical; 43 ological->name = (char*)xmalloc((strlen(name)+1)*sizeof(char));42 ological->name =xNew<char>(strlen(name)+1); 44 43 memcpy(ological->name,name,(strlen(name)+1)*sizeof(char)); 45 44 … … 48 47 _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ological->name,"logical",ological->name,mxGetClassName(prhs[0])); 49 48 } 50 51 49 FetchData(&ological->values,&ological->numel,&ological->ndims,&ological->size,prhs[0]); 52 50 … … 60 58 /*check and parse the name */ 61 59 ochar=new OptionChar(); 62 ochar->name = (char*)xmalloc((strlen(name)+1)*sizeof(char));60 ochar->name =xNew<char>(strlen(name)+1); 63 61 memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char)); 64 62 … … 67 65 _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ochar->name,"char",ochar->name,mxGetClassName(prhs[0])); 68 66 } 69 70 67 FetchData(&ochar->values,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]); 71 68 … … 85 82 /*check and parse the name */ 86 83 ostruct=new OptionStruct; 87 ostruct->name = (char*)xmalloc((strlen(name)+1)*sizeof(char));84 ostruct->name =xNew<char>(strlen(name)+1); 88 85 memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char)); 89 86 … … 92 89 _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ostruct->name,"struct",ostruct->name,mxGetClassName(prhs[0])); 93 90 } 94 95 91 ostruct->numel=mxGetNumberOfElements(prhs[0]); 96 92 ostruct->ndims=mxGetNumberOfDimensions(prhs[0]); 97 93 ipt =mxGetDimensions(prhs[0]); 98 ostruct->size = (int *) xmalloc(ostruct->ndims*sizeof(int));94 ostruct->size =xNew<int>(ostruct->ndims); 99 95 for (i=0; i<ostruct->ndims; i++) ostruct->size[i]=(int)ipt[i]; 100 if (ostruct->numel) ostruct->values= (Options**) xmalloc(ostruct->numel*sizeof(Options *));96 if (ostruct->numel) ostruct->values=xNew<Options*>(ostruct->numel); 101 97 102 98 /*loop through and process each element of the struct array */ … … 132 128 /*check and parse the name */ 133 129 ocell=new OptionCell; 134 ocell->name = (char *) xmalloc((strlen(name)+1)*sizeof(char));130 ocell->name =xNew<char>(strlen(name)+1); 135 131 memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char)); 136 132 … … 143 139 ocell->ndims=mxGetNumberOfDimensions(prhs[0]); 144 140 ipt =mxGetDimensions(prhs[0]); 145 ocell->size = (int *) xmalloc(ocell->ndims*sizeof(int));141 ocell->size =xNew<int>(ocell->ndims); 146 142 for (i=0; i<ocell->ndims; i++) ocell->size[i]=(int)ipt[i]; 147 143 ocell->values=new Options; 148 144 149 145 /*loop through and process each element of the cell array */ 150 dims= (int *) xmalloc(ocell->ndims*sizeof(int));146 dims=xNew<int>(ocell->ndims); 151 147 for (cindex=0; cindex<ocell->numel; cindex++) { 152 148 ColumnWiseDimsFromIndex(dims,(int)cindex,ocell->size,ocell->ndims); … … 163 159 option=NULL; 164 160 } 165 x free((void**)&dims);161 xDelete<int>(dims); 166 162 167 163 return(ocell); -
issm/trunk-jpl/src/c/matlab/io/PrintfFunction.cpp
r12016 r12434 27 27 28 28 /*allocate buffer for given string size*/ 29 buffer= (char*)xmalloc(size*sizeof(char));29 buffer=xNew<char>(size); 30 30 31 31 /* Try to print in the allocated space. */ … … 47 47 size*=2; /* twice the old size */ 48 48 49 x free((void**)&buffer);49 xDelete<char>(buffer); 50 50 } 51 51 … … 54 54 55 55 /*Clean up and return*/ 56 x free((void**)&buffer);56 xDelete<char>(buffer); 57 57 return 1; 58 58 } -
issm/trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp
r12365 r12434 249 249 250 250 /*Free ressources:*/ 251 x free((void**)&matrix_ptr);251 xDelete<double>(matrix_ptr); 252 252 253 253 } … … 290 290 291 291 /*Clean-up and return*/ 292 x free((void**)&vector_ptr);292 xDelete<double>(vector_ptr); 293 293 *pdataref=dataref; 294 294 }
Note:
See TracChangeset
for help on using the changeset viewer.