Salome HOME
Full synchronisation of patches across levels.
[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 void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr) throw(INTERP_KERNEL::Exception)
1047 {
1048   const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1049   if(PyList_Check(pyLi))
1050     {
1051       Py_ssize_t sz=PyList_Size(pyLi);
1052       arr.resize(sz);
1053       for(int i=0;i<sz;i++)
1054         {
1055           PyObject *o=PyList_GetItem(pyLi,i);
1056           if(PyTuple_Check(o))
1057             {
1058               int sz2=PyTuple_Size(o);
1059               if(sz2!=2)
1060                 throw INTERP_KERNEL::Exception(msg);
1061               std::pair<std::string, std::vector<std::string> > item;
1062               PyObject *o_0=PyTuple_GetItem(o,0);
1063               if(!PyString_Check(o_0))
1064                 throw INTERP_KERNEL::Exception(msg);
1065               item.first=PyString_AsString(o_0);
1066               PyObject *o_1=PyTuple_GetItem(o,1);
1067               if(!fillStringVector(o_1,item.second))
1068                 throw INTERP_KERNEL::Exception(msg);
1069               arr[i]=item;
1070             }
1071           else
1072             throw INTERP_KERNEL::Exception(msg);
1073         }
1074     }
1075   else if(PyTuple_Check(pyLi))
1076     {
1077       Py_ssize_t sz=PyTuple_Size(pyLi);
1078       arr.resize(sz);
1079       for(int i=0;i<sz;i++)
1080         {
1081           PyObject *o=PyTuple_GetItem(pyLi,i);
1082           if(PyTuple_Check(o))
1083             {
1084               int sz2=PyTuple_Size(o);
1085               if(sz2!=2)
1086                 throw INTERP_KERNEL::Exception(msg);
1087               std::pair<std::string, std::vector<std::string> > item;
1088               PyObject *o_0=PyTuple_GetItem(o,0);
1089               if(!PyString_Check(o_0))
1090                 throw INTERP_KERNEL::Exception(msg);
1091               item.first=PyString_AsString(o_0);
1092               PyObject *o_1=PyTuple_GetItem(o,1);
1093               if(!fillStringVector(o_1,item.second))
1094                 throw INTERP_KERNEL::Exception(msg);
1095               arr[i]=item;
1096             }
1097           else
1098             throw INTERP_KERNEL::Exception(msg);
1099         }
1100     }
1101   else
1102     throw INTERP_KERNEL::Exception(msg);
1103 }
1104
1105 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
1106 {
1107   PyObject *ret=PyList_New(size);
1108   for(int i=0;i<size;i++)
1109     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1110   return ret;
1111 }
1112
1113 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
1114 {
1115   int size=v.size();
1116   PyObject *ret=PyList_New(size);
1117   for(int i=0;i<size;i++)
1118     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1119   return ret;
1120 }
1121
1122 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1123 {
1124   PyObject *ret=PyList_New(nbOfTuples);
1125   for(int i=0;i<nbOfTuples;i++)
1126     {
1127       PyObject *t=PyTuple_New(nbOfComp);
1128       for(int j=0;j<nbOfComp;j++)
1129         PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1130       PyList_SetItem(ret,i,t);
1131     }
1132   return ret;
1133 }
1134
1135 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1136 {
1137   PyObject *ret=PyList_New(nbOfTuples);
1138   INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1139   for(int i=0;i<nbOfTuples;i++)
1140     {
1141       std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1142       PyList_SetItem(ret,i,PyString_FromString(tmp));
1143     }
1144   return ret;
1145 }
1146
1147 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1148 {
1149   if(PyList_Check(pyLi))
1150     {
1151       *size=PyList_Size(pyLi);
1152       double *tmp=(double *)malloc((*size)*sizeof(double));
1153       for(int i=0;i<*size;i++)
1154         {
1155           PyObject *o=PyList_GetItem(pyLi,i);
1156           if(PyFloat_Check(o))
1157             {
1158               double val=PyFloat_AS_DOUBLE(o);
1159               tmp[i]=val;
1160             }
1161           else if(PyInt_Check(o))
1162             {
1163               long val0=PyInt_AS_LONG(o);
1164               double val=val0;
1165               tmp[i]=val;
1166             }
1167           else
1168             {
1169               free(tmp);
1170               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1171             }
1172         }
1173       return tmp;
1174     }
1175   else if(PyTuple_Check(pyLi))
1176     {
1177       *size=PyTuple_Size(pyLi);
1178       double *tmp=(double *)malloc((*size)*sizeof(double));
1179       for(int i=0;i<*size;i++)
1180         {
1181           PyObject *o=PyTuple_GetItem(pyLi,i);
1182           if(PyFloat_Check(o))
1183             {
1184               double val=PyFloat_AS_DOUBLE(o);
1185               tmp[i]=val;
1186             }
1187           else if(PyInt_Check(o))
1188             {
1189               long val0=PyInt_AS_LONG(o);
1190               double val=val0;
1191               tmp[i]=val;
1192             }
1193           else
1194             {
1195               free(tmp);
1196               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1197             }
1198         }
1199       return tmp;
1200     }
1201   else
1202     throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1203 }
1204
1205 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1206 {
1207   static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1208   if(PyFloat_Check(pyLi))
1209     {
1210       if(nbOfElt==-1)
1211         nbOfElt=1;
1212       else
1213         if(nbOfElt!=1)
1214           throw INTERP_KERNEL::Exception(MSG);
1215       double val=PyFloat_AS_DOUBLE(pyLi);
1216       ret.push_back(val);
1217     }
1218   else if(PyInt_Check(pyLi))
1219     {
1220       long val0=PyInt_AS_LONG(pyLi);
1221       double val=val0;
1222       if(nbOfElt==-1)
1223         nbOfElt=1;
1224       else
1225         if(nbOfElt!=1)
1226           throw INTERP_KERNEL::Exception(MSG);
1227       ret.push_back(val);
1228     }
1229   else if(PyList_Check(pyLi))
1230     {
1231       int size=PyList_Size(pyLi);
1232       int tmp=0;
1233       for(int i=0;i<size;i++)
1234         {
1235           PyObject *o=PyList_GetItem(pyLi,i);
1236           int tmp1=-1;
1237           fillArrayWithPyListDbl3(o,tmp1,ret);
1238           tmp+=tmp1;
1239         }
1240       if(nbOfElt==-1)
1241         nbOfElt=tmp;
1242       else
1243         {
1244           if(nbOfElt!=tmp)
1245             throw INTERP_KERNEL::Exception(MSG);
1246         }
1247     }
1248   else if(PyTuple_Check(pyLi))
1249     {
1250       int size=PyTuple_Size(pyLi);
1251       int tmp=0;
1252       for(int i=0;i<size;i++)
1253         {
1254           PyObject *o=PyTuple_GetItem(pyLi,i);
1255           int tmp1=-1;
1256           fillArrayWithPyListDbl3(o,tmp1,ret);
1257           tmp+=tmp1;
1258         }
1259       if(nbOfElt==-1)
1260         nbOfElt=tmp;
1261       else
1262         {
1263           if(nbOfElt!=tmp)
1264             throw INTERP_KERNEL::Exception(MSG);
1265         }
1266     }
1267   else
1268     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1269 }
1270
1271 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1272 {
1273   std::vector<double> ret;
1274   int size1=-1,size2=-1;
1275   if(PyList_Check(pyLi))
1276     {
1277       size1=PyList_Size(pyLi);
1278       for(int i=0;i<size1;i++)
1279         {
1280           PyObject *o=PyList_GetItem(pyLi,i);
1281           fillArrayWithPyListDbl3(o,size2,ret);
1282         }
1283       if(size1==0)
1284         size2=1;
1285     }
1286   else if(PyTuple_Check(pyLi))
1287     {
1288       size1=PyTuple_Size(pyLi);
1289       for(int i=0;i<size1;i++)
1290         {
1291           PyObject *o=PyTuple_GetItem(pyLi,i);
1292           fillArrayWithPyListDbl3(o,size2,ret);
1293         }
1294       if(size1==0)
1295         size2=1;
1296     }
1297   else
1298     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1299   //
1300   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1301   return ret;
1302 }
1303
1304 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1305 template<class T>
1306 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1307 {
1308   void *argp=0;
1309   if(PyList_Check(pyLi))
1310     {
1311       int size=PyList_Size(pyLi);
1312       ret.resize(size);
1313       for(int i=0;i<size;i++)
1314         {
1315           PyObject *obj=PyList_GetItem(pyLi,i);
1316           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1317           if(!SWIG_IsOK(status))
1318             {
1319               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1320               throw INTERP_KERNEL::Exception(oss.str().c_str());
1321             }
1322           T arg=reinterpret_cast< T >(argp);
1323           ret[i]=arg;
1324         }
1325     }
1326   else if(PyTuple_Check(pyLi))
1327     {
1328       int size=PyTuple_Size(pyLi);
1329       ret.resize(size);
1330       for(int i=0;i<size;i++)
1331         {
1332           PyObject *obj=PyTuple_GetItem(pyLi,i);
1333           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1334           if(!SWIG_IsOK(status))
1335             {
1336               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1337               throw INTERP_KERNEL::Exception(oss.str().c_str());
1338             }
1339           T arg=reinterpret_cast< T >(argp);
1340           ret[i]=arg;
1341         }
1342     }
1343   else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1344     {
1345       ret.resize(1);
1346       T arg=reinterpret_cast< T >(argp);
1347       ret[0]=arg;
1348     }
1349   else
1350     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1351 }
1352
1353 /*!
1354  * if python int -> cpp int sw=1
1355  * if python list[int] -> cpp vector<int> sw=2
1356  * if python tuple[int] -> cpp vector<int> sw=2
1357  * if python DataArrayInt -> cpp DataArrayInt sw=3
1358  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1359  *
1360  * switch between (int,vector<int>,DataArrayInt)
1361  */
1362 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1363 {
1364   sw=-1;
1365   if(PyInt_Check(value))
1366     {
1367       iTyypp=(int)PyInt_AS_LONG(value);
1368       sw=1;
1369       return;
1370     }
1371   if(PyTuple_Check(value))
1372     {
1373       int size=PyTuple_Size(value);
1374       stdvecTyypp.resize(size);
1375       for(int i=0;i<size;i++)
1376         {
1377           PyObject *o=PyTuple_GetItem(value,i);
1378           if(PyInt_Check(o))
1379             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1380           else
1381             {
1382               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1383               throw INTERP_KERNEL::Exception(oss.str().c_str());
1384             }
1385         }
1386       sw=2;
1387       return;
1388     }
1389   if(PyList_Check(value))
1390     {
1391       int size=PyList_Size(value);
1392       stdvecTyypp.resize(size);
1393       for(int i=0;i<size;i++)
1394         {
1395           PyObject *o=PyList_GetItem(value,i);
1396           if(PyInt_Check(o))
1397             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1398           else
1399             {
1400               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1401               throw INTERP_KERNEL::Exception(oss.str().c_str());
1402             }
1403         }
1404       sw=2;
1405       return;
1406     }
1407   void *argp;
1408   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1409   if(SWIG_IsOK(status))
1410     {
1411       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1412       sw=3;
1413       return;
1414     }
1415   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1416   if(SWIG_IsOK(status))
1417     {  
1418       daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1419       sw=4;
1420       return ;
1421     }
1422   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1423 }
1424
1425 /*!
1426  * if python double -> cpp double sw=1
1427  * if python int -> cpp double sw=1
1428  * if python list[double] -> cpp vector<double> sw=2
1429  * if python list[int] -> cpp vector<double> sw=2
1430  * if python tuple[double] -> cpp vector<double> sw=2
1431  * if python tuple[int] -> cpp vector<double> sw=2
1432  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1433  *
1434  * switch between (int,vector<int>,DataArrayInt)
1435  */
1436 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1437 {
1438   sw=-1;
1439   if(PyFloat_Check(value))
1440     {
1441       iTyypp=PyFloat_AS_DOUBLE(value);
1442       sw=1;
1443       return;
1444     }
1445   if(PyInt_Check(value))
1446     {
1447       iTyypp=(double)PyInt_AS_LONG(value);
1448       sw=1;
1449       return;
1450     }
1451   if(PyTuple_Check(value))
1452     {
1453       int size=PyTuple_Size(value);
1454       stdvecTyypp.resize(size);
1455       for(int i=0;i<size;i++)
1456         {
1457           PyObject *o=PyTuple_GetItem(value,i);
1458           if(PyFloat_Check(o))
1459             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1460           else if(PyInt_Check(o))
1461             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1462           else
1463             {
1464               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1465               throw INTERP_KERNEL::Exception(oss.str().c_str());
1466             }
1467         }
1468       sw=2;
1469       return;
1470     }
1471   if(PyList_Check(value))
1472     {
1473       int size=PyList_Size(value);
1474       stdvecTyypp.resize(size);
1475       for(int i=0;i<size;i++)
1476         {
1477           PyObject *o=PyList_GetItem(value,i);
1478           if(PyFloat_Check(o))
1479             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1480           else if(PyInt_Check(o))
1481             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1482           else
1483             {
1484               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1485               throw INTERP_KERNEL::Exception(oss.str().c_str());
1486             }
1487         }
1488       sw=2;
1489       return;
1490     }
1491   void *argp;
1492   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1493   if(!SWIG_IsOK(status))
1494     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1495   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1496   sw=3;
1497 }
1498
1499 /*!
1500  * if python double -> cpp double sw=1
1501  * if python int -> cpp double sw=1
1502  * if python list[double] -> cpp vector<double> sw=2
1503  * if python list[int] -> cpp vector<double> sw=2
1504  * if python tuple[double] -> cpp vector<double> sw=2
1505  * if python tuple[int] -> cpp vector<double> sw=2
1506  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1507  *
1508  * switch between (int,vector<int>,DataArrayInt)
1509  */
1510 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1511 {
1512   sw=-1;
1513   if(PyFloat_Check(value))
1514     {
1515       iTyypp=PyFloat_AS_DOUBLE(value);
1516       sw=1;
1517       return;
1518     }
1519   if(PyInt_Check(value))
1520     {
1521       iTyypp=(double)PyInt_AS_LONG(value);
1522       sw=1;
1523       return;
1524     }
1525   if(PyTuple_Check(value))
1526     {
1527       int size=PyTuple_Size(value);
1528       stdvecTyypp.resize(size);
1529       for(int i=0;i<size;i++)
1530         {
1531           PyObject *o=PyTuple_GetItem(value,i);
1532           if(PyFloat_Check(o))
1533             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1534           else if(PyInt_Check(o))
1535             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1536           else
1537             {
1538               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1539               throw INTERP_KERNEL::Exception(oss.str().c_str());
1540             }
1541         }
1542       sw=2;
1543       return;
1544     }
1545   if(PyList_Check(value))
1546     {
1547       int size=PyList_Size(value);
1548       stdvecTyypp.resize(size);
1549       for(int i=0;i<size;i++)
1550         {
1551           PyObject *o=PyList_GetItem(value,i);
1552           if(PyFloat_Check(o))
1553             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1554           else if(PyInt_Check(o))
1555             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1556           else
1557             {
1558               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1559               throw INTERP_KERNEL::Exception(oss.str().c_str());
1560             }
1561         }
1562       sw=2;
1563       return;
1564     }
1565   void *argp;
1566   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1567   if(!SWIG_IsOK(status))
1568     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1569   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1570   sw=3;
1571 }
1572
1573 /*!
1574  * if python int -> cpp int sw=1
1575  * if python list[int] -> cpp vector<int> sw=2
1576  * if python tuple[int] -> cpp vector<int> sw=2
1577  * if python slicp -> cpp pair sw=3 (begin,end,step)
1578  * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1579  *
1580  * switch between (int,vector<int>,DataArrayInt)
1581  */
1582 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)
1583 {
1584   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1585   sw=-1;
1586   if(PyInt_Check(value))
1587     {
1588       iTyypp=(int)PyInt_AS_LONG(value);
1589       sw=1;
1590       return;
1591     }
1592   if(PyTuple_Check(value))
1593     {
1594       int size=PyTuple_Size(value);
1595       stdvecTyypp.resize(size);
1596       for(int i=0;i<size;i++)
1597         {
1598           PyObject *o=PyTuple_GetItem(value,i);
1599           if(PyInt_Check(o))
1600             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1601           else
1602             {
1603               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1604               throw INTERP_KERNEL::Exception(oss.str().c_str());
1605             }
1606         }
1607       sw=2;
1608       return;
1609     }
1610   if(PyList_Check(value))
1611     {
1612       int size=PyList_Size(value);
1613       stdvecTyypp.resize(size);
1614       for(int i=0;i<size;i++)
1615         {
1616           PyObject *o=PyList_GetItem(value,i);
1617           if(PyInt_Check(o))
1618             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1619           else
1620             {
1621               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1622               throw INTERP_KERNEL::Exception(oss.str().c_str());
1623             }
1624         }
1625       sw=2;
1626       return;
1627     }
1628   if(PySlice_Check(value))
1629     {
1630       Py_ssize_t strt=2,stp=2,step=2;
1631       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1632       GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1633       p.first=strt;
1634       p.second.first=stp;
1635       p.second.second=step;
1636       sw=3;
1637       return ;
1638     }
1639   void *argp;
1640   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1641   if(SWIG_IsOK(status))
1642     {
1643       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1644       if(!daIntTyypp)
1645         {
1646           std::ostringstream oss; oss << msg << " Instance in null !";
1647           throw INTERP_KERNEL::Exception(oss.str().c_str());
1648         }
1649       sw=4;
1650       return ;
1651     }
1652   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1653   if(SWIG_IsOK(status))
1654     {
1655       ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1656       if(!tmp)
1657         {
1658           std::ostringstream oss; oss << msg << " Instance in null !";
1659           throw INTERP_KERNEL::Exception(oss.str().c_str());
1660         }
1661       stdvecTyypp.resize(tmp->getNumberOfCompo());
1662       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1663       sw=2;
1664       return ;
1665     }
1666   throw INTERP_KERNEL::Exception(msg);
1667 }
1668
1669 /*!
1670  * Idem than convertObjToPossibleCpp2
1671  */
1672 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)
1673 {
1674   convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1675   if(sw==1)
1676     {
1677       iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1678     }
1679 }
1680
1681 /*!
1682  * if python int -> cpp int sw=1
1683  * if python tuple[int] -> cpp vector<int> sw=2
1684  * if python list[int] -> cpp vector<int> sw=2
1685  * if python slice -> cpp pair sw=3
1686  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1687  */
1688 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)
1689 {
1690   sw=-1;
1691   if(PyInt_Check(value))
1692     {
1693       iTyypp=(int)PyInt_AS_LONG(value);
1694       sw=1;
1695       return;
1696     }
1697   if(PyTuple_Check(value))
1698     {
1699       int size=PyTuple_Size(value);
1700       stdvecTyypp.resize(size);
1701       for(int i=0;i<size;i++)
1702         {
1703           PyObject *o=PyTuple_GetItem(value,i);
1704           if(PyInt_Check(o))
1705             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1706           else
1707             {
1708               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1709               throw INTERP_KERNEL::Exception(oss.str().c_str());
1710             }
1711         }
1712       sw=2;
1713       return;
1714     }
1715   if(PyList_Check(value))
1716     {
1717       int size=PyList_Size(value);
1718       stdvecTyypp.resize(size);
1719       for(int i=0;i<size;i++)
1720         {
1721           PyObject *o=PyList_GetItem(value,i);
1722           if(PyInt_Check(o))
1723             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1724           else
1725             {
1726               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1727               throw INTERP_KERNEL::Exception(oss.str().c_str());
1728             }
1729         }
1730       sw=2;
1731       return;
1732     }
1733   if(PySlice_Check(value))
1734     {
1735       Py_ssize_t strt=2,stp=2,step=2;
1736       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1737       GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1738       p.first=strt;
1739       p.second.first=stp;
1740       p.second.second=step;
1741       sw=3;
1742       return ;
1743     }
1744   void *argp;
1745   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1746   if(!SWIG_IsOK(status))
1747     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1748   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1749   sw=4;
1750 }
1751
1752 /*!
1753  * if python string with size one -> cpp char sw=1
1754  * if python string with size different from one -> cpp string sw=2
1755  * if python tuple[string] or list[string] -> vector<string> sw=3
1756  * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1757  * switch between (int,string,vector<string>,DataArrayChar)
1758  */
1759 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1760 {
1761   const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1762   sw=-1;
1763   if(PyString_Check(value))
1764     {
1765       const char *pt=PyString_AsString(value);
1766       Py_ssize_t sz=PyString_Size(value);
1767       if(sz==1)
1768         {
1769           cTyp=pt[0];
1770           sw=1;
1771           return;
1772         }
1773       else
1774         {
1775           sType=pt;
1776           sw=2;
1777           return;
1778         }
1779     }
1780   if(PyTuple_Check(value))
1781     {
1782       int size=PyTuple_Size(value);
1783       vsType.resize(size);
1784       for(int i=0;i<size;i++)
1785         {
1786           PyObject *o=PyTuple_GetItem(value,i);
1787           if(PyString_Check(o))
1788             vsType[i]=PyString_AsString(o);
1789           else
1790             {
1791               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1792               throw INTERP_KERNEL::Exception(oss.str().c_str());
1793             }
1794         }
1795       sw=3;
1796       return;
1797     }
1798   if(PyList_Check(value))
1799     {
1800       int size=PyList_Size(value);
1801       vsType.resize(size);
1802       for(int i=0;i<size;i++)
1803         {
1804           PyObject *o=PyList_GetItem(value,i);
1805           if(PyString_Check(o))
1806             vsType[i]=PyString_AsString(o);
1807           else
1808             {
1809               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1810               throw INTERP_KERNEL::Exception(oss.str().c_str());
1811             }
1812         }
1813       sw=3;
1814       return;
1815     }
1816   void *argp;
1817   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1818   if(SWIG_IsOK(status))
1819     {
1820       dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1821       if(!dacType)
1822         {
1823           std::ostringstream oss; oss << msg << " Instance in null !";
1824           throw INTERP_KERNEL::Exception(oss.str().c_str());
1825         }
1826       sw=4;
1827       return ;
1828     }
1829   throw INTERP_KERNEL::Exception(msg);
1830 }
1831
1832 /*!
1833  * if value int -> cpp it sw=1
1834  * if value list[int] -> vt sw=2
1835  * if value tuple[int] -> vt sw=2
1836  * if value slice -> pt sw=3
1837  * if value DataArrayInt -> dt sw=4
1838  * if value tuple [int,int] -> cpp it,ip sw=5
1839  * if value tuple [list[int],int] -> cpp vt,ip sw=6
1840  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1841  * if value tuple [slice,int] -> cpp pt,ip sw=7
1842  * if value tuple [DaI,int] -> cpp dt,ip sw=8
1843  * if value tuple [int,list[int]] -> cpp it,vc sw=9
1844  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1845  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1846  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1847  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1848  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1849  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1850  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1851  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1852  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1853  * if value tuple [int,slice] -> cpp it,pc sw=13
1854  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1855  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1856  * if value tuple [slice,slice] -> cpp pt,pc sw=15
1857  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1858  *
1859  * switch between (int,vector<int>,DataArrayInt)
1860  */
1861 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1862                                      std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1863                                      ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1864 {
1865   if(!PyTuple_Check(value))
1866     {
1867       convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1868       return ;
1869     }
1870   else
1871     {
1872       int sz=PyTuple_Size(value);
1873       if(sz!=2)
1874         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1875       PyObject *ob0=PyTuple_GetItem(value,0);
1876       int sw1,sw2;
1877       convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1878       PyObject *ob1=PyTuple_GetItem(value,1);
1879       convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1880       sw=4*sw2+sw1;
1881     }
1882 }
1883
1884 /*!
1885  * if value int -> cpp val sw=1
1886  * if value double -> cpp val sw=1
1887  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1888  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1889  * if value list[int,double] -> cpp std::vector<double> sw=4
1890  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1891  */
1892 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1893 {
1894   sw=-1;
1895   if(PyFloat_Check(value))
1896     {
1897       val=PyFloat_AS_DOUBLE(value);
1898       sw=1;
1899       return;
1900     }
1901   if(PyInt_Check(value))
1902     {
1903       val=(double)PyInt_AS_LONG(value);
1904       sw=1;
1905       return;
1906     }
1907   if(PyTuple_Check(value))
1908     {
1909       int size=PyTuple_Size(value);
1910       f.resize(size);
1911       for(int i=0;i<size;i++)
1912         {
1913           PyObject *o=PyTuple_GetItem(value,i);
1914           if(PyFloat_Check(o))
1915             f[i]=PyFloat_AS_DOUBLE(o);
1916           else if(PyInt_Check(o))
1917             f[i]=(double)PyInt_AS_LONG(o);
1918           else
1919             {
1920               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1921               throw INTERP_KERNEL::Exception(oss.str().c_str());
1922             }
1923         }
1924       sw=4;
1925       return;
1926     }
1927   if(PyList_Check(value))
1928     {
1929       int size=PyList_Size(value);
1930       f.resize(size);
1931       for(int i=0;i<size;i++)
1932         {
1933           PyObject *o=PyList_GetItem(value,i);
1934           if(PyFloat_Check(o))
1935             f[i]=PyFloat_AS_DOUBLE(o);
1936           else if(PyInt_Check(o))
1937             f[i]=(double)PyInt_AS_LONG(o);
1938           else
1939             {
1940               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1941               throw INTERP_KERNEL::Exception(oss.str().c_str());
1942             }
1943         }
1944       sw=4;
1945       return;
1946     }
1947   void *argp;
1948   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1949   if(SWIG_IsOK(status))
1950     {  
1951       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1952       sw=2;
1953       return ;
1954     }
1955   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1956   if(SWIG_IsOK(status))
1957     {  
1958       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1959       sw=3;
1960       return ;
1961     }
1962   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1963 }
1964
1965 /*!
1966  * if value int -> cpp val sw=1
1967  * if value double -> cpp val sw=1
1968  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1969  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1970  * if value list[int,double] -> cpp std::vector<double> sw=4
1971  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1972  */
1973 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1974                                                    const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1975 {
1976   sw=-1;
1977   if(PyFloat_Check(value))
1978     {
1979       val=PyFloat_AS_DOUBLE(value);
1980       sw=1;
1981       if(nbTuplesExpected*nbCompExpected!=1)
1982         {
1983           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1984           throw INTERP_KERNEL::Exception(oss.str().c_str());
1985         }
1986       return &val;
1987     }
1988   if(PyInt_Check(value))
1989     {
1990       val=(double)PyInt_AS_LONG(value);
1991       sw=1;
1992       if(nbTuplesExpected*nbCompExpected!=1)
1993         {
1994           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1995           throw INTERP_KERNEL::Exception(oss.str().c_str());
1996         }
1997       return &val;
1998     }
1999   if(PyTuple_Check(value) || PyList_Check(value))
2000     {
2001       try
2002         {
2003           int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2004           std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2005           sw=4;
2006           f=ret;
2007           return &f[0];
2008         }
2009       catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2010     }
2011   void *argp;
2012   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2013   if(SWIG_IsOK(status))
2014     {  
2015       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2016       sw=2;
2017       if(d)
2018         {
2019           if(d->getNumberOfTuples()==nbTuplesExpected)
2020             {
2021               if(d->getNumberOfComponents()==nbCompExpected)
2022                 {
2023                   return d->getConstPointer();
2024                 }
2025               else
2026                 {
2027                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2028                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2029                 }
2030             }
2031           else
2032             {
2033               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2034               throw INTERP_KERNEL::Exception(oss.str().c_str());
2035             }
2036         }
2037       else
2038         {
2039           if(throwIfNullPt)
2040             {
2041               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2042               throw INTERP_KERNEL::Exception(oss.str().c_str());
2043             }
2044           else
2045             return 0;
2046         }
2047     }
2048   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2049   if(SWIG_IsOK(status))
2050     {  
2051       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2052       sw=3;
2053       if(e->getNumberOfCompo()==nbCompExpected)
2054         {
2055           if(nbTuplesExpected==1)
2056             return e->getConstPointer();
2057           else
2058             {
2059               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2060               throw INTERP_KERNEL::Exception(oss.str().c_str());
2061             }
2062         }
2063       else
2064         {
2065           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2066           throw INTERP_KERNEL::Exception(oss.str().c_str());
2067         }
2068     }
2069   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2070 }
2071
2072 /*!
2073  * if value int -> cpp val sw=1
2074  * if value double -> cpp val sw=1
2075  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2076  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2077  * if value list[int,double] -> cpp std::vector<double> sw=4
2078  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2079  */
2080 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
2081                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2082 {
2083   sw=-1;
2084   if(PyFloat_Check(value))
2085     {
2086       val=PyFloat_AS_DOUBLE(value);
2087       sw=1;
2088       if(nbCompExpected!=1)
2089         {
2090           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
2091           throw INTERP_KERNEL::Exception(oss.str().c_str());
2092         }
2093       nbTuples=1;
2094       return &val;
2095     }
2096   if(PyInt_Check(value))
2097     {
2098       val=(double)PyInt_AS_LONG(value);
2099       sw=1;
2100       if(nbCompExpected!=1)
2101         {
2102           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
2103           throw INTERP_KERNEL::Exception(oss.str().c_str());
2104         }
2105       nbTuples=1;
2106       return &val;
2107     }
2108   if(PyTuple_Check(value))
2109     {
2110       int size=PyTuple_Size(value);
2111       f.resize(size);
2112       for(int i=0;i<size;i++)
2113         {
2114           PyObject *o=PyTuple_GetItem(value,i);
2115           if(PyFloat_Check(o))
2116             f[i]=PyFloat_AS_DOUBLE(o);
2117           else if(PyInt_Check(o))
2118             f[i]=(double)PyInt_AS_LONG(o);
2119           else
2120             {
2121               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2122               throw INTERP_KERNEL::Exception(oss.str().c_str());
2123             }
2124         }
2125       sw=4;
2126       if(size%nbCompExpected!=0)
2127         {
2128           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
2129           throw INTERP_KERNEL::Exception(oss.str().c_str());
2130         }
2131       nbTuples=size/nbCompExpected;
2132       return &f[0];
2133     }
2134   if(PyList_Check(value))
2135     {
2136       int size=PyList_Size(value);
2137       f.resize(size);
2138       for(int i=0;i<size;i++)
2139         {
2140           PyObject *o=PyList_GetItem(value,i);
2141           if(PyFloat_Check(o))
2142             f[i]=PyFloat_AS_DOUBLE(o);
2143           else if(PyInt_Check(o))
2144             f[i]=(double)PyInt_AS_LONG(o);
2145           else
2146             {
2147               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2148               throw INTERP_KERNEL::Exception(oss.str().c_str());
2149             }
2150         }
2151       sw=4;
2152       if(size%nbCompExpected!=0)
2153         {
2154           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
2155           throw INTERP_KERNEL::Exception(oss.str().c_str());
2156         }
2157       nbTuples=size/nbCompExpected;
2158       return &f[0];
2159     }
2160   void *argp;
2161   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2162   if(SWIG_IsOK(status))
2163     {  
2164       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2165       sw=2;
2166       if(d)
2167         {
2168           if(d->getNumberOfComponents()==nbCompExpected)
2169             {
2170               nbTuples=d->getNumberOfTuples();
2171               return d->getConstPointer();
2172             }
2173           else
2174             {
2175               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2176               throw INTERP_KERNEL::Exception(oss.str().c_str());
2177             }
2178         }
2179       else
2180         {
2181           if(throwIfNullPt)
2182             {
2183               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2184               throw INTERP_KERNEL::Exception(oss.str().c_str());
2185             }
2186           else
2187             { nbTuples=0; return 0; }
2188         }
2189     }
2190   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2191   if(SWIG_IsOK(status))
2192     {  
2193       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2194       sw=3;
2195       if(e)
2196         {
2197           if(e->getNumberOfCompo()==nbCompExpected)
2198             {
2199               nbTuples=1;
2200               return e->getConstPointer();
2201             }
2202           else
2203             {
2204               std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2205               throw INTERP_KERNEL::Exception(oss.str().c_str());
2206             }
2207         }
2208       else
2209         {
2210           if(throwIfNullPt)
2211             {
2212               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2213               throw INTERP_KERNEL::Exception(oss.str().c_str());
2214             }
2215           else
2216             { nbTuples=0; return 0; }
2217         }
2218     }
2219   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2220 }
2221
2222 /*!
2223  * if value int -> cpp val sw=1
2224  * if value double -> cpp val sw=1
2225  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2226  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2227  * if value list[int,double] -> cpp std::vector<double> sw=4
2228  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2229  */
2230 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2231                                                           const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2232 {
2233   ParaMEDMEM::DataArrayDouble *d=0;
2234   ParaMEDMEM::DataArrayDoubleTuple *e=0;
2235   sw=-1;
2236   if(PyFloat_Check(value))
2237     {
2238       val=PyFloat_AS_DOUBLE(value);
2239       sw=1;
2240       nbTuples=1;
2241       return &val;
2242     }
2243   if(PyInt_Check(value))
2244     {
2245       val=(double)PyInt_AS_LONG(value);
2246       sw=1;
2247       nbTuples=1;
2248       return &val;
2249     }
2250   if(PyTuple_Check(value))
2251     {
2252       int size=PyTuple_Size(value);
2253       f.resize(size);
2254       for(int i=0;i<size;i++)
2255         {
2256           PyObject *o=PyTuple_GetItem(value,i);
2257           if(PyFloat_Check(o))
2258             f[i]=PyFloat_AS_DOUBLE(o);
2259           else if(PyInt_Check(o))
2260             f[i]=(double)PyInt_AS_LONG(o);
2261           else
2262             {
2263               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2264               throw INTERP_KERNEL::Exception(oss.str().c_str());
2265             }
2266         }
2267       sw=4;
2268       nbTuples=size;
2269       return &f[0];
2270     }
2271   if(PyList_Check(value))
2272     {
2273       int size=PyList_Size(value);
2274       f.resize(size);
2275       for(int i=0;i<size;i++)
2276         {
2277           PyObject *o=PyList_GetItem(value,i);
2278           if(PyFloat_Check(o))
2279             f[i]=PyFloat_AS_DOUBLE(o);
2280           else if(PyInt_Check(o))
2281             f[i]=(double)PyInt_AS_LONG(o);
2282           else
2283             {
2284               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2285               throw INTERP_KERNEL::Exception(oss.str().c_str());
2286             }
2287         }
2288       sw=4;
2289       nbTuples=size;
2290       return &f[0];
2291     }
2292   void *argp;
2293   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2294   if(SWIG_IsOK(status))
2295     {  
2296       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2297       sw=2;
2298       if(d)
2299         {
2300           if(d->getNumberOfComponents()==1)
2301             {
2302               nbTuples=d->getNumberOfTuples();
2303               return d->getConstPointer();
2304             }
2305           else
2306             {
2307               std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2308               throw INTERP_KERNEL::Exception(oss.str().c_str());
2309             }
2310         }
2311       else
2312         {
2313           if(throwIfNullPt)
2314             {
2315               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2316               throw INTERP_KERNEL::Exception(oss.str().c_str());
2317             }
2318           else
2319             { nbTuples=0; return 0; }
2320         }
2321     }
2322   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2323   if(SWIG_IsOK(status))
2324     {  
2325       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2326       sw=3;
2327       if(e)
2328         {
2329           nbTuples=e->getNumberOfCompo();
2330           return e->getConstPointer();
2331         }
2332       else
2333         {
2334           if(throwIfNullPt)
2335             {
2336               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2337               throw INTERP_KERNEL::Exception(oss.str().c_str());
2338             }
2339           else
2340             { nbTuples=0; return 0; }
2341         }
2342     }
2343   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2344 }
2345
2346 /*!
2347  * if python int -> cpp int sw=1
2348  * if python list[int] -> cpp vector<int> sw=2
2349  * if python tuple[int] -> cpp vector<int> sw=2
2350  * if python DataArrayInt -> cpp DataArrayInt sw=3
2351  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2352  *
2353  * switch between (int,vector<int>,DataArrayInt)
2354  */
2355 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2356 {
2357   sw=-1;
2358   if(PyInt_Check(value))
2359     {
2360       iTyypp=(int)PyInt_AS_LONG(value);
2361       sw=1; sz=1;
2362       return &iTyypp;
2363     }
2364   if(PyTuple_Check(value))
2365     {
2366       int size=PyTuple_Size(value);
2367       stdvecTyypp.resize(size);
2368       for(int i=0;i<size;i++)
2369         {
2370           PyObject *o=PyTuple_GetItem(value,i);
2371           if(PyInt_Check(o))
2372             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2373           else
2374             {
2375               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2376               throw INTERP_KERNEL::Exception(oss.str().c_str());
2377             }
2378         }
2379       sw=2; sz=size;
2380       return &stdvecTyypp[0];
2381     }
2382   if(PyList_Check(value))
2383     {
2384       int size=PyList_Size(value);
2385       stdvecTyypp.resize(size);
2386       for(int i=0;i<size;i++)
2387         {
2388           PyObject *o=PyList_GetItem(value,i);
2389           if(PyInt_Check(o))
2390             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2391           else
2392             {
2393               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2394               throw INTERP_KERNEL::Exception(oss.str().c_str());
2395             }
2396         }
2397       sw=2; sz=size;
2398       return &stdvecTyypp[0];
2399     }
2400   void *argp;
2401   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2402   if(SWIG_IsOK(status))
2403     {
2404       ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2405       if(daIntTyypp)
2406         {
2407           sw=3; sz=daIntTyypp->getNbOfElems();
2408           return daIntTyypp->begin();
2409         }
2410       else
2411         {
2412           sz=0;
2413           return 0;
2414         }
2415     }
2416   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2417   if(SWIG_IsOK(status))
2418     {  
2419       ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2420       sw=4; sz=daIntTuple->getNumberOfCompo();
2421       return daIntTuple->getConstPointer();
2422     }
2423   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2424 }
2425
2426 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2427 {
2428   void *aBasePtrVS=0;
2429   int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2430   if(!SWIG_IsOK(status))
2431     {
2432       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2433       if(!SWIG_IsOK(status))
2434         {
2435           status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2436           if(!SWIG_IsOK(status))
2437             {
2438               status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2439               if(!SWIG_IsOK(status))
2440                 {
2441                   status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2442                   std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2443                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2444                 }
2445             }
2446         }
2447     }
2448   return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);
2449 }