Salome HOME
Merge from V6_main 13/12/2012
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingTypemaps.i
1 // Copyright (C) 2007-2012  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.
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
20 #ifdef WITH_NUMPY2
21 #include <numpy/arrayobject.h>
22 #endif
23
24 static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
25 {
26   PyObject *ret=0;
27   if(dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(mesh))
28     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner);
29   if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
30     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
31   if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
32     ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
33   if(!ret)
34     throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
35   return ret;
36 }
37
38 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
39 {
40   PyObject *ret=0;
41   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
42     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
43   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
44     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
45   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
46     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
47   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
48     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
49   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
50     ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
51   if(!ret)
52     throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
53   return ret;
54 }
55
56 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
57 {
58   PyObject *ret=0;
59   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
60     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
61   else
62     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
63   return ret;
64 }
65
66 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
67 {
68 #ifndef WITH_NUMPY2
69   PyObject *ret=PyList_New(size);
70   for(int i=0;i<size;i++)
71     PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
72   return ret;
73 #else
74   npy_intp dim = (npy_intp) size;
75   int *tmp=new int[size];
76   std::copy(ptr,ptr+size,tmp);
77   return PyArray_SimpleNewFromData(1,&dim,NPY_INT,const_cast<int *>(tmp));
78 #endif
79 }
80
81 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
82 {
83 #ifndef WITH_NUMPY2
84   int size=v.size();
85   PyObject *ret=PyList_New(size);
86   for(int i=0;i<size;i++)
87     PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
88   return ret;
89 #else
90   npy_intp dim = (npy_intp) v.size();
91   int *tmp=new int[v.size()];
92   std::copy(v.begin(),v.end(),tmp);
93   return PyArray_SimpleNewFromData(1,&dim,NPY_INT,tmp);
94 #endif
95 }
96
97 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
98 {
99   int size=v.size();
100   PyObject *ret=PyList_New(size);
101   std::set<int>::const_iterator it=v.begin();
102   for(int i=0;i<size;i++,it++)
103     PyList_SetItem(ret,i,PyInt_FromLong(*it));
104   return ret;
105 }
106
107 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
108 {
109   PyObject *ret=PyList_New(nbOfTuples);
110   for(int i=0;i<nbOfTuples;i++)
111     {
112       PyObject *t=PyTuple_New(nbOfComp);
113       for(int j=0;j<nbOfComp;j++)
114         PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
115       PyList_SetItem(ret,i,t);
116     }
117   return ret;
118 }
119
120 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
121 {
122   if(PyList_Check(pyLi))
123     {
124       *size=PyList_Size(pyLi);
125       int *tmp=new int[*size];
126       for(int i=0;i<*size;i++)
127         {
128           PyObject *o=PyList_GetItem(pyLi,i);
129           if(PyInt_Check(o))
130             {
131               int val=(int)PyInt_AS_LONG(o);
132               tmp[i]=val;
133             }
134           else
135             {
136               delete [] tmp;
137               throw INTERP_KERNEL::Exception("list must contain integers only");
138             }
139         }
140       return tmp;
141     }
142   else if(PyTuple_Check(pyLi))
143     {
144       *size=PyTuple_Size(pyLi);
145       int *tmp=new int[*size];
146       for(int i=0;i<*size;i++)
147         {
148           PyObject *o=PyTuple_GetItem(pyLi,i);
149           if(PyInt_Check(o))
150             {
151               int val=(int)PyInt_AS_LONG(o);
152               tmp[i]=val;
153             }
154           else
155             {
156               delete [] tmp;
157               throw INTERP_KERNEL::Exception("tuple must contain integers only");
158             }
159         }
160       return tmp;
161     }
162   else
163     {
164 #ifndef WITH_NUMPY2
165       throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
166 #else
167       if(PyArray_Check(pyLi))
168         {
169           npy_intp mySize = PyArray_SIZE(pyLi);
170           int *ret=(int *)PyArray_BYTES(pyLi);
171           *size=mySize;
172           return ret;
173         }
174       else
175         {
176           throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list nor PyArray");
177         }
178 #endif
179     }
180 }
181
182 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
183 {
184   const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
185   if(PyList_Check(pyLi))
186     {
187       int size=PyList_Size(pyLi);
188       arr.resize(size);
189       for(int i=0;i<size;i++)
190         {
191           PyObject *o=PyList_GetItem(pyLi,i);
192           if(PyTuple_Check(o))
193             {
194               int sz2=PyTuple_Size(o);
195               if(sz2!=2)
196                 throw INTERP_KERNEL::Exception(msg);
197               PyObject *o_0=PyTuple_GetItem(o,0);
198               if(!PyInt_Check(o_0))
199                 throw INTERP_KERNEL::Exception(msg);
200               PyObject *o_1=PyTuple_GetItem(o,1);
201               if(!PyInt_Check(o_1))
202                 throw INTERP_KERNEL::Exception(msg);
203               arr[i].first=(int)PyInt_AS_LONG(o_0);
204               arr[i].second=(int)PyInt_AS_LONG(o_1);
205             }
206           else
207             throw INTERP_KERNEL::Exception(msg);
208         }
209     }
210   else if(PyTuple_Check(pyLi))
211     {
212       int size=PyTuple_Size(pyLi);
213       arr.resize(size);
214       for(int i=0;i<size;i++)
215         {
216           PyObject *o=PyTuple_GetItem(pyLi,i);
217           if(PyTuple_Check(o))
218             {
219               int sz2=PyTuple_Size(o);
220               if(sz2!=2)
221                 throw INTERP_KERNEL::Exception(msg);
222               PyObject *o_0=PyTuple_GetItem(o,0);
223               if(!PyInt_Check(o_0))
224                 throw INTERP_KERNEL::Exception(msg);
225               PyObject *o_1=PyTuple_GetItem(o,1);
226               if(!PyInt_Check(o_1))
227                 throw INTERP_KERNEL::Exception(msg);
228               arr[i].first=(int)PyInt_AS_LONG(o_0);
229               arr[i].second=(int)PyInt_AS_LONG(o_1);
230             }
231           else
232             throw INTERP_KERNEL::Exception(msg);
233         }
234     }
235   else
236     throw INTERP_KERNEL::Exception(msg);
237 }
238
239 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
240 {
241   if(PyList_Check(pyLi))
242     {
243       int size=PyList_Size(pyLi);
244       arr.resize(size);
245       for(int i=0;i<size;i++)
246         {
247           PyObject *o=PyList_GetItem(pyLi,i);
248           if(PyInt_Check(o))
249             {
250               int val=(int)PyInt_AS_LONG(o);
251               arr[i]=val;
252             }
253           else
254             throw INTERP_KERNEL::Exception("list must contain integers only");
255         }
256     }
257   else if(PyTuple_Check(pyLi))
258     {
259       int size=PyTuple_Size(pyLi);
260       arr.resize(size);
261       for(int i=0;i<size;i++)
262         {
263           PyObject *o=PyTuple_GetItem(pyLi,i);
264           if(PyInt_Check(o))
265             {
266               int val=(int)PyInt_AS_LONG(o);
267               arr[i]=val;
268             }
269           else
270             throw INTERP_KERNEL::Exception("tuple must contain integers only");
271         }
272     }
273   else
274     {
275 #ifndef WITH_NUMPY2
276       throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
277 #else
278       if(PyArray_Check(pyLi))
279         {
280           npy_intp mySize = PyArray_SIZE(pyLi);
281           int *ret=(int *)PyArray_BYTES(pyLi);
282           arr.resize(mySize);
283           std::copy(ret,ret+mySize,arr.begin());
284           return ;
285         }
286       else
287         throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple nor PyArray");
288 #endif
289     }
290 }
291
292 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
293 {
294   if(recurseLev<0)
295     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
296   arr.clear();
297   if(PyList_Check(pyLi))
298     {
299       int size=PyList_Size(pyLi);
300       for(int i=0;i<size;i++)
301         {
302           PyObject *o=PyList_GetItem(pyLi,i);
303           if(PyInt_Check(o))
304             {
305               int val=(int)PyInt_AS_LONG(o);
306               arr.push_back(val);
307             }
308           else
309             {
310               std::vector<int> arr2;
311               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
312               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
313                   {
314                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
315                     throw INTERP_KERNEL::Exception(oss.str().c_str());
316                   }
317               arr.insert(arr.end(),arr2.begin(),arr2.end());
318             }
319         }
320     }
321   else if(PyTuple_Check(pyLi))
322     {
323       int size=PyTuple_Size(pyLi);
324       for(int i=0;i<size;i++)
325         {
326           PyObject *o=PyTuple_GetItem(pyLi,i);
327           if(PyInt_Check(o))
328             {
329               int val=(int)PyInt_AS_LONG(o);
330               arr.push_back(val);
331             }
332           else
333             {
334               std::vector<int> arr2;
335               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
336               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
337                   {
338                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
339                     throw INTERP_KERNEL::Exception(oss.str().c_str());
340                   }
341               arr.insert(arr.end(),arr2.begin(),arr2.end());
342             }
343         }
344     }
345   else
346     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
347 }
348
349 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
350 {
351   if(nbOfTuples==-1)
352     {
353       if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
354       else { if(nbOfComp==size2) { nbOfTuples=size1; } else
355           {
356             std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
357             oss << " whereas nb of components expected is " << nbOfComp << " !";
358             throw INTERP_KERNEL::Exception(oss.str().c_str());
359           } }
360     }
361   else
362     {
363       if(nbOfComp!=-1)
364         {
365           if((nbOfTuples!=size1 || nbOfComp!=size2))
366             {
367               if(size2!=1 || size1!=nbOfComp*nbOfTuples)
368                 {
369                   std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
370                   oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
371                   throw INTERP_KERNEL::Exception(oss.str().c_str());
372                 }
373             }
374         }
375       else
376         {
377           if(nbOfTuples==size1)
378             nbOfComp=size2;
379           else
380             {
381               std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
382               oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
383               throw INTERP_KERNEL::Exception(oss.str().c_str());
384             }
385         }
386     }
387 }
388
389 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
390 {
391   static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
392   if(PyInt_Check(pyLi))
393     {
394       long val=PyInt_AS_LONG(pyLi);
395       if(nbOfElt==-1)
396         nbOfElt=1;
397       else
398         if(nbOfElt!=1)
399           throw INTERP_KERNEL::Exception(MSG);
400       ret.push_back(val);
401     }
402   else if(PyList_Check(pyLi))
403     {
404       int size=PyList_Size(pyLi);
405       int tmp=0;
406       for(int i=0;i<size;i++)
407         {
408           PyObject *o=PyList_GetItem(pyLi,i);
409           int tmp1=-1;
410           fillArrayWithPyListInt3(o,tmp1,ret);
411           tmp+=tmp1;
412         }
413       if(nbOfElt==-1)
414         nbOfElt=tmp;
415       else
416         {
417           if(nbOfElt!=tmp)
418             throw INTERP_KERNEL::Exception(MSG);
419         }
420     }
421   else if(PyTuple_Check(pyLi))
422     {
423       int size=PyTuple_Size(pyLi);
424       int tmp=0;
425       for(int i=0;i<size;i++)
426         {
427           PyObject *o=PyTuple_GetItem(pyLi,i);
428           int tmp1=-1;
429           fillArrayWithPyListInt3(o,tmp1,ret);
430           tmp+=tmp1;
431         }
432       if(nbOfElt==-1)
433         nbOfElt=tmp;
434       else
435         {
436           if(nbOfElt!=tmp)
437             throw INTERP_KERNEL::Exception(MSG);
438         }
439     }
440   else
441     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
442 }
443
444 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
445 {
446   std::vector<int> ret;
447   int size1=-1,size2=-1;
448   if(PyList_Check(pyLi))
449     {
450       size1=PyList_Size(pyLi);
451       for(int i=0;i<size1;i++)
452         {
453           PyObject *o=PyList_GetItem(pyLi,i);
454           fillArrayWithPyListInt3(o,size2,ret);
455         }
456     }
457   else if(PyTuple_Check(pyLi))
458     {
459       size1=PyTuple_Size(pyLi);
460       for(int i=0;i<size1;i++)
461         {
462           PyObject *o=PyTuple_GetItem(pyLi,i);
463           fillArrayWithPyListInt3(o,size2,ret);
464         }
465     }
466   else
467     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
468   //
469   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
470   return ret;
471 }
472
473 /*
474  * will become obsolete -> fillArrayWithPyListInt2
475  */
476 static void fillArrayWithPyListInt(PyObject *pyLi, int *arrToFill, int sizeOfArray, int dftVal, bool chckSize) throw(INTERP_KERNEL::Exception)
477 {
478   if(PyList_Check(pyLi))
479     {
480       int size=PyList_Size(pyLi);
481       if(chckSize)
482         if(size!=sizeOfArray)
483           {
484             std::ostringstream oss; oss << "fillArrayWithPyListInt : List expected to be of size " << sizeOfArray << " but the size is " << size << " !";
485             throw INTERP_KERNEL::Exception(oss.str().c_str());
486           }
487       for(int i=0;i<size;i++)
488         {
489           PyObject *o=PyList_GetItem(pyLi,i);
490           if(PyInt_Check(o))
491             {
492               int val=(int)PyInt_AS_LONG(o);
493               if(i<sizeOfArray)
494                 arrToFill[i]=val;
495             }
496           else
497             throw INTERP_KERNEL::Exception("fillArrayWithPyListInt : List must contain integers only !");
498         }
499       for(int i=size;i<sizeOfArray;i++)
500         arrToFill[i]=dftVal;
501       return;
502       
503     }
504   else if(PyTuple_Check(pyLi))
505     {
506       int size=PyTuple_Size(pyLi);
507       if(chckSize)
508         if(size!=sizeOfArray)
509           {
510             std::ostringstream oss; oss << "fillArrayWithPyListInt : Tuple expected to be of size " << sizeOfArray << " but the size is " << size << " !";
511             throw INTERP_KERNEL::Exception(oss.str().c_str());
512           }
513       for(int i=0;i<size;i++)
514         {
515           PyObject *o=PyTuple_GetItem(pyLi,i);
516           if(PyInt_Check(o))
517             {
518               int val=(int)PyInt_AS_LONG(o);
519               if(i<sizeOfArray)
520                 arrToFill[i]=val;
521             }
522           else
523             throw INTERP_KERNEL::Exception("tuple must contain integers only");
524         }
525       for(int i=size;i<sizeOfArray;i++)
526         arrToFill[i]=dftVal;
527       return;
528     }
529   else
530     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt : not a list");
531 }
532
533 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
534 {
535   PyObject *ret=PyList_New(size);
536   for(int i=0;i<size;i++)
537     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
538   return ret;
539 }
540
541 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
542 {
543   int size=v.size();
544   PyObject *ret=PyList_New(size);
545   for(int i=0;i<size;i++)
546     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
547   return ret;
548 }
549
550 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
551 {
552   PyObject *ret=PyList_New(nbOfTuples);
553   for(int i=0;i<nbOfTuples;i++)
554     {
555       PyObject *t=PyTuple_New(nbOfComp);
556       for(int j=0;j<nbOfComp;j++)
557         PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
558       PyList_SetItem(ret,i,t);
559     }
560   return ret;
561 }
562
563 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
564 {
565   if(PyList_Check(pyLi))
566     {
567       *size=PyList_Size(pyLi);
568       double *tmp=new double[*size];
569       for(int i=0;i<*size;i++)
570         {
571           PyObject *o=PyList_GetItem(pyLi,i);
572           if(PyFloat_Check(o))
573             {
574               double val=PyFloat_AS_DOUBLE(o);
575               tmp[i]=val;
576             }
577           else if(PyInt_Check(o))
578             {
579               long val0=PyInt_AS_LONG(o);
580               double val=val0;
581               tmp[i]=val;
582             }
583           else
584             {
585               delete [] tmp;
586               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
587             }
588         }
589       return tmp;
590     }
591   else if(PyTuple_Check(pyLi))
592     {
593       *size=PyTuple_Size(pyLi);
594       double *tmp=new double[*size];
595       for(int i=0;i<*size;i++)
596         {
597           PyObject *o=PyTuple_GetItem(pyLi,i);
598           if(PyFloat_Check(o))
599             {
600               double val=PyFloat_AS_DOUBLE(o);
601               tmp[i]=val;
602             }
603           else if(PyInt_Check(o))
604             {
605               long val0=PyInt_AS_LONG(o);
606               double val=val0;
607               tmp[i]=val;
608             }
609           else
610             {
611               delete [] tmp;
612               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
613             }
614         }
615       return tmp;
616     }
617   else
618     throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
619 }
620
621 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
622 {
623   static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
624   if(PyFloat_Check(pyLi))
625     {
626       if(nbOfElt==-1)
627         nbOfElt=1;
628       else
629         if(nbOfElt!=1)
630           throw INTERP_KERNEL::Exception(MSG);
631       double val=PyFloat_AS_DOUBLE(pyLi);
632       ret.push_back(val);
633     }
634   else if(PyInt_Check(pyLi))
635     {
636       long val0=PyInt_AS_LONG(pyLi);
637       double val=val0;
638       if(nbOfElt==-1)
639         nbOfElt=1;
640       else
641         if(nbOfElt!=1)
642           throw INTERP_KERNEL::Exception(MSG);
643       ret.push_back(val);
644     }
645   else if(PyList_Check(pyLi))
646     {
647       int size=PyList_Size(pyLi);
648       int tmp=0;
649       for(int i=0;i<size;i++)
650         {
651           PyObject *o=PyList_GetItem(pyLi,i);
652           int tmp1=-1;
653           fillArrayWithPyListDbl3(o,tmp1,ret);
654           tmp+=tmp1;
655         }
656       if(nbOfElt==-1)
657         nbOfElt=tmp;
658       else
659         {
660           if(nbOfElt!=tmp)
661             throw INTERP_KERNEL::Exception(MSG);
662         }
663     }
664   else if(PyTuple_Check(pyLi))
665     {
666       int size=PyTuple_Size(pyLi);
667       int tmp=0;
668       for(int i=0;i<size;i++)
669         {
670           PyObject *o=PyTuple_GetItem(pyLi,i);
671           int tmp1=-1;
672           fillArrayWithPyListDbl3(o,tmp1,ret);
673           tmp+=tmp1;
674         }
675       if(nbOfElt==-1)
676         nbOfElt=tmp;
677       else
678         {
679           if(nbOfElt!=tmp)
680             throw INTERP_KERNEL::Exception(MSG);
681         }
682     }
683   else
684     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
685 }
686
687 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
688 {
689   std::vector<double> ret;
690   int size1=-1,size2=-1;
691   if(PyList_Check(pyLi))
692     {
693       size1=PyList_Size(pyLi);
694       for(int i=0;i<size1;i++)
695         {
696           PyObject *o=PyList_GetItem(pyLi,i);
697           fillArrayWithPyListDbl3(o,size2,ret);
698         }
699     }
700   else if(PyTuple_Check(pyLi))
701     {
702       size1=PyTuple_Size(pyLi);
703       for(int i=0;i<size1;i++)
704         {
705           PyObject *o=PyTuple_GetItem(pyLi,i);
706           fillArrayWithPyListDbl3(o,size2,ret);
707         }
708     }
709   else
710     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
711   //
712   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
713   return ret;
714 }
715
716 /*
717  * will become obsolete -> fillArrayWithPyListDbl2
718  */
719 static void fillArrayWithPyListDbl(PyObject *pyLi, double *arrToFill, int sizeOfArray, double dftVal, bool chckSize) throw(INTERP_KERNEL::Exception)
720 {
721   if(PyList_Check(pyLi))
722     {
723       int size=PyList_Size(pyLi);
724       if(chckSize)
725         if(size!=sizeOfArray)
726           {
727             std::ostringstream oss; oss << "fillArrayWithPyListDbl : List expected to be of size " << sizeOfArray << " but the size is " << size << " !";
728             throw INTERP_KERNEL::Exception(oss.str().c_str());
729           }
730       for(int i=0;i<size;i++)
731         {
732           PyObject *o=PyList_GetItem(pyLi,i);
733           if(PyFloat_Check(o))
734             {
735               double val=PyFloat_AS_DOUBLE(o);
736               if(i<sizeOfArray)
737                 arrToFill[i]=val;
738             }
739           else if(PyInt_Check(o))
740             {
741               long val0=PyInt_AS_LONG(o);
742               double val=val0;
743               if(i<sizeOfArray)
744                 arrToFill[i]=val;
745             }
746           else
747             throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : list must contain floats/integers only");
748         }
749       for(int i=size;i<sizeOfArray;i++)
750         arrToFill[i]=dftVal;
751       return;
752     }
753   else if(PyTuple_Check(pyLi))
754     {
755       int size=PyTuple_Size(pyLi);
756       if(chckSize)
757         if(size!=sizeOfArray)
758           {
759             std::ostringstream oss; oss << "fillArrayWithPyListDbl : Tuple expected to be of size " << sizeOfArray << " but the size is " << size << " !";
760             throw INTERP_KERNEL::Exception(oss.str().c_str());
761           }
762       for(int i=0;i<size;i++)
763         {
764           PyObject *o=PyTuple_GetItem(pyLi,i);
765           if(PyFloat_Check(o))
766             {
767               double val=PyFloat_AS_DOUBLE(o);
768               arrToFill[i]=val;
769             }
770           else if(PyInt_Check(o))
771             {
772               long val0=PyInt_AS_LONG(o);
773               double val=val0;
774               arrToFill[i]=val;
775             }
776           else
777             throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : tuple must contain floats/integers only");
778         }
779       for(int i=size;i<sizeOfArray;i++)
780         arrToFill[i]=dftVal;
781       return ;
782     }
783   else
784     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : not a list nor a tuple");
785 }
786
787 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
788 template<class T>
789 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
790 {
791   void *argp=0;
792   if(PyList_Check(pyLi))
793     {
794       int size=PyList_Size(pyLi);
795       ret.resize(size);
796       for(int i=0;i<size;i++)
797         {
798           PyObject *obj=PyList_GetItem(pyLi,i);
799           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
800           if(!SWIG_IsOK(status))
801             throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
802           T arg=reinterpret_cast< T >(argp);
803           ret[i]=arg;
804         }
805     }
806   else if(PyTuple_Check(pyLi))
807     {
808       int size=PyTuple_Size(pyLi);
809       ret.resize(size);
810       for(int i=0;i<size;i++)
811         {
812           PyObject *obj=PyTuple_GetItem(pyLi,i);
813           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
814           if(!SWIG_IsOK(status))
815             {
816               std::ostringstream oss; oss << "tuple must contain only " << typeStr;
817               throw INTERP_KERNEL::Exception(oss.str().c_str());
818             }
819           T arg=reinterpret_cast< T >(argp);
820           ret[i]=arg;
821         }
822     }
823   else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
824     {
825       ret.resize(1);
826       T arg=reinterpret_cast< T >(argp);
827       ret[0]=arg;
828     }
829   else
830     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
831 }
832
833 /*!
834  * if python int -> cpp int sw=1
835  * if python list[int] -> cpp vector<int> sw=2
836  * if python tuple[int] -> cpp vector<int> sw=2
837  * if python DataArrayInt -> cpp DataArrayInt sw=3
838  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
839  *
840  * switch between (int,vector<int>,DataArrayInt)
841  */
842 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
843 {
844   sw=-1;
845   if(PyInt_Check(value))
846     {
847       iTyypp=(int)PyInt_AS_LONG(value);
848       sw=1;
849       return;
850     }
851   if(PyTuple_Check(value))
852     {
853       int size=PyTuple_Size(value);
854       stdvecTyypp.resize(size);
855       for(int i=0;i<size;i++)
856         {
857           PyObject *o=PyTuple_GetItem(value,i);
858           if(PyInt_Check(o))
859             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
860           else
861             {
862               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
863               throw INTERP_KERNEL::Exception(oss.str().c_str());
864             }
865         }
866       sw=2;
867       return;
868     }
869   if(PyList_Check(value))
870     {
871       int size=PyList_Size(value);
872       stdvecTyypp.resize(size);
873       for(int i=0;i<size;i++)
874         {
875           PyObject *o=PyList_GetItem(value,i);
876           if(PyInt_Check(o))
877             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
878           else
879             {
880               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
881               throw INTERP_KERNEL::Exception(oss.str().c_str());
882             }
883         }
884       sw=2;
885       return;
886     }
887   void *argp;
888   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
889   if(SWIG_IsOK(status))
890     {
891       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
892       sw=3;
893       return;
894     }
895   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
896   if(SWIG_IsOK(status))
897     {  
898       daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
899       sw=4;
900       return ;
901     }
902   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
903 }
904
905 /*!
906  * if python double -> cpp double sw=1
907  * if python int -> cpp double sw=1
908  * if python list[double] -> cpp vector<double> sw=2
909  * if python list[int] -> cpp vector<double> sw=2
910  * if python tuple[double] -> cpp vector<double> sw=2
911  * if python tuple[int] -> cpp vector<double> sw=2
912  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
913  *
914  * switch between (int,vector<int>,DataArrayInt)
915  */
916 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
917 {
918   sw=-1;
919   if(PyFloat_Check(value))
920     {
921       iTyypp=PyFloat_AS_DOUBLE(value);
922       sw=1;
923       return;
924     }
925   if(PyInt_Check(value))
926     {
927       iTyypp=(double)PyInt_AS_LONG(value);
928       sw=1;
929       return;
930     }
931   if(PyTuple_Check(value))
932     {
933       int size=PyTuple_Size(value);
934       stdvecTyypp.resize(size);
935       for(int i=0;i<size;i++)
936         {
937           PyObject *o=PyTuple_GetItem(value,i);
938           if(PyFloat_Check(o))
939             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
940           else if(PyInt_Check(o))
941             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
942           else
943             {
944               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
945               throw INTERP_KERNEL::Exception(oss.str().c_str());
946             }
947         }
948       sw=2;
949       return;
950     }
951   if(PyList_Check(value))
952     {
953       int size=PyList_Size(value);
954       stdvecTyypp.resize(size);
955       for(int i=0;i<size;i++)
956         {
957           PyObject *o=PyList_GetItem(value,i);
958           if(PyFloat_Check(o))
959             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
960           else if(PyInt_Check(o))
961             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
962           else
963             {
964               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
965               throw INTERP_KERNEL::Exception(oss.str().c_str());
966             }
967         }
968       sw=2;
969       return;
970     }
971   void *argp;
972   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
973   if(!SWIG_IsOK(status))
974     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
975   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
976   sw=3;
977 }
978
979 /*!
980  * if python double -> cpp double sw=1
981  * if python int -> cpp double sw=1
982  * if python list[double] -> cpp vector<double> sw=2
983  * if python list[int] -> cpp vector<double> sw=2
984  * if python tuple[double] -> cpp vector<double> sw=2
985  * if python tuple[int] -> cpp vector<double> sw=2
986  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
987  *
988  * switch between (int,vector<int>,DataArrayInt)
989  */
990 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
991 {
992   sw=-1;
993   if(PyFloat_Check(value))
994     {
995       iTyypp=PyFloat_AS_DOUBLE(value);
996       sw=1;
997       return;
998     }
999   if(PyInt_Check(value))
1000     {
1001       iTyypp=(double)PyInt_AS_LONG(value);
1002       sw=1;
1003       return;
1004     }
1005   if(PyTuple_Check(value))
1006     {
1007       int size=PyTuple_Size(value);
1008       stdvecTyypp.resize(size);
1009       for(int i=0;i<size;i++)
1010         {
1011           PyObject *o=PyTuple_GetItem(value,i);
1012           if(PyFloat_Check(o))
1013             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1014           else if(PyInt_Check(o))
1015             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1016           else
1017             {
1018               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1019               throw INTERP_KERNEL::Exception(oss.str().c_str());
1020             }
1021         }
1022       sw=2;
1023       return;
1024     }
1025   if(PyList_Check(value))
1026     {
1027       int size=PyList_Size(value);
1028       stdvecTyypp.resize(size);
1029       for(int i=0;i<size;i++)
1030         {
1031           PyObject *o=PyList_GetItem(value,i);
1032           if(PyFloat_Check(o))
1033             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1034           else if(PyInt_Check(o))
1035             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1036           else
1037             {
1038               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1039               throw INTERP_KERNEL::Exception(oss.str().c_str());
1040             }
1041         }
1042       sw=2;
1043       return;
1044     }
1045   void *argp;
1046   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1047   if(!SWIG_IsOK(status))
1048     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1049   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1050   sw=3;
1051 }
1052
1053 /*!
1054  * if python int -> cpp int sw=1
1055  * if python list[int] -> cpp vector<int> sw=2
1056  * if python tuple[int] -> cpp vector<int> sw=2
1057  * if python slicp -> cpp pair sw=3
1058  * if python DataArrayInt -> cpp DataArrayInt sw=4
1059  *
1060  * switch between (int,vector<int>,DataArrayInt)
1061  */
1062 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)
1063 {
1064   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1065   sw=-1;
1066   if(PyInt_Check(value))
1067     {
1068       iTyypp=(int)PyInt_AS_LONG(value);
1069       sw=1;
1070       return;
1071     }
1072   if(PyTuple_Check(value))
1073     {
1074       int size=PyTuple_Size(value);
1075       stdvecTyypp.resize(size);
1076       for(int i=0;i<size;i++)
1077         {
1078           PyObject *o=PyTuple_GetItem(value,i);
1079           if(PyInt_Check(o))
1080             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1081           else
1082             {
1083               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1084               throw INTERP_KERNEL::Exception(oss.str().c_str());
1085             }
1086         }
1087       sw=2;
1088       return;
1089     }
1090   if(PyList_Check(value))
1091     {
1092       int size=PyList_Size(value);
1093       stdvecTyypp.resize(size);
1094       for(int i=0;i<size;i++)
1095         {
1096           PyObject *o=PyList_GetItem(value,i);
1097           if(PyInt_Check(o))
1098             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1099           else
1100             {
1101               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1102               throw INTERP_KERNEL::Exception(oss.str().c_str());
1103             }
1104         }
1105       sw=2;
1106       return;
1107     }
1108   if(PySlice_Check(value))
1109     {
1110       Py_ssize_t strt,stp,step;
1111       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1112       if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1113         {
1114           std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elemnts is : " << nbelem;
1115           throw INTERP_KERNEL::Exception(oss.str().c_str());
1116         }
1117       p.first=strt;
1118       p.second.first=stp;
1119       p.second.second=step;
1120       sw=3;
1121       return ;
1122     }
1123   void *argp;
1124   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1125   if(SWIG_IsOK(status))
1126     {
1127       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1128       if(!daIntTyypp)
1129         {
1130           std::ostringstream oss; oss << msg << " Instance in null !";
1131           throw INTERP_KERNEL::Exception(oss.str().c_str());
1132         }
1133       sw=4;
1134       return ;
1135     }
1136   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);;
1137   if(SWIG_IsOK(status))
1138     {
1139       ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1140       if(!tmp)
1141         {
1142           std::ostringstream oss; oss << msg << " Instance in null !";
1143           throw INTERP_KERNEL::Exception(oss.str().c_str());
1144         }
1145       stdvecTyypp.resize(tmp->getNumberOfCompo());
1146       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1147       sw=2;
1148       return ;
1149     }
1150   throw INTERP_KERNEL::Exception(msg);
1151 }
1152
1153 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)
1154 {
1155   sw=-1;
1156   if(PyInt_Check(value))
1157     {
1158       iTyypp=(int)PyInt_AS_LONG(value);
1159       sw=1;
1160       return;
1161     }
1162   if(PyTuple_Check(value))
1163     {
1164       int size=PyTuple_Size(value);
1165       stdvecTyypp.resize(size);
1166       for(int i=0;i<size;i++)
1167         {
1168           PyObject *o=PyTuple_GetItem(value,i);
1169           if(PyInt_Check(o))
1170             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1171           else
1172             {
1173               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1174               throw INTERP_KERNEL::Exception(oss.str().c_str());
1175             }
1176         }
1177       sw=2;
1178       return;
1179     }
1180   if(PyList_Check(value))
1181     {
1182       int size=PyList_Size(value);
1183       stdvecTyypp.resize(size);
1184       for(int i=0;i<size;i++)
1185         {
1186           PyObject *o=PyList_GetItem(value,i);
1187           if(PyInt_Check(o))
1188             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1189           else
1190             {
1191               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1192               throw INTERP_KERNEL::Exception(oss.str().c_str());
1193             }
1194         }
1195       sw=2;
1196       return;
1197     }
1198   if(PySlice_Check(value))
1199     {
1200       Py_ssize_t strt,stp,step;
1201       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1202       if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1203         {
1204           std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elemnts is : " << nbelem;
1205           throw INTERP_KERNEL::Exception(oss.str().c_str());
1206         }
1207       p.first=strt;
1208       p.second.first=stp;
1209       p.second.second=step;
1210       sw=3;
1211       return ;
1212     }
1213   void *argp;
1214   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1215   if(!SWIG_IsOK(status))
1216     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1217   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1218   sw=4;
1219 }
1220
1221 /*!
1222  * if value int -> cpp it sw=1
1223  * if value list[int] -> vt sw=2
1224  * if value tuple[int] -> vt sw=2
1225  * if value slice -> pt sw=3
1226  * if value DataArrayInt -> dt sw=4
1227  * if value tuple [int,int] -> cpp it,ip sw=5
1228  * if value tuple [list[int],int] -> cpp vt,ip sw=6
1229  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1230  * if value tuple [slice,int] -> cpp pt,ip sw=7
1231  * if value tuple [DaI,int] -> cpp dt,ip sw=8
1232  * if value tuple [int,list[int]] -> cpp it,vc sw=9
1233  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1234  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1235  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1236  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1237  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1238  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1239  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1240  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1241  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1242  * if value tuple [int,slice] -> cpp it,pc sw=13
1243  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1244  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1245  * if value tuple [slice,slice] -> cpp pt,pc sw=15
1246  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1247  *
1248  * switch between (int,vector<int>,DataArrayInt)
1249  */
1250 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1251                                      std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1252                                      ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1253 {
1254   if(!PyTuple_Check(value))
1255     {
1256       convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1257       return ;
1258     }
1259   else
1260     {
1261       int sz=PyTuple_Size(value);
1262       if(sz!=2)
1263         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1264       PyObject *ob0=PyTuple_GetItem(value,0);
1265       int sw1,sw2;
1266       convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1267       PyObject *ob1=PyTuple_GetItem(value,1);
1268       convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1269       sw=4*sw2+sw1;
1270     }
1271 }
1272
1273 /*!
1274  * if value int -> cpp val sw=1
1275  * if value double -> cpp val sw=1
1276  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1277  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1278  * if value list[int,double] -> cpp std::vector<double> sw=4
1279  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1280  */
1281 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1282 {
1283   sw=-1;
1284   if(PyFloat_Check(value))
1285     {
1286       val=PyFloat_AS_DOUBLE(value);
1287       sw=1;
1288       return;
1289     }
1290   if(PyInt_Check(value))
1291     {
1292       val=(double)PyInt_AS_LONG(value);
1293       sw=1;
1294       return;
1295     }
1296   if(PyTuple_Check(value))
1297     {
1298       int size=PyTuple_Size(value);
1299       f.resize(size);
1300       for(int i=0;i<size;i++)
1301         {
1302           PyObject *o=PyTuple_GetItem(value,i);
1303           if(PyFloat_Check(o))
1304             f[i]=PyFloat_AS_DOUBLE(o);
1305           else if(PyInt_Check(o))
1306             f[i]=(double)PyInt_AS_LONG(o);
1307           else
1308             {
1309               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1310               throw INTERP_KERNEL::Exception(oss.str().c_str());
1311             }
1312         }
1313       sw=4;
1314       return;
1315     }
1316   if(PyList_Check(value))
1317     {
1318       int size=PyList_Size(value);
1319       f.resize(size);
1320       for(int i=0;i<size;i++)
1321         {
1322           PyObject *o=PyList_GetItem(value,i);
1323           if(PyFloat_Check(o))
1324             f[i]=PyFloat_AS_DOUBLE(o);
1325           else if(PyInt_Check(o))
1326             f[i]=(double)PyInt_AS_LONG(o);
1327           else
1328             {
1329               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1330               throw INTERP_KERNEL::Exception(oss.str().c_str());
1331             }
1332         }
1333       sw=4;
1334       return;
1335     }
1336   void *argp;
1337   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1338   if(SWIG_IsOK(status))
1339     {  
1340       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1341       sw=2;
1342       return ;
1343     }
1344   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1345   if(SWIG_IsOK(status))
1346     {  
1347       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1348       sw=3;
1349       return ;
1350     }
1351   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1352 }
1353
1354 /*!
1355  * if value int -> cpp val sw=1
1356  * if value double -> cpp val sw=1
1357  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1358  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1359  * if value list[int,double] -> cpp std::vector<double> sw=4
1360  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1361  */
1362 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1363                                                    const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1364 {
1365   sw=-1;
1366   if(PyFloat_Check(value))
1367     {
1368       val=PyFloat_AS_DOUBLE(value);
1369       sw=1;
1370       if(nbTuplesExpected*nbCompExpected!=1)
1371         {
1372           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1373           throw INTERP_KERNEL::Exception(oss.str().c_str());
1374         }
1375       return &val;
1376     }
1377   if(PyInt_Check(value))
1378     {
1379       val=(double)PyInt_AS_LONG(value);
1380       sw=1;
1381       if(nbTuplesExpected*nbCompExpected!=1)
1382         {
1383           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1384           throw INTERP_KERNEL::Exception(oss.str().c_str());
1385         }
1386       return &val;
1387     }
1388   if(PyTuple_Check(value) || PyList_Check(value))
1389     {
1390       try
1391         {
1392           int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1393           std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1394           sw=4;
1395           f=ret;
1396           return &f[0];
1397         }
1398       catch(INTERP_KERNEL::Exception& e) { throw e; }
1399     }
1400   void *argp;
1401   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1402   if(SWIG_IsOK(status))
1403     {  
1404       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1405       sw=2;
1406       if(d)
1407         {
1408           if(d->getNumberOfTuples()==nbTuplesExpected)
1409             {
1410               if(d->getNumberOfComponents()==nbCompExpected)
1411                 {
1412                   return d->getConstPointer();
1413                 }
1414               else
1415                 {
1416                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1417                   throw INTERP_KERNEL::Exception(oss.str().c_str());
1418                 }
1419             }
1420           else
1421             {
1422               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1423               throw INTERP_KERNEL::Exception(oss.str().c_str());
1424             }
1425         }
1426       else
1427         {
1428           if(throwIfNullPt)
1429             {
1430               std::ostringstream oss; oss << msg << " null pointer not accepted!";
1431               throw INTERP_KERNEL::Exception(oss.str().c_str());
1432             }
1433           else
1434             return 0;
1435         }
1436     }
1437   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1438   if(SWIG_IsOK(status))
1439     {  
1440       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1441       sw=3;
1442       if(e->getNumberOfCompo()==nbCompExpected)
1443         {
1444           if(nbTuplesExpected==1)
1445             return e->getConstPointer();
1446           else
1447             {
1448               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1449               throw INTERP_KERNEL::Exception(oss.str().c_str());
1450             }
1451         }
1452       else
1453         {
1454           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1455           throw INTERP_KERNEL::Exception(oss.str().c_str());
1456         }
1457     }
1458   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1459 }
1460
1461 /*!
1462  * if value int -> cpp val sw=1
1463  * if value double -> cpp val sw=1
1464  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1465  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1466  * if value list[int,double] -> cpp std::vector<double> sw=4
1467  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1468  */
1469 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1470                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1471 {
1472   sw=-1;
1473   if(PyFloat_Check(value))
1474     {
1475       val=PyFloat_AS_DOUBLE(value);
1476       sw=1;
1477       if(nbCompExpected!=1)
1478         {
1479           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1480           throw INTERP_KERNEL::Exception(oss.str().c_str());
1481         }
1482       nbTuples=1;
1483       return &val;
1484     }
1485   if(PyInt_Check(value))
1486     {
1487       val=(double)PyInt_AS_LONG(value);
1488       sw=1;
1489       if(nbCompExpected!=1)
1490         {
1491           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1492           throw INTERP_KERNEL::Exception(oss.str().c_str());
1493         }
1494       nbTuples=1;
1495       return &val;
1496     }
1497   if(PyTuple_Check(value))
1498     {
1499       int size=PyTuple_Size(value);
1500       f.resize(size);
1501       for(int i=0;i<size;i++)
1502         {
1503           PyObject *o=PyTuple_GetItem(value,i);
1504           if(PyFloat_Check(o))
1505             f[i]=PyFloat_AS_DOUBLE(o);
1506           else if(PyInt_Check(o))
1507             f[i]=(double)PyInt_AS_LONG(o);
1508           else
1509             {
1510               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1511               throw INTERP_KERNEL::Exception(oss.str().c_str());
1512             }
1513         }
1514       sw=4;
1515       if(size%nbCompExpected!=0)
1516         {
1517           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1518           throw INTERP_KERNEL::Exception(oss.str().c_str());
1519         }
1520       nbTuples=size/nbCompExpected;
1521       return &f[0];
1522     }
1523   if(PyList_Check(value))
1524     {
1525       int size=PyList_Size(value);
1526       f.resize(size);
1527       for(int i=0;i<size;i++)
1528         {
1529           PyObject *o=PyList_GetItem(value,i);
1530           if(PyFloat_Check(o))
1531             f[i]=PyFloat_AS_DOUBLE(o);
1532           else if(PyInt_Check(o))
1533             f[i]=(double)PyInt_AS_LONG(o);
1534           else
1535             {
1536               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1537               throw INTERP_KERNEL::Exception(oss.str().c_str());
1538             }
1539         }
1540       sw=4;
1541       if(size%nbCompExpected!=0)
1542         {
1543           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1544           throw INTERP_KERNEL::Exception(oss.str().c_str());
1545         }
1546       nbTuples=size/nbCompExpected;
1547       return &f[0];
1548     }
1549   void *argp;
1550   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1551   if(SWIG_IsOK(status))
1552     {  
1553       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1554       sw=2;
1555       if(d)
1556         {
1557           if(d->getNumberOfComponents()==nbCompExpected)
1558             {
1559               nbTuples=d->getNumberOfTuples();
1560               return d->getConstPointer();
1561             }
1562           else
1563             {
1564               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1565               throw INTERP_KERNEL::Exception(oss.str().c_str());
1566             }
1567         }
1568       else
1569         {
1570           if(throwIfNullPt)
1571             {
1572               std::ostringstream oss; oss << msg << " null pointer not accepted!";
1573               throw INTERP_KERNEL::Exception(oss.str().c_str());
1574             }
1575           else
1576             return 0;
1577         }
1578     }
1579   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1580   if(SWIG_IsOK(status))
1581     {  
1582       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1583       sw=3;
1584       if(e->getNumberOfCompo()==nbCompExpected)
1585         {
1586           nbTuples=1;
1587           return e->getConstPointer();
1588         }
1589       else
1590         {
1591           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1592           throw INTERP_KERNEL::Exception(oss.str().c_str());
1593         }
1594     }
1595   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1596 }
1597
1598 /*!
1599  * if python int -> cpp int sw=1
1600  * if python list[int] -> cpp vector<int> sw=2
1601  * if python tuple[int] -> cpp vector<int> sw=2
1602  * if python DataArrayInt -> cpp DataArrayInt sw=3
1603  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1604  *
1605  * switch between (int,vector<int>,DataArrayInt)
1606  */
1607 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
1608 {
1609   sw=-1;
1610   if(PyInt_Check(value))
1611     {
1612       iTyypp=(int)PyInt_AS_LONG(value);
1613       sw=1; sz=1;
1614       return &iTyypp;
1615     }
1616   if(PyTuple_Check(value))
1617     {
1618       int size=PyTuple_Size(value);
1619       stdvecTyypp.resize(size);
1620       for(int i=0;i<size;i++)
1621         {
1622           PyObject *o=PyTuple_GetItem(value,i);
1623           if(PyInt_Check(o))
1624             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1625           else
1626             {
1627               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1628               throw INTERP_KERNEL::Exception(oss.str().c_str());
1629             }
1630         }
1631       sw=2; sz=size;
1632       return &stdvecTyypp[0];
1633     }
1634   if(PyList_Check(value))
1635     {
1636       int size=PyList_Size(value);
1637       stdvecTyypp.resize(size);
1638       for(int i=0;i<size;i++)
1639         {
1640           PyObject *o=PyList_GetItem(value,i);
1641           if(PyInt_Check(o))
1642             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1643           else
1644             {
1645               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1646               throw INTERP_KERNEL::Exception(oss.str().c_str());
1647             }
1648         }
1649       sw=2; sz=size;
1650       return &stdvecTyypp[0];
1651     }
1652   void *argp;
1653   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1654   if(SWIG_IsOK(status))
1655     {
1656       ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1657       if(daIntTyypp)
1658         {
1659           sw=3; sz=daIntTyypp->getNbOfElems();
1660           return daIntTyypp->begin();
1661         }
1662       else
1663         {
1664           sz=0;
1665           return 0;
1666         }
1667     }
1668   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1669   if(SWIG_IsOK(status))
1670     {  
1671       ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1672       sw=4; sz=daIntTuple->getNumberOfCompo();
1673       return daIntTuple->getConstPointer();
1674     }
1675   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1676 }