Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/OptionParse.cpp =================================================================== --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/OptionParse.cpp (revision 12433) +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/OptionParse.cpp (revision 12434) @@ -21,14 +21,13 @@ /*check and parse the name */ odouble=new OptionDouble; - odouble->name =(char *) xmalloc((strlen(name)+1)*sizeof(char)); + odouble->name =xNew(strlen(name)+1); memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char)); /*check and parse the value */ if (!mxIsClass(prhs[0],"double")){ _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",odouble->name,"double",odouble->name,mxGetClassName(prhs[0])); } - FetchData(&odouble->values,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]); return(odouble); @@ -40,14 +39,13 @@ /*check and parse the name */ ological=new OptionLogical; - ological->name =(char*)xmalloc((strlen(name)+1)*sizeof(char)); + ological->name =xNew(strlen(name)+1); memcpy(ological->name,name,(strlen(name)+1)*sizeof(char)); /*check and parse the value */ if (!mxIsClass(prhs[0],"logical")){ _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ological->name,"logical",ological->name,mxGetClassName(prhs[0])); } - FetchData(&ological->values,&ological->numel,&ological->ndims,&ological->size,prhs[0]); return(ological); @@ -59,14 +57,13 @@ /*check and parse the name */ ochar=new OptionChar(); - ochar->name =(char*)xmalloc((strlen(name)+1)*sizeof(char)); + ochar->name =xNew(strlen(name)+1); memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char)); /*check and parse the value */ if (!mxIsClass(prhs[0],"char")){ _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ochar->name,"char",ochar->name,mxGetClassName(prhs[0])); } - FetchData(&ochar->values,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]); return(ochar); @@ -84,20 +81,19 @@ /*check and parse the name */ ostruct=new OptionStruct; - ostruct->name =(char*)xmalloc((strlen(name)+1)*sizeof(char)); + ostruct->name =xNew(strlen(name)+1); memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char)); /*check and parse the value */ if (!mxIsClass(prhs[0],"struct")){ _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ostruct->name,"struct",ostruct->name,mxGetClassName(prhs[0])); } - ostruct->numel=mxGetNumberOfElements(prhs[0]); ostruct->ndims=mxGetNumberOfDimensions(prhs[0]); ipt =mxGetDimensions(prhs[0]); - ostruct->size =(int *) xmalloc(ostruct->ndims*sizeof(int)); + ostruct->size =xNew(ostruct->ndims); for (i=0; indims; i++) ostruct->size[i]=(int)ipt[i]; - if (ostruct->numel) ostruct->values=(Options**) xmalloc(ostruct->numel*sizeof(Options *)); + if (ostruct->numel) ostruct->values=xNew(ostruct->numel); /*loop through and process each element of the struct array */ for (sindex=0; sindexnumel; sindex++) { @@ -131,7 +127,7 @@ /*check and parse the name */ ocell=new OptionCell; - ocell->name =(char *) xmalloc((strlen(name)+1)*sizeof(char)); + ocell->name =xNew(strlen(name)+1); memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char)); /*check and parse the value */ @@ -142,12 +138,12 @@ ocell->numel=mxGetNumberOfElements(prhs[0]); ocell->ndims=mxGetNumberOfDimensions(prhs[0]); ipt =mxGetDimensions(prhs[0]); - ocell->size =(int *) xmalloc(ocell->ndims*sizeof(int)); + ocell->size =xNew(ocell->ndims); for (i=0; indims; i++) ocell->size[i]=(int)ipt[i]; ocell->values=new Options; /*loop through and process each element of the cell array */ - dims=(int *) xmalloc(ocell->ndims*sizeof(int)); + dims=xNew(ocell->ndims); for (cindex=0; cindexnumel; cindex++) { ColumnWiseDimsFromIndex(dims,(int)cindex,ocell->size,ocell->ndims); StringFromDims(cstr,dims,ocell->ndims); @@ -162,7 +158,7 @@ ocell->values->AddObject((Object*)option); option=NULL; } - xfree((void**)&dims); + xDelete(dims); return(ocell); }/*}}}*/ Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp =================================================================== --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp (revision 12433) +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp (revision 12434) @@ -92,7 +92,7 @@ if (pnumel)*pnumel=outmatrix_numel; if (pndims)*pndims=outmatrix_ndims; if (psize )*psize =outmatrix_size; - else xfree((void**)&outmatrix_size); + else xDelete(outmatrix_size); } /*}}}*/ @@ -123,7 +123,7 @@ MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref); /*Convert double matrix into integer matrix: */ - outmatrix=(int*)xmalloc(outmatrix_rows*outmatrix_cols*sizeof(int)); + outmatrix=xNew(outmatrix_rows*outmatrix_cols); for(i=0;i(outmatrix_rows*outmatrix_cols); for(i=0;i(outmatrix_numel); for(i=0;i(doublematrix); } } else{ @@ -241,7 +241,7 @@ if (pnumel)*pnumel=outmatrix_numel; if (pndims)*pndims=outmatrix_ndims; if (psize )*psize =outmatrix_size; - else xfree((void**)&outmatrix_size); + else xDelete(outmatrix_size); } /*}}}*/ @@ -291,7 +291,7 @@ MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref); /*Convert double vector into integer vector: */ - outvector=(int*)xmalloc(outvector_rows*sizeof(int)); + outvector=xNew(outvector_rows); for(i=0;i(outvector_rows); for(i=0;i(outvector_rows); for(i=0;i(stringlen); mxGetString(dataref,outstring,stringlen); } @@ -419,7 +419,7 @@ if (pnumel)*pnumel=outmatrix_numel; if (pndims)*pndims=outmatrix_ndims; if (psize )*psize =outmatrix_size; - else xfree((void**)&outmatrix_size); + else xDelete(outmatrix_size); } /*}}}*/ Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabVectorToDoubleVector.cpp =================================================================== --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabVectorToDoubleVector.cpp (revision 12433) +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabVectorToDoubleVector.cpp (revision 12434) @@ -50,7 +50,7 @@ nz=(int)((double)nnz/(double)rows); if(rows){ - vector=(double*)xcalloc(rows,sizeof(double)); + vector=xNewInit(rows,0.0); /*Now, get ir,jc and pr: */ pr=mxGetPr(mxvector); @@ -80,7 +80,7 @@ /*allocate and memcpy*/ if(rows){ - vector=(double*)xmalloc(rows*sizeof(double)); + vector=xNew(rows); memcpy(vector,mxvector_ptr,rows*sizeof(double)); } else{ Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp =================================================================== --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp (revision 12433) +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp (revision 12434) @@ -248,7 +248,7 @@ mxSetPr(dataref,tmatrix_ptr); /*Free ressources:*/ - xfree((void**)&matrix_ptr); + xDelete(matrix_ptr); } else{ @@ -289,7 +289,7 @@ } /*Clean-up and return*/ - xfree((void**)&vector_ptr); + xDelete(vector_ptr); *pdataref=dataref; } /*}}}*/ Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp =================================================================== --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp (revision 12433) +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp (revision 12434) @@ -38,7 +38,7 @@ cols=mxGetN(mxmatrix); if(rows*cols){ - matrix=(double*)xcalloc(rows*cols,sizeof(double)); + matrix=xNewInit(rows*cols,0.0); /*Now, get ir,jc and pr: */ ir=mxGetIr(mxmatrix); @@ -63,7 +63,7 @@ /*Create serial matrix: */ if(rows*cols){ - matrix=(double*)xcalloc(rows*cols,sizeof(double)); + matrix=xNewInit(rows*cols,0.0); for(i=0;i(rows*cols,0.0); for(i=0;i(rows*cols,0.0); for(i=0;i(rows); for(i=0;i(size); /* Try to print in the allocated space. */ va_start(args, format); @@ -46,13 +46,13 @@ else /* glibc 2.0 */ size*=2; /* twice the old size */ - xfree((void**)&buffer); + xDelete(buffer); } /*Ok, if we are running in parallel, get node 0 to print*/ if(my_rank==0)printf(buffer); /*Clean up and return*/ - xfree((void**)&buffer); + xDelete(buffer); return 1; } Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp =================================================================== --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp (revision 12433) +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp (revision 12434) @@ -8,8 +8,8 @@ #else #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" #endif +#include "../../shared/shared.h" - /*Petsc includes: */ #include "petscmat.h" #include "petscvec.h" @@ -18,30 +18,28 @@ /*Matlab includes: */ #include "mex.h" -#include "../../shared/shared.h" - int MatlabMatrixToPetscMatrix(Mat* pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ int rows, cols; - double* mxmatrix_ptr=NULL; - double* tmatrix=NULL; + double *mxmatrix_ptr = NULL; + double *tmatrix = NULL; int ierr; int i,j; /*output: */ - Mat matrix=NULL; + Mat matrix = NULL; /*matlab indices: */ - mwIndex* ir=NULL; - mwIndex* jc=NULL; - double* pr=NULL; + mwIndex *ir = NULL; + mwIndex *jc = NULL; + double *pr = NULL; int count; int nnz; int nz; /*petsc indices: */ - int* idxm=NULL; - int* idxn=NULL; + int *idxm = NULL; + int *idxn = NULL; /*Ok, first check if we are dealing with a sparse or full matrix: */ if (mxIsSparse(mxmatrix)){ @@ -73,17 +71,15 @@ count++; } } - } else{ - /*Dealing with dense matrix: recover pointer and size: */ mxmatrix_ptr=(double*)mxGetPr(mxmatrix); rows=mxGetM(mxmatrix); cols=mxGetN(mxmatrix); /*transpose, as Petsc now does not allows MAT_COLUMN_ORIENTED matrices in MatSetValues: */ - tmatrix=(double*)xmalloc(rows*cols*sizeof(double)); + tmatrix=xNew(rows*cols); for(i=0;i(rows); + idxn=xNew(cols); for(i=0;i(tmatrix); } /*Assemble matrix: */ MatAssemblyBegin(matrix,MAT_FINAL_ASSEMBLY); MatAssemblyEnd(matrix,MAT_FINAL_ASSEMBLY); - /*Assign output pointer: */ *pmatrix=matrix; if(pmatrix_rows) *pmatrix_rows=rows; Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp =================================================================== --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp (revision 12433) +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp (revision 12434) @@ -38,8 +38,8 @@ numel=mxGetNumberOfElements(mxmatrix); ndims=mxGetNumberOfDimensions(mxmatrix); ipt =mxGetDimensions(mxmatrix); - size =(int *) xcalloc(ndims,sizeof(int)); - for (i=0; i(ndims); + for (i=0;i(rows*cols,0.0); /*Now, get ir,jc and pr: */ ir=mxGetIr(mxmatrix); @@ -73,15 +73,15 @@ mxmatrix_ptr=(double*)mxGetPr(mxmatrix); /*Create serial matrix: */ - matrix=(double*)xcalloc(numel,sizeof(double)); + matrix=xNewInit(numel,0.0); - dims=(int *) xcalloc(ndims,sizeof(int)); + dims=xNew(ndims); for(i=0;i(dims); } @@ -118,8 +118,8 @@ numel=mxGetNumberOfElements(mxmatrix); ndims=mxGetNumberOfDimensions(mxmatrix); ipt =mxGetDimensions(mxmatrix); - size =(int *) xcalloc(ndims,sizeof(int)); - for (i=0; i(ndims); + for (i=0;i(rows*cols,false); /*Now, get ir,jc and pm: */ ir=mxGetIr(mxmatrix); @@ -153,16 +153,14 @@ mxmatrix_ptr=(bool*)mxGetData(mxmatrix); /*Create serial matrix: */ - matrix=(bool*)xcalloc(numel,sizeof(bool)); - - dims=(int *) xcalloc(ndims,sizeof(int)); + matrix=xNew(numel); + dims=xNew(ndims); for(i=0;i(dims); } /*Assign output pointer: */ @@ -198,8 +196,8 @@ numel=mxGetNumberOfElements(mxmatrix); ndims=mxGetNumberOfDimensions(mxmatrix); ipt =mxGetDimensions(mxmatrix); - size =(int *) xcalloc(ndims,sizeof(int)); - for (i=0; i(ndims); + for (i=0;i(rows*cols); /*Now, get ir,jc and pm: */ ir=mxGetIr(mxmatrix); @@ -233,7 +231,7 @@ mxmatrix_ptr=mxGetChars(mxmatrix); /*Create serial matrix: */ - matrix=(char*)xcalloc(numel+1,sizeof(mxChar)); + matrix=xNew(numel+1); /*looping code adapted from Matlab example explore.c: */ int elements_per_page = size[0] * size[1];