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