Salome HOME
cbd924d82eb38cdee3f473e5d1d29f77ab97bc18
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingDataArrayTypemaps.i
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "InterpKernelAutoPtr.hxx"
22
23 /*!
24  * This method is an extention of PySlice_GetIndices but less
25  * open than PySlice_GetIndicesEx that accepts too many situations.
26  */
27 void GetIndicesOfSlice(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
28 {
29   int ret(PySlice_GetIndices(slice,length,start,stop,step));
30   if(ret==0)
31     return ;
32   if(*step>0 && *start==*stop && length==*start)
33     return ;
34   throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
35 }
36
37 /*!
38  * This method allows to retrieve slice info from \a slice.
39  */
40 void GetIndicesOfSliceExplicitely(PySliceObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
41 {
42   int ret(PySlice_GetIndices(slice,std::numeric_limits<int>::max(),start,stop,step));
43   if(ret==0)
44     {
45       if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
46         return ;
47       std::ostringstream oss;
48       oss << msgInCaseOfFailure << " The input slice contains some unknowns that can't be determined in static method ! The input slice must be explicit here !";
49       throw INTERP_KERNEL::Exception(oss.str().c_str());
50     }
51   throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
52 }
53
54 int InterpreteNegativeInt(int val, int nbelem)
55 {
56   if(val<0)
57     {
58       int newVal(nbelem+val);
59       if(newVal<0)
60         {
61           std::ostringstream oss; oss << "interpreteNegativeInt : request for negative int=" << val << " but number of elems is equal to " << nbelem << " !";
62           throw INTERP_KERNEL::Exception(oss.str().c_str());
63         }
64       return newVal;
65     }
66   else
67     return val;
68 }
69
70 #ifdef WITH_NUMPY
71 #include <numpy/arrayobject.h>
72 #if NPY_API_VERSION <= 0x00000006
73 #  define MED_NUMPY_OWNDATA NPY_OWNDATA
74 #else
75 #  define MED_NUMPY_OWNDATA NPY_ARRAY_OWNDATA
76 #endif
77
78 // specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
79 // method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
80 // if no more alive the "standart" DataArray deallocator is called.
81 void numarrdeal(void *pt, void *wron)
82 {
83   void **wronc=(void **)wron;
84   PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
85   PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
86   if(obj!=Py_None)
87     {
88       Py_XINCREF(obj);
89       PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
90       objC->flags|=MED_NUMPY_OWNDATA;
91       Py_XDECREF(weakRefOnOwner);
92       Py_XDECREF(obj);
93     }
94   else
95     {
96       typedef void (*MyDeallocator)(void *,void *);
97       MyDeallocator deall=(MyDeallocator)wronc[1];
98       deall(pt,NULL);
99       Py_XDECREF(weakRefOnOwner);
100     }
101   delete [] wronc;
102 }
103
104 template<class MCData>
105 struct PyCallBackDataArraySt {
106     PyObject_HEAD
107     MCData *_pt_mc;
108 };
109
110 typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt> PyCallBackDataArrayInt;
111 typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayDouble> PyCallBackDataArrayDouble;
112
113 extern "C"
114 {
115   static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
116   
117   static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
118   {
119     PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
120     return (PyObject *)self;
121   }
122
123   static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
124   {
125     PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
126     return (PyObject *)self;
127   }
128   
129   static void callbackmcdataarray_dealloc(PyObject *self)
130   {
131     Py_TYPE(self)->tp_free(self);
132   }
133   
134   // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
135   // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
136   static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
137   {
138     if(self->_pt_mc)
139       {
140         MEDCoupling::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
141         mma.destroy();
142       }
143     Py_XINCREF(Py_None);
144     return Py_None;
145   }
146   
147   // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
148   // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
149   static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
150   {
151     if(self->_pt_mc)
152       {
153         MEDCoupling::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
154         mma.destroy();
155       }
156     Py_XINCREF(Py_None);
157     return Py_None;
158   }
159 }
160
161 PyTypeObject PyCallBackDataArrayInt_RefType = {
162   PyVarObject_HEAD_INIT(&PyType_Type, 0)
163   "callbackmcdataarrayint",
164   sizeof(PyCallBackDataArrayInt),
165   0,
166   callbackmcdataarray_dealloc,            /*tp_dealloc*/
167   0,                          /*tp_print*/
168   0,                          /*tp_getattr*/
169   0,                          /*tp_setattr*/
170   0,                          /*tp_compare*/
171   0,                          /*tp_repr*/
172   0,                          /*tp_as_number*/
173   0,                          /*tp_as_sequence*/
174   0,                          /*tp_as_mapping*/
175   0,                          /*tp_hash*/
176   (ternaryfunc)callbackmcdataarrayint_call,  /*tp_call*/
177   0,                          /*tp_str*/
178   0,                          /*tp_getattro*/
179   0,                          /*tp_setattro*/
180   0,                          /*tp_as_buffer*/
181   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
182   0,                          /*tp_doc*/
183   0,                          /*tp_traverse*/
184   0,                          /*tp_clear*/
185   0,                          /*tp_richcompare*/
186   0,                          /*tp_weaklistoffset*/
187   0,                          /*tp_iter*/
188   0,                          /*tp_iternext*/
189   0,                          /*tp_methods*/
190   0,                          /*tp_members*/
191   0,                          /*tp_getset*/
192   0,                          /*tp_base*/
193   0,                          /*tp_dict*/
194   0,                          /*tp_descr_get*/
195   0,                          /*tp_descr_set*/
196   0,                          /*tp_dictoffset*/
197   callbackmcdataarray___init__,           /*tp_init*/
198   PyType_GenericAlloc,        /*tp_alloc*/
199   callbackmcdataarrayint___new__,            /*tp_new*/
200   PyObject_GC_Del,            /*tp_free*/
201 };
202
203 PyTypeObject PyCallBackDataArrayDouble_RefType = {
204   PyVarObject_HEAD_INIT(&PyType_Type, 0)
205   "callbackmcdataarraydouble",
206   sizeof(PyCallBackDataArrayDouble),
207   0,
208   callbackmcdataarray_dealloc,            /*tp_dealloc*/
209   0,                          /*tp_print*/
210   0,                          /*tp_getattr*/
211   0,                          /*tp_setattr*/
212   0,                          /*tp_compare*/
213   0,                          /*tp_repr*/
214   0,                          /*tp_as_number*/
215   0,                          /*tp_as_sequence*/
216   0,                          /*tp_as_mapping*/
217   0,                          /*tp_hash*/
218   (ternaryfunc)callbackmcdataarraydouble_call,  /*tp_call*/
219   0,                          /*tp_str*/
220   0,                          /*tp_getattro*/
221   0,                          /*tp_setattro*/
222   0,                          /*tp_as_buffer*/
223   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
224   0,                          /*tp_doc*/
225   0,                          /*tp_traverse*/
226   0,                          /*tp_clear*/
227   0,                          /*tp_richcompare*/
228   0,                          /*tp_weaklistoffset*/
229   0,                          /*tp_iter*/
230   0,                          /*tp_iternext*/
231   0,                          /*tp_methods*/
232   0,                          /*tp_members*/
233   0,                          /*tp_getset*/
234   0,                          /*tp_base*/
235   0,                          /*tp_dict*/
236   0,                          /*tp_descr_get*/
237   0,                          /*tp_descr_set*/
238   0,                          /*tp_dictoffset*/
239   callbackmcdataarray___init__,           /*tp_init*/
240   PyType_GenericAlloc,        /*tp_alloc*/
241   callbackmcdataarraydouble___new__,            /*tp_new*/
242   PyObject_GC_Del,            /*tp_free*/
243 };
244
245 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
246 // in input when an another DataArray is already client of this.
247 template<class MCData>
248 void numarrdeal2(void *pt, void *obj)
249 {
250   typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
251   void **obj1=(void **)obj;
252   PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
253   PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
254   cbdaic->_pt_mc=0;
255   Py_XDECREF(weakRefOnOwner);
256   Py_XDECREF(cbdaic);
257   delete [] obj1;
258 }
259
260 template<class MCData, class T>
261 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
262 {
263   int ndim=PyArray_NDIM(elt0);
264   if(ndim!=1 && ndim!=2)
265     throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
266   if(PyArray_DESCR(elt0)->type_num != npyObjectType)
267     {
268       std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
269       throw INTERP_KERNEL::Exception(oss.str().c_str());
270     }
271   npy_intp sz0=PyArray_DIM(elt0,0);
272   npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
273   //
274   int itemSize=PyArray_ITEMSIZE(elt0);
275   if(itemSize!=sizeof(T))
276     {
277       std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
278       throw INTERP_KERNEL::Exception(oss.str().c_str());
279     }
280   if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
281     throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
282   if(ndim==2)
283     if(itemSize!=PyArray_STRIDE(elt0,1))
284       throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays for component #1 !");
285   const char *data=PyArray_BYTES(elt0);
286   typename MEDCoupling::MEDCouplingAutoRefCountObjectPtr<MCData> ret=MCData::New();
287   if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
288     {
289       PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
290       PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & MED_NUMPY_OWNDATA)?elt0C:NULL;
291       int mask=MED_NUMPY_OWNDATA; mask=~mask;
292       elt0C->flags&=mask;
293       PyObject *deepestObj=elt0;
294       PyObject *base=elt0C->base;
295       if(base) deepestObj=base;
296       bool isSpetialCase(false);
297       while(base)
298         {
299           if(PyArray_Check(base))
300             {
301               PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
302               eltOwning=(PyArray_FLAGS(baseC) & MED_NUMPY_OWNDATA)?baseC:eltOwning;
303               baseC->flags&=mask;
304               base=baseC->base;
305               if(base) deepestObj=base;
306             }
307           else
308             {
309               isSpetialCase=true;
310               break;
311             }
312         }
313       if(isSpetialCase)
314         {// this case is present for numpy arrayint coming from load of pickelized string. The owner of elt0 is not an array -> A copy is requested.
315           std::size_t nbOfElems(sz0*sz1);
316           T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems);
317           std::copy(reinterpret_cast<const T*>(data),reinterpret_cast<const T*>(data)+nbOfElems,dataCpy);
318           ret->useArray(dataCpy,true,MEDCoupling::C_DEALLOC,sz0,sz1);
319           return ret.retn();
320         }
321       typename MEDCoupling::MemArray<T>& mma=ret->accessToMemArray();
322       if(eltOwning==NULL)
323         {
324           PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
325           cb->_pt_mc=ret;
326           ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
327           PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
328           void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
329           mma.setParameterForDeallocator(objs);
330           mma.setSpecificDeallocator(numarrdeal2<MCData>);
331           //"Impossible to share this numpy array chunk of data, because already shared by an another non numpy array object (maybe an another DataArrayInt instance) ! Release it, or perform a copy on the input array !");
332         }
333       else
334         {
335           ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
336           PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
337           typename MEDCoupling::MemArray<T>::Deallocator tmp(MEDCoupling::MemArray<T>::CDeallocator);
338           void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
339           void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
340           mma.setParameterForDeallocator(objs);
341           mma.setSpecificDeallocator(numarrdeal);
342         }
343     }
344   else if(PyArray_ISBEHAVED_RO(elt0))
345     ret->useArray(reinterpret_cast<const T *>(data),false,MEDCoupling::CPP_DEALLOC,sz0,sz1);
346   return ret.retn();
347 }
348
349
350 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
351 {
352     if (obj == NULL) {
353         PyErr_SetString(PyExc_ValueError,
354                 "Cannot set the NumPy array 'base' "
355                 "dependency to NULL after initialization");
356         return -1;
357     }
358     /*
359      * Allow the base to be set only once. Once the object which
360      * owns the data is set, it doesn't make sense to change it.
361      */
362     if (PyArray_BASE(arr) != NULL) {
363         Py_DECREF(obj);
364         PyErr_SetString(PyExc_ValueError,
365                 "Cannot set the NumPy array 'base' "
366                 "dependency more than once");
367         return -1;
368     }
369
370     /*
371      * Don't allow infinite chains of views, always set the base
372      * to the first owner of the data.  
373      * That is, either the first object which isn't an array, 
374      * or the first object which owns its own data.
375      */
376
377     while (PyArray_Check(obj) && (PyObject *)arr != obj) {
378         PyArrayObject *obj_arr = (PyArrayObject *)obj;
379         PyObject *tmp;
380  
381
382         /* If this array owns its own data, stop collapsing */
383         if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) { 
384             break;
385         }   
386
387         tmp = PyArray_BASE(obj_arr);
388         /* If there's no base, stop collapsing */
389         if (tmp == NULL) {
390             break;
391         }
392         /* Stop the collapse new base when the would not be of the same 
393          * type (i.e. different subclass).
394          */
395         if (Py_TYPE(tmp) != Py_TYPE(arr)) {
396             break;
397         }
398
399
400         Py_INCREF(tmp);
401         Py_DECREF(obj);
402         obj = tmp;
403     }
404
405     /* Disallow circular references */
406     if ((PyObject *)arr == obj) {
407         Py_DECREF(obj);
408         PyErr_SetString(PyExc_ValueError,
409                 "Cannot create a circular NumPy array 'base' dependency");
410         return -1;
411     }
412
413     arr->base = obj;
414
415     return 0;
416 }
417
418 template<class MCData, class T>
419 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
420 {
421   if(!self->isAllocated())
422     {
423       std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
424       throw INTERP_KERNEL::Exception(oss.str().c_str());
425     }
426   MEDCoupling::MemArray<T>& mem=self->accessToMemArray();
427   if(nbComp==0)
428     {
429       std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !"; 
430       throw INTERP_KERNEL::Exception(oss.str().c_str());
431     }
432   int nbDims=nbComp==1?1:2;
433   npy_intp dim[2];
434   dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
435   const T *bg=self->getConstPointer();
436   PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
437   if(mem.isDeallocatorCalled())
438     {
439       if(mem.getDeallocator()!=numarrdeal)
440         {// case for the first call of toNumPyArray
441           PyObject *ref(PyWeakref_NewRef(ret,NULL));
442           typename MEDCoupling::MemArray<T>::Deallocator tmp(mem.getDeallocator());
443           void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
444           void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
445           mem.setParameterForDeallocator(objs);
446           mem.setSpecificDeallocator(numarrdeal);
447           return ret;
448         }
449       else
450         {// case for the second and other call of toNumPyArray
451           void **objs=(void **)mem.getParameterForDeallocator();
452           PyObject *weakRefOnOwner=(PyObject *)objs[0];
453           PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
454           if(obj!=Py_None)
455             {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
456               Py_XINCREF(obj);
457               NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
458             }
459           else
460             {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
461               Py_XDECREF(weakRefOnOwner);
462               PyObject *ref=PyWeakref_NewRef(ret,NULL);
463               objs[0]=ref;
464             }
465         }
466     }
467   return ret;
468 }
469
470 template<class MCData, class T>
471 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
472 {
473   return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
474 }
475
476 SWIGINTERN PyObject *MEDCoupling_DataArrayInt_toNumPyArray(MEDCoupling::DataArrayInt *self);
477 SWIGINTERN PyObject *MEDCoupling_DataArrayDouble_toNumPyArray(MEDCoupling::DataArrayDouble *self);
478
479 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
480 {
481   int nbRows((int)m.size());
482   MEDCoupling::MEDCouplingAutoRefCountObjectPtr<MEDCoupling::DataArrayInt> indPtr(MEDCoupling::DataArrayInt::New()),indices(MEDCoupling::DataArrayInt::New());
483   MEDCoupling::MEDCouplingAutoRefCountObjectPtr<MEDCoupling::DataArrayDouble> data(MEDCoupling::DataArrayDouble::New());
484   indPtr->alloc(nbRows+1,1);
485   int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
486   int sz2(0);
487   for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
488     {
489       sz2+=(int)(*it0).size();
490       *intPtr_ptr=sz2;
491     }
492   indices->alloc(sz2,1); data->alloc(sz2,1);
493   int *indices_ptr(indices->getPointer());
494   double *data_ptr(data->getPointer());
495   for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
496     for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
497       {
498         *indices_ptr=(*it1).first;
499         *data_ptr=(*it1).second;
500       }
501   PyObject *a(MEDCoupling_DataArrayDouble_toNumPyArray(data)),*b(MEDCoupling_DataArrayInt_toNumPyArray(indices)),*c(MEDCoupling_DataArrayInt_toNumPyArray(indPtr));
502   //
503   PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
504   PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
505   PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
506   PyObject *tmp1(PyString_FromString("shape"));
507   PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
508   PyObject* pdict=PyDict_New();
509   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
510   PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
511   if(!tmp)
512     throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
513   PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
514   if(!csrMatrixCls)
515     throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
516   PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
517   Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
518   return ret;
519 }
520
521 #endif
522
523 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
524 {
525   PyObject *ret=0;
526   if(!dac)
527     {
528       Py_XINCREF(Py_None);
529       return Py_None;
530     }
531   if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
532     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
533   if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
534     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
535   if(!ret)
536     throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
537   return ret;
538 }
539
540 static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
541 {
542   PyObject *ret=0;
543   if(!dac)
544     {
545       Py_XINCREF(Py_None);
546       return Py_None;
547     }
548   if(dynamic_cast<MEDCoupling::DataArrayDouble *>(dac))
549     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
550   if(dynamic_cast<MEDCoupling::DataArrayInt *>(dac))
551     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner);
552   if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
553     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
554   if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
555     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
556   if(!ret)
557     throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
558   return ret;
559 }
560
561 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
562 {
563   PyObject *ret=PyList_New(size);
564   for(int i=0;i<size;i++)
565     PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
566   return ret;
567 }
568
569 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
570 {
571   int size=v.size();
572   PyObject *ret=PyList_New(size);
573   for(int i=0;i<size;i++)
574     PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
575   return ret;
576 }
577
578 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
579 {
580   int size=v.size();
581   PyObject *ret=PyList_New(size);
582   std::set<int>::const_iterator it=v.begin();
583   for(int i=0;i<size;i++,it++)
584     PyList_SetItem(ret,i,PyInt_FromLong(*it));
585   return ret;
586 }
587
588 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
589 {
590   PyObject *ret=PyList_New(nbOfTuples);
591   for(int i=0;i<nbOfTuples;i++)
592     {
593       PyObject *t=PyTuple_New(nbOfComp);
594       for(int j=0;j<nbOfComp;j++)
595         PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
596       PyList_SetItem(ret,i,t);
597     }
598   return ret;
599 }
600
601 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
602 {
603   if(PyList_Check(pyLi))
604     {
605       *size=PyList_Size(pyLi);
606       int *tmp=new int[*size];
607       for(int i=0;i<*size;i++)
608         {
609           PyObject *o=PyList_GetItem(pyLi,i);
610           if(PyInt_Check(o))
611             {
612               int val=(int)PyInt_AS_LONG(o);
613               tmp[i]=val;
614             }
615           else
616             {
617               delete [] tmp;
618               throw INTERP_KERNEL::Exception("list must contain integers only");
619             }
620         }
621       return tmp;
622     }
623   else if(PyTuple_Check(pyLi))
624     {
625       *size=PyTuple_Size(pyLi);
626       int *tmp=new int[*size];
627       for(int i=0;i<*size;i++)
628         {
629           PyObject *o=PyTuple_GetItem(pyLi,i);
630           if(PyInt_Check(o))
631             {
632               int val=(int)PyInt_AS_LONG(o);
633               tmp[i]=val;
634             }
635           else
636             {
637               delete [] tmp;
638               throw INTERP_KERNEL::Exception("tuple must contain integers only");
639             }
640         }
641       return tmp;
642     }
643   else
644     {
645       throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
646     }
647 }
648
649 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
650 {
651   PyObject *ret=PyList_New(arr.size());
652   for(std::size_t i=0;i<arr.size();i++)
653     {
654       PyObject *t=PyTuple_New(2);
655       PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
656       PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
657       PyList_SetItem(ret,i,t);
658     }
659   return ret;
660 }
661
662 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
663 {
664   const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
665   if(PyList_Check(pyLi))
666     {
667       int size=PyList_Size(pyLi);
668       arr.resize(size);
669       for(int i=0;i<size;i++)
670         {
671           PyObject *o=PyList_GetItem(pyLi,i);
672           if(PyTuple_Check(o))
673             {
674               int sz2=PyTuple_Size(o);
675               if(sz2!=2)
676                 throw INTERP_KERNEL::Exception(msg);
677               PyObject *o_0=PyTuple_GetItem(o,0);
678               if(!PyInt_Check(o_0))
679                 throw INTERP_KERNEL::Exception(msg);
680               PyObject *o_1=PyTuple_GetItem(o,1);
681               if(!PyInt_Check(o_1))
682                 throw INTERP_KERNEL::Exception(msg);
683               arr[i].first=(int)PyInt_AS_LONG(o_0);
684               arr[i].second=(int)PyInt_AS_LONG(o_1);
685             }
686           else
687             throw INTERP_KERNEL::Exception(msg);
688         }
689     }
690   else if(PyTuple_Check(pyLi))
691     {
692       int size=PyTuple_Size(pyLi);
693       arr.resize(size);
694       for(int i=0;i<size;i++)
695         {
696           PyObject *o=PyTuple_GetItem(pyLi,i);
697           if(PyTuple_Check(o))
698             {
699               int sz2=PyTuple_Size(o);
700               if(sz2!=2)
701                 throw INTERP_KERNEL::Exception(msg);
702               PyObject *o_0=PyTuple_GetItem(o,0);
703               if(!PyInt_Check(o_0))
704                 throw INTERP_KERNEL::Exception(msg);
705               PyObject *o_1=PyTuple_GetItem(o,1);
706               if(!PyInt_Check(o_1))
707                 throw INTERP_KERNEL::Exception(msg);
708               arr[i].first=(int)PyInt_AS_LONG(o_0);
709               arr[i].second=(int)PyInt_AS_LONG(o_1);
710             }
711           else
712             throw INTERP_KERNEL::Exception(msg);
713         }
714     }
715   else
716     throw INTERP_KERNEL::Exception(msg);
717 }
718
719 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr) throw(INTERP_KERNEL::Exception)
720 {
721   const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
722   if(PyList_Check(pyLi))
723     {
724       int size=PyList_Size(pyLi);
725       arr.resize(size);
726       for(int i=0;i<size;i++)
727         {
728           PyObject *o=PyList_GetItem(pyLi,i);
729           if(PyTuple_Check(o))
730             {
731               int sz2=PyTuple_Size(o);
732               if(sz2!=2)
733                 throw INTERP_KERNEL::Exception(msg);
734               PyObject *o_0=PyTuple_GetItem(o,0);
735               if(!PyString_Check(o_0))
736                 throw INTERP_KERNEL::Exception(msg);
737               PyObject *o_1=PyTuple_GetItem(o,1);
738               if(!PyInt_Check(o_1))
739                 throw INTERP_KERNEL::Exception(msg);
740               arr[i].first=PyString_AsString(o_0);
741               arr[i].second=(int)PyInt_AS_LONG(o_1);
742             }
743           else
744             throw INTERP_KERNEL::Exception(msg);
745         }
746     }
747   else if(PyTuple_Check(pyLi))
748     {
749       int size=PyTuple_Size(pyLi);
750       arr.resize(size);
751       for(int i=0;i<size;i++)
752         {
753           PyObject *o=PyTuple_GetItem(pyLi,i);
754           if(PyTuple_Check(o))
755             {
756               int sz2=PyTuple_Size(o);
757               if(sz2!=2)
758                 throw INTERP_KERNEL::Exception(msg);
759               PyObject *o_0=PyTuple_GetItem(o,0);
760               if(!PyString_Check(o_0))
761                 throw INTERP_KERNEL::Exception(msg);
762               PyObject *o_1=PyTuple_GetItem(o,1);
763               if(!PyInt_Check(o_1))
764                 throw INTERP_KERNEL::Exception(msg);
765               arr[i].first=PyString_AsString(o_0);
766               arr[i].second=(int)PyInt_AS_LONG(o_1);
767             }
768           else
769             throw INTERP_KERNEL::Exception(msg);
770         }
771     }
772   else
773     throw INTERP_KERNEL::Exception(msg);
774 }
775
776 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
777 {
778   if(PyList_Check(pyLi))
779     {
780       int size=PyList_Size(pyLi);
781       arr.resize(size);
782       for(int i=0;i<size;i++)
783         {
784           PyObject *o=PyList_GetItem(pyLi,i);
785           if(PyInt_Check(o))
786             {
787               int val=(int)PyInt_AS_LONG(o);
788               arr[i]=val;
789             }
790           else
791             throw INTERP_KERNEL::Exception("list must contain integers only");
792         }
793     }
794   else if(PyTuple_Check(pyLi))
795     {
796       int size=PyTuple_Size(pyLi);
797       arr.resize(size);
798       for(int i=0;i<size;i++)
799         {
800           PyObject *o=PyTuple_GetItem(pyLi,i);
801           if(PyInt_Check(o))
802             {
803               int val=(int)PyInt_AS_LONG(o);
804               arr[i]=val;
805             }
806           else
807             throw INTERP_KERNEL::Exception("tuple must contain integers only");
808         }
809     }
810   else
811     {
812       throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
813     }
814 }
815
816 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
817 {
818   if(recurseLev<0)
819     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
820   arr.clear();
821   if(PyList_Check(pyLi))
822     {
823       int size=PyList_Size(pyLi);
824       for(int i=0;i<size;i++)
825         {
826           PyObject *o=PyList_GetItem(pyLi,i);
827           if(PyInt_Check(o))
828             {
829               int val=(int)PyInt_AS_LONG(o);
830               arr.push_back(val);
831             }
832           else
833             {
834               std::vector<int> arr2;
835               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
836               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
837                   {
838                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
839                     throw INTERP_KERNEL::Exception(oss.str().c_str());
840                   }
841               arr.insert(arr.end(),arr2.begin(),arr2.end());
842             }
843         }
844     }
845   else if(PyTuple_Check(pyLi))
846     {
847       int size=PyTuple_Size(pyLi);
848       for(int i=0;i<size;i++)
849         {
850           PyObject *o=PyTuple_GetItem(pyLi,i);
851           if(PyInt_Check(o))
852             {
853               int val=(int)PyInt_AS_LONG(o);
854               arr.push_back(val);
855             }
856           else
857             {
858               std::vector<int> arr2;
859               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
860               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
861                   {
862                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
863                     throw INTERP_KERNEL::Exception(oss.str().c_str());
864                   }
865               arr.insert(arr.end(),arr2.begin(),arr2.end());
866             }
867         }
868     }
869   else
870     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
871 }
872
873 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
874 {
875   if(nbOfTuples==-1)
876     {
877       if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
878       else { if(nbOfComp==size2) { nbOfTuples=size1; } else
879           {
880             std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
881             oss << " whereas nb of components expected is " << nbOfComp << " !";
882             throw INTERP_KERNEL::Exception(oss.str().c_str());
883           } }
884     }
885   else
886     {
887       if(nbOfComp!=-1)
888         {
889           if((nbOfTuples!=size1 || nbOfComp!=size2))
890             {
891               if(size2!=1 || size1!=nbOfComp*nbOfTuples)
892                 {
893                   std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
894                   oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
895                   throw INTERP_KERNEL::Exception(oss.str().c_str());
896                 }
897             }
898         }
899       else
900         {
901           if(nbOfTuples==size1)
902             nbOfComp=size2;
903           else
904             {
905               std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
906               oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
907               throw INTERP_KERNEL::Exception(oss.str().c_str());
908             }
909         }
910     }
911 }
912
913 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
914 {
915   static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
916   if(PyInt_Check(pyLi))
917     {
918       long val=PyInt_AS_LONG(pyLi);
919       if(nbOfElt==-1)
920         nbOfElt=1;
921       else
922         if(nbOfElt!=1)
923           throw INTERP_KERNEL::Exception(MSG);
924       ret.push_back(val);
925     }
926   else if(PyList_Check(pyLi))
927     {
928       int size=PyList_Size(pyLi);
929       int tmp=0;
930       for(int i=0;i<size;i++)
931         {
932           PyObject *o=PyList_GetItem(pyLi,i);
933           int tmp1=-1;
934           fillArrayWithPyListInt3(o,tmp1,ret);
935           tmp+=tmp1;
936         }
937       if(nbOfElt==-1)
938         nbOfElt=tmp;
939       else
940         {
941           if(nbOfElt!=tmp)
942             throw INTERP_KERNEL::Exception(MSG);
943         }
944     }
945   else if(PyTuple_Check(pyLi))
946     {
947       int size=PyTuple_Size(pyLi);
948       int tmp=0;
949       for(int i=0;i<size;i++)
950         {
951           PyObject *o=PyTuple_GetItem(pyLi,i);
952           int tmp1=-1;
953           fillArrayWithPyListInt3(o,tmp1,ret);
954           tmp+=tmp1;
955         }
956       if(nbOfElt==-1)
957         nbOfElt=tmp;
958       else
959         {
960           if(nbOfElt!=tmp)
961             throw INTERP_KERNEL::Exception(MSG);
962         }
963     }
964   else
965     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
966 }
967
968 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
969 {
970   std::vector<int> ret;
971   int size1=-1,size2=-1;
972   if(PyList_Check(pyLi))
973     {
974       size1=PyList_Size(pyLi);
975       for(int i=0;i<size1;i++)
976         {
977           PyObject *o=PyList_GetItem(pyLi,i);
978           fillArrayWithPyListInt3(o,size2,ret);
979         }
980       if(size1==0)
981         size2=1;
982     }
983   else if(PyTuple_Check(pyLi))
984     {
985       size1=PyTuple_Size(pyLi);
986       for(int i=0;i<size1;i++)
987         {
988           PyObject *o=PyTuple_GetItem(pyLi,i);
989           fillArrayWithPyListInt3(o,size2,ret);
990         }
991       if(size1==0)
992         size2=1;
993     }
994   else
995     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
996   //
997   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
998   return ret;
999 }
1000
1001 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
1002 {
1003   if(PyList_Check(pyLi))
1004     {
1005       Py_ssize_t sz=PyList_Size(pyLi);
1006       vec.resize(sz);
1007       for(int i=0;i<sz;i++)
1008         {
1009           PyObject *o=PyList_GetItem(pyLi,i);
1010           if(PyString_Check(o))
1011             vec[i]=PyString_AsString(o);
1012           else
1013             return false;
1014         }
1015       return true;
1016     }
1017   else if(PyTuple_Check(pyLi))
1018     {
1019       Py_ssize_t sz=PyTuple_Size(pyLi);
1020       vec.resize(sz);
1021       for(int i=0;i<sz;i++)
1022         {
1023           PyObject *o=PyTuple_GetItem(pyLi,i);
1024           if(PyString_Check(o))
1025             vec[i]=PyString_AsString(o);
1026           else
1027             return false;
1028         }
1029       return true;
1030     }
1031   else
1032     return false;
1033 }
1034 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr) throw(INTERP_KERNEL::Exception)
1035 {
1036   const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
1037   if(PyList_Check(pyLi))
1038     {
1039       Py_ssize_t sz=PyList_Size(pyLi);
1040       arr.resize(sz);
1041       for(int i=0;i<sz;i++)
1042         {
1043           PyObject *o=PyList_GetItem(pyLi,i);
1044           if(!fillStringVector(o,arr[i]))
1045             throw INTERP_KERNEL::Exception(msg);
1046         }
1047     }
1048   else if(PyTuple_Check(pyLi))
1049     {
1050       Py_ssize_t sz=PyTuple_Size(pyLi);
1051       arr.resize(sz);
1052       for(int i=0;i<sz;i++)
1053         {
1054           PyObject *o=PyTuple_GetItem(pyLi,i);
1055           if(!fillStringVector(o,arr[i]))
1056             throw INTERP_KERNEL::Exception(msg);
1057         }
1058     }
1059   else
1060     throw INTERP_KERNEL::Exception(msg);
1061 }
1062
1063 static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec) throw(INTERP_KERNEL::Exception)
1064 {
1065   if(PyList_Check(pyLi))
1066     {
1067       Py_ssize_t sz=PyList_Size(pyLi);
1068       vec.resize(sz);
1069       for(int i=0;i<sz;i++)
1070         {
1071           PyObject *o=PyList_GetItem(pyLi,i);
1072           if(PyInt_Check(o))
1073             vec[i]=PyInt_AS_LONG(o);
1074           else
1075             return false;
1076         }
1077       return true;
1078     }
1079   else if(PyTuple_Check(pyLi))
1080     {
1081       Py_ssize_t sz=PyTuple_Size(pyLi);
1082       vec.resize(sz);
1083       for(int i=0;i<sz;i++)
1084         {
1085           PyObject *o=PyTuple_GetItem(pyLi,i);
1086           if(PyInt_Check(o))
1087             vec[i]=PyInt_AS_LONG(o);
1088           else
1089             return false;
1090         }
1091       return true;
1092     }
1093   else
1094     return false;
1095 }
1096
1097 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr) throw(INTERP_KERNEL::Exception)
1098 {
1099   const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1100   if(PyList_Check(pyLi))
1101     {
1102       Py_ssize_t sz=PyList_Size(pyLi);
1103       arr.resize(sz);
1104       for(int i=0;i<sz;i++)
1105         {
1106           PyObject *o=PyList_GetItem(pyLi,i);
1107           if(!fillIntVector(o,arr[i]))
1108             throw INTERP_KERNEL::Exception(msg);
1109         }
1110     }
1111   else if(PyTuple_Check(pyLi))
1112     {
1113       Py_ssize_t sz=PyTuple_Size(pyLi);
1114       arr.resize(sz);
1115       for(int i=0;i<sz;i++)
1116         {
1117           PyObject *o=PyTuple_GetItem(pyLi,i);
1118           if(!fillIntVector(o,arr[i]))
1119             throw INTERP_KERNEL::Exception(msg);
1120         }
1121     }
1122   else
1123     throw INTERP_KERNEL::Exception(msg);
1124 }
1125
1126 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr) throw(INTERP_KERNEL::Exception)
1127 {
1128   const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1129   if(PyList_Check(pyLi))
1130     {
1131       Py_ssize_t sz=PyList_Size(pyLi);
1132       arr.resize(sz);
1133       for(int i=0;i<sz;i++)
1134         {
1135           PyObject *o=PyList_GetItem(pyLi,i);
1136           if(PyTuple_Check(o))
1137             {
1138               int sz2=PyTuple_Size(o);
1139               if(sz2!=2)
1140                 throw INTERP_KERNEL::Exception(msg);
1141               std::pair<std::string, std::vector<std::string> > item;
1142               PyObject *o_0=PyTuple_GetItem(o,0);
1143               if(!PyString_Check(o_0))
1144                 throw INTERP_KERNEL::Exception(msg);
1145               item.first=PyString_AsString(o_0);
1146               PyObject *o_1=PyTuple_GetItem(o,1);
1147               if(!fillStringVector(o_1,item.second))
1148                 throw INTERP_KERNEL::Exception(msg);
1149               arr[i]=item;
1150             }
1151           else
1152             throw INTERP_KERNEL::Exception(msg);
1153         }
1154     }
1155   else if(PyTuple_Check(pyLi))
1156     {
1157       Py_ssize_t sz=PyTuple_Size(pyLi);
1158       arr.resize(sz);
1159       for(int i=0;i<sz;i++)
1160         {
1161           PyObject *o=PyTuple_GetItem(pyLi,i);
1162           if(PyTuple_Check(o))
1163             {
1164               int sz2=PyTuple_Size(o);
1165               if(sz2!=2)
1166                 throw INTERP_KERNEL::Exception(msg);
1167               std::pair<std::string, std::vector<std::string> > item;
1168               PyObject *o_0=PyTuple_GetItem(o,0);
1169               if(!PyString_Check(o_0))
1170                 throw INTERP_KERNEL::Exception(msg);
1171               item.first=PyString_AsString(o_0);
1172               PyObject *o_1=PyTuple_GetItem(o,1);
1173               if(!fillStringVector(o_1,item.second))
1174                 throw INTERP_KERNEL::Exception(msg);
1175               arr[i]=item;
1176             }
1177           else
1178             throw INTERP_KERNEL::Exception(msg);
1179         }
1180     }
1181   else
1182     throw INTERP_KERNEL::Exception(msg);
1183 }
1184
1185 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
1186 {
1187   PyObject *ret=PyList_New(size);
1188   for(int i=0;i<size;i++)
1189     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1190   return ret;
1191 }
1192
1193 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
1194 {
1195   int size=v.size();
1196   PyObject *ret=PyList_New(size);
1197   for(int i=0;i<size;i++)
1198     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1199   return ret;
1200 }
1201
1202 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1203 {
1204   PyObject *ret=PyList_New(nbOfTuples);
1205   for(int i=0;i<nbOfTuples;i++)
1206     {
1207       PyObject *t=PyTuple_New(nbOfComp);
1208       for(int j=0;j<nbOfComp;j++)
1209         PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1210       PyList_SetItem(ret,i,t);
1211     }
1212   return ret;
1213 }
1214
1215 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1216 {
1217   PyObject *ret=PyList_New(nbOfTuples);
1218   INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1219   for(int i=0;i<nbOfTuples;i++)
1220     {
1221       std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1222       PyList_SetItem(ret,i,PyString_FromString(tmp));
1223     }
1224   return ret;
1225 }
1226
1227 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1228 {
1229   if(PyList_Check(pyLi))
1230     {
1231       *size=PyList_Size(pyLi);
1232       double *tmp=(double *)malloc((*size)*sizeof(double));
1233       for(int i=0;i<*size;i++)
1234         {
1235           PyObject *o=PyList_GetItem(pyLi,i);
1236           if(PyFloat_Check(o))
1237             {
1238               double val=PyFloat_AS_DOUBLE(o);
1239               tmp[i]=val;
1240             }
1241           else if(PyInt_Check(o))
1242             {
1243               long val0=PyInt_AS_LONG(o);
1244               double val=val0;
1245               tmp[i]=val;
1246             }
1247           else
1248             {
1249               free(tmp);
1250               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1251             }
1252         }
1253       return tmp;
1254     }
1255   else if(PyTuple_Check(pyLi))
1256     {
1257       *size=PyTuple_Size(pyLi);
1258       double *tmp=(double *)malloc((*size)*sizeof(double));
1259       for(int i=0;i<*size;i++)
1260         {
1261           PyObject *o=PyTuple_GetItem(pyLi,i);
1262           if(PyFloat_Check(o))
1263             {
1264               double val=PyFloat_AS_DOUBLE(o);
1265               tmp[i]=val;
1266             }
1267           else if(PyInt_Check(o))
1268             {
1269               long val0=PyInt_AS_LONG(o);
1270               double val=val0;
1271               tmp[i]=val;
1272             }
1273           else
1274             {
1275               free(tmp);
1276               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1277             }
1278         }
1279       return tmp;
1280     }
1281   else
1282     throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1283 }
1284
1285 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1286 {
1287   static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1288   if(PyFloat_Check(pyLi))
1289     {
1290       if(nbOfElt==-1)
1291         nbOfElt=1;
1292       else
1293         if(nbOfElt!=1)
1294           throw INTERP_KERNEL::Exception(MSG);
1295       double val=PyFloat_AS_DOUBLE(pyLi);
1296       ret.push_back(val);
1297     }
1298   else if(PyInt_Check(pyLi))
1299     {
1300       long val0=PyInt_AS_LONG(pyLi);
1301       double val=val0;
1302       if(nbOfElt==-1)
1303         nbOfElt=1;
1304       else
1305         if(nbOfElt!=1)
1306           throw INTERP_KERNEL::Exception(MSG);
1307       ret.push_back(val);
1308     }
1309   else if(PyList_Check(pyLi))
1310     {
1311       int size=PyList_Size(pyLi);
1312       int tmp=0;
1313       for(int i=0;i<size;i++)
1314         {
1315           PyObject *o=PyList_GetItem(pyLi,i);
1316           int tmp1=-1;
1317           fillArrayWithPyListDbl3(o,tmp1,ret);
1318           tmp+=tmp1;
1319         }
1320       if(nbOfElt==-1)
1321         nbOfElt=tmp;
1322       else
1323         {
1324           if(nbOfElt!=tmp)
1325             throw INTERP_KERNEL::Exception(MSG);
1326         }
1327     }
1328   else if(PyTuple_Check(pyLi))
1329     {
1330       int size=PyTuple_Size(pyLi);
1331       int tmp=0;
1332       for(int i=0;i<size;i++)
1333         {
1334           PyObject *o=PyTuple_GetItem(pyLi,i);
1335           int tmp1=-1;
1336           fillArrayWithPyListDbl3(o,tmp1,ret);
1337           tmp+=tmp1;
1338         }
1339       if(nbOfElt==-1)
1340         nbOfElt=tmp;
1341       else
1342         {
1343           if(nbOfElt!=tmp)
1344             throw INTERP_KERNEL::Exception(MSG);
1345         }
1346     }
1347   else
1348     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1349 }
1350
1351 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1352 {
1353   std::vector<double> ret;
1354   int size1=-1,size2=-1;
1355   if(PyList_Check(pyLi))
1356     {
1357       size1=PyList_Size(pyLi);
1358       for(int i=0;i<size1;i++)
1359         {
1360           PyObject *o=PyList_GetItem(pyLi,i);
1361           fillArrayWithPyListDbl3(o,size2,ret);
1362         }
1363       if(size1==0)
1364         size2=1;
1365     }
1366   else if(PyTuple_Check(pyLi))
1367     {
1368       size1=PyTuple_Size(pyLi);
1369       for(int i=0;i<size1;i++)
1370         {
1371           PyObject *o=PyTuple_GetItem(pyLi,i);
1372           fillArrayWithPyListDbl3(o,size2,ret);
1373         }
1374       if(size1==0)
1375         size2=1;
1376     }
1377   else
1378     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1379   //
1380   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1381   return ret;
1382 }
1383
1384 //convertFromPyObjVectorOfObj<const MEDCoupling::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,"MEDCouplingUMesh")
1385 template<class T>
1386 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1387 {
1388   void *argp=0;
1389   if(PyList_Check(pyLi))
1390     {
1391       int size=PyList_Size(pyLi);
1392       ret.resize(size);
1393       for(int i=0;i<size;i++)
1394         {
1395           PyObject *obj=PyList_GetItem(pyLi,i);
1396           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1397           if(!SWIG_IsOK(status))
1398             {
1399               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1400               throw INTERP_KERNEL::Exception(oss.str().c_str());
1401             }
1402           T arg=reinterpret_cast< T >(argp);
1403           ret[i]=arg;
1404         }
1405     }
1406   else if(PyTuple_Check(pyLi))
1407     {
1408       int size=PyTuple_Size(pyLi);
1409       ret.resize(size);
1410       for(int i=0;i<size;i++)
1411         {
1412           PyObject *obj=PyTuple_GetItem(pyLi,i);
1413           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1414           if(!SWIG_IsOK(status))
1415             {
1416               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1417               throw INTERP_KERNEL::Exception(oss.str().c_str());
1418             }
1419           T arg=reinterpret_cast< T >(argp);
1420           ret[i]=arg;
1421         }
1422     }
1423   else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1424     {
1425       ret.resize(1);
1426       T arg=reinterpret_cast< T >(argp);
1427       ret[0]=arg;
1428     }
1429   else
1430     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1431 }
1432
1433 /*!
1434  * if python int -> cpp int sw=1
1435  * if python list[int] -> cpp vector<int> sw=2
1436  * if python tuple[int] -> cpp vector<int> sw=2
1437  * if python DataArrayInt -> cpp DataArrayInt sw=3
1438  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1439  *
1440  * switch between (int,vector<int>,DataArrayInt)
1441  */
1442 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, MEDCoupling::DataArrayInt *& daIntTyypp, MEDCoupling::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1443 {
1444   sw=-1;
1445   if(PyInt_Check(value))
1446     {
1447       iTyypp=(int)PyInt_AS_LONG(value);
1448       sw=1;
1449       return;
1450     }
1451   if(PyTuple_Check(value))
1452     {
1453       int size=PyTuple_Size(value);
1454       stdvecTyypp.resize(size);
1455       for(int i=0;i<size;i++)
1456         {
1457           PyObject *o=PyTuple_GetItem(value,i);
1458           if(PyInt_Check(o))
1459             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1460           else
1461             {
1462               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1463               throw INTERP_KERNEL::Exception(oss.str().c_str());
1464             }
1465         }
1466       sw=2;
1467       return;
1468     }
1469   if(PyList_Check(value))
1470     {
1471       int size=PyList_Size(value);
1472       stdvecTyypp.resize(size);
1473       for(int i=0;i<size;i++)
1474         {
1475           PyObject *o=PyList_GetItem(value,i);
1476           if(PyInt_Check(o))
1477             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1478           else
1479             {
1480               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1481               throw INTERP_KERNEL::Exception(oss.str().c_str());
1482             }
1483         }
1484       sw=2;
1485       return;
1486     }
1487   void *argp;
1488   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1489   if(SWIG_IsOK(status))
1490     {
1491       daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1492       sw=3;
1493       return;
1494     }
1495   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1496   if(SWIG_IsOK(status))
1497     {  
1498       daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1499       sw=4;
1500       return ;
1501     }
1502   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1503 }
1504
1505 /*!
1506  * if python double -> cpp double sw=1
1507  * if python int -> cpp double sw=1
1508  * if python list[double] -> cpp vector<double> sw=2
1509  * if python list[int] -> cpp vector<double> sw=2
1510  * if python tuple[double] -> cpp vector<double> sw=2
1511  * if python tuple[int] -> cpp vector<double> sw=2
1512  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1513  *
1514  * switch between (int,vector<int>,DataArrayInt)
1515  */
1516 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1517 {
1518   sw=-1;
1519   if(PyFloat_Check(value))
1520     {
1521       iTyypp=PyFloat_AS_DOUBLE(value);
1522       sw=1;
1523       return;
1524     }
1525   if(PyInt_Check(value))
1526     {
1527       iTyypp=(double)PyInt_AS_LONG(value);
1528       sw=1;
1529       return;
1530     }
1531   if(PyTuple_Check(value))
1532     {
1533       int size=PyTuple_Size(value);
1534       stdvecTyypp.resize(size);
1535       for(int i=0;i<size;i++)
1536         {
1537           PyObject *o=PyTuple_GetItem(value,i);
1538           if(PyFloat_Check(o))
1539             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1540           else if(PyInt_Check(o))
1541             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1542           else
1543             {
1544               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1545               throw INTERP_KERNEL::Exception(oss.str().c_str());
1546             }
1547         }
1548       sw=2;
1549       return;
1550     }
1551   if(PyList_Check(value))
1552     {
1553       int size=PyList_Size(value);
1554       stdvecTyypp.resize(size);
1555       for(int i=0;i<size;i++)
1556         {
1557           PyObject *o=PyList_GetItem(value,i);
1558           if(PyFloat_Check(o))
1559             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1560           else if(PyInt_Check(o))
1561             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1562           else
1563             {
1564               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1565               throw INTERP_KERNEL::Exception(oss.str().c_str());
1566             }
1567         }
1568       sw=2;
1569       return;
1570     }
1571   void *argp;
1572   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
1573   if(!SWIG_IsOK(status))
1574     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1575   daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
1576   sw=3;
1577 }
1578
1579 /*!
1580  * if python double -> cpp double sw=1
1581  * if python int -> cpp double sw=1
1582  * if python list[double] -> cpp vector<double> sw=2
1583  * if python list[int] -> cpp vector<double> sw=2
1584  * if python tuple[double] -> cpp vector<double> sw=2
1585  * if python tuple[int] -> cpp vector<double> sw=2
1586  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1587  *
1588  * switch between (int,vector<int>,DataArrayInt)
1589  */
1590 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1591 {
1592   sw=-1;
1593   if(PyFloat_Check(value))
1594     {
1595       iTyypp=PyFloat_AS_DOUBLE(value);
1596       sw=1;
1597       return;
1598     }
1599   if(PyInt_Check(value))
1600     {
1601       iTyypp=(double)PyInt_AS_LONG(value);
1602       sw=1;
1603       return;
1604     }
1605   if(PyTuple_Check(value))
1606     {
1607       int size=PyTuple_Size(value);
1608       stdvecTyypp.resize(size);
1609       for(int i=0;i<size;i++)
1610         {
1611           PyObject *o=PyTuple_GetItem(value,i);
1612           if(PyFloat_Check(o))
1613             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1614           else if(PyInt_Check(o))
1615             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1616           else
1617             {
1618               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1619               throw INTERP_KERNEL::Exception(oss.str().c_str());
1620             }
1621         }
1622       sw=2;
1623       return;
1624     }
1625   if(PyList_Check(value))
1626     {
1627       int size=PyList_Size(value);
1628       stdvecTyypp.resize(size);
1629       for(int i=0;i<size;i++)
1630         {
1631           PyObject *o=PyList_GetItem(value,i);
1632           if(PyFloat_Check(o))
1633             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1634           else if(PyInt_Check(o))
1635             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1636           else
1637             {
1638               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1639               throw INTERP_KERNEL::Exception(oss.str().c_str());
1640             }
1641         }
1642       sw=2;
1643       return;
1644     }
1645   void *argp;
1646   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1647   if(!SWIG_IsOK(status))
1648     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1649   daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1650   sw=3;
1651 }
1652
1653 /*!
1654  * if python int -> cpp int sw=1
1655  * if python list[int] -> cpp vector<int> sw=2
1656  * if python tuple[int] -> cpp vector<int> sw=2
1657  * if python slicp -> cpp pair sw=3 (begin,end,step)
1658  * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1659  *
1660  * switch between (int,vector<int>,DataArrayInt)
1661  */
1662 static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1663 {
1664   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1665   sw=-1;
1666   if(PyInt_Check(value))
1667     {
1668       iTyypp=(int)PyInt_AS_LONG(value);
1669       sw=1;
1670       return;
1671     }
1672   if(PyTuple_Check(value))
1673     {
1674       int size=PyTuple_Size(value);
1675       stdvecTyypp.resize(size);
1676       for(int i=0;i<size;i++)
1677         {
1678           PyObject *o=PyTuple_GetItem(value,i);
1679           if(PyInt_Check(o))
1680             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1681           else
1682             {
1683               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1684               throw INTERP_KERNEL::Exception(oss.str().c_str());
1685             }
1686         }
1687       sw=2;
1688       return;
1689     }
1690   if(PyList_Check(value))
1691     {
1692       int size=PyList_Size(value);
1693       stdvecTyypp.resize(size);
1694       for(int i=0;i<size;i++)
1695         {
1696           PyObject *o=PyList_GetItem(value,i);
1697           if(PyInt_Check(o))
1698             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1699           else
1700             {
1701               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1702               throw INTERP_KERNEL::Exception(oss.str().c_str());
1703             }
1704         }
1705       sw=2;
1706       return;
1707     }
1708   if(PySlice_Check(value))
1709     {
1710       Py_ssize_t strt=2,stp=2,step=2;
1711       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1712       GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1713       p.first=strt;
1714       p.second.first=stp;
1715       p.second.second=step;
1716       sw=3;
1717       return ;
1718     }
1719   void *argp;
1720   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1721   if(SWIG_IsOK(status))
1722     {
1723       daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1724       if(!daIntTyypp)
1725         {
1726           std::ostringstream oss; oss << msg << " Instance in null !";
1727           throw INTERP_KERNEL::Exception(oss.str().c_str());
1728         }
1729       sw=4;
1730       return ;
1731     }
1732   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1733   if(SWIG_IsOK(status))
1734     {
1735       MEDCoupling::DataArrayIntTuple *tmp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1736       if(!tmp)
1737         {
1738           std::ostringstream oss; oss << msg << " Instance in null !";
1739           throw INTERP_KERNEL::Exception(oss.str().c_str());
1740         }
1741       stdvecTyypp.resize(tmp->getNumberOfCompo());
1742       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1743       sw=2;
1744       return ;
1745     }
1746   throw INTERP_KERNEL::Exception(msg);
1747 }
1748
1749 /*!
1750  * Idem than convertObjToPossibleCpp2
1751  */
1752 static void convertObjToPossibleCpp2WithNegIntInterp(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1753 {
1754   convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1755   if(sw==1)
1756     {
1757       iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1758     }
1759 }
1760
1761 /*!
1762  * if python int -> cpp int sw=1
1763  * if python tuple[int] -> cpp vector<int> sw=2
1764  * if python list[int] -> cpp vector<int> sw=2
1765  * if python slice -> cpp pair sw=3
1766  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1767  */
1768 static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayIntTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1769 {
1770   sw=-1;
1771   if(PyInt_Check(value))
1772     {
1773       iTyypp=(int)PyInt_AS_LONG(value);
1774       sw=1;
1775       return;
1776     }
1777   if(PyTuple_Check(value))
1778     {
1779       int size=PyTuple_Size(value);
1780       stdvecTyypp.resize(size);
1781       for(int i=0;i<size;i++)
1782         {
1783           PyObject *o=PyTuple_GetItem(value,i);
1784           if(PyInt_Check(o))
1785             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1786           else
1787             {
1788               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1789               throw INTERP_KERNEL::Exception(oss.str().c_str());
1790             }
1791         }
1792       sw=2;
1793       return;
1794     }
1795   if(PyList_Check(value))
1796     {
1797       int size=PyList_Size(value);
1798       stdvecTyypp.resize(size);
1799       for(int i=0;i<size;i++)
1800         {
1801           PyObject *o=PyList_GetItem(value,i);
1802           if(PyInt_Check(o))
1803             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1804           else
1805             {
1806               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1807               throw INTERP_KERNEL::Exception(oss.str().c_str());
1808             }
1809         }
1810       sw=2;
1811       return;
1812     }
1813   if(PySlice_Check(value))
1814     {
1815       Py_ssize_t strt=2,stp=2,step=2;
1816       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1817       GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1818       p.first=strt;
1819       p.second.first=stp;
1820       p.second.second=step;
1821       sw=3;
1822       return ;
1823     }
1824   void *argp;
1825   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1826   if(!SWIG_IsOK(status))
1827     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1828   daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1829   sw=4;
1830 }
1831
1832 /*!
1833  * if python string with size one -> cpp char sw=1
1834  * if python string with size different from one -> cpp string sw=2
1835  * if python tuple[string] or list[string] -> vector<string> sw=3
1836  * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1837  * switch between (int,string,vector<string>,DataArrayChar)
1838  */
1839 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1840 {
1841   const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1842   sw=-1;
1843   if(PyString_Check(value))
1844     {
1845       const char *pt=PyString_AsString(value);
1846       Py_ssize_t sz=PyString_Size(value);
1847       if(sz==1)
1848         {
1849           cTyp=pt[0];
1850           sw=1;
1851           return;
1852         }
1853       else
1854         {
1855           sType=pt;
1856           sw=2;
1857           return;
1858         }
1859     }
1860   if(PyTuple_Check(value))
1861     {
1862       int size=PyTuple_Size(value);
1863       vsType.resize(size);
1864       for(int i=0;i<size;i++)
1865         {
1866           PyObject *o=PyTuple_GetItem(value,i);
1867           if(PyString_Check(o))
1868             vsType[i]=PyString_AsString(o);
1869           else
1870             {
1871               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1872               throw INTERP_KERNEL::Exception(oss.str().c_str());
1873             }
1874         }
1875       sw=3;
1876       return;
1877     }
1878   if(PyList_Check(value))
1879     {
1880       int size=PyList_Size(value);
1881       vsType.resize(size);
1882       for(int i=0;i<size;i++)
1883         {
1884           PyObject *o=PyList_GetItem(value,i);
1885           if(PyString_Check(o))
1886             vsType[i]=PyString_AsString(o);
1887           else
1888             {
1889               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1890               throw INTERP_KERNEL::Exception(oss.str().c_str());
1891             }
1892         }
1893       sw=3;
1894       return;
1895     }
1896   void *argp;
1897   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
1898   if(SWIG_IsOK(status))
1899     {
1900       dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
1901       if(!dacType)
1902         {
1903           std::ostringstream oss; oss << msg << " Instance in null !";
1904           throw INTERP_KERNEL::Exception(oss.str().c_str());
1905         }
1906       sw=4;
1907       return ;
1908     }
1909   throw INTERP_KERNEL::Exception(msg);
1910 }
1911
1912 /*!
1913  * if value int -> cpp it sw=1
1914  * if value list[int] -> vt sw=2
1915  * if value tuple[int] -> vt sw=2
1916  * if value slice -> pt sw=3
1917  * if value DataArrayInt -> dt sw=4
1918  * if value tuple [int,int] -> cpp it,ip sw=5
1919  * if value tuple [list[int],int] -> cpp vt,ip sw=6
1920  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1921  * if value tuple [slice,int] -> cpp pt,ip sw=7
1922  * if value tuple [DaI,int] -> cpp dt,ip sw=8
1923  * if value tuple [int,list[int]] -> cpp it,vc sw=9
1924  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1925  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1926  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1927  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1928  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1929  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1930  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1931  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1932  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1933  * if value tuple [int,slice] -> cpp it,pc sw=13
1934  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1935  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1936  * if value tuple [slice,slice] -> cpp pt,pc sw=15
1937  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1938  *
1939  * switch between (int,vector<int>,DataArrayInt)
1940  */
1941 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1942                                      std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1943                                      MEDCoupling::DataArrayInt *&dt, MEDCoupling::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1944 {
1945   if(!PyTuple_Check(value))
1946     {
1947       convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1948       return ;
1949     }
1950   else
1951     {
1952       int sz=PyTuple_Size(value);
1953       if(sz!=2)
1954         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1955       PyObject *ob0=PyTuple_GetItem(value,0);
1956       int sw1,sw2;
1957       convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1958       PyObject *ob1=PyTuple_GetItem(value,1);
1959       convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1960       sw=4*sw2+sw1;
1961     }
1962 }
1963
1964 /*!
1965  * if value int -> cpp val sw=1
1966  * if value double -> cpp val sw=1
1967  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1968  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1969  * if value list[int,double] -> cpp std::vector<double> sw=4
1970  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1971  */
1972 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1973 {
1974   sw=-1;
1975   if(PyFloat_Check(value))
1976     {
1977       val=PyFloat_AS_DOUBLE(value);
1978       sw=1;
1979       return;
1980     }
1981   if(PyInt_Check(value))
1982     {
1983       val=(double)PyInt_AS_LONG(value);
1984       sw=1;
1985       return;
1986     }
1987   if(PyTuple_Check(value))
1988     {
1989       int size=PyTuple_Size(value);
1990       f.resize(size);
1991       for(int i=0;i<size;i++)
1992         {
1993           PyObject *o=PyTuple_GetItem(value,i);
1994           if(PyFloat_Check(o))
1995             f[i]=PyFloat_AS_DOUBLE(o);
1996           else if(PyInt_Check(o))
1997             f[i]=(double)PyInt_AS_LONG(o);
1998           else
1999             {
2000               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2001               throw INTERP_KERNEL::Exception(oss.str().c_str());
2002             }
2003         }
2004       sw=4;
2005       return;
2006     }
2007   if(PyList_Check(value))
2008     {
2009       int size=PyList_Size(value);
2010       f.resize(size);
2011       for(int i=0;i<size;i++)
2012         {
2013           PyObject *o=PyList_GetItem(value,i);
2014           if(PyFloat_Check(o))
2015             f[i]=PyFloat_AS_DOUBLE(o);
2016           else if(PyInt_Check(o))
2017             f[i]=(double)PyInt_AS_LONG(o);
2018           else
2019             {
2020               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2021               throw INTERP_KERNEL::Exception(oss.str().c_str());
2022             }
2023         }
2024       sw=4;
2025       return;
2026     }
2027   void *argp;
2028   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2029   if(SWIG_IsOK(status))
2030     {  
2031       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2032       sw=2;
2033       return ;
2034     }
2035   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2036   if(SWIG_IsOK(status))
2037     {  
2038       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2039       sw=3;
2040       return ;
2041     }
2042   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2043 }
2044
2045 /*!
2046  * if value int -> cpp val sw=1
2047  * if value double -> cpp val sw=1
2048  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2049  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2050  * if value list[int,double] -> cpp std::vector<double> sw=4
2051  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2052  */
2053 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2054                                                    const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
2055 {
2056   sw=-1;
2057   if(PyFloat_Check(value))
2058     {
2059       val=PyFloat_AS_DOUBLE(value);
2060       sw=1;
2061       if(nbTuplesExpected*nbCompExpected!=1)
2062         {
2063           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
2064           throw INTERP_KERNEL::Exception(oss.str().c_str());
2065         }
2066       return &val;
2067     }
2068   if(PyInt_Check(value))
2069     {
2070       val=(double)PyInt_AS_LONG(value);
2071       sw=1;
2072       if(nbTuplesExpected*nbCompExpected!=1)
2073         {
2074           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
2075           throw INTERP_KERNEL::Exception(oss.str().c_str());
2076         }
2077       return &val;
2078     }
2079   if(PyTuple_Check(value) || PyList_Check(value))
2080     {
2081       try
2082         {
2083           int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2084           std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2085           sw=4;
2086           f=ret;
2087           return &f[0];
2088         }
2089       catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2090     }
2091   void *argp;
2092   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2093   if(SWIG_IsOK(status))
2094     {  
2095       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2096       sw=2;
2097       if(d)
2098         {
2099           if(d->getNumberOfTuples()==nbTuplesExpected)
2100             {
2101               if(d->getNumberOfComponents()==nbCompExpected)
2102                 {
2103                   return d->getConstPointer();
2104                 }
2105               else
2106                 {
2107                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2108                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2109                 }
2110             }
2111           else
2112             {
2113               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2114               throw INTERP_KERNEL::Exception(oss.str().c_str());
2115             }
2116         }
2117       else
2118         {
2119           if(throwIfNullPt)
2120             {
2121               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2122               throw INTERP_KERNEL::Exception(oss.str().c_str());
2123             }
2124           else
2125             return 0;
2126         }
2127     }
2128   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2129   if(SWIG_IsOK(status))
2130     {  
2131       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2132       sw=3;
2133       if(e->getNumberOfCompo()==nbCompExpected)
2134         {
2135           if(nbTuplesExpected==1)
2136             return e->getConstPointer();
2137           else
2138             {
2139               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2140               throw INTERP_KERNEL::Exception(oss.str().c_str());
2141             }
2142         }
2143       else
2144         {
2145           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2146           throw INTERP_KERNEL::Exception(oss.str().c_str());
2147         }
2148     }
2149   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2150 }
2151
2152 /*!
2153  * if value int -> cpp val sw=1
2154  * if value double -> cpp val sw=1
2155  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2156  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2157  * if value list[int,double] -> cpp std::vector<double> sw=4
2158  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2159  */
2160 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2161                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2162 {
2163   sw=-1;
2164   if(PyFloat_Check(value))
2165     {
2166       val=PyFloat_AS_DOUBLE(value);
2167       sw=1;
2168       if(nbCompExpected!=1)
2169         {
2170           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
2171           throw INTERP_KERNEL::Exception(oss.str().c_str());
2172         }
2173       nbTuples=1;
2174       return &val;
2175     }
2176   if(PyInt_Check(value))
2177     {
2178       val=(double)PyInt_AS_LONG(value);
2179       sw=1;
2180       if(nbCompExpected!=1)
2181         {
2182           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
2183           throw INTERP_KERNEL::Exception(oss.str().c_str());
2184         }
2185       nbTuples=1;
2186       return &val;
2187     }
2188   if(PyTuple_Check(value))
2189     {
2190       int size=PyTuple_Size(value);
2191       f.resize(size);
2192       for(int i=0;i<size;i++)
2193         {
2194           PyObject *o=PyTuple_GetItem(value,i);
2195           if(PyFloat_Check(o))
2196             f[i]=PyFloat_AS_DOUBLE(o);
2197           else if(PyInt_Check(o))
2198             f[i]=(double)PyInt_AS_LONG(o);
2199           else
2200             {
2201               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2202               throw INTERP_KERNEL::Exception(oss.str().c_str());
2203             }
2204         }
2205       sw=4;
2206       if(size%nbCompExpected!=0)
2207         {
2208           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
2209           throw INTERP_KERNEL::Exception(oss.str().c_str());
2210         }
2211       nbTuples=size/nbCompExpected;
2212       return &f[0];
2213     }
2214   if(PyList_Check(value))
2215     {
2216       int size=PyList_Size(value);
2217       f.resize(size);
2218       for(int i=0;i<size;i++)
2219         {
2220           PyObject *o=PyList_GetItem(value,i);
2221           if(PyFloat_Check(o))
2222             f[i]=PyFloat_AS_DOUBLE(o);
2223           else if(PyInt_Check(o))
2224             f[i]=(double)PyInt_AS_LONG(o);
2225           else
2226             {
2227               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2228               throw INTERP_KERNEL::Exception(oss.str().c_str());
2229             }
2230         }
2231       sw=4;
2232       if(size%nbCompExpected!=0)
2233         {
2234           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
2235           throw INTERP_KERNEL::Exception(oss.str().c_str());
2236         }
2237       nbTuples=size/nbCompExpected;
2238       return &f[0];
2239     }
2240   void *argp;
2241   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2242   if(SWIG_IsOK(status))
2243     {  
2244       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2245       sw=2;
2246       if(d)
2247         {
2248           if(d->getNumberOfComponents()==nbCompExpected)
2249             {
2250               nbTuples=d->getNumberOfTuples();
2251               return d->getConstPointer();
2252             }
2253           else
2254             {
2255               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2256               throw INTERP_KERNEL::Exception(oss.str().c_str());
2257             }
2258         }
2259       else
2260         {
2261           if(throwIfNullPt)
2262             {
2263               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2264               throw INTERP_KERNEL::Exception(oss.str().c_str());
2265             }
2266           else
2267             { nbTuples=0; return 0; }
2268         }
2269     }
2270   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2271   if(SWIG_IsOK(status))
2272     {  
2273       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2274       sw=3;
2275       if(e)
2276         {
2277           if(e->getNumberOfCompo()==nbCompExpected)
2278             {
2279               nbTuples=1;
2280               return e->getConstPointer();
2281             }
2282           else
2283             {
2284               std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2285               throw INTERP_KERNEL::Exception(oss.str().c_str());
2286             }
2287         }
2288       else
2289         {
2290           if(throwIfNullPt)
2291             {
2292               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2293               throw INTERP_KERNEL::Exception(oss.str().c_str());
2294             }
2295           else
2296             { nbTuples=0; return 0; }
2297         }
2298     }
2299   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2300 }
2301
2302 /*!
2303  * if value int -> cpp val sw=1
2304  * if value double -> cpp val sw=1
2305  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2306  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2307  * if value list[int,double] -> cpp std::vector<double> sw=4
2308  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2309  */
2310 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2311                                                           const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2312 {
2313   MEDCoupling::DataArrayDouble *d=0;
2314   MEDCoupling::DataArrayDoubleTuple *e=0;
2315   sw=-1;
2316   if(PyFloat_Check(value))
2317     {
2318       val=PyFloat_AS_DOUBLE(value);
2319       sw=1;
2320       nbTuples=1;
2321       return &val;
2322     }
2323   if(PyInt_Check(value))
2324     {
2325       val=(double)PyInt_AS_LONG(value);
2326       sw=1;
2327       nbTuples=1;
2328       return &val;
2329     }
2330   if(PyTuple_Check(value))
2331     {
2332       int size=PyTuple_Size(value);
2333       f.resize(size);
2334       for(int i=0;i<size;i++)
2335         {
2336           PyObject *o=PyTuple_GetItem(value,i);
2337           if(PyFloat_Check(o))
2338             f[i]=PyFloat_AS_DOUBLE(o);
2339           else if(PyInt_Check(o))
2340             f[i]=(double)PyInt_AS_LONG(o);
2341           else
2342             {
2343               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2344               throw INTERP_KERNEL::Exception(oss.str().c_str());
2345             }
2346         }
2347       sw=4;
2348       nbTuples=size;
2349       return &f[0];
2350     }
2351   if(PyList_Check(value))
2352     {
2353       int size=PyList_Size(value);
2354       f.resize(size);
2355       for(int i=0;i<size;i++)
2356         {
2357           PyObject *o=PyList_GetItem(value,i);
2358           if(PyFloat_Check(o))
2359             f[i]=PyFloat_AS_DOUBLE(o);
2360           else if(PyInt_Check(o))
2361             f[i]=(double)PyInt_AS_LONG(o);
2362           else
2363             {
2364               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2365               throw INTERP_KERNEL::Exception(oss.str().c_str());
2366             }
2367         }
2368       sw=4;
2369       nbTuples=size;
2370       return &f[0];
2371     }
2372   void *argp;
2373   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2374   if(SWIG_IsOK(status))
2375     {  
2376       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2377       sw=2;
2378       if(d)
2379         {
2380           if(d->getNumberOfComponents()==1)
2381             {
2382               nbTuples=d->getNumberOfTuples();
2383               return d->getConstPointer();
2384             }
2385           else
2386             {
2387               std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2388               throw INTERP_KERNEL::Exception(oss.str().c_str());
2389             }
2390         }
2391       else
2392         {
2393           if(throwIfNullPt)
2394             {
2395               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2396               throw INTERP_KERNEL::Exception(oss.str().c_str());
2397             }
2398           else
2399             { nbTuples=0; return 0; }
2400         }
2401     }
2402   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2403   if(SWIG_IsOK(status))
2404     {  
2405       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2406       sw=3;
2407       if(e)
2408         {
2409           nbTuples=e->getNumberOfCompo();
2410           return e->getConstPointer();
2411         }
2412       else
2413         {
2414           if(throwIfNullPt)
2415             {
2416               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2417               throw INTERP_KERNEL::Exception(oss.str().c_str());
2418             }
2419           else
2420             { nbTuples=0; return 0; }
2421         }
2422     }
2423   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2424 }
2425
2426 /*!
2427  * if python int -> cpp int sw=1
2428  * if python list[int] -> cpp vector<int> sw=2
2429  * if python tuple[int] -> cpp vector<int> sw=2
2430  * if python DataArrayInt -> cpp DataArrayInt sw=3
2431  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2432  *
2433  * switch between (int,vector<int>,DataArrayInt)
2434  */
2435 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2436 {
2437   sw=-1;
2438   if(PyInt_Check(value))
2439     {
2440       iTyypp=(int)PyInt_AS_LONG(value);
2441       sw=1; sz=1;
2442       return &iTyypp;
2443     }
2444   if(PyTuple_Check(value))
2445     {
2446       int size=PyTuple_Size(value);
2447       stdvecTyypp.resize(size);
2448       for(int i=0;i<size;i++)
2449         {
2450           PyObject *o=PyTuple_GetItem(value,i);
2451           if(PyInt_Check(o))
2452             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2453           else
2454             {
2455               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2456               throw INTERP_KERNEL::Exception(oss.str().c_str());
2457             }
2458         }
2459       sw=2; sz=size;
2460       return &stdvecTyypp[0];
2461     }
2462   if(PyList_Check(value))
2463     {
2464       int size=PyList_Size(value);
2465       stdvecTyypp.resize(size);
2466       for(int i=0;i<size;i++)
2467         {
2468           PyObject *o=PyList_GetItem(value,i);
2469           if(PyInt_Check(o))
2470             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2471           else
2472             {
2473               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2474               throw INTERP_KERNEL::Exception(oss.str().c_str());
2475             }
2476         }
2477       sw=2; sz=size;
2478       return &stdvecTyypp[0];
2479     }
2480   void *argp;
2481   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
2482   if(SWIG_IsOK(status))
2483     {
2484       MEDCoupling::DataArrayInt *daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
2485       if(daIntTyypp)
2486         {
2487           sw=3; sz=daIntTyypp->getNbOfElems();
2488           return daIntTyypp->begin();
2489         }
2490       else
2491         {
2492           sz=0;
2493           return 0;
2494         }
2495     }
2496   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
2497   if(SWIG_IsOK(status))
2498     {  
2499       MEDCoupling::DataArrayIntTuple *daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
2500       sw=4; sz=daIntTuple->getNumberOfCompo();
2501       return daIntTuple->getConstPointer();
2502     }
2503   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2504 }
2505
2506 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2507 {
2508   void *aBasePtrVS=0;
2509   int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2510   if(!SWIG_IsOK(status))
2511     {
2512       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2513       if(!SWIG_IsOK(status))
2514         {
2515           status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
2516           if(!SWIG_IsOK(status))
2517             {
2518               status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2519               if(!SWIG_IsOK(status))
2520                 {
2521                   status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2522                   std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2523                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2524                 }
2525             }
2526         }
2527     }
2528   return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2529 }