[12679] | 1 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/OptionParse.cpp
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/OptionParse.cpp (revision 12433)
|
---|
| 4 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/OptionParse.cpp (revision 12434)
|
---|
| 5 | @@ -21,14 +21,13 @@
|
---|
| 6 |
|
---|
| 7 | /*check and parse the name */
|
---|
| 8 | odouble=new OptionDouble;
|
---|
| 9 | - odouble->name =(char *) xmalloc((strlen(name)+1)*sizeof(char));
|
---|
| 10 | + odouble->name =xNew<char>(strlen(name)+1);
|
---|
| 11 | memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));
|
---|
| 12 |
|
---|
| 13 | /*check and parse the value */
|
---|
| 14 | if (!mxIsClass(prhs[0],"double")){
|
---|
| 15 | _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",odouble->name,"double",odouble->name,mxGetClassName(prhs[0]));
|
---|
| 16 | }
|
---|
| 17 | -
|
---|
| 18 | FetchData(&odouble->values,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]);
|
---|
| 19 |
|
---|
| 20 | return(odouble);
|
---|
| 21 | @@ -40,14 +39,13 @@
|
---|
| 22 |
|
---|
| 23 | /*check and parse the name */
|
---|
| 24 | ological=new OptionLogical;
|
---|
| 25 | - ological->name =(char*)xmalloc((strlen(name)+1)*sizeof(char));
|
---|
| 26 | + ological->name =xNew<char>(strlen(name)+1);
|
---|
| 27 | memcpy(ological->name,name,(strlen(name)+1)*sizeof(char));
|
---|
| 28 |
|
---|
| 29 | /*check and parse the value */
|
---|
| 30 | if (!mxIsClass(prhs[0],"logical")){
|
---|
| 31 | _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ological->name,"logical",ological->name,mxGetClassName(prhs[0]));
|
---|
| 32 | }
|
---|
| 33 | -
|
---|
| 34 | FetchData(&ological->values,&ological->numel,&ological->ndims,&ological->size,prhs[0]);
|
---|
| 35 |
|
---|
| 36 | return(ological);
|
---|
| 37 | @@ -59,14 +57,13 @@
|
---|
| 38 |
|
---|
| 39 | /*check and parse the name */
|
---|
| 40 | ochar=new OptionChar();
|
---|
| 41 | - ochar->name =(char*)xmalloc((strlen(name)+1)*sizeof(char));
|
---|
| 42 | + ochar->name =xNew<char>(strlen(name)+1);
|
---|
| 43 | memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char));
|
---|
| 44 |
|
---|
| 45 | /*check and parse the value */
|
---|
| 46 | if (!mxIsClass(prhs[0],"char")){
|
---|
| 47 | _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ochar->name,"char",ochar->name,mxGetClassName(prhs[0]));
|
---|
| 48 | }
|
---|
| 49 | -
|
---|
| 50 | FetchData(&ochar->values,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]);
|
---|
| 51 |
|
---|
| 52 | return(ochar);
|
---|
| 53 | @@ -84,20 +81,19 @@
|
---|
| 54 |
|
---|
| 55 | /*check and parse the name */
|
---|
| 56 | ostruct=new OptionStruct;
|
---|
| 57 | - ostruct->name =(char*)xmalloc((strlen(name)+1)*sizeof(char));
|
---|
| 58 | + ostruct->name =xNew<char>(strlen(name)+1);
|
---|
| 59 | memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char));
|
---|
| 60 |
|
---|
| 61 | /*check and parse the value */
|
---|
| 62 | if (!mxIsClass(prhs[0],"struct")){
|
---|
| 63 | _error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ostruct->name,"struct",ostruct->name,mxGetClassName(prhs[0]));
|
---|
| 64 | }
|
---|
| 65 | -
|
---|
| 66 | ostruct->numel=mxGetNumberOfElements(prhs[0]);
|
---|
| 67 | ostruct->ndims=mxGetNumberOfDimensions(prhs[0]);
|
---|
| 68 | ipt =mxGetDimensions(prhs[0]);
|
---|
| 69 | - ostruct->size =(int *) xmalloc(ostruct->ndims*sizeof(int));
|
---|
| 70 | + ostruct->size =xNew<int>(ostruct->ndims);
|
---|
| 71 | for (i=0; i<ostruct->ndims; i++) ostruct->size[i]=(int)ipt[i];
|
---|
| 72 | - if (ostruct->numel) ostruct->values=(Options**) xmalloc(ostruct->numel*sizeof(Options *));
|
---|
| 73 | + if (ostruct->numel) ostruct->values=xNew<Options*>(ostruct->numel);
|
---|
| 74 |
|
---|
| 75 | /*loop through and process each element of the struct array */
|
---|
| 76 | for (sindex=0; sindex<ostruct->numel; sindex++) {
|
---|
| 77 | @@ -131,7 +127,7 @@
|
---|
| 78 |
|
---|
| 79 | /*check and parse the name */
|
---|
| 80 | ocell=new OptionCell;
|
---|
| 81 | - ocell->name =(char *) xmalloc((strlen(name)+1)*sizeof(char));
|
---|
| 82 | + ocell->name =xNew<char>(strlen(name)+1);
|
---|
| 83 | memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char));
|
---|
| 84 |
|
---|
| 85 | /*check and parse the value */
|
---|
| 86 | @@ -142,12 +138,12 @@
|
---|
| 87 | ocell->numel=mxGetNumberOfElements(prhs[0]);
|
---|
| 88 | ocell->ndims=mxGetNumberOfDimensions(prhs[0]);
|
---|
| 89 | ipt =mxGetDimensions(prhs[0]);
|
---|
| 90 | - ocell->size =(int *) xmalloc(ocell->ndims*sizeof(int));
|
---|
| 91 | + ocell->size =xNew<int>(ocell->ndims);
|
---|
| 92 | for (i=0; i<ocell->ndims; i++) ocell->size[i]=(int)ipt[i];
|
---|
| 93 | ocell->values=new Options;
|
---|
| 94 |
|
---|
| 95 | /*loop through and process each element of the cell array */
|
---|
| 96 | - dims=(int *) xmalloc(ocell->ndims*sizeof(int));
|
---|
| 97 | + dims=xNew<int>(ocell->ndims);
|
---|
| 98 | for (cindex=0; cindex<ocell->numel; cindex++) {
|
---|
| 99 | ColumnWiseDimsFromIndex(dims,(int)cindex,ocell->size,ocell->ndims);
|
---|
| 100 | StringFromDims(cstr,dims,ocell->ndims);
|
---|
| 101 | @@ -162,7 +158,7 @@
|
---|
| 102 | ocell->values->AddObject((Object*)option);
|
---|
| 103 | option=NULL;
|
---|
| 104 | }
|
---|
| 105 | - xfree((void**)&dims);
|
---|
| 106 | + xDelete<int>(dims);
|
---|
| 107 |
|
---|
| 108 | return(ocell);
|
---|
| 109 | }/*}}}*/
|
---|
| 110 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp
|
---|
| 111 | ===================================================================
|
---|
| 112 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp (revision 12433)
|
---|
| 113 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/FetchMatlabData.cpp (revision 12434)
|
---|
| 114 | @@ -92,7 +92,7 @@
|
---|
| 115 | if (pnumel)*pnumel=outmatrix_numel;
|
---|
| 116 | if (pndims)*pndims=outmatrix_ndims;
|
---|
| 117 | if (psize )*psize =outmatrix_size;
|
---|
| 118 | - else xfree((void**)&outmatrix_size);
|
---|
| 119 | + else xDelete<int>(outmatrix_size);
|
---|
| 120 |
|
---|
| 121 | }
|
---|
| 122 | /*}}}*/
|
---|
| 123 | @@ -123,7 +123,7 @@
|
---|
| 124 | MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);
|
---|
| 125 |
|
---|
| 126 | /*Convert double matrix into integer matrix: */
|
---|
| 127 | - outmatrix=(int*)xmalloc(outmatrix_rows*outmatrix_cols*sizeof(int));
|
---|
| 128 | + outmatrix=xNew<int>(outmatrix_rows*outmatrix_cols);
|
---|
| 129 | for(i=0;i<outmatrix_rows*outmatrix_cols;i++)outmatrix[i]=(int)doublematrix[i];
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | @@ -165,7 +165,7 @@
|
---|
| 133 | MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);
|
---|
| 134 |
|
---|
| 135 | /*Convert double matrix into integer matrix: */
|
---|
| 136 | - outmatrix=(bool*)xmalloc(outmatrix_rows*outmatrix_cols*sizeof(bool));
|
---|
| 137 | + outmatrix=xNew<bool>(outmatrix_rows*outmatrix_cols);
|
---|
| 138 | for(i=0;i<outmatrix_rows;i++)outmatrix[i]=(bool)doublematrix[i];
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | @@ -226,9 +226,9 @@
|
---|
| 142 | MatlabNArrayToNArray(&doublematrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
|
---|
| 143 |
|
---|
| 144 | /*Convert double matrix into bool matrix: */
|
---|
| 145 | - outmatrix=(bool*)xmalloc(outmatrix_numel*sizeof(bool));
|
---|
| 146 | + outmatrix=xNew<bool>(outmatrix_numel);
|
---|
| 147 | for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i];
|
---|
| 148 | - xfree((void**)&doublematrix);
|
---|
| 149 | + xDelete<double>(doublematrix);
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | else{
|
---|
| 153 | @@ -241,7 +241,7 @@
|
---|
| 154 | if (pnumel)*pnumel=outmatrix_numel;
|
---|
| 155 | if (pndims)*pndims=outmatrix_ndims;
|
---|
| 156 | if (psize )*psize =outmatrix_size;
|
---|
| 157 | - else xfree((void**)&outmatrix_size);
|
---|
| 158 | + else xDelete<int>(outmatrix_size);
|
---|
| 159 |
|
---|
| 160 | }
|
---|
| 161 | /*}}}*/
|
---|
| 162 | @@ -291,7 +291,7 @@
|
---|
| 163 | MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref);
|
---|
| 164 |
|
---|
| 165 | /*Convert double vector into integer vector: */
|
---|
| 166 | - outvector=(int*)xmalloc(outvector_rows*sizeof(int));
|
---|
| 167 | + outvector=xNew<int>(outvector_rows);
|
---|
| 168 | for(i=0;i<outvector_rows;i++)outvector[i]=(int)doublevector[i];
|
---|
| 169 | }
|
---|
| 170 | else{
|
---|
| 171 | @@ -323,7 +323,7 @@
|
---|
| 172 | MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref);
|
---|
| 173 |
|
---|
| 174 | /*Convert double vector into integer vector: */
|
---|
| 175 | - outvector=(bool*)xmalloc(outvector_rows*sizeof(bool));
|
---|
| 176 | + outvector=xNew<bool>(outvector_rows);
|
---|
| 177 | for(i=0;i<outvector_rows;i++)outvector[i]=(bool)doublevector[i];
|
---|
| 178 | }
|
---|
| 179 | else{
|
---|
| 180 | @@ -355,7 +355,7 @@
|
---|
| 181 | MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref);
|
---|
| 182 |
|
---|
| 183 | /*Convert double vector into float vector: */
|
---|
| 184 | - outvector=(float*)xmalloc(outvector_rows*sizeof(float));
|
---|
| 185 | + outvector=xNew<float>(outvector_rows);
|
---|
| 186 | for(i=0;i<outvector_rows;i++)outvector[i]=(float)doublevector[i];
|
---|
| 187 | }
|
---|
| 188 | else{
|
---|
| 189 | @@ -383,7 +383,7 @@
|
---|
| 190 | int stringlen;
|
---|
| 191 |
|
---|
| 192 | stringlen = mxGetM(dataref)*mxGetN(dataref)+1;
|
---|
| 193 | - outstring = (char*)xmalloc(sizeof(mxChar)*stringlen);
|
---|
| 194 | + outstring =xNew<char>(stringlen);
|
---|
| 195 | mxGetString(dataref,outstring,stringlen);
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | @@ -419,7 +419,7 @@
|
---|
| 199 | if (pnumel)*pnumel=outmatrix_numel;
|
---|
| 200 | if (pndims)*pndims=outmatrix_ndims;
|
---|
| 201 | if (psize )*psize =outmatrix_size;
|
---|
| 202 | - else xfree((void**)&outmatrix_size);
|
---|
| 203 | + else xDelete<int>(outmatrix_size);
|
---|
| 204 |
|
---|
| 205 | }
|
---|
| 206 | /*}}}*/
|
---|
| 207 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabVectorToDoubleVector.cpp
|
---|
| 208 | ===================================================================
|
---|
| 209 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabVectorToDoubleVector.cpp (revision 12433)
|
---|
| 210 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabVectorToDoubleVector.cpp (revision 12434)
|
---|
| 211 | @@ -50,7 +50,7 @@
|
---|
| 212 | nz=(int)((double)nnz/(double)rows);
|
---|
| 213 |
|
---|
| 214 | if(rows){
|
---|
| 215 | - vector=(double*)xcalloc(rows,sizeof(double));
|
---|
| 216 | + vector=xNewInit<double>(rows,0.0);
|
---|
| 217 |
|
---|
| 218 | /*Now, get ir,jc and pr: */
|
---|
| 219 | pr=mxGetPr(mxvector);
|
---|
| 220 | @@ -80,7 +80,7 @@
|
---|
| 221 |
|
---|
| 222 | /*allocate and memcpy*/
|
---|
| 223 | if(rows){
|
---|
| 224 | - vector=(double*)xmalloc(rows*sizeof(double));
|
---|
| 225 | + vector=xNew<double>(rows);
|
---|
| 226 | memcpy(vector,mxvector_ptr,rows*sizeof(double));
|
---|
| 227 | }
|
---|
| 228 | else{
|
---|
| 229 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp
|
---|
| 230 | ===================================================================
|
---|
| 231 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp (revision 12433)
|
---|
| 232 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp (revision 12434)
|
---|
| 233 | @@ -248,7 +248,7 @@
|
---|
| 234 | mxSetPr(dataref,tmatrix_ptr);
|
---|
| 235 |
|
---|
| 236 | /*Free ressources:*/
|
---|
| 237 | - xfree((void**)&matrix_ptr);
|
---|
| 238 | + xDelete<double>(matrix_ptr);
|
---|
| 239 |
|
---|
| 240 | }
|
---|
| 241 | else{
|
---|
| 242 | @@ -289,7 +289,7 @@
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | /*Clean-up and return*/
|
---|
| 246 | - xfree((void**)&vector_ptr);
|
---|
| 247 | + xDelete<double>(vector_ptr);
|
---|
| 248 | *pdataref=dataref;
|
---|
| 249 | }
|
---|
| 250 | /*}}}*/
|
---|
| 251 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp
|
---|
| 252 | ===================================================================
|
---|
| 253 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp (revision 12433)
|
---|
| 254 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp (revision 12434)
|
---|
| 255 | @@ -38,7 +38,7 @@
|
---|
| 256 | cols=mxGetN(mxmatrix);
|
---|
| 257 |
|
---|
| 258 | if(rows*cols){
|
---|
| 259 | - matrix=(double*)xcalloc(rows*cols,sizeof(double));
|
---|
| 260 | + matrix=xNewInit<double>(rows*cols,0.0);
|
---|
| 261 |
|
---|
| 262 | /*Now, get ir,jc and pr: */
|
---|
| 263 | ir=mxGetIr(mxmatrix);
|
---|
| 264 | @@ -63,7 +63,7 @@
|
---|
| 265 |
|
---|
| 266 | /*Create serial matrix: */
|
---|
| 267 | if(rows*cols){
|
---|
| 268 | - matrix=(double*)xcalloc(rows*cols,sizeof(double));
|
---|
| 269 | + matrix=xNewInit<double>(rows*cols,0.0);
|
---|
| 270 |
|
---|
| 271 | for(i=0;i<rows;i++){
|
---|
| 272 | for(j=0;j<cols;j++){
|
---|
| 273 | @@ -80,7 +80,7 @@
|
---|
| 274 |
|
---|
| 275 | /*Create serial matrix: */
|
---|
| 276 | if(rows*cols){
|
---|
| 277 | - matrix=(double*)xcalloc(rows*cols,sizeof(double));
|
---|
| 278 | + matrix=xNewInit<double>(rows*cols,0.0);
|
---|
| 279 |
|
---|
| 280 | for(i=0;i<rows;i++){
|
---|
| 281 | for(j=0;j<cols;j++){
|
---|
| 282 | @@ -97,7 +97,7 @@
|
---|
| 283 |
|
---|
| 284 | /*Create serial matrix: */
|
---|
| 285 | if(rows*cols){
|
---|
| 286 | - matrix=(double*)xcalloc(rows*cols,sizeof(double));
|
---|
| 287 | + matrix=xNewInit<double>(rows*cols,0.0);
|
---|
| 288 |
|
---|
| 289 | for(i=0;i<rows;i++){
|
---|
| 290 | for(j=0;j<cols;j++){
|
---|
| 291 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabVectorToPetscVector.cpp
|
---|
| 292 | ===================================================================
|
---|
| 293 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabVectorToPetscVector.cpp (revision 12433)
|
---|
| 294 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabVectorToPetscVector.cpp (revision 12434)
|
---|
| 295 | @@ -78,7 +78,7 @@
|
---|
| 296 | ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr);
|
---|
| 297 |
|
---|
| 298 | /*Insert mxvector_ptr values into petsc vector: */
|
---|
| 299 | - idxm=(int*)xmalloc(rows*sizeof(int));
|
---|
| 300 | + idxm=xNew<int>(rows);
|
---|
| 301 |
|
---|
| 302 | for(i=0;i<rows;i++)idxm[i]=i;
|
---|
| 303 |
|
---|
| 304 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/PrintfFunction.cpp
|
---|
| 305 | ===================================================================
|
---|
| 306 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/PrintfFunction.cpp (revision 12433)
|
---|
| 307 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/PrintfFunction.cpp (revision 12434)
|
---|
| 308 | @@ -26,7 +26,7 @@
|
---|
| 309 | while(true){
|
---|
| 310 |
|
---|
| 311 | /*allocate buffer for given string size*/
|
---|
| 312 | - buffer=(char*)xmalloc(size*sizeof(char));
|
---|
| 313 | + buffer=xNew<char>(size);
|
---|
| 314 |
|
---|
| 315 | /* Try to print in the allocated space. */
|
---|
| 316 | va_start(args, format);
|
---|
| 317 | @@ -46,13 +46,13 @@
|
---|
| 318 | else /* glibc 2.0 */
|
---|
| 319 | size*=2; /* twice the old size */
|
---|
| 320 |
|
---|
| 321 | - xfree((void**)&buffer);
|
---|
| 322 | + xDelete<char>(buffer);
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | /*Ok, if we are running in parallel, get node 0 to print*/
|
---|
| 326 | if(my_rank==0)printf(buffer);
|
---|
| 327 |
|
---|
| 328 | /*Clean up and return*/
|
---|
| 329 | - xfree((void**)&buffer);
|
---|
| 330 | + xDelete<char>(buffer);
|
---|
| 331 | return 1;
|
---|
| 332 | }
|
---|
| 333 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp
|
---|
| 334 | ===================================================================
|
---|
| 335 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp (revision 12433)
|
---|
| 336 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp (revision 12434)
|
---|
| 337 | @@ -8,8 +8,8 @@
|
---|
| 338 | #else
|
---|
| 339 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 340 | #endif
|
---|
| 341 | +#include "../../shared/shared.h"
|
---|
| 342 |
|
---|
| 343 | -
|
---|
| 344 | /*Petsc includes: */
|
---|
| 345 | #include "petscmat.h"
|
---|
| 346 | #include "petscvec.h"
|
---|
| 347 | @@ -18,30 +18,28 @@
|
---|
| 348 | /*Matlab includes: */
|
---|
| 349 | #include "mex.h"
|
---|
| 350 |
|
---|
| 351 | -#include "../../shared/shared.h"
|
---|
| 352 | -
|
---|
| 353 | int MatlabMatrixToPetscMatrix(Mat* pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){
|
---|
| 354 |
|
---|
| 355 | int rows, cols;
|
---|
| 356 | - double* mxmatrix_ptr=NULL;
|
---|
| 357 | - double* tmatrix=NULL;
|
---|
| 358 | + double *mxmatrix_ptr = NULL;
|
---|
| 359 | + double *tmatrix = NULL;
|
---|
| 360 | int ierr;
|
---|
| 361 | int i,j;
|
---|
| 362 |
|
---|
| 363 | /*output: */
|
---|
| 364 | - Mat matrix=NULL;
|
---|
| 365 | + Mat matrix = NULL;
|
---|
| 366 |
|
---|
| 367 | /*matlab indices: */
|
---|
| 368 | - mwIndex* ir=NULL;
|
---|
| 369 | - mwIndex* jc=NULL;
|
---|
| 370 | - double* pr=NULL;
|
---|
| 371 | + mwIndex *ir = NULL;
|
---|
| 372 | + mwIndex *jc = NULL;
|
---|
| 373 | + double *pr = NULL;
|
---|
| 374 | int count;
|
---|
| 375 | int nnz;
|
---|
| 376 | int nz;
|
---|
| 377 |
|
---|
| 378 | /*petsc indices: */
|
---|
| 379 | - int* idxm=NULL;
|
---|
| 380 | - int* idxn=NULL;
|
---|
| 381 | + int *idxm = NULL;
|
---|
| 382 | + int *idxn = NULL;
|
---|
| 383 |
|
---|
| 384 | /*Ok, first check if we are dealing with a sparse or full matrix: */
|
---|
| 385 | if (mxIsSparse(mxmatrix)){
|
---|
| 386 | @@ -73,17 +71,15 @@
|
---|
| 387 | count++;
|
---|
| 388 | }
|
---|
| 389 | }
|
---|
| 390 | -
|
---|
| 391 | }
|
---|
| 392 | else{
|
---|
| 393 | -
|
---|
| 394 | /*Dealing with dense matrix: recover pointer and size: */
|
---|
| 395 | mxmatrix_ptr=(double*)mxGetPr(mxmatrix);
|
---|
| 396 | rows=mxGetM(mxmatrix);
|
---|
| 397 | cols=mxGetN(mxmatrix);
|
---|
| 398 |
|
---|
| 399 | /*transpose, as Petsc now does not allows MAT_COLUMN_ORIENTED matrices in MatSetValues: */
|
---|
| 400 | - tmatrix=(double*)xmalloc(rows*cols*sizeof(double));
|
---|
| 401 | + tmatrix=xNew<double>(rows*cols);
|
---|
| 402 | for(i=0;i<cols;i++){
|
---|
| 403 | for(j=0;j<rows;j++){
|
---|
| 404 | *(tmatrix+rows*i+j)=*(mxmatrix_ptr+cols*j+i);
|
---|
| 405 | @@ -94,23 +90,21 @@
|
---|
| 406 | ierr=MatCreateSeqDense(PETSC_COMM_SELF,rows,cols,NULL,&matrix);CHKERRQ(ierr);
|
---|
| 407 |
|
---|
| 408 | /*Insert mxmatrix_ptr values into petsc matrix: */
|
---|
| 409 | - idxm=(int*)xmalloc(rows*sizeof(int));
|
---|
| 410 | - idxn=(int*)xmalloc(cols*sizeof(int));
|
---|
| 411 | + idxm=xNew<int>(rows);
|
---|
| 412 | + idxn=xNew<int>(cols);
|
---|
| 413 |
|
---|
| 414 | for(i=0;i<rows;i++)idxm[i]=i;
|
---|
| 415 | for(i=0;i<cols;i++)idxn[i]=i;
|
---|
| 416 |
|
---|
| 417 | ierr=MatSetValues(matrix,rows,idxm,cols,idxn,tmatrix,INSERT_VALUES); CHKERRQ(ierr);
|
---|
| 418 |
|
---|
| 419 | - xfree((void**)&tmatrix);
|
---|
| 420 | -
|
---|
| 421 | + xDelete<double>(tmatrix);
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | /*Assemble matrix: */
|
---|
| 425 | MatAssemblyBegin(matrix,MAT_FINAL_ASSEMBLY);
|
---|
| 426 | MatAssemblyEnd(matrix,MAT_FINAL_ASSEMBLY);
|
---|
| 427 |
|
---|
| 428 | -
|
---|
| 429 | /*Assign output pointer: */
|
---|
| 430 | *pmatrix=matrix;
|
---|
| 431 | if(pmatrix_rows) *pmatrix_rows=rows;
|
---|
| 432 | Index: /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp
|
---|
| 433 | ===================================================================
|
---|
| 434 | --- /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp (revision 12433)
|
---|
| 435 | +++ /u/astrid-r1b/morlighe/issmuci/trunk-jpl/../trunk-jpl/src/c/matlab/io/MatlabNArrayToNArray.cpp (revision 12434)
|
---|
| 436 | @@ -38,8 +38,8 @@
|
---|
| 437 | numel=mxGetNumberOfElements(mxmatrix);
|
---|
| 438 | ndims=mxGetNumberOfDimensions(mxmatrix);
|
---|
| 439 | ipt =mxGetDimensions(mxmatrix);
|
---|
| 440 | - size =(int *) xcalloc(ndims,sizeof(int));
|
---|
| 441 | - for (i=0; i<ndims; i++) size[i]=(int)ipt[i];
|
---|
| 442 | + size =xNew<int>(ndims);
|
---|
| 443 | + for (i=0;i<ndims;i++) size[i]=(int)ipt[i];
|
---|
| 444 |
|
---|
| 445 | /*Ok, first check if we are dealing with a sparse or full matrix: */
|
---|
| 446 | if (mxIsSparse(mxmatrix)){
|
---|
| 447 | @@ -50,7 +50,7 @@
|
---|
| 448 | nnz=mxGetNzmax(mxmatrix);
|
---|
| 449 | nz=(int)((double)nnz/(double)rows);
|
---|
| 450 |
|
---|
| 451 | - matrix=(double*)xcalloc(rows*cols,sizeof(double));
|
---|
| 452 | + matrix=xNewInit<double>(rows*cols,0.0);
|
---|
| 453 |
|
---|
| 454 | /*Now, get ir,jc and pr: */
|
---|
| 455 | ir=mxGetIr(mxmatrix);
|
---|
| 456 | @@ -73,15 +73,15 @@
|
---|
| 457 | mxmatrix_ptr=(double*)mxGetPr(mxmatrix);
|
---|
| 458 |
|
---|
| 459 | /*Create serial matrix: */
|
---|
| 460 | - matrix=(double*)xcalloc(numel,sizeof(double));
|
---|
| 461 | + matrix=xNewInit<double>(numel,0.0);
|
---|
| 462 |
|
---|
| 463 | - dims=(int *) xcalloc(ndims,sizeof(int));
|
---|
| 464 | + dims=xNew<int>(ndims);
|
---|
| 465 | for(i=0;i<numel;i++){
|
---|
| 466 | ColumnWiseDimsFromIndex(dims,i,size,ndims);
|
---|
| 467 | j=IndexFromRowWiseDims(dims,size,ndims);
|
---|
| 468 | *(matrix+j)=*(mxmatrix_ptr+i);
|
---|
| 469 | }
|
---|
| 470 | - xfree((void**)&dims);
|
---|
| 471 | + xDelete<int>(dims);
|
---|
| 472 |
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | @@ -118,8 +118,8 @@
|
---|
| 476 | numel=mxGetNumberOfElements(mxmatrix);
|
---|
| 477 | ndims=mxGetNumberOfDimensions(mxmatrix);
|
---|
| 478 | ipt =mxGetDimensions(mxmatrix);
|
---|
| 479 | - size =(int *) xcalloc(ndims,sizeof(int));
|
---|
| 480 | - for (i=0; i<ndims; i++) size[i]=(int)ipt[i];
|
---|
| 481 | + size =xNew<int>(ndims);
|
---|
| 482 | + for (i=0;i<ndims;i++) size[i]=(int)ipt[i];
|
---|
| 483 |
|
---|
| 484 | /*Ok, first check if we are dealing with a sparse or full matrix: */
|
---|
| 485 | if (mxIsSparse(mxmatrix)){
|
---|
| 486 | @@ -130,7 +130,7 @@
|
---|
| 487 | nnz=mxGetNzmax(mxmatrix);
|
---|
| 488 | nz=(int)((double)nnz/(double)rows);
|
---|
| 489 |
|
---|
| 490 | - matrix=(bool*)xcalloc(rows*cols,sizeof(bool));
|
---|
| 491 | + matrix=xNewInit<bool>(rows*cols,false);
|
---|
| 492 |
|
---|
| 493 | /*Now, get ir,jc and pm: */
|
---|
| 494 | ir=mxGetIr(mxmatrix);
|
---|
| 495 | @@ -153,16 +153,14 @@
|
---|
| 496 | mxmatrix_ptr=(bool*)mxGetData(mxmatrix);
|
---|
| 497 |
|
---|
| 498 | /*Create serial matrix: */
|
---|
| 499 | - matrix=(bool*)xcalloc(numel,sizeof(bool));
|
---|
| 500 | -
|
---|
| 501 | - dims=(int *) xcalloc(ndims,sizeof(int));
|
---|
| 502 | + matrix=xNew<bool>(numel);
|
---|
| 503 | + dims=xNew<int>(ndims);
|
---|
| 504 | for(i=0;i<numel;i++){
|
---|
| 505 | ColumnWiseDimsFromIndex(dims,i,size,ndims);
|
---|
| 506 | j=IndexFromRowWiseDims(dims,size,ndims);
|
---|
| 507 | *(matrix+j)=(bool)*(mxmatrix_ptr+i);
|
---|
| 508 | }
|
---|
| 509 | - xfree((void**)&dims);
|
---|
| 510 | -
|
---|
| 511 | + xDelete<int>(dims);
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 | /*Assign output pointer: */
|
---|
| 515 | @@ -198,8 +196,8 @@
|
---|
| 516 | numel=mxGetNumberOfElements(mxmatrix);
|
---|
| 517 | ndims=mxGetNumberOfDimensions(mxmatrix);
|
---|
| 518 | ipt =mxGetDimensions(mxmatrix);
|
---|
| 519 | - size =(int *) xcalloc(ndims,sizeof(int));
|
---|
| 520 | - for (i=0; i<ndims; i++) size[i]=(int)ipt[i];
|
---|
| 521 | + size =xNew<int>(ndims);
|
---|
| 522 | + for (i=0;i<ndims;i++) size[i]=(int)ipt[i];
|
---|
| 523 |
|
---|
| 524 | /*Ok, first check if we are dealing with a sparse or full matrix: */
|
---|
| 525 | if (mxIsSparse(mxmatrix)){
|
---|
| 526 | @@ -210,7 +208,7 @@
|
---|
| 527 | nnz=mxGetNzmax(mxmatrix);
|
---|
| 528 | nz=(int)((double)nnz/(double)rows);
|
---|
| 529 |
|
---|
| 530 | - matrix=(char*)xcalloc(rows*cols,sizeof(double));
|
---|
| 531 | + matrix=xNew<char>(rows*cols);
|
---|
| 532 |
|
---|
| 533 | /*Now, get ir,jc and pm: */
|
---|
| 534 | ir=mxGetIr(mxmatrix);
|
---|
| 535 | @@ -233,7 +231,7 @@
|
---|
| 536 | mxmatrix_ptr=mxGetChars(mxmatrix);
|
---|
| 537 |
|
---|
| 538 | /*Create serial matrix: */
|
---|
| 539 | - matrix=(char*)xcalloc(numel+1,sizeof(mxChar));
|
---|
| 540 | + matrix=xNew<char>(numel+1);
|
---|
| 541 |
|
---|
| 542 | /*looping code adapted from Matlab example explore.c: */
|
---|
| 543 | int elements_per_page = size[0] * size[1];
|
---|