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