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