Changeset 14221
- Timestamp:
- 01/09/13 10:47:56 (12 years ago)
- Location:
- issm/trunk-jpl/src/wrappers
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.cpp
r13355 r14221 22 22 23 23 /* output: */ 24 SeqMat< double>*index = NULL;24 SeqMat<int> *index = NULL; 25 25 SeqVec<double> *x = NULL; 26 26 SeqVec<double> *y = NULL; 27 SeqMat< double>*segments = NULL;28 SeqVec< double>*segmentmarkerlist = NULL;27 SeqMat<int> *segments = NULL; 28 SeqVec<int> *segmentmarkerlist = NULL; 29 29 30 30 /*Boot module: */ -
issm/trunk-jpl/src/wrappers/TriMeshProcessRifts/TriMeshProcessRifts.cpp
r13639 r14221 18 18 /* input: */ 19 19 int nel,nods; 20 double*index = NULL;20 int *index = NULL; 21 21 double *x = NULL; 22 22 double *y = NULL; 23 double*segments = NULL;24 double*segmentmarkers = NULL;23 int *segments = NULL; 24 int *segmentmarkers = NULL; 25 25 int num_seg; 26 26 -
issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp
r13749 r14221 290 290 } 291 291 /*}}}*/ 292 /*FUNCTION WriteData(mxArray** pdataref,SeqMat<int>* matrix){{{*/ 293 void WriteData(mxArray** pdataref,SeqMat<int>* matrix){ 294 295 int i,j; 296 int rows,cols; 297 mxArray *dataref = NULL; 298 int *matrix_ptr = NULL; 299 double *tmatrix_ptr = NULL; 300 301 if(matrix){ 302 303 matrix_ptr=matrix->ToSerial(); 304 matrix->GetSize(&rows,&cols); 305 306 /*Now transpose the matrix and allocate with Matlab's memory manager: */ 307 tmatrix_ptr=(double*)mxMalloc(rows*cols*sizeof(double)); 308 for(i=0;i<rows;i++){ 309 for(j=0;j<cols;j++){ 310 tmatrix_ptr[j*rows+i]=(double)matrix_ptr[i*cols+j]; 311 } 312 } 313 314 /*create matlab matrix: */ 315 dataref=mxCreateDoubleMatrix(0,0,mxREAL); 316 mxSetM(dataref,rows); 317 mxSetN(dataref,cols); 318 mxSetPr(dataref,tmatrix_ptr); 319 320 /*Free ressources:*/ 321 xDelete<int>(matrix_ptr); 322 } 323 else{ 324 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 325 } 326 327 *pdataref=dataref; 328 } 329 /*}}}*/ 330 /*FUNCTION WriteData(mxArray** pdataref,SeqVec<int>* vector){{{*/ 331 void WriteData(mxArray** pdataref,SeqVec<int>* vector){ 332 333 mxArray* dataref=NULL; 334 int* vector_ptr=NULL; 335 double* vector_matlab=NULL; 336 int rows; 337 338 if(vector){ 339 /*call toolkit routine: */ 340 vector_ptr=vector->ToMPISerial(); 341 vector->GetSize(&rows); 342 343 /*now create the matlab vector with Matlab's memory manager */ 344 vector_matlab=(double*)mxMalloc(rows*sizeof(double)); 345 for(int i=0;i<rows;i++) vector_matlab[i]=(double)vector_ptr[i]; 346 347 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 348 mxSetM(dataref,rows); 349 mxSetN(dataref,1); 350 mxSetPr(dataref,vector_matlab); 351 } 352 else{ 353 dataref = mxCreateDoubleMatrix(0,0,mxREAL); 354 } 355 356 /*Clean-up and return*/ 357 xDelete<int>(vector_ptr); 358 *pdataref=dataref; 359 } 360 /*}}}*/ 292 361 /*FUNCTION WriteData(mxArray** pdataref,RiftStruct* riftstruct){{{*/ 293 362 void WriteData(mxArray** pdataref,RiftStruct* riftstruct){ … … 363 432 } 364 433 /*}}}*/ 434 /*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,int* fieldpointer){{{*/ 435 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,int* fieldpointer){ 436 437 mxArray* field = NULL; 438 439 /*Convert field*/ 440 WriteData(&field,fieldpointer,M,N); 441 442 /*Assign to structure*/ 443 mxSetField(dataref,i,fieldname,field); 444 } 445 /*}}}*/ 365 446 /*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field){{{*/ 366 447 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldin){ -
issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h
r13749 r14221 17 17 #include "../../c/include/include.h" 18 18 19 void WriteData(mxArray** pdataref,SeqMat<int>* matrix); 19 20 void WriteData(mxArray** pdataref,SeqMat<double>* matrix); 20 21 void WriteData(mxArray** pdataref,double* matrix, int M,int N); 21 22 void WriteData(mxArray** pdataref,int* matrix, int M,int N); 23 void WriteData(mxArray** pdataref,SeqVec<int>* vector); 22 24 void WriteData(mxArray** pdataref,SeqVec<double>* vector); 23 25 void WriteData(mxArray** pdataref,double* vector, int M); … … 64 66 void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer); 65 67 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer); 68 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldrows,int fieldcols,int* fieldpointer); 66 69 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field); 67 70 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field); -
issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp
r14098 r14221 298 298 else 299 299 vector=NULL; 300 301 /*output: */ 302 if(pM)*pM=M; 303 if(pvector)*pvector=vector; 304 } 305 /*}}}*/ 306 /*FUNCTION FetchData(int** pvector,int* pM, PyObject* py_vector){{{*/ 307 void FetchData(int** pvector,int* pM,PyObject* py_vector){ 308 309 /*output: */ 310 int* vector=NULL; 311 int M; 312 int ndim; 313 npy_intp* dims=NULL; 314 315 /*intermediary:*/ 316 long* lvector=NULL; 317 bool* bvector=NULL; 318 double* dvector=NULL; 319 int i; 320 321 /*retrieve dimensions: */ 322 ndim=PyArray_NDIM((const PyArrayObject*)py_vector); 323 if(ndim!=1)_error_("expecting an Mx1 vector in input!"); 324 dims=PyArray_DIMS((PyArrayObject*)py_vector); 325 M=dims[0]; 326 327 if (M) { 328 if (PyArray_TYPE((PyArrayObject*)py_vector) == NPY_DOUBLE) { 329 /*retrieve internal value: */ 330 dvector=(double*)PyArray_DATA((PyArrayObject*)py_vector); 331 332 /*transform into int vector: */ 333 vector=xNew<int>(M); 334 for(i=0;i<M;i++)vector[i]=(int)lvector[i]; 335 } 336 337 else if (PyArray_TYPE((PyArrayObject*)py_vector) == NPY_INT64) { 338 /*retrieve internal value: */ 339 lvector=(long*)PyArray_DATA((PyArrayObject*)py_vector); 340 341 /*transform into int vector: */ 342 vector=xNew<int>(M); 343 for(i=0;i<M;i++)vector[i]=(int)lvector[i]; 344 } 345 346 else if (PyArray_TYPE((PyArrayObject*)py_vector) == NPY_BOOL) { 347 /*retrieve internal value: */ 348 bvector=(bool*)PyArray_DATA((PyArrayObject*)py_vector); 349 350 /*transform into int vector: */ 351 vector=xNew<int>(M); 352 for(i=0;i<M;i++)vector[i]=(int)bvector[i]; 353 } 354 355 else 356 _error_("unrecognized vector type in input!"); 357 } 358 else 359 vector=NULL; 300 360 301 361 /*output: */ -
issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp
r14010 r14221 162 162 } 163 163 /*}}}*/ 164 /*FUNCTION WriteData(PyObject* py_tuple,int index,SeqMat<int>* matrix){{{*/ 165 void WriteData(PyObject* py_tuple,int index,SeqMat<int>* matrix){ 166 167 //FIXME: convert to double for now 168 169 int M,N; 170 int* buffer=NULL; 171 npy_intp dims[2]={0,0}; 172 PyObject* array=NULL; 173 174 matrix->GetSize(&M,&N); 175 buffer=matrix->ToSerial(); 176 177 /*convert to double*/ 178 double* bufferdouble=xNew<IssmDouble>(M*N); 179 for(int i=0;i<M*N;i++) bufferdouble[i]=(double)buffer[i]; 180 xDelete<int>(buffer); 181 182 dims[0]=(npy_intp)M; 183 dims[1]=(npy_intp)N; 184 array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,bufferdouble); 185 186 PyTuple_SetItem(py_tuple, index, array); 187 188 }/*}}}*/ 189 /*FUNCTION WriteData(PyObject* py_tuple,int index,SeqVec<int>* vector){{{*/ 190 void WriteData(PyObject* py_tuple,int index,SeqVec<int>* vector){ 191 192 //FIXME: convert to double for now 193 194 int M; 195 int* buffer=NULL; 196 npy_intp dim=10; 197 PyObject* array=NULL; 198 199 vector->GetSize(&M); 200 buffer=vector->ToMPISerial(); 201 202 /*convert to double*/ 203 IssmDouble* bufferdouble=xNew<IssmDouble>(M); 204 for(int i=0;i<M;i++) bufferdouble[i]=(double)buffer[i]; 205 xDelete<int>(buffer); 206 207 dim=(npy_intp)M; 208 array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,bufferdouble); 209 210 PyTuple_SetItem(py_tuple, index, array); 211 } 212 /*}}}*/ 164 213 /*FUNCTION WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){{{*/ 165 214 void WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){ … … 225 274 } 226 275 /*}}}*/ 276 /*FUNCTION PyArrayFromCopiedData(int dimi,int dimj,int* data){{{*/ 277 PyObject* PyArrayFromCopiedData(int dimi,int dimj,int* data){ 278 279 //FIXME: convert to double for now 280 281 double* pydata; 282 npy_intp pydims[2]={0,0}; 283 284 /* note that PyArray_SimpleNewFromData does not copy the data, so that when the original 285 object (e.g. bamggeom,bamgmesh) is deleted, the data is gone. */ 286 287 pydims[0]=(npy_intp)dimi; 288 pydims[1]=(npy_intp)dimj; 289 pydata=xNew<IssmDouble>(dimi*dimj); 290 //memcpy(pydata,data,dimi*dimj*sizeof(int)); 291 for(int i=0;i<dimi*dimj;i++) pydata[i]=(double)data[i]; 292 return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata); 293 } 294 /*}}}*/ -
issm/trunk-jpl/src/wrappers/python/io/pythonio.h
r14093 r14221 25 25 void WriteData(PyObject* py_tuple,int index, SeqMat<double>* matrix); 26 26 void WriteData(PyObject* py_tuple,int index, SeqVec<double>* vector); 27 void WriteData(PyObject* py_tuple,int index, SeqMat<int>* matrix); 28 void WriteData(PyObject* py_tuple,int index, SeqVec<int>* vector); 27 29 void WriteData(PyObject* py_tuple,int index, BamgGeom* bamggeom); 28 30 void WriteData(PyObject* py_tuple,int index, BamgMesh* bamgmesh); 29 31 void WriteData(PyObject* py_tuple,int index, RiftStruct* riftstruct); 30 32 33 void FetchData(int** pvector,int* pM,PyObject* py_ref); 31 34 void FetchData(double** pvector,int* pM,PyObject* py_ref); 32 35 void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_array); … … 47 50 PyObject* PyArrayFromCopiedData(int dims[2],double* data); 48 51 PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data); 52 PyObject* PyArrayFromCopiedData(int dimi,int dimj,int* data); 49 53 50 54 #endif /* _IO_H_ */
Note:
See TracChangeset
for help on using the changeset viewer.