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