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