Changeset 24112
- Timestamp:
- 07/30/19 07:16:33 (6 years ago)
- Location:
- issm/trunk-jpl/src/wrappers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp
r23651 r24112 10 10 11 11 #include "./javascriptio.h" 12 #include <cstring> 12 #include <cstring> 13 13 14 14 /*Primitive data types*/ … … 24 24 /*FUNCTION FetchData(int* pinteger,int integer){{{*/ 25 25 void FetchData(int* pinteger,int integer){ 26 26 27 27 *pinteger = integer; 28 28 } … … 30 30 /*FUNCTION FetchData(double* pscalar,double scalar){{{*/ 31 31 void FetchData(double* pscalar,double scalar){ 32 32 33 33 *pscalar = scalar; 34 34 } … … 38 38 39 39 double* vector=NULL; 40 40 41 41 vector=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(vector,vectorin,nods); 42 42 43 43 *pvector=vector; 44 44 } … … 48 48 49 49 double* vector=NULL; 50 50 51 51 vector=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(vector,vectorin,nods); 52 52 53 53 *pvector=vector; 54 54 *pnods=nods; … … 60 60 double* outmatrix=NULL; 61 61 int outmatrix_rows,outmatrix_cols; 62 62 63 63 if(M == 0 || N == 0){ 64 64 /*Nothing to pick up. Just initialize matrix pointer to NULL: */ … … 67 67 outmatrix=NULL; 68 68 } 69 else if (pmatrix && matrixin){ 69 else if (pmatrix && matrixin){ 70 70 outmatrix_rows=M; 71 71 outmatrix_cols=N; 72 outmatrix=xNew<IssmPDouble>(M*N); 72 outmatrix=xNew<IssmPDouble>(M*N); 73 73 for(int i=0;i<M*N;i++)outmatrix[i]=(IssmPDouble)matrixin[i]; 74 74 } … … 92 92 outmatrix=NULL; 93 93 } 94 else if (pmatrix && matrixin){ 94 else if (pmatrix && matrixin){ 95 95 outmatrix_rows=M; 96 96 outmatrix_cols=N; 97 outmatrix=xNew<IssmPDouble>(M*N); xMemCpy<IssmPDouble>(outmatrix,matrixin,M*N); 97 outmatrix=xNew<IssmPDouble>(M*N); xMemCpy<IssmPDouble>(outmatrix,matrixin,M*N); 98 98 } 99 99 … … 116 116 outmatrix=NULL; 117 117 } 118 else if (pmatrix && matrixin){ 118 else if (pmatrix && matrixin){ 119 119 outmatrix_rows=M; 120 120 outmatrix_cols=N; 121 outmatrix=xNew<int>(M*N); xMemCpy<int>(outmatrix,matrixin,M*N); 121 outmatrix=xNew<int>(M*N); xMemCpy<int>(outmatrix,matrixin,M*N); 122 122 } 123 123 … … 141 141 142 142 if (nods){ 143 143 144 144 contouri=new Contour<double>(); 145 145 contouri->nods=nods; … … 149 149 contours->AddObject(contouri); 150 150 } 151 151 152 152 *pcontours=contours; 153 153 } … … 193 193 /*}}}*/ 194 194 /*FUNCTION FetchData(BamgOpts** pbamgopts, double anisomax, double cutoff, double coeff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, int* hminVerticesSize, double* hminVertices, int* hmaxVerticesSize, double* hmaxVertices, int* hVerticesSize, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err){{{*/ 195 void FetchData(BamgOpts** pbamgopts, double anisomax, double coeff, double cutoff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, int* hminVerticesSize, double* hminVertices, int* hmaxVerticesSize, double* hmaxVertices, int* hVertices Size, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err){195 void FetchData(BamgOpts** pbamgopts, double anisomax, double coeff, double cutoff, double errg, double gradation, int Hessiantype, int maxnbv, double maxsubdiv, int Metrictype, int nbjacobi, int nbsmooth, double omega, double power, int verbose, int Crack, int KeepVertices, int splitcorners, double hmin, double hmax, int* hminVerticesSize, double* hminVertices, int* hmaxVerticesSize, double* hmaxVertices, int* hVerticesLength, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err){ 196 196 197 197 BamgOpts *bamgopts = new BamgOpts(); … … 217 217 bamgopts->KeepVertices = KeepVertices; 218 218 bamgopts->splitcorners = splitcorners; 219 219 220 220 /*Metric related*/ 221 221 bamgopts->hmin = hmin; … … 223 223 FetchData(&bamgopts->hminVertices, &bamgopts->hminVerticesSize[0], &bamgopts->hminVerticesSize[1], hminVertices, hminVerticesSize[0], hminVerticesSize[1]); 224 224 FetchData(&bamgopts->hmaxVertices, &bamgopts->hmaxVerticesSize[0], &bamgopts->hmaxVerticesSize[1], hmaxVertices, hmaxVerticesSize[0], hmaxVerticesSize[1]); 225 FetchData(&bamgopts->hVertices, &bamgopts->hVertices Size[0], &bamgopts->hVerticesSize[1], hVertices, hVerticesSize[0], hVerticesSize[1]);225 FetchData(&bamgopts->hVertices, &bamgopts->hVerticesLength, hVertices, hVerticesLength); 226 226 FetchData(&bamgopts->field, &bamgopts->fieldSize[0], &bamgopts->fieldSize[1], field, fieldSize[0], fieldSize[1]); 227 227 FetchData(&bamgopts->metric, &bamgopts->metricSize[0], &bamgopts->metricSize[1], metric, metricSize[0], metricSize[1]); 228 228 FetchData(&bamgopts->err, &bamgopts->errSize[0], &bamgopts->errSize[1], err, errSize[0], errSize[1]); 229 229 230 230 /*Additional checks*/ 231 231 bamgopts->Check(); … … 240 240 /*Initialize output*/ 241 241 Options* options=new Options(); 242 242 243 243 /*check and parse the name */ 244 244 GenericOption<double> *odouble = new GenericOption<double>(); -
issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp
r24107 r24112 10 10 11 11 #include "./matlabio.h" 12 #include <cstring> 12 #include <cstring> 13 13 14 14 /*Primitive data types*/ … … 24 24 outmatrix=NULL; 25 25 } 26 else if( mxIsClass(dataref,"double") || 27 mxIsClass(dataref,"single") || 28 mxIsClass(dataref,"int16") || 29 mxIsClass(dataref,"int8") || 26 else if( mxIsClass(dataref,"double") || 27 mxIsClass(dataref,"single") || 28 mxIsClass(dataref,"int16") || 29 mxIsClass(dataref,"int8") || 30 30 mxIsClass(dataref,"uint8")){ 31 31 /*Check dataref is not pointing to NaN: */ … … 67 67 outmatrix=NULL; 68 68 } 69 else if( mxIsClass(dataref,"double") || 70 mxIsClass(dataref,"single") || 71 mxIsClass(dataref,"int16") || 72 mxIsClass(dataref,"int8") || 69 else if( mxIsClass(dataref,"double") || 70 mxIsClass(dataref,"single") || 71 mxIsClass(dataref,"int16") || 72 mxIsClass(dataref,"int8") || 73 73 mxIsClass(dataref,"uint8")){ 74 74 … … 393 393 FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],mxGetField(dataref,0,"hminVertices")); 394 394 FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],mxGetField(dataref,0,"hmaxVertices")); 395 FetchData(&bamgopts->hVertices,&bamgopts->hVertices Size[0],&bamgopts->hVerticesSize[1],mxGetField(dataref,0,"hVertices"));395 FetchData(&bamgopts->hVertices,&bamgopts->hVerticesLength,mxGetField(dataref,0,"hVertices")); 396 396 FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],mxGetField(dataref,0,"metric")); 397 397 FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],mxGetField(dataref,0,"field")); -
issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp
r24107 r24112 19 19 void FetchData(double* pscalar,PyObject* py_float){ 20 20 21 21 double dscalar; 22 22 23 23 /*return internal value: */ 24 25 26 27 24 #if _PYTHON_MAJOR_ == 3 25 if (PyFloat_Check(py_float)) 26 dscalar=PyFloat_AsDouble(py_float); 27 else if (PyLong_Check(py_float)) 28 28 dscalar=(double)PyLong_AsLong(py_float); 29 29 else if (PyBool_Check(py_float)) … … 34 34 FetchData(&dscalar,PyList_GetItem(py_float,(Py_ssize_t)0)); 35 35 else 36 _error_("unrecognized float type in input!");36 _error_("unrecognized float type py3 in input!"); 37 37 38 38 #else … … 50 50 FetchData(&dscalar,PyList_GetItem(py_float,(Py_ssize_t)0)); 51 51 else 52 _error_("unrecognized float type in input!");52 _error_("unrecognized float type in py2 input!"); 53 53 #endif 54 54 /*output: */ … … 64 64 #if _PYTHON_MAJOR_ == 3 65 65 if (PyFloat_Check(py_float)) 66 66 fscalar=PyFloat_AsDouble(py_float); 67 67 else if (PyLong_Check(py_float)) 68 68 fscalar=(float)PyLong_AsLong(py_float); … … 142 142 /*return internal value: */ 143 143 #if _PYTHON_MAJOR_ == 3 144 if 144 if (PyBool_Check(py_boolean)) 145 145 bscalar=(bool)PyLong_AsLong(py_boolean); 146 146 else if (PyLong_Check(py_boolean)) … … 192 192 PyObject* py_matrix2=NULL; 193 193 194 if 194 if (PyArray_Check((PyArrayObject*)py_matrix)) { 195 195 /*retrieve dimensions: */ 196 196 ndim=PyArray_NDIM((const PyArrayObject*)py_matrix); 197 if 197 if (ndim==2) { 198 198 dims=PyArray_DIMS((PyArrayObject*)py_matrix); 199 199 M=dims[0]; N=dims[1]; … … 212 212 } 213 213 214 if 214 if (PyArray_TYPE((PyArrayObject*)py_matrix) == NPY_DOUBLE) { 215 215 /*retrieve internal value: */ 216 216 dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix); … … 218 218 /*copy matrix: */ 219 219 matrix=xNew<double>(M*N); 220 // if (PyArray_ISCONTIGUOUS((PyArrayObject*)py_matrix)) { 221 memcpy(matrix,dmatrix,(M*N)*sizeof(double)); 222 // } 223 224 // else { 225 // int j,k,ipt=0; 226 // int mstride,nstride; 227 // mstride=(int)PyArray_STRIDE((PyArrayObject*)py_matrix,0)/PyArray_ITEMSIZE((PyArrayObject*)py_matrix); 228 // if (ndim > 1) 229 // nstride=(int)PyArray_STRIDE((PyArrayObject*)py_matrix,1)/PyArray_ITEMSIZE((PyArrayObject*)py_matrix); 230 // else 231 // nstride=1; 232 // for (i=0; i<M; i++) { 233 // k=i*mstride; 234 // for (j=0; j<N; j++) { 235 // matrix[ipt++]=dmatrix[k]; 236 // k+=nstride; 237 // } 238 // } 239 // } 240 220 memcpy(matrix,dmatrix,(M*N)*sizeof(double)); 241 221 } 242 222 … … 264 244 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 265 245 } 246 else 247 matrix=NULL; 248 } 249 else if (PyList_Check(py_matrix)) { 250 /*retrieve dimensions: */ 251 M=(int)PyList_Size(py_matrix); 252 N=1 253 254 if (M) { 255 matrix=xNew<double>(M); 256 for (int index = 0; index < M; index++) { 257 PyObject *item; 258 item = PyList_GetItem(py_matrix, index); 259 if ((int)PyList_Size(item)>1) 260 _error_("2D lists are not suported"); 261 FetchData(&(matrix[index]),item); 262 } 263 } 264 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 265 else 266 matrix=NULL; 267 } 268 else if (PyTuple_Check(py_matrix)) { 269 /*retrieve dimensions: */ 270 M=(int)PyTuple_Size(py_matrix); 271 N=1 272 if (M) { 273 matrix=xNew<double>(M); 274 for (int index = 0; index < M; index++) { 275 PyObject *item; 276 item = PyTuple_GetItem(py_matrix, index); 277 if ((int)PyTuple_Size(item)>1) 278 _error_("2D tuple are not suported"); 279 FetchData(&(matrix[index]),item); 280 } 281 } 282 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 266 283 else 267 284 matrix=NULL; … … 356 373 matrix=NULL; 357 374 } 375 else if (PyList_Check(py_matrix)) { 376 /*retrieve dimensions: */ 377 M=(int)PyList_Size(py_matrix); 378 N=1 379 if (M) { 380 matrix=xNew<int>(M); 381 for (int index = 0; index < M; index++) { 382 PyObject *item; 383 item = PyList_GetItem(py_matrix, index); 384 if ((int)PyList_Size(item)>1) 385 _error_("2D lists are not suported"); 386 FetchData(&(matrix[index]),item); 387 } 388 } 389 else 390 matrix=NULL; 391 } 392 else if (PyTuple_Check(py_matrix)) { 393 /*retrieve dimensions: */ 394 M=(int)PyTuple_Size(py_matrix); 395 N=1 396 if (M) { 397 matrix=xNew<int>(M); 398 for (int index = 0; index < M; index++) { 399 PyObject *item; 400 item = PyTuple_GetItem(py_matrix, index); 401 if ((int)PyTuple_Size(item)>1) 402 _error_("2D tuple are not suported"); 403 FetchData(&(matrix[index]),item); 404 } 405 } 406 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 407 else 408 matrix=NULL; 409 } 358 410 359 411 else { … … 443 495 matrix=NULL; 444 496 } 497 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 498 499 else if (PyList_Check(py_matrix)) { 500 /*retrieve dimensions: */ 501 M=(int)PyList_Size(py_matrix); 502 N=1; 503 if (M) { 504 matrix=xNew<bool>(M); 505 for (int index = 0; index < M; index++) { 506 PyObject *item; 507 item = PyList_GetItem(py_matrix, index); 508 if ((int)PyList_Size(item)>1) 509 _error_("2D lists are not suported"); 510 FetchData(&(matrix[index]),item); 511 } 512 } 513 else 514 matrix=NULL; 515 } 516 else if (PyTuple_Check(py_matrix)) { 517 /*retrieve dimensions: */ 518 M=(int)PyTuple_Size(py_matrix); 519 N=1 520 if (M) { 521 matrix=xNew<bool>(M); 522 for (int index = 0; index < M; index++) { 523 PyObject *item; 524 item = PyTuple_GetItem(py_matrix, index); 525 if ((int)PyTuple_Size(item)>1) 526 _error_("2D tuples are not suported"); 527 FetchData(&(matrix[index]),item); 528 } 529 } 530 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 531 else 532 matrix=NULL; 533 } 445 534 446 535 else { … … 534 623 vector=NULL; 535 624 } 625 else if (PyList_Check(py_vector)) { 626 /*retrieve dimensions: */ 627 M=(int)PyList_Size(py_vector); 628 629 if (M) { 630 vector=xNew<double>(M); 631 for (int index = 0; index < M; index++) { 632 PyObject *item; 633 item = PyList_GetItem(py_vector, index); 634 FetchData(&(vector[index]),item); 635 } 636 } 637 else 638 vector=NULL; 639 } 640 else if (PyTuple_Check(py_vector)) { 641 /*retrieve dimensions: */ 642 M=(int)PyTuple_Size(py_vector); 643 644 if (M) { 645 vector=xNew<double>(M); 646 for (int index = 0; index < M; index++) { 647 PyObject *item; 648 item = PyTuple_GetItem(py_vector, index); 649 FetchData(&(vector[index]),item); 650 } 651 } 652 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 653 else 654 vector=NULL; 655 } 536 656 537 657 else { … … 620 740 vector=NULL; 621 741 } 742 else if (PyList_Check(py_vector)) { 743 /*retrieve dimensions: */ 744 M=(int)PyList_Size(py_vector); 745 746 if (M) { 747 vector=xNew<float>(M); 748 for (int index = 0; index < M; index++) { 749 PyObject *item; 750 item = PyList_GetItem(py_vector, index); 751 FetchData(&(vector[index]),item); 752 } 753 } 754 else 755 vector=NULL; 756 } 757 758 else if (PyTuple_Check(py_vector)) { 759 /*retrieve dimensions: */ 760 M=(int)PyTuple_Size(py_vector); 761 762 if (M) { 763 vector=xNew<float>(M); 764 for (int index = 0; index < M; index++) { 765 PyObject *item; 766 item = PyTuple_GetItem(py_vector, index); 767 FetchData(&(vector[index]),item); 768 } 769 } 770 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 771 else 772 vector=NULL; 773 } 774 622 775 else{ 623 776 M=1; … … 707 860 } 708 861 862 else if (PyList_Check(py_vector)) { 863 /*retrieve dimensions: */ 864 M=(int)PyList_Size(py_vector); 865 866 if (M) { 867 vector=xNew<int>(M); 868 for (int index = 0; index < M; index++) { 869 PyObject *item; 870 item = PyList_GetItem(py_vector, index); 871 FetchData(&(vector[index]),item); 872 } 873 } 874 else 875 vector=NULL; 876 } 877 878 else if (PyTuple_Check(py_vector)) { 879 /*retrieve dimensions: */ 880 M=(int)PyTuple_Size(py_vector); 881 882 if (M) { 883 vector=xNew<int>(M); 884 for (int index = 0; index < M; index++) { 885 PyObject *item; 886 item = PyTuple_GetItem(py_vector, index); 887 FetchData(&(vector[index]),item); 888 } 889 } 890 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 891 else 892 vector=NULL; 893 } 894 709 895 else { 710 896 M=1; … … 790 976 delete(py_vector2); 791 977 } 978 else 979 vector=NULL; 980 } 981 else if (PyList_Check(py_vector)) { 982 /*retrieve dimensions: */ 983 M=(int)PyList_Size(py_vector); 984 if (M) { 985 vector=xNew<bool>(M); 986 for (int index = 0; index < M; index++) { 987 PyObject *item; 988 item = PyList_GetItem(py_vector, index); 989 FetchData(&(vector[index]),item); 990 } 991 } 992 else 993 vector=NULL; 994 } 995 996 else if (PyTuple_Check(py_vector)) { 997 /*retrieve dimensions: */ 998 M=(int)PyTuple_Size(py_vector); 999 1000 if (M) { 1001 vector=xNew<bool>(M); 1002 for (int index = 0; index < M; index++) { 1003 PyObject *item; 1004 item = PyTuple_GetItem(py_vector, index); 1005 FetchData(&(vector[index]),item); 1006 } 1007 } 1008 //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to be creating a segfault! 792 1009 else 793 1010 vector=NULL; … … 876 1093 FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],PyDict_GetItemString(py_dict,"hminVertices")); 877 1094 FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],PyDict_GetItemString(py_dict,"hmaxVertices")); 878 FetchData(&bamgopts->hVertices,&bamgopts->hVertices Size[0],&bamgopts->hVerticesSize[1],PyDict_GetItemString(py_dict,"hVertices"));1095 FetchData(&bamgopts->hVertices,&bamgopts->hVerticesLength,PyDict_GetItemString(py_dict,"hVertices")); 879 1096 FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],PyDict_GetItemString(py_dict,"metric")); 880 1097 FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],PyDict_GetItemString(py_dict,"field"));
Note:
See TracChangeset
for help on using the changeset viewer.