Salome HOME
numpy bindings for dense matrix
[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 convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
703 {
704   if(PyList_Check(pyLi))
705     {
706       int size=PyList_Size(pyLi);
707       arr.resize(size);
708       for(int i=0;i<size;i++)
709         {
710           PyObject *o=PyList_GetItem(pyLi,i);
711           if(PyInt_Check(o))
712             {
713               int val=(int)PyInt_AS_LONG(o);
714               arr[i]=val;
715             }
716           else
717             throw INTERP_KERNEL::Exception("list must contain integers only");
718         }
719     }
720   else if(PyTuple_Check(pyLi))
721     {
722       int size=PyTuple_Size(pyLi);
723       arr.resize(size);
724       for(int i=0;i<size;i++)
725         {
726           PyObject *o=PyTuple_GetItem(pyLi,i);
727           if(PyInt_Check(o))
728             {
729               int val=(int)PyInt_AS_LONG(o);
730               arr[i]=val;
731             }
732           else
733             throw INTERP_KERNEL::Exception("tuple must contain integers only");
734         }
735     }
736   else
737     {
738       throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
739     }
740 }
741
742 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
743 {
744   if(recurseLev<0)
745     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
746   arr.clear();
747   if(PyList_Check(pyLi))
748     {
749       int size=PyList_Size(pyLi);
750       for(int i=0;i<size;i++)
751         {
752           PyObject *o=PyList_GetItem(pyLi,i);
753           if(PyInt_Check(o))
754             {
755               int val=(int)PyInt_AS_LONG(o);
756               arr.push_back(val);
757             }
758           else
759             {
760               std::vector<int> arr2;
761               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
762               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
763                   {
764                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
765                     throw INTERP_KERNEL::Exception(oss.str().c_str());
766                   }
767               arr.insert(arr.end(),arr2.begin(),arr2.end());
768             }
769         }
770     }
771   else if(PyTuple_Check(pyLi))
772     {
773       int size=PyTuple_Size(pyLi);
774       for(int i=0;i<size;i++)
775         {
776           PyObject *o=PyTuple_GetItem(pyLi,i);
777           if(PyInt_Check(o))
778             {
779               int val=(int)PyInt_AS_LONG(o);
780               arr.push_back(val);
781             }
782           else
783             {
784               std::vector<int> arr2;
785               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
786               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
787                   {
788                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
789                     throw INTERP_KERNEL::Exception(oss.str().c_str());
790                   }
791               arr.insert(arr.end(),arr2.begin(),arr2.end());
792             }
793         }
794     }
795   else
796     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
797 }
798
799 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
800 {
801   if(nbOfTuples==-1)
802     {
803       if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
804       else { if(nbOfComp==size2) { nbOfTuples=size1; } else
805           {
806             std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
807             oss << " whereas nb of components expected is " << nbOfComp << " !";
808             throw INTERP_KERNEL::Exception(oss.str().c_str());
809           } }
810     }
811   else
812     {
813       if(nbOfComp!=-1)
814         {
815           if((nbOfTuples!=size1 || nbOfComp!=size2))
816             {
817               if(size2!=1 || size1!=nbOfComp*nbOfTuples)
818                 {
819                   std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
820                   oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
821                   throw INTERP_KERNEL::Exception(oss.str().c_str());
822                 }
823             }
824         }
825       else
826         {
827           if(nbOfTuples==size1)
828             nbOfComp=size2;
829           else
830             {
831               std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
832               oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
833               throw INTERP_KERNEL::Exception(oss.str().c_str());
834             }
835         }
836     }
837 }
838
839 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
840 {
841   static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
842   if(PyInt_Check(pyLi))
843     {
844       long val=PyInt_AS_LONG(pyLi);
845       if(nbOfElt==-1)
846         nbOfElt=1;
847       else
848         if(nbOfElt!=1)
849           throw INTERP_KERNEL::Exception(MSG);
850       ret.push_back(val);
851     }
852   else if(PyList_Check(pyLi))
853     {
854       int size=PyList_Size(pyLi);
855       int tmp=0;
856       for(int i=0;i<size;i++)
857         {
858           PyObject *o=PyList_GetItem(pyLi,i);
859           int tmp1=-1;
860           fillArrayWithPyListInt3(o,tmp1,ret);
861           tmp+=tmp1;
862         }
863       if(nbOfElt==-1)
864         nbOfElt=tmp;
865       else
866         {
867           if(nbOfElt!=tmp)
868             throw INTERP_KERNEL::Exception(MSG);
869         }
870     }
871   else if(PyTuple_Check(pyLi))
872     {
873       int size=PyTuple_Size(pyLi);
874       int tmp=0;
875       for(int i=0;i<size;i++)
876         {
877           PyObject *o=PyTuple_GetItem(pyLi,i);
878           int tmp1=-1;
879           fillArrayWithPyListInt3(o,tmp1,ret);
880           tmp+=tmp1;
881         }
882       if(nbOfElt==-1)
883         nbOfElt=tmp;
884       else
885         {
886           if(nbOfElt!=tmp)
887             throw INTERP_KERNEL::Exception(MSG);
888         }
889     }
890   else
891     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
892 }
893
894 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
895 {
896   std::vector<int> ret;
897   int size1=-1,size2=-1;
898   if(PyList_Check(pyLi))
899     {
900       size1=PyList_Size(pyLi);
901       for(int i=0;i<size1;i++)
902         {
903           PyObject *o=PyList_GetItem(pyLi,i);
904           fillArrayWithPyListInt3(o,size2,ret);
905         }
906       if(size1==0)
907         size2=1;
908     }
909   else if(PyTuple_Check(pyLi))
910     {
911       size1=PyTuple_Size(pyLi);
912       for(int i=0;i<size1;i++)
913         {
914           PyObject *o=PyTuple_GetItem(pyLi,i);
915           fillArrayWithPyListInt3(o,size2,ret);
916         }
917       if(size1==0)
918         size2=1;
919     }
920   else
921     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
922   //
923   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
924   return ret;
925 }
926
927 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
928 {
929   if(PyList_Check(pyLi))
930     {
931       Py_ssize_t sz=PyList_Size(pyLi);
932       vec.resize(sz);
933       for(int i=0;i<sz;i++)
934         {
935           PyObject *o=PyList_GetItem(pyLi,i);
936           if(PyString_Check(o))
937             vec[i]=PyString_AsString(o);
938           else
939             return false;
940         }
941       return true;
942     }
943   else if(PyTuple_Check(pyLi))
944     {
945       Py_ssize_t sz=PyTuple_Size(pyLi);
946       vec.resize(sz);
947       for(int i=0;i<sz;i++)
948         {
949           PyObject *o=PyTuple_GetItem(pyLi,i);
950           if(PyString_Check(o))
951             vec[i]=PyString_AsString(o);
952           else
953             return false;
954         }
955       return true;
956     }
957   else
958     return false;
959 }
960
961 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
962 {
963   PyObject *ret=PyList_New(size);
964   for(int i=0;i<size;i++)
965     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
966   return ret;
967 }
968
969 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
970 {
971   int size=v.size();
972   PyObject *ret=PyList_New(size);
973   for(int i=0;i<size;i++)
974     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
975   return ret;
976 }
977
978 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
979 {
980   PyObject *ret=PyList_New(nbOfTuples);
981   for(int i=0;i<nbOfTuples;i++)
982     {
983       PyObject *t=PyTuple_New(nbOfComp);
984       for(int j=0;j<nbOfComp;j++)
985         PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
986       PyList_SetItem(ret,i,t);
987     }
988   return ret;
989 }
990
991 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
992 {
993   PyObject *ret=PyList_New(nbOfTuples);
994   INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
995   for(int i=0;i<nbOfTuples;i++)
996     {
997       std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
998       PyList_SetItem(ret,i,PyString_FromString(tmp));
999     }
1000   return ret;
1001 }
1002
1003 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1004 {
1005   if(PyList_Check(pyLi))
1006     {
1007       *size=PyList_Size(pyLi);
1008       double *tmp=(double *)malloc((*size)*sizeof(double));
1009       for(int i=0;i<*size;i++)
1010         {
1011           PyObject *o=PyList_GetItem(pyLi,i);
1012           if(PyFloat_Check(o))
1013             {
1014               double val=PyFloat_AS_DOUBLE(o);
1015               tmp[i]=val;
1016             }
1017           else if(PyInt_Check(o))
1018             {
1019               long val0=PyInt_AS_LONG(o);
1020               double val=val0;
1021               tmp[i]=val;
1022             }
1023           else
1024             {
1025               free(tmp);
1026               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1027             }
1028         }
1029       return tmp;
1030     }
1031   else if(PyTuple_Check(pyLi))
1032     {
1033       *size=PyTuple_Size(pyLi);
1034       double *tmp=(double *)malloc((*size)*sizeof(double));
1035       for(int i=0;i<*size;i++)
1036         {
1037           PyObject *o=PyTuple_GetItem(pyLi,i);
1038           if(PyFloat_Check(o))
1039             {
1040               double val=PyFloat_AS_DOUBLE(o);
1041               tmp[i]=val;
1042             }
1043           else if(PyInt_Check(o))
1044             {
1045               long val0=PyInt_AS_LONG(o);
1046               double val=val0;
1047               tmp[i]=val;
1048             }
1049           else
1050             {
1051               free(tmp);
1052               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1053             }
1054         }
1055       return tmp;
1056     }
1057   else
1058     throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1059 }
1060
1061 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1062 {
1063   static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1064   if(PyFloat_Check(pyLi))
1065     {
1066       if(nbOfElt==-1)
1067         nbOfElt=1;
1068       else
1069         if(nbOfElt!=1)
1070           throw INTERP_KERNEL::Exception(MSG);
1071       double val=PyFloat_AS_DOUBLE(pyLi);
1072       ret.push_back(val);
1073     }
1074   else if(PyInt_Check(pyLi))
1075     {
1076       long val0=PyInt_AS_LONG(pyLi);
1077       double val=val0;
1078       if(nbOfElt==-1)
1079         nbOfElt=1;
1080       else
1081         if(nbOfElt!=1)
1082           throw INTERP_KERNEL::Exception(MSG);
1083       ret.push_back(val);
1084     }
1085   else if(PyList_Check(pyLi))
1086     {
1087       int size=PyList_Size(pyLi);
1088       int tmp=0;
1089       for(int i=0;i<size;i++)
1090         {
1091           PyObject *o=PyList_GetItem(pyLi,i);
1092           int tmp1=-1;
1093           fillArrayWithPyListDbl3(o,tmp1,ret);
1094           tmp+=tmp1;
1095         }
1096       if(nbOfElt==-1)
1097         nbOfElt=tmp;
1098       else
1099         {
1100           if(nbOfElt!=tmp)
1101             throw INTERP_KERNEL::Exception(MSG);
1102         }
1103     }
1104   else if(PyTuple_Check(pyLi))
1105     {
1106       int size=PyTuple_Size(pyLi);
1107       int tmp=0;
1108       for(int i=0;i<size;i++)
1109         {
1110           PyObject *o=PyTuple_GetItem(pyLi,i);
1111           int tmp1=-1;
1112           fillArrayWithPyListDbl3(o,tmp1,ret);
1113           tmp+=tmp1;
1114         }
1115       if(nbOfElt==-1)
1116         nbOfElt=tmp;
1117       else
1118         {
1119           if(nbOfElt!=tmp)
1120             throw INTERP_KERNEL::Exception(MSG);
1121         }
1122     }
1123   else
1124     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1125 }
1126
1127 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1128 {
1129   std::vector<double> ret;
1130   int size1=-1,size2=-1;
1131   if(PyList_Check(pyLi))
1132     {
1133       size1=PyList_Size(pyLi);
1134       for(int i=0;i<size1;i++)
1135         {
1136           PyObject *o=PyList_GetItem(pyLi,i);
1137           fillArrayWithPyListDbl3(o,size2,ret);
1138         }
1139       if(size1==0)
1140         size2=1;
1141     }
1142   else if(PyTuple_Check(pyLi))
1143     {
1144       size1=PyTuple_Size(pyLi);
1145       for(int i=0;i<size1;i++)
1146         {
1147           PyObject *o=PyTuple_GetItem(pyLi,i);
1148           fillArrayWithPyListDbl3(o,size2,ret);
1149         }
1150       if(size1==0)
1151         size2=1;
1152     }
1153   else
1154     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1155   //
1156   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1157   return ret;
1158 }
1159
1160 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1161 template<class T>
1162 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1163 {
1164   void *argp=0;
1165   if(PyList_Check(pyLi))
1166     {
1167       int size=PyList_Size(pyLi);
1168       ret.resize(size);
1169       for(int i=0;i<size;i++)
1170         {
1171           PyObject *obj=PyList_GetItem(pyLi,i);
1172           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1173           if(!SWIG_IsOK(status))
1174             {
1175               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1176               throw INTERP_KERNEL::Exception(oss.str().c_str());
1177             }
1178           T arg=reinterpret_cast< T >(argp);
1179           ret[i]=arg;
1180         }
1181     }
1182   else if(PyTuple_Check(pyLi))
1183     {
1184       int size=PyTuple_Size(pyLi);
1185       ret.resize(size);
1186       for(int i=0;i<size;i++)
1187         {
1188           PyObject *obj=PyTuple_GetItem(pyLi,i);
1189           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1190           if(!SWIG_IsOK(status))
1191             {
1192               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1193               throw INTERP_KERNEL::Exception(oss.str().c_str());
1194             }
1195           T arg=reinterpret_cast< T >(argp);
1196           ret[i]=arg;
1197         }
1198     }
1199   else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1200     {
1201       ret.resize(1);
1202       T arg=reinterpret_cast< T >(argp);
1203       ret[0]=arg;
1204     }
1205   else
1206     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1207 }
1208
1209 /*!
1210  * if python int -> cpp int sw=1
1211  * if python list[int] -> cpp vector<int> sw=2
1212  * if python tuple[int] -> cpp vector<int> sw=2
1213  * if python DataArrayInt -> cpp DataArrayInt sw=3
1214  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1215  *
1216  * switch between (int,vector<int>,DataArrayInt)
1217  */
1218 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1219 {
1220   sw=-1;
1221   if(PyInt_Check(value))
1222     {
1223       iTyypp=(int)PyInt_AS_LONG(value);
1224       sw=1;
1225       return;
1226     }
1227   if(PyTuple_Check(value))
1228     {
1229       int size=PyTuple_Size(value);
1230       stdvecTyypp.resize(size);
1231       for(int i=0;i<size;i++)
1232         {
1233           PyObject *o=PyTuple_GetItem(value,i);
1234           if(PyInt_Check(o))
1235             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1236           else
1237             {
1238               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1239               throw INTERP_KERNEL::Exception(oss.str().c_str());
1240             }
1241         }
1242       sw=2;
1243       return;
1244     }
1245   if(PyList_Check(value))
1246     {
1247       int size=PyList_Size(value);
1248       stdvecTyypp.resize(size);
1249       for(int i=0;i<size;i++)
1250         {
1251           PyObject *o=PyList_GetItem(value,i);
1252           if(PyInt_Check(o))
1253             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1254           else
1255             {
1256               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1257               throw INTERP_KERNEL::Exception(oss.str().c_str());
1258             }
1259         }
1260       sw=2;
1261       return;
1262     }
1263   void *argp;
1264   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1265   if(SWIG_IsOK(status))
1266     {
1267       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1268       sw=3;
1269       return;
1270     }
1271   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1272   if(SWIG_IsOK(status))
1273     {  
1274       daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1275       sw=4;
1276       return ;
1277     }
1278   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1279 }
1280
1281 /*!
1282  * if python double -> cpp double sw=1
1283  * if python int -> cpp double sw=1
1284  * if python list[double] -> cpp vector<double> sw=2
1285  * if python list[int] -> cpp vector<double> sw=2
1286  * if python tuple[double] -> cpp vector<double> sw=2
1287  * if python tuple[int] -> cpp vector<double> sw=2
1288  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1289  *
1290  * switch between (int,vector<int>,DataArrayInt)
1291  */
1292 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1293 {
1294   sw=-1;
1295   if(PyFloat_Check(value))
1296     {
1297       iTyypp=PyFloat_AS_DOUBLE(value);
1298       sw=1;
1299       return;
1300     }
1301   if(PyInt_Check(value))
1302     {
1303       iTyypp=(double)PyInt_AS_LONG(value);
1304       sw=1;
1305       return;
1306     }
1307   if(PyTuple_Check(value))
1308     {
1309       int size=PyTuple_Size(value);
1310       stdvecTyypp.resize(size);
1311       for(int i=0;i<size;i++)
1312         {
1313           PyObject *o=PyTuple_GetItem(value,i);
1314           if(PyFloat_Check(o))
1315             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1316           else if(PyInt_Check(o))
1317             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1318           else
1319             {
1320               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1321               throw INTERP_KERNEL::Exception(oss.str().c_str());
1322             }
1323         }
1324       sw=2;
1325       return;
1326     }
1327   if(PyList_Check(value))
1328     {
1329       int size=PyList_Size(value);
1330       stdvecTyypp.resize(size);
1331       for(int i=0;i<size;i++)
1332         {
1333           PyObject *o=PyList_GetItem(value,i);
1334           if(PyFloat_Check(o))
1335             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1336           else if(PyInt_Check(o))
1337             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1338           else
1339             {
1340               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1341               throw INTERP_KERNEL::Exception(oss.str().c_str());
1342             }
1343         }
1344       sw=2;
1345       return;
1346     }
1347   void *argp;
1348   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1349   if(!SWIG_IsOK(status))
1350     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1351   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1352   sw=3;
1353 }
1354
1355 /*!
1356  * if python double -> cpp double sw=1
1357  * if python int -> cpp double sw=1
1358  * if python list[double] -> cpp vector<double> sw=2
1359  * if python list[int] -> cpp vector<double> sw=2
1360  * if python tuple[double] -> cpp vector<double> sw=2
1361  * if python tuple[int] -> cpp vector<double> sw=2
1362  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1363  *
1364  * switch between (int,vector<int>,DataArrayInt)
1365  */
1366 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1367 {
1368   sw=-1;
1369   if(PyFloat_Check(value))
1370     {
1371       iTyypp=PyFloat_AS_DOUBLE(value);
1372       sw=1;
1373       return;
1374     }
1375   if(PyInt_Check(value))
1376     {
1377       iTyypp=(double)PyInt_AS_LONG(value);
1378       sw=1;
1379       return;
1380     }
1381   if(PyTuple_Check(value))
1382     {
1383       int size=PyTuple_Size(value);
1384       stdvecTyypp.resize(size);
1385       for(int i=0;i<size;i++)
1386         {
1387           PyObject *o=PyTuple_GetItem(value,i);
1388           if(PyFloat_Check(o))
1389             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1390           else if(PyInt_Check(o))
1391             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1392           else
1393             {
1394               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1395               throw INTERP_KERNEL::Exception(oss.str().c_str());
1396             }
1397         }
1398       sw=2;
1399       return;
1400     }
1401   if(PyList_Check(value))
1402     {
1403       int size=PyList_Size(value);
1404       stdvecTyypp.resize(size);
1405       for(int i=0;i<size;i++)
1406         {
1407           PyObject *o=PyList_GetItem(value,i);
1408           if(PyFloat_Check(o))
1409             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1410           else if(PyInt_Check(o))
1411             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1412           else
1413             {
1414               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1415               throw INTERP_KERNEL::Exception(oss.str().c_str());
1416             }
1417         }
1418       sw=2;
1419       return;
1420     }
1421   void *argp;
1422   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1423   if(!SWIG_IsOK(status))
1424     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1425   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1426   sw=3;
1427 }
1428
1429 /*!
1430  * if python int -> cpp int sw=1
1431  * if python list[int] -> cpp vector<int> sw=2
1432  * if python tuple[int] -> cpp vector<int> sw=2
1433  * if python slicp -> cpp pair sw=3 (begin,end,step)
1434  * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1435  *
1436  * switch between (int,vector<int>,DataArrayInt)
1437  */
1438 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)
1439 {
1440   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1441   sw=-1;
1442   if(PyInt_Check(value))
1443     {
1444       iTyypp=(int)PyInt_AS_LONG(value);
1445       sw=1;
1446       return;
1447     }
1448   if(PyTuple_Check(value))
1449     {
1450       int size=PyTuple_Size(value);
1451       stdvecTyypp.resize(size);
1452       for(int i=0;i<size;i++)
1453         {
1454           PyObject *o=PyTuple_GetItem(value,i);
1455           if(PyInt_Check(o))
1456             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1457           else
1458             {
1459               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1460               throw INTERP_KERNEL::Exception(oss.str().c_str());
1461             }
1462         }
1463       sw=2;
1464       return;
1465     }
1466   if(PyList_Check(value))
1467     {
1468       int size=PyList_Size(value);
1469       stdvecTyypp.resize(size);
1470       for(int i=0;i<size;i++)
1471         {
1472           PyObject *o=PyList_GetItem(value,i);
1473           if(PyInt_Check(o))
1474             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1475           else
1476             {
1477               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1478               throw INTERP_KERNEL::Exception(oss.str().c_str());
1479             }
1480         }
1481       sw=2;
1482       return;
1483     }
1484   if(PySlice_Check(value))
1485     {
1486       Py_ssize_t strt=2,stp=2,step=2;
1487       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1488       GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1489       p.first=strt;
1490       p.second.first=stp;
1491       p.second.second=step;
1492       sw=3;
1493       return ;
1494     }
1495   void *argp;
1496   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1497   if(SWIG_IsOK(status))
1498     {
1499       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1500       if(!daIntTyypp)
1501         {
1502           std::ostringstream oss; oss << msg << " Instance in null !";
1503           throw INTERP_KERNEL::Exception(oss.str().c_str());
1504         }
1505       sw=4;
1506       return ;
1507     }
1508   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1509   if(SWIG_IsOK(status))
1510     {
1511       ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1512       if(!tmp)
1513         {
1514           std::ostringstream oss; oss << msg << " Instance in null !";
1515           throw INTERP_KERNEL::Exception(oss.str().c_str());
1516         }
1517       stdvecTyypp.resize(tmp->getNumberOfCompo());
1518       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1519       sw=2;
1520       return ;
1521     }
1522   throw INTERP_KERNEL::Exception(msg);
1523 }
1524
1525 /*!
1526  * Idem than convertObjToPossibleCpp2
1527  */
1528 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)
1529 {
1530   convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1531   if(sw==1)
1532     {
1533       iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1534     }
1535 }
1536
1537 /*!
1538  * if python int -> cpp int sw=1
1539  * if python tuple[int] -> cpp vector<int> sw=2
1540  * if python list[int] -> cpp vector<int> sw=2
1541  * if python slice -> cpp pair sw=3
1542  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1543  */
1544 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)
1545 {
1546   sw=-1;
1547   if(PyInt_Check(value))
1548     {
1549       iTyypp=(int)PyInt_AS_LONG(value);
1550       sw=1;
1551       return;
1552     }
1553   if(PyTuple_Check(value))
1554     {
1555       int size=PyTuple_Size(value);
1556       stdvecTyypp.resize(size);
1557       for(int i=0;i<size;i++)
1558         {
1559           PyObject *o=PyTuple_GetItem(value,i);
1560           if(PyInt_Check(o))
1561             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1562           else
1563             {
1564               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1565               throw INTERP_KERNEL::Exception(oss.str().c_str());
1566             }
1567         }
1568       sw=2;
1569       return;
1570     }
1571   if(PyList_Check(value))
1572     {
1573       int size=PyList_Size(value);
1574       stdvecTyypp.resize(size);
1575       for(int i=0;i<size;i++)
1576         {
1577           PyObject *o=PyList_GetItem(value,i);
1578           if(PyInt_Check(o))
1579             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1580           else
1581             {
1582               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1583               throw INTERP_KERNEL::Exception(oss.str().c_str());
1584             }
1585         }
1586       sw=2;
1587       return;
1588     }
1589   if(PySlice_Check(value))
1590     {
1591       Py_ssize_t strt=2,stp=2,step=2;
1592       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1593       GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1594       p.first=strt;
1595       p.second.first=stp;
1596       p.second.second=step;
1597       sw=3;
1598       return ;
1599     }
1600   void *argp;
1601   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1602   if(!SWIG_IsOK(status))
1603     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1604   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1605   sw=4;
1606 }
1607
1608 /*!
1609  * if python string with size one -> cpp char sw=1
1610  * if python string with size different from one -> cpp string sw=2
1611  * if python tuple[string] or list[string] -> vector<string> sw=3
1612  * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1613  * switch between (int,string,vector<string>,DataArrayChar)
1614  */
1615 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1616 {
1617   const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1618   sw=-1;
1619   if(PyString_Check(value))
1620     {
1621       const char *pt=PyString_AsString(value);
1622       Py_ssize_t sz=PyString_Size(value);
1623       if(sz==1)
1624         {
1625           cTyp=pt[0];
1626           sw=1;
1627           return;
1628         }
1629       else
1630         {
1631           sType=pt;
1632           sw=2;
1633           return;
1634         }
1635     }
1636   if(PyTuple_Check(value))
1637     {
1638       int size=PyTuple_Size(value);
1639       vsType.resize(size);
1640       for(int i=0;i<size;i++)
1641         {
1642           PyObject *o=PyTuple_GetItem(value,i);
1643           if(PyString_Check(o))
1644             vsType[i]=PyString_AsString(o);
1645           else
1646             {
1647               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1648               throw INTERP_KERNEL::Exception(oss.str().c_str());
1649             }
1650         }
1651       sw=3;
1652       return;
1653     }
1654   if(PyList_Check(value))
1655     {
1656       int size=PyList_Size(value);
1657       vsType.resize(size);
1658       for(int i=0;i<size;i++)
1659         {
1660           PyObject *o=PyList_GetItem(value,i);
1661           if(PyString_Check(o))
1662             vsType[i]=PyString_AsString(o);
1663           else
1664             {
1665               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1666               throw INTERP_KERNEL::Exception(oss.str().c_str());
1667             }
1668         }
1669       sw=3;
1670       return;
1671     }
1672   void *argp;
1673   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1674   if(SWIG_IsOK(status))
1675     {
1676       dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1677       if(!dacType)
1678         {
1679           std::ostringstream oss; oss << msg << " Instance in null !";
1680           throw INTERP_KERNEL::Exception(oss.str().c_str());
1681         }
1682       sw=4;
1683       return ;
1684     }
1685   throw INTERP_KERNEL::Exception(msg);
1686 }
1687
1688 /*!
1689  * if value int -> cpp it sw=1
1690  * if value list[int] -> vt sw=2
1691  * if value tuple[int] -> vt sw=2
1692  * if value slice -> pt sw=3
1693  * if value DataArrayInt -> dt sw=4
1694  * if value tuple [int,int] -> cpp it,ip sw=5
1695  * if value tuple [list[int],int] -> cpp vt,ip sw=6
1696  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1697  * if value tuple [slice,int] -> cpp pt,ip sw=7
1698  * if value tuple [DaI,int] -> cpp dt,ip sw=8
1699  * if value tuple [int,list[int]] -> cpp it,vc sw=9
1700  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1701  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1702  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1703  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1704  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1705  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1706  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1707  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1708  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1709  * if value tuple [int,slice] -> cpp it,pc sw=13
1710  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1711  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1712  * if value tuple [slice,slice] -> cpp pt,pc sw=15
1713  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1714  *
1715  * switch between (int,vector<int>,DataArrayInt)
1716  */
1717 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1718                                      std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1719                                      ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1720 {
1721   if(!PyTuple_Check(value))
1722     {
1723       convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1724       return ;
1725     }
1726   else
1727     {
1728       int sz=PyTuple_Size(value);
1729       if(sz!=2)
1730         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1731       PyObject *ob0=PyTuple_GetItem(value,0);
1732       int sw1,sw2;
1733       convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1734       PyObject *ob1=PyTuple_GetItem(value,1);
1735       convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1736       sw=4*sw2+sw1;
1737     }
1738 }
1739
1740 /*!
1741  * if value int -> cpp val sw=1
1742  * if value double -> cpp val sw=1
1743  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1744  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1745  * if value list[int,double] -> cpp std::vector<double> sw=4
1746  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1747  */
1748 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1749 {
1750   sw=-1;
1751   if(PyFloat_Check(value))
1752     {
1753       val=PyFloat_AS_DOUBLE(value);
1754       sw=1;
1755       return;
1756     }
1757   if(PyInt_Check(value))
1758     {
1759       val=(double)PyInt_AS_LONG(value);
1760       sw=1;
1761       return;
1762     }
1763   if(PyTuple_Check(value))
1764     {
1765       int size=PyTuple_Size(value);
1766       f.resize(size);
1767       for(int i=0;i<size;i++)
1768         {
1769           PyObject *o=PyTuple_GetItem(value,i);
1770           if(PyFloat_Check(o))
1771             f[i]=PyFloat_AS_DOUBLE(o);
1772           else if(PyInt_Check(o))
1773             f[i]=(double)PyInt_AS_LONG(o);
1774           else
1775             {
1776               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1777               throw INTERP_KERNEL::Exception(oss.str().c_str());
1778             }
1779         }
1780       sw=4;
1781       return;
1782     }
1783   if(PyList_Check(value))
1784     {
1785       int size=PyList_Size(value);
1786       f.resize(size);
1787       for(int i=0;i<size;i++)
1788         {
1789           PyObject *o=PyList_GetItem(value,i);
1790           if(PyFloat_Check(o))
1791             f[i]=PyFloat_AS_DOUBLE(o);
1792           else if(PyInt_Check(o))
1793             f[i]=(double)PyInt_AS_LONG(o);
1794           else
1795             {
1796               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1797               throw INTERP_KERNEL::Exception(oss.str().c_str());
1798             }
1799         }
1800       sw=4;
1801       return;
1802     }
1803   void *argp;
1804   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1805   if(SWIG_IsOK(status))
1806     {  
1807       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1808       sw=2;
1809       return ;
1810     }
1811   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1812   if(SWIG_IsOK(status))
1813     {  
1814       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1815       sw=3;
1816       return ;
1817     }
1818   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1819 }
1820
1821 /*!
1822  * if value int -> cpp val sw=1
1823  * if value double -> cpp val sw=1
1824  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1825  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1826  * if value list[int,double] -> cpp std::vector<double> sw=4
1827  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1828  */
1829 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1830                                                    const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1831 {
1832   sw=-1;
1833   if(PyFloat_Check(value))
1834     {
1835       val=PyFloat_AS_DOUBLE(value);
1836       sw=1;
1837       if(nbTuplesExpected*nbCompExpected!=1)
1838         {
1839           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1840           throw INTERP_KERNEL::Exception(oss.str().c_str());
1841         }
1842       return &val;
1843     }
1844   if(PyInt_Check(value))
1845     {
1846       val=(double)PyInt_AS_LONG(value);
1847       sw=1;
1848       if(nbTuplesExpected*nbCompExpected!=1)
1849         {
1850           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1851           throw INTERP_KERNEL::Exception(oss.str().c_str());
1852         }
1853       return &val;
1854     }
1855   if(PyTuple_Check(value) || PyList_Check(value))
1856     {
1857       try
1858         {
1859           int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1860           std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1861           sw=4;
1862           f=ret;
1863           return &f[0];
1864         }
1865       catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1866     }
1867   void *argp;
1868   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1869   if(SWIG_IsOK(status))
1870     {  
1871       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1872       sw=2;
1873       if(d)
1874         {
1875           if(d->getNumberOfTuples()==nbTuplesExpected)
1876             {
1877               if(d->getNumberOfComponents()==nbCompExpected)
1878                 {
1879                   return d->getConstPointer();
1880                 }
1881               else
1882                 {
1883                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1884                   throw INTERP_KERNEL::Exception(oss.str().c_str());
1885                 }
1886             }
1887           else
1888             {
1889               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1890               throw INTERP_KERNEL::Exception(oss.str().c_str());
1891             }
1892         }
1893       else
1894         {
1895           if(throwIfNullPt)
1896             {
1897               std::ostringstream oss; oss << msg << " null pointer not accepted!";
1898               throw INTERP_KERNEL::Exception(oss.str().c_str());
1899             }
1900           else
1901             return 0;
1902         }
1903     }
1904   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1905   if(SWIG_IsOK(status))
1906     {  
1907       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1908       sw=3;
1909       if(e->getNumberOfCompo()==nbCompExpected)
1910         {
1911           if(nbTuplesExpected==1)
1912             return e->getConstPointer();
1913           else
1914             {
1915               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1916               throw INTERP_KERNEL::Exception(oss.str().c_str());
1917             }
1918         }
1919       else
1920         {
1921           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1922           throw INTERP_KERNEL::Exception(oss.str().c_str());
1923         }
1924     }
1925   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1926 }
1927
1928 /*!
1929  * if value int -> cpp val sw=1
1930  * if value double -> cpp val sw=1
1931  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1932  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1933  * if value list[int,double] -> cpp std::vector<double> sw=4
1934  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1935  */
1936 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1937                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1938 {
1939   sw=-1;
1940   if(PyFloat_Check(value))
1941     {
1942       val=PyFloat_AS_DOUBLE(value);
1943       sw=1;
1944       if(nbCompExpected!=1)
1945         {
1946           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1947           throw INTERP_KERNEL::Exception(oss.str().c_str());
1948         }
1949       nbTuples=1;
1950       return &val;
1951     }
1952   if(PyInt_Check(value))
1953     {
1954       val=(double)PyInt_AS_LONG(value);
1955       sw=1;
1956       if(nbCompExpected!=1)
1957         {
1958           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1959           throw INTERP_KERNEL::Exception(oss.str().c_str());
1960         }
1961       nbTuples=1;
1962       return &val;
1963     }
1964   if(PyTuple_Check(value))
1965     {
1966       int size=PyTuple_Size(value);
1967       f.resize(size);
1968       for(int i=0;i<size;i++)
1969         {
1970           PyObject *o=PyTuple_GetItem(value,i);
1971           if(PyFloat_Check(o))
1972             f[i]=PyFloat_AS_DOUBLE(o);
1973           else if(PyInt_Check(o))
1974             f[i]=(double)PyInt_AS_LONG(o);
1975           else
1976             {
1977               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1978               throw INTERP_KERNEL::Exception(oss.str().c_str());
1979             }
1980         }
1981       sw=4;
1982       if(size%nbCompExpected!=0)
1983         {
1984           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1985           throw INTERP_KERNEL::Exception(oss.str().c_str());
1986         }
1987       nbTuples=size/nbCompExpected;
1988       return &f[0];
1989     }
1990   if(PyList_Check(value))
1991     {
1992       int size=PyList_Size(value);
1993       f.resize(size);
1994       for(int i=0;i<size;i++)
1995         {
1996           PyObject *o=PyList_GetItem(value,i);
1997           if(PyFloat_Check(o))
1998             f[i]=PyFloat_AS_DOUBLE(o);
1999           else if(PyInt_Check(o))
2000             f[i]=(double)PyInt_AS_LONG(o);
2001           else
2002             {
2003               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2004               throw INTERP_KERNEL::Exception(oss.str().c_str());
2005             }
2006         }
2007       sw=4;
2008       if(size%nbCompExpected!=0)
2009         {
2010           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
2011           throw INTERP_KERNEL::Exception(oss.str().c_str());
2012         }
2013       nbTuples=size/nbCompExpected;
2014       return &f[0];
2015     }
2016   void *argp;
2017   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2018   if(SWIG_IsOK(status))
2019     {  
2020       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2021       sw=2;
2022       if(d)
2023         {
2024           if(d->getNumberOfComponents()==nbCompExpected)
2025             {
2026               nbTuples=d->getNumberOfTuples();
2027               return d->getConstPointer();
2028             }
2029           else
2030             {
2031               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2032               throw INTERP_KERNEL::Exception(oss.str().c_str());
2033             }
2034         }
2035       else
2036         {
2037           if(throwIfNullPt)
2038             {
2039               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2040               throw INTERP_KERNEL::Exception(oss.str().c_str());
2041             }
2042           else
2043             { nbTuples=0; return 0; }
2044         }
2045     }
2046   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2047   if(SWIG_IsOK(status))
2048     {  
2049       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2050       sw=3;
2051       if(e)
2052         {
2053           if(e->getNumberOfCompo()==nbCompExpected)
2054             {
2055               nbTuples=1;
2056               return e->getConstPointer();
2057             }
2058           else
2059             {
2060               std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2061               throw INTERP_KERNEL::Exception(oss.str().c_str());
2062             }
2063         }
2064       else
2065         {
2066           if(throwIfNullPt)
2067             {
2068               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2069               throw INTERP_KERNEL::Exception(oss.str().c_str());
2070             }
2071           else
2072             { nbTuples=0; return 0; }
2073         }
2074     }
2075   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2076 }
2077
2078 /*!
2079  * if value int -> cpp val sw=1
2080  * if value double -> cpp val sw=1
2081  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2082  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2083  * if value list[int,double] -> cpp std::vector<double> sw=4
2084  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2085  */
2086 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2087                                                           const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2088 {
2089   ParaMEDMEM::DataArrayDouble *d=0;
2090   ParaMEDMEM::DataArrayDoubleTuple *e=0;
2091   sw=-1;
2092   if(PyFloat_Check(value))
2093     {
2094       val=PyFloat_AS_DOUBLE(value);
2095       sw=1;
2096       nbTuples=1;
2097       return &val;
2098     }
2099   if(PyInt_Check(value))
2100     {
2101       val=(double)PyInt_AS_LONG(value);
2102       sw=1;
2103       nbTuples=1;
2104       return &val;
2105     }
2106   if(PyTuple_Check(value))
2107     {
2108       int size=PyTuple_Size(value);
2109       f.resize(size);
2110       for(int i=0;i<size;i++)
2111         {
2112           PyObject *o=PyTuple_GetItem(value,i);
2113           if(PyFloat_Check(o))
2114             f[i]=PyFloat_AS_DOUBLE(o);
2115           else if(PyInt_Check(o))
2116             f[i]=(double)PyInt_AS_LONG(o);
2117           else
2118             {
2119               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2120               throw INTERP_KERNEL::Exception(oss.str().c_str());
2121             }
2122         }
2123       sw=4;
2124       nbTuples=size;
2125       return &f[0];
2126     }
2127   if(PyList_Check(value))
2128     {
2129       int size=PyList_Size(value);
2130       f.resize(size);
2131       for(int i=0;i<size;i++)
2132         {
2133           PyObject *o=PyList_GetItem(value,i);
2134           if(PyFloat_Check(o))
2135             f[i]=PyFloat_AS_DOUBLE(o);
2136           else if(PyInt_Check(o))
2137             f[i]=(double)PyInt_AS_LONG(o);
2138           else
2139             {
2140               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2141               throw INTERP_KERNEL::Exception(oss.str().c_str());
2142             }
2143         }
2144       sw=4;
2145       nbTuples=size;
2146       return &f[0];
2147     }
2148   void *argp;
2149   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2150   if(SWIG_IsOK(status))
2151     {  
2152       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2153       sw=2;
2154       if(d)
2155         {
2156           if(d->getNumberOfComponents()==1)
2157             {
2158               nbTuples=d->getNumberOfTuples();
2159               return d->getConstPointer();
2160             }
2161           else
2162             {
2163               std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2164               throw INTERP_KERNEL::Exception(oss.str().c_str());
2165             }
2166         }
2167       else
2168         {
2169           if(throwIfNullPt)
2170             {
2171               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2172               throw INTERP_KERNEL::Exception(oss.str().c_str());
2173             }
2174           else
2175             { nbTuples=0; return 0; }
2176         }
2177     }
2178   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2179   if(SWIG_IsOK(status))
2180     {  
2181       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2182       sw=3;
2183       if(e)
2184         {
2185           nbTuples=e->getNumberOfCompo();
2186           return e->getConstPointer();
2187         }
2188       else
2189         {
2190           if(throwIfNullPt)
2191             {
2192               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2193               throw INTERP_KERNEL::Exception(oss.str().c_str());
2194             }
2195           else
2196             { nbTuples=0; return 0; }
2197         }
2198     }
2199   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2200 }
2201
2202 /*!
2203  * if python int -> cpp int sw=1
2204  * if python list[int] -> cpp vector<int> sw=2
2205  * if python tuple[int] -> cpp vector<int> sw=2
2206  * if python DataArrayInt -> cpp DataArrayInt sw=3
2207  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2208  *
2209  * switch between (int,vector<int>,DataArrayInt)
2210  */
2211 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2212 {
2213   sw=-1;
2214   if(PyInt_Check(value))
2215     {
2216       iTyypp=(int)PyInt_AS_LONG(value);
2217       sw=1; sz=1;
2218       return &iTyypp;
2219     }
2220   if(PyTuple_Check(value))
2221     {
2222       int size=PyTuple_Size(value);
2223       stdvecTyypp.resize(size);
2224       for(int i=0;i<size;i++)
2225         {
2226           PyObject *o=PyTuple_GetItem(value,i);
2227           if(PyInt_Check(o))
2228             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2229           else
2230             {
2231               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2232               throw INTERP_KERNEL::Exception(oss.str().c_str());
2233             }
2234         }
2235       sw=2; sz=size;
2236       return &stdvecTyypp[0];
2237     }
2238   if(PyList_Check(value))
2239     {
2240       int size=PyList_Size(value);
2241       stdvecTyypp.resize(size);
2242       for(int i=0;i<size;i++)
2243         {
2244           PyObject *o=PyList_GetItem(value,i);
2245           if(PyInt_Check(o))
2246             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2247           else
2248             {
2249               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2250               throw INTERP_KERNEL::Exception(oss.str().c_str());
2251             }
2252         }
2253       sw=2; sz=size;
2254       return &stdvecTyypp[0];
2255     }
2256   void *argp;
2257   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2258   if(SWIG_IsOK(status))
2259     {
2260       ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2261       if(daIntTyypp)
2262         {
2263           sw=3; sz=daIntTyypp->getNbOfElems();
2264           return daIntTyypp->begin();
2265         }
2266       else
2267         {
2268           sz=0;
2269           return 0;
2270         }
2271     }
2272   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2273   if(SWIG_IsOK(status))
2274     {  
2275       ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2276       sw=4; sz=daIntTuple->getNumberOfCompo();
2277       return daIntTuple->getConstPointer();
2278     }
2279   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2280 }
2281
2282 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2283 {
2284   void *aBasePtrVS=0;
2285   int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2286   if(!SWIG_IsOK(status))
2287     {
2288       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2289       if(!SWIG_IsOK(status))
2290         {
2291           status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2292           if(!SWIG_IsOK(status))
2293             {
2294               status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2295               if(!SWIG_IsOK(status))
2296                 {
2297                   status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2298                   std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2299                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2300                 }
2301             }
2302         }
2303     }
2304   return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);
2305 }