Salome HOME
27a6de03ee46ace0d49c2b5e3307887ebd2154a1
[tools/medcoupling.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::MEDCouplingExtrudedMesh *>(mesh))
423     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
424   if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
425     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
426   if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
427     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
428   if(!ret)
429     throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
430   return ret;
431 }
432
433 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
434 {
435   PyObject *ret=0;
436   if(!fd)
437     {
438       Py_XINCREF(Py_None);
439       return Py_None;
440     }
441   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
442     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
443   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
444     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
445   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
446     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
447   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
448     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
449   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
450     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
451   if(!ret)
452     throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
453   return ret;
454 }
455
456 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
457 {
458   PyObject *ret=0;
459   if(!dac)
460     {
461       Py_XINCREF(Py_None);
462       return Py_None;
463     }
464   if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
465     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
466   if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
467     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
468   if(!ret)
469     throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
470   return ret;
471 }
472
473 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
474 {
475   PyObject *ret=0;
476   if(!dac)
477     {
478       Py_XINCREF(Py_None);
479       return Py_None;
480     }
481   if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
482     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
483   if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
484     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
485   if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
486     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
487   if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
488     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
489   if(!ret)
490     throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
491   return ret;
492 }
493
494 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
495 {
496   PyObject *ret=0;
497   if(!mfs)
498     {
499       Py_XINCREF(Py_None);
500       return Py_None;
501     }
502   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
503     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
504   else
505     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
506   return ret;
507 }
508
509 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
510 {
511   PyObject *ret=PyList_New(size);
512   for(int i=0;i<size;i++)
513     PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
514   return ret;
515 }
516
517 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
518 {
519   int size=v.size();
520   PyObject *ret=PyList_New(size);
521   for(int i=0;i<size;i++)
522     PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
523   return ret;
524 }
525
526 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
527 {
528   int size=v.size();
529   PyObject *ret=PyList_New(size);
530   std::set<int>::const_iterator it=v.begin();
531   for(int i=0;i<size;i++,it++)
532     PyList_SetItem(ret,i,PyInt_FromLong(*it));
533   return ret;
534 }
535
536 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
537 {
538   PyObject *ret=PyList_New(nbOfTuples);
539   for(int i=0;i<nbOfTuples;i++)
540     {
541       PyObject *t=PyTuple_New(nbOfComp);
542       for(int j=0;j<nbOfComp;j++)
543         PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
544       PyList_SetItem(ret,i,t);
545     }
546   return ret;
547 }
548
549 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
550 {
551   if(PyList_Check(pyLi))
552     {
553       *size=PyList_Size(pyLi);
554       int *tmp=new int[*size];
555       for(int i=0;i<*size;i++)
556         {
557           PyObject *o=PyList_GetItem(pyLi,i);
558           if(PyInt_Check(o))
559             {
560               int val=(int)PyInt_AS_LONG(o);
561               tmp[i]=val;
562             }
563           else
564             {
565               delete [] tmp;
566               throw INTERP_KERNEL::Exception("list must contain integers only");
567             }
568         }
569       return tmp;
570     }
571   else if(PyTuple_Check(pyLi))
572     {
573       *size=PyTuple_Size(pyLi);
574       int *tmp=new int[*size];
575       for(int i=0;i<*size;i++)
576         {
577           PyObject *o=PyTuple_GetItem(pyLi,i);
578           if(PyInt_Check(o))
579             {
580               int val=(int)PyInt_AS_LONG(o);
581               tmp[i]=val;
582             }
583           else
584             {
585               delete [] tmp;
586               throw INTERP_KERNEL::Exception("tuple must contain integers only");
587             }
588         }
589       return tmp;
590     }
591   else
592     {
593       throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
594     }
595 }
596
597 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
598 {
599   const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
600   if(PyList_Check(pyLi))
601     {
602       int size=PyList_Size(pyLi);
603       arr.resize(size);
604       for(int i=0;i<size;i++)
605         {
606           PyObject *o=PyList_GetItem(pyLi,i);
607           if(PyTuple_Check(o))
608             {
609               int sz2=PyTuple_Size(o);
610               if(sz2!=2)
611                 throw INTERP_KERNEL::Exception(msg);
612               PyObject *o_0=PyTuple_GetItem(o,0);
613               if(!PyInt_Check(o_0))
614                 throw INTERP_KERNEL::Exception(msg);
615               PyObject *o_1=PyTuple_GetItem(o,1);
616               if(!PyInt_Check(o_1))
617                 throw INTERP_KERNEL::Exception(msg);
618               arr[i].first=(int)PyInt_AS_LONG(o_0);
619               arr[i].second=(int)PyInt_AS_LONG(o_1);
620             }
621           else
622             throw INTERP_KERNEL::Exception(msg);
623         }
624     }
625   else if(PyTuple_Check(pyLi))
626     {
627       int size=PyTuple_Size(pyLi);
628       arr.resize(size);
629       for(int i=0;i<size;i++)
630         {
631           PyObject *o=PyTuple_GetItem(pyLi,i);
632           if(PyTuple_Check(o))
633             {
634               int sz2=PyTuple_Size(o);
635               if(sz2!=2)
636                 throw INTERP_KERNEL::Exception(msg);
637               PyObject *o_0=PyTuple_GetItem(o,0);
638               if(!PyInt_Check(o_0))
639                 throw INTERP_KERNEL::Exception(msg);
640               PyObject *o_1=PyTuple_GetItem(o,1);
641               if(!PyInt_Check(o_1))
642                 throw INTERP_KERNEL::Exception(msg);
643               arr[i].first=(int)PyInt_AS_LONG(o_0);
644               arr[i].second=(int)PyInt_AS_LONG(o_1);
645             }
646           else
647             throw INTERP_KERNEL::Exception(msg);
648         }
649     }
650   else
651     throw INTERP_KERNEL::Exception(msg);
652 }
653
654 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
655 {
656   if(PyList_Check(pyLi))
657     {
658       int size=PyList_Size(pyLi);
659       arr.resize(size);
660       for(int i=0;i<size;i++)
661         {
662           PyObject *o=PyList_GetItem(pyLi,i);
663           if(PyInt_Check(o))
664             {
665               int val=(int)PyInt_AS_LONG(o);
666               arr[i]=val;
667             }
668           else
669             throw INTERP_KERNEL::Exception("list must contain integers only");
670         }
671     }
672   else if(PyTuple_Check(pyLi))
673     {
674       int size=PyTuple_Size(pyLi);
675       arr.resize(size);
676       for(int i=0;i<size;i++)
677         {
678           PyObject *o=PyTuple_GetItem(pyLi,i);
679           if(PyInt_Check(o))
680             {
681               int val=(int)PyInt_AS_LONG(o);
682               arr[i]=val;
683             }
684           else
685             throw INTERP_KERNEL::Exception("tuple must contain integers only");
686         }
687     }
688   else
689     {
690       throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
691     }
692 }
693
694 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
695 {
696   if(recurseLev<0)
697     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
698   arr.clear();
699   if(PyList_Check(pyLi))
700     {
701       int size=PyList_Size(pyLi);
702       for(int i=0;i<size;i++)
703         {
704           PyObject *o=PyList_GetItem(pyLi,i);
705           if(PyInt_Check(o))
706             {
707               int val=(int)PyInt_AS_LONG(o);
708               arr.push_back(val);
709             }
710           else
711             {
712               std::vector<int> arr2;
713               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
714               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
715                   {
716                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
717                     throw INTERP_KERNEL::Exception(oss.str().c_str());
718                   }
719               arr.insert(arr.end(),arr2.begin(),arr2.end());
720             }
721         }
722     }
723   else if(PyTuple_Check(pyLi))
724     {
725       int size=PyTuple_Size(pyLi);
726       for(int i=0;i<size;i++)
727         {
728           PyObject *o=PyTuple_GetItem(pyLi,i);
729           if(PyInt_Check(o))
730             {
731               int val=(int)PyInt_AS_LONG(o);
732               arr.push_back(val);
733             }
734           else
735             {
736               std::vector<int> arr2;
737               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
738               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
739                   {
740                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
741                     throw INTERP_KERNEL::Exception(oss.str().c_str());
742                   }
743               arr.insert(arr.end(),arr2.begin(),arr2.end());
744             }
745         }
746     }
747   else
748     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
749 }
750
751 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
752 {
753   if(nbOfTuples==-1)
754     {
755       if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
756       else { if(nbOfComp==size2) { nbOfTuples=size1; } else
757           {
758             std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
759             oss << " whereas nb of components expected is " << nbOfComp << " !";
760             throw INTERP_KERNEL::Exception(oss.str().c_str());
761           } }
762     }
763   else
764     {
765       if(nbOfComp!=-1)
766         {
767           if((nbOfTuples!=size1 || nbOfComp!=size2))
768             {
769               if(size2!=1 || size1!=nbOfComp*nbOfTuples)
770                 {
771                   std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
772                   oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
773                   throw INTERP_KERNEL::Exception(oss.str().c_str());
774                 }
775             }
776         }
777       else
778         {
779           if(nbOfTuples==size1)
780             nbOfComp=size2;
781           else
782             {
783               std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
784               oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
785               throw INTERP_KERNEL::Exception(oss.str().c_str());
786             }
787         }
788     }
789 }
790
791 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
792 {
793   static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
794   if(PyInt_Check(pyLi))
795     {
796       long val=PyInt_AS_LONG(pyLi);
797       if(nbOfElt==-1)
798         nbOfElt=1;
799       else
800         if(nbOfElt!=1)
801           throw INTERP_KERNEL::Exception(MSG);
802       ret.push_back(val);
803     }
804   else if(PyList_Check(pyLi))
805     {
806       int size=PyList_Size(pyLi);
807       int tmp=0;
808       for(int i=0;i<size;i++)
809         {
810           PyObject *o=PyList_GetItem(pyLi,i);
811           int tmp1=-1;
812           fillArrayWithPyListInt3(o,tmp1,ret);
813           tmp+=tmp1;
814         }
815       if(nbOfElt==-1)
816         nbOfElt=tmp;
817       else
818         {
819           if(nbOfElt!=tmp)
820             throw INTERP_KERNEL::Exception(MSG);
821         }
822     }
823   else if(PyTuple_Check(pyLi))
824     {
825       int size=PyTuple_Size(pyLi);
826       int tmp=0;
827       for(int i=0;i<size;i++)
828         {
829           PyObject *o=PyTuple_GetItem(pyLi,i);
830           int tmp1=-1;
831           fillArrayWithPyListInt3(o,tmp1,ret);
832           tmp+=tmp1;
833         }
834       if(nbOfElt==-1)
835         nbOfElt=tmp;
836       else
837         {
838           if(nbOfElt!=tmp)
839             throw INTERP_KERNEL::Exception(MSG);
840         }
841     }
842   else
843     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
844 }
845
846 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
847 {
848   std::vector<int> ret;
849   int size1=-1,size2=-1;
850   if(PyList_Check(pyLi))
851     {
852       size1=PyList_Size(pyLi);
853       for(int i=0;i<size1;i++)
854         {
855           PyObject *o=PyList_GetItem(pyLi,i);
856           fillArrayWithPyListInt3(o,size2,ret);
857         }
858       if(size1==0)
859         size2=1;
860     }
861   else if(PyTuple_Check(pyLi))
862     {
863       size1=PyTuple_Size(pyLi);
864       for(int i=0;i<size1;i++)
865         {
866           PyObject *o=PyTuple_GetItem(pyLi,i);
867           fillArrayWithPyListInt3(o,size2,ret);
868         }
869       if(size1==0)
870         size2=1;
871     }
872   else
873     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
874   //
875   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
876   return ret;
877 }
878
879 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
880 {
881   if(PyList_Check(pyLi))
882     {
883       Py_ssize_t sz=PyList_Size(pyLi);
884       vec.resize(sz);
885       for(int i=0;i<sz;i++)
886         {
887           PyObject *o=PyList_GetItem(pyLi,i);
888           if(PyString_Check(o))
889             vec[i]=PyString_AsString(o);
890           else
891             return false;
892         }
893       return true;
894     }
895   else if(PyTuple_Check(pyLi))
896     {
897       Py_ssize_t sz=PyTuple_Size(pyLi);
898       vec.resize(sz);
899       for(int i=0;i<sz;i++)
900         {
901           PyObject *o=PyTuple_GetItem(pyLi,i);
902           if(PyString_Check(o))
903             vec[i]=PyString_AsString(o);
904           else
905             return false;
906         }
907       return true;
908     }
909   else
910     return false;
911 }
912
913 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
914 {
915   PyObject *ret=PyList_New(size);
916   for(int i=0;i<size;i++)
917     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
918   return ret;
919 }
920
921 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
922 {
923   int size=v.size();
924   PyObject *ret=PyList_New(size);
925   for(int i=0;i<size;i++)
926     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
927   return ret;
928 }
929
930 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
931 {
932   PyObject *ret=PyList_New(nbOfTuples);
933   for(int i=0;i<nbOfTuples;i++)
934     {
935       PyObject *t=PyTuple_New(nbOfComp);
936       for(int j=0;j<nbOfComp;j++)
937         PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
938       PyList_SetItem(ret,i,t);
939     }
940   return ret;
941 }
942
943 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
944 {
945   PyObject *ret=PyList_New(nbOfTuples);
946   INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
947   for(int i=0;i<nbOfTuples;i++)
948     {
949       std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
950       PyList_SetItem(ret,i,PyString_FromString(tmp));
951     }
952   return ret;
953 }
954
955 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
956 {
957   if(PyList_Check(pyLi))
958     {
959       *size=PyList_Size(pyLi);
960       double *tmp=(double *)malloc((*size)*sizeof(double));
961       for(int i=0;i<*size;i++)
962         {
963           PyObject *o=PyList_GetItem(pyLi,i);
964           if(PyFloat_Check(o))
965             {
966               double val=PyFloat_AS_DOUBLE(o);
967               tmp[i]=val;
968             }
969           else if(PyInt_Check(o))
970             {
971               long val0=PyInt_AS_LONG(o);
972               double val=val0;
973               tmp[i]=val;
974             }
975           else
976             {
977               free(tmp);
978               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
979             }
980         }
981       return tmp;
982     }
983   else if(PyTuple_Check(pyLi))
984     {
985       *size=PyTuple_Size(pyLi);
986       double *tmp=(double *)malloc((*size)*sizeof(double));
987       for(int i=0;i<*size;i++)
988         {
989           PyObject *o=PyTuple_GetItem(pyLi,i);
990           if(PyFloat_Check(o))
991             {
992               double val=PyFloat_AS_DOUBLE(o);
993               tmp[i]=val;
994             }
995           else if(PyInt_Check(o))
996             {
997               long val0=PyInt_AS_LONG(o);
998               double val=val0;
999               tmp[i]=val;
1000             }
1001           else
1002             {
1003               free(tmp);
1004               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1005             }
1006         }
1007       return tmp;
1008     }
1009   else
1010     throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1011 }
1012
1013 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1014 {
1015   static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1016   if(PyFloat_Check(pyLi))
1017     {
1018       if(nbOfElt==-1)
1019         nbOfElt=1;
1020       else
1021         if(nbOfElt!=1)
1022           throw INTERP_KERNEL::Exception(MSG);
1023       double val=PyFloat_AS_DOUBLE(pyLi);
1024       ret.push_back(val);
1025     }
1026   else if(PyInt_Check(pyLi))
1027     {
1028       long val0=PyInt_AS_LONG(pyLi);
1029       double val=val0;
1030       if(nbOfElt==-1)
1031         nbOfElt=1;
1032       else
1033         if(nbOfElt!=1)
1034           throw INTERP_KERNEL::Exception(MSG);
1035       ret.push_back(val);
1036     }
1037   else if(PyList_Check(pyLi))
1038     {
1039       int size=PyList_Size(pyLi);
1040       int tmp=0;
1041       for(int i=0;i<size;i++)
1042         {
1043           PyObject *o=PyList_GetItem(pyLi,i);
1044           int tmp1=-1;
1045           fillArrayWithPyListDbl3(o,tmp1,ret);
1046           tmp+=tmp1;
1047         }
1048       if(nbOfElt==-1)
1049         nbOfElt=tmp;
1050       else
1051         {
1052           if(nbOfElt!=tmp)
1053             throw INTERP_KERNEL::Exception(MSG);
1054         }
1055     }
1056   else if(PyTuple_Check(pyLi))
1057     {
1058       int size=PyTuple_Size(pyLi);
1059       int tmp=0;
1060       for(int i=0;i<size;i++)
1061         {
1062           PyObject *o=PyTuple_GetItem(pyLi,i);
1063           int tmp1=-1;
1064           fillArrayWithPyListDbl3(o,tmp1,ret);
1065           tmp+=tmp1;
1066         }
1067       if(nbOfElt==-1)
1068         nbOfElt=tmp;
1069       else
1070         {
1071           if(nbOfElt!=tmp)
1072             throw INTERP_KERNEL::Exception(MSG);
1073         }
1074     }
1075   else
1076     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1077 }
1078
1079 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1080 {
1081   std::vector<double> ret;
1082   int size1=-1,size2=-1;
1083   if(PyList_Check(pyLi))
1084     {
1085       size1=PyList_Size(pyLi);
1086       for(int i=0;i<size1;i++)
1087         {
1088           PyObject *o=PyList_GetItem(pyLi,i);
1089           fillArrayWithPyListDbl3(o,size2,ret);
1090         }
1091       if(size1==0)
1092         size2=1;
1093     }
1094   else if(PyTuple_Check(pyLi))
1095     {
1096       size1=PyTuple_Size(pyLi);
1097       for(int i=0;i<size1;i++)
1098         {
1099           PyObject *o=PyTuple_GetItem(pyLi,i);
1100           fillArrayWithPyListDbl3(o,size2,ret);
1101         }
1102       if(size1==0)
1103         size2=1;
1104     }
1105   else
1106     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1107   //
1108   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1109   return ret;
1110 }
1111
1112 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1113 template<class T>
1114 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1115 {
1116   void *argp=0;
1117   if(PyList_Check(pyLi))
1118     {
1119       int size=PyList_Size(pyLi);
1120       ret.resize(size);
1121       for(int i=0;i<size;i++)
1122         {
1123           PyObject *obj=PyList_GetItem(pyLi,i);
1124           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1125           if(!SWIG_IsOK(status))
1126             throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
1127           T arg=reinterpret_cast< T >(argp);
1128           ret[i]=arg;
1129         }
1130     }
1131   else if(PyTuple_Check(pyLi))
1132     {
1133       int size=PyTuple_Size(pyLi);
1134       ret.resize(size);
1135       for(int i=0;i<size;i++)
1136         {
1137           PyObject *obj=PyTuple_GetItem(pyLi,i);
1138           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1139           if(!SWIG_IsOK(status))
1140             {
1141               std::ostringstream oss; oss << "tuple must contain only " << typeStr;
1142               throw INTERP_KERNEL::Exception(oss.str().c_str());
1143             }
1144           T arg=reinterpret_cast< T >(argp);
1145           ret[i]=arg;
1146         }
1147     }
1148   else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1149     {
1150       ret.resize(1);
1151       T arg=reinterpret_cast< T >(argp);
1152       ret[0]=arg;
1153     }
1154   else
1155     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1156 }
1157
1158 /*!
1159  * if python int -> cpp int sw=1
1160  * if python list[int] -> cpp vector<int> sw=2
1161  * if python tuple[int] -> cpp vector<int> sw=2
1162  * if python DataArrayInt -> cpp DataArrayInt sw=3
1163  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1164  *
1165  * switch between (int,vector<int>,DataArrayInt)
1166  */
1167 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1168 {
1169   sw=-1;
1170   if(PyInt_Check(value))
1171     {
1172       iTyypp=(int)PyInt_AS_LONG(value);
1173       sw=1;
1174       return;
1175     }
1176   if(PyTuple_Check(value))
1177     {
1178       int size=PyTuple_Size(value);
1179       stdvecTyypp.resize(size);
1180       for(int i=0;i<size;i++)
1181         {
1182           PyObject *o=PyTuple_GetItem(value,i);
1183           if(PyInt_Check(o))
1184             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1185           else
1186             {
1187               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1188               throw INTERP_KERNEL::Exception(oss.str().c_str());
1189             }
1190         }
1191       sw=2;
1192       return;
1193     }
1194   if(PyList_Check(value))
1195     {
1196       int size=PyList_Size(value);
1197       stdvecTyypp.resize(size);
1198       for(int i=0;i<size;i++)
1199         {
1200           PyObject *o=PyList_GetItem(value,i);
1201           if(PyInt_Check(o))
1202             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1203           else
1204             {
1205               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1206               throw INTERP_KERNEL::Exception(oss.str().c_str());
1207             }
1208         }
1209       sw=2;
1210       return;
1211     }
1212   void *argp;
1213   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1214   if(SWIG_IsOK(status))
1215     {
1216       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1217       sw=3;
1218       return;
1219     }
1220   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1221   if(SWIG_IsOK(status))
1222     {  
1223       daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1224       sw=4;
1225       return ;
1226     }
1227   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1228 }
1229
1230 /*!
1231  * if python double -> cpp double sw=1
1232  * if python int -> cpp double sw=1
1233  * if python list[double] -> cpp vector<double> sw=2
1234  * if python list[int] -> cpp vector<double> sw=2
1235  * if python tuple[double] -> cpp vector<double> sw=2
1236  * if python tuple[int] -> cpp vector<double> sw=2
1237  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1238  *
1239  * switch between (int,vector<int>,DataArrayInt)
1240  */
1241 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1242 {
1243   sw=-1;
1244   if(PyFloat_Check(value))
1245     {
1246       iTyypp=PyFloat_AS_DOUBLE(value);
1247       sw=1;
1248       return;
1249     }
1250   if(PyInt_Check(value))
1251     {
1252       iTyypp=(double)PyInt_AS_LONG(value);
1253       sw=1;
1254       return;
1255     }
1256   if(PyTuple_Check(value))
1257     {
1258       int size=PyTuple_Size(value);
1259       stdvecTyypp.resize(size);
1260       for(int i=0;i<size;i++)
1261         {
1262           PyObject *o=PyTuple_GetItem(value,i);
1263           if(PyFloat_Check(o))
1264             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1265           else if(PyInt_Check(o))
1266             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1267           else
1268             {
1269               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1270               throw INTERP_KERNEL::Exception(oss.str().c_str());
1271             }
1272         }
1273       sw=2;
1274       return;
1275     }
1276   if(PyList_Check(value))
1277     {
1278       int size=PyList_Size(value);
1279       stdvecTyypp.resize(size);
1280       for(int i=0;i<size;i++)
1281         {
1282           PyObject *o=PyList_GetItem(value,i);
1283           if(PyFloat_Check(o))
1284             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1285           else if(PyInt_Check(o))
1286             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1287           else
1288             {
1289               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1290               throw INTERP_KERNEL::Exception(oss.str().c_str());
1291             }
1292         }
1293       sw=2;
1294       return;
1295     }
1296   void *argp;
1297   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1298   if(!SWIG_IsOK(status))
1299     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1300   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1301   sw=3;
1302 }
1303
1304 /*!
1305  * if python double -> cpp double sw=1
1306  * if python int -> cpp double sw=1
1307  * if python list[double] -> cpp vector<double> sw=2
1308  * if python list[int] -> cpp vector<double> sw=2
1309  * if python tuple[double] -> cpp vector<double> sw=2
1310  * if python tuple[int] -> cpp vector<double> sw=2
1311  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1312  *
1313  * switch between (int,vector<int>,DataArrayInt)
1314  */
1315 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1316 {
1317   sw=-1;
1318   if(PyFloat_Check(value))
1319     {
1320       iTyypp=PyFloat_AS_DOUBLE(value);
1321       sw=1;
1322       return;
1323     }
1324   if(PyInt_Check(value))
1325     {
1326       iTyypp=(double)PyInt_AS_LONG(value);
1327       sw=1;
1328       return;
1329     }
1330   if(PyTuple_Check(value))
1331     {
1332       int size=PyTuple_Size(value);
1333       stdvecTyypp.resize(size);
1334       for(int i=0;i<size;i++)
1335         {
1336           PyObject *o=PyTuple_GetItem(value,i);
1337           if(PyFloat_Check(o))
1338             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1339           else if(PyInt_Check(o))
1340             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1341           else
1342             {
1343               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1344               throw INTERP_KERNEL::Exception(oss.str().c_str());
1345             }
1346         }
1347       sw=2;
1348       return;
1349     }
1350   if(PyList_Check(value))
1351     {
1352       int size=PyList_Size(value);
1353       stdvecTyypp.resize(size);
1354       for(int i=0;i<size;i++)
1355         {
1356           PyObject *o=PyList_GetItem(value,i);
1357           if(PyFloat_Check(o))
1358             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1359           else if(PyInt_Check(o))
1360             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1361           else
1362             {
1363               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1364               throw INTERP_KERNEL::Exception(oss.str().c_str());
1365             }
1366         }
1367       sw=2;
1368       return;
1369     }
1370   void *argp;
1371   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1372   if(!SWIG_IsOK(status))
1373     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1374   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1375   sw=3;
1376 }
1377
1378 /*!
1379  * if python int -> cpp int sw=1
1380  * if python list[int] -> cpp vector<int> sw=2
1381  * if python tuple[int] -> cpp vector<int> sw=2
1382  * if python slicp -> cpp pair sw=3 (begin,end,step)
1383  * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1384  *
1385  * switch between (int,vector<int>,DataArrayInt)
1386  */
1387 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)
1388 {
1389   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1390   sw=-1;
1391   if(PyInt_Check(value))
1392     {
1393       iTyypp=(int)PyInt_AS_LONG(value);
1394       sw=1;
1395       return;
1396     }
1397   if(PyTuple_Check(value))
1398     {
1399       int size=PyTuple_Size(value);
1400       stdvecTyypp.resize(size);
1401       for(int i=0;i<size;i++)
1402         {
1403           PyObject *o=PyTuple_GetItem(value,i);
1404           if(PyInt_Check(o))
1405             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1406           else
1407             {
1408               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1409               throw INTERP_KERNEL::Exception(oss.str().c_str());
1410             }
1411         }
1412       sw=2;
1413       return;
1414     }
1415   if(PyList_Check(value))
1416     {
1417       int size=PyList_Size(value);
1418       stdvecTyypp.resize(size);
1419       for(int i=0;i<size;i++)
1420         {
1421           PyObject *o=PyList_GetItem(value,i);
1422           if(PyInt_Check(o))
1423             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1424           else
1425             {
1426               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1427               throw INTERP_KERNEL::Exception(oss.str().c_str());
1428             }
1429         }
1430       sw=2;
1431       return;
1432     }
1433   if(PySlice_Check(value))
1434     {
1435       Py_ssize_t strt=2,stp=2,step=2;
1436       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1437       if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1438         if(nbelem!=0 || strt!=0 || stp!=0)
1439           {
1440             std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1441             throw INTERP_KERNEL::Exception(oss.str().c_str());
1442           }
1443       p.first=strt;
1444       p.second.first=stp;
1445       p.second.second=step;
1446       sw=3;
1447       return ;
1448     }
1449   void *argp;
1450   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1451   if(SWIG_IsOK(status))
1452     {
1453       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1454       if(!daIntTyypp)
1455         {
1456           std::ostringstream oss; oss << msg << " Instance in null !";
1457           throw INTERP_KERNEL::Exception(oss.str().c_str());
1458         }
1459       sw=4;
1460       return ;
1461     }
1462   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1463   if(SWIG_IsOK(status))
1464     {
1465       ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1466       if(!tmp)
1467         {
1468           std::ostringstream oss; oss << msg << " Instance in null !";
1469           throw INTERP_KERNEL::Exception(oss.str().c_str());
1470         }
1471       stdvecTyypp.resize(tmp->getNumberOfCompo());
1472       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1473       sw=2;
1474       return ;
1475     }
1476   throw INTERP_KERNEL::Exception(msg);
1477 }
1478
1479 /*!
1480  * if python int -> cpp int sw=1
1481  * if python tuple[int] -> cpp vector<int> sw=2
1482  * if python list[int] -> cpp vector<int> sw=2
1483  * if python slice -> cpp pair sw=3
1484  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1485  */
1486 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)
1487 {
1488   sw=-1;
1489   if(PyInt_Check(value))
1490     {
1491       iTyypp=(int)PyInt_AS_LONG(value);
1492       sw=1;
1493       return;
1494     }
1495   if(PyTuple_Check(value))
1496     {
1497       int size=PyTuple_Size(value);
1498       stdvecTyypp.resize(size);
1499       for(int i=0;i<size;i++)
1500         {
1501           PyObject *o=PyTuple_GetItem(value,i);
1502           if(PyInt_Check(o))
1503             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1504           else
1505             {
1506               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1507               throw INTERP_KERNEL::Exception(oss.str().c_str());
1508             }
1509         }
1510       sw=2;
1511       return;
1512     }
1513   if(PyList_Check(value))
1514     {
1515       int size=PyList_Size(value);
1516       stdvecTyypp.resize(size);
1517       for(int i=0;i<size;i++)
1518         {
1519           PyObject *o=PyList_GetItem(value,i);
1520           if(PyInt_Check(o))
1521             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1522           else
1523             {
1524               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1525               throw INTERP_KERNEL::Exception(oss.str().c_str());
1526             }
1527         }
1528       sw=2;
1529       return;
1530     }
1531   if(PySlice_Check(value))
1532     {
1533       Py_ssize_t strt=2,stp=2,step=2;
1534       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1535       if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1536         if(nbelem!=0 || strt!=0 || stp!=0)
1537           {
1538             std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1539             throw INTERP_KERNEL::Exception(oss.str().c_str());
1540           }
1541       p.first=strt;
1542       p.second.first=stp;
1543       p.second.second=step;
1544       sw=3;
1545       return ;
1546     }
1547   void *argp;
1548   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1549   if(!SWIG_IsOK(status))
1550     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1551   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1552   sw=4;
1553 }
1554
1555 /*!
1556  * if python string with size one -> cpp char sw=1
1557  * if python string with size different from one -> cpp string sw=2
1558  * if python tuple[string] or list[string] -> vector<string> sw=3
1559  * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1560  * switch between (int,string,vector<string>,DataArrayChar)
1561  */
1562 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1563 {
1564   const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1565   sw=-1;
1566   if(PyString_Check(value))
1567     {
1568       const char *pt=PyString_AsString(value);
1569       Py_ssize_t sz=PyString_Size(value);
1570       if(sz==1)
1571         {
1572           cTyp=pt[0];
1573           sw=1;
1574           return;
1575         }
1576       else
1577         {
1578           sType=pt;
1579           sw=2;
1580           return;
1581         }
1582     }
1583   if(PyTuple_Check(value))
1584     {
1585       int size=PyTuple_Size(value);
1586       vsType.resize(size);
1587       for(int i=0;i<size;i++)
1588         {
1589           PyObject *o=PyTuple_GetItem(value,i);
1590           if(PyString_Check(o))
1591             vsType[i]=PyString_AsString(o);
1592           else
1593             {
1594               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1595               throw INTERP_KERNEL::Exception(oss.str().c_str());
1596             }
1597         }
1598       sw=3;
1599       return;
1600     }
1601   if(PyList_Check(value))
1602     {
1603       int size=PyList_Size(value);
1604       vsType.resize(size);
1605       for(int i=0;i<size;i++)
1606         {
1607           PyObject *o=PyList_GetItem(value,i);
1608           if(PyString_Check(o))
1609             vsType[i]=PyString_AsString(o);
1610           else
1611             {
1612               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1613               throw INTERP_KERNEL::Exception(oss.str().c_str());
1614             }
1615         }
1616       sw=3;
1617       return;
1618     }
1619   void *argp;
1620   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1621   if(SWIG_IsOK(status))
1622     {
1623       dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1624       if(!dacType)
1625         {
1626           std::ostringstream oss; oss << msg << " Instance in null !";
1627           throw INTERP_KERNEL::Exception(oss.str().c_str());
1628         }
1629       sw=4;
1630       return ;
1631     }
1632   throw INTERP_KERNEL::Exception(msg);
1633 }
1634
1635 /*!
1636  * if value int -> cpp it sw=1
1637  * if value list[int] -> vt sw=2
1638  * if value tuple[int] -> vt sw=2
1639  * if value slice -> pt sw=3
1640  * if value DataArrayInt -> dt sw=4
1641  * if value tuple [int,int] -> cpp it,ip sw=5
1642  * if value tuple [list[int],int] -> cpp vt,ip sw=6
1643  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1644  * if value tuple [slice,int] -> cpp pt,ip sw=7
1645  * if value tuple [DaI,int] -> cpp dt,ip sw=8
1646  * if value tuple [int,list[int]] -> cpp it,vc sw=9
1647  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1648  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1649  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1650  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1651  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1652  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1653  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1654  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1655  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1656  * if value tuple [int,slice] -> cpp it,pc sw=13
1657  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1658  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1659  * if value tuple [slice,slice] -> cpp pt,pc sw=15
1660  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1661  *
1662  * switch between (int,vector<int>,DataArrayInt)
1663  */
1664 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1665                                      std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1666                                      ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1667 {
1668   if(!PyTuple_Check(value))
1669     {
1670       convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1671       return ;
1672     }
1673   else
1674     {
1675       int sz=PyTuple_Size(value);
1676       if(sz!=2)
1677         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1678       PyObject *ob0=PyTuple_GetItem(value,0);
1679       int sw1,sw2;
1680       convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1681       PyObject *ob1=PyTuple_GetItem(value,1);
1682       convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1683       sw=4*sw2+sw1;
1684     }
1685 }
1686
1687 /*!
1688  * if value int -> cpp val sw=1
1689  * if value double -> cpp val sw=1
1690  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1691  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1692  * if value list[int,double] -> cpp std::vector<double> sw=4
1693  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1694  */
1695 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1696 {
1697   sw=-1;
1698   if(PyFloat_Check(value))
1699     {
1700       val=PyFloat_AS_DOUBLE(value);
1701       sw=1;
1702       return;
1703     }
1704   if(PyInt_Check(value))
1705     {
1706       val=(double)PyInt_AS_LONG(value);
1707       sw=1;
1708       return;
1709     }
1710   if(PyTuple_Check(value))
1711     {
1712       int size=PyTuple_Size(value);
1713       f.resize(size);
1714       for(int i=0;i<size;i++)
1715         {
1716           PyObject *o=PyTuple_GetItem(value,i);
1717           if(PyFloat_Check(o))
1718             f[i]=PyFloat_AS_DOUBLE(o);
1719           else if(PyInt_Check(o))
1720             f[i]=(double)PyInt_AS_LONG(o);
1721           else
1722             {
1723               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1724               throw INTERP_KERNEL::Exception(oss.str().c_str());
1725             }
1726         }
1727       sw=4;
1728       return;
1729     }
1730   if(PyList_Check(value))
1731     {
1732       int size=PyList_Size(value);
1733       f.resize(size);
1734       for(int i=0;i<size;i++)
1735         {
1736           PyObject *o=PyList_GetItem(value,i);
1737           if(PyFloat_Check(o))
1738             f[i]=PyFloat_AS_DOUBLE(o);
1739           else if(PyInt_Check(o))
1740             f[i]=(double)PyInt_AS_LONG(o);
1741           else
1742             {
1743               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1744               throw INTERP_KERNEL::Exception(oss.str().c_str());
1745             }
1746         }
1747       sw=4;
1748       return;
1749     }
1750   void *argp;
1751   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1752   if(SWIG_IsOK(status))
1753     {  
1754       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1755       sw=2;
1756       return ;
1757     }
1758   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1759   if(SWIG_IsOK(status))
1760     {  
1761       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1762       sw=3;
1763       return ;
1764     }
1765   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1766 }
1767
1768 /*!
1769  * if value int -> cpp val sw=1
1770  * if value double -> cpp val sw=1
1771  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1772  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1773  * if value list[int,double] -> cpp std::vector<double> sw=4
1774  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1775  */
1776 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1777                                                    const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1778 {
1779   sw=-1;
1780   if(PyFloat_Check(value))
1781     {
1782       val=PyFloat_AS_DOUBLE(value);
1783       sw=1;
1784       if(nbTuplesExpected*nbCompExpected!=1)
1785         {
1786           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1787           throw INTERP_KERNEL::Exception(oss.str().c_str());
1788         }
1789       return &val;
1790     }
1791   if(PyInt_Check(value))
1792     {
1793       val=(double)PyInt_AS_LONG(value);
1794       sw=1;
1795       if(nbTuplesExpected*nbCompExpected!=1)
1796         {
1797           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1798           throw INTERP_KERNEL::Exception(oss.str().c_str());
1799         }
1800       return &val;
1801     }
1802   if(PyTuple_Check(value) || PyList_Check(value))
1803     {
1804       try
1805         {
1806           int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1807           std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1808           sw=4;
1809           f=ret;
1810           return &f[0];
1811         }
1812       catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1813     }
1814   void *argp;
1815   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1816   if(SWIG_IsOK(status))
1817     {  
1818       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1819       sw=2;
1820       if(d)
1821         {
1822           if(d->getNumberOfTuples()==nbTuplesExpected)
1823             {
1824               if(d->getNumberOfComponents()==nbCompExpected)
1825                 {
1826                   return d->getConstPointer();
1827                 }
1828               else
1829                 {
1830                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1831                   throw INTERP_KERNEL::Exception(oss.str().c_str());
1832                 }
1833             }
1834           else
1835             {
1836               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1837               throw INTERP_KERNEL::Exception(oss.str().c_str());
1838             }
1839         }
1840       else
1841         {
1842           if(throwIfNullPt)
1843             {
1844               std::ostringstream oss; oss << msg << " null pointer not accepted!";
1845               throw INTERP_KERNEL::Exception(oss.str().c_str());
1846             }
1847           else
1848             return 0;
1849         }
1850     }
1851   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1852   if(SWIG_IsOK(status))
1853     {  
1854       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1855       sw=3;
1856       if(e->getNumberOfCompo()==nbCompExpected)
1857         {
1858           if(nbTuplesExpected==1)
1859             return e->getConstPointer();
1860           else
1861             {
1862               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1863               throw INTERP_KERNEL::Exception(oss.str().c_str());
1864             }
1865         }
1866       else
1867         {
1868           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1869           throw INTERP_KERNEL::Exception(oss.str().c_str());
1870         }
1871     }
1872   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1873 }
1874
1875 /*!
1876  * if value int -> cpp val sw=1
1877  * if value double -> cpp val sw=1
1878  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1879  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1880  * if value list[int,double] -> cpp std::vector<double> sw=4
1881  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1882  */
1883 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1884                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1885 {
1886   sw=-1;
1887   if(PyFloat_Check(value))
1888     {
1889       val=PyFloat_AS_DOUBLE(value);
1890       sw=1;
1891       if(nbCompExpected!=1)
1892         {
1893           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1894           throw INTERP_KERNEL::Exception(oss.str().c_str());
1895         }
1896       nbTuples=1;
1897       return &val;
1898     }
1899   if(PyInt_Check(value))
1900     {
1901       val=(double)PyInt_AS_LONG(value);
1902       sw=1;
1903       if(nbCompExpected!=1)
1904         {
1905           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1906           throw INTERP_KERNEL::Exception(oss.str().c_str());
1907         }
1908       nbTuples=1;
1909       return &val;
1910     }
1911   if(PyTuple_Check(value))
1912     {
1913       int size=PyTuple_Size(value);
1914       f.resize(size);
1915       for(int i=0;i<size;i++)
1916         {
1917           PyObject *o=PyTuple_GetItem(value,i);
1918           if(PyFloat_Check(o))
1919             f[i]=PyFloat_AS_DOUBLE(o);
1920           else if(PyInt_Check(o))
1921             f[i]=(double)PyInt_AS_LONG(o);
1922           else
1923             {
1924               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1925               throw INTERP_KERNEL::Exception(oss.str().c_str());
1926             }
1927         }
1928       sw=4;
1929       if(size%nbCompExpected!=0)
1930         {
1931           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1932           throw INTERP_KERNEL::Exception(oss.str().c_str());
1933         }
1934       nbTuples=size/nbCompExpected;
1935       return &f[0];
1936     }
1937   if(PyList_Check(value))
1938     {
1939       int size=PyList_Size(value);
1940       f.resize(size);
1941       for(int i=0;i<size;i++)
1942         {
1943           PyObject *o=PyList_GetItem(value,i);
1944           if(PyFloat_Check(o))
1945             f[i]=PyFloat_AS_DOUBLE(o);
1946           else if(PyInt_Check(o))
1947             f[i]=(double)PyInt_AS_LONG(o);
1948           else
1949             {
1950               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1951               throw INTERP_KERNEL::Exception(oss.str().c_str());
1952             }
1953         }
1954       sw=4;
1955       if(size%nbCompExpected!=0)
1956         {
1957           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1958           throw INTERP_KERNEL::Exception(oss.str().c_str());
1959         }
1960       nbTuples=size/nbCompExpected;
1961       return &f[0];
1962     }
1963   void *argp;
1964   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1965   if(SWIG_IsOK(status))
1966     {  
1967       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1968       sw=2;
1969       if(d)
1970         {
1971           if(d->getNumberOfComponents()==nbCompExpected)
1972             {
1973               nbTuples=d->getNumberOfTuples();
1974               return d->getConstPointer();
1975             }
1976           else
1977             {
1978               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1979               throw INTERP_KERNEL::Exception(oss.str().c_str());
1980             }
1981         }
1982       else
1983         {
1984           if(throwIfNullPt)
1985             {
1986               std::ostringstream oss; oss << msg << " null pointer not accepted!";
1987               throw INTERP_KERNEL::Exception(oss.str().c_str());
1988             }
1989           else
1990             { nbTuples=0; return 0; }
1991         }
1992     }
1993   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1994   if(SWIG_IsOK(status))
1995     {  
1996       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1997       sw=3;
1998       if(e)
1999         {
2000           if(e->getNumberOfCompo()==nbCompExpected)
2001             {
2002               nbTuples=1;
2003               return e->getConstPointer();
2004             }
2005           else
2006             {
2007               std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2008               throw INTERP_KERNEL::Exception(oss.str().c_str());
2009             }
2010         }
2011       else
2012         {
2013           if(throwIfNullPt)
2014             {
2015               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2016               throw INTERP_KERNEL::Exception(oss.str().c_str());
2017             }
2018           else
2019             { nbTuples=0; return 0; }
2020         }
2021     }
2022   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2023 }
2024
2025 /*!
2026  * if value int -> cpp val sw=1
2027  * if value double -> cpp val sw=1
2028  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2029  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2030  * if value list[int,double] -> cpp std::vector<double> sw=4
2031  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2032  */
2033 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2034                                                           const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2035 {
2036   ParaMEDMEM::DataArrayDouble *d=0;
2037   ParaMEDMEM::DataArrayDoubleTuple *e=0;
2038   sw=-1;
2039   if(PyFloat_Check(value))
2040     {
2041       val=PyFloat_AS_DOUBLE(value);
2042       sw=1;
2043       nbTuples=1;
2044       return &val;
2045     }
2046   if(PyInt_Check(value))
2047     {
2048       val=(double)PyInt_AS_LONG(value);
2049       sw=1;
2050       nbTuples=1;
2051       return &val;
2052     }
2053   if(PyTuple_Check(value))
2054     {
2055       int size=PyTuple_Size(value);
2056       f.resize(size);
2057       for(int i=0;i<size;i++)
2058         {
2059           PyObject *o=PyTuple_GetItem(value,i);
2060           if(PyFloat_Check(o))
2061             f[i]=PyFloat_AS_DOUBLE(o);
2062           else if(PyInt_Check(o))
2063             f[i]=(double)PyInt_AS_LONG(o);
2064           else
2065             {
2066               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2067               throw INTERP_KERNEL::Exception(oss.str().c_str());
2068             }
2069         }
2070       sw=4;
2071       nbTuples=size;
2072       return &f[0];
2073     }
2074   if(PyList_Check(value))
2075     {
2076       int size=PyList_Size(value);
2077       f.resize(size);
2078       for(int i=0;i<size;i++)
2079         {
2080           PyObject *o=PyList_GetItem(value,i);
2081           if(PyFloat_Check(o))
2082             f[i]=PyFloat_AS_DOUBLE(o);
2083           else if(PyInt_Check(o))
2084             f[i]=(double)PyInt_AS_LONG(o);
2085           else
2086             {
2087               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2088               throw INTERP_KERNEL::Exception(oss.str().c_str());
2089             }
2090         }
2091       sw=4;
2092       nbTuples=size;
2093       return &f[0];
2094     }
2095   void *argp;
2096   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2097   if(SWIG_IsOK(status))
2098     {  
2099       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2100       sw=2;
2101       if(d)
2102         {
2103           if(d->getNumberOfComponents()==1)
2104             {
2105               nbTuples=d->getNumberOfTuples();
2106               return d->getConstPointer();
2107             }
2108           else
2109             {
2110               std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2111               throw INTERP_KERNEL::Exception(oss.str().c_str());
2112             }
2113         }
2114       else
2115         {
2116           if(throwIfNullPt)
2117             {
2118               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2119               throw INTERP_KERNEL::Exception(oss.str().c_str());
2120             }
2121           else
2122             { nbTuples=0; return 0; }
2123         }
2124     }
2125   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2126   if(SWIG_IsOK(status))
2127     {  
2128       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2129       sw=3;
2130       if(e)
2131         {
2132           nbTuples=e->getNumberOfCompo();
2133           return e->getConstPointer();
2134         }
2135       else
2136         {
2137           if(throwIfNullPt)
2138             {
2139               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2140               throw INTERP_KERNEL::Exception(oss.str().c_str());
2141             }
2142           else
2143             { nbTuples=0; return 0; }
2144         }
2145     }
2146   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2147 }
2148
2149 /*!
2150  * if python int -> cpp int sw=1
2151  * if python list[int] -> cpp vector<int> sw=2
2152  * if python tuple[int] -> cpp vector<int> sw=2
2153  * if python DataArrayInt -> cpp DataArrayInt sw=3
2154  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2155  *
2156  * switch between (int,vector<int>,DataArrayInt)
2157  */
2158 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2159 {
2160   sw=-1;
2161   if(PyInt_Check(value))
2162     {
2163       iTyypp=(int)PyInt_AS_LONG(value);
2164       sw=1; sz=1;
2165       return &iTyypp;
2166     }
2167   if(PyTuple_Check(value))
2168     {
2169       int size=PyTuple_Size(value);
2170       stdvecTyypp.resize(size);
2171       for(int i=0;i<size;i++)
2172         {
2173           PyObject *o=PyTuple_GetItem(value,i);
2174           if(PyInt_Check(o))
2175             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2176           else
2177             {
2178               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2179               throw INTERP_KERNEL::Exception(oss.str().c_str());
2180             }
2181         }
2182       sw=2; sz=size;
2183       return &stdvecTyypp[0];
2184     }
2185   if(PyList_Check(value))
2186     {
2187       int size=PyList_Size(value);
2188       stdvecTyypp.resize(size);
2189       for(int i=0;i<size;i++)
2190         {
2191           PyObject *o=PyList_GetItem(value,i);
2192           if(PyInt_Check(o))
2193             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2194           else
2195             {
2196               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2197               throw INTERP_KERNEL::Exception(oss.str().c_str());
2198             }
2199         }
2200       sw=2; sz=size;
2201       return &stdvecTyypp[0];
2202     }
2203   void *argp;
2204   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2205   if(SWIG_IsOK(status))
2206     {
2207       ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2208       if(daIntTyypp)
2209         {
2210           sw=3; sz=daIntTyypp->getNbOfElems();
2211           return daIntTyypp->begin();
2212         }
2213       else
2214         {
2215           sz=0;
2216           return 0;
2217         }
2218     }
2219   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2220   if(SWIG_IsOK(status))
2221     {  
2222       ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2223       sw=4; sz=daIntTuple->getNumberOfCompo();
2224       return daIntTuple->getConstPointer();
2225     }
2226   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2227 }
2228
2229 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2230 {
2231   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.";
2232   const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
2233   void *argp;
2234   //
2235   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2236     {
2237       ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2238       if(other)
2239         return (*self)+(*other);
2240       else
2241         throw INTERP_KERNEL::Exception(msg);
2242     }
2243   //
2244   double val;
2245   ParaMEDMEM::DataArrayDouble *a;
2246   ParaMEDMEM::DataArrayDoubleTuple *aa;
2247   std::vector<double> bb;
2248   int sw;
2249   convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2250   switch(sw)
2251     {
2252     case 1:
2253       {
2254         if(!self->getArray())
2255           throw INTERP_KERNEL::Exception(msg2);
2256         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2257         ret->applyLin(1.,val);
2258         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2259         ret2->setArray(ret);
2260         return ret2.retn();
2261       }
2262     case 2:
2263       {
2264         if(!self->getArray())
2265           throw INTERP_KERNEL::Exception(msg2);
2266         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a);
2267         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2268         ret2->setArray(ret);
2269         return ret2.retn();
2270       }
2271     case 3:
2272       {
2273         if(!self->getArray())
2274           throw INTERP_KERNEL::Exception(msg2);
2275         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2276         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2277         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2278         ret2->setArray(ret);
2279         return ret2.retn();
2280       }
2281     case 4:
2282       {
2283         if(!self->getArray())
2284           throw INTERP_KERNEL::Exception(msg2);
2285         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2286         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2287         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2288         ret2->setArray(ret);
2289         return ret2.retn();
2290       }
2291     default:
2292       { throw INTERP_KERNEL::Exception(msg); }
2293     }
2294 }
2295
2296 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2297 {
2298   return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj);
2299 }
2300
2301 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2302 {
2303   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.";
2304   const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
2305   void *argp;
2306   //
2307   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2308     {
2309       ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2310       if(other)
2311         return (*other)-(*self);
2312       else
2313         throw INTERP_KERNEL::Exception(msg);
2314     }
2315   //
2316   double val;
2317   ParaMEDMEM::DataArrayDouble *a;
2318   ParaMEDMEM::DataArrayDoubleTuple *aa;
2319   std::vector<double> bb;
2320   int sw;
2321   convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2322   switch(sw)
2323     {
2324     case 1:
2325       {
2326         if(!self->getArray())
2327           throw INTERP_KERNEL::Exception(msg2);
2328         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2329         ret->applyLin(-1.,val);
2330         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2331         ret2->setArray(ret);
2332         return ret2.retn();
2333       }
2334     case 2:
2335       {
2336         if(!self->getArray())
2337           throw INTERP_KERNEL::Exception(msg2);
2338         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray());
2339         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2340         ret2->setArray(ret);
2341         return ret2.retn();
2342       }
2343     case 3:
2344       {
2345         if(!self->getArray())
2346           throw INTERP_KERNEL::Exception(msg2);
2347         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2348         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2349         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2350         ret2->setArray(ret);
2351         return ret2.retn();
2352       }
2353     case 4:
2354       {
2355         if(!self->getArray())
2356           throw INTERP_KERNEL::Exception(msg2);
2357         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2358         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2359         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2360         ret2->setArray(ret);
2361         return ret2.retn();
2362       }
2363     default:
2364       { throw INTERP_KERNEL::Exception(msg); }
2365     }
2366 }
2367
2368 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2369 {
2370   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.";
2371   const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
2372   void *argp;
2373   //
2374   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2375     {
2376       ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2377       if(other)
2378         return (*self)*(*other);
2379       else
2380         throw INTERP_KERNEL::Exception(msg);
2381     }
2382   //
2383   double val;
2384   ParaMEDMEM::DataArrayDouble *a;
2385   ParaMEDMEM::DataArrayDoubleTuple *aa;
2386   std::vector<double> bb;
2387   int sw;
2388   convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2389   switch(sw)
2390     {
2391     case 1:
2392       {
2393         if(!self->getArray())
2394           throw INTERP_KERNEL::Exception(msg2);
2395         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2396         ret->applyLin(val,0.);
2397         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2398         ret2->setArray(ret);
2399         return ret2.retn();
2400       }
2401     case 2:
2402       {
2403         if(!self->getArray())
2404           throw INTERP_KERNEL::Exception(msg2);
2405         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a);
2406         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2407         ret2->setArray(ret);
2408         return ret2.retn();
2409       }
2410     case 3:
2411       {
2412         if(!self->getArray())
2413           throw INTERP_KERNEL::Exception(msg2);
2414         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2415         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2416         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2417         ret2->setArray(ret);
2418         return ret2.retn();
2419       }
2420     case 4:
2421       {
2422         if(!self->getArray())
2423           throw INTERP_KERNEL::Exception(msg2);
2424         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2425         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2426         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2427         ret2->setArray(ret);
2428         return ret2.retn();
2429       }
2430     default:
2431       { throw INTERP_KERNEL::Exception(msg); }
2432     }
2433 }
2434
2435 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2436 {
2437   return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj);
2438 }
2439
2440 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2441 {
2442   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.";
2443   const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
2444   void *argp;
2445   //
2446   if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2447     {
2448       ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2449       if(other)
2450         return (*other)/(*self);
2451       else
2452         throw INTERP_KERNEL::Exception(msg);
2453     }
2454   //
2455   double val;
2456   ParaMEDMEM::DataArrayDouble *a;
2457   ParaMEDMEM::DataArrayDoubleTuple *aa;
2458   std::vector<double> bb;
2459   int sw;
2460   convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2461   switch(sw)
2462     {
2463     case 1:
2464       {
2465         if(!self->getArray())
2466           throw INTERP_KERNEL::Exception(msg2);
2467         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2468         ret->applyInv(val);
2469         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2470         ret2->setArray(ret);
2471         return ret2.retn();
2472       }
2473     case 2:
2474       {
2475         if(!self->getArray())
2476           throw INTERP_KERNEL::Exception(msg2);
2477         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray());
2478         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2479         ret2->setArray(ret);
2480         return ret2.retn();
2481       }
2482     case 3:
2483       {
2484         if(!self->getArray())
2485           throw INTERP_KERNEL::Exception(msg2);
2486         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2487         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2488         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2489         ret2->setArray(ret);
2490         return ret2.retn();
2491       }
2492     case 4:
2493       {
2494         if(!self->getArray())
2495           throw INTERP_KERNEL::Exception(msg2);
2496         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2497         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2498         ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2499         ret2->setArray(ret);
2500         return ret2.retn();
2501       }
2502     default:
2503       { throw INTERP_KERNEL::Exception(msg); }
2504     }
2505 }
2506
2507 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2508 {
2509   void *aBasePtrVS=0;
2510   int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2511   if(!SWIG_IsOK(status))
2512     {
2513       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2514       if(!SWIG_IsOK(status))
2515         {
2516           status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2517           if(!SWIG_IsOK(status))
2518             {
2519               status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2520               if(!SWIG_IsOK(status))
2521                 {
2522                   status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2523                   std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2524                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2525                 }
2526             }
2527         }
2528     }
2529   return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);
2530 }