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