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