Salome HOME
Implementation of planar symmetry + aggregation methods for MEDFileData+MEDFileUMesh
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2016  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 "MEDFileField.txx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDLoaderTraits.hxx"
25 #include "MEDFileUtilities.hxx"
26 #include "MEDFileSafeCaller.txx"
27 #include "MEDFileFieldOverView.hxx"
28
29 #include "MEDCouplingFieldDouble.hxx"
30 #include "MEDCouplingFieldTemplate.hxx"
31 #include "MEDCouplingFieldDiscretization.hxx"
32
33 #include "InterpKernelAutoPtr.hxx"
34 #include "CellModel.hxx"
35
36 #include <algorithm>
37 #include <iterator>
38
39 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
40 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
41 extern med_geometry_type typmainoeud[1];
42 extern med_geometry_type typmai3[34];
43
44 using namespace MEDCoupling;
45
46 template class MEDFileField1TSTemplateWithoutSDA<int>;
47 template class MEDFileField1TSTemplateWithoutSDA<double>;
48
49 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
50 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
51
52 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
53 {
54   return new MEDFileFieldLoc(fid,locName);
55 }
56
57 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
58 {
59   return new MEDFileFieldLoc(fid,id);
60 }
61
62 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
63 {
64   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
65 }
66
67 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
68 {
69   med_geometry_type geotype;
70   med_geometry_type sectiongeotype;
71   int nsectionmeshcell;
72   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
73   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
74   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
75   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
76   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
77   _nb_node_per_cell=cm.getNumberOfNodes();
78   _ref_coo.resize(_dim*_nb_node_per_cell);
79   _gs_coo.resize(_dim*_nb_gauss_pt);
80   _w.resize(_nb_gauss_pt);
81   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
82 }
83
84 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
85 {
86   med_geometry_type geotype;
87   med_geometry_type sectiongeotype;
88   int nsectionmeshcell;
89   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
90   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
91   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
92   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
93   _name=locName;
94   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
95   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
96   _nb_node_per_cell=cm.getNumberOfNodes();
97   _ref_coo.resize(_dim*_nb_node_per_cell);
98   _gs_coo.resize(_dim*_nb_gauss_pt);
99   _w.resize(_nb_gauss_pt);
100   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
101 }
102
103 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
104                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
105                                      _w(w)
106 {
107   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
108   _dim=cm.getDimension();
109   _nb_node_per_cell=cm.getNumberOfNodes();
110   _nb_gauss_pt=_w.size();
111 }
112
113 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
114 {
115   return new MEDFileFieldLoc(*this);
116 }
117
118 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
119 {
120   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
121 }
122
123 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
124 {
125   return std::vector<const BigMemoryObject *>();
126 }
127
128 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
129 {
130   static const char OFF7[]="\n    ";
131   oss << "\"" << _name << "\"" << OFF7;
132   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
133   oss << "Dimension=" << _dim << OFF7;
134   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
135   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
136   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
137   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
138   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
139 }
140
141 void MEDFileFieldLoc::setName(const std::string& name)
142 {
143   _name=name;
144 }
145
146 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
147 {
148   if(_name!=other._name)
149     return false;
150   if(_dim!=other._dim)
151     return false;
152   if(_nb_gauss_pt!=other._nb_gauss_pt)
153     return false;
154   if(_nb_node_per_cell!=other._nb_node_per_cell)
155     return false;
156   if(_geo_type!=other._geo_type)
157     return false;
158   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
159     return false;
160   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
161     return false;
162   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
163     return false;
164
165   return true;
166 }
167
168 void MEDFileFieldLoc::writeLL(med_idt fid) const
169 {
170   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
171 }
172
173 std::string MEDFileFieldLoc::repr() const
174 {
175   std::ostringstream oss; oss.precision(15);
176   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
177   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
178   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
179   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
180   oss << "\n  - Ref coords are : ";
181   int sz=_ref_coo.size();
182   if(sz%_dim==0)
183     {
184       int nbOfTuples=sz/_dim;
185       for(int i=0;i<nbOfTuples;i++)
186         {
187           oss << "(";
188           for(int j=0;j<_dim;j++)
189             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
190           oss << ") ";
191         }
192     }
193   else
194     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
195   oss << "\n  - Gauss coords in reference element : ";
196   sz=_gs_coo.size();
197   if(sz%_dim==0)
198     {
199       int nbOfTuples=sz/_dim;
200       for(int i=0;i<nbOfTuples;i++)
201         {
202           oss << "(";
203           for(int j=0;j<_dim;j++)
204             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
205           oss << ") ";
206         }
207     }
208   else
209     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
210   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
211   return oss.str();
212 }
213
214 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
215 {
216   _type=field->getTypeOfField();
217   _start=start;
218   switch(_type)
219   {
220     case ON_CELLS:
221       {
222         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
223         _end=_start+nbOfCells;
224         _nval=nbOfCells;
225         break;
226       }
227     case ON_GAUSS_NE:
228       {
229         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
230         const int *arrPtr=arr->getConstPointer();
231         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
232         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
233         _nval=nbOfCells;
234         break;
235       }
236     case ON_GAUSS_PT:
237       {
238         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
239         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
240         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
241         if(!disc2)
242           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
243         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
244         MCAuto<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
245         const int *dai2Ptr=dai2->getConstPointer();
246         int nbi=gsLoc.getWeights().size();
247         MCAuto<DataArrayInt> da2=dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
248         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
249         const int *da3Ptr=da3->getConstPointer();
250         if(da3->getNumberOfTuples()!=nbOfCells)
251           {//profile : for gauss even in NoProfile !!!
252             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
253             _profile=oss.str();
254             da3->setName(_profile.c_str());
255             glob.appendProfile(da3);
256           }
257         MCAuto<DataArrayInt> da4=DataArrayInt::New();
258         _nval=da3->getNbOfElems();
259         da4->alloc(_nval*nbi,1);
260         int *da4Ptr=da4->getPointer();
261         for(int i=0;i<_nval;i++)
262           {
263             int ref=dai2Ptr[offset+da3Ptr[i]];
264             for(int j=0;j<nbi;j++)
265               *da4Ptr++=ref+j;
266           }
267         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
268         _localization=oss2.str();
269         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
270         _end=_start+_nval*nbi;
271         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
272         break;
273       }
274     default:
275       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
276   }
277   start=_end;
278 }
279
280 /*!
281  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
282  * \param [in] pflName input containing name of profile if any. 0 if no profile (except for GAUSS_PT where a no profile can hide a profile when splitted by loc_id).
283  * \param [in] multiTypePfl is the end user profile specified in high level API
284  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
285  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
286  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
287  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
288  */
289 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
290 {
291   _profile.clear();
292   _type=field->getTypeOfField();
293   std::string pflName(multiTypePfl->getName());
294   std::ostringstream oss; oss << pflName;
295   if(_type!=ON_NODES)
296     {
297       if(!isPflAlone)
298         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
299     }
300   else
301     { oss << "_NODE"; }
302   if(locIds)
303     {
304       if(pflName.empty())
305         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
306       if(_type!=ON_GAUSS_PT)
307         {
308           locIds->setName(oss.str());
309           glob.appendProfile(locIds);
310           _profile=oss.str();
311         }
312     }
313   _start=start;
314   switch(_type)
315   {
316     case ON_NODES:
317       {
318         _nval=idsInPfl->getNumberOfTuples();
319         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
320         _end=_start+_nval;
321         break;
322       }
323     case ON_CELLS:
324       {
325         _nval=idsInPfl->getNumberOfTuples();
326         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
327         _end=_start+_nval;
328         break;
329       }
330     case ON_GAUSS_NE:
331       {
332         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
333         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
334         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
335         arr3->computeOffsetsFull();
336         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
337         int trueNval=tmp->getNumberOfTuples();
338         _nval=idsInPfl->getNumberOfTuples();
339         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
340         _end=_start+trueNval;
341         break;
342       }
343     case ON_GAUSS_PT:
344       {
345         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
346         if(!disc2)
347           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
348         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
349         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
350         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
351         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
352         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
353         //
354         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
355         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
356         //
357         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
358         int trueNval=0;
359         for(const int *pt=da4->begin();pt!=da4->end();pt++)
360           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
361         tmp->alloc(trueNval,1);
362         int *tmpPtr=tmp->getPointer();
363         for(const int *pt=da4->begin();pt!=da4->end();pt++)
364           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
365             *tmpPtr++=j;
366         //
367         _nval=da4->getNumberOfTuples();
368         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
369         _end=_start+trueNval;
370         oss << "_loc_" << _loc_id;
371         if(locIds)
372           {
373             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
374             da5->setName(oss.str());
375             glob.appendProfile(da5);
376             _profile=oss.str();
377           }
378         else
379           {
380             if(!da3->isIota(nbOfEltsInWholeMesh))
381               {
382                 da3->setName(oss.str());
383                 glob.appendProfile(da3);
384                 _profile=oss.str();
385               }
386           }
387         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
388         _localization=oss2.str();
389         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
390         break;
391       }
392     default:
393       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
394   }
395   start=_end;
396 }
397
398 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
399 {
400   _start=start;
401   _nval=arrr->getNumberOfTuples();
402   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
403   _end=_start+_nval;
404   start=_end;
405 }
406
407 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
408 {
409   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
410 }
411
412 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
413 {
414   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
415 }
416
417 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
418 {
419   return new MEDFileFieldPerMeshPerTypePerDisc(other);
420 }
421
422 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
423 {
424   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
425 }
426
427 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
428 {
429   std::vector<const BigMemoryObject *> ret(1);
430   ret[0]=(const PartDefinition*)_pd;
431   return ret;
432 }
433
434 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerType *father) const
435 {
436   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
437   ret->_father=father;
438   return ret.retn();
439 }
440
441 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
442 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
443 {
444   if(pd)
445     pd->incrRef();
446 }
447 catch(INTERP_KERNEL::Exception& e)
448 {
449     throw e;
450 }
451
452 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
453 {
454 }
455
456 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_profile_it(other._profile_it),_pd(other._pd),_tmp_work1(other._tmp_work1)
457 {
458 }
459
460 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
461     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
462 {
463 }
464
465 void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const std::string& fieldName, int nbOfCompo, int iteration, int order, med_entity_type menti, med_geometry_type mgeoti, unsigned char *startFeedingPtr)
466 {
467   const PartDefinition *pd(_pd);
468   if(!pd)
469     {
470       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
471       int nbi,tmp1;
472       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
473       if(_end-_start!=nbValsInFile*nbi)
474         {
475           std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
476           throw INTERP_KERNEL::Exception(oss.str());
477         }
478       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
479     }
480   else
481     {
482       if(!_profile.empty())
483         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
484       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
485       int profilesize,nbi;
486       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
487       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
488       if(spd)
489         {
490           int start,stop,step;
491           spd->getSlice(start,stop,step);
492           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
493           med_filter filter=MED_FILTER_INIT;
494           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
495                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
496                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
497                                    /*lastblocksize=useless because count=1*/0,&filter);
498           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
499           MEDfilterClose(&filter);
500           return ;
501         }
502       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
503       if(dpd)
504         {
505           dpd->checkConsistencyLight();
506           MCAuto<DataArrayInt> myIds(dpd->toDAI());
507           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
508           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
509           myIds->applyLin(1,-a);
510           int nbOfEltsToLoad(b-a+1);
511           med_filter filter=MED_FILTER_INIT;
512           {//TODO : manage int32 !
513             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
514             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
515             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
516                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
517                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
518                                      /*lastblocksize=useless because count=1*/0,&filter);
519             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
520             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
521             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
522             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
523           }
524           MEDfilterClose(&filter);
525         }
526       else
527         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
528     }
529 }
530
531 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
532 {
533   return _father;
534 }
535
536 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
537 {
538   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
539   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
540   std::string fieldName(nasc.getName()),meshName(getMeshName());
541   int iteration(getIteration()),order(getOrder());
542   TypeOfField type(getType());
543   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
544   int profilesize,nbi;
545   med_geometry_type mgeoti;
546   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
547   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
548   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
549   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
550   const PartDefinition *pd(_pd);
551   if(!pd)
552     {
553       _nval=zeNVal;
554     }
555   else
556     {
557       if(!_profile.empty())
558         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
559       _nval=pd->getNumberOfElems();
560     }
561   _start=start;
562   _end=start+_nval*nbi;
563   start=_end;
564   if(type==ON_CELLS && !_localization.empty())
565     {
566       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
567         setType(ON_GAUSS_PT);
568       else
569         {
570           setType(ON_GAUSS_NE);
571           _localization.clear();
572         }
573     }
574 }
575
576 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
577 {
578   std::string fieldName(nasc.getName()),meshName(getMeshName());
579   int iteration(getIteration()),order(getOrder());
580   TypeOfField type(getType());
581   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
582   med_geometry_type mgeoti;
583   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
584   if(_start>_end)
585     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
586   if(_start==_end)
587     return ;
588   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
589   if(_start<0 || _start>=arr->getNumberOfTuples())
590     {
591       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
592       throw INTERP_KERNEL::Exception(oss.str());
593     }
594   if(_end<0 || _end>arr->getNumberOfTuples())
595     {
596       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
597       throw INTERP_KERNEL::Exception(oss.str());
598     }
599   int nbOfCompo(arr->getNumberOfComponents());
600   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
601   if(arrD)
602     {
603       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
604       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
605       return ;
606     }
607   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
608   if(arrI)
609     {
610       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
611       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
612       return ;
613     }
614   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
615 }
616
617 /*!
618  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
619  */
620 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
621 {
622   int delta=_end-_start;
623   _start=newValueOfStart;
624   _end=_start+delta;
625 }
626
627 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
628 {
629   return _father->getIteration();
630 }
631
632 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
633 {
634   return _father->getOrder();
635 }
636
637 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
638 {
639   return _father->getTime();
640 }
641
642 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
643 {
644   return _father->getMeshName();
645 }
646
647 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
648 {
649   const char startLine[]="    ## ";
650   std::string startLine2(bkOffset,' ');
651   startLine2+=startLine;
652   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
653   oss << startLine2 << "Localization #" << id << "." << std::endl;
654   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
655   delete tmp;
656   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
657   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
658   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
659 }
660
661 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
662 {
663   return _type;
664 }
665
666 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
667 {
668   types.insert(_type);
669 }
670
671 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
672 {
673   _type=newType;
674 }
675
676 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
677 {
678   return _father->getGeoType();
679 }
680
681 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
682 {
683   return _father->getNumberOfComponents();
684 }
685
686 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
687 {
688   return _end-_start;
689 }
690
691 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
692 {
693   return _father->getOrCreateAndGetArray();
694 }
695
696 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
697 {
698   const MEDFileFieldPerMeshPerType *fath=_father;
699   return fath->getOrCreateAndGetArray();
700 }
701
702 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
703 {
704   return _father->getInfo();
705 }
706
707 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
708 {
709   return _profile;
710 }
711
712 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
713 {
714   _profile=newPflName;
715 }
716
717 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
718 {
719   return _localization;
720 }
721
722 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
723 {
724   _localization=newLocName;
725 }
726
727 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
728 {
729   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
730     {
731       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
732         {
733           _profile=(*it2).second;
734           return;
735         }
736     }
737 }
738
739 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
740 {
741   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
742     {
743       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
744         {
745           _localization=(*it2).second;
746           return;
747         }
748     }
749 }
750
751 void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
752 {
753   if(type!=_type)
754     return ;
755   dads.push_back(std::pair<int,int>(_start,_end));
756   geoTypes.push_back(getGeoType());
757   if(_profile.empty())
758     pfls.push_back(0);
759   else
760     {
761       pfls.push_back(glob->getProfile(_profile.c_str()));
762     }
763   if(_localization.empty())
764     locs.push_back(-1);
765   else
766     {
767       locs.push_back(glob->getLocalizationId(_localization.c_str()));
768     }
769 }
770
771 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
772 {
773   entries[startEntryId]=std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int> ,std::pair<int,int> >(std::pair<INTERP_KERNEL::NormalizedCellType,int>(getGeoType(),discId),std::pair<int,int>(_start,_end));
774   startEntryId++;
775 }
776
777 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
778 {
779   TypeOfField type=getType();
780   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
781   med_geometry_type mgeoti;
782   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
783   const DataArray *arr=getOrCreateAndGetArray();
784   if(!arr)
785     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
786   if(!arr->isAllocated())
787     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
788   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
789   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
790   const unsigned char *locToWrite=0;
791   if(arrD)
792     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
793   else if(arrI)
794     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
795   else
796     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
797   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
798                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
799                                                    locToWrite));
800 }
801
802 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
803 {
804   type=_type;
805   pfl=_profile;
806   loc=_localization;
807   dad.first=_start; dad.second=_end;
808 }
809
810 /*!
811  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
812  *             This code corresponds to the distribution of types in the corresponding mesh.
813  * \param [out] ptToFill memory zone where the output will be stored.
814  * \return the size of data pushed into output param \a ptToFill
815  */
816 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
817 {
818   _loc_id=offset;
819   std::ostringstream oss;
820   std::size_t nbOfType=codeOfMesh.size()/3;
821   int found=-1;
822   for(std::size_t i=0;i<nbOfType && found==-1;i++)
823     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
824       found=(int)i;
825   if(found==-1)
826     {
827       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
828       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
829       throw INTERP_KERNEL::Exception(oss.str());
830     }
831   int *work=ptToFill;
832   if(_profile.empty())
833     {
834       if(_nval!=codeOfMesh[3*found+1])
835         {
836           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
837           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
838           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
839           throw INTERP_KERNEL::Exception(oss.str());
840         }
841       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
842         *work++=ii;
843     }
844   else
845     {
846       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
847       if(pfl->getNumberOfTuples()!=_nval)
848         {
849           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
850           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
851           oss << _nval;
852           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
853           throw INTERP_KERNEL::Exception(oss.str());
854         }
855       int offset2=codeOfMesh[3*found+2];
856       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
857         {
858           if(*pflId<codeOfMesh[3*found+1])
859             *work++=offset2+*pflId;
860         }
861     }
862   return _nval;
863 }
864
865 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
866 {
867   for(int i=_start;i<_end;i++)
868     *ptToFill++=i;
869   return _end-_start;
870 }
871
872 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
873 {
874   switch(type)
875   {
876     case ON_CELLS:
877       return -2;
878     case ON_GAUSS_NE:
879       return -1;
880     case ON_GAUSS_PT:
881       return locId;
882     default:
883       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
884   }
885 }
886
887 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
888 {
889   int id=0;
890   std::map<std::pair<std::string,TypeOfField>,int> m;
891   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
892   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
893     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
894       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
895   ret.resize(id);
896   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
897     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
898   return ret;
899 }
900
901 /*!
902  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
903  * 
904  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
905  * \param [in] entriesOnSameDisc some entries **on same localization** if not the result can be invalid. The _start and _end on them are relative to \a arr parameter.
906  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
907  * \param [in] newCode one of the input parameter to explicit the new geo type dispatch (in classical format same than those asked by MEDFileFields::renumberEntitiesLyingOnMesh)
908  * \param [in,out] glob if necessary by the method, new profiles can be added to it
909  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
910  * \param [out] result All new entries will be appended on it.
911  * \return false if the configuration of renumbering leads to an unnecessary resplit of input \a entriesOnSameDisc. If not true is returned (the most general case !)
912  */
913 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
914                                                        const DataArrayInt *explicitIdsInMesh,
915                                                        const std::vector<int>& newCode,
916                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
917                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
918 {
919   if(entriesOnSameDisc.empty())
920     return false;
921   TypeOfField type=entriesOnSameDisc[0]->getType();
922   int szEntities=0,szTuples=0;
923   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
924     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
925   int nbi=szTuples/szEntities;
926   if(szTuples%szEntities!=0)
927     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
928   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
929   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
930   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
931   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
932   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
933   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
934   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
935   int id=0;
936   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
937     {
938       int startOfEltIdOfChunk=(*it)->_start;
939       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
940       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
941       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
942       //
943       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
944       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
945       //
946       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
947       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
948     }
949   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
950   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
951   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
952   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
953   //
954   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
955   //
956   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
957   arrPart->renumberInPlace(renumTupleIds->begin());
958   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
959   bool ret=false;
960   const int *idIt=diffVals->begin();
961   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
962   int offset2=0;
963   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
964     {
965       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
966       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
967       int nbEntityElts=subIds->getNumberOfTuples();
968       bool ret2;
969       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
970           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
971                                       offset+offset2,
972                                       li,glob,ret2);
973       ret=ret || ret2;
974       result.push_back(eltToAdd);
975       offset2+=nbEntityElts*nbi;
976     }
977   ret=ret || li.empty();
978   return ret;
979 }
980
981 /*!
982  * \param [in] typeF type of field of new chunk
983  * \param [in] geoType the geometric type of the chunk
984  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
985  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
986  * \param [in] nbi number of integration points
987  * \param [in] offset The offset in the **global array of data**.
988  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
989  *                 to the new chunk to create.
990  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
991  * \param [out] notInExisting If false the return newly allocated entry is not coming from \a entriesOnSameDisc. If true the output comes from copy of \a entriesOnSameDisc
992  *              and corresponding entry erased from \a entriesOnSameDisc.
993  * \return a newly allocated chunk
994  */
995 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
996                                                                                                   bool isPfl, int nbi, int offset,
997                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
998                                                                                                   MEDFileFieldGlobsReal& glob,
999                                                                                                   bool &notInExisting)
1000 {
1001   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1002   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1003   for(;it!=entriesOnSameDisc.end();it++)
1004     {
1005       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1006         {
1007           if(!isPfl)
1008             {
1009               if((*it)->_profile.empty())
1010                 break;
1011               else
1012                 if(!(*it)->_profile.empty())
1013                   {
1014                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1015                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1016                       break;
1017                   }
1018             }
1019         }
1020     }
1021   if(it==entriesOnSameDisc.end())
1022     {
1023       notInExisting=true;
1024       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1025       ret->_type=typeF;
1026       ret->_loc_id=(int)geoType;
1027       ret->_nval=nbMeshEntities;
1028       ret->_start=offset;
1029       ret->_end=ret->_start+ret->_nval*nbi;
1030       if(isPfl)
1031         {
1032           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1033           glob.appendProfile(idsOfMeshElt);
1034           ret->_profile=idsOfMeshElt->getName();
1035         }
1036       //tony treatment of localization
1037       return ret;
1038     }
1039   else
1040     {
1041       notInExisting=false;
1042       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1043       ret->_loc_id=(int)geoType;
1044       ret->setNewStart(offset);
1045       entriesOnSameDisc.erase(it);
1046       return ret;
1047     }
1048
1049 }
1050
1051 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1052 {
1053   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1054 }
1055
1056 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1057 {
1058   return new MEDFileFieldPerMeshPerType(fath,geoType);
1059 }
1060
1061 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1062 {
1063   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1064 }
1065
1066 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1067 {
1068   std::vector<const BigMemoryObject *> ret;
1069   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1070     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1071   return ret;
1072 }
1073
1074 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1075 {
1076   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1077   ret->_father=father;
1078   std::size_t i=0;
1079   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1080     {
1081       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1082         ret->_field_pm_pt_pd[i]=(*it)->deepCopy((MEDFileFieldPerMeshPerType *)ret);
1083     }
1084   return ret.retn();
1085 }
1086
1087 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1088 {
1089   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1090   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1091     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1092 }
1093
1094 /*!
1095  * This method is the most general one. No optimization is done here.
1096  * \param [in] multiTypePfl is the end user profile specified in high level API
1097  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1098  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
1099  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1100  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1101  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
1102  */
1103 void MEDFileFieldPerMeshPerType::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1104 {
1105   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1106   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1107     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1108 }
1109
1110 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1111 {
1112   _field_pm_pt_pd.resize(1);
1113   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1114   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1115 }
1116
1117 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1118 {
1119   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1120   if(!arr || !arr->isAllocated())
1121     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1122   _field_pm_pt_pd.resize(1);
1123   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1124   _field_pm_pt_pd[0]->assignFieldProfile(true,start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1125 }
1126
1127 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1128 {
1129   TypeOfField type=field->getTypeOfField();
1130   if(type!=ON_GAUSS_PT)
1131     {
1132       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1133       int sz=_field_pm_pt_pd.size();
1134       bool found=false;
1135       for(int j=0;j<sz && !found;j++)
1136         {
1137           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1138             {
1139               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1140               found=true;
1141             }
1142         }
1143       if(!found)
1144         {
1145           _field_pm_pt_pd.resize(sz+1);
1146           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1147         }
1148       std::vector<int> ret(1,(int)sz);
1149       return ret;
1150     }
1151   else
1152     {
1153       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1154       int sz2=ret2.size();
1155       std::vector<int> ret3(sz2);
1156       int k=0;
1157       for(int i=0;i<sz2;i++)
1158         {
1159           int sz=_field_pm_pt_pd.size();
1160           int locIdToFind=ret2[i];
1161           bool found=false;
1162           for(int j=0;j<sz && !found;j++)
1163             {
1164               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1165                 {
1166                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1167                   ret3[k++]=j;
1168                   found=true;
1169                 }
1170             }
1171           if(!found)
1172             {
1173               _field_pm_pt_pd.resize(sz+1);
1174               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1175               ret3[k++]=sz;
1176             }
1177         }
1178       return ret3;
1179     }
1180 }
1181
1182 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1183 {
1184   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1185   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1186   if(!disc2)
1187     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1188   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1189   if(!da)
1190     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1191   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1192   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1193   if(retTmp->presenceOfValue(-1))
1194     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1195   std::vector<int> ret(retTmp->begin(),retTmp->end());
1196   return ret;
1197 }
1198
1199 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1200 {
1201   TypeOfField type=field->getTypeOfField();
1202   if(type!=ON_GAUSS_PT)
1203     {
1204       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1205       int sz=_field_pm_pt_pd.size();
1206       bool found=false;
1207       for(int j=0;j<sz && !found;j++)
1208         {
1209           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1210             {
1211               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1212               found=true;
1213             }
1214         }
1215       if(!found)
1216         {
1217           _field_pm_pt_pd.resize(sz+1);
1218           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1219         }
1220       std::vector<int> ret(1,0);
1221       return ret;
1222     }
1223   else
1224     {
1225       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1226       int sz2=ret2.size();
1227       std::vector<int> ret3(sz2);
1228       int k=0;
1229       for(int i=0;i<sz2;i++)
1230         {
1231           int sz=_field_pm_pt_pd.size();
1232           int locIdToFind=ret2[i];
1233           bool found=false;
1234           for(int j=0;j<sz && !found;j++)
1235             {
1236               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1237                 {
1238                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1239                   ret3[k++]=j;
1240                   found=true;
1241                 }
1242             }
1243           if(!found)
1244             {
1245               _field_pm_pt_pd.resize(sz+1);
1246               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1247               ret3[k++]=sz;
1248             }
1249         }
1250       return ret3;
1251     }
1252 }
1253
1254 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1255 {
1256   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1257   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1258   if(!disc2)
1259     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1260   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1261   if(!da)
1262     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1263   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1264   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1265   if(retTmp->presenceOfValue(-1))
1266     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1267   std::vector<int> ret(retTmp->begin(),retTmp->end());
1268   return ret;
1269 }
1270
1271 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1272 {
1273   return _father;
1274 }
1275
1276 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1277 {
1278   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1279   int curDim((int)cm.getDimension());
1280   dim=std::max(dim,curDim);
1281 }
1282
1283 bool MEDFileFieldPerMeshPerType::isUniqueLevel(int& dim) const
1284 {
1285   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1286   int curDim((int)cm.getDimension());
1287   if(dim!=std::numeric_limits<int>::max())
1288     {
1289       if(dim!=curDim)
1290         return false;
1291     }
1292   else
1293     dim=curDim;
1294   return true;
1295 }
1296
1297 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1298 {
1299   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1300     {
1301       (*it)->fillTypesOfFieldAvailable(types);
1302     }
1303 }
1304
1305 void MEDFileFieldPerMeshPerType::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1306 {
1307   int sz=_field_pm_pt_pd.size();
1308   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1309   for(int i=0;i<sz;i++)
1310     {
1311       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1312     }
1313 }
1314
1315 int MEDFileFieldPerMeshPerType::getIteration() const
1316 {
1317   return _father->getIteration();
1318 }
1319
1320 int MEDFileFieldPerMeshPerType::getOrder() const
1321 {
1322   return _father->getOrder();
1323 }
1324
1325 double MEDFileFieldPerMeshPerType::getTime() const
1326 {
1327   return _father->getTime();
1328 }
1329
1330 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1331 {
1332   return _father->getMeshName();
1333 }
1334
1335 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1336 {
1337   const char startLine[]="  ## ";
1338   std::string startLine2(bkOffset,' ');
1339   std::string startLine3(startLine2);
1340   startLine3+=startLine;
1341   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1342     {
1343       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1344       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1345     }
1346   else
1347     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1348   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1349   int i=0;
1350   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1351     {
1352       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1353       if(cur)
1354         cur->simpleRepr(bkOffset,oss,i);
1355       else
1356         {
1357           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1358         }
1359     }
1360 }
1361
1362 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1363 {
1364   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1365     {
1366       globalSz+=(*it)->getNumberOfTuples();
1367     }
1368   nbOfEntries+=(int)_field_pm_pt_pd.size();
1369 }
1370
1371 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1372 {
1373   return _geo_type;
1374 }
1375
1376
1377 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1378 {
1379   return _father->getNumberOfComponents();
1380 }
1381
1382 bool MEDFileFieldPerMeshPerType::presenceOfMultiDiscPerGeoType() const
1383 {
1384   std::size_t nb(0);
1385   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1386     {
1387       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1388       if(fmtd)
1389         nb++;
1390     }
1391   return nb>1;
1392 }
1393
1394 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1395 {
1396   return _father->getOrCreateAndGetArray();
1397 }
1398
1399 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1400 {
1401   const MEDFileFieldPerMesh *fath=_father;
1402   return fath->getOrCreateAndGetArray();
1403 }
1404
1405 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1406 {
1407   return _father->getInfo();
1408 }
1409
1410 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1411 {
1412   std::vector<std::string> ret;
1413   std::set<std::string> ret2;
1414   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1415     {
1416       std::string tmp=(*it1)->getProfile();
1417       if(!tmp.empty())
1418         if(ret2.find(tmp)==ret2.end())
1419           {
1420             ret.push_back(tmp);
1421             ret2.insert(tmp);
1422           }
1423     }
1424   return ret;
1425 }
1426
1427 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1428 {
1429   std::vector<std::string> ret;
1430   std::set<std::string> ret2;
1431   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1432     {
1433       std::string tmp=(*it1)->getLocalization();
1434       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1435         if(ret2.find(tmp)==ret2.end())
1436           {
1437             ret.push_back(tmp);
1438             ret2.insert(tmp);
1439           }
1440     }
1441   return ret;
1442 }
1443
1444 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1445 {
1446   std::vector<std::string> ret;
1447   std::set<std::string> ret2;
1448   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1449     {
1450       std::string tmp=(*it1)->getProfile();
1451       if(!tmp.empty())
1452         ret.push_back(tmp);
1453     }
1454   return ret;
1455 }
1456
1457 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1458 {
1459   std::vector<std::string> ret;
1460   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1461     {
1462       std::string tmp=(*it1)->getLocalization();
1463       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1464         ret.push_back(tmp);
1465     }
1466   return ret;
1467 }
1468
1469 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1470 {
1471   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1472     (*it1)->changePflsRefsNamesGen(mapOfModif);
1473 }
1474
1475 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1476 {
1477   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1478     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1479 }
1480
1481 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1482 {
1483   if(_field_pm_pt_pd.empty())
1484     {
1485       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1486       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1487       throw INTERP_KERNEL::Exception(oss.str());
1488     }
1489   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1490     return _field_pm_pt_pd[locId];
1491   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1492   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1493   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1494   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1495   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1496 }
1497
1498 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1499 {
1500   if(_field_pm_pt_pd.empty())
1501     {
1502       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1503       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1504       throw INTERP_KERNEL::Exception(oss.str());
1505     }
1506   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1507     return _field_pm_pt_pd[locId];
1508   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1509   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1510   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1511   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1512   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1513 }
1514
1515 void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1516 {
1517   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1518     {
1519       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1520       if(meshDim!=(int)cm.getDimension())
1521         return ;
1522     }
1523   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1524     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1525 }
1526
1527 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1528 {
1529   int i=0;
1530   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1531     {
1532       (*it)->fillValues(i,startEntryId,entries);
1533     }
1534 }
1535
1536 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1537 {
1538   _field_pm_pt_pd=leaves;
1539   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1540     (*it)->setFather(this);
1541 }
1542
1543 /*!
1544  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1545  *  \param [out] its - list of pair (start,stop) kept
1546  *  \return bool - false if the type of field \a tof is not contained in \a this.
1547  */
1548 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1549 {
1550   bool ret(false);
1551   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1552   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1553     if((*it)->getType()==tof)
1554       {
1555         newPmPtPd.push_back(*it);
1556         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1557         (*it)->setNewStart(globalNum);
1558         globalNum=(*it)->getEnd();
1559         its.push_back(bgEnd);
1560         ret=true;
1561       }
1562   if(ret)
1563     _field_pm_pt_pd=newPmPtPd;
1564   return ret;
1565 }
1566
1567 /*!
1568  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1569  *  \param [out] its - list of pair (start,stop) kept
1570  *  \return bool - false if the type of field \a tof is not contained in \a this.
1571  */
1572 bool MEDFileFieldPerMeshPerType::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1573 {
1574   if(_field_pm_pt_pd.size()<=idOfDisc)
1575     return false;
1576   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1577   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1578   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1579   elt->setNewStart(globalNum);
1580   globalNum=elt->getEnd();
1581   its.push_back(bgEnd);
1582   _field_pm_pt_pd=newPmPtPd;
1583   return true;
1584 }
1585
1586 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1587 {
1588   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1589   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1590   med_geometry_type mgeoti;
1591   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1592   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1593   _field_pm_pt_pd.resize(nbProfiles);
1594   for(int i=0;i<nbProfiles;i++)
1595     {
1596       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1597     }
1598   if(type==ON_CELLS)
1599     {
1600       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1601       for(int i=0;i<nbProfiles2;i++)
1602         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1603     }
1604 }
1605
1606 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1607 {
1608   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1609     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1610 }
1611
1612 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1613 {
1614   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1615     (*it)->loadBigArray(fid,nasc);
1616 }
1617
1618 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1619 {
1620   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1621     {
1622       (*it)->copyOptionsFrom(*this);
1623       (*it)->writeLL(fid,nasc);
1624     }
1625 }
1626
1627 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1628 {
1629   switch(ikType)
1630   {
1631     case ON_CELLS:
1632       medfGeoType=typmai3[(int)ikGeoType];
1633       return MED_CELL;
1634     case ON_NODES:
1635       medfGeoType=MED_NONE;
1636       return MED_NODE;
1637     case ON_GAUSS_NE:
1638       medfGeoType=typmai3[(int)ikGeoType];
1639       return MED_NODE_ELEMENT;
1640     case ON_GAUSS_PT:
1641       medfGeoType=typmai3[(int)ikGeoType];
1642       return MED_CELL;
1643     default:
1644       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1645   }
1646   return MED_UNDEF_ENTITY_TYPE;
1647 }
1648
1649 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
1650 {
1651   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1652 }
1653
1654 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1655 {
1656   return new MEDFileFieldPerMesh(fath,mesh);
1657 }
1658
1659 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1660 {
1661   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1662 }
1663
1664 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1665 {
1666   std::vector<const BigMemoryObject *> ret;
1667   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1668     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1669   return ret;
1670 }
1671
1672 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1673 {
1674   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1675   ret->_father=father;
1676   std::size_t i=0;
1677   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1678     {
1679       if((const MEDFileFieldPerMeshPerType *)*it)
1680         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1681     }
1682   return ret.retn();
1683 }
1684
1685 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1686 {
1687   std::string startLine(bkOffset,' ');
1688   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1689   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1690   int i=0;
1691   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1692     {
1693       const MEDFileFieldPerMeshPerType *cur=*it;
1694       if(cur)
1695         cur->simpleRepr(bkOffset,oss,i);
1696       else
1697         {
1698           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1699         }
1700     }
1701 }
1702
1703 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1704 {
1705   _mesh_name=mesh->getName();
1706   mesh->getTime(_mesh_iteration,_mesh_order);
1707 }
1708
1709 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1710 {
1711   int nbOfTypes=code.size()/3;
1712   int offset=0;
1713   for(int i=0;i<nbOfTypes;i++)
1714     {
1715       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1716       int nbOfCells=code[3*i+1];
1717       int pos=addNewEntryIfNecessary(type);
1718       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1719       offset+=nbOfCells;
1720     }
1721 }
1722
1723 /*!
1724  * This method is the most general one. No optimization is done here.
1725  * \param [in] multiTypePfl is the end user profile specified in high level API
1726  * \param [in] code is the code of \a mesh[multiTypePfl] mesh. It is of size of number of different geometric types into \a mesh[multiTypePfl].
1727  * \param [in] code2 is the code of the \b WHOLE mesh on the same level. So all types in \a code are in \a code2.
1728  * \param [in] idsInPflPerType is the selection into the \a multiTypePfl whole profile that corresponds to the given geometric type. This vector is always 3 times smaller than \a code.
1729  * \param [in] idsPerType is a vector containing the profiles needed to be created for MED file format. \b WARNING these processed MED file profiles can be subdivided again in case of Gauss points.
1730  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
1731  */
1732 void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<int>& code2, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1733 {
1734   int nbOfTypes(code.size()/3);
1735   for(int i=0;i<nbOfTypes;i++)
1736     {
1737       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1738       int pos=addNewEntryIfNecessary(type);
1739       DataArrayInt *pfl=0;
1740       if(code[3*i+2]!=-1)
1741         pfl=idsPerType[code[3*i+2]];
1742       int nbOfTupes2=code2.size()/3;
1743       int found=0;
1744       for(;found<nbOfTupes2;found++)
1745         if(code[3*i]==code2[3*found])
1746           break;
1747       if(found==nbOfTupes2)
1748         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1749       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1750     }
1751 }
1752
1753 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1754 {
1755   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1756   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1757 }
1758
1759 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1760 {
1761   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1762   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1763 }
1764
1765 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1766 {
1767   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1768     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1769 }
1770
1771 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1772 {
1773   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1774     (*it)->loadBigArraysRecursively(fid,nasc);
1775 }
1776
1777 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1778 {
1779   int nbOfTypes=_field_pm_pt.size();
1780   for(int i=0;i<nbOfTypes;i++)
1781     {
1782       _field_pm_pt[i]->copyOptionsFrom(*this);
1783       _field_pm_pt[i]->writeLL(fid,nasc);
1784     }
1785 }
1786
1787 void MEDFileFieldPerMesh::getDimension(int& dim) const
1788 {
1789   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1790     (*it)->getDimension(dim);
1791 }
1792
1793 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
1794 {
1795   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1796     if(!(*it)->isUniqueLevel(dim))
1797       return false;
1798   return true;
1799 }
1800
1801 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1802 {
1803   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1804     (*it)->fillTypesOfFieldAvailable(types);
1805 }
1806
1807 std::vector< std::vector< std::pair<int,int> > > MEDFileFieldPerMesh::getFieldSplitedByType(std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> > & locs) const
1808 {
1809   int sz=_field_pm_pt.size();
1810   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1811   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1812   for(int i=0;i<sz;i++)
1813     {
1814       types[i]=_field_pm_pt[i]->getGeoType();
1815       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1816     }
1817   return ret;
1818 }
1819
1820 double MEDFileFieldPerMesh::getTime() const
1821 {
1822   int tmp1,tmp2;
1823   return _father->getTime(tmp1,tmp2);
1824 }
1825
1826 int MEDFileFieldPerMesh::getIteration() const
1827 {
1828   return _father->getIteration();
1829 }
1830
1831 int MEDFileFieldPerMesh::getOrder() const
1832 {
1833   return _father->getOrder();
1834 }
1835
1836 int MEDFileFieldPerMesh::getNumberOfComponents() const
1837 {
1838   return _father->getNumberOfComponents();
1839 }
1840
1841 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1842 {
1843   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1844     {
1845       const MEDFileFieldPerMeshPerType *fpmt(*it);
1846       if(!fpmt)
1847         continue;
1848       if(fpmt->presenceOfMultiDiscPerGeoType())
1849         return true;
1850     }
1851   return false;
1852 }
1853
1854 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1855 {
1856   if(!_father)
1857     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1858   return _father->getOrCreateAndGetArray();
1859 }
1860
1861 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1862 {
1863   if(!_father)
1864     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1865   return _father->getOrCreateAndGetArray();
1866 }
1867
1868 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1869 {
1870   return _father->getInfo();
1871 }
1872
1873 /*!
1874  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1875  * Before the call of this method 'geoTypes','dads','pfls','locs' must be reorganized so that types in geoTypes are contiguous and ordered following typmai2 array.
1876  * It returns 2 output vectors :
1877  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1878  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1879  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1880  */
1881 void MEDFileFieldPerMesh::SortArraysPerType(const MEDFileFieldGlobsReal *glob, TypeOfField type, const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes, const std::vector< std::pair<int,int> >& dads, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& locs, std::vector<int>& code, std::vector<DataArrayInt *>& notNullPfls)
1882 {
1883   int notNullPflsSz=0;
1884   int nbOfArrs=geoTypes.size();
1885   for(int i=0;i<nbOfArrs;i++)
1886     if(pfls[i])
1887       notNullPflsSz++;
1888   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1889   int nbOfDiffGeoTypes=geoTypes3.size();
1890   code.resize(3*nbOfDiffGeoTypes);
1891   notNullPfls.resize(notNullPflsSz);
1892   notNullPflsSz=0;
1893   int j=0;
1894   for(int i=0;i<nbOfDiffGeoTypes;i++)
1895     {
1896       int startZone=j;
1897       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1898       std::vector<const DataArrayInt *> notNullTmp;
1899       if(pfls[j])
1900         notNullTmp.push_back(pfls[j]);
1901       j++;
1902       for(;j<nbOfArrs;j++)
1903         if(geoTypes[j]==refType)
1904           {
1905             if(pfls[j])
1906               notNullTmp.push_back(pfls[j]);
1907           }
1908         else
1909           break;
1910       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1911       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1912       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1913       code[3*i]=(int)refType;
1914       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1915       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1916       if(notNullTmp.empty())
1917         code[3*i+2]=-1;
1918       else
1919         {
1920           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1921           code[3*i+2]=notNullPflsSz++;
1922         }
1923     }
1924 }
1925
1926 /*!
1927  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1928  */
1929 int MEDFileFieldPerMesh::ComputeNbOfElems(const MEDFileFieldGlobsReal *glob, TypeOfField type, const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes, const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs)
1930 {
1931   int sz=dads.size();
1932   int ret=0;
1933   for(int i=0;i<sz;i++)
1934     {
1935       if(locs[i]==-1)
1936         {
1937           if(type!=ON_GAUSS_NE)
1938             ret+=dads[i].second-dads[i].first;
1939           else
1940             {
1941               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1942               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1943             }
1944         }
1945       else
1946         {
1947           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1948           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1949         }
1950     }
1951   return ret;
1952 }
1953
1954 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1955 {
1956   std::vector<std::string> ret;
1957   std::set<std::string> ret2;
1958   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1959     {
1960       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1961       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1962         if(ret2.find(*it2)==ret2.end())
1963           {
1964             ret.push_back(*it2);
1965             ret2.insert(*it2);
1966           }
1967     }
1968   return ret;
1969 }
1970
1971 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1972 {
1973   std::vector<std::string> ret;
1974   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1975     {
1976       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1977       ret.insert(ret.end(),tmp.begin(),tmp.end());
1978     }
1979   return ret;
1980 }
1981
1982 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1983 {
1984   std::vector<std::string> ret;
1985   std::set<std::string> ret2;
1986   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1987     {
1988       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1989       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1990         if(ret2.find(*it2)==ret2.end())
1991           {
1992             ret.push_back(*it2);
1993             ret2.insert(*it2);
1994           }
1995     }
1996   return ret;
1997 }
1998
1999 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2000 {
2001   std::vector<std::string> ret;
2002   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2003     {
2004       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2005       ret.insert(ret.end(),tmp.begin(),tmp.end());
2006     }
2007   return ret;
2008 }
2009
2010 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2011 {
2012   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2013     {
2014       if((*it).first==_mesh_name)
2015         {
2016           _mesh_name=(*it).second;
2017           return true;
2018         }
2019     }
2020   return false;
2021 }
2022
2023 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2024                                                       MEDFileFieldGlobsReal& glob)
2025 {
2026   if(_mesh_name!=meshName)
2027     return false;
2028   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2029   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2030   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2031   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2032   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2033   getUndergroundDataArrayExt(entries);
2034   DataArray *arr0=getOrCreateAndGetArray();//tony
2035   if(!arr0)
2036     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2037   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
2038   if(!arr0)
2039     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2040   int sz=0;
2041   if(!arr)
2042     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2043   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2044     {
2045       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2046         {
2047           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2048           sz+=(*it).second.second-(*it).second.first;
2049         }
2050       else
2051         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2052     }
2053   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2054   ////////////////////
2055   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2056   int *workI2=explicitIdsOldInMesh->getPointer();
2057   int sz1=0,sz2=0,sid=1;
2058   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2059   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2060   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2061     {
2062       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2063       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2064       int *workI=explicitIdsOldInArr->getPointer();
2065       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2066         {
2067           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2068           (*itL2)->setLocId(sz2);
2069           (*itL2)->_tmp_work1=(*itL2)->getStart();
2070           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2071         }
2072       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2073     }
2074   explicitIdsOldInMesh->reAlloc(sz2);
2075   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2076   ////////////////////
2077   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2078   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2079   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2080   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2081     {
2082       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2083       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2084       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2085     }
2086   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2087   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2088   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2089     {
2090       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2091       int newStart=elt->getLocId();
2092       elt->setLocId((*it)->getGeoType());
2093       elt->setNewStart(newStart);
2094       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2095       entriesKeptNew.push_back(elt);
2096       entriesKeptNew2.push_back(elt);
2097     }
2098   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2099   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2100   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2101   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2102   bool ret=false;
2103   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2104     {
2105       sid=0;
2106       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2107         {
2108           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2109           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2110           }*/
2111       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2112                                                             glob,arr2,otherEntriesNew) || ret;
2113     }
2114   if(!ret)
2115     return false;
2116   // Assign new dispatching
2117   assignNewLeaves(otherEntriesNew);
2118   arr->deepCopyFrom(*arr2);
2119   return true;
2120 }
2121
2122 /*!
2123  * \param [in,out] globalNum a global numbering counter for the renumbering.
2124  * \param [out] its - list of pair (start,stop) kept
2125  */
2126 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2127 {
2128   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2129   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2130     {
2131       std::vector< std::pair<int,int> > its2;
2132       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2133         {
2134           ret.push_back(*it);
2135           its.insert(its.end(),its2.begin(),its2.end());
2136         }
2137     }
2138   _field_pm_pt=ret;
2139 }
2140
2141 /*!
2142  * \param [in,out] globalNum a global numbering counter for the renumbering.
2143  * \param [out] its - list of pair (start,stop) kept
2144  */
2145 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2146 {
2147   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > ret;
2148   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2149     {
2150       std::vector< std::pair<int,int> > its2;
2151       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2152         {
2153           ret.push_back(*it);
2154           its.insert(its.end(),its2.begin(),its2.end());
2155         }
2156     }
2157   _field_pm_pt=ret;
2158 }
2159
2160 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2161 {
2162   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2163   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2164     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2165   //
2166   std::vector< MCAuto< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2167   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2168   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2169   for(;it1!=types.end();it1++,it2++)
2170     {
2171       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2172       elt->setLeaves((*it1).second);
2173       *it2=elt;
2174     }
2175   _field_pm_pt=fieldPmPt;
2176 }
2177
2178 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2179 {
2180   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2181     (*it)->changePflsRefsNamesGen(mapOfModif);
2182 }
2183
2184 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2185 {
2186   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2187     (*it)->changeLocsRefsNamesGen(mapOfModif);
2188 }
2189
2190 /*!
2191  * \param [in] mesh is the whole mesh
2192  */
2193 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2194 {
2195   if(_field_pm_pt.empty())
2196     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2197   //
2198   std::vector< std::pair<int,int> > dads;
2199   std::vector<const DataArrayInt *> pfls;
2200   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2201   std::vector<int> locs,code;
2202   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2203   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2204     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2205   // Sort by types
2206   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2207   if(code.empty())
2208     {
2209       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2210       throw INTERP_KERNEL::Exception(oss.str());
2211     }
2212   //
2213   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2214   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2215   if(type!=ON_NODES)
2216     {
2217       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2218       if(!arr)
2219         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2220       else
2221         {
2222           MCAuto<DataArrayInt> arr2(arr);
2223           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2224         }
2225     }
2226   else
2227     {
2228       if(code.size()!=3)
2229         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2230       int nb=code[1];
2231       if(code[2]==-1)
2232         {
2233           if(nb!=mesh->getNumberOfNodes())
2234             {
2235               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2236               oss << " nodes in mesh !";
2237               throw INTERP_KERNEL::Exception(oss.str());
2238             }
2239           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2240         }
2241       else
2242         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2243     }
2244 }
2245
2246 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2247 {
2248   if(_field_pm_pt.empty())
2249     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2250   //
2251   std::vector<std::pair<int,int> > dads;
2252   std::vector<const DataArrayInt *> pfls;
2253   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2254   std::vector<int> locs,code;
2255   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2256   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2257     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2258   // Sort by types
2259   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2260   if(code.empty())
2261     {
2262       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2263       throw INTERP_KERNEL::Exception(oss.str());
2264     }
2265   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2266   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2267   if(type!=ON_NODES)
2268     {
2269       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2270       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2271     }
2272   else
2273     {
2274       if(code.size()!=3)
2275         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2276       int nb=code[1];
2277       if(code[2]==-1)
2278         {
2279           if(nb!=mesh->getNumberOfNodes())
2280             {
2281               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2282               oss << " nodes in mesh !";
2283               throw INTERP_KERNEL::Exception(oss.str());
2284             }
2285         }
2286       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2287     }
2288   //
2289   return 0;
2290 }
2291
2292 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2293 {
2294   int globalSz=0;
2295   int nbOfEntries=0;
2296   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2297     {
2298       (*it)->getSizes(globalSz,nbOfEntries);
2299     }
2300   entries.resize(nbOfEntries);
2301   nbOfEntries=0;
2302   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2303     {
2304       (*it)->fillValues(nbOfEntries,entries);
2305     }
2306 }
2307
2308 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2309 {
2310   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2311     {
2312       if((*it)->getGeoType()==typ)
2313         return (*it)->getLeafGivenLocId(locId);
2314     }
2315   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2316   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2317   oss << "Possiblities are : ";
2318   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2319     {
2320       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2321       oss << "\"" << cm2.getRepr() << "\", ";
2322     }
2323   throw INTERP_KERNEL::Exception(oss.str());
2324 }
2325
2326 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2327 {
2328   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2329     {
2330       if((*it)->getGeoType()==typ)
2331         return (*it)->getLeafGivenLocId(locId);
2332     }
2333   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2334   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2335   oss << "Possiblities are : ";
2336   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2337     {
2338       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2339       oss << "\"" << cm2.getRepr() << "\", ";
2340     }
2341   throw INTERP_KERNEL::Exception(oss.str());
2342 }
2343
2344 /*!
2345  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2346  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2347  * \param [in] dts - (Distribution of types) = level 1 : meshes to aggregate. Level 2 : all geo type. Level 3 pair specifying geo type and number of elem in geotype.
2348  * \param [out] extractInfo - Gives information about the where the data comes from. It is a vector of triplet. First element in the triplet the mesh pos. The 2nd one the start pos. The 3rd the end pos.
2349  */
2350 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> MEDFileFieldPerMeshPerTypePerDisc::Aggregate(int &start, const std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, TypeOfField tof, MEDFileFieldPerMeshPerType *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2351 {
2352   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2353   if(pms.empty())
2354     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2355   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2356     {
2357       if(!(*it).second)
2358         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2359       if(!(*it).second->getProfile().empty())
2360         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2361       if(!(*it).second->getLocalization().empty())
2362         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2363     }
2364   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2365   std::size_t i(0);
2366   std::vector< std::pair<int,int> > filteredDTS;
2367   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2368     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2369       if((*it2).first==gt)
2370         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2371   if(pms.size()!=filteredDTS.size())
2372     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2373   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2374   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2375   int zeStart(start),nval(0);
2376   for(;it1!=pms.end();it1++,it2++)
2377     {
2378       if((*it1).first!=(*it2).first)
2379         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2380       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2381       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2382       start+=e1-s1;
2383       nval+=((*it1).second)->getNumberOfVals();
2384     }
2385   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2386   return ret;
2387 }
2388
2389 MCAuto<MEDFileFieldPerMeshPerType> MEDFileFieldPerMeshPerType::Aggregate(int &start, const std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2390 {
2391   MCAuto<MEDFileFieldPerMeshPerType> ret(new MEDFileFieldPerMeshPerType(father,gt));
2392   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
2393   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2394     {
2395       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
2396         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
2397     }
2398   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
2399     {
2400       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2401       ret->_field_pm_pt_pd.push_back(agg);
2402     }
2403   return ret;
2404 }
2405
2406 MCAuto<MEDFileFieldPerMesh> MEDFileFieldPerMesh::Aggregate(int &start, const std::vector<const MEDFileFieldPerMesh *>& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2407 {
2408   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2409   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2410   std::size_t i(0);
2411   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2412     {
2413       const std::vector< MCAuto< MEDFileFieldPerMeshPerType > >& v((*it)->_field_pm_pt);
2414       for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2415         {
2416           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2417           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,*it2));
2418         }
2419     }
2420   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2421     {
2422       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2423       ret->_field_pm_pt.push_back(agg);
2424     }
2425   return ret;
2426 }
2427
2428 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2429 {
2430   int i=0;
2431   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2432   std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2433   for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2434     {
2435       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2436       if(type==curType)
2437         return i;
2438       else
2439         {
2440           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2441           if(pos>pos2)
2442             it2=it+1;
2443         }
2444     }
2445   int ret=std::distance(_field_pm_pt.begin(),it2);
2446   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2447   return ret;
2448 }
2449
2450 /*!
2451  * 'dads' and 'locs' input parameters have the same number of elements
2452  * \param [in] mesh is \b NOT the global mesh, but the possibly reduced mesh. \a mesh parameter will be directly aggregated in the returned field
2453  */
2454 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2455                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2456                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2457 {
2458   isPfl=false;
2459   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2460   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2461   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2462   const std::vector<std::string>& infos=getInfo();
2463   da->setInfoOnComponents(infos);
2464   da->setName("");
2465   if(type==ON_GAUSS_PT)
2466     {
2467       int offset=0;
2468       int nbOfArrs=dads.size();
2469       for(int i=0;i<nbOfArrs;i++)
2470         {
2471           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2472           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2473           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2474           MCAuto<DataArrayInt> di=DataArrayInt::New();
2475           di->alloc(nbOfElems,1);
2476           di->iota(offset);
2477           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2478           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2479           offset+=nbOfElems;
2480         }
2481     }
2482   arrOut=da;
2483   return ret.retn();
2484 }
2485
2486 /*!
2487  * This method is an extension of MEDFileFieldPerMesh::finishField method. It deals with profiles. This method should be called when type is different from ON_NODES.
2488  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2489  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2490  * The order of cells in the returned field is those imposed by the profile.
2491  * \param [in] mesh is the global mesh.
2492  */
2493 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2494                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2495                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2496                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2497 {
2498   if(da->isIota(mesh->getNumberOfCells()))
2499     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2500   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2501   m2->setName(mesh->getName().c_str());
2502   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2503   isPfl=true;
2504   return ret.retn();
2505 }
2506
2507 /*!
2508  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2509  */
2510 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2511                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2512                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2513 {
2514   if(da->isIota(mesh->getNumberOfNodes()))
2515     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2516   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2517   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2518   if(meshu)
2519     {
2520       if(meshu->getNodalConnectivity()==0)
2521         {
2522           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2523           int nb=da->getNbOfElems();
2524           const int *ptr=da->getConstPointer();
2525           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2526           meshuc->allocateCells(nb);
2527           for(int i=0;i<nb;i++)
2528             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2529           meshuc->finishInsertingCells();
2530           ret->setMesh(meshuc);
2531           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2532           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2533           disc->checkCoherencyBetween(meshuc,arrOut);
2534           return ret.retn();
2535         }
2536     }
2537   //
2538   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2539   isPfl=true;
2540   DataArrayInt *arr2=0;
2541   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2542   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2543   MCAuto<DataArrayInt> arr3(arr2);
2544   int nnodes=mesh2->getNumberOfNodes();
2545   if(nnodes==(int)da->getNbOfElems())
2546     {
2547       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2548       arrOut->renumberInPlace(da3->getConstPointer());
2549       mesh2->setName(mesh->getName().c_str());
2550       ret->setMesh(mesh2);
2551       return ret.retn();
2552     }
2553   else
2554     {
2555       std::ostringstream oss; oss << "MEDFileFieldPerMesh::finishFieldNode2 : The field on nodes lies on a node profile so that it is impossible to find a submesh having exactly the same nodes of that profile !!!";
2556       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2557       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2558       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2559       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2560       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2561       throw INTERP_KERNEL::Exception(oss.str());
2562     }
2563   return 0;
2564 }
2565
2566 /*!
2567  * This method is the most light method of field retrieving.
2568  */
2569 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2570 {
2571   if(!pflIn)
2572     {
2573       pflOut=DataArrayInt::New();
2574       pflOut->alloc(nbOfElems,1);
2575       pflOut->iota(0);
2576     }
2577   else
2578     {
2579       pflOut=const_cast<DataArrayInt*>(pflIn);
2580       pflOut->incrRef();
2581     }
2582   MCAuto<DataArrayInt> safePfl(pflOut);
2583   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2584   const std::vector<std::string>& infos=getInfo();
2585   int nbOfComp=infos.size();
2586   for(int i=0;i<nbOfComp;i++)
2587     da->setInfoOnComponent(i,infos[i].c_str());
2588   safePfl->incrRef();
2589   return da.retn();
2590 }
2591
2592
2593 /// @cond INTERNAL
2594
2595 class MFFPMIter
2596 {
2597 public:
2598   static MFFPMIter *NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2599   static bool IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2600   virtual ~MFFPMIter() { }
2601   virtual void begin() = 0;
2602   virtual bool finished() const = 0;
2603   virtual void next() = 0;
2604   virtual int current() const = 0;
2605 };
2606
2607 class MFFPMIterSimple : public MFFPMIter
2608 {
2609 public:
2610   MFFPMIterSimple():_pos(0) { }
2611   void begin() { _pos=0; }
2612   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2613   void next() { _pos++; }
2614   int current() const { return _pos; }
2615 private:
2616   int _pos;
2617 };
2618
2619 class MFFPMIter2 : public MFFPMIter
2620 {
2621 public:
2622   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2623   void begin() { _it=_ids.begin(); }
2624   bool finished() const { return _it==_ids.end(); }
2625   void next() { _it++; }
2626   int current() const { return *_it; }
2627 private:
2628   std::vector<int> _ids;
2629   std::vector<int>::const_iterator _it;
2630 };
2631
2632 MFFPMIter *MFFPMIter::NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2633 {
2634   if(!entities)
2635     return new MFFPMIterSimple;
2636   else
2637     {
2638       std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2639       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2640         {
2641           if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2642             tmp.push_back((*it).second);
2643         }
2644       return new MFFPMIter2(tmp);
2645     }
2646 }
2647
2648 bool MFFPMIter::IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2649 {
2650   if(!entities)
2651     return true;
2652   else
2653     {
2654       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2655         if((*it).first==ON_NODES)
2656           return true;
2657       return false;
2658     }
2659 }
2660
2661 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2662 {
2663   std::size_t sz(cts.size());
2664   _ids.resize(sz);
2665   for(std::size_t i=0;i<sz;i++)
2666     {
2667       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2668       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2669         _ids[i]=(int)std::distance(typmai2,loc);
2670       else
2671         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2672     }
2673 }
2674
2675 /// @endcond
2676
2677 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2678     _father(fath)
2679 {
2680   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2681   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2682   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2683   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2684   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2685   for(iter0->begin();!iter0->finished();iter0->next())
2686     {
2687       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2688       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2689       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2690       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2691       if(nbProfile>0 || nbProfile2>0)
2692         {
2693           const PartDefinition *pd(0);
2694           if(mmu)
2695             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2696           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2697           if(nbProfile>0)
2698             _mesh_name=name0;
2699           else
2700             _mesh_name=name1;
2701         }
2702     }
2703   if(MFFPMIter::IsPresenceOfNode(entities))
2704     {
2705       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2706       if(nbProfile>0)
2707         {
2708           const PartDefinition *pd(0);
2709           if(mmu)
2710             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2711           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2712           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2713         }
2714     }
2715 }
2716
2717 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2718 {
2719   copyTinyInfoFrom(mesh);
2720 }
2721
2722 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2723 {
2724   if(id>=(int)_pfls.size())
2725     _pfls.resize(id+1);
2726   _pfls[id]=DataArrayInt::New();
2727   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2728   _pfls[id]->setName(pflName);
2729   _pfls[id]->alloc(lgth,1);
2730   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2731   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2732 }
2733
2734 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2735 {
2736   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2737   int sz;
2738   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2739   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2740   if(i>=(int)_pfls.size())
2741     _pfls.resize(i+1);
2742   _pfls[i]=DataArrayInt::New();
2743   _pfls[i]->alloc(sz,1);
2744   _pfls[i]->setName(pflCpp.c_str());
2745   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2746   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2747 }
2748
2749 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2750 {
2751   int nbOfPfls=_pfls.size();
2752   for(int i=0;i<nbOfPfls;i++)
2753     {
2754       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2755       cpy->applyLin(1,1,0);
2756       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2757       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2758       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2759     }
2760   //
2761   int nbOfLocs=_locs.size();
2762   for(int i=0;i<nbOfLocs;i++)
2763     _locs[i]->writeLL(fid);
2764 }
2765
2766 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2767 {
2768   std::vector<std::string> pfls=getPfls();
2769   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2770     {
2771       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2772       if(it2==pfls.end())
2773         {
2774           _pfls.push_back(*it);
2775         }
2776       else
2777         {
2778           int id=std::distance(pfls.begin(),it2);
2779           if(!(*it)->isEqual(*_pfls[id]))
2780             {
2781               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2782               throw INTERP_KERNEL::Exception(oss.str());
2783             }
2784         }
2785     }
2786   std::vector<std::string> locs=getLocs();
2787   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2788     {
2789       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2790       if(it2==locs.end())
2791         {
2792           _locs.push_back(*it);
2793         }
2794       else
2795         {
2796           int id=std::distance(locs.begin(),it2);
2797           if(!(*it)->isEqual(*_locs[id],eps))
2798             {
2799               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2800               throw INTERP_KERNEL::Exception(oss.str());
2801             }
2802         }
2803     }
2804 }
2805
2806 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2807 {
2808   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2809     getProfile((*it).c_str());
2810 }
2811
2812 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2813 {
2814   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2815     getLocalization((*it).c_str());
2816 }
2817
2818 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2819 {
2820   std::vector<std::string> profiles=real.getPflsReallyUsed();
2821   int sz=profiles.size();
2822   _pfls.resize(sz);
2823   for(int i=0;i<sz;i++)
2824     loadProfileInFile(fid,i,profiles[i].c_str());
2825   //
2826   std::vector<std::string> locs=real.getLocsReallyUsed();
2827   sz=locs.size();
2828   _locs.resize(sz);
2829   for(int i=0;i<sz;i++)
2830     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2831 }
2832
2833 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2834 {
2835   int nProfil=MEDnProfile(fid);
2836   for(int i=0;i<nProfil;i++)
2837     loadProfileInFile(fid,i);
2838   int sz=MEDnLocalization(fid);
2839   _locs.resize(sz);
2840   for(int i=0;i<sz;i++)
2841     {
2842       _locs[i]=MEDFileFieldLoc::New(fid,i);
2843     }
2844 }
2845
2846 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2847 {
2848   return new MEDFileFieldGlobs(fname);
2849 }
2850
2851 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2852 {
2853   return new MEDFileFieldGlobs;
2854 }
2855
2856 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2857 {
2858   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
2859 }
2860
2861 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2862 {
2863   std::vector<const BigMemoryObject *> ret;
2864   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2865     ret.push_back((const DataArrayInt *)*it);
2866   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2867     ret.push_back((const MEDFileFieldLoc *)*it);
2868   return ret;
2869 }
2870
2871 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
2872 {
2873   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2874   std::size_t i=0;
2875   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2876     {
2877       if((const DataArrayInt *)*it)
2878         ret->_pfls[i]=(*it)->deepCopy();
2879     }
2880   i=0;
2881   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2882     {
2883       if((const MEDFileFieldLoc*)*it)
2884         ret->_locs[i]=(*it)->deepCopy();
2885     }
2886   return ret.retn();
2887 }
2888
2889 /*!
2890  * \throw if a profile in \a pfls in not in \a this.
2891  * \throw if a localization in \a locs in not in \a this.
2892  * \sa MEDFileFieldGlobs::deepCpyPart
2893  */
2894 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2895 {
2896   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2897   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2898     {
2899       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2900       if(!pfl)
2901         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2902       pfl->incrRef();
2903       MCAuto<DataArrayInt> pfl2(pfl);
2904       ret->_pfls.push_back(pfl2);
2905     }
2906   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2907     {
2908       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2909       if(!loc)
2910         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2911       loc->incrRef();
2912       MCAuto<MEDFileFieldLoc> loc2(loc);
2913       ret->_locs.push_back(loc2);
2914     }
2915   ret->setFileName(getFileName());
2916   return ret.retn();
2917 }
2918
2919 /*!
2920  * \throw if a profile in \a pfls in not in \a this.
2921  * \throw if a localization in \a locs in not in \a this.
2922  * \sa MEDFileFieldGlobs::shallowCpyPart
2923  */
2924 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2925 {
2926   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2927   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2928     {
2929       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2930       if(!pfl)
2931         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2932       ret->_pfls.push_back(pfl->deepCopy());
2933     }
2934   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2935     {
2936       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2937       if(!loc)
2938         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2939       ret->_locs.push_back(loc->deepCopy());
2940     }
2941   ret->setFileName(getFileName());
2942   return ret.retn();
2943 }
2944
2945 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2946 {
2947 }
2948
2949 MEDFileFieldGlobs::MEDFileFieldGlobs()
2950 {
2951 }
2952
2953 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2954 {
2955 }
2956
2957 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2958 {
2959   oss << "Profiles :\n";
2960   std::size_t n=_pfls.size();
2961   for(std::size_t i=0;i<n;i++)
2962     {
2963       oss << "  - #" << i << " ";
2964       const DataArrayInt *pfl=_pfls[i];
2965       if(pfl)
2966         oss << "\"" << pfl->getName() << "\"\n";
2967       else
2968         oss << "EMPTY !\n";
2969     }
2970   n=_locs.size();
2971   oss << "Localizations :\n";
2972   for(std::size_t i=0;i<n;i++)
2973     {
2974       oss << "  - #" << i << " ";
2975       const MEDFileFieldLoc *loc=_locs[i];
2976       if(loc)
2977         loc->simpleRepr(oss);
2978       else
2979         oss<< "EMPTY !\n";
2980     }
2981 }
2982
2983 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2984 {
2985   _file_name=fileName;
2986 }
2987
2988 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2989 {
2990   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2991     {
2992       DataArrayInt *elt(*it);
2993       if(elt)
2994         {
2995           std::string name(elt->getName());
2996           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2997             {
2998               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2999                 {
3000                   elt->setName((*it2).second.c_str());
3001                   return;
3002                 }
3003             }
3004         }
3005     }
3006 }
3007
3008 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3009 {
3010   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3011     {
3012       MEDFileFieldLoc *elt(*it);
3013       if(elt)
3014         {
3015           std::string name(elt->getName());
3016           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3017             {
3018               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3019                 {
3020                   elt->setName((*it2).second.c_str());
3021                   return;
3022                 }
3023             }
3024         }
3025     }
3026 }
3027
3028 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3029 {
3030   if(locId<0 || locId>=(int)_locs.size())
3031     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3032   return _locs[locId]->getNbOfGaussPtPerCell();
3033 }
3034
3035 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3036 {
3037   return getLocalizationFromId(getLocalizationId(locName));
3038 }
3039
3040 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3041 {
3042   if(locId<0 || locId>=(int)_locs.size())
3043     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3044   return *_locs[locId];
3045 }
3046
3047 /// @cond INTERNAL
3048 namespace MEDCouplingImpl
3049 {
3050   class LocFinder
3051   {
3052   public:
3053     LocFinder(const std::string& loc):_loc(loc) { }
3054     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3055   private:
3056     const std::string &_loc;
3057   };
3058
3059   class PflFinder
3060   {
3061   public:
3062     PflFinder(const std::string& pfl):_pfl(pfl) { }
3063     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3064   private:
3065     const std::string& _pfl;
3066   };
3067 }
3068 /// @endcond
3069
3070 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3071 {
3072   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3073   if(it==_locs.end())
3074     {
3075       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3076       for(it=_locs.begin();it!=_locs.end();it++)
3077         oss << "\"" << (*it)->getName() << "\", ";
3078       throw INTERP_KERNEL::Exception(oss.str());
3079     }
3080   return std::distance(_locs.begin(),it);
3081 }
3082
3083 /*!
3084  * The returned value is never null.
3085  */
3086 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3087 {
3088   std::string pflNameCpp(pflName);
3089   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3090   if(it==_pfls.end())
3091     {
3092       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3093       for(it=_pfls.begin();it!=_pfls.end();it++)
3094         oss << "\"" << (*it)->getName() << "\", ";
3095       throw INTERP_KERNEL::Exception(oss.str());
3096     }
3097   return *it;
3098 }
3099
3100 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3101 {
3102   if(pflId<0 || pflId>=(int)_pfls.size())
3103     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3104   return _pfls[pflId];
3105 }
3106
3107 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3108 {
3109   if(locId<0 || locId>=(int)_locs.size())
3110     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3111   return *_locs[locId];
3112 }
3113
3114 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3115 {
3116   return getLocalizationFromId(getLocalizationId(locName));
3117 }
3118
3119 /*!
3120  * The returned value is never null.
3121  */
3122 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3123 {
3124   std::string pflNameCpp(pflName);
3125   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3126   if(it==_pfls.end())
3127     {
3128       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3129       for(it=_pfls.begin();it!=_pfls.end();it++)
3130         oss << "\"" << (*it)->getName() << "\", ";
3131       throw INTERP_KERNEL::Exception(oss.str());
3132     }
3133   return *it;
3134 }
3135
3136 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3137 {
3138   if(pflId<0 || pflId>=(int)_pfls.size())
3139     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3140   return _pfls[pflId];
3141 }
3142
3143 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3144 {
3145   std::vector< MCAuto<DataArrayInt> > newPfls;
3146   int i=0;
3147   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3148     {
3149       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3150         newPfls.push_back(*it);
3151     }
3152   _pfls=newPfls;
3153 }
3154
3155 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3156 {
3157   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3158   int i=0;
3159   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3160     {
3161       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3162         newLocs.push_back(*it);
3163     }
3164   _locs=newLocs;
3165 }
3166
3167 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3168 {
3169   int sz=_pfls.size();
3170   std::vector<std::string> ret(sz);
3171   for(int i=0;i<sz;i++)
3172     ret[i]=_pfls[i]->getName();
3173   return ret;
3174 }
3175
3176 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3177 {
3178   int sz=_locs.size();
3179   std::vector<std::string> ret(sz);
3180   for(int i=0;i<sz;i++)
3181     ret[i]=_locs[i]->getName();
3182   return ret;
3183 }
3184
3185 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3186 {
3187   std::vector<std::string> v=getPfls();
3188   std::string s(pflName);
3189   return std::find(v.begin(),v.end(),s)!=v.end();
3190 }
3191
3192 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3193 {
3194   std::vector<std::string> v=getLocs();
3195   std::string s(locName);
3196   return std::find(v.begin(),v.end(),s)!=v.end();
3197 }
3198
3199 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3200 {
3201   std::map<int,std::vector<int> > m;
3202   int i=0;
3203   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3204     {
3205       const DataArrayInt *tmp=(*it);
3206       if(tmp)
3207         {
3208           m[tmp->getHashCode()].push_back(i);
3209         }
3210     }
3211   std::vector< std::vector<int> > ret;
3212   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3213     {
3214       if((*it2).second.size()>1)
3215         {
3216           std::vector<int> ret0;
3217           bool equalityOrNot=false;
3218           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3219             {
3220               std::vector<int>::const_iterator it4=it3; it4++;
3221               for(;it4!=(*it2).second.end();it4++)
3222                 {
3223                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3224                     {
3225                       if(!equalityOrNot)
3226                         ret0.push_back(*it3);
3227                       ret0.push_back(*it4);
3228                       equalityOrNot=true;
3229                     }
3230                 }
3231             }
3232           if(!ret0.empty())
3233             ret.push_back(ret0);
3234         }
3235     }
3236   return ret;
3237 }
3238
3239 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3240 {
3241   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3242 }
3243
3244 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3245 {
3246   std::string name(pfl->getName());
3247   if(name.empty())
3248     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3249   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3250     if(name==(*it)->getName())
3251       {
3252         if(!pfl->isEqual(*(*it)))
3253           {
3254             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3255             throw INTERP_KERNEL::Exception(oss.str());
3256           }
3257       }
3258   pfl->incrRef();
3259   _pfls.push_back(pfl);
3260 }
3261
3262 void MEDFileFieldGlobs::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
3263 {
3264   std::string name(locName);
3265   if(name.empty())
3266     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3267   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3268   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3269     if((*it)->isName(locName))
3270       {
3271         if(!(*it)->isEqual(*obj,1e-12))
3272           {
3273             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3274             throw INTERP_KERNEL::Exception(oss.str());
3275           }
3276       }
3277   _locs.push_back(obj);
3278 }
3279
3280 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3281 {
3282   std::vector<std::string> names=getPfls();
3283   return CreateNewNameNotIn("NewPfl_",names);
3284 }
3285
3286 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3287 {
3288   std::vector<std::string> names=getLocs();
3289   return CreateNewNameNotIn("NewLoc_",names);
3290 }
3291
3292 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3293 {
3294   for(std::size_t sz=0;sz<100000;sz++)
3295     {
3296       std::ostringstream tryName;
3297       tryName << prefix << sz;
3298       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3299         return tryName.str();
3300     }
3301   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3302 }
3303
3304 /*!
3305  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3306  *  \param [in] fname - the file name.
3307  */
3308 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3309 {
3310 }
3311
3312 /*!
3313  * Creates an empty MEDFileFieldGlobsReal.
3314  */
3315 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3316 {
3317 }
3318
3319 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3320 {
3321   return 0;
3322 }
3323
3324 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3325 {
3326   std::vector<const BigMemoryObject *> ret;
3327   ret.push_back((const MEDFileFieldGlobs *)_globals);
3328   return ret;
3329 }
3330
3331 /*!
3332  * Returns a string describing profiles and Gauss points held in \a this.
3333  *  \return std::string - the description string.
3334  */
3335 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3336 {
3337   const MEDFileFieldGlobs *glob=_globals;
3338   std::ostringstream oss2; oss2 << glob;
3339   std::string stars(oss2.str().length(),'*');
3340   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3341   if(glob)
3342     glob->simpleRepr(oss);
3343   else
3344     oss << "NO GLOBAL INFORMATION !\n";
3345 }
3346
3347 void MEDFileFieldGlobsReal::resetContent()
3348 {
3349   _globals=MEDFileFieldGlobs::New();
3350 }
3351
3352 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3353 {
3354 }
3355
3356 /*!
3357  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3358  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3359  */
3360 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3361 {
3362   _globals=other._globals;
3363 }
3364
3365 /*!
3366  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3367  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3368  */
3369 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3370 {
3371   const MEDFileFieldGlobs *otherg(other._globals);
3372   if(!otherg)
3373     return ;
3374   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3375 }
3376
3377 /*!
3378  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3379  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3380  */
3381 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3382 {
3383   const MEDFileFieldGlobs *otherg(other._globals);
3384   if(!otherg)
3385     return ;
3386   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3387 }
3388
3389 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3390 {
3391   _globals=other._globals;
3392   if((const MEDFileFieldGlobs *)_globals)
3393     _globals=other._globals->deepCopy();
3394 }
3395
3396 /*!
3397  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3398  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3399  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3400  *         \a this and \a other MEDFileFieldGlobsReal.
3401  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3402  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3403  */
3404 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3405 {
3406   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3407   if(thisGlobals==otherGlobals)
3408     return ;
3409   if(!thisGlobals)
3410     {
3411       _globals=other._globals;
3412       return ;
3413     }
3414   _globals->appendGlobs(*other._globals,eps);
3415 }
3416
3417 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3418 {
3419   checkGlobsPflsPartCoherency();
3420   checkGlobsLocsPartCoherency();
3421 }
3422
3423 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3424 {
3425   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3426 }
3427
3428 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3429 {
3430   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3431 }
3432
3433 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3434 {
3435   contentNotNull()->loadProfileInFile(fid,id,pflName);
3436 }
3437
3438 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3439 {
3440   contentNotNull()->loadProfileInFile(fid,id);
3441 }
3442
3443 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3444 {
3445   contentNotNull()->loadGlobals(fid,*this);
3446 }
3447
3448 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3449 {
3450   contentNotNull()->loadAllGlobals(fid);
3451 }
3452
3453 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3454 {
3455   contentNotNull()->writeGlobals(fid,opt);
3456 }
3457
3458 /*!
3459  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3460  * or getPflsReallyUsedMulti().
3461  *  \return std::vector<std::string> - a sequence of names of all profiles.
3462  */
3463 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3464 {
3465   return contentNotNull()->getPfls();
3466 }
3467
3468 /*!
3469  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3470  * or getLocsReallyUsedMulti().
3471  *  \return std::vector<std::string> - a sequence of names of all localizations.
3472  */
3473 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3474 {
3475   return contentNotNull()->getLocs();
3476 }
3477
3478 /*!
3479  * Checks if the profile with a given name exists.
3480  *  \param [in] pflName - the profile name of interest.
3481  *  \return bool - \c true if the profile named \a pflName exists.
3482  */
3483 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3484 {
3485   return contentNotNull()->existsPfl(pflName);
3486 }
3487
3488 /*!
3489  * Checks if the localization with a given name exists.
3490  *  \param [in] locName - the localization name of interest.
3491  *  \return bool - \c true if the localization named \a locName exists.
3492  */
3493 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3494 {
3495   return contentNotNull()->existsLoc(locName);
3496 }
3497
3498 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3499 {
3500   return contentNotNull()->createNewNameOfPfl();
3501 }
3502
3503 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3504 {
3505   return contentNotNull()->createNewNameOfLoc();
3506 }
3507
3508 /*!
3509  * Sets the name of a MED file.
3510  *  \param [inout] fileName - the file name.
3511  */
3512 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3513 {
3514   contentNotNull()->setFileName(fileName);
3515 }
3516
3517 /*!
3518  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3519  * in the same order.
3520  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3521  *          Each item of this sequence is a vector containing ids of equal profiles.
3522  */
3523 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3524 {
3525   return contentNotNull()->whichAreEqualProfiles();
3526 }
3527
3528 /*!
3529  * Finds equal localizations.
3530  *  \param [in] eps - a precision used to compare real values of the localizations.
3531  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3532  *          Each item of this sequence is a vector containing ids of equal localizations.
3533  */
3534 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3535 {
3536   return contentNotNull()->whichAreEqualLocs(eps);
3537 }
3538
3539 /*!
3540  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3541  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3542  *        this sequence is a pair whose 
3543  *        - the first item is a vector of profile names to replace by the second item,
3544  *        - the second item is a profile name to replace every profile name of the first item.
3545  */
3546 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3547 {
3548   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3549 }
3550
3551 /*!
3552  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3553  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3554  *        this sequence is a pair whose 
3555  *        - the first item is a vector of localization names to replace by the second item,
3556  *        - the second item is a localization name to replace every localization name of the first item.
3557  */
3558 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3559 {
3560   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3561 }
3562
3563 /*!
3564  * Replaces references to some profiles (a reference is a profile name) by references
3565  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3566  * them-selves accordingly. <br>
3567  * This method is a generalization of changePflName().
3568  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3569  *        this sequence is a pair whose 
3570  *        - the first item is a vector of profile names to replace by the second item,
3571  *        - the second item is a profile name to replace every profile of the first item.
3572  * \sa changePflsRefsNamesGen()
3573  * \sa changePflName()
3574  */
3575 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3576 {
3577   changePflsRefsNamesGen(mapOfModif);
3578   changePflsNamesInStruct(mapOfModif);
3579 }
3580
3581 /*!
3582  * Replaces references to some localizations (a reference is a localization name) by references
3583  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3584  * them-selves accordingly. <br>
3585  * This method is a generalization of changeLocName().
3586  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3587  *        this sequence is a pair whose 
3588  *        - the first item is a vector of localization names to replace by the second item,
3589  *        - the second item is a localization name to replace every localization of the first item.
3590  * \sa changeLocsRefsNamesGen()
3591  * \sa changeLocName()
3592  */
3593 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3594 {
3595   changeLocsRefsNamesGen(mapOfModif);
3596   changeLocsNamesInStruct(mapOfModif);
3597 }
3598
3599 /*!
3600  * Renames the profile having a given name and updates references to this profile.
3601  *  \param [in] oldName - the name of the profile to rename.
3602  *  \param [in] newName - a new name of the profile.
3603  * \sa changePflsNames().
3604  */
3605 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3606 {
3607   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3608   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3609   mapOfModif[0]=p;
3610   changePflsNames(mapOfModif);
3611 }
3612
3613 /*!
3614  * Renames the localization having a given name and updates references to this localization.
3615  *  \param [in] oldName - the name of the localization to rename.
3616  *  \param [in] newName - a new name of the localization.
3617  * \sa changeLocsNames().
3618  */
3619 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3620 {
3621   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3622   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3623   mapOfModif[0]=p;
3624   changeLocsNames(mapOfModif);
3625 }
3626
3627 /*!
3628  * Removes duplicated profiles. Returns a map used to update references to removed 
3629  * profiles via changePflsRefsNamesGen().
3630  * Equal profiles are found using whichAreEqualProfiles().
3631  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3632  *          a sequence describing the performed replacements of profiles. Each element of
3633  *          this sequence is a pair whose
3634  *          - the first item is a vector of profile names replaced by the second item,
3635  *          - the second item is a profile name replacing every profile of the first item.
3636  */
3637 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3638 {
3639   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3640   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3641   int i=0;
3642   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3643     {
3644       std::vector< std::string > tmp((*it).size());
3645       int j=0;
3646       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3647         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3648       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3649       ret[i]=p;
3650       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3651       killProfileIds(tmp2);
3652     }
3653   changePflsRefsNamesGen(ret);
3654   return ret;
3655 }
3656
3657 /*!
3658  * Removes duplicated localizations. Returns a map used to update references to removed 
3659  * localizations via changeLocsRefsNamesGen().
3660  * Equal localizations are found using whichAreEqualLocs().
3661  *  \param [in] eps - a precision used to compare real values of the localizations.
3662  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3663  *          a sequence describing the performed replacements of localizations. Each element of
3664  *          this sequence is a pair whose
3665  *          - the first item is a vector of localization names replaced by the second item,
3666  *          - the second item is a localization name replacing every localization of the first item.
3667  */
3668 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3669 {
3670   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3671   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3672   int i=0;
3673   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3674     {
3675       std::vector< std::string > tmp((*it).size());
3676       int j=0;
3677       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3678         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3679       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3680       ret[i]=p;
3681       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3682       killLocalizationIds(tmp2);
3683     }
3684   changeLocsRefsNamesGen(ret);
3685   return ret;
3686 }
3687
3688 /*!
3689  * Returns number of Gauss points per cell in a given localization.
3690  *  \param [in] locId - an id of the localization of interest.
3691  *  \return int - the number of the Gauss points per cell.
3692  */
3693 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3694 {
3695   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3696 }
3697
3698 /*!
3699  * Returns an id of a localization by its name.
3700  *  \param [in] loc - the localization name of interest.
3701  *  \return int - the id of the localization.
3702  *  \throw If there is no a localization named \a loc.
3703  */
3704 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3705 {
3706   return contentNotNull()->getLocalizationId(loc);
3707 }
3708
3709 /*!
3710  * Returns the name of the MED file.
3711  *  \return const std::string&  - the MED file name.
3712  */
3713 std::string MEDFileFieldGlobsReal::getFileName() const
3714 {
3715   return contentNotNull()->getFileName();
3716 }
3717
3718 /*!
3719  * Returns a localization object by its name.
3720  *  \param [in] locName - the name of the localization of interest.
3721  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3722  *  \throw If there is no a localization named \a locName.
3723  */
3724 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3725 {
3726   return contentNotNull()->getLocalization(locName);
3727 }
3728
3729 /*!
3730  * Returns a localization object by its id.
3731  *  \param [in] locId - the id of the localization of interest.
3732  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3733  *  \throw If there is no a localization with id \a locId.
3734  */
3735 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3736 {
3737   return contentNotNull()->getLocalizationFromId(locId);
3738 }
3739
3740 /*!
3741  * Returns a profile array by its name.
3742  *  \param [in] pflName - the name of the profile of interest.
3743  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3744  *  \throw If there is no a profile named \a pflName.
3745  */
3746 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3747 {
3748   return contentNotNull()->getProfile(pflName);
3749 }
3750
3751 /*!
3752  * Returns a profile array by its id.
3753  *  \param [in] pflId - the id of the profile of interest.
3754  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3755  *  \throw If there is no a profile with id \a pflId.
3756  */
3757 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3758 {
3759   return contentNotNull()->getProfileFromId(pflId);
3760 }
3761
3762 /*!
3763  * Returns a localization object, apt for modification, by its id.
3764  *  \param [in] locId - the id of the localization of interest.
3765  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3766  *          having the id \a locId.
3767  *  \throw If there is no a localization with id \a locId.
3768  */
3769 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3770 {
3771   return contentNotNull()->getLocalizationFromId(locId);
3772 }
3773
3774 /*!
3775  * Returns a localization object, apt for modification, by its name.
3776  *  \param [in] locName - the name of the localization of interest.
3777  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3778  *          having the name \a locName.
3779  *  \throw If there is no a localization named \a locName.
3780  */
3781 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3782 {
3783   return contentNotNull()->getLocalization(locName);
3784 }
3785
3786 /*!
3787  * Returns a profile array, apt for modification, by its name.
3788  *  \param [in] pflName - the name of the profile of interest.
3789  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3790  *  \throw If there is no a profile named \a pflName.
3791  */
3792 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3793 {
3794   return contentNotNull()->getProfile(pflName);
3795 }
3796
3797 /*!
3798  * Returns a profile array, apt for modification, by its id.
3799  *  \param [in] pflId - the id of the profile of interest.
3800  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3801  *  \throw If there is no a profile with id \a pflId.
3802  */
3803 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3804 {
3805   return contentNotNull()->getProfileFromId(pflId);
3806 }
3807
3808 /*!
3809  * Removes profiles given by their ids. No data is updated to track this removal.
3810  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3811  */
3812 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3813 {
3814   contentNotNull()->killProfileIds(pflIds);
3815 }
3816
3817 /*!
3818  * Removes localizations given by their ids. No data is updated to track this removal.
3819  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3820  */
3821 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3822 {
3823   contentNotNull()->killLocalizationIds(locIds);
3824 }
3825
3826 /*!
3827  * Stores a profile array.
3828  *  \param [in] pfl - the profile array to store.
3829  *  \throw If the name of \a pfl is empty.
3830  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3831  *         different ids.
3832  */
3833 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3834 {
3835   contentNotNull()->appendProfile(pfl);
3836 }
3837
3838 /*!
3839  * Adds a new localization of Gauss points.
3840  *  \param [in] locName - the name of the new localization.
3841  *  \param [in] geoType - a geometrical type of the reference cell.
3842  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3843  *         must be \c nbOfNodesPerCell * \c dimOfType.
3844  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3845  *         must be  _wg_.size() * \c dimOfType.
3846  *  \param [in] w - the weights of Gauss points.
3847  *  \throw If \a locName is empty.
3848  *  \throw If a localization with the name \a locName already exists but is
3849  *         different form the new one.
3850  */
3851 void MEDFileFieldGlobsReal::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
3852 {
3853   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3854 }
3855
3856 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3857 {
3858   MEDFileFieldGlobs *g(_globals);
3859   if(!g)
3860     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3861   return g;
3862 }
3863
3864 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3865 {
3866   const MEDFileFieldGlobs *g(_globals);
3867   if(!g)
3868     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3869   return g;
3870 }
3871
3872 //= MEDFileFieldNameScope
3873
3874 MEDFileFieldNameScope::MEDFileFieldNameScope()
3875 {
3876 }
3877
3878 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3879 {
3880 }
3881
3882 /*!
3883  * Returns the name of \a this field.
3884  *  \return std::string - a string containing the field name.
3885  */
3886 std::string MEDFileFieldNameScope::getName() const
3887 {
3888   return _name;
3889 }
3890
3891 /*!
3892  * Sets name of \a this field
3893  *  \param [in] name - the new field name.
3894  */
3895 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3896 {
3897   _name=fieldName;
3898 }
3899
3900 std::string MEDFileFieldNameScope::getDtUnit() const
3901 {
3902   return _dt_unit;
3903 }
3904
3905 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3906 {
3907   _dt_unit=dtUnit;
3908 }
3909
3910 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3911 {
3912   _name=other._name;
3913   _dt_unit=other._dt_unit;
3914 }
3915
3916 //= MEDFileAnyTypeField1TSWithoutSDA
3917
3918 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3919 {
3920   _field_per_mesh.resize(other._field_per_mesh.size());
3921   std::size_t i=0;
3922   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3923     {
3924       if((const MEDFileFieldPerMesh *)*it)
3925         _field_per_mesh[i]=(*it)->deepCopy(this);
3926     }
3927 }
3928
3929 /*!
3930  * Prints a string describing \a this field into a stream. This string is outputted 
3931  * by \c print Python command.
3932  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3933  *  \param [in,out] oss - the out stream.
3934  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3935  *          info id printed, else, not.
3936  */
3937 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3938 {
3939   std::string startOfLine(bkOffset,' ');
3940   oss << startOfLine << "Field ";
3941   if(bkOffset==0)
3942     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3943   oss << "on one time Step ";
3944   if(f1tsId>=0)
3945     oss << "(" << f1tsId << ") ";
3946   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3947   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3948   const DataArray *arr=getUndergroundDataArray();
3949   if(arr)
3950     {
3951       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3952       if(f1tsId<0)
3953         {
3954           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3955           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3956             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3957         }
3958       if(arr->isAllocated())
3959         {
3960           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3961         }
3962       else
3963         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3964     }
3965   else
3966     {
3967       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3968     }
3969   oss << startOfLine << "----------------------" << std::endl;
3970   if(!_field_per_mesh.empty())
3971     {
3972       int i=0;
3973       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3974         {
3975           const MEDFileFieldPerMesh *cur=(*it2);
3976           if(cur)
3977             cur->simpleRepr(bkOffset,oss,i);
3978           else
3979             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3980         }
3981     }
3982   else
3983     {
3984       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3985     }
3986   oss << startOfLine << "----------------------" << std::endl;
3987 }
3988
3989 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3990 {
3991   const DataArray *arr(getUndergroundDataArray());
3992   if(!arr)
3993     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3994   int nbOfCompo=arr->getNumberOfComponents();
3995   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3996   for(int i=0;i<nbOfCompo;i++)
3997     {
3998       ret[i]=deepCopy();
3999       std::vector<int> v(1,i);
4000       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4001       ret[i]->setArray(arr2);
4002     }
4003   return ret;
4004 }
4005
4006 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName),_iteration(iteration),_order(order),_csit(csit),_nb_of_tuples_to_be_allocated(-2)
4007 {
4008 }
4009
4010 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4011 {
4012 }
4013
4014 /*!
4015  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4016  * empty. Returns -1 if this in on nodes.
4017  *  \return int - the dimension of \a this.
4018  */
4019 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4020 {
4021   int ret=-2;
4022   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4023     (*it)->getDimension(ret);
4024   return ret;
4025 }
4026
4027 /*!
4028  * Returns the mesh name.
4029  *  \return std::string - a string holding the mesh name.
4030  *  \throw If \c _field_per_mesh.empty()
4031  */
4032 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
4033 {
4034   if(_field_per_mesh.empty())
4035     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
4036   return _field_per_mesh[0]->getMeshName();
4037 }
4038
4039 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
4040 {
4041   std::string oldName(getMeshName());
4042   std::vector< std::pair<std::string,std::string> > v(1);
4043   v[0].first=oldName; v[0].second=newMeshName;
4044   changeMeshNames(v);
4045 }
4046
4047 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4048 {
4049   bool ret=false;
4050   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4051     {
4052       MEDFileFieldPerMesh *cur(*it);
4053       if(cur)
4054         ret=cur->changeMeshNames(modifTab) || ret;
4055     }
4056   return ret;
4057 }
4058
4059 /*!
4060  * Returns the number of iteration of the state of underlying mesh.
4061  *  \return int - the iteration number.
4062  *  \throw If \c _field_per_mesh.empty()
4063  */
4064 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4065 {
4066   if(_field_per_mesh.empty())
4067     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4068   return _field_per_mesh[0]->getMeshIteration();
4069 }
4070
4071 /*!
4072  * Returns the order number of iteration of the state of underlying mesh.
4073  *  \return int - the order number.
4074  *  \throw If \c _field_per_mesh.empty()
4075  */
4076 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4077 {
4078   if(_field_per_mesh.empty())
4079     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4080   return _field_per_mesh[0]->getMeshOrder();
4081 }
4082
4083 /*!
4084  * Checks if \a this field is tagged by a given iteration number and a given
4085  * iteration order number.
4086  *  \param [in] iteration - the iteration number of interest.
4087  *  \param [in] order - the iteration order number of interest.
4088  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4089  *          \a this->getOrder() == \a order.
4090  */
4091 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4092 {
4093   return iteration==_iteration && order==_order;
4094 }
4095
4096 /*!
4097  * Returns number of iteration and order number of iteration when
4098  * \a this field has been calculated.
4099  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4100  *          order number.
4101  */
4102 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4103 {
4104   std::pair<int,int> p;
4105   fillIteration(p);
4106   return p;
4107 }
4108
4109 /*!
4110  * Returns number of iteration and order number of iteration when
4111  * \a this field has been calculated.
4112  *  \param [in,out] p - a pair returning the iteration number and the iteration
4113  *          order number.
4114  */
4115 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4116 {
4117   p.first=_iteration;
4118   p.second=_order;
4119 }
4120
4121 /*!
4122  * Returns all types of spatial discretization of \a this field.
4123  *  \param [in,out] types - a sequence of types of \a this field.
4124  */
4125 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4126 {
4127   std::set<TypeOfField> types2;
4128   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4129     {
4130       (*it)->fillTypesOfFieldAvailable(types2);
4131     }
4132   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4133   std::copy(types2.begin(),types2.end(),bi);
4134 }
4135
4136 /*!
4137  * Returns all types of spatial discretization of \a this field.
4138  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4139  *          of \a this field.
4140  */
4141 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4142 {
4143   std::vector<TypeOfField> ret;
4144   fillTypesOfFieldAvailable(ret);
4145   return ret;
4146 }
4147
4148 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4149 {
4150   std::vector<std::string> ret;
4151   std::set<std::string> ret2;
4152   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4153     {
4154       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4155       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4156         if(ret2.find(*it2)==ret2.end())
4157           {
4158             ret.push_back(*it2);
4159             ret2.insert(*it2);
4160           }
4161     }
4162   return ret;
4163 }
4164
4165 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4166 {
4167   std::vector<std::string> ret;
4168   std::set<std::string> ret2;
4169   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4170     {
4171       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4172       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4173         if(ret2.find(*it2)==ret2.end())
4174           {
4175             ret.push_back(*it2);
4176             ret2.insert(*it2);
4177           }
4178     }
4179   return ret;
4180 }
4181
4182 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4183 {
4184   std::vector<std::string> ret;
4185   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4186     {
4187       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4188       ret.insert(ret.end(),tmp.begin(),tmp.end());
4189     }
4190   return ret;
4191 }
4192
4193 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4194 {
4195   std::vector<std::string> ret;
4196   std::set<std::string> ret2;
4197   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4198     {
4199       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4200       ret.insert(ret.end(),tmp.begin(),tmp.end());
4201     }
4202   return ret;
4203 }
4204
4205 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4206 {
4207   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4208     (*it)->changePflsRefsNamesGen(mapOfModif);
4209 }
4210
4211 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4212 {
4213   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4214     (*it)->changeLocsRefsNamesGen(mapOfModif);
4215 }
4216
4217 /*!
4218  * Returns all attributes of parts of \a this field lying on a given mesh.
4219  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4220  * item of every of returned sequences refers to the _i_-th part of \a this field.
4221  * Thus all sequences returned by this method are of the same length equal to number
4222  * of different types of supporting entities.<br>
4223  * A field part can include sub-parts with several different spatial discretizations,
4224  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4225  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4226  * of a nested sequence corresponds to a type of spatial discretization.<br>
4227  * This method allows for iteration over MEDFile DataStructure without any overhead.
4228  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4229  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4230  *          not checked if \a mname == \c NULL).
4231  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4232  *          a field part is returned. 
4233  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4234  *          This sequence is of the same length as \a types. 
4235  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4236  *          discretization. A profile name can be empty.
4237  *          Length of this and of nested sequences is the same as that of \a typesF.
4238  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4239  *          discretization. A localization name can be empty.
4240  *          Length of this and of nested sequences is the same as that of \a typesF.
4241  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4242  *          of ids of tuples within the data array, per each type of spatial
4243  *          discretization within one mesh entity type. 
4244  *          Length of this and of nested sequences is the same as that of \a typesF.
4245  *  \throw If no field is lying on \a mname.
4246  */
4247 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeField1TSWithoutSDA::getFieldSplitedByType(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
4248 {
4249   int meshId=0;
4250   if(!mname.empty())
4251     meshId=getMeshIdFromMeshName(mname);
4252   else
4253     if(_field_per_mesh.empty())
4254       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4255   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4256 }
4257
4258 /*!
4259  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4260  * maximal absolute dimension and values returned via the out parameter \a levs are 
4261  * dimensions relative to the maximal absolute dimension. <br>
4262  * This method is designed for MEDFileField1TS instances that have a discretization
4263  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4264  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4265  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4266  * Only these 3 discretizations will be taken into account here. If \a this is
4267  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4268  * This method is useful to make the link between the dimension of the underlying mesh
4269  * and the levels of \a this, because it is possible that the highest dimension of \a this
4270  * field is not equal to the dimension of the underlying mesh.
4271  * 
4272  * Let's consider the following case:
4273  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4274  * TETRA4, HEXA8, TRI3 and SEG2.
4275  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4276  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4277  *
4278  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4279  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4280  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4281  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4282  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4283  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4284  * For example<br>
4285  * to retrieve the highest level of
4286  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4287  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4288  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4289  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4290  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4291  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4292  *          not checked if \a mname == \c NULL).
4293  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4294  *          absolute one. They are in decreasing order. This sequence is cleared before
4295  *          filling it in.
4296  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4297  *  \throw If no field is lying on \a mname.
4298  */
4299 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4300 {
4301   levs.clear();
4302   int meshId=getMeshIdFromMeshName(mname);
4303   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4304   std::vector< std::vector<TypeOfField> > typesF;
4305   std::vector< std::vector<std::string> > pfls, locs;
4306   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4307   if(types.empty())
4308     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4309   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4310   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4311     return -1;
4312   st.erase(INTERP_KERNEL::NORM_ERROR);
4313   std::set<int> ret1;
4314   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4315     {
4316       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4317       ret1.insert((int)cm.getDimension());
4318     }
4319   int ret=*std::max_element(ret1.begin(),ret1.end());
4320   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4321   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4322   return ret;
4323 }
4324
4325 /*!
4326  * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
4327  * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
4328  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4329  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4330  */
4331 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4332 {
4333   int mid=getMeshIdFromMeshName(mName);
4334   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4335 }
4336
4337 /*!
4338  * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
4339  * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
4340  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4341  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4342  */
4343 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4344 {
4345   int mid=getMeshIdFromMeshName(mName);
4346   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4347 }
4348
4349 /*!
4350  * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
4351  */
4352 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4353 {
4354   if(_field_per_mesh.empty())
4355     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4356   if(mName.empty())
4357     return 0;
4358   std::string mName2(mName);
4359   int ret=0;
4360   std::vector<std::string> msg;
4361   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4362     if(mName2==(*it)->getMeshName())
4363       return ret;
4364     else
4365       msg.push_back((*it)->getMeshName());
4366   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4367   oss << "Possible meshes are : ";
4368   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4369     oss << "\"" << (*it2) << "\" ";
4370   throw INTERP_KERNEL::Exception(oss.str());
4371 }
4372
4373 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4374 {
4375   if(!mesh)
4376     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4377   std::string tmp(mesh->getName());
4378   if(tmp.empty())
4379     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4380   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4381   int i=0;
4382   for(;it!=_field_per_mesh.end();it++,i++)
4383     {
4384       if((*it)->getMeshName()==tmp)
4385         return i;
4386     }
4387   int sz=_field_per_mesh.size();
4388   _field_per_mesh.resize(sz+1);
4389   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4390   return sz;
4391 }
4392
4393 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4394                                                                    MEDFileFieldGlobsReal& glob)
4395 {
4396   bool ret=false;
4397   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4398     {
4399       MEDFileFieldPerMesh *fpm(*it);
4400       if(fpm)
4401         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4402     }
4403   return ret;
4404 }
4405
4406 /*!
4407  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4408  * splitting that leads to single spatial discretization of this.
4409  *
4410  * \sa splitMultiDiscrPerGeoTypes
4411  */
4412 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4413 {
4414   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4415   std::vector< std::vector<TypeOfField> > typesF;
4416   std::vector< std::vector<std::string> > pfls,locs;
4417   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4418   std::set<TypeOfField> allEnt;
4419   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4420     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4421       allEnt.insert(*it2);
4422   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4423   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4424   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4425     {
4426       std::vector< std::pair<int,int> > its;
4427       ret[i]=shallowCpy();
4428       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4429       ret[i]->updateData(newLgth,its);
4430     }
4431   return ret;
4432 }
4433
4434 /*!
4435  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4436  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4437  *
4438  * \sa splitDiscretizations
4439  */
4440 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4441 {
4442   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4443   std::vector< std::vector<TypeOfField> > typesF;
4444   std::vector< std::vector<std::string> > pfls,locs;
4445   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4446   std::set<TypeOfField> allEnt;
4447   std::size_t nbOfMDPGT(0),ii(0);
4448   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4449     {
4450       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4451       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4452         allEnt.insert(*it2);
4453     }
4454   if(allEnt.size()!=1)
4455     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4456   if(nbOfMDPGT==0)
4457     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4458   if(nbOfMDPGT==1)
4459     {
4460       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4461       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4462       return ret0;
4463     }
4464   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4465   for(std::size_t i=0;i<nbOfMDPGT;i++)
4466     {
4467       std::vector< std::pair<int,int> > its;
4468       ret[i]=shallowCpy();
4469       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4470       ret[i]->updateData(newLgth,its);
4471     }
4472   return ret;
4473 }
4474
4475 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4476 {
4477   int globalCounter(0);
4478   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4479     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4480   return globalCounter;
4481 }
4482
4483 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4484 {
4485   int globalCounter(0);
4486   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4487     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4488   return globalCounter;
4489 }
4490
4491 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4492 {
4493   if(_nb_of_tuples_to_be_allocated>=0)
4494     {
4495       _nb_of_tuples_to_be_allocated=newLgth;
4496       const DataArray *oldArr(getUndergroundDataArray());
4497       if(oldArr)
4498         {
4499           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4500           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4501           setArray(newArr);
4502           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4503         }
4504       return ;
4505     }
4506   if(_nb_of_tuples_to_be_allocated==-1)
4507     return ;
4508   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4509     {
4510       const DataArray *oldArr(getUndergroundDataArray());
4511       if(!oldArr || !oldArr->isAllocated())
4512         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4513       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4514       newArr->alloc(newLgth,getNumberOfComponents());
4515       if(oldArr)
4516         newArr->copyStringInfoFrom(*oldArr);
4517       int pos=0;
4518       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4519         {
4520           if((*it).second<(*it).first)
4521             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4522           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4523           pos+=(*it).second-(*it).first;
4524         }
4525       setArray(newArr);
4526       return ;
4527     }
4528   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4529 }
4530
4531 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4532 {
4533   if(_field_per_mesh.empty())
4534     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4535   if(_field_per_mesh.size()>1)
4536     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4537   _field_per_mesh[0]->copyOptionsFrom(opts);
4538   _field_per_mesh[0]->writeLL(fid,nasc);
4539 }
4540
4541 /*!
4542  * This methods returns true is the allocation has been needed leading to a modification of state in \a this->_nb_of_tuples_to_be_allocated.
4543  * If false is returned the memory allocation is not required.
4544  */
4545 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4546 {
4547   if(_nb_of_tuples_to_be_allocated>=0)
4548     {
4549       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4550       _nb_of_tuples_to_be_allocated=-2;
4551       return true;
4552     }
4553   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4554     return false;
4555   if(_nb_of_tuples_to_be_allocated==-1)
4556     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4557   if(_nb_of_tuples_to_be_allocated<-3)
4558     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4559   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4560 }
4561
4562 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4563 {
4564   med_int numdt,numit;
4565   med_float dt;
4566   med_int nmesh;
4567   med_bool localMesh;
4568   med_int meshnumdt,meshnumit;
4569   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4570   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4571   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4572   if(_iteration!=numdt || _order!=numit)
4573     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4574   _field_per_mesh.resize(nmesh);
4575   //
4576   MEDFileMesh *mm(0);
4577   if(ms)
4578     {
4579       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4580       mm=ms->getMeshWithName(meshNameCpp);
4581     }
4582   //
4583   for(int i=0;i<nmesh;i++)
4584     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4585   _nb_of_tuples_to_be_allocated=0;
4586   for(int i=0;i<nmesh;i++)
4587     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4588 }
4589
4590 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4591 {
4592   allocIfNecessaryTheArrayToReceiveDataFromFile();
4593   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4594     (*it)->loadBigArraysRecursively(fid,nasc);
4595 }
4596
4597 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4598 {
4599   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4600     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4601       (*it)->loadBigArraysRecursively(fid,nasc);
4602 }
4603
4604 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4605 {
4606   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4607   loadBigArraysRecursively(fid,nasc);
4608 }
4609
4610 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4611 {
4612   DataArray *thisArr(getUndergroundDataArray());
4613   if(thisArr && thisArr->isAllocated())
4614     {
4615       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4616       thisArr->desallocate();
4617     }
4618 }
4619
4620 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4621 {
4622   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4623 }
4624
4625 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4626 {
4627   std::vector<const BigMemoryObject *> ret;
4628   if(getUndergroundDataArray())
4629     ret.push_back(getUndergroundDataArray());
4630   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4631     ret.push_back((const MEDFileFieldPerMesh *)*it);
4632   return ret;
4633 }
4634
4635 /*!
4636  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4637  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4638  * "Sort By Type"), if not, an exception is thrown. 
4639  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4640  *  \param [in] arr - the array of values.
4641  *  \param [in,out] glob - the global data where profiles and localization present in
4642  *          \a field, if any, are added.
4643  *  \throw If the name of \a field is empty.
4644  *  \throw If the data array of \a field is not set.
4645  *  \throw If \a this->_arr is already allocated but has different number of components
4646  *         than \a field.
4647  *  \throw If the underlying mesh of \a field has no name.
4648  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4649  */
4650 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4651 {
4652   const MEDCouplingMesh *mesh=field->getMesh();
4653   //
4654   TypeOfField type=field->getTypeOfField();
4655   std::vector<DataArrayInt *> dummy;
4656   int start=copyTinyInfoFrom(field,arr);
4657   int pos=addNewEntryIfNecessary(mesh);
4658   if(type!=ON_NODES)
4659     {
4660       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4661       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4662     }
4663   else
4664     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4665 }
4666
4667 /*!
4668  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4669  * of a given mesh are used as the support of the given field (a real support is not used). 
4670  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4671  * Order of underlying mesh entities of the given field specified by \a profile parameter
4672  * is not prescribed; this method permutes field values to have them sorted by element
4673  * type as required for writing to MED file. A new profile is added only if no equal
4674  * profile is missing. 
4675  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4676  *  \param [in] arrOfVals - the values of the field \a field used.
4677  *  \param [in] mesh - the supporting mesh of \a field.
4678  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4679  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4680  *  \param [in,out] glob - the global data where profiles and localization present in
4681  *          \a field, if any, are added.
4682  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4683  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4684  *  \throw If the data array of \a field is not set.
4685  *  \throw If \a this->_arr is already allocated but has different number of components
4686  *         than \a field.
4687  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4688  *  \sa setFieldNoProfileSBT()
4689  */
4690 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4691 {
4692   if(!field)
4693     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4694   if(!arrOfVals || !arrOfVals->isAllocated())
4695     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4696   TypeOfField type=field->getTypeOfField();
4697   std::vector<DataArrayInt *> idsInPflPerType;
4698   std::vector<DataArrayInt *> idsPerType;
4699   std::vector<int> code,code2;
4700   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4701   if(type!=ON_NODES)
4702     {
4703       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4704       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4705       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4706       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4707       // start of check
4708       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4709       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4710       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4711         {
4712           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4713           throw INTERP_KERNEL::Exception(oss.str());
4714         }
4715       // end of check
4716       int start=copyTinyInfoFrom(field,arrOfVals);
4717       code2=m->getDistributionOfTypes();
4718       //
4719       int pos=addNewEntryIfNecessary(m);
4720       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4721     }
4722   else
4723     {
4724       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4725         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4726       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4727       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4728       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4729       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4730         {
4731           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4732           throw INTERP_KERNEL::Exception(oss.str());
4733         }
4734       int start=copyTinyInfoFrom(field,arrOfVals);
4735       int pos=addNewEntryIfNecessary(m);
4736       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4737     }
4738 }
4739
4740 /*!
4741  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4742  */
4743 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4744 {
4745   if(_nb_of_tuples_to_be_allocated>=0)
4746     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile : the object is expected to be appended to a data coming from a file but not loaded ! Load before appending data !");
4747   DataArray *arr(getOrCreateAndGetArray());
4748   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4749   _nb_of_tuples_to_be_allocated=-3;
4750 }
4751
4752 /*!
4753  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4754  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4755  * larger by the size of \a field. Returns an id of the first not filled
4756  * tuple of \a this->_arr.
4757  *  \param [in] field - the field to copy the info on components and the name from.
4758  *  \return int - the id of first not initialized tuple of \a this->_arr.
4759  *  \throw If the name of \a field is empty.
4760  *  \throw If the data array of \a field is not set.
4761  *  \throw If \a this->_arr is already allocated but has different number of components
4762  *         than \a field.
4763  */
4764 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4765 {
4766   if(!field)
4767     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4768   std::string name(field->getName());
4769   setName(name.c_str());
4770   setDtUnit(field->getTimeUnit());
4771   if(name.empty())
4772     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4773   if(!arr)
4774     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4775   if(!arr->isAllocated())
4776     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4777   _dt=field->getTime(_iteration,_order);
4778   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4779   if(!getOrCreateAndGetArray()->isAllocated())
4780     {
4781       allocNotFromFile(arr->getNumberOfTuples());
4782       return 0;
4783     }
4784   else
4785     {
4786       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4787       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4788       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4789       _nb_of_tuples_to_be_allocated=-3;
4790       return oldNbOfTuples;
4791     }
4792 }
4793
4794 /*!
4795  * Returns number of components in \a this field
4796  *  \return int - the number of components.
4797  */
4798 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4799 {
4800   return getOrCreateAndGetArray()->getNumberOfComponents();
4801 }
4802
4803 /*!
4804  * Change info on components in \a this.
4805  * \throw If size of \a infos is not equal to the number of components already in \a this.
4806  */
4807 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4808 {
4809   DataArray *arr=getOrCreateAndGetArray();
4810   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4811 }
4812
4813 /*!
4814  * Returns info on components of \a this field.
4815  *  \return const std::vector<std::string>& - a sequence of strings each being an
4816  *          information on _i_-th component.
4817  */
4818 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4819 {
4820   const DataArray *arr=getOrCreateAndGetArray();
4821   return arr->getInfoOnComponents();
4822 }
4823
4824 /*!
4825  * Returns a mutable info on components of \a this field.
4826  *  \return std::vector<std::string>& - a sequence of strings each being an
4827  *          information on _i_-th component.
4828  */
4829 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4830 {
4831   DataArray *arr=getOrCreateAndGetArray();
4832   return arr->getInfoOnComponents();
4833 }
4834
4835 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4836 {
4837   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4838     {
4839       const MEDFileFieldPerMesh *fpm(*it);
4840       if(!fpm)
4841         continue;
4842       if(fpm->presenceOfMultiDiscPerGeoType())
4843         return true;
4844     }
4845   return false;
4846 }
4847
4848 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4849 {
4850   static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to be extracted with  \"field\" method ! Call getFieldOnMeshAtLevel method instead to deal with complexity !";
4851   if(_field_per_mesh.empty())
4852     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
4853   if(_field_per_mesh.size()>1)
4854     throw INTERP_KERNEL::Exception(MSG0);
4855   if(_field_per_mesh[0].isNull())
4856     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
4857   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
4858   std::set<TypeOfField> types;
4859   pm->fillTypesOfFieldAvailable(types);
4860   if(types.size()!=1)
4861     throw INTERP_KERNEL::Exception(MSG0);
4862   TypeOfField type(*types.begin());
4863   int meshDimRelToMax(0);
4864   if(type==ON_NODES)
4865     meshDimRelToMax=0;
4866   else
4867     {
4868       int myDim(std::numeric_limits<int>::max());
4869       bool isUnique(pm->isUniqueLevel(myDim));
4870       if(!isUnique)
4871         throw INTERP_KERNEL::Exception(MSG0);
4872       meshDimRelToMax=myDim-mesh->getMeshDimension();
4873       if(meshDimRelToMax>0)
4874         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
4875     }
4876   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
4877 }
4878
4879 /*!
4880  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4881  *  \param [in] type - a spatial discretization of the new field.
4882  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4883  *  \param [in] mName - a name of the supporting mesh.
4884  *  \param [in] renumPol - specifies how to permute values of the result field according to
4885  *          the optional numbers of cells and nodes, if any. The valid values are
4886  *          - 0 - do not permute.
4887  *          - 1 - permute cells.
4888  *          - 2 - permute nodes.
4889  *          - 3 - permute cells and nodes.
4890  *
4891  *  \param [in] glob - the global data storing profiles and localization.
4892  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4893  *          caller is to delete this field using decrRef() as it is no more needed. 
4894  *  \throw If the MED file is not readable.
4895  *  \throw If there is no mesh named \a mName in the MED file.
4896  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4897  *  \throw If no field of \a this is lying on the mesh \a mName.
4898  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4899  */
4900 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4901 {
4902   MCAuto<MEDFileMesh> mm;
4903   if(mName.empty())
4904     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4905   else
4906     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4907   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4908 }
4909
4910 /*!
4911  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4912  *  \param [in] type - a spatial discretization of the new field.
4913  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4914  *  \param [in] renumPol - specifies how to permute values of the result field according to
4915  *          the optional numbers of cells and nodes, if any. The valid values are
4916  *          - 0 - do not permute.
4917  *          - 1 - permute cells.
4918  *          - 2 - permute nodes.
4919  *          - 3 - permute cells and nodes.
4920  *
4921  *  \param [in] glob - the global data storing profiles and localization.
4922  *  \param [in] mesh - the supporting mesh.
4923  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4924  *          caller is to delete this field using decrRef() as it is no more needed. 
4925  *  \throw If the MED file is not readable.
4926  *  \throw If no field of \a this is lying on \a mesh.
4927  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4928  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4929  */
4930 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4931 {
4932   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
4933   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
4934   if(meshDimRelToMax==1)
4935     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4936   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4937 }
4938
4939 /*!
4940  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4941  * given mesh. 
4942  *  \param [in] type - a spatial discretization of the new field.
4943  *  \param [in] mName - a name of the supporting mesh.
4944  *  \param [in] renumPol - specifies how to permute values of the result field according to
4945  *          the optional numbers of cells and nodes, if any. The valid values are
4946  *          - 0 - do not permute.
4947  *          - 1 - permute cells.
4948  *          - 2 - permute nodes.
4949  *          - 3 - permute cells and nodes.
4950  *
4951  *  \param [in] glob - the global data storing profiles and localization.
4952  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4953  *          caller is to delete this field using decrRef() as it is no more needed. 
4954  *  \throw If the MED file is not readable.
4955  *  \throw If there is no mesh named \a mName in the MED file.
4956  *  \throw If there are no mesh entities in the mesh.
4957  *  \throw If no field values of the given \a type are available.
4958  */
4959 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4960 {
4961   MCAuto<MEDFileMesh> mm;
4962   if(mName.empty())
4963     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4964   else
4965     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4966   int absDim=getDimension();
4967   int meshDimRelToMax=absDim-mm->getMeshDimension();
4968   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4969 }
4970
4971 /*!
4972  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4973  *  \param [in] type - a spatial discretization of the new field.
4974  *  \param [in] renumPol - specifies how to permute values of the result field according to
4975  *          the optional numbers of cells and nodes, if any. The valid values are
4976  *          - 0 - do not permute.
4977  *          - 1 - permute cells.
4978  *          - 2 - permute nodes.
4979  *          - 3 - permute cells and nodes.
4980  *
4981  *  \param [in] glob - the global data storing profiles and localization.
4982  *  \param [in] mesh - the supporting mesh.
4983  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4984  *         field according to \a renumPol.
4985  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4986  *         field according to \a renumPol.
4987  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4988  *          caller is to delete this field using decrRef() as it is no more needed. 
4989  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4990  *  \throw If no field of \a this is lying on \a mesh.
4991  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4992  */
4993 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4994 {
4995   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4996   int meshId=getMeshIdFromMeshName(mesh->getName());
4997   bool isPfl=false;
4998   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4999   switch(renumPol)
5000   {
5001     case 0:
5002       {
5003         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5004         return ret.retn();
5005       }
5006     case 3:
5007     case 1:
5008       {
5009         if(isPfl)
5010           throw INTERP_KERNEL::Exception(msg1);
5011         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5012         if(cellRenum)
5013           {
5014             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5015               {
5016                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5017                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5018                 throw INTERP_KERNEL::Exception(oss.str());
5019               }
5020             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5021             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5022             std::vector<DataArray *> arrOut2(1,arrOut);
5023             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5024             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5025             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5026           }
5027         if(renumPol==1)
5028           return ret.retn();
5029       }
5030     case 2:
5031       {
5032         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5033         if(isPfl)
5034           throw INTERP_KERNEL::Exception(msg1);
5035         if(nodeRenum)
5036           {
5037             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5038               {
5039                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5040                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5041                 throw INTERP_KERNEL::Exception(oss.str());
5042               }
5043             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5044             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5045               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5046             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5047           }
5048         return ret.retn();
5049       }
5050     default:
5051       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5052   }
5053 }
5054
5055 /*!
5056  * Returns values and a profile of the field of a given type lying on a given support.
5057  *  \param [in] type - a spatial discretization of the field.
5058  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5059  *  \param [in] mesh - the supporting mesh.
5060  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5061  *          field of interest lies on. If the field lies on all entities of the given
5062  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5063  *          using decrRef() as it is no more needed.  
5064  *  \param [in] glob - the global data storing profiles and localization.
5065  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5066  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5067  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5068  *  \throw If no field of \a this is lying on \a mesh.
5069  *  \throw If no field values of the given \a type are available.
5070  */
5071 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5072 {
5073   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5074   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
5075   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5076   ret->setName(nasc.getName().c_str());
5077   return ret.retn();
5078 }
5079
5080 //= MEDFileField1TSWithoutSDA
5081
5082 /*!
5083  * Throws if a given value is not a valid (non-extended) relative dimension.
5084  *  \param [in] meshDimRelToMax - the relative dimension value.
5085  *  \throw If \a meshDimRelToMax > 0.
5086  */
5087 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5088 {
5089   if(meshDimRelToMax>0)
5090     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5091 }
5092
5093 /*!
5094  * Checks if elements of a given mesh are in the order suitable for writing 
5095  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5096  * vector describing types of elements and their number.
5097  *  \param [in] mesh - the mesh to check.
5098  *  \return std::vector<int> - a vector holding for each element type (1) item of
5099  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5100  *          These values are in full-interlace mode.
5101  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5102  */
5103 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5104 {
5105   if(!mesh)
5106     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5107   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5108   int nbOfTypes=geoTypes.size();
5109   std::vector<int> code(3*nbOfTypes);
5110   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5111   arr1->alloc(nbOfTypes,1);
5112   int *arrPtr=arr1->getPointer();
5113   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5114   for(int i=0;i<nbOfTypes;i++,it++)
5115     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5116   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5117   const int *arrPtr2=arr2->getConstPointer();
5118   int i=0;
5119   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5120     {
5121       int pos=arrPtr2[i];
5122       int nbCells=mesh->getNumberOfCellsWithType(*it);
5123       code[3*pos]=(int)(*it);
5124       code[3*pos+1]=nbCells;
5125       code[3*pos+2]=-1;//no profiles
5126     }
5127   std::vector<const DataArrayInt *> idsPerType;//no profiles
5128   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5129   if(da)
5130     {
5131       da->decrRef();
5132       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5133     }
5134   return code;
5135 }
5136
5137 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5138 {
5139   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5140 }
5141
5142 /*!
5143  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5144  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5145  * item of every of returned sequences refers to the _i_-th part of \a this field.
5146  * Thus all sequences returned by this method are of the same length equal to number
5147  * of different types of supporting entities.<br>
5148  * A field part can include sub-parts with several different spatial discretizations,
5149  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5150  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5151  * of a nested sequence corresponds to a type of spatial discretization.<br>
5152  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5153  * The overhead is due to selecting values into new instances of DataArrayDouble.
5154  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5155  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5156  *          not checked if \a mname == \c NULL).
5157  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5158  *          a field part is returned. 
5159  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5160  *          A field part can include sub-parts with several different spatial discretizations,
5161  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5162  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5163  *          This sequence is of the same length as \a types. 
5164  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5165  *          discretization. A profile name can be empty.
5166  *          Length of this and of nested sequences is the same as that of \a typesF.
5167  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5168  *          discretization. A localization name can be empty.
5169  *          Length of this and of nested sequences is the same as that of \a typesF.
5170  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5171  *          per each type of spatial discretization within one mesh entity type.
5172  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5173  *          Length of this and of nested sequences is the same as that of \a typesF.
5174  *  \throw If no field is lying on \a mname.
5175  */
5176 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TSWithoutSDA::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
5177 {
5178   int meshId=0;
5179   if(!mname.empty())
5180     meshId=getMeshIdFromMeshName(mname);
5181   else
5182     if(_field_per_mesh.empty())
5183       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5184   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5185   int nbOfRet=ret0.size();
5186   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5187   for(int i=0;i<nbOfRet;i++)
5188     {
5189       const std::vector< std::pair<int,int> >& p=ret0[i];
5190       int nbOfRet1=p.size();
5191       ret[i].resize(nbOfRet1);
5192       for(int j=0;j<nbOfRet1;j++)
5193         {
5194           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5195           ret[i][j]=tmp;
5196         }
5197     }
5198   return ret;
5199 }
5200
5201 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5202 {
5203   return TYPE_STR;
5204 }
5205
5206 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5207 {
5208   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5209   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5210   ret->deepCpyLeavesFrom(*this);
5211   const DataArrayDouble *arr(_arr);
5212   if(arr)
5213     {
5214       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5215       ret->setArray(arr2);
5216     }
5217   return ret.retn();
5218 }
5219
5220 /*!
5221  * Returns a pointer to the underground DataArrayDouble instance and a
5222  * sequence describing parameters of a support of each part of \a this field. The
5223  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5224  * direct access to the field values. This method is intended for the field lying on one
5225  * mesh only.
5226  *  \param [in,out] entries - the sequence describing parameters of a support of each
5227  *         part of \a this field. Each item of this sequence consists of two parts. The
5228  *         first part describes a type of mesh entity and an id of discretization of a
5229  *         current field part. The second part describes a range of values [begin,end)
5230  *         within the returned array relating to the current field part.
5231  *  \return DataArrayDouble * - the pointer to the field values array.
5232  *  \throw If the number of underlying meshes is not equal to 1.
5233  *  \throw If no field values are available.
5234  *  \sa getUndergroundDataArray()
5235  */
5236 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5237 {
5238   if(_field_per_mesh.size()!=1)
5239     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5240   if(_field_per_mesh[0]==0)
5241     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5242   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5243   return getUndergroundDataArrayTemplate();
5244 }
5245
5246 /*!
5247  * Returns a pointer to the underground DataArrayDouble instance and a
5248  * sequence describing parameters of a support of each part of \a this field. The
5249  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5250  * direct access to the field values. This method is intended for the field lying on one
5251  * mesh only.
5252  *  \param [in,out] entries - the sequence describing parameters of a support of each
5253  *         part of \a this field. Each item of this sequence consists of two parts. The
5254  *         first part describes a type of mesh entity and an id of discretization of a
5255  *         current field part. The second part describes a range of values [begin,end)
5256  *         within the returned array relating to the current field part.
5257  *  \return DataArrayDouble * - the pointer to the field values array.
5258  *  \throw If the number of underlying meshes is not equal to 1.
5259  *  \throw If no field values are available.
5260  *  \sa getUndergroundDataArray()
5261  */
5262 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5263 {
5264   return getUndergroundDataArrayDoubleExt(entries);
5265 }
5266
5267 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,csit,iteration,order)
5268 {
5269   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5270   arr->setInfoAndChangeNbOfCompo(infos);
5271 }
5272
5273 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5274 {
5275 }
5276
5277 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5278 {
5279   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5280   ret->deepCpyLeavesFrom(*this);
5281   return ret.retn();
5282 }
5283
5284 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5285 {
5286   MCAuto<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5287   if((const DataArrayDouble *)_arr)
5288     ret->_arr=_arr->deepCopy();
5289   return ret.retn();
5290 }
5291
5292 //= MEDFileIntField1TSWithoutSDA
5293
5294 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5295 {
5296   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5297 }
5298
5299 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5300 {
5301 }
5302
5303 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5304                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,csit,iteration,order)
5305 {
5306   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5307   arr->setInfoAndChangeNbOfCompo(infos);
5308 }
5309
5310 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5311 {
5312   return TYPE_STR;
5313 }
5314
5315 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5316 {
5317   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5318   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5319   ret->deepCpyLeavesFrom(*this);
5320   const DataArrayInt *arr(_arr);
5321   if(arr)
5322     {
5323       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5324       ret->setArray(arr2);
5325     }
5326   return ret.retn();
5327 }
5328
5329 /*!
5330  * Returns a pointer to the underground DataArrayInt instance and a
5331  * sequence describing parameters of a support of each part of \a this field. The
5332  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5333  * direct access to the field values. This method is intended for the field lying on one
5334  * mesh only.
5335  *  \param [in,out] entries - the sequence describing parameters of a support of each
5336  *         part of \a this field. Each item of this sequence consists of two parts. The
5337  *         first part describes a type of mesh entity and an id of discretization of a
5338  *         current field part. The second part describes a range of values [begin,end)
5339  *         within the returned array relating to the current field part.
5340  *  \return DataArrayInt * - the pointer to the field values array.
5341  *  \throw If the number of underlying meshes is not equal to 1.
5342  *  \throw If no field values are available.
5343  *  \sa getUndergroundDataArray()
5344  */
5345 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5346 {
5347   return getUndergroundDataArrayIntExt(entries);
5348 }
5349
5350 /*!
5351  * Returns a pointer to the underground DataArrayInt instance and a
5352  * sequence describing parameters of a support of each part of \a this field. The
5353  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5354  * direct access to the field values. This method is intended for the field lying on one
5355  * mesh only.
5356  *  \param [in,out] entries - the sequence describing parameters of a support of each
5357  *         part of \a this field. Each item of this sequence consists of two parts. The
5358  *         first part describes a type of mesh entity and an id of discretization of a
5359  *         current field part. The second part describes a range of values [begin,end)
5360  *         within the returned array relating to the current field part.
5361  *  \return DataArrayInt * - the pointer to the field values array.
5362  *  \throw If the number of underlying meshes is not equal to 1.
5363  *  \throw If no field values are available.
5364  *  \sa getUndergroundDataArray()
5365  */
5366 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5367 {
5368   if(_field_per_mesh.size()!=1)
5369     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5370   if(_field_per_mesh[0]==0)
5371     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5372   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5373   return getUndergroundDataArrayTemplate();
5374 }
5375
5376 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5377 {
5378   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5379   ret->deepCpyLeavesFrom(*this);
5380   return ret.retn();
5381 }
5382
5383 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5384 {
5385   MCAuto<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5386   if((const DataArrayInt *)_arr)
5387     ret->_arr=_arr->deepCopy();
5388   return ret.retn();
5389 }
5390
5391 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5392 {
5393 }
5394
5395 //= MEDFileAnyTypeField1TS
5396
5397 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5398 {
5399   med_field_type typcha;
5400   //
5401   std::vector<std::string> infos;
5402   std::string dtunit,fieldName;
5403   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5404   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5405   switch(typcha)
5406   {
5407     case MED_FLOAT64:
5408       {
5409         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5410         break;
5411       }
5412     case MED_INT32:
5413       {
5414         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5415         break;
5416       }
5417     default:
5418       {
5419         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
5420         throw INTERP_KERNEL::Exception(oss.str());
5421       }
5422   }
5423   ret->setDtUnit(dtunit.c_str());
5424   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5425   //
5426   med_int numdt,numit;
5427   med_float dt;
5428   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5429   ret->setTime(numdt,numit,dt);
5430   ret->_csit=1;
5431   if(loadAll)
5432     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5433   else
5434     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5435   return ret.retn();
5436 }
5437
5438 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5439 try:MEDFileFieldGlobsReal(fileName)
5440 {
5441   MEDFileUtilities::CheckFileForRead(fileName);
5442   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5443   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5444   loadGlobals(fid);
5445 }
5446 catch(INTERP_KERNEL::Exception& e)
5447 {
5448     throw e;
5449 }
5450
5451 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5452 {
5453   med_field_type typcha;
5454   std::vector<std::string> infos;
5455   std::string dtunit;
5456   int iii=-1;
5457   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5458   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5459   switch(typcha)
5460   {
5461     case MED_FLOAT64:
5462       {
5463         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5464         break;
5465       }
5466     case MED_INT32:
5467       {
5468         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5469         break;
5470       }
5471     default:
5472       {
5473         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5474         throw INTERP_KERNEL::Exception(oss.str());
5475       }
5476   }
5477   ret->setDtUnit(dtunit.c_str());
5478   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5479   //
5480   if(nbSteps<1)
5481     {
5482       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5483       throw INTERP_KERNEL::Exception(oss.str());
5484     }
5485   //
5486   med_int numdt,numit;
5487   med_float dt;
5488   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5489   ret->setTime(numdt,numit,dt);
5490   ret->_csit=1;
5491   if(loadAll)
5492     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5493   else
5494     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5495   return ret.retn();
5496 }
5497
5498 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5499 try:MEDFileFieldGlobsReal(fileName)
5500 {
5501   MEDFileUtilities::CheckFileForRead(fileName);
5502   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5503   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5504   loadGlobals(fid);
5505 }
5506 catch(INTERP_KERNEL::Exception& e)
5507 {
5508     throw e;
5509 }
5510
5511 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5512 {
5513   if(!c)
5514     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5515   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5516     {
5517       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New();
5518       ret->setFileName(fileName);
5519       ret->_content=c; c->incrRef();
5520       return ret.retn();
5521     }
5522   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5523     {
5524       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5525       ret->setFileName(fileName);
5526       ret->_content=c; c->incrRef();
5527       return ret.retn();
5528     }
5529   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5530 }
5531
5532 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5533 {
5534   MEDFileUtilities::CheckFileForRead(fileName);
5535   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5536   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5537   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5538   ret->loadGlobals(fid);
5539   return ret.retn();
5540 }
5541
5542 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5543 {
5544   MEDFileUtilities::CheckFileForRead(fileName);
5545   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5546   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5547   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5548   ret->loadGlobals(fid);
5549   return ret.retn();
5550 }
5551
5552 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5553 {
5554   MEDFileUtilities::CheckFileForRead(fileName);
5555   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5556   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5557   MCAuto<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5558   ret->loadGlobals(fid);
5559   return ret.retn();
5560 }
5561
5562 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5563 {
5564   med_field_type typcha;
5565   std::vector<std::string> infos;
5566   std::string dtunit;
5567   int iii=-1;
5568   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5569   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5570   switch(typcha)
5571   {
5572     case MED_FLOAT64:
5573       {
5574         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5575         break;
5576       }
5577     case MED_INT32:
5578       {
5579         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5580         break;
5581       }
5582     default:
5583       {
5584         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName,iteration,order) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5585         throw INTERP_KERNEL::Exception(oss.str());
5586       }
5587   }
5588   ret->setDtUnit(dtunit.c_str());
5589   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5590   //
5591   bool found=false;
5592   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5593   for(int i=0;i<nbOfStep2 && !found;i++)
5594     {
5595       med_int numdt,numit;
5596       med_float dt;
5597       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5598       if(numdt==iteration && numit==order)
5599         {
5600           found=true;
5601           ret->_csit=i+1;
5602         }
5603       else
5604         dtits[i]=std::pair<int,int>(numdt,numit);
5605     }
5606   if(!found)
5607     {
5608       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5609       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5610         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5611       throw INTERP_KERNEL::Exception(oss.str());
5612     }
5613   if(loadAll)
5614     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5615   else
5616     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5617   return ret.retn();
5618 }
5619
5620 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5621 try:MEDFileFieldGlobsReal(fileName)
5622 {
5623   MEDFileUtilities::CheckFileForRead(fileName);
5624   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5625   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5626   loadGlobals(fid);
5627 }
5628 catch(INTERP_KERNEL::Exception& e)
5629 {
5630     throw e;
5631 }
5632
5633 /*!
5634  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5635  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5636  *
5637  * \warning this is a shallow copy constructor
5638  */
5639 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5640 {
5641   if(!shallowCopyOfContent)
5642     {
5643       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5644       otherPtr->incrRef();
5645       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5646     }
5647   else
5648     {
5649       _content=other.shallowCpy();
5650     }
5651 }
5652
5653 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, const std::string& fileName, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5654 {
5655   if(checkFieldId)
5656     {
5657       int nbFields=MEDnField(fid);
5658       if(fieldIdCFormat>=nbFields)
5659         {
5660           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5661           throw INTERP_KERNEL::Exception(oss.str());
5662         }
5663     }
5664   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5665   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5666   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5667   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5668   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5669   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5670   med_bool localMesh;
5671   int nbOfStep;
5672   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5673   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5674   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5675   infos.clear(); infos.resize(ncomp);
5676   for(int j=0;j<ncomp;j++)
5677     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5678   return nbOfStep;
5679 }
5680
5681 /*!
5682  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5683  * 
5684  * \param [out]
5685  * \return in case of success the number of time steps available for the field with name \a fieldName.
5686  */
5687 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fileName, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5688 {
5689   int nbFields=MEDnField(fid);
5690   bool found=false;
5691   std::vector<std::string> fns(nbFields);
5692   int nbOfStep2=-1;
5693   for(int i=0;i<nbFields && !found;i++)
5694     {
5695       std::string tmp;
5696       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5697       fns[i]=tmp;
5698       found=(tmp==fieldName);
5699       if(found)
5700         posCFormat=i;
5701     }
5702   if(!found)
5703     {
5704       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5705       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5706         oss << "\"" << *it << "\" ";
5707       throw INTERP_KERNEL::Exception(oss.str());
5708     }
5709   return nbOfStep2;
5710 }
5711
5712 /*!
5713  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5714  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5715  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5716  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5717  * to keep a valid instance.
5718  * If \b this do not have any leaf that correspond to the request of the input parameter (\b mName, \b typ, \b locId) an INTERP_KERNEL::Exception will be thrown.
5719  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5720  * If \b newPflName already exists and that \b forceRenameOnGlob is false (the default) an INTERP_KERNEL::Exception will be thrown to avoid big confusion. In this case the called should rename before the profile name with name \b newPflName.
5721  *
5722  * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
5723  * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
5724  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5725  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5726  * \param [in] newLocName is the new localization name.
5727  * \param [in] forceRenameOnGlob specifies the behaviour in case of profile \b newPflName already exists. If true, the renaming is done without check. It can lead to major bug.
5728  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5729  */
5730 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5731 {
5732   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5733   std::string oldPflName=disc->getProfile();
5734   std::vector<std::string> vv=getPflsReallyUsedMulti();
5735   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5736   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5737     {
5738       disc->setProfile(newPflName);
5739       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5740       pfl->setName(newPflName);
5741     }
5742   else
5743     {
5744       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5745       throw INTERP_KERNEL::Exception(oss.str());
5746     }
5747 }
5748
5749 /*!
5750  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5751  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5752  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5753  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5754  * to keep a valid instance.
5755  * If \b this do not have any leaf that correspond to the request of the input parameter (\b mName, \b typ, \b locId) an INTERP_KERNEL::Exception will be thrown.
5756  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5757  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5758  * If \b newLocName already exists an INTERP_KERNEL::Exception will be thrown to avoid big confusion. In this case the called should rename before the profile name with name \b newLocName.
5759  *
5760  * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
5761  * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
5762  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5763  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5764  * \param [in] newLocName is the new localization name.
5765  * \param [in] forceRenameOnGlob specifies the behaviour in case of profile \b newLocName already exists. If true, the renaming is done without check. It can lead to major bug.
5766  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5767  */
5768 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5769 {
5770   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5771   std::string oldLocName=disc->getLocalization();
5772   std::vector<std::string> vv=getLocsReallyUsedMulti();
5773   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5774   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5775     {
5776       disc->setLocalization(newLocName);
5777       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5778       loc.setName(newLocName);
5779     }
5780   else
5781     {
5782       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5783       throw INTERP_KERNEL::Exception(oss.str());
5784     }
5785 }
5786
5787 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5788 {
5789   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5790   if(!ret)
5791     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5792   return ret;
5793 }
5794
5795 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5796 {
5797   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5798   if(!ret)
5799     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5800   return ret;
5801 }
5802
5803 /*!
5804  * Writes \a this field into a MED file specified by its name.
5805  *  \param [in] fileName - the MED file name.
5806  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5807  * - 2 - erase; an existing file is removed.
5808  * - 1 - append; same data should not be present in an existing file.
5809  * - 0 - overwrite; same data present in an existing file is overwritten.
5810  *  \throw If the field name is not set.
5811  *  \throw If no field data is set.
5812  *  \throw If \a mode == 1 and the same data is present in an existing file.
5813  */
5814 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5815 {
5816   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5817   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5818   writeLL(fid);
5819 }
5820
5821 /*!
5822  * This method alloc the arrays and load potentially huge arrays contained in this field.
5823  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5824  * This method can be also called to refresh or reinit values from a file.
5825  * 
5826  * \throw If the fileName is not set or points to a non readable MED file.
5827  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5828  */
5829 void MEDFileAnyTypeField1TS::loadArrays()
5830 {
5831   if(getFileName().empty())
5832     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5833   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5834   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5835 }
5836
5837 /*!
5838  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5839  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5840  * this method does not throw if \a this does not come from file read.
5841  * 
5842  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5843  */
5844 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5845 {
5846   if(!getFileName().empty())
5847     {
5848       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5849       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5850     }
5851 }
5852
5853 /*!
5854  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5855  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5856  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5857  * 
5858  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5859  */
5860 void MEDFileAnyTypeField1TS::unloadArrays()
5861 {
5862   contentNotNullBase()->unloadArrays();
5863 }
5864
5865 /*!
5866  * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
5867  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5868  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5869  * 
5870  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5871  */
5872 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5873 {
5874   if(!getFileName().empty())
5875     contentNotNullBase()->unloadArrays();
5876 }
5877
5878 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5879 {
5880   int nbComp=getNumberOfComponents();
5881   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5882   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5883   for(int i=0;i<nbComp;i++)
5884     {
5885       std::string info=getInfo()[i];
5886       std::string c,u;
5887       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5888       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5889       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5890     }
5891   if(getName().empty())
5892     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5893   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
5894   writeGlobals(fid,*this);
5895   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5896 }
5897
5898 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5899 {
5900   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5901 }
5902
5903 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5904 {
5905   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5906   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5907   return ret;
5908 }
5909
5910 /*!
5911  * Returns a string describing \a this field. This string is outputted 
5912  * by \c print Python command.
5913  */
5914 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5915 {
5916   std::ostringstream oss;
5917   contentNotNullBase()->simpleRepr(0,oss,-1);
5918   simpleReprGlobs(oss);
5919   return oss.str();
5920 }
5921
5922 /*!
5923  * This method returns all profiles whose name is non empty used.
5924  * \b WARNING If profile is used several times it will be reported \b only \b once.
5925  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5926  */
5927 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5928 {
5929   return contentNotNullBase()->getPflsReallyUsed2();
5930 }
5931
5932 /*!
5933  * This method returns all localizations whose name is non empty used.
5934  * \b WARNING If localization is used several times it will be reported \b only \b once.
5935  */
5936 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5937 {
5938   return contentNotNullBase()->getLocsReallyUsed2();
5939 }
5940
5941 /*!
5942  * This method returns all profiles whose name is non empty used.
5943  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5944  */
5945 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5946 {
5947   return contentNotNullBase()->getPflsReallyUsedMulti2();
5948 }
5949
5950 /*!
5951  * This method returns all localizations whose name is non empty used.
5952  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5953  */
5954 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5955 {
5956   return contentNotNullBase()->getLocsReallyUsedMulti2();
5957 }
5958
5959 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5960 {
5961   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5962 }
5963
5964 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5965 {
5966   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5967 }
5968
5969 int MEDFileAnyTypeField1TS::getDimension() const
5970 {
5971   return contentNotNullBase()->getDimension();
5972 }
5973
5974 int MEDFileAnyTypeField1TS::getIteration() const
5975 {
5976   return contentNotNullBase()->getIteration();
5977 }
5978
5979 int MEDFileAnyTypeField1TS::getOrder() const
5980 {
5981   return contentNotNullBase()->getOrder();
5982 }
5983
5984 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5985 {
5986   return contentNotNullBase()->getTime(iteration,order);
5987 }
5988
5989 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5990 {
5991   contentNotNullBase()->setTime(iteration,order,val);
5992 }
5993
5994 std::string MEDFileAnyTypeField1TS::getName() const
5995 {
5996   return contentNotNullBase()->getName();
5997 }
5998
5999 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6000 {
6001   contentNotNullBase()->setName(name);
6002 }
6003
6004 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6005 {
6006   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6007 }
6008
6009 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6010 {
6011   return contentNotNullBase()->getDtUnit();
6012 }
6013
6014 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6015 {
6016   contentNotNullBase()->setDtUnit(dtUnit);
6017 }
6018
6019 std::string MEDFileAnyTypeField1TS::getMeshName() const
6020 {
6021   return contentNotNullBase()->getMeshName();
6022 }
6023
6024 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6025 {
6026   contentNotNullBase()->setMeshName(newMeshName);
6027 }
6028
6029 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6030 {
6031   return contentNotNullBase()->changeMeshNames(modifTab);
6032 }
6033
6034 int MEDFileAnyTypeField1TS::getMeshIteration() const
6035 {
6036   return contentNotNullBase()->getMeshIteration();
6037 }
6038
6039 int MEDFileAnyTypeField1TS::getMeshOrder() const
6040 {
6041   return contentNotNullBase()->getMeshOrder();
6042 }
6043
6044 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6045 {
6046   return contentNotNullBase()->getNumberOfComponents();
6047 }
6048
6049 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6050 {
6051   return contentNotNullBase()->isDealingTS(iteration,order);
6052 }
6053
6054 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6055 {
6056   return contentNotNullBase()->getDtIt();
6057 }
6058
6059 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6060 {
6061   contentNotNullBase()->fillIteration(p);
6062 }
6063
6064 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6065 {
6066   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6067 }
6068
6069 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6070 {
6071   contentNotNullBase()->setInfo(infos);
6072 }
6073
6074 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6075 {
6076   return contentNotNullBase()->getInfo();
6077 }
6078 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6079 {
6080   return contentNotNullBase()->getInfo();
6081 }
6082
6083 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6084 {
6085   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6086 }
6087
6088 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6089 {
6090   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6091 }
6092
6093 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6094 {
6095   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6096 }
6097
6098 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6099 {
6100   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6101 }
6102
6103 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6104 {
6105   return contentNotNullBase()->getTypesOfFieldAvailable();
6106 }
6107
6108 std::vector< std::vector<std::pair<int,int> > > MEDFileAnyTypeField1TS::getFieldSplitedByType(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6109                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6110 {
6111   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6112 }
6113
6114 /*!
6115  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6116  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6117  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6118  */
6119 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6120 {
6121   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6122   if(!content)
6123     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6124   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6125   std::size_t sz(contentsSplit.size());
6126   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6127   for(std::size_t i=0;i<sz;i++)
6128     {
6129       ret[i]=shallowCpy();
6130       ret[i]->_content=contentsSplit[i];
6131     }
6132   return ret;
6133 }
6134
6135 /*!
6136  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6137  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6138  */
6139 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6140 {
6141   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6142   if(!content)
6143     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6144   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6145   std::size_t sz(contentsSplit.size());
6146   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6147   for(std::size_t i=0;i<sz;i++)
6148     {
6149       ret[i]=shallowCpy();
6150       ret[i]->_content=contentsSplit[i];
6151     }
6152   return ret;
6153 }
6154
6155 /*!
6156  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6157  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6158  */
6159 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6160 {
6161   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6162   if(!content)
6163     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6164   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6165   std::size_t sz(contentsSplit.size());
6166   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6167   for(std::size_t i=0;i<sz;i++)
6168     {
6169       ret[i]=shallowCpy();
6170       ret[i]->_content=contentsSplit[i];
6171     }
6172   return ret;
6173 }
6174
6175 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6176 {
6177   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6178   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6179     ret->_content=_content->deepCopy();
6180   ret->deepCpyGlobs(*this);
6181   return ret.retn();
6182 }
6183
6184 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6185 {
6186   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6187 }
6188
6189 //= MEDFileField1TS
6190
6191 /*!
6192  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6193  * the first field that has been read from a specified MED file.
6194  *  \param [in] fileName - the name of the MED file to read.
6195  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6196  *          is to delete this field using decrRef() as it is no more needed.
6197  *  \throw If reading the file fails.
6198  */
6199 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6200 {
6201   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
6202   ret->contentNotNull();
6203   return ret.retn();
6204 }
6205
6206 /*!
6207  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6208  * a given field that has been read from a specified MED file.
6209  *  \param [in] fileName - the name of the MED file to read.
6210  *  \param [in] fieldName - the name of the field to read.
6211  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6212  *          is to delete this field using decrRef() as it is no more needed.
6213  *  \throw If reading the file fails.
6214  *  \throw If there is no field named \a fieldName in the file.
6215  */
6216 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6217 {
6218   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
6219   ret->contentNotNull();
6220   return ret.retn();
6221 }
6222
6223 /*!
6224  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6225  * a given field that has been read from a specified MED file.
6226  *  \param [in] fileName - the name of the MED file to read.
6227  *  \param [in] fieldName - the name of the field to read.
6228  *  \param [in] iteration - the iteration number of a required time step.
6229  *  \param [in] order - the iteration order number of required time step.
6230  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6231  *          is to delete this field using decrRef() as it is no more needed.
6232  *  \throw If reading the file fails.
6233  *  \throw If there is no field named \a fieldName in the file.
6234  *  \throw If the required time step is missing from the file.
6235  */
6236 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6237 {
6238   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6239   ret->contentNotNull();
6240   return ret.retn();
6241 }
6242
6243 /*!
6244  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6245  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6246  *
6247  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6248  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6249  * \warning this is a shallow copy constructor
6250  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6251  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6252  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6253  *          is to delete this field using decrRef() as it is no more needed.
6254  */
6255 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6256 {
6257   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6258   ret->contentNotNull();
6259   return ret.retn();
6260 }
6261
6262 /*!
6263  * Returns a new empty instance of MEDFileField1TS.
6264  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6265  *          is to delete this field using decrRef() as it is no more needed.
6266  */
6267 MEDFileField1TS *MEDFileField1TS::New()
6268 {
6269   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6270   ret->contentNotNull();
6271   return ret.retn();
6272 }
6273
6274 /*!
6275  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6276  * following the given input policy.
6277  *
6278  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6279  *                            By default (true) the globals are deeply copied.
6280  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6281  */
6282 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6283 {
6284   MCAuto<MEDFileIntField1TS> ret;
6285   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6286   if(content)
6287     {
6288       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6289       if(!contc)
6290         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6291       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6292       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6293     }
6294   else
6295     ret=MEDFileIntField1TS::New();
6296   if(isDeepCpyGlobs)
6297     ret->deepCpyGlobs(*this);
6298   else
6299     ret->shallowCpyGlobs(*this);
6300   return ret.retn();
6301 }
6302
6303 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6304 {
6305   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6306   if(!pt)
6307     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6308   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6309   if(!ret)
6310     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
6311   return ret;
6312 }
6313
6314 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6315 {
6316   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6317   if(!pt)
6318     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6319   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6320   if(!ret)
6321     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
6322   return ret;
6323 }
6324
6325 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6326 {
6327   if(!f)
6328     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6329   if(arr.isNull())
6330     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6331   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6332   if(!arrOutC)
6333     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6334   f->setArray(arrOutC);
6335 }
6336
6337 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6338 {
6339   if(arr.isNull())
6340     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6341   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6342   if(!arrOutC)
6343     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6344   arrOutC->incrRef();
6345   return arrOutC;
6346 }
6347
6348 /*!
6349  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6350  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6351  *
6352  * \return A new object that the caller is responsible to deallocate.
6353  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6354  */
6355 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6356 {
6357   if(!mm)
6358     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6359   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6360   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6361   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6362     {
6363       if((*it0)!=ON_NODES)
6364         {
6365           std::vector<int> levs;
6366           getNonEmptyLevels(mm->getName(),levs);
6367           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6368             {
6369               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6370               if(it2!=extractDef.end())
6371                 {
6372                   MCAuto<DataArrayInt> t((*it2).second);
6373                   if(t.isNull())
6374                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6375                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6376                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6377                   ret->setFieldNoProfileSBT(fOut);
6378                 }
6379             }
6380         }
6381       else
6382         {
6383           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6384           if(it2==extractDef.end())
6385             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6386           MCAuto<DataArrayInt> t((*it2).second);
6387           if(t.isNull())
6388             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6389           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6390           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6391           DataArrayDouble *arr(f->getArray());
6392           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6393           fOut->setArray(newArr);
6394           ret->setFieldNoProfileSBT(fOut);
6395         }
6396     }
6397   return ret.retn();
6398 }
6399
6400 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6401 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6402 {
6403 }
6404 catch(INTERP_KERNEL::Exception& e)
6405 { throw e; }
6406
6407 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6408 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6409 {
6410 }
6411 catch(INTERP_KERNEL::Exception& e)
6412 { throw e; }
6413
6414 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6415 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6416 {
6417 }
6418 catch(INTERP_KERNEL::Exception& e)
6419 { throw e; }
6420
6421 /*!
6422  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6423  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6424  *
6425  * \warning this is a shallow copy constructor
6426  */
6427 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6428 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6429 {
6430 }
6431 catch(INTERP_KERNEL::Exception& e)
6432 { throw e; }
6433
6434 MEDFileField1TS::MEDFileField1TS()
6435 {
6436   _content=new MEDFileField1TSWithoutSDA;
6437 }
6438
6439 /*!
6440  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
6441  * method should be called (getFieldOnMeshAtLevel for example).
6442  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6443  *
6444  * \param [in] mesh - the mesh the field is lying on
6445  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6446  *          caller is to delete this field using decrRef() as it is no more needed. 
6447  */
6448 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6449 {
6450   MCAuto<DataArray> arrOut;
6451   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6452   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6453   return ret.retn();
6454 }
6455
6456 /*!
6457  * Returns a new MEDCouplingFieldDouble of a given type lying on
6458  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6459  * has not been constructed via file reading, an exception is thrown.
6460  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6461  *  \param [in] type - a spatial discretization of interest.
6462  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6463  *  \param [in] renumPol - specifies how to permute values of the result field according to
6464  *          the optional numbers of cells and nodes, if any. The valid values are
6465  *          - 0 - do not permute.
6466  *          - 1 - permute cells.
6467  *          - 2 - permute nodes.
6468  *          - 3 - permute cells and nodes.
6469  *
6470  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6471  *          caller is to delete this field using decrRef() as it is no more needed. 
6472  *  \throw If \a this field has not been constructed via file reading.
6473  *  \throw If the MED file is not readable.
6474  *  \throw If there is no mesh in the MED file.
6475  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6476  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6477  *  \sa getFieldOnMeshAtLevel()
6478  */
6479 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6480 {
6481   if(getFileName().empty())
6482     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6483   MCAuto<DataArray> arrOut;
6484   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6485   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6486   return ret.retn();
6487 }
6488
6489 /*!
6490  * Returns a new MEDCouplingFieldDouble of a given type lying on
6491  * the top level cells of the first mesh in MED file. If \a this field 
6492  * has not been constructed via file reading, an exception is thrown.
6493  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6494  *  \param [in] type - a spatial discretization of interest.
6495  *  \param [in] renumPol - specifies how to permute values of the result field according to
6496  *          the optional numbers of cells and nodes, if any. The valid values are
6497  *          - 0 - do not permute.
6498  *          - 1 - permute cells.
6499  *          - 2 - permute nodes.
6500  *          - 3 - permute cells and nodes.
6501  *
6502  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6503  *          caller is to delete this field using decrRef() as it is no more needed. 
6504  *  \throw If \a this field has not been constructed via file reading.
6505  *  \throw If the MED file is not readable.
6506  *  \throw If there is no mesh in the MED file.
6507  *  \throw If no field values of the given \a type.
6508  *  \throw If no field values lying on the top level support.
6509  *  \sa getFieldAtLevel()
6510  */
6511 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6512 {
6513   if(getFileName().empty())
6514     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6515   MCAuto<DataArray> arrOut;
6516   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6517   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6518   return ret.retn();
6519 }
6520
6521 /*!
6522  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6523  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6524  *  \param [in] type - a spatial discretization of the new field.
6525  *  \param [in] mesh - the supporting mesh.
6526  *  \param [in] renumPol - specifies how to permute values of the result field according to
6527  *          the optional numbers of cells and nodes, if any. The valid values are
6528  *          - 0 - do not permute.
6529  *          - 1 - permute cells.
6530  *          - 2 - permute nodes.
6531  *          - 3 - permute cells and nodes.
6532  *
6533  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6534  *          caller is to delete this field using decrRef() as it is no more needed. 
6535  *  \throw If no field of \a this is lying on \a mesh.
6536  *  \throw If the mesh is empty.
6537  *  \throw If no field values of the given \a type are available.
6538  *  \sa getFieldAtLevel()
6539  *  \sa getFieldOnMeshAtLevel() 
6540  */
6541 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6542 {
6543   MCAuto<DataArray> arrOut;
6544   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
6545   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6546   return ret.retn();
6547 }
6548
6549 /*!
6550  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6551  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6552  *  \param [in] type - a spatial discretization of interest.
6553  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6554  *  \param [in] mesh - the supporting mesh.
6555  *  \param [in] renumPol - specifies how to permute values of the result field according to
6556  *          the optional numbers of cells and nodes, if any. The valid values are
6557  *          - 0 - do not permute.
6558  *          - 1 - permute cells.
6559  *          - 2 - permute nodes.
6560  *          - 3 - permute cells and nodes.
6561  *
6562  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6563  *          caller is to delete this field using decrRef() as it is no more needed. 
6564  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6565  *  \throw If no field of \a this is lying on \a mesh.
6566  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6567  *  \sa getFieldAtLevel()
6568  *  \sa getFieldOnMeshAtLevel() 
6569  */
6570 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6571 {
6572   MCAuto<DataArray> arrOut;
6573   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
6574   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6575   return ret.retn();
6576 }
6577
6578 /*!
6579  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6580  * This method is called "Old" because in MED3 norm a field has only one meshName
6581  * attached, so this method is for readers of MED2 files. If \a this field 
6582  * has not been constructed via file reading, an exception is thrown.
6583  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6584  *  \param [in] type - a spatial discretization of interest.
6585  *  \param [in] mName - a name of the supporting mesh.
6586  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6587  *  \param [in] renumPol - specifies how to permute values of the result field according to
6588  *          the optional numbers of cells and nodes, if any. The valid values are
6589  *          - 0 - do not permute.
6590  *          - 1 - permute cells.
6591  *          - 2 - permute nodes.
6592  *          - 3 - permute cells and nodes.
6593  *
6594  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6595  *          caller is to delete this field using decrRef() as it is no more needed. 
6596  *  \throw If the MED file is not readable.
6597  *  \throw If there is no mesh named \a mName in the MED file.
6598  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6599  *  \throw If \a this field has not been constructed via file reading.
6600  *  \throw If no field of \a this is lying on the mesh named \a mName.
6601  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6602  *  \sa getFieldAtLevel()
6603  */
6604 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6605 {
6606   if(getFileName().empty())
6607     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6608   MCAuto<DataArray> arrOut;
6609   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
6610   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6611   return ret.retn();
6612 }
6613
6614 /*!
6615  * Returns values and a profile of the field of a given type lying on a given support.
6616  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6617  *  \param [in] type - a spatial discretization of the field.
6618  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6619  *  \param [in] mesh - the supporting mesh.
6620  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6621  *          field of interest lies on. If the field lies on all entities of the given
6622  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6623  *          using decrRef() as it is no more needed.  
6624  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6625  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6626  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6627  *  \throw If no field of \a this is lying on \a mesh.
6628  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6629  */
6630 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6631 {
6632   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6633   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6634 }
6635
6636 /*!
6637  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6638  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6639  * "Sort By Type"), if not, an exception is thrown. 
6640  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6641  *  \param [in] field - the field to add to \a this.
6642  *  \throw If the name of \a field is empty.
6643  *  \throw If the data array of \a field is not set.
6644  *  \throw If the data array is already allocated but has different number of components
6645  *         than \a field.
6646  *  \throw If the underlying mesh of \a field has no name.
6647  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6648  */
6649 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6650 {
6651   setFileName("");
6652   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6653 }
6654
6655 /*!
6656  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6657  * can be an aggregation of several MEDCouplingFieldDouble instances.
6658  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6659  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6660  * and \a profile.
6661  *
6662  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6663  * A new profile is added only if no equal profile is missing.
6664  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6665  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6666  *  \param [in] mesh - the supporting mesh of \a field.
6667  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6668  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6669  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6670  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6671  *  \throw If the data array of \a field is not set.
6672  *  \throw If the data array of \a this is already allocated but has different number of
6673  *         components than \a field.
6674  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6675  *  \sa setFieldNoProfileSBT()
6676  */
6677 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6678 {
6679   setFileName("");
6680   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6681 }
6682
6683 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6684 {
6685   return new MEDFileField1TS(*this);
6686 }
6687
6688 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6689 {
6690   return contentNotNull()->getUndergroundDataArrayTemplate();
6691 }
6692
6693 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6694 {
6695   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6696 }
6697
6698 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6699                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6700 {
6701   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6702 }
6703
6704 //= MEDFileIntField1TS
6705
6706 MEDFileIntField1TS *MEDFileIntField1TS::New()
6707 {
6708   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6709   ret->contentNotNull();
6710   return ret.retn();
6711 }
6712
6713 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6714 {
6715   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6716   ret->contentNotNull();
6717   return ret.retn();
6718 }
6719
6720 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6721 {
6722   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6723   ret->contentNotNull();
6724   return ret.retn();
6725 }
6726
6727 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6728 {
6729   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6730   ret->contentNotNull();
6731   return ret.retn();
6732 }
6733
6734 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6735 {
6736   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6737   ret->contentNotNull();
6738   return ret.retn();
6739 }
6740
6741 MEDFileIntField1TS::MEDFileIntField1TS()
6742 {
6743   _content=new MEDFileIntField1TSWithoutSDA;
6744 }
6745
6746 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6747 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6748 {
6749 }
6750 catch(INTERP_KERNEL::Exception& e)
6751 { throw e; }
6752
6753 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6754 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6755 {
6756 }
6757 catch(INTERP_KERNEL::Exception& e)
6758 { throw e; }
6759
6760 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6761 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6762 {
6763 }
6764 catch(INTERP_KERNEL::Exception& e)
6765 { throw e; }
6766
6767 /*!
6768  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6769  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6770  *
6771  * \warning this is a shallow copy constructor
6772  */
6773 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6774 {
6775 }
6776
6777 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6778 {
6779   return new MEDFileIntField1TS(*this);
6780 }
6781
6782 /*!
6783  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6784  * following the given input policy.
6785  *
6786  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6787  *                            By default (true) the globals are deeply copied.
6788  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6789  */
6790 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6791 {
6792   MCAuto<MEDFileField1TS> ret;
6793   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6794   if(content)
6795     {
6796       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6797       if(!contc)
6798         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6799       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6800       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6801     }
6802   else
6803     ret=MEDFileField1TS::New();
6804   if(isDeepCpyGlobs)
6805     ret->deepCpyGlobs(*this);
6806   else
6807     ret->shallowCpyGlobs(*this);
6808   return ret.retn();
6809 }
6810
6811 /*!
6812  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
6813  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6814  * "Sort By Type"), if not, an exception is thrown. 
6815  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6816  *  \param [in] field - the field to add to \a this.
6817  *  \throw If the name of \a field is empty.
6818  *  \throw If the data array of \a field is not set.
6819  *  \throw If the data array is already allocated but has different number of components
6820  *         than \a field.
6821  *  \throw If the underlying mesh of \a field has no name.
6822  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6823  */
6824 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
6825 {
6826   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
6827   setFileName("");
6828   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
6829 }
6830
6831 /*!
6832  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6833  * can be an aggregation of several MEDCouplingFieldDouble instances.
6834  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6835  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6836  * and \a profile.
6837  *
6838  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6839  * A new profile is added only if no equal profile is missing.
6840  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6841  *  \param [in] field - the field to add to \a this.
6842  *  \param [in] mesh - the supporting mesh of \a field.
6843  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6844  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6845  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6846  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6847  *  \throw If the data array of \a field is not set.
6848  *  \throw If the data array of \a this is already allocated but has different number of
6849  *         components than \a field.
6850  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6851  *  \sa setFieldNoProfileSBT()
6852  */
6853 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6854 {
6855   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
6856   setFileName("");
6857   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6858 }
6859
6860 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6861 {
6862   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6863   if(!pt)
6864     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6865   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6866   if(!ret)
6867     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !");
6868   return ret;
6869 }
6870
6871 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6872 {
6873   if(getFileName().empty())
6874     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6875   MCAuto<DataArray> arrOut;
6876   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6877   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
6878   return ret2.retn();
6879 }
6880
6881 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
6882 {
6883   if(arr.isNull())
6884     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6885   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
6886   if(!arrC)
6887     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6888   arrC->incrRef();
6889   return arrC;
6890 }
6891
6892 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6893 {
6894   int t1,t2;
6895   double t0(f->getTime(t1,t2));
6896   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
6897   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
6898   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
6899   ret->setTime(t0,t1,t2); ret->setArray(arr2);
6900   return ret.retn();
6901 }
6902
6903 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
6904 {
6905   if(!f)
6906     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
6907   int t1,t2;
6908   double t0(f->getTime(t1,t2));
6909   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
6910   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
6911   ret->setTime(t0,t1,t2);
6912   return ret;
6913 }
6914
6915 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6916 {
6917   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
6918 }
6919
6920 /*!
6921  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
6922  * method should be called (getFieldOnMeshAtLevel for example).
6923  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6924  *
6925  * \param [in] mesh - the mesh the field is lying on
6926  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
6927  *          caller is to delete this field using decrRef() as it is no more needed. 
6928  */
6929 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
6930 {
6931   MCAuto<DataArray> arrOut;
6932   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6933   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
6934   return ret2.retn();
6935 }
6936
6937 /*!
6938  * Returns a new MEDCouplingFieldInt of a given type lying on
6939  * the top level cells of the first mesh in MED file. If \a this field 
6940  * has not been constructed via file reading, an exception is thrown.
6941  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6942  *  \param [in] type - a spatial discretization of interest.
6943  *  \param [in] renumPol - specifies how to permute values of the result field according to
6944  *          the optional numbers of cells and nodes, if any. The valid values are
6945  *          - 0 - do not permute.
6946  *          - 1 - permute cells.
6947  *          - 2 - permute nodes.
6948  *          - 3 - permute cells and nodes.
6949  *
6950  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
6951  *          caller is to delete this field using decrRef() as it is no more needed. 
6952  *  \throw If \a this field has not been constructed via file reading.
6953  *  \throw If the MED file is not readable.
6954  *  \throw If there is no mesh in the MED file.
6955  *  \throw If no field values of the given \a type.
6956  *  \throw If no field values lying on the top level support.
6957  *  \sa getFieldAtLevel()
6958  */
6959 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6960 {
6961   if(getFileName().empty())
6962     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6963   MCAuto<DataArray> arrOut;
6964   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6965   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
6966   return ret2.retn();
6967 }
6968
6969 /*!
6970  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
6971  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6972  *  \param [in] type - a spatial discretization of the new field.
6973  *  \param [in] mesh - the supporting mesh.
6974  *  \param [in] renumPol - specifies how to permute values of the result field according to
6975  *          the optional numbers of cells and nodes, if any. The valid values are
6976  *          - 0 - do not permute.
6977  *          - 1 - permute cells.
6978  *          - 2 - permute nodes.
6979  *          - 3 - permute cells and nodes.
6980  *
6981  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
6982  *          caller is to delete this field using decrRef() as it is no more needed. 
6983  *  \throw If no field of \a this is lying on \a mesh.
6984  *  \throw If the mesh is empty.
6985  *  \throw If no field values of the given \a type are available.
6986  *  \sa getFieldAtLevel()
6987  *  \sa getFieldOnMeshAtLevel() 
6988  */
6989 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6990 {
6991   MCAuto<DataArray> arrOut;
6992   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
6993   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
6994   return ret2.retn();
6995 }
6996
6997 /*!
6998  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
6999  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7000  *  \param [in] type - a spatial discretization of interest.
7001  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7002  *  \param [in] mesh - the supporting mesh.
7003  *  \param [in] renumPol - specifies how to permute values of the result field according to
7004  *          the optional numbers of cells and nodes, if any. The valid values are
7005  *          - 0 - do not permute.
7006  *          - 1 - permute cells.
7007  *          - 2 - permute nodes.
7008  *          - 3 - permute cells and nodes.
7009  *
7010  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7011  *          caller is to delete this field using decrRef() as it is no more needed. 
7012  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7013  *  \throw If no field of \a this is lying on \a mesh.
7014  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7015  *  \sa getFieldAtLevel()
7016  *  \sa getFieldOnMeshAtLevel() 
7017  */
7018 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7019 {
7020   MCAuto<DataArray> arrOut;
7021   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7022   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7023   return ret2.retn();
7024 }
7025
7026 /*!
7027  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7028  * This method is called "Old" because in MED3 norm a field has only one meshName
7029  * attached, so this method is for readers of MED2 files. If \a this field 
7030  * has not been constructed via file reading, an exception is thrown.
7031  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7032  *  \param [in] type - a spatial discretization of interest.
7033  *  \param [in] mName - a name of the supporting mesh.
7034  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7035  *  \param [in] renumPol - specifies how to permute values of the result field according to
7036  *          the optional numbers of cells and nodes, if any. The valid values are
7037  *          - 0 - do not permute.
7038  *          - 1 - permute cells.
7039  *          - 2 - permute nodes.
7040  *          - 3 - permute cells and nodes.
7041  *
7042  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7043  *          caller is to delete this field using decrRef() as it is no more needed. 
7044  *  \throw If the MED file is not readable.
7045  *  \throw If there is no mesh named \a mName in the MED file.
7046  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7047  *  \throw If \a this field has not been constructed via file reading.
7048  *  \throw If no field of \a this is lying on the mesh named \a mName.
7049  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7050  *  \sa getFieldAtLevel()
7051  */
7052 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7053 {
7054   if(getFileName().empty())
7055     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7056   MCAuto<DataArray> arrOut;
7057   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7058   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7059   return ret2.retn();
7060 }
7061
7062 /*!
7063  * Returns values and a profile of the field of a given type lying on a given support.
7064  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7065  *  \param [in] type - a spatial discretization of the field.
7066  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7067  *  \param [in] mesh - the supporting mesh.
7068  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7069  *          field of interest lies on. If the field lies on all entities of the given
7070  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7071  *          using decrRef() as it is no more needed.  
7072  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7073  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7074  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7075  *  \throw If no field of \a this is lying on \a mesh.
7076  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7077  */
7078 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7079 {
7080   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7081   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7082 }
7083
7084 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7085 {
7086   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7087   if(!pt)
7088     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7089   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7090   if(!ret)
7091     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !");
7092   return ret;
7093 }
7094
7095 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7096 {
7097   return contentNotNull()->getUndergroundDataArrayTemplate();
7098 }
7099
7100 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7101
7102 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7103 {
7104 }
7105
7106 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7107 {
7108 }
7109
7110 /*!
7111  * \param [in] fieldId field id in C mode
7112  */
7113 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7114 {
7115   med_field_type typcha;
7116   std::string dtunitOut;
7117   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
7118   setDtUnit(dtunitOut.c_str());
7119   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7120 }
7121
7122 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7123 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7124 {
7125   setDtUnit(dtunit.c_str());
7126   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7127 }
7128 catch(INTERP_KERNEL::Exception& e)
7129 {
7130     throw e;
7131 }
7132
7133 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7134 {
7135   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7136   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7137     ret+=(*it).capacity();
7138   return ret;
7139 }
7140
7141 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7142 {
7143   std::vector<const BigMemoryObject *> ret;
7144   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7145     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7146   return ret;
7147 }
7148
7149 /*!
7150  * If one of the id in [ \a startIds , \a endIds ) points to a null element, there is not throw. Simply, this empty element is added as if it were not
7151  * NULL.
7152  */
7153 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7154 {
7155   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7156   ret->setInfo(_infos);
7157   int sz=(int)_time_steps.size();
7158   for(const int *id=startIds;id!=endIds;id++)
7159     {
7160       if(*id>=0 && *id<sz)
7161         {
7162           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7163           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7164           if(tse)
7165             {
7166               tse->incrRef();
7167               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7168             }
7169           ret->pushBackTimeStep(tse2);
7170         }
7171       else
7172         {
7173           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7174           oss << " ! Should be in [0," << sz << ") !";
7175           throw INTERP_KERNEL::Exception(oss.str());
7176         }
7177     }
7178   if(ret->getNumberOfTS()>0)
7179     ret->synchronizeNameScope();
7180   ret->copyNameScope(*this);
7181   return ret.retn();
7182 }
7183
7184 /*!
7185  * If one of the id in the input range points to a null element, there is not throw. Simply, this empty element is added as if it were not
7186  * NULL.
7187  */
7188 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7189 {
7190   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7191   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7192   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7193   ret->setInfo(_infos);
7194   int sz=(int)_time_steps.size();
7195   int j=bg;
7196   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7197     {
7198       if(j>=0 && j<sz)
7199         {
7200           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7201           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7202           if(tse)
7203             {
7204               tse->incrRef();
7205               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7206             }
7207           ret->pushBackTimeStep(tse2);
7208         }
7209       else
7210         {
7211           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7212           oss << " ! Should be in [0," << sz << ") !";
7213           throw INTERP_KERNEL::Exception(oss.str());
7214         }
7215     }
7216   if(ret->getNumberOfTS()>0)
7217     ret->synchronizeNameScope();
7218   ret->copyNameScope(*this);
7219   return ret.retn();
7220 }
7221
7222 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7223 {
7224   int id=0;
7225   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7226   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7227     {
7228       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7229       if(!cur)
7230         continue;
7231       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7232       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7233         ids->pushBackSilent(id);
7234     }
7235   return buildFromTimeStepIds(ids->begin(),ids->end());
7236 }
7237
7238 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7239 {
7240   int id=0;
7241   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7242   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7243     {
7244       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7245       if(!cur)
7246         continue;
7247       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7248       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7249         ids->pushBackSilent(id);
7250     }
7251   return buildFromTimeStepIds(ids->begin(),ids->end());
7252 }
7253
7254 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7255 {
7256   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7257     {
7258       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7259       if(!cur)
7260         continue;
7261       if(cur->presenceOfMultiDiscPerGeoType())
7262         return true;
7263     }
7264   return false;
7265 }
7266
7267 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7268 {
7269   return _infos;
7270 }
7271
7272 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7273 {
7274   _infos=info;
7275 }
7276
7277 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7278 {
7279   int ret=0;
7280   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7281     {
7282       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7283       if(pt->isDealingTS(iteration,order))
7284         return ret;
7285     }
7286   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7287   std::vector< std::pair<int,int> > vp=getIterations();
7288   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7289     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7290   throw INTERP_KERNEL::Exception(oss.str());
7291 }
7292
7293 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7294 {
7295   return *_time_steps[getTimeStepPos(iteration,order)];
7296 }
7297
7298 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7299 {
7300   return *_time_steps[getTimeStepPos(iteration,order)];
7301 }
7302
7303 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7304 {
7305   if(_time_steps.empty())
7306     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7307   return _time_steps[0]->getMeshName();
7308 }
7309
7310 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7311 {
7312   std::string oldName(getMeshName());
7313   std::vector< std::pair<std::string,std::string> > v(1);
7314   v[0].first=oldName; v[0].second=newMeshName;
7315   changeMeshNames(v);
7316 }
7317
7318 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7319 {
7320   bool ret=false;
7321   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7322     {
7323       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7324       if(cur)
7325         ret=cur->changeMeshNames(modifTab) || ret;
7326     }
7327   return ret;
7328 }
7329
7330 /*!
7331  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7332  */
7333 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7334 {
7335   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7336 }
7337
7338 /*!
7339  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7340  */
7341 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7342 {
7343   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7344 }
7345
7346 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7347                                                                        MEDFileFieldGlobsReal& glob)
7348 {
7349   bool ret=false;
7350   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7351     {
7352       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7353       if(f1ts)
7354         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7355     }
7356   return ret;
7357 }
7358
7359 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7360 {
7361   std::string startLine(bkOffset,' ');
7362   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7363   if(fmtsId>=0)
7364     oss << " (" << fmtsId << ")";
7365   oss << " has the following name: \"" << _name << "\"." << std::endl;
7366   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7367   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7368     {
7369       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7370     }
7371   int i=0;
7372   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7373     {
7374       std::string chapter(17,'0'+i);
7375       oss << startLine << chapter << std::endl;
7376       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7377       if(cur)
7378         cur->simpleRepr(bkOffset+2,oss,i);
7379       else
7380         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7381       oss << startLine << chapter << std::endl;
7382     }
7383 }
7384
7385 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7386 {
7387   std::size_t sz=_time_steps.size();
7388   std::vector< std::pair<int,int> > ret(sz);
7389   ret1.resize(sz);
7390   for(std::size_t i=0;i<sz;i++)
7391     {
7392       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7393       if(f1ts)
7394         {
7395           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7396         }
7397       else
7398         {
7399           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7400           throw INTERP_KERNEL::Exception(oss.str());
7401         }
7402     }
7403   return ret;
7404 }
7405
7406 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7407 {
7408   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7409   if(!tse2)
7410     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7411   checkCoherencyOfType(tse2);
7412   if(_time_steps.empty())
7413     {
7414       setName(tse2->getName().c_str());
7415       setInfo(tse2->getInfo());
7416     }
7417   checkThatComponentsMatch(tse2->getInfo());
7418   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7419     setDtUnit(tse->getDtUnit());
7420   _time_steps.push_back(tse);
7421 }
7422
7423 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7424 {
7425   std::size_t nbOfCompo=_infos.size();
7426   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7427     {
7428       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7429       if(cur)
7430         {
7431           if((cur->getInfo()).size()!=nbOfCompo)
7432             {
7433               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7434               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7435               throw INTERP_KERNEL::Exception(oss.str());
7436             }
7437           cur->copyNameScope(*this);
7438         }
7439     }
7440 }
7441
7442 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7443 {
7444   _time_steps.resize(nbPdt);
7445   for(int i=0;i<nbPdt;i++)
7446     {
7447       std::vector< std::pair<int,int> > ts;
7448       med_int numdt=0,numo=0;
7449       med_int meshIt=0,meshOrder=0;
7450       med_float dt=0.0;
7451       MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder));
7452       switch(fieldTyp)
7453       {
7454         case MED_FLOAT64:
7455           {
7456             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7457             break;
7458           }
7459         case MED_INT32:
7460           {
7461             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7462             break;
7463           }
7464         default:
7465           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7466       }
7467       if(loadAll)
7468         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7469       else
7470         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7471       synchronizeNameScope();
7472     }
7473 }
7474
7475 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7476 {
7477   if(_time_steps.empty())
7478     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7479   checkThatNbOfCompoOfTSMatchThis();
7480   std::vector<std::string> infos(getInfo());
7481   int nbComp=infos.size();
7482   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7483   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7484   for(int i=0;i<nbComp;i++)
7485     {
7486       std::string info=infos[i];
7487       std::string c,u;
7488       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7489       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7490       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7491     }
7492   if(_name.empty())
7493     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7494   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7495   int nbOfTS=_time_steps.size();
7496   for(int i=0;i<nbOfTS;i++)
7497     _time_steps[i]->writeLL(fid,opts,*this);
7498 }
7499
7500 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7501 {
7502   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7503     {
7504       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7505       if(elt)
7506         elt->loadBigArraysRecursively(fid,nasc);
7507     }
7508 }
7509
7510 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7511 {
7512   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7513     {
7514       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7515       if(elt)
7516         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7517     }
7518 }
7519
7520 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7521 {
7522   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7523     {
7524       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7525       if(elt)
7526         elt->unloadArrays();
7527     }
7528 }
7529
7530 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7531 {
7532   return _time_steps.size();
7533 }
7534
7535 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7536 {
7537   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7538   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7539     {
7540       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7541       if(tmp)
7542         newTS.push_back(*it);
7543     }
7544   _time_steps=newTS;
7545 }
7546
7547 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7548 {
7549   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7550   int maxId=(int)_time_steps.size();
7551   int ii=0;
7552   std::set<int> idsToDel;
7553   for(const int *id=startIds;id!=endIds;id++,ii++)
7554     {
7555       if(*id>=0 && *id<maxId)
7556         {
7557           idsToDel.insert(*id);
7558         }
7559       else
7560         {
7561           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7562           throw INTERP_KERNEL::Exception(oss.str());
7563         }
7564     }
7565   for(int iii=0;iii<maxId;iii++)
7566     if(idsToDel.find(iii)==idsToDel.end())
7567       newTS.push_back(_time_steps[iii]);
7568   _time_steps=newTS;
7569 }
7570
7571 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7572 {
7573   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7574   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7575   if(nbOfEntriesToKill==0)
7576     return ;
7577   std::size_t sz=_time_steps.size();
7578   std::vector<bool> b(sz,true);
7579   int j=bg;
7580   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7581     b[j]=false;
7582   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7583   for(std::size_t i=0;i<sz;i++)
7584     if(b[i])
7585       newTS.push_back(_time_steps[i]);
7586   _time_steps=newTS;
7587 }
7588
7589 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7590 {
7591   int ret=0;
7592   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7593   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7594     {
7595       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7596       if(tmp)
7597         {
7598           int it2,ord;
7599           tmp->getTime(it2,ord);
7600           if(it2==iteration && order==ord)
7601             return ret;
7602           else
7603             oss << "(" << it2 << ","  << ord << "), ";
7604         }
7605     }
7606   throw INTERP_KERNEL::Exception(oss.str());
7607 }
7608
7609 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7610 {
7611   int ret=0;
7612   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7613   oss.precision(15);
7614   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7615     {
7616       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7617       if(tmp)
7618         {
7619           int it2,ord;
7620           double ti=tmp->getTime(it2,ord);
7621           if(fabs(time-ti)<eps)
7622             return ret;
7623           else
7624             oss << ti << ", ";
7625         }
7626     }
7627   throw INTERP_KERNEL::Exception(oss.str());
7628 }
7629
7630 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7631 {
7632   int lgth=_time_steps.size();
7633   std::vector< std::pair<int,int> > ret(lgth);
7634   for(int i=0;i<lgth;i++)
7635     _time_steps[i]->fillIteration(ret[i]);
7636   return ret;
7637 }
7638
7639 /*!
7640  * This method has 3 inputs 'iteration' 'order' 'mname'. 'mname' can be null if the user is the general case where there is only one meshName lying on 'this'
7641  * This method returns two things.
7642  * - The absolute dimension of 'this' in first parameter. 
7643  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7644  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7645  *
7646  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7647  * Only these 3 discretizations will be taken into account here.
7648  *
7649  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7650  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7651  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7652  *
7653  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7654  * It is possible (even if it is not common) that the highest level in 'this' were not equal to the meshDimension of the underlying mesh in 'this'.
7655  * 
7656  * Let's consider the typical following case :
7657  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7658  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7659  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7660  *   TETRA4 and SEG2
7661  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7662  *
7663  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7664  * 
7665  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7666  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7667  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7668  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7669  */
7670 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7671 {
7672   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7673 }
7674
7675 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7676 {
7677   if(pos<0 || pos>=(int)_time_steps.size())
7678     {
7679       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7680       throw INTERP_KERNEL::Exception(oss.str());
7681     }
7682   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7683   if(item==0)
7684     {
7685       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7686       oss << "\nTry to use following method eraseEmptyTS !";
7687       throw INTERP_KERNEL::Exception(oss.str());
7688     }
7689   return item;
7690 }
7691
7692 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7693 {
7694   if(pos<0 || pos>=(int)_time_steps.size())
7695     {
7696       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7697       throw INTERP_KERNEL::Exception(oss.str());
7698     }
7699   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7700   if(item==0)
7701     {
7702       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7703       oss << "\nTry to use following method eraseEmptyTS !";
7704       throw INTERP_KERNEL::Exception(oss.str());
7705     }
7706   return item;
7707 }
7708
7709 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7710 {
7711   std::vector<std::string> ret;
7712   std::set<std::string> ret2;
7713   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7714     {
7715       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7716       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7717         if(ret2.find(*it2)==ret2.end())
7718           {
7719             ret.push_back(*it2);
7720             ret2.insert(*it2);
7721           }
7722     }
7723   return ret;
7724 }
7725
7726 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7727 {
7728   std::vector<std::string> ret;
7729   std::set<std::string> ret2;
7730   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7731     {
7732       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7733       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7734         if(ret2.find(*it2)==ret2.end())
7735           {
7736             ret.push_back(*it2);
7737             ret2.insert(*it2);
7738           }
7739     }
7740   return ret;
7741 }
7742
7743 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7744 {
7745   std::vector<std::string> ret;
7746   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7747     {
7748       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7749       ret.insert(ret.end(),tmp.begin(),tmp.end());
7750     }
7751   return ret;
7752 }
7753
7754 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7755 {
7756   std::vector<std::string> ret;
7757   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7758     {
7759       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7760       ret.insert(ret.end(),tmp.begin(),tmp.end());
7761     }
7762   return ret;
7763 }
7764
7765 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7766 {
7767   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7768     (*it)->changePflsRefsNamesGen2(mapOfModif);
7769 }
7770
7771 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7772 {
7773   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7774     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7775 }
7776
7777 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7778 {
7779   int lgth=_time_steps.size();
7780   std::vector< std::vector<TypeOfField> > ret(lgth);
7781   for(int i=0;i<lgth;i++)
7782     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7783   return ret;
7784 }
7785
7786 /*!
7787  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7788  */
7789 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTSWithoutSDA::getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
7790 {
7791   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7792 }
7793
7794 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7795 {
7796   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7797   std::size_t i=0;
7798   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7799     {
7800       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7801         ret->_time_steps[i]=(*it)->deepCopy();
7802     }
7803   return ret.retn();
7804 }
7805
7806 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7807 {
7808   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7809   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7810   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7811   for(std::size_t i=0;i<sz;i++)
7812     {
7813       ret[i]=shallowCpy();
7814       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7815     }
7816   for(std::size_t i=0;i<sz2;i++)
7817     {
7818       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7819       if(ret1.size()!=sz)
7820         {
7821           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7822           throw INTERP_KERNEL::Exception(oss.str());
7823         }
7824       ts[i]=ret1;
7825     }
7826   for(std::size_t i=0;i<sz;i++)
7827     for(std::size_t j=0;j<sz2;j++)
7828       ret[i]->_time_steps[j]=ts[j][i];
7829   return ret;
7830 }
7831
7832 /*!
7833  * This method splits into discretization each time steps in \a this.
7834  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7835  */
7836 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7837 {
7838   std::size_t sz(_time_steps.size());
7839   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7840   for(std::size_t i=0;i<sz;i++)
7841     {
7842       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7843       if(!timeStep)
7844         {
7845           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7846           throw INTERP_KERNEL::Exception(oss.str());
7847         }
7848       items[i]=timeStep->splitDiscretizations();  
7849     }
7850   //
7851   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7852   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7853   std::vector< TypeOfField > types;
7854   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7855     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7856       {
7857         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7858         if(ts.size()!=1)
7859           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7860         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7861         if(it2==types.end())
7862           types.push_back(ts[0]);
7863       }
7864   ret.resize(types.size()); ret2.resize(types.size());
7865   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7866     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7867       {
7868         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7869         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7870         ret2[pos].push_back(*it1);
7871       }
7872   for(std::size_t i=0;i<types.size();i++)
7873     {
7874       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7875       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7876         elt->pushBackTimeStep(*it1);//also updates infos in elt
7877       ret[i]=elt;
7878       elt->MEDFileFieldNameScope::operator=(*this);
7879     }
7880   return ret;
7881 }
7882
7883 /*!
7884  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7885  */
7886 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7887 {
7888   std::size_t sz(_time_steps.size());
7889   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7890   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7891   for(std::size_t i=0;i<sz;i++)
7892     {
7893       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7894       if(!timeStep)
7895         {
7896           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7897           throw INTERP_KERNEL::Exception(oss.str());
7898         }
7899       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7900       if(szOut==std::numeric_limits<std::size_t>::max())
7901         szOut=items[i].size();
7902       else
7903         if(items[i].size()!=szOut)
7904           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7905     }
7906   if(szOut==std::numeric_limits<std::size_t>::max())
7907     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7908   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7909   for(std::size_t i=0;i<szOut;i++)
7910     {
7911       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7912       for(std::size_t j=0;j<sz;j++)
7913         elt->pushBackTimeStep(items[j][i]);
7914       ret[i]=elt;
7915       elt->MEDFileFieldNameScope::operator=(*this);
7916     }
7917   return ret;
7918 }
7919
7920 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7921 {
7922   _name=field->getName();
7923   if(_name.empty())
7924     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7925   if(!arr)
7926     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7927   _infos=arr->getInfoOnComponents();
7928 }
7929
7930 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7931 {
7932   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7933   if(_name!=field->getName())
7934     {
7935       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7936       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7937       throw INTERP_KERNEL::Exception(oss.str());
7938     }
7939   if(!arr)
7940     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7941   checkThatComponentsMatch(arr->getInfoOnComponents());
7942 }
7943
7944 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7945 {
7946   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7947   if(getInfo().size()!=compos.size())
7948     {
7949       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7950       oss << " number of components of element to append (" << compos.size() << ") !";
7951       throw INTERP_KERNEL::Exception(oss.str());
7952     }
7953   if(_infos!=compos)
7954     {
7955       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7956       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7957       oss << " But compo in input fields are : ";
7958       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7959       oss << " !";
7960       throw INTERP_KERNEL::Exception(oss.str());
7961     }
7962 }
7963
7964 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7965 {
7966   std::size_t sz=_infos.size();
7967   int j=0;
7968   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7969     {
7970       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7971       if(elt)
7972         if(elt->getInfo().size()!=sz)
7973           {
7974             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7975             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7976             throw INTERP_KERNEL::Exception(oss.str());
7977           }
7978     }
7979 }
7980
7981 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7982 {
7983   if(!field)
7984     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7985   if(!_time_steps.empty())
7986     checkCoherencyOfTinyInfo(field,arr);
7987   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7988   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7989   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7990   copyTinyInfoFrom(field,arr);
7991   _time_steps.push_back(obj);
7992 }
7993
7994 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7995 {
7996   if(!field)
7997     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7998   if(!_time_steps.empty())
7999     checkCoherencyOfTinyInfo(field,arr);
8000   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8001   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8002   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8003   copyTinyInfoFrom(field,arr);
8004   _time_steps.push_back(obj);
8005 }
8006
8007 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8008 {
8009   int sz=(int)_time_steps.size();
8010   if(i<0 || i>=sz)
8011     {
8012       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8013       throw INTERP_KERNEL::Exception(oss.str());
8014     }
8015   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8016   if(tsPtr)
8017     {
8018       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8019         {
8020           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8021           throw INTERP_KERNEL::Exception(oss.str());
8022         }
8023     }
8024   _time_steps[i]=ts;
8025 }
8026
8027 //= MEDFileFieldMultiTSWithoutSDA
8028
8029 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8030 {
8031   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8032 }
8033
8034 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8035 {
8036 }
8037
8038 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8039 {
8040 }
8041
8042 /*!
8043  * \param [in] fieldId field id in C mode
8044  */
8045 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8046 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8047 {
8048 }
8049 catch(INTERP_KERNEL::Exception& e)
8050 { throw e; }
8051
8052 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8053 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8054 {
8055 }
8056 catch(INTERP_KERNEL::Exception& e)
8057 { throw e; }
8058
8059 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8060 {
8061   return new MEDFileField1TSWithoutSDA;
8062 }
8063
8064 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8065 {
8066   if(!f1ts)
8067     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8068   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8069   if(!f1tsC)
8070     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8071 }
8072
8073 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8074 {
8075   return MEDFileField1TSWithoutSDA::TYPE_STR;
8076 }
8077
8078 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8079 {
8080   return new MEDFileFieldMultiTSWithoutSDA(*this);
8081 }
8082
8083 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8084 {
8085   return new MEDFileFieldMultiTSWithoutSDA;
8086 }
8087
8088 /*!
8089  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8090  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8091  */
8092 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
8093 {
8094   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8095   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8096   if(!myF1TSC)
8097     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8098   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8099 }
8100
8101 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8102 {
8103   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8104   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8105   int i=0;
8106   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8107     {
8108       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8109       if(eltToConv)
8110         {
8111           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8112           if(!eltToConvC)
8113             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8114           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8115           ret->setIteration(i,elt);
8116         }
8117     }
8118   return ret.retn();
8119 }
8120
8121 //= MEDFileAnyTypeFieldMultiTS
8122
8123 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8124 {
8125 }
8126
8127 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8128 try:MEDFileFieldGlobsReal(fileName)
8129 {
8130   MEDFileUtilities::CheckFileForRead(fileName);
8131   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8132   _content=BuildContentFrom(fid,fileName,loadAll,ms);
8133   loadGlobals(fid);
8134 }
8135 catch(INTERP_KERNEL::Exception& e)
8136 {
8137     throw e;
8138 }
8139
8140 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8141 {
8142   med_field_type typcha;
8143   std::vector<std::string> infos;
8144   std::string dtunit;
8145   int i=-1;
8146   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
8147   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8148   switch(typcha)
8149   {
8150     case MED_FLOAT64:
8151       {
8152         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8153         break;
8154       }
8155     case MED_INT32:
8156       {
8157         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8158         break;
8159       }
8160     default:
8161       {
8162         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
8163         throw INTERP_KERNEL::Exception(oss.str());
8164       }
8165   }
8166   ret->setDtUnit(dtunit.c_str());
8167   return ret.retn();
8168 }
8169
8170 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8171 {
8172   med_field_type typcha;
8173   //
8174   std::vector<std::string> infos;
8175   std::string dtunit,fieldName;
8176   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8177   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8178   switch(typcha)
8179   {
8180     case MED_FLOAT64:
8181       {
8182         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8183         break;
8184       }
8185     case MED_INT32:
8186       {
8187         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8188         break;
8189       }
8190     default:
8191       {
8192         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
8193         throw INTERP_KERNEL::Exception(oss.str());
8194       }
8195   }
8196   ret->setDtUnit(dtunit.c_str());
8197   return ret.retn();
8198 }
8199
8200 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8201 {
8202   if(!c)
8203     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8204   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8205     {
8206       MCAuto<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8207       ret->setFileName(fileName);
8208       ret->_content=c;  c->incrRef();
8209       return ret.retn();
8210     }
8211   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8212     {
8213       MCAuto<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8214       ret->setFileName(fileName);
8215       ret->_content=c;  c->incrRef();
8216       return ret.retn();
8217     }
8218   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8219 }
8220
8221 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8222 try:MEDFileFieldGlobsReal(fileName)
8223 {
8224   MEDFileUtilities::CheckFileForRead(fileName);
8225   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8226   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms,entities);
8227   loadGlobals(fid);
8228 }
8229 catch(INTERP_KERNEL::Exception& e)
8230 {
8231     throw e;
8232 }
8233
8234 //= MEDFileIntFieldMultiTSWithoutSDA
8235
8236 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8237 {
8238   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8239 }
8240
8241 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8242 {
8243 }
8244
8245 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8246 {
8247 }
8248
8249 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8250 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8251 {
8252 }
8253 catch(INTERP_KERNEL::Exception& e)
8254 { throw e; }
8255
8256 /*!
8257  * \param [in] fieldId field id in C mode
8258  */
8259 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8260 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8261 {
8262 }
8263 catch(INTERP_KERNEL::Exception& e)
8264 { throw e; }
8265
8266 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8267 {
8268   return new MEDFileIntField1TSWithoutSDA;
8269 }
8270
8271 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8272 {
8273   if(!f1ts)
8274     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8275   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8276   if(!f1tsC)
8277     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8278 }
8279
8280 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8281 {
8282   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8283 }
8284
8285 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8286 {
8287   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8288 }
8289
8290 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8291 {
8292   return new MEDFileIntFieldMultiTSWithoutSDA;
8293 }
8294
8295 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8296 {
8297   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8298   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8299   int i=0;
8300   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8301     {
8302       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8303       if(eltToConv)
8304         {
8305           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8306           if(!eltToConvC)
8307             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8308           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8309           ret->setIteration(i,elt);
8310         }
8311     }
8312   return ret.retn();
8313 }
8314
8315 //= MEDFileAnyTypeFieldMultiTS
8316
8317 /*!
8318  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8319  * that has been read from a specified MED file.
8320  *  \param [in] fileName - the name of the MED file to read.
8321  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8322  *          is to delete this field using decrRef() as it is no more needed.
8323  *  \throw If reading the file fails.
8324  */
8325 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8326 {
8327   MEDFileUtilities::CheckFileForRead(fileName);
8328   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8329   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8330   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8331   ret->loadGlobals(fid);
8332   return ret.retn();
8333 }
8334
8335 /*!
8336  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8337  * that has been read from a specified MED file.
8338  *  \param [in] fileName - the name of the MED file to read.
8339  *  \param [in] fieldName - the name of the field to read.
8340  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8341  *          is to delete this field using decrRef() as it is no more needed.
8342  *  \throw If reading the file fails.
8343  *  \throw If there is no field named \a fieldName in the file.
8344  */
8345 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8346 {
8347   MEDFileUtilities::CheckFileForRead(fileName);
8348   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8349   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fileName,fieldName,loadAll,0,0));
8350   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8351   ret->loadGlobals(fid);
8352   return ret.retn();
8353 }
8354
8355 /*!
8356  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8357  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8358  *
8359  * \warning this is a shallow copy constructor
8360  */
8361 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8362 {
8363   if(!shallowCopyOfContent)
8364     {
8365       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8366       otherPtr->incrRef();
8367       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8368     }
8369   else
8370     {
8371       _content=other.shallowCpy();
8372     }
8373 }
8374
8375 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8376 {
8377   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8378   if(!ret)
8379     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8380   return ret;
8381 }
8382
8383 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8384 {
8385   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8386   if(!ret)
8387     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8388   return ret;
8389 }
8390
8391 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8392 {
8393   return contentNotNullBase()->getPflsReallyUsed2();
8394 }
8395
8396 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8397 {
8398   return contentNotNullBase()->getLocsReallyUsed2();
8399 }
8400
8401 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8402 {
8403   return contentNotNullBase()->getPflsReallyUsedMulti2();
8404 }
8405
8406 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8407 {
8408   return contentNotNullBase()->getLocsReallyUsedMulti2();
8409 }
8410
8411 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8412 {
8413   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8414 }
8415
8416 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8417 {
8418   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8419 }
8420
8421 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8422 {
8423   return contentNotNullBase()->getNumberOfTS();
8424 }
8425
8426 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8427 {
8428   contentNotNullBase()->eraseEmptyTS();
8429 }
8430
8431 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8432 {
8433   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8434 }
8435
8436 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8437 {
8438   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8439 }
8440
8441 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8442 {
8443   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8444   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8445   ret->_content=c;
8446   return ret.retn();
8447 }
8448
8449 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8450 {
8451   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8452   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8453   ret->_content=c;
8454   return ret.retn();
8455 }
8456
8457 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8458 {
8459   return contentNotNullBase()->getIterations();
8460 }
8461
8462 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8463 {
8464   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8465     pushBackTimeStep(*it);
8466 }
8467
8468 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8469 {
8470   if(!fmts)
8471     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8472   int nbOfTS(fmts->getNumberOfTS());
8473   for(int i=0;i<nbOfTS;i++)
8474     {
8475       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8476       pushBackTimeStep(elt);
8477     }
8478 }
8479
8480 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8481 {
8482   if(!f1ts)
8483     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8484   checkCoherencyOfType(f1ts);
8485   f1ts->incrRef();
8486   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8487   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8488   c->incrRef();
8489   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8490   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8491     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8492   _content->pushBackTimeStep(cSafe);
8493   appendGlobs(*f1ts,1e-12);
8494 }
8495
8496 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8497 {
8498   contentNotNullBase()->synchronizeNameScope();
8499 }
8500
8501 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8502 {
8503   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8504 }
8505
8506 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8507 {
8508   return contentNotNullBase()->getPosGivenTime(time,eps);
8509 }
8510
8511 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8512 {
8513   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8514 }
8515
8516 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8517 {
8518   return contentNotNullBase()->getTypesOfFieldAvailable();
8519 }
8520
8521 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeFieldMultiTS::getFieldSplitedByType(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
8522 {
8523   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8524 }
8525
8526 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8527 {
8528   return contentNotNullBase()->getName();
8529 }
8530
8531 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8532 {
8533   contentNotNullBase()->setName(name);
8534 }
8535
8536 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8537 {
8538   return contentNotNullBase()->getDtUnit();
8539 }
8540
8541 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8542 {
8543   contentNotNullBase()->setDtUnit(dtUnit);
8544 }
8545
8546 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8547 {
8548   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8549 }
8550
8551 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8552 {
8553   return contentNotNullBase()->getTimeSteps(ret1);
8554 }
8555
8556 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8557 {
8558   return contentNotNullBase()->getMeshName();
8559 }
8560
8561 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8562 {
8563   contentNotNullBase()->setMeshName(newMeshName);
8564 }
8565
8566 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8567 {
8568   return contentNotNullBase()->changeMeshNames(modifTab);
8569 }
8570
8571 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8572 {
8573   return contentNotNullBase()->getInfo();
8574 }
8575
8576 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8577 {
8578   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8579 }
8580
8581 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8582 {
8583   return contentNotNullBase()->setInfo(info);
8584 }
8585
8586 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8587 {
8588   const std::vector<std::string> ret=getInfo();
8589   return (int)ret.size();
8590 }
8591
8592 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8593 {
8594   writeGlobals(fid,*this);
8595   contentNotNullBase()->writeLL(fid,*this);
8596 }
8597
8598 /*!
8599  * Writes \a this field into a MED file specified by its name.
8600  *  \param [in] fileName - the MED file name.
8601  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8602  * - 2 - erase; an existing file is removed.
8603  * - 1 - append; same data should not be present in an existing file.
8604  * - 0 - overwrite; same data present in an existing file is overwritten.
8605  *  \throw If the field name is not set.
8606  *  \throw If no field data is set.
8607  *  \throw If \a mode == 1 and the same data is present in an existing file.
8608  */
8609 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8610 {
8611   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8612   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8613   writeLL(fid);
8614 }
8615
8616 /*!
8617  * This method alloc the arrays and load potentially huge arrays contained in this field.
8618  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8619  * This method can be also called to refresh or reinit values from a file.
8620  * 
8621  * \throw If the fileName is not set or points to a non readable MED file.
8622  */
8623 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8624 {
8625   if(getFileName().empty())
8626     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8627   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8628   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8629 }
8630
8631 /*!
8632  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8633  * But once data loaded once, this method does nothing.
8634  * 
8635  * \throw If the fileName is not set or points to a non readable MED file.
8636  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8637  */
8638 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8639 {
8640   if(!getFileName().empty())
8641     {
8642       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8643       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8644     }
8645 }
8646
8647 /*!
8648  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8649  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8650  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8651  * 
8652  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8653  */
8654 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8655 {
8656   contentNotNullBase()->unloadArrays();
8657 }
8658
8659 /*!
8660  * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
8661  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8662  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8663  * 
8664  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8665  */
8666 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8667 {
8668   if(!getFileName().empty())
8669     contentNotNullBase()->unloadArrays();
8670 }
8671
8672 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8673 {
8674   std::ostringstream oss;
8675   contentNotNullBase()->simpleRepr(0,oss,-1);
8676   simpleReprGlobs(oss);
8677   return oss.str();
8678 }
8679
8680 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8681 {
8682   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8683 }
8684
8685 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8686 {
8687   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8688   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8689   return ret;
8690 }
8691
8692 /*!
8693  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8694  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8695  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8696  */
8697 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8698 {
8699   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8700   if(!content)
8701     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8702   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8703   std::size_t sz(contentsSplit.size());
8704   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8705   for(std::size_t i=0;i<sz;i++)
8706     {
8707       ret[i]=shallowCpy();
8708       ret[i]->_content=contentsSplit[i];
8709     }
8710   return ret;
8711 }
8712
8713 /*!
8714  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8715  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8716  */
8717 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8718 {
8719   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8720   if(!content)
8721     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8722   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8723   std::size_t sz(contentsSplit.size());
8724   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8725   for(std::size_t i=0;i<sz;i++)
8726     {
8727       ret[i]=shallowCpy();
8728       ret[i]->_content=contentsSplit[i];
8729     }
8730   return ret;
8731 }
8732
8733 /*!
8734  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8735  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8736  */
8737 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8738 {
8739   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8740   if(!content)
8741     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8742   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8743   std::size_t sz(contentsSplit.size());
8744   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8745   for(std::size_t i=0;i<sz;i++)
8746     {
8747       ret[i]=shallowCpy();
8748       ret[i]->_content=contentsSplit[i];
8749     }
8750   return ret;
8751 }
8752
8753 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8754 {
8755   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8756   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8757     ret->_content=_content->deepCopy();
8758   ret->deepCpyGlobs(*this);
8759   return ret.retn();
8760 }
8761
8762 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8763 {
8764   return _content;
8765 }
8766
8767 /*!
8768  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8769  *  \param [in] iteration - the iteration number of a required time step.
8770  *  \param [in] order - the iteration order number of required time step.
8771  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8772  *          delete this field using decrRef() as it is no more needed.
8773  *  \throw If there is no required time step in \a this field.
8774  */
8775 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8776 {
8777   int pos=getPosOfTimeStep(iteration,order);
8778   return getTimeStepAtPos(pos);
8779 }
8780
8781 /*!
8782  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8783  *  \param [in] time - the time of the time step of interest.
8784  *  \param [in] eps - a precision used to compare time values.
8785  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8786  *          delete this field using decrRef() as it is no more needed.
8787  *  \throw If there is no required time step in \a this field.
8788  */
8789 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8790 {
8791   int pos=getPosGivenTime(time,eps);
8792   return getTimeStepAtPos(pos);
8793 }
8794
8795 /*!
8796  * This method groups not null items in \a vectFMTS per time step series. Two time series are considered equal if the list of their pair of integers iteration,order are equal.
8797  * The float64 value of time attached to the pair of integers are not considered here.
8798  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8799  *
8800  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8801  * \throw If there is a null pointer in \a vectFMTS.
8802  */
8803 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8804 {
8805   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8806   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8807   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8808   while(!lstFMTS.empty())
8809     {
8810       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8811       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8812       if(!curIt)
8813         throw INTERP_KERNEL::Exception(msg);
8814       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8815       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8816       elt.push_back(curIt); it=lstFMTS.erase(it);
8817       while(it!=lstFMTS.end())
8818         {
8819           curIt=*it;
8820           if(!curIt)
8821             throw INTERP_KERNEL::Exception(msg);
8822           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8823           if(refIts==curIts)
8824             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8825           else
8826             it++;
8827         }
8828       ret.push_back(elt);
8829     }
8830   return ret;
8831 }
8832
8833 /*!
8834  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8835  * All returned instances in a subvector can be safely loaded, rendered along time
8836  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8837  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8838  * All items in \a vectFMTS must lie on the mesh (located by meshname and time step) and compatible with the input mesh \a mesh (having the same name than those in items).
8839  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8840  * For items in \a vectFMTS that are ON_NODES it is possible to appear several times (more than once or once) in the returned vector.
8841  *
8842  * \param [in] vectFMTS - list of multi times step part all defined each on a same spatial discretization along time and pointing to a mesh whose name is equal to \c mesh->getName().
8843  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8844  * \param [out] fsc - A vector having same size than returned vector. It specifies the support comporator of the corresponding vector of MEDFileAnyTypeFieldMultiTS in returned vector of vector.
8845  * \return - A vector of vector of objects that contains the same pointers (objects) than thoose in \a vectFMTS except that there are organized differently. So pointers included in returned vector of vector should \b not been dealt by the caller.
8846  *
8847  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8848  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8849  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8850  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8851  * \throw If mesh is null.
8852  * \throw If an element in \a vectFMTS is null.
8853  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8854  */
8855 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8856 {
8857   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8858   if(!mesh)
8859     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8860   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8861   if(vectFMTS.empty())
8862     return ret;
8863   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8864   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8865   if(!frstElt)
8866     throw INTERP_KERNEL::Exception(msg);
8867   std::size_t i=0;
8868   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8869   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8870   for(;it!=vectFMTS.end();it++,i++)
8871     {
8872       if(!(*it))
8873         throw INTERP_KERNEL::Exception(msg);
8874       TypeOfField tof0,tof1;
8875       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8876         {
8877           if(tof1!=ON_NODES)
8878             vectFMTSNotNodes.push_back(*it);
8879           else
8880             vectFMTSNodes.push_back(*it);
8881         }
8882       else
8883         vectFMTSNotNodes.push_back(*it);
8884     }
8885   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8886   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8887   ret=retCell;
8888   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8889     {
8890       i=0;
8891       bool isFetched(false);
8892       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8893         {
8894           if((*it0).empty())
8895             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8896           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8897             { ret[i].push_back(*it2); isFetched=true; }
8898         }
8899       if(!isFetched)
8900         {
8901           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8902           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8903           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8904         }
8905     }
8906   fsc=cmps;
8907   return ret;
8908 }
8909
8910 /*!
8911  * WARNING no check here. The caller must be sure that all items in vectFMTS are coherent each other in time steps, only one same spatial discretization and not ON_NODES.
8912  * \param [out] cmps - same size than the returned vector.
8913  */
8914 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8915 {
8916   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8917   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8918   while(!lstFMTS.empty())
8919     {
8920       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8921       MEDFileAnyTypeFieldMultiTS *ref(*it);
8922       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8923       elt.push_back(ref); it=lstFMTS.erase(it);
8924       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8925       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8926       while(it!=lstFMTS.end())
8927         {
8928           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8929           if(cmp->isEqual(curIt))
8930             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8931           else
8932             it++;
8933         }
8934       ret.push_back(elt); cmps.push_back(cmp);
8935     }
8936   return ret;
8937 }
8938
8939 /*!
8940  * This method scan the two main structs along time of \a f0 and \a f1 to see if there are all lying on the same mesh along time than those in \a mesh.
8941  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8942  *
8943  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8944  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8945  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8946  * \thorw If \a f0 and \a f1 do not have the same times steps.
8947  * \throw If mesh is null.
8948  * \throw If \a f0 or \a f1 is null.
8949  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8950  */
8951 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8952 {
8953   if(!mesh)
8954     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8955   if(!f0 || !f1)
8956     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8957   if(f0->getMeshName()!=mesh->getName())
8958     {
8959       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8960       throw INTERP_KERNEL::Exception(oss.str());
8961     }
8962   if(f1->getMeshName()!=mesh->getName())
8963     {
8964       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8965       throw INTERP_KERNEL::Exception(oss.str());
8966     }
8967   int nts=f0->getNumberOfTS();
8968   if(nts!=f1->getNumberOfTS())
8969     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8970   if(nts==0)
8971     return nts;
8972   for(int i=0;i<nts;i++)
8973     {
8974       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8975       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8976       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8977       if(tofs0.size()!=1 || tofs1.size()!=1)
8978         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8979       if(i!=0)
8980         {
8981           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8982             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8983         }
8984       else
8985         { tof0=tofs0[0]; tof1=tofs1[0]; }
8986       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8987         {
8988           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh time step (" << f0cur->getMeshIteration() << ","<< f0cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
8989           throw INTERP_KERNEL::Exception(oss.str());
8990         }
8991       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8992         {
8993           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh time step (" << f1cur->getMeshIteration() << ","<< f1cur->getMeshOrder() << ") whereas input mesh points to time step (" << mesh->getIteration() << "," << mesh->getOrder() << ") !";
8994           throw INTERP_KERNEL::Exception(oss.str());
8995         }
8996       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8997         {
8998           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : all the time steps must be the same ! it is not the case (" << f0cur->getIteration() << "," << f0cur->getOrder() << ")!=(" << f1cur->getIteration() << "," << f1cur->getOrder() << ") !";
8999           throw INTERP_KERNEL::Exception(oss.str());
9000         }
9001     }
9002   return nts;
9003 }
9004
9005 /*!
9006  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9007  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9008  *
9009  * \return A new object that the caller is responsible to deallocate.
9010  */
9011 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9012 {
9013   if(!mm)
9014     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9015   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9016   int nbTS(getNumberOfTS());
9017   for(int i=0;i<nbTS;i++)
9018     {
9019       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9020       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9021       fmtsOut->pushBackTimeStep(f1tsOut);
9022     }
9023   return fmtsOut.retn();
9024 }
9025
9026 template<class T>
9027 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9028 {
9029   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9030   if(f1tss.empty())
9031     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9032   std::size_t sz(f1tss.size()),i(0);
9033   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9034   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9035     {
9036       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9037       if(!elt)
9038         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9039       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9040     }
9041   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9042   if(!retc)
9043     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9044   retc->aggregate(f1tsw,dts);
9045   ret->setDtUnit(f1tss[0]->getDtUnit());
9046   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9047 }
9048
9049 template<class T>
9050 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9051 {
9052   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9053   if(fmtss.empty())
9054     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9055   std::size_t sz(fmtss.size());
9056   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9057     {
9058       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9059       if(!elt)
9060         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9061     }
9062   int nbTS(fmtss[0]->getNumberOfTS());
9063   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9064     if((*it)->getNumberOfTS()!=nbTS)
9065       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9066   for(int iterTS=0;iterTS<nbTS;iterTS++)
9067     {
9068       std::size_t i(0);
9069       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9070       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9071       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9072         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9073       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9074       ret->pushBackTimeStep(f1ts);
9075       ret->setDtUnit(f1ts->getDtUnit());
9076     }
9077   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9078 }
9079
9080 /*!
9081  * \a dts and \a ftmss are expected to have same size.
9082  */
9083 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9084 {
9085   if(fmtss.empty())
9086     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9087   std::size_t sz(fmtss.size());
9088   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9089   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9090   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9091     {
9092       if(!(*it))
9093         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9094       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9095       if(elt1)
9096         {
9097           fmtss1.push_back(elt1);
9098           continue;
9099         }
9100       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9101       if(elt2)
9102         {
9103           fmtss2.push_back(elt2);
9104           continue;
9105         }
9106       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9107     }
9108   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9109     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9110   if(fmtss1.size()==sz)
9111     return AggregateHelperFMTS<double>(fmtss1,dts);
9112   if(fmtss2.size()!=sz)
9113     return AggregateHelperFMTS<int>(fmtss2,dts);
9114   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9115 }
9116
9117 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9118 {
9119   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9120 }
9121
9122 //= MEDFileFieldMultiTS
9123
9124 /*!
9125  * Returns a new empty instance of MEDFileFieldMultiTS.
9126  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9127  *          is to delete this field using decrRef() as it is no more needed.
9128  */
9129 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9130 {
9131   return new MEDFileFieldMultiTS;
9132 }
9133
9134 /*!
9135  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9136  * that has been read from a specified MED file.
9137  *  \param [in] fileName - the name of the MED file to read.
9138  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9139  *          is to delete this field using decrRef() as it is no more needed.
9140  *  \throw If reading the file fails.
9141  */
9142 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9143 {
9144   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
9145   ret->contentNotNull();//to check that content type matches with \a this type.
9146   return ret.retn();
9147 }
9148
9149 /*!
9150  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9151  * that has been read from a specified MED file.
9152  *  \param [in] fileName - the name of the MED file to read.
9153  *  \param [in] fieldName - the name of the field to read.
9154  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9155  *          is to delete this field using decrRef() as it is no more needed.
9156  *  \throw If reading the file fails.
9157  *  \throw If there is no field named \a fieldName in the file.
9158  */
9159 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9160 {
9161   MCAuto<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
9162   ret->contentNotNull();//to check that content type matches with \a this type.
9163   return ret.retn();
9164 }
9165
9166 /*!
9167  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9168  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9169  *
9170  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9171  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9172  * \warning this is a shallow copy constructor
9173  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9174  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9175  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9176  *          is to delete this field using decrRef() as it is no more needed.
9177  */
9178 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9179 {
9180   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9181 }
9182
9183 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9184 {
9185   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0,&entities));
9186   ret->contentNotNull();//to check that content type matches with \a this type.
9187   return ret.retn();
9188 }
9189
9190 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9191 {
9192   return new MEDFileFieldMultiTS(*this);
9193 }
9194
9195 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9196 {
9197   if(!f1ts)
9198     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9199   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9200   if(!f1tsC)
9201     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9202 }
9203
9204 /*!
9205  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9206  * following the given input policy.
9207  *
9208  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9209  *                            By default (true) the globals are deeply copied.
9210  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9211  */
9212 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9213 {
9214   MCAuto<MEDFileIntFieldMultiTS> ret;
9215   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9216   if(content)
9217     {
9218       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9219       if(!contc)
9220         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9221       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9222       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
9223     }
9224   else
9225     ret=MEDFileIntFieldMultiTS::New();
9226   if(isDeepCpyGlobs)
9227     ret->deepCpyGlobs(*this);
9228   else
9229     ret->shallowCpyGlobs(*this);
9230   return ret.retn();
9231 }
9232
9233 /*!
9234  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9235  *  \param [in] pos - a time step id.
9236  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9237  *          delete this field using decrRef() as it is no more needed.
9238  *  \throw If \a pos is not a valid time step id.
9239  */
9240 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9241 {
9242   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9243   if(!item)
9244     {
9245       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9246       throw INTERP_KERNEL::Exception(oss.str());
9247     }
9248   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9249   if(itemC)
9250     {
9251       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9252       ret->shallowCpyGlobs(*this);
9253       return ret.retn();
9254     }
9255   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9256   throw INTERP_KERNEL::Exception(oss.str());
9257 }
9258
9259 /*!
9260  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9261  * mesh entities of a given dimension of the first mesh in MED file.
9262  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9263  *  \param [in] type - a spatial discretization of interest.
9264  *  \param [in] iteration - the iteration number of a required time step.
9265  *  \param [in] order - the iteration order number of required time step.
9266  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9267  *  \param [in] renumPol - specifies how to permute values of the result field according to
9268  *          the optional numbers of cells and nodes, if any. The valid values are
9269  *          - 0 - do not permute.
9270  *          - 1 - permute cells.
9271  *          - 2 - permute nodes.
9272  *          - 3 - permute cells and nodes.
9273  *
9274  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9275  *          caller is to delete this field using decrRef() as it is no more needed. 
9276  *  \throw If the MED file is not readable.
9277  *  \throw If there is no mesh in the MED file.
9278  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9279  *  \throw If no field values of the required parameters are available.
9280  */
9281 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9282 {
9283   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9284   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9285   if(!myF1TSC)
9286     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9287   MCAuto<DataArray> arrOut;
9288   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9289   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9290   return ret.retn();
9291 }
9292
9293 /*!
9294  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9295  * the top level cells of the first mesh in MED file.
9296  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9297  *  \param [in] type - a spatial discretization of interest.
9298  *  \param [in] iteration - the iteration number of a required time step.
9299  *  \param [in] order - the iteration order number of required time step.
9300  *  \param [in] renumPol - specifies how to permute values of the result field according to
9301  *          the optional numbers of cells and nodes, if any. The valid values are
9302  *          - 0 - do not permute.
9303  *          - 1 - permute cells.
9304  *          - 2 - permute nodes.
9305  *          - 3 - permute cells and nodes.
9306  *
9307  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9308  *          caller is to delete this field using decrRef() as it is no more needed. 
9309  *  \throw If the MED file is not readable.
9310  *  \throw If there is no mesh in the MED file.
9311  *  \throw If no field values of the required parameters are available.
9312  */
9313 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9314 {
9315   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9316   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9317   if(!myF1TSC)
9318     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9319   MCAuto<DataArray> arrOut;
9320   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9321   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9322   return ret.retn();
9323 }
9324
9325 /*!
9326  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
9327  * method should be called (getFieldOnMeshAtLevel for example).
9328  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9329  *
9330  * \param [in] iteration - the iteration number of a required time step.
9331  * \param [in] order - the iteration order number of required time step.
9332  * \param [in] mesh - the mesh the field is lying on
9333  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9334  *          caller is to delete this field using decrRef() as it is no more needed. 
9335  */
9336 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9337 {
9338   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9339   MCAuto<DataArray> arrOut;
9340   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9341   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9342   return ret.retn();
9343 }
9344
9345 /*!
9346  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9347  * a given support.
9348  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9349  *  \param [in] type - a spatial discretization of interest.
9350  *  \param [in] iteration - the iteration number of a required time step.
9351  *  \param [in] order - the iteration order number of required time step.
9352  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9353  *  \param [in] mesh - the supporting mesh.
9354  *  \param [in] renumPol - specifies how to permute values of the result field according to
9355  *          the optional numbers of cells and nodes, if any. The valid values are
9356  *          - 0 - do not permute.
9357  *          - 1 - permute cells.
9358  *          - 2 - permute nodes.
9359  *          - 3 - permute cells and nodes.
9360  *
9361  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9362  *          caller is to delete this field using decrRef() as it is no more needed. 
9363  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9364  *  \throw If no field of \a this is lying on \a mesh.
9365  *  \throw If no field values of the required parameters are available.
9366  */
9367 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9368 {
9369   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9370   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9371   if(!myF1TSC)
9372     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9373   MCAuto<DataArray> arrOut;
9374   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9375   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9376   return ret.retn();
9377 }
9378
9379 /*!
9380  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9381  * given support. 
9382  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9383  *  \param [in] type - a spatial discretization of the new field.
9384  *  \param [in] iteration - the iteration number of a required time step.
9385  *  \param [in] order - the iteration order number of required time step.
9386  *  \param [in] mesh - the supporting mesh.
9387  *  \param [in] renumPol - specifies how to permute values of the result field according to
9388  *          the optional numbers of cells and nodes, if any. The valid values are
9389  *          - 0 - do not permute.
9390  *          - 1 - permute cells.
9391  *          - 2 - permute nodes.
9392  *          - 3 - permute cells and nodes.
9393  *
9394  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9395  *          caller is to delete this field using decrRef() as it is no more needed. 
9396  *  \throw If no field of \a this is lying on \a mesh.
9397  *  \throw If no field values of the required parameters are available.
9398  */
9399 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9400 {
9401   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9402   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9403   if(!myF1TSC)
9404     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9405   MCAuto<DataArray> arrOut;
9406   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9407   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9408   return ret.retn();
9409 }
9410
9411 /*!
9412  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9413  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9414  * This method is useful for MED2 file format when field on different mesh was autorized.
9415  */
9416 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9417 {
9418   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9419   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9420   if(!myF1TSC)
9421     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9422   MCAuto<DataArray> arrOut;
9423   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9424   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9425   return ret.retn();
9426 }
9427
9428 /*!
9429  * Returns values and a profile of the field of a given type, of a given time step,
9430  * lying on a given support.
9431  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9432  *  \param [in] type - a spatial discretization of the field.
9433  *  \param [in] iteration - the iteration number of a required time step.
9434  *  \param [in] order - the iteration order number of required time step.
9435  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9436  *  \param [in] mesh - the supporting mesh.
9437  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9438  *          field of interest lies on. If the field lies on all entities of the given
9439  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9440  *          using decrRef() as it is no more needed.  
9441  *  \param [in] glob - the global data storing profiles and localization.
9442  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9443  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9444  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9445  *  \throw If no field of \a this is lying on \a mesh.
9446  *  \throw If no field values of the required parameters are available.
9447  */
9448 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9449 {
9450   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9451   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9452   if(!myF1TSC)
9453     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9454   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9455   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9456 }
9457
9458 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9459 {
9460   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9461   if(!pt)
9462     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9463   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9464   if(!ret)
9465     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
9466   return ret;
9467 }
9468
9469 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9470 {
9471   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9472   if(!pt)
9473     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9474   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9475   if(!ret)
9476     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
9477   return ret;
9478 }
9479
9480 /*!
9481  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9482  * the given field is checked if its elements are sorted suitable for writing to MED file
9483  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9484  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9485  *  \param [in] field - the field to add to \a this.
9486  *  \throw If the name of \a field is empty.
9487  *  \throw If the data array of \a field is not set.
9488  *  \throw If existing time steps have different name or number of components than \a field.
9489  *  \throw If the underlying mesh of \a field has no name.
9490  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9491  */
9492 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9493 {
9494   const DataArrayDouble *arr=0;
9495   if(field)
9496     arr=field->getArray();
9497   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9498 }
9499
9500 /*!
9501  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9502  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9503  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9504  * and \a profile.
9505  *
9506  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9507  * A new profile is added only if no equal profile is missing.
9508  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9509  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9510  *  \param [in] mesh - the supporting mesh of \a field.
9511  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9512  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9513  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9514  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9515  *  \throw If the data array of \a field is not set.
9516  *  \throw If the data array of \a this is already allocated but has different number of
9517  *         components than \a field.
9518  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9519  *  \sa setFieldNoProfileSBT()
9520  */
9521 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9522 {
9523   const DataArrayDouble *arr=0;
9524   if(field)
9525     arr=field->getArray();
9526   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9527 }
9528
9529 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9530 {
9531   _content=new MEDFileFieldMultiTSWithoutSDA;
9532 }
9533
9534 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9535 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9536 {
9537 }
9538 catch(INTERP_KERNEL::Exception& e)
9539 { throw e; }
9540
9541 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9542 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9543 {
9544 }
9545 catch(INTERP_KERNEL::Exception& e)
9546 { throw e; }
9547
9548 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9549 {
9550 }
9551
9552 std::vector< std::vector<DataArrayDouble *> > MEDFileFieldMultiTS::getFieldSplitedByType2(int iteration, int order, const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
9553 {
9554   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9555 }
9556
9557 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9558 {
9559   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9560 }
9561
9562 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9563 {
9564   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9565 }
9566
9567 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
9568 {
9569   return MEDFileFieldMultiTS::New();
9570 }
9571
9572 //= MEDFileAnyTypeFieldMultiTSIterator
9573
9574 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9575 {
9576   if(fmts)
9577     {
9578       fmts->incrRef();
9579       _nb_iter=fmts->getNumberOfTS();
9580     }
9581 }
9582
9583 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9584 {
9585 }
9586
9587 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9588 {
9589   if(_iter_id<_nb_iter)
9590     {
9591       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9592       if(fmts)
9593         return fmts->getTimeStepAtPos(_iter_id++);
9594       else
9595         return 0;
9596     }
9597   else
9598     return 0;
9599 }
9600
9601 //= MEDFileIntFieldMultiTS
9602
9603 /*!
9604  * Returns a new empty instance of MEDFileFieldMultiTS.
9605  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9606  *          is to delete this field using decrRef() as it is no more needed.
9607  */
9608 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9609 {
9610   return new MEDFileIntFieldMultiTS;
9611 }
9612
9613 /*!
9614  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9615  * that has been read from a specified MED file.
9616  *  \param [in] fileName - the name of the MED file to read.
9617  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9618  *          is to delete this field using decrRef() as it is no more needed.
9619  *  \throw If reading the file fails.
9620  */
9621 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9622 {
9623   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9624   ret->contentNotNull();//to check that content type matches with \a this type.
9625   return ret.retn();
9626 }
9627
9628 /*!
9629  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9630  * that has been read from a specified MED file.
9631  *  \param [in] fileName - the name of the MED file to read.
9632  *  \param [in] fieldName - the name of the field to read.
9633  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9634  *          is to delete this field using decrRef() as it is no more needed.
9635  *  \throw If reading the file fails.
9636  *  \throw If there is no field named \a fieldName in the file.
9637  */
9638 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9639 {
9640   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9641   ret->contentNotNull();//to check that content type matches with \a this type.
9642   return ret.retn();
9643 }
9644
9645 /*!
9646  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9647  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9648  *
9649  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9650  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9651  * \warning this is a shallow copy constructor
9652  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9653  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9654  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9655  *          is to delete this field using decrRef() as it is no more needed.
9656  */
9657 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9658 {
9659   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9660 }
9661
9662 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9663 {
9664   MCAuto<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0,&entities);
9665   ret->contentNotNull();//to check that content type matches with \a this type.
9666   return ret.retn();
9667 }
9668
9669 /*!
9670  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9671  * following the given input policy.
9672  *
9673  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9674  *                            By default (true) the globals are deeply copied.
9675  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9676  */
9677 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9678 {
9679   MCAuto<MEDFileFieldMultiTS> ret;
9680   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9681   if(content)
9682     {
9683       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9684       if(!contc)
9685         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9686       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9687       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9688     }
9689   else
9690     ret=MEDFileFieldMultiTS::New();
9691   if(isDeepCpyGlobs)
9692     ret->deepCpyGlobs(*this);
9693   else
9694     ret->shallowCpyGlobs(*this);
9695   return ret.retn();
9696 }
9697
9698 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9699 {
9700   return new MEDFileIntFieldMultiTS(*this);
9701 }
9702
9703 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9704 {
9705   if(!f1ts)
9706     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9707   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9708   if(!f1tsC)
9709     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9710 }
9711
9712 /*!
9713  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
9714  * method should be called (getFieldOnMeshAtLevel for example).
9715  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9716  *
9717  * \param [in] iteration - the iteration number of a required time step.
9718  * \param [in] order - the iteration order number of required time step.
9719  * \param [in] mesh - the mesh the field is lying on
9720  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
9721  *          caller is to delete this field using decrRef() as it is no more needed. 
9722  */
9723 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9724 {
9725   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9726   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9727   if(!myF1TSC)
9728     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
9729   MCAuto<DataArray> arrOut;
9730   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9731   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
9732   return ret2.retn();
9733 }
9734
9735 /*!
9736  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9737  * mesh entities of a given dimension of the first mesh in MED file.
9738  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9739  *  \param [in] type - a spatial discretization of interest.
9740  *  \param [in] iteration - the iteration number of a required time step.
9741  *  \param [in] order - the iteration order number of required time step.
9742  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9743  *  \param [in] renumPol - specifies how to permute values of the result field according to
9744  *          the optional numbers of cells and nodes, if any. The valid values are
9745  *          - 0 - do not permute.
9746  *          - 1 - permute cells.
9747  *          - 2 - permute nodes.
9748  *          - 3 - permute cells and nodes.
9749  *
9750  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9751  *          caller is to delete this field using decrRef() as it is no more needed. 
9752  *  \throw If the MED file is not readable.
9753  *  \throw If there is no mesh in the MED file.
9754  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9755  *  \throw If no field values of the required parameters are available.
9756  */
9757 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9758 {
9759   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9760   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9761   if(!myF1TSC)
9762     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9763   MCAuto<DataArray> arr;
9764   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
9765   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9766   return ret2.retn();
9767 }
9768
9769 /*!
9770  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9771  * the top level cells of the first mesh in MED file.
9772  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9773  *  \param [in] type - a spatial discretization of interest.
9774  *  \param [in] iteration - the iteration number of a required time step.
9775  *  \param [in] order - the iteration order number of required time step.
9776  *  \param [in] renumPol - specifies how to permute values of the result field according to
9777  *          the optional numbers of cells and nodes, if any. The valid values are
9778  *          - 0 - do not permute.
9779  *          - 1 - permute cells.
9780  *          - 2 - permute nodes.
9781  *          - 3 - permute cells and nodes.
9782  *
9783  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9784  *          caller is to delete this field using decrRef() as it is no more needed. 
9785  *  \throw If the MED file is not readable.
9786  *  \throw If there is no mesh in the MED file.
9787  *  \throw If no field values of the required parameters are available.
9788  */
9789 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9790 {
9791   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9792   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9793   if(!myF1TSC)
9794     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9795   MCAuto<DataArray> arr;
9796   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
9797   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9798   return ret2.retn();
9799 }
9800
9801 /*!
9802  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9803  * a given support.
9804  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9805  *  \param [in] type - a spatial discretization of interest.
9806  *  \param [in] iteration - the iteration number of a required time step.
9807  *  \param [in] order - the iteration order number of required time step.
9808  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9809  *  \param [in] mesh - the supporting mesh.
9810  *  \param [in] renumPol - specifies how to permute values of the result field according to
9811  *          the optional numbers of cells and nodes, if any. The valid values are
9812  *          - 0 - do not permute.
9813  *          - 1 - permute cells.
9814  *          - 2 - permute nodes.
9815  *          - 3 - permute cells and nodes.
9816  *
9817  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9818  *          caller is to delete this field using decrRef() as it is no more needed. 
9819  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9820  *  \throw If no field of \a this is lying on \a mesh.
9821  *  \throw If no field values of the required parameters are available.
9822  */
9823 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9824 {
9825   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9826   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9827   if(!myF1TSC)
9828     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9829   MCAuto<DataArray> arr;
9830   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
9831   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9832   return ret2.retn();
9833 }
9834
9835 /*!
9836  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
9837  * given support. 
9838  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9839  *  \param [in] type - a spatial discretization of the new field.
9840  *  \param [in] iteration - the iteration number of a required time step.
9841  *  \param [in] order - the iteration order number of required time step.
9842  *  \param [in] mesh - the supporting mesh.
9843  *  \param [out] arrOut - the DataArrayInt containing values of field.
9844  *  \param [in] renumPol - specifies how to permute values of the result field according to
9845  *          the optional numbers of cells and nodes, if any. The valid values are
9846  *          - 0 - do not permute.
9847  *          - 1 - permute cells.
9848  *          - 2 - permute nodes.
9849  *          - 3 - permute cells and nodes.
9850  *
9851  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9852  *          caller is to delete this field using decrRef() as it is no more needed. 
9853  *  \throw If no field of \a this is lying on \a mesh.
9854  *  \throw If no field values of the required parameters are available.
9855  */
9856 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9857 {
9858   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9859   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9860   if(!myF1TSC)
9861     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9862   MCAuto<DataArray> arr;
9863   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
9864   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9865   return ret2.retn();
9866 }
9867
9868 /*!
9869  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9870  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9871  * This method is useful for MED2 file format when field on different mesh was autorized.
9872  */
9873 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
9874 {
9875   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9876   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9877   if(!myF1TSC)
9878     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9879   MCAuto<DataArray> arr;
9880   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
9881   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9882   return ret2.retn();
9883 }
9884
9885 /*!
9886  * Returns values and a profile of the field of a given type, of a given time step,
9887  * lying on a given support.
9888  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9889  *  \param [in] type - a spatial discretization of the field.
9890  *  \param [in] iteration - the iteration number of a required time step.
9891  *  \param [in] order - the iteration order number of required time step.
9892  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9893  *  \param [in] mesh - the supporting mesh.
9894  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9895  *          field of interest lies on. If the field lies on all entities of the given
9896  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9897  *          using decrRef() as it is no more needed.  
9898  *  \param [in] glob - the global data storing profiles and localization.
9899  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9900  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9901  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9902  *  \throw If no field of \a this is lying on \a mesh.
9903  *  \throw If no field values of the required parameters are available.
9904  */
9905 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9906 {
9907   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9908   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9909   if(!myF1TSC)
9910     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9911   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9912   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9913 }
9914
9915 /*!
9916  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9917  *  \param [in] pos - a time step id.
9918  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9919  *          delete this field using decrRef() as it is no more needed.
9920  *  \throw If \a pos is not a valid time step id.
9921  */
9922 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9923 {
9924   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9925   if(!item)
9926     {
9927       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9928       throw INTERP_KERNEL::Exception(oss.str());
9929     }
9930   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9931   if(itemC)
9932     {
9933       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9934       ret->shallowCpyGlobs(*this);
9935       return ret.retn();
9936     }
9937   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9938   throw INTERP_KERNEL::Exception(oss.str());
9939 }
9940
9941 /*!
9942  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
9943  * the given field is checked if its elements are sorted suitable for writing to MED file
9944  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9945  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9946  *  \param [in] field - the field to add to \a this.
9947  *  \throw If the name of \a field is empty.
9948  *  \throw If the data array of \a field is not set.
9949  *  \throw If existing time steps have different name or number of components than \a field.
9950  *  \throw If the underlying mesh of \a field has no name.
9951  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9952  */
9953 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
9954 {
9955   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
9956   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
9957 }
9958
9959 /*!
9960  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9961  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9962  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9963  * and \a profile.
9964  *
9965  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9966  * A new profile is added only if no equal profile is missing.
9967  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9968  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9969  *  \param [in] arrOfVals - the values of the field \a field used.
9970  *  \param [in] mesh - the supporting mesh of \a field.
9971  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9972  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9973  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9974  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9975  *  \throw If the data array of \a field is not set.
9976  *  \throw If the data array of \a this is already allocated but has different number of
9977  *         components than \a field.
9978  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9979  *  \sa setFieldNoProfileSBT()
9980  */
9981 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9982 {
9983   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
9984   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
9985 }
9986
9987 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9988 {
9989   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9990   if(!pt)
9991     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9992   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9993   if(!ret)
9994     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is not null but it is not of type int ! Reason is maybe that the read field has not the type INT32 !");
9995   return ret;
9996 }
9997
9998 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9999 {
10000   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10001   if(!pt)
10002     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10003   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10004   if(!ret)
10005     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is not null but it is not of type int ! Reason is maybe that the read field has not the type INT32 !");
10006   return ret;
10007 }
10008
10009 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10010 {
10011   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10012 }
10013
10014 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10015 {
10016 }
10017
10018 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10019 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
10020 {
10021 }
10022 catch(INTERP_KERNEL::Exception& e)
10023 { throw e; }
10024
10025 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
10026 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
10027 {
10028 }
10029 catch(INTERP_KERNEL::Exception& e)
10030 { throw e; }
10031
10032 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10033 {
10034   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10035 }
10036
10037 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10038 {
10039   return MEDFileIntFieldMultiTS::New();
10040 }
10041
10042 //= MEDFileFields
10043
10044 MEDFileFields *MEDFileFields::New()
10045 {
10046   return new MEDFileFields;
10047 }
10048
10049 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10050 {
10051   return new MEDFileFields(fileName,loadAll,0,0);
10052 }
10053
10054 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10055 {
10056   return new MEDFileFields(fileName,loadAll,ms,0);
10057 }
10058
10059 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10060 {
10061   return new MEDFileFields(fileName,loadAll,0,&entities);
10062 }
10063
10064 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10065 {
10066   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10067   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10068   return ret;
10069 }
10070
10071 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10072 {
10073   std::vector<const BigMemoryObject *> ret;
10074   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10075     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10076   return ret;
10077 }
10078
10079 MEDFileFields *MEDFileFields::deepCopy() const
10080 {
10081   MCAuto<MEDFileFields> ret=shallowCpy();
10082   std::size_t i=0;
10083   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10084     {
10085       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10086         ret->_fields[i]=(*it)->deepCopy();
10087     }
10088   ret->deepCpyGlobs(*this);
10089   return ret.retn();
10090 }
10091
10092 MEDFileFields *MEDFileFields::shallowCpy() const
10093 {
10094   return new MEDFileFields(*this);
10095 }
10096
10097 /*!
10098  * This method scans for all fields in \a this which time steps ids are common. Time step are discriminated by the pair of integer (iteration,order) whatever
10099  * the double time value. If all returned time steps are \b exactly those for all fields in \a this output parameter \a areThereSomeForgottenTS will be set to false.
10100  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10101  *
10102  * \param [out] areThereSomeForgottenTS - indicates to the caller if there is some time steps in \a this that are not present for all fields in \a this.
10103  * \return the sorted list of time steps (specified with a pair of integer iteration first and order second) present for all fields in \a this.
10104  * 
10105  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10106  */
10107 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10108 {
10109   std::set< std::pair<int,int> > s;
10110   bool firstShot=true;
10111   areThereSomeForgottenTS=false;
10112   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10113     {
10114       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10115         continue;
10116       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10117       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10118       if(firstShot)
10119         { s=s1; firstShot=false; }
10120       else
10121         {
10122           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10123           if(s!=s2)
10124             areThereSomeForgottenTS=true;
10125           s=s2;
10126         }
10127     }
10128   std::vector< std::pair<int,int> > ret;
10129   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10130   return ret;
10131 }
10132
10133 int MEDFileFields::getNumberOfFields() const
10134 {
10135   return _fields.size();
10136 }
10137
10138 std::vector<std::string> MEDFileFields::getFieldsNames() const
10139 {
10140   std::vector<std::string> ret(_fields.size());
10141   int i=0;
10142   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10143     {
10144       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10145       if(f)
10146         {
10147           ret[i]=f->getName();
10148         }
10149       else
10150         {
10151           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10152           throw INTERP_KERNEL::Exception(oss.str());
10153         }
10154     }
10155   return ret;
10156 }
10157
10158 std::vector<std::string> MEDFileFields::getMeshesNames() const
10159 {
10160   std::vector<std::string> ret;
10161   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10162     {
10163       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10164       if(cur)
10165         ret.push_back(cur->getMeshName());
10166     }
10167   return ret;
10168 }
10169
10170 std::string MEDFileFields::simpleRepr() const
10171 {
10172   std::ostringstream oss;
10173   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10174   simpleRepr(0,oss);
10175   return oss.str();
10176 }
10177
10178 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10179 {
10180   int nbOfFields=getNumberOfFields();
10181   std::string startLine(bkOffset,' ');
10182   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10183   int i=0;
10184   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10185     {
10186       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10187       if(cur)
10188         {
10189           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10190         }
10191       else
10192         {
10193           oss << startLine << "  - not defined !" << std::endl;
10194         }
10195     }
10196   i=0;
10197   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10198     {
10199       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10200       std::string chapter(17,'0'+i);
10201       oss << startLine << chapter << std::endl;
10202       if(cur)
10203         {
10204           cur->simpleRepr(bkOffset+2,oss,i);
10205         }
10206       else
10207         {
10208           oss << startLine << "  - not defined !" << std::endl;
10209         }
10210       oss << startLine << chapter << std::endl;
10211     }
10212   simpleReprGlobs(oss);
10213 }
10214
10215 MEDFileFields::MEDFileFields()
10216 {
10217 }
10218
10219 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
10220 try:MEDFileFieldGlobsReal(fileName)
10221 {
10222   MEDFileUtilities::CheckFileForRead(fileName);
10223   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
10224   int nbFields(MEDnField(fid));
10225   _fields.resize(nbFields);
10226   med_field_type typcha;
10227   for(int i=0;i<nbFields;i++)
10228     {
10229       std::vector<std::string> infos;
10230       std::string fieldName,dtunit;
10231       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
10232       switch(typcha)
10233       {
10234         case MED_FLOAT64:
10235           {
10236             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10237             break;
10238           }
10239         case MED_INT32:
10240           {
10241             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10242             break;
10243           }
10244         default:
10245           {
10246             std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << fileName << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
10247             throw INTERP_KERNEL::Exception(oss.str());
10248           }
10249       }
10250     }
10251   loadAllGlobals(fid);
10252 }
10253 catch(INTERP_KERNEL::Exception& e)
10254 {
10255     throw e;
10256 }
10257
10258 void MEDFileFields::writeLL(med_idt fid) const
10259 {
10260   int i=0;
10261   writeGlobals(fid,*this);
10262   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10263     {
10264       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10265       if(!elt)
10266         {
10267           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10268           throw INTERP_KERNEL::Exception(oss.str());
10269         }
10270       elt->writeLL(fid,*this);
10271     }
10272 }
10273
10274 void MEDFileFields::write(const std::string& fileName, int mode) const
10275 {
10276   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
10277   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
10278   writeLL(fid);
10279 }
10280
10281 /*!
10282  * This method alloc the arrays and load potentially huge arrays contained in this field.
10283  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10284  * This method can be also called to refresh or reinit values from a file.
10285  * 
10286  * \throw If the fileName is not set or points to a non readable MED file.
10287  */
10288 void MEDFileFields::loadArrays()
10289 {
10290   if(getFileName().empty())
10291     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10292   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10293   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10294     {
10295       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10296       if(elt)
10297         elt->loadBigArraysRecursively(fid,*elt);
10298     }
10299 }
10300
10301 /*!
10302  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10303  * But once data loaded once, this method does nothing.
10304  * 
10305  * \throw If the fileName is not set or points to a non readable MED file.
10306  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10307  */
10308 void MEDFileFields::loadArraysIfNecessary()
10309 {
10310   if(!getFileName().empty())
10311     {
10312       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10313       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10314         {
10315           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10316           if(elt)
10317             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10318         }
10319     }
10320 }
10321
10322 /*!
10323  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10324  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10325  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10326  * 
10327  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10328  */
10329 void MEDFileFields::unloadArrays()
10330 {
10331   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10332     {
10333       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10334       if(elt)
10335         elt->unloadArrays();
10336     }
10337 }
10338
10339 /*!
10340  * This method potentially releases big data arrays if \a this is coming from a file. If \a this has been built from scratch this method will have no effect.
10341  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10342  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10343  * 
10344  * \sa MEDFileFields::loadArraysIfNecessary
10345  */
10346 void MEDFileFields::unloadArraysWithoutDataLoss()
10347 {
10348   if(!getFileName().empty())
10349     unloadArrays();
10350 }
10351
10352 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10353 {
10354   std::vector<std::string> ret;
10355   std::set<std::string> ret2;
10356   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10357     {
10358       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10359       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10360         if(ret2.find(*it2)==ret2.end())
10361           {
10362             ret.push_back(*it2);
10363             ret2.insert(*it2);
10364           }
10365     }
10366   return ret;
10367 }
10368
10369 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10370 {
10371   std::vector<std::string> ret;
10372   std::set<std::string> ret2;
10373   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10374     {
10375       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10376       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10377         if(ret2.find(*it2)==ret2.end())
10378           {
10379             ret.push_back(*it2);
10380             ret2.insert(*it2);
10381           }
10382     }
10383   return ret;
10384 }
10385
10386 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10387 {
10388   std::vector<std::string> ret;
10389   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10390     {
10391       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10392       ret.insert(ret.end(),tmp.begin(),tmp.end());
10393     }
10394   return ret;
10395 }
10396
10397 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10398 {
10399   std::vector<std::string> ret;
10400   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10401     {
10402       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10403       ret.insert(ret.end(),tmp.begin(),tmp.end());
10404     }
10405   return ret;
10406 }
10407
10408 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10409 {
10410   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10411     (*it)->changePflsRefsNamesGen2(mapOfModif);
10412 }
10413
10414 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10415 {
10416   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10417     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10418 }
10419
10420 void MEDFileFields::resize(int newSize)
10421 {
10422   _fields.resize(newSize);
10423 }
10424
10425 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10426 {
10427   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10428     pushField(*it);
10429 }
10430
10431 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10432 {
10433   if(!field)
10434     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10435   _fields.push_back(field->getContent());
10436   appendGlobs(*field,1e-12);
10437 }
10438
10439 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10440 {
10441   if(!field)
10442     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10443   if(i>=(int)_fields.size())
10444     _fields.resize(i+1);
10445   _fields[i]=field->getContent();
10446   appendGlobs(*field,1e-12);
10447 }
10448
10449 void MEDFileFields::destroyFieldAtPos(int i)
10450 {
10451   destroyFieldsAtPos(&i,&i+1);
10452 }
10453
10454 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10455 {
10456   std::vector<bool> b(_fields.size(),true);
10457   for(const int *i=startIds;i!=endIds;i++)
10458     {
10459       if(*i<0 || *i>=(int)_fields.size())
10460         {
10461           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10462           throw INTERP_KERNEL::Exception(oss.str());
10463         }
10464       b[*i]=false;
10465     }
10466   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10467   std::size_t j=0;
10468   for(std::size_t i=0;i<_fields.size();i++)
10469     if(b[i])
10470       fields[j++]=_fields[i];
10471   _fields=fields;
10472 }
10473
10474 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10475 {
10476   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10477   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10478   std::vector<bool> b(_fields.size(),true);
10479   int k=bg;
10480   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10481     {
10482       if(k<0 || k>=(int)_fields.size())
10483         {
10484           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10485           throw INTERP_KERNEL::Exception(oss.str());
10486         }
10487       b[k]=false;
10488     }
10489   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10490   std::size_t j=0;
10491   for(std::size_t i=0;i<_fields.size();i++)
10492     if(b[i])
10493       fields[j++]=_fields[i];
10494   _fields=fields;
10495 }
10496
10497 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10498 {
10499   bool ret=false;
10500   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10501     {
10502       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10503       if(cur)
10504         ret=cur->changeMeshNames(modifTab) || ret;
10505     }
10506   return ret;
10507 }
10508
10509 /*!
10510  * \param [in] meshName the name of the mesh that will be renumbered.
10511  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10512  *             This code corresponds to the distribution of types in the corresponding mesh.
10513  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10514  * \param [in] renumO2N the old to new renumber array.
10515  * \return If true a renumbering has been performed. The structure in \a this has been modified. If false, nothing has been done: it is typically the case if \a meshName is not refered by any 
10516  *         field in \a this.
10517  */
10518 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10519 {
10520   bool ret=false;
10521   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10522     {
10523       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10524       if(fmts)
10525         {
10526           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10527         }
10528     }
10529   return ret;
10530 }
10531
10532 /*!
10533  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10534  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10535  *
10536  * \return A new object that the caller is responsible to deallocate.
10537  */
10538 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10539 {
10540   if(!mm)
10541     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10542   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10543   int nbFields(getNumberOfFields());
10544   for(int i=0;i<nbFields;i++)
10545     {
10546       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
10547       if(!fmts)
10548         {
10549           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10550           throw INTERP_KERNEL::Exception(oss.str());
10551         }
10552       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10553       fsOut->pushField(fmtsOut);
10554     }
10555   return fsOut.retn();
10556 }
10557
10558 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10559 {
10560   if(i<0 || i>=(int)_fields.size())
10561     {
10562       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10563       throw INTERP_KERNEL::Exception(oss.str());
10564     }
10565   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10566   if(!fmts)
10567     return 0;
10568   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10569   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10570   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10571   if(fmtsC)
10572     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10573   else if(fmtsC2)
10574     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10575   else
10576     {
10577       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10578       throw INTERP_KERNEL::Exception(oss.str());
10579     }
10580   ret->shallowCpyGlobs(*this);
10581   return ret.retn();
10582 }
10583
10584 /*!
10585  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10586  * This method is accessible in python using __getitem__ with a list in input.
10587  * \return a new object that the caller should deal with.
10588  */
10589 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10590 {
10591   MCAuto<MEDFileFields> ret=shallowCpy();
10592   std::size_t sz=std::distance(startIds,endIds);
10593   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10594   int j=0;
10595   for(const int *i=startIds;i!=endIds;i++,j++)
10596     {
10597       if(*i<0 || *i>=(int)_fields.size())
10598         {
10599           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10600           throw INTERP_KERNEL::Exception(oss.str());
10601         }
10602       fields[j]=_fields[*i];
10603     }
10604   ret->_fields=fields;
10605   return ret.retn();
10606 }
10607
10608 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10609 {
10610   return getFieldAtPos(getPosFromFieldName(fieldName));
10611 }
10612
10613 /*!
10614  * This method removes, if any, fields in \a this having no time steps.
10615  * If there is one or more than one such field in \a this true is returned and those fields will not be referenced anymore in \a this.
10616  * 
10617  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10618  */
10619 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10620 {
10621   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10622   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10623     {
10624       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10625       if(elt)
10626         {
10627           if(elt->getNumberOfTS()>0)
10628             newFields.push_back(*it);
10629         }
10630     }
10631   if(_fields.size()==newFields.size())
10632     return false;
10633   _fields=newFields;
10634   return true;
10635 }
10636
10637 /*!
10638  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10639  * This method can be seen as a filter applied on \a this, that returns an object containing
10640  * reduced the list of fields compared to those in \a this. The returned object is a new object but the object on which it lies are only
10641  * shallow copied from \a this.
10642  * 
10643  * \param [in] meshName - the name of the mesh on w
10644  * \return a new object that the caller should deal with.
10645  */
10646 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10647 {
10648   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10649   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10650     {
10651       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10652       if(!cur)
10653         continue;
10654       if(cur->getMeshName()==meshName)
10655         {
10656           cur->incrRef();
10657           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10658           ret->_fields.push_back(cur2);
10659         }
10660     }
10661   ret->shallowCpyOnlyUsedGlobs(*this);
10662   return ret.retn();
10663 }
10664
10665 /*!
10666  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10667  * Input time steps are specified using a pair of integer (iteration, order).
10668  * This method can be seen as a filter applied on \a this, that returns an object containing the same number of fields than those in \a this,
10669  * but for each multitimestep only the time steps in \a timeSteps are kept.
10670  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10671  * 
10672  * The returned object points to shallow copy of elements in \a this.
10673  * 
10674  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10675  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10676  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10677  */
10678 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10679 {
10680   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10681   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10682     {
10683       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10684       if(!cur)
10685         continue;
10686       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10687       ret->_fields.push_back(elt);
10688     }
10689   ret->shallowCpyOnlyUsedGlobs(*this);
10690   return ret.retn();
10691 }
10692
10693 /*!
10694  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10695  */
10696 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10697 {
10698   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10699   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10700     {
10701       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10702       if(!cur)
10703         continue;
10704       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10705       if(elt->getNumberOfTS()!=0)
10706         ret->_fields.push_back(elt);
10707     }
10708   ret->shallowCpyOnlyUsedGlobs(*this);
10709   return ret.retn();
10710 }
10711
10712 MEDFileFieldsIterator *MEDFileFields::iterator()
10713 {
10714   return new MEDFileFieldsIterator(this);
10715 }
10716
10717 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10718 {
10719   std::string tmp(fieldName);
10720   std::vector<std::string> poss;
10721   for(std::size_t i=0;i<_fields.size();i++)
10722     {
10723       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10724       if(f)
10725         {
10726           std::string fname(f->getName());
10727           if(tmp==fname)
10728             return i;
10729           else
10730             poss.push_back(fname);
10731         }
10732     }
10733   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10734   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10735   oss << " !";
10736   throw INTERP_KERNEL::Exception(oss.str());
10737 }
10738
10739 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10740 {
10741   if(fs)
10742     {
10743       fs->incrRef();
10744       _nb_iter=fs->getNumberOfFields();
10745     }
10746 }
10747
10748 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10749 {
10750 }
10751
10752 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10753 {
10754   if(_iter_id<_nb_iter)
10755     {
10756       MEDFileFields *fs(_fs);
10757       if(fs)
10758         return fs->getFieldAtPos(_iter_id++);
10759       else
10760         return 0;
10761     }
10762   else
10763     return 0;
10764 }