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