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