Changeset 24112


Ignore:
Timestamp:
07/30/19 07:16:33 (6 years ago)
Author:
bdef
Message:

CHG: change the treatment of hVertices to vector

Location:
issm/trunk-jpl/src/wrappers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/wrappers/javascript/io/FetchJavascriptData.cpp

    r23651 r24112  
    1010
    1111#include "./javascriptio.h"
    12 #include <cstring> 
     12#include <cstring>
    1313
    1414/*Primitive data types*/
     
    2424/*FUNCTION FetchData(int* pinteger,int integer){{{*/
    2525void FetchData(int* pinteger,int integer){
    26        
     26
    2727        *pinteger = integer;
    2828}
     
    3030/*FUNCTION FetchData(double* pscalar,double scalar){{{*/
    3131void FetchData(double* pscalar,double scalar){
    32        
     32
    3333        *pscalar = scalar;
    3434}
     
    3838
    3939        double* vector=NULL;
    40        
     40
    4141        vector=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(vector,vectorin,nods);
    42        
     42
    4343        *pvector=vector;
    4444}
     
    4848
    4949        double* vector=NULL;
    50        
     50
    5151        vector=xNew<IssmPDouble>(nods); xMemCpy<IssmPDouble>(vector,vectorin,nods);
    52        
     52
    5353        *pvector=vector;
    5454        *pnods=nods;
     
    6060        double*  outmatrix=NULL;
    6161        int      outmatrix_rows,outmatrix_cols;
    62        
     62
    6363        if(M == 0 || N == 0){
    6464                /*Nothing to pick up. Just initialize matrix pointer to NULL: */
     
    6767                outmatrix=NULL;
    6868        }
    69     else if (pmatrix && matrixin){ 
     69    else if (pmatrix && matrixin){
    7070                outmatrix_rows=M;
    7171                outmatrix_cols=N;
    72                 outmatrix=xNew<IssmPDouble>(M*N); 
     72                outmatrix=xNew<IssmPDouble>(M*N);
    7373                for(int i=0;i<M*N;i++)outmatrix[i]=(IssmPDouble)matrixin[i];
    7474        }
     
    9292                outmatrix=NULL;
    9393        }
    94     else if (pmatrix && matrixin){ 
     94    else if (pmatrix && matrixin){
    9595                outmatrix_rows=M;
    9696                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);
    9898        }
    9999
     
    116116                outmatrix=NULL;
    117117        }
    118     else if (pmatrix && matrixin){ 
     118    else if (pmatrix && matrixin){
    119119                outmatrix_rows=M;
    120120                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);
    122122        }
    123123
     
    141141
    142142        if (nods){
    143                        
     143
    144144                contouri=new Contour<double>();
    145145                contouri->nods=nods;
     
    149149                contours->AddObject(contouri);
    150150        }
    151        
     151
    152152        *pcontours=contours;
    153153}
     
    193193/*}}}*/
    194194/*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* hVerticesSize, double* hVertices, int* metricSize, double* metric, int* fieldSize, double* field, int* errSize, double* err){
     195void 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){
    196196
    197197        BamgOpts *bamgopts      = new BamgOpts();
     
    217217    bamgopts->KeepVertices      = KeepVertices;
    218218    bamgopts->splitcorners      = splitcorners;
    219        
     219
    220220    /*Metric related*/
    221221    bamgopts->hmin              = hmin;
     
    223223        FetchData(&bamgopts->hminVertices, &bamgopts->hminVerticesSize[0], &bamgopts->hminVerticesSize[1], hminVertices, hminVerticesSize[0], hminVerticesSize[1]);
    224224        FetchData(&bamgopts->hmaxVertices, &bamgopts->hmaxVerticesSize[0], &bamgopts->hmaxVerticesSize[1], hmaxVertices, hmaxVerticesSize[0], hmaxVerticesSize[1]);
    225         FetchData(&bamgopts->hVertices, &bamgopts->hVerticesSize[0], &bamgopts->hVerticesSize[1], hVertices, hVerticesSize[0], hVerticesSize[1]);
     225        FetchData(&bamgopts->hVertices, &bamgopts->hVerticesLength, hVertices, hVerticesLength);
    226226        FetchData(&bamgopts->field, &bamgopts->fieldSize[0], &bamgopts->fieldSize[1], field, fieldSize[0], fieldSize[1]);
    227227        FetchData(&bamgopts->metric, &bamgopts->metricSize[0], &bamgopts->metricSize[1], metric, metricSize[0], metricSize[1]);
    228228        FetchData(&bamgopts->err, &bamgopts->errSize[0], &bamgopts->errSize[1], err, errSize[0], errSize[1]);
    229    
     229
    230230        /*Additional checks*/
    231231        bamgopts->Check();
     
    240240        /*Initialize output*/
    241241        Options* options=new Options();
    242        
     242
    243243        /*check and parse the name  */
    244244        GenericOption<double> *odouble = new GenericOption<double>();
  • issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp

    r24107 r24112  
    1010
    1111#include "./matlabio.h"
    12 #include <cstring> 
     12#include <cstring>
    1313
    1414/*Primitive data types*/
     
    2424                outmatrix=NULL;
    2525        }
    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") ||
    3030                                mxIsClass(dataref,"uint8")){
    3131                /*Check dataref is not pointing to NaN: */
     
    6767                outmatrix=NULL;
    6868        }
    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") ||
    7373                                mxIsClass(dataref,"uint8")){
    7474
     
    393393        FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],mxGetField(dataref,0,"hminVertices"));
    394394        FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],mxGetField(dataref,0,"hmaxVertices"));
    395         FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],mxGetField(dataref,0,"hVertices"));
     395        FetchData(&bamgopts->hVertices,&bamgopts->hVerticesLength,mxGetField(dataref,0,"hVertices"));
    396396        FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],mxGetField(dataref,0,"metric"));
    397397        FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],mxGetField(dataref,0,"field"));
  • issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp

    r24107 r24112  
    1919void FetchData(double* pscalar,PyObject* py_float){
    2020
    21         double dscalar;
     21   double dscalar;
    2222
    2323        /*return internal value: */
    24         #if _PYTHON_MAJOR_ == 3
    25         if (PyFloat_Check(py_float))
    26                 dscalar=PyFloat_AsDouble(py_float);
    27         else if (PyLong_Check(py_float))
     24   #if _PYTHON_MAJOR_ == 3
     25   if (PyFloat_Check(py_float))
     26      dscalar=PyFloat_AsDouble(py_float);
     27   else if (PyLong_Check(py_float))
    2828                dscalar=(double)PyLong_AsLong(py_float);
    2929        else if (PyBool_Check(py_float))
     
    3434                FetchData(&dscalar,PyList_GetItem(py_float,(Py_ssize_t)0));
    3535        else
    36                 _error_("unrecognized float type in input!");
     36                _error_("unrecognized float type py3 in input!");
    3737
    3838        #else
     
    5050                FetchData(&dscalar,PyList_GetItem(py_float,(Py_ssize_t)0));
    5151        else
    52                 _error_("unrecognized float type in input!");
     52                _error_("unrecognized float type in py2 input!");
    5353        #endif
    5454        /*output: */
     
    6464        #if _PYTHON_MAJOR_ == 3
    6565        if  (PyFloat_Check(py_float))
    66         fscalar=PyFloat_AsDouble(py_float);
     66      fscalar=PyFloat_AsDouble(py_float);
    6767        else if (PyLong_Check(py_float))
    6868                fscalar=(float)PyLong_AsLong(py_float);
     
    142142        /*return internal value: */
    143143        #if _PYTHON_MAJOR_ == 3
    144         if      (PyBool_Check(py_boolean))
     144        if (PyBool_Check(py_boolean))
    145145                bscalar=(bool)PyLong_AsLong(py_boolean);
    146146        else if (PyLong_Check(py_boolean))
     
    192192        PyObject* py_matrix2=NULL;
    193193
    194         if     (PyArray_Check((PyArrayObject*)py_matrix)) {
     194        if (PyArray_Check((PyArrayObject*)py_matrix)) {
    195195                /*retrieve dimensions: */
    196196                ndim=PyArray_NDIM((const PyArrayObject*)py_matrix);
    197                 if      (ndim==2) {
     197                if (ndim==2) {
    198198                        dims=PyArray_DIMS((PyArrayObject*)py_matrix);
    199199                        M=dims[0]; N=dims[1];
     
    212212                        }
    213213
    214                         if      (PyArray_TYPE((PyArrayObject*)py_matrix) == NPY_DOUBLE) {
     214                        if (PyArray_TYPE((PyArrayObject*)py_matrix) == NPY_DOUBLE) {
    215215                                /*retrieve internal value: */
    216216                                dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix);
     
    218218                                /*copy matrix: */
    219219                                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));
    241221                        }
    242222
     
    264244                        //if (py_matrix2) delete(py_matrix2); Not doing this for now, seems to  be creating a segfault!
    265245                }
     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!
    266283                else
    267284                        matrix=NULL;
     
    356373                        matrix=NULL;
    357374        }
     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        }
    358410
    359411        else {
     
    443495                        matrix=NULL;
    444496        }
     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        }
    445534
    446535        else {
     
    534623                        vector=NULL;
    535624        }
     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        }
    536656
    537657        else {
     
    620740                        vector=NULL;
    621741        }
     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
    622775        else{
    623776                M=1;
     
    707860        }
    708861
     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
    709895        else {
    710896                M=1;
     
    790976                                delete(py_vector2);
    791977                }
     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!
    7921009                else
    7931010                        vector=NULL;
     
    8761093        FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],PyDict_GetItemString(py_dict,"hminVertices"));
    8771094        FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],PyDict_GetItemString(py_dict,"hmaxVertices"));
    878         FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],PyDict_GetItemString(py_dict,"hVertices"));
     1095        FetchData(&bamgopts->hVertices,&bamgopts->hVerticesLength,PyDict_GetItemString(py_dict,"hVertices"));
    8791096        FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],PyDict_GetItemString(py_dict,"metric"));
    8801097        FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],PyDict_GetItemString(py_dict,"field"));
Note: See TracChangeset for help on using the changeset viewer.