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