]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileField.cxx
Salome HOME
Merge branch 'master' of ssh://git.salome-platform.org/tools/medcoupling
[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 "MEDFileSafeCaller.txx"
26 #include "MEDFileFieldOverView.hxx"
27 #include "MEDFileBlowStrEltUp.hxx"
28 #include "MEDFileFieldVisitor.hxx"
29
30 #include "MEDCouplingFieldDouble.hxx"
31 #include "MEDCouplingFieldTemplate.hxx"
32 #include "MEDCouplingFieldDiscretization.hxx"
33
34 #include "InterpKernelAutoPtr.hxx"
35 #include "CellModel.hxx"
36
37 #include <algorithm>
38 #include <iterator>
39
40 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
41 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
42 extern med_geometry_type typmainoeud[1];
43 extern med_geometry_type typmai3[34];
44
45 using namespace MEDCoupling;
46
47 template class MEDFileField1TSTemplateWithoutSDA<int>;
48 template class MEDFileField1TSTemplateWithoutSDA<double>;
49
50 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
51 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
52
53 MEDFileGTKeeper::~MEDFileGTKeeper()
54 {
55 }
56
57 MEDFileGTKeeper *MEDFileGTKeeperSta::deepCopy() const
58 {
59   return new MEDFileGTKeeperSta(_geo_type);
60 }
61
62 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperSta::getGeoType() const
63 {
64   return _geo_type;
65 }
66
67 std::string MEDFileGTKeeperSta::getRepr() const
68 {
69   return INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr();
70 }
71
72 bool MEDFileGTKeeperSta::isEqual(const MEDFileGTKeeper *other) const
73 {
74   const MEDFileGTKeeperSta *otherC(dynamic_cast<const MEDFileGTKeeperSta *>(other));
75   if(!otherC)
76     return false;
77   return _geo_type==otherC->_geo_type;
78 }
79
80 MEDFileGTKeeperDyn::MEDFileGTKeeperDyn(const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileStructureElement *se):_mesh(mesh),_section(section),_se(se)
81 {
82   if(mesh)
83     mesh->incrRef();
84   if(section)
85     section->incrRef();
86   if(se)
87     se->incrRef();
88   if(_mesh.isNull() || _section.isNull() || _se.isNull())
89     throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn constructor : null pointer not allowed !");
90 }
91
92 MEDFileGTKeeper *MEDFileGTKeeperDyn::deepCopy() const
93 {
94   return new MEDFileGTKeeperDyn(_mesh,_section,_se);
95 }
96
97 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperDyn::getGeoType() const
98 {
99   throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn::getGeoType : not valid !");
100 }
101
102 std::string MEDFileGTKeeperDyn::getRepr() const
103 {
104   std::ostringstream oss;
105   oss << _se->getDynGT();
106   return oss.str();
107 }
108
109 bool MEDFileGTKeeperDyn::isEqual(const MEDFileGTKeeper *other) const
110 {
111   const MEDFileGTKeeperDyn *otherC(dynamic_cast<const MEDFileGTKeeperDyn *>(other));
112   if(!otherC)
113     return false;
114   return this==otherC;
115 }
116
117 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
118 {
119   return new MEDFileFieldLoc(fid,locName);
120 }
121
122 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id, const MEDFileEntities *entities)
123 {
124   return new MEDFileFieldLoc(fid,id,entities);
125 }
126
127 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)
128 {
129   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
130 }
131
132 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
133 {
134   med_geometry_type geotype;
135   med_geometry_type sectiongeotype;
136   int nsectionmeshcell;
137   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
138   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
139   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
140   _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
141   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
142   _nb_node_per_cell=cm.getNumberOfNodes();
143   _ref_coo.resize(_dim*_nb_node_per_cell);
144   _gs_coo.resize(_dim*_nb_gauss_pt);
145   _w.resize(_nb_gauss_pt);
146   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
147 }
148
149 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id, const MEDFileEntities *entities)
150 {
151   med_geometry_type geotype;
152   med_geometry_type sectiongeotype;
153   int nsectionmeshcell;
154   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
155   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
156   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
157   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
158   _name=locName;
159   std::string sectionName(MEDLoaderBase::buildStringFromFortran(sectionmeshname,MED_NAME_SIZE));
160   if(sectionName.empty())
161     {
162       _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
163       const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
164       _nb_node_per_cell=cm.getNumberOfNodes();
165     }
166   else
167     {
168       const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
169       if(!entities2)
170         {
171           std::ostringstream oss; oss << "MEDFileFieldLoc cstr : for loc \"" << _name << "\" presence of non static type ! Expect entities !";
172           throw INTERP_KERNEL::Exception(oss.str());
173         }
174       const MEDFileStructureElement *se(entities2->getWithGT(geotype));
175       const MEDFileUMesh *um(entities2->getSupMeshWithName(se->getMeshName()));
176       const MEDFileUMesh *section(entities2->getSupMeshWithName(sectionName));
177       _gt=new MEDFileGTKeeperDyn(um,section,se);
178       {
179         int dummy;
180         MEDFILESAFECALLERWR0(MEDmeshGeotypeParameter,(fid,geotype,&dummy,&_nb_node_per_cell));
181       }
182     }
183   _ref_coo.resize(_dim*_nb_node_per_cell);
184   _gs_coo.resize(_dim*_nb_gauss_pt);
185   _w.resize(_nb_gauss_pt);
186   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
187 }
188
189 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
190                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_gt(new MEDFileGTKeeperSta(geoType)),_ref_coo(refCoo),_gs_coo(gsCoo),_w(w)
191 {
192   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
193   _dim=cm.getDimension();
194   _nb_node_per_cell=cm.getNumberOfNodes();
195   _nb_gauss_pt=_w.size();
196 }
197
198
199 MEDFileFieldLoc::MEDFileFieldLoc(const MEDFileFieldLoc& other):_dim(other._dim),_nb_gauss_pt(other._nb_gauss_pt),_gt(other._gt->deepCopy()),_nb_node_per_cell(other._nb_node_per_cell),_name(other._name),_ref_coo(other._ref_coo),_gs_coo(other._gs_coo),_w(other._w)
200 {
201 }
202
203 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
204 {
205   return new MEDFileFieldLoc(*this);
206 }
207
208 bool MEDFileFieldLoc::isOnStructureElement() const
209 {
210   const MEDFileGTKeeper *gt(_gt);
211   if(!gt)
212     throw INTERP_KERNEL::Exception("MEDFileFieldLoc::isOnStructureElement : null pointer !");
213   const MEDFileGTKeeperDyn *gt2(dynamic_cast<const MEDFileGTKeeperDyn *>(gt));
214   return gt2!=NULL;
215 }
216
217 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
218 {
219   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
220 }
221
222 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
223 {
224   return std::vector<const BigMemoryObject *>();
225 }
226
227 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
228 {
229   static const char OFF7[]="\n    ";
230   oss << "\"" << _name << "\"" << OFF7;
231   oss << "GeoType=" << _gt->getRepr() << OFF7;
232   oss << "Dimension=" << _dim << OFF7;
233   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
234   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
235   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
236   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
237   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
238 }
239
240 void MEDFileFieldLoc::setName(const std::string& name)
241 {
242   _name=name;
243 }
244
245 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
246 {
247   if(_name!=other._name)
248     return false;
249   if(_dim!=other._dim)
250     return false;
251   if(_nb_gauss_pt!=other._nb_gauss_pt)
252     return false;
253   if(_nb_node_per_cell!=other._nb_node_per_cell)
254     return false;
255   if(!_gt->isEqual(other._gt))
256     return false;
257   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
258     return false;
259   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
260     return false;
261   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
262     return false;
263
264   return true;
265 }
266
267 void MEDFileFieldLoc::writeLL(med_idt fid) const
268 {
269   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)getGeoType()],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
270 }
271
272 std::string MEDFileFieldLoc::repr() const
273 {
274   std::ostringstream oss; oss.precision(15);
275   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
276   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
277   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
278   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
279   oss << "\n  - Ref coords are : ";
280   int sz=_ref_coo.size();
281   if(sz%_dim==0)
282     {
283       int nbOfTuples=sz/_dim;
284       for(int i=0;i<nbOfTuples;i++)
285         {
286           oss << "(";
287           for(int j=0;j<_dim;j++)
288             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
289           oss << ") ";
290         }
291     }
292   else
293     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
294   oss << "\n  - Gauss coords in reference element : ";
295   sz=_gs_coo.size();
296   if(sz%_dim==0)
297     {
298       int nbOfTuples=sz/_dim;
299       for(int i=0;i<nbOfTuples;i++)
300         {
301           oss << "(";
302           for(int j=0;j<_dim;j++)
303             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
304           oss << ") ";
305         }
306     }
307   else
308     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
309   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
310   return oss.str();
311 }
312
313 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
314 {
315   _type=field->getTypeOfField();
316   _start=start;
317   switch(_type)
318   {
319     case ON_CELLS:
320       {
321         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
322         _end=_start+nbOfCells;
323         _nval=nbOfCells;
324         break;
325       }
326     case ON_GAUSS_NE:
327       {
328         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
329         const int *arrPtr=arr->getConstPointer();
330         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
331         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
332         _nval=nbOfCells;
333         break;
334       }
335     case ON_GAUSS_PT:
336       {
337         const MEDCouplingFieldDiscretization *disc(field->getDiscretization());
338         const MEDCouplingGaussLocalization& gsLoc(field->getGaussLocalization(_loc_id));
339         const MEDCouplingFieldDiscretizationGauss *disc2(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc));
340         if(!disc2)
341           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
342         const DataArrayInt *dai(disc2->getArrayOfDiscIds());
343         MCAuto<DataArrayInt> dai2(disc2->getOffsetArr(field->getMesh()));
344         const int *dai2Ptr(dai2->getConstPointer());
345         int nbi(gsLoc.getWeights().size());
346         MCAuto<DataArrayInt> da2(dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1));
347         MCAuto<DataArrayInt> da3(da2->findIdsEqual(_loc_id));
348         const int *da3Ptr(da3->getConstPointer());
349         if(da3->getNumberOfTuples()!=nbOfCells)
350           {//profile : for gauss even in NoProfile !!!
351             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
352             _profile=oss.str();
353             da3->setName(_profile.c_str());
354             glob.appendProfile(da3);
355           }
356         MCAuto<DataArrayInt> da4(DataArrayInt::New());
357         _nval=da3->getNbOfElems();
358         da4->alloc(_nval*nbi,1);
359         int *da4Ptr(da4->getPointer());
360         for(int i=0;i<_nval;i++)
361           {
362             int ref=dai2Ptr[offset+da3Ptr[i]];
363             for(int j=0;j<nbi;j++)
364               *da4Ptr++=ref+j;
365           }
366         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
367         _localization=oss2.str();
368         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
369         _end=_start+_nval*nbi;
370         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
371         break;
372       }
373     default:
374       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
375   }
376   start=_end;
377 }
378
379 /*!
380  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
381  * \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).
382  * \param [in] multiTypePfl is the end user profile specified in high level API
383  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
384  * \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.
385  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
386  * \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.
387  */
388 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)
389 {
390   _profile.clear();
391   _type=field->getTypeOfField();
392   std::string pflName(multiTypePfl->getName());
393   std::ostringstream oss; oss << pflName;
394   if(_type!=ON_NODES)
395     {
396       if(!isPflAlone)
397         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
398     }
399   else
400     { oss << "_NODE"; }
401   if(locIds)
402     {
403       if(pflName.empty())
404         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
405       if(_type!=ON_GAUSS_PT)
406         {
407           locIds->setName(oss.str());
408           glob.appendProfile(locIds);
409           _profile=oss.str();
410         }
411     }
412   _start=start;
413   switch(_type)
414   {
415     case ON_NODES:
416       {
417         _nval=idsInPfl->getNumberOfTuples();
418         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
419         _end=_start+_nval;
420         break;
421       }
422     case ON_CELLS:
423       {
424         _nval=idsInPfl->getNumberOfTuples();
425         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
426         _end=_start+_nval;
427         break;
428       }
429     case ON_GAUSS_NE:
430       {
431         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
432         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
433         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
434         arr3->computeOffsetsFull();
435         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
436         int trueNval=tmp->getNumberOfTuples();
437         _nval=idsInPfl->getNumberOfTuples();
438         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
439         _end=_start+trueNval;
440         break;
441       }
442     case ON_GAUSS_PT:
443       {
444         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
445         if(!disc2)
446           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
447         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
448         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
449         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
450         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
451         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
452         //
453         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
454         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
455         //
456         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
457         int trueNval=0;
458         for(const int *pt=da4->begin();pt!=da4->end();pt++)
459           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
460         tmp->alloc(trueNval,1);
461         int *tmpPtr=tmp->getPointer();
462         for(const int *pt=da4->begin();pt!=da4->end();pt++)
463           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
464             *tmpPtr++=j;
465         //
466         _nval=da4->getNumberOfTuples();
467         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
468         _end=_start+trueNval;
469         oss << "_loc_" << _loc_id;
470         if(locIds)
471           {
472             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
473             da5->setName(oss.str());
474             glob.appendProfile(da5);
475             _profile=oss.str();
476           }
477         else
478           {
479             if(!da3->isIota(nbOfEltsInWholeMesh))
480               {
481                 da3->setName(oss.str());
482                 glob.appendProfile(da3);
483                 _profile=oss.str();
484               }
485           }
486         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
487         _localization=oss2.str();
488         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
489         break;
490       }
491     default:
492       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
493   }
494   start=_end;
495 }
496
497 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
498 {
499   _start=start;
500   _nval=arrr->getNumberOfTuples();
501   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
502   _end=_start+_nval;
503   start=_end;
504 }
505
506 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
507 {
508   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
509 }
510
511 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId)
512 {
513   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
514 }
515
516 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
517 {
518   return new MEDFileFieldPerMeshPerTypePerDisc(other);
519 }
520
521 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
522 {
523   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
524 }
525
526 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
527 {
528   std::vector<const BigMemoryObject *> ret(1);
529   ret[0]=(const PartDefinition*)_pd;
530   return ret;
531 }
532
533 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const
534 {
535   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(*this));
536   ret->_father=father;
537   return ret.retn();
538 }
539
540 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
541 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
542 {
543   if(pd)
544     pd->incrRef();
545 }
546 catch(INTERP_KERNEL::Exception& e)
547 {
548     throw e;
549 }
550
551 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
552 {
553 }
554
555 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)
556 {
557 }
558
559 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
560     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
561 {
562 }
563
564 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)
565 {
566   const PartDefinition *pd(_pd);
567   if(!pd)
568     {
569       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
570       int nbi,tmp1;
571       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
572       if(_end-_start!=nbValsInFile*nbi)
573         {
574           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 !";
575           throw INTERP_KERNEL::Exception(oss.str());
576         }
577       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
578     }
579   else
580     {
581       if(!_profile.empty())
582         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
583       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
584       int profilesize,nbi;
585       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
586       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
587       if(spd)
588         {
589           int start,stop,step;
590           spd->getSlice(start,stop,step);
591           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
592           med_filter filter=MED_FILTER_INIT;
593           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
594                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
595                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
596                                    /*lastblocksize=useless because count=1*/0,&filter);
597           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
598           MEDfilterClose(&filter);
599           return ;
600         }
601       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
602       if(dpd)
603         {
604           dpd->checkConsistencyLight();
605           MCAuto<DataArrayInt> myIds(dpd->toDAI());
606           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
607           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
608           myIds->applyLin(1,-a);
609           int nbOfEltsToLoad(b-a+1);
610           med_filter filter=MED_FILTER_INIT;
611           {//TODO : manage int32 !
612             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
613             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
614             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
615                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
616                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
617                                      /*lastblocksize=useless because count=1*/0,&filter);
618             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
619             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
620             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
621             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
622           }
623           MEDfilterClose(&filter);
624         }
625       else
626         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
627     }
628 }
629
630 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
631 {
632   return _father;
633 }
634
635 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
636 {
637   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
638   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
639   std::string fieldName(nasc.getName()),meshName(getMeshName());
640   int iteration(getIteration()),order(getOrder()),profilesize,nbi;
641   TypeOfField type(getType());
642   med_geometry_type mgeoti;
643   med_entity_type menti;
644   _father->entriesForMEDfile(type,mgeoti,menti);
645   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
646   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
647   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
648   const PartDefinition *pd(_pd);
649   if(!pd)
650     {
651       _nval=zeNVal;
652     }
653   else
654     {
655       if(!_profile.empty())
656         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
657       _nval=pd->getNumberOfElems();
658     }
659   _start=start;
660   _end=start+_nval*nbi;
661   start=_end;
662   if(type==ON_CELLS && !_localization.empty())
663     {
664       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
665         setType(ON_GAUSS_PT);
666       else
667         {
668           setType(ON_GAUSS_NE);
669           _localization.clear();
670         }
671     }
672 }
673
674 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
675 {
676   std::string fieldName(nasc.getName()),meshName(getMeshName());
677   int iteration(getIteration()),order(getOrder());
678   TypeOfField type(getType());
679   med_geometry_type mgeoti;
680   med_entity_type menti;
681   _father->entriesForMEDfile(type,mgeoti,menti);
682   if(_start>_end)
683     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
684   if(_start==_end)
685     return ;
686   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
687   if(_start<0 || _start>=arr->getNumberOfTuples())
688     {
689       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
690       throw INTERP_KERNEL::Exception(oss.str());
691     }
692   if(_end<0 || _end>arr->getNumberOfTuples())
693     {
694       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
695       throw INTERP_KERNEL::Exception(oss.str());
696     }
697   int nbOfCompo(arr->getNumberOfComponents());
698   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
699   if(arrD)
700     {
701       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
702       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
703       return ;
704     }
705   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
706   if(arrI)
707     {
708       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
709       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
710       return ;
711     }
712   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
713 }
714
715 /*!
716  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
717  */
718 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
719 {
720   int delta=_end-_start;
721   _start=newValueOfStart;
722   _end=_start+delta;
723 }
724
725 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
726 {
727   return _father->getIteration();
728 }
729
730 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
731 {
732   return _father->getOrder();
733 }
734
735 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
736 {
737   return _father->getTime();
738 }
739
740 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
741 {
742   return _father->getMeshName();
743 }
744
745 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
746 {
747   const char startLine[]="    ## ";
748   std::string startLine2(bkOffset,' ');
749   startLine2+=startLine;
750   INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
751   oss << startLine2 << "Localization #" << id << "." << std::endl;
752   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
753   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
754   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
755   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
756 }
757
758 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
759 {
760   return _type;
761 }
762
763 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
764 {
765   return _father->getGeoType();
766 }
767
768 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
769 {
770   types.insert(_type);
771 }
772
773 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
774 {
775   _type=newType;
776 }
777
778 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
779 {
780   return _father->getNumberOfComponents();
781 }
782
783 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
784 {
785   return _end-_start;
786 }
787
788 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
789 {
790   return _father->getOrCreateAndGetArray();
791 }
792
793 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
794 {
795   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
796   return fath->getOrCreateAndGetArray();
797 }
798
799 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
800 {
801   return _father->getInfo();
802 }
803
804 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
805 {
806   return _profile;
807 }
808
809 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
810 {
811   _profile=newPflName;
812 }
813
814 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
815 {
816   return _localization;
817 }
818
819 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
820 {
821   _localization=newLocName;
822 }
823
824 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
825 {
826   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
827     {
828       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
829         {
830           _profile=(*it2).second;
831           return;
832         }
833     }
834 }
835
836 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
837 {
838   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
839     {
840       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
841         {
842           _localization=(*it2).second;
843           return;
844         }
845     }
846 }
847
848 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
849 {
850   if(type!=_type)
851     return ;
852   dads.push_back(std::pair<int,int>(_start,_end));
853   geoTypes.push_back(getGeoType());
854   if(_profile.empty())
855     pfls.push_back(0);
856   else
857     {
858       pfls.push_back(glob->getProfile(_profile.c_str()));
859     }
860   if(_localization.empty())
861     locs.push_back(-1);
862   else
863     {
864       locs.push_back(glob->getLocalizationId(_localization.c_str()));
865     }
866 }
867
868 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
869 {
870   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));
871   startEntryId++;
872 }
873
874 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
875 {
876   TypeOfField type=getType();
877   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
878   med_geometry_type mgeoti;
879   med_entity_type menti;
880   _father->entriesForMEDfile(getType(),mgeoti,menti);
881   const DataArray *arr(getOrCreateAndGetArray());
882   if(!arr)
883     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
884   if(!arr->isAllocated())
885     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
886   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
887   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
888   const unsigned char *locToWrite=0;
889   if(arrD)
890     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
891   else if(arrI)
892     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
893   else
894     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
895   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
896                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
897                                                    locToWrite));
898 }
899
900 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
901 {
902   type=_type;
903   pfl=_profile;
904   loc=_localization;
905   dad.first=_start; dad.second=_end;
906 }
907
908 /*!
909  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
910  *             This code corresponds to the distribution of types in the corresponding mesh.
911  * \param [out] ptToFill memory zone where the output will be stored.
912  * \return the size of data pushed into output param \a ptToFill
913  */
914 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
915 {
916   _loc_id=offset;
917   std::ostringstream oss;
918   std::size_t nbOfType=codeOfMesh.size()/3;
919   int found=-1;
920   for(std::size_t i=0;i<nbOfType && found==-1;i++)
921     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
922       found=(int)i;
923   if(found==-1)
924     {
925       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
926       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
927       throw INTERP_KERNEL::Exception(oss.str());
928     }
929   int *work=ptToFill;
930   if(_profile.empty())
931     {
932       if(_nval!=codeOfMesh[3*found+1])
933         {
934           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
935           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
936           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
937           throw INTERP_KERNEL::Exception(oss.str());
938         }
939       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
940         *work++=ii;
941     }
942   else
943     {
944       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
945       if(pfl->getNumberOfTuples()!=_nval)
946         {
947           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
948           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
949           oss << _nval;
950           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
951           throw INTERP_KERNEL::Exception(oss.str());
952         }
953       int offset2=codeOfMesh[3*found+2];
954       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
955         {
956           if(*pflId<codeOfMesh[3*found+1])
957             *work++=offset2+*pflId;
958         }
959     }
960   return _nval;
961 }
962
963 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
964 {
965   for(int i=_start;i<_end;i++)
966     *ptToFill++=i;
967   return _end-_start;
968 }
969
970 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
971 {
972   switch(type)
973   {
974     case ON_CELLS:
975       return -2;
976     case ON_GAUSS_NE:
977       return -1;
978     case ON_GAUSS_PT:
979       return locId;
980     default:
981       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
982   }
983 }
984
985 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
986 {
987   int id=0;
988   std::map<std::pair<std::string,TypeOfField>,int> m;
989   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
990   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
991     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
992       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
993   ret.resize(id);
994   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
995     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
996   return ret;
997 }
998
999 /*!
1000  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
1001  * 
1002  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
1003  * \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.
1004  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
1005  * \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)
1006  * \param [in,out] glob if necessary by the method, new profiles can be added to it
1007  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
1008  * \param [out] result All new entries will be appended on it.
1009  * \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 !)
1010  */
1011 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1012                                                        const DataArrayInt *explicitIdsInMesh,
1013                                                        const std::vector<int>& newCode,
1014                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
1015                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
1016 {
1017   if(entriesOnSameDisc.empty())
1018     return false;
1019   TypeOfField type=entriesOnSameDisc[0]->getType();
1020   int szEntities=0,szTuples=0;
1021   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
1022     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
1023   int nbi=szTuples/szEntities;
1024   if(szTuples%szEntities!=0)
1025     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
1026   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
1027   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
1028   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
1029   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
1030   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
1031   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
1032   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
1033   int id=0;
1034   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
1035     {
1036       int startOfEltIdOfChunk=(*it)->_start;
1037       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
1038       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
1039       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
1040       //
1041       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
1042       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
1043       //
1044       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
1045       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
1046     }
1047   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
1048   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
1049   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
1050   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
1051   //
1052   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
1053   //
1054   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
1055   arrPart->renumberInPlace(renumTupleIds->begin());
1056   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
1057   bool ret=false;
1058   const int *idIt=diffVals->begin();
1059   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
1060   int offset2=0;
1061   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
1062     {
1063       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
1064       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
1065       int nbEntityElts=subIds->getNumberOfTuples();
1066       bool ret2;
1067       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
1068           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
1069                                       offset+offset2,
1070                                       li,glob,ret2);
1071       ret=ret || ret2;
1072       result.push_back(eltToAdd);
1073       offset2+=nbEntityElts*nbi;
1074     }
1075   ret=ret || li.empty();
1076   return ret;
1077 }
1078
1079 /*!
1080  * \param [in] typeF type of field of new chunk
1081  * \param [in] geoType the geometric type of the chunk
1082  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
1083  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
1084  * \param [in] nbi number of integration points
1085  * \param [in] offset The offset in the **global array of data**.
1086  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
1087  *                 to the new chunk to create.
1088  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
1089  * \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
1090  *              and corresponding entry erased from \a entriesOnSameDisc.
1091  * \return a newly allocated chunk
1092  */
1093 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
1094                                                                                                   bool isPfl, int nbi, int offset,
1095                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1096                                                                                                   MEDFileFieldGlobsReal& glob,
1097                                                                                                   bool &notInExisting)
1098 {
1099   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1100   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1101   for(;it!=entriesOnSameDisc.end();it++)
1102     {
1103       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1104         {
1105           if(!isPfl)
1106             {
1107               if((*it)->_profile.empty())
1108                 break;
1109               else
1110                 if(!(*it)->_profile.empty())
1111                   {
1112                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1113                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1114                       break;
1115                   }
1116             }
1117         }
1118     }
1119   if(it==entriesOnSameDisc.end())
1120     {
1121       notInExisting=true;
1122       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1123       ret->_type=typeF;
1124       ret->_loc_id=(int)geoType;
1125       ret->_nval=nbMeshEntities;
1126       ret->_start=offset;
1127       ret->_end=ret->_start+ret->_nval*nbi;
1128       if(isPfl)
1129         {
1130           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1131           glob.appendProfile(idsOfMeshElt);
1132           ret->_profile=idsOfMeshElt->getName();
1133         }
1134       //tony treatment of localization
1135       return ret;
1136     }
1137   else
1138     {
1139       notInExisting=false;
1140       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1141       ret->_loc_id=(int)geoType;
1142       ret->setNewStart(offset);
1143       entriesOnSameDisc.erase(it);
1144       return ret;
1145     }
1146
1147 }
1148
1149 ////////////////////////////////////
1150
1151 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1152 {
1153 }
1154
1155 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1156 {
1157   _father=father;
1158 }
1159
1160 void MEDFileFieldPerMeshPerTypeCommon::accept(MEDFileFieldVisitor& visitor) const
1161 {
1162   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1163     if((*it).isNotNull())
1164       {
1165         visitor.newPerMeshPerTypePerDisc(*it);
1166       }
1167 }
1168
1169 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1170 {
1171   std::size_t i=0;
1172   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1173     {
1174       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1175         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1176     }
1177 }
1178
1179 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1180 {
1181   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1182 }
1183
1184 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1185 {
1186   std::vector<const BigMemoryObject *> ret;
1187   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1188     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1189   return ret;
1190 }
1191
1192 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1193 {
1194   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1195   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1196     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1197 }
1198
1199 /*!
1200  * This method is the most general one. No optimization is done here.
1201  * \param [in] multiTypePfl is the end user profile specified in high level API
1202  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1203  * \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.
1204  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1205  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1206  * \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.
1207  */
1208 void MEDFileFieldPerMeshPerTypeCommon::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)
1209 {
1210   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1211   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1212     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1213 }
1214
1215 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1216 {
1217   _field_pm_pt_pd.resize(1);
1218   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1219   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1220 }
1221
1222 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1223 {
1224   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1225   if(!arr || !arr->isAllocated())
1226     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1227   _field_pm_pt_pd.resize(1);
1228   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1229   _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.
1230 }
1231
1232 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1233 {
1234   TypeOfField type=field->getTypeOfField();
1235   if(type!=ON_GAUSS_PT)
1236     {
1237       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1238       int sz=_field_pm_pt_pd.size();
1239       bool found=false;
1240       for(int j=0;j<sz && !found;j++)
1241         {
1242           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1243             {
1244               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1245               found=true;
1246             }
1247         }
1248       if(!found)
1249         {
1250           _field_pm_pt_pd.resize(sz+1);
1251           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1252         }
1253       std::vector<int> ret(1,(int)sz);
1254       return ret;
1255     }
1256   else
1257     {
1258       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1259       int sz2=ret2.size();
1260       std::vector<int> ret3(sz2);
1261       int k=0;
1262       for(int i=0;i<sz2;i++)
1263         {
1264           int sz=_field_pm_pt_pd.size();
1265           int locIdToFind=ret2[i];
1266           bool found=false;
1267           for(int j=0;j<sz && !found;j++)
1268             {
1269               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1270                 {
1271                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1272                   ret3[k++]=j;
1273                   found=true;
1274                 }
1275             }
1276           if(!found)
1277             {
1278               _field_pm_pt_pd.resize(sz+1);
1279               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1280               ret3[k++]=sz;
1281             }
1282         }
1283       return ret3;
1284     }
1285 }
1286
1287 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1288 {
1289   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1290   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1291   if(!disc2)
1292     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1293   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1294   if(!da)
1295     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1296   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1297   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1298   if(retTmp->presenceOfValue(-1))
1299     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1300   std::vector<int> ret(retTmp->begin(),retTmp->end());
1301   return ret;
1302 }
1303
1304 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1305 {
1306   TypeOfField type=field->getTypeOfField();
1307   if(type!=ON_GAUSS_PT)
1308     {
1309       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1310       int sz=_field_pm_pt_pd.size();
1311       bool found=false;
1312       for(int j=0;j<sz && !found;j++)
1313         {
1314           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1315             {
1316               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1317               found=true;
1318             }
1319         }
1320       if(!found)
1321         {
1322           _field_pm_pt_pd.resize(sz+1);
1323           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1324         }
1325       std::vector<int> ret(1,0);
1326       return ret;
1327     }
1328   else
1329     {
1330       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1331       int sz2=ret2.size();
1332       std::vector<int> ret3(sz2);
1333       int k=0;
1334       for(int i=0;i<sz2;i++)
1335         {
1336           int sz=_field_pm_pt_pd.size();
1337           int locIdToFind=ret2[i];
1338           bool found=false;
1339           for(int j=0;j<sz && !found;j++)
1340             {
1341               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1342                 {
1343                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1344                   ret3[k++]=j;
1345                   found=true;
1346                 }
1347             }
1348           if(!found)
1349             {
1350               _field_pm_pt_pd.resize(sz+1);
1351               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1352               ret3[k++]=sz;
1353             }
1354         }
1355       return ret3;
1356     }
1357 }
1358
1359 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1360 {
1361   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1362   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1363   if(!disc2)
1364     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1365   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1366   if(!da)
1367     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1368   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1369   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1370   if(retTmp->presenceOfValue(-1))
1371     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1372   std::vector<int> ret(retTmp->begin(),retTmp->end());
1373   return ret;
1374 }
1375
1376 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1377 {
1378   return _father;
1379 }
1380
1381 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1382 {
1383   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1384   int curDim((int)cm.getDimension());
1385   if(dim!=std::numeric_limits<int>::max())
1386     {
1387       if(dim!=curDim)
1388         return false;
1389     }
1390   else
1391     dim=curDim;
1392   return true;
1393 }
1394
1395 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1396 {
1397   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1398     {
1399       (*it)->fillTypesOfFieldAvailable(types);
1400     }
1401 }
1402
1403 void MEDFileFieldPerMeshPerTypeCommon::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1404 {
1405   int sz=_field_pm_pt_pd.size();
1406   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1407   for(int i=0;i<sz;i++)
1408     {
1409       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1410     }
1411 }
1412
1413 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1414 {
1415   return _father->getIteration();
1416 }
1417
1418 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1419 {
1420   return _father->getOrder();
1421 }
1422
1423 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1424 {
1425   return _father->getTime();
1426 }
1427
1428 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1429 {
1430   return _father->getMeshName();
1431 }
1432
1433 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1434 {
1435   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1436     {
1437       globalSz+=(*it)->getNumberOfTuples();
1438     }
1439   nbOfEntries+=(int)_field_pm_pt_pd.size();
1440 }
1441
1442 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1443 {
1444   return _father->getNumberOfComponents();
1445 }
1446
1447 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1448 {
1449   std::size_t nb(0);
1450   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1451     {
1452       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1453       if(fmtd)
1454         nb++;
1455     }
1456   return nb>1;
1457 }
1458
1459 void MEDFileFieldPerMeshPerTypeCommon::pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc)
1460 {
1461   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt;
1462   elt.takeRef(disc);
1463   _field_pm_pt_pd.push_back(elt);
1464 }
1465
1466 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1467 {
1468   return _father->getOrCreateAndGetArray();
1469 }
1470
1471 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1472 {
1473   const MEDFileFieldPerMesh *fath=_father;
1474   return fath->getOrCreateAndGetArray();
1475 }
1476
1477 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1478 {
1479   return _father->getInfo();
1480 }
1481
1482 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1483 {
1484   std::vector<std::string> ret;
1485   std::set<std::string> ret2;
1486   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1487     {
1488       std::string tmp=(*it1)->getProfile();
1489       if(!tmp.empty())
1490         if(ret2.find(tmp)==ret2.end())
1491           {
1492             ret.push_back(tmp);
1493             ret2.insert(tmp);
1494           }
1495     }
1496   return ret;
1497 }
1498
1499 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1500 {
1501   std::vector<std::string> ret;
1502   std::set<std::string> ret2;
1503   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1504     {
1505       std::string tmp=(*it1)->getLocalization();
1506       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1507         if(ret2.find(tmp)==ret2.end())
1508           {
1509             ret.push_back(tmp);
1510             ret2.insert(tmp);
1511           }
1512     }
1513   return ret;
1514 }
1515
1516 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1517 {
1518   std::vector<std::string> ret;
1519   std::set<std::string> ret2;
1520   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1521     {
1522       std::string tmp=(*it1)->getProfile();
1523       if(!tmp.empty())
1524         ret.push_back(tmp);
1525     }
1526   return ret;
1527 }
1528
1529 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1530 {
1531   std::vector<std::string> ret;
1532   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1533     {
1534       std::string tmp=(*it1)->getLocalization();
1535       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1536         ret.push_back(tmp);
1537     }
1538   return ret;
1539 }
1540
1541 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1542 {
1543   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1544     (*it1)->changePflsRefsNamesGen(mapOfModif);
1545 }
1546
1547 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1548 {
1549   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1550     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1551 }
1552
1553 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1554 {
1555   if(_field_pm_pt_pd.empty())
1556     {
1557       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1558       throw INTERP_KERNEL::Exception(oss.str());
1559     }
1560   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1561     return _field_pm_pt_pd[locId];
1562   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1563   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1564   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1565   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1566 }
1567
1568 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1569 {
1570   if(_field_pm_pt_pd.empty())
1571     {
1572       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1573       throw INTERP_KERNEL::Exception(oss.str());
1574     }
1575   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1576     return _field_pm_pt_pd[locId];
1577   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1578   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1579   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1580   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1581 }
1582
1583 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1584 {
1585   int i=0;
1586   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1587     {
1588       (*it)->fillValues(i,startEntryId,entries);
1589     }
1590 }
1591
1592 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1593 {
1594   _field_pm_pt_pd=leaves;
1595   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1596     (*it)->setFather(this);
1597 }
1598
1599 /*!
1600  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1601  *  \param [out] its - list of pair (start,stop) kept
1602  *  \return bool - false if the type of field \a tof is not contained in \a this.
1603  */
1604 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1605 {
1606   bool ret(false);
1607   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1608   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1609     if((*it)->getType()==tof)
1610       {
1611         newPmPtPd.push_back(*it);
1612         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1613         (*it)->setNewStart(globalNum);
1614         globalNum=(*it)->getEnd();
1615         its.push_back(bgEnd);
1616         ret=true;
1617       }
1618   if(ret)
1619     _field_pm_pt_pd=newPmPtPd;
1620   return ret;
1621 }
1622
1623 /*!
1624  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1625  *  \param [out] its - list of pair (start,stop) kept
1626  *  \return bool - false if the type of field \a tof is not contained in \a this.
1627  */
1628 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1629 {
1630   if(_field_pm_pt_pd.size()<=idOfDisc)
1631     return false;
1632   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1633   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1634   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1635   elt->setNewStart(globalNum);
1636   globalNum=elt->getEnd();
1637   its.push_back(bgEnd);
1638   _field_pm_pt_pd=newPmPtPd;
1639   return true;
1640 }
1641
1642 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1643 {
1644   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1645     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1646 }
1647
1648 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1649 {
1650   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1651     (*it)->loadBigArray(fid,nasc);
1652 }
1653
1654 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1655 {
1656   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1657     {
1658       (*it)->copyOptionsFrom(*this);
1659       (*it)->writeLL(fid,nasc);
1660     }
1661 }
1662
1663 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1664 {
1665   switch(ikType)
1666   {
1667     case ON_CELLS:
1668       medfGeoType=typmai3[(int)ikGeoType];
1669       return MED_CELL;
1670     case ON_NODES:
1671       medfGeoType=MED_NONE;
1672       return MED_NODE;
1673     case ON_GAUSS_NE:
1674       medfGeoType=typmai3[(int)ikGeoType];
1675       return MED_NODE_ELEMENT;
1676     case ON_GAUSS_PT:
1677       medfGeoType=typmai3[(int)ikGeoType];
1678       return MED_CELL;
1679     default:
1680       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1681   }
1682   return MED_UNDEF_ENTITY_TYPE;
1683 }
1684
1685 //////////////////////////////////////////////////
1686
1687 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1688 {
1689   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1690 }
1691
1692 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1693 {
1694   return new MEDFileFieldPerMeshPerType(fath,geoType);
1695 }
1696
1697 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1698 {
1699   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1700   ret->setFather(father);
1701   ret->deepCopyElements();
1702   return ret.retn();
1703 }
1704
1705 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
1706 {
1707   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1708     {
1709       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1710       if(meshDim!=(int)cm.getDimension())
1711         return ;
1712     }
1713   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1714     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1715 }
1716
1717 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1718 {
1719   return _geo_type;
1720 }
1721
1722 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1723 {
1724   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1725 }
1726
1727 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1728 {
1729   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1730   int curDim((int)cm.getDimension());
1731   dim=std::max(dim,curDim);
1732 }
1733
1734 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1735 {
1736   const char startLine[]="  ## ";
1737   std::string startLine2(bkOffset,' ');
1738   std::string startLine3(startLine2);
1739   startLine3+=startLine;
1740   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1741     {
1742       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1743       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1744     }
1745   else
1746     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1747   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1748   int i=0;
1749   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1750     {
1751       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1752       if(cur)
1753         cur->simpleRepr(bkOffset,oss,i);
1754       else
1755         {
1756           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1757         }
1758     }
1759 }
1760
1761 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1762 {
1763   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1764   return std::string(cm.getRepr());
1765 }
1766
1767 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1768 {
1769 }
1770
1771 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1772 {
1773   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1774   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1775   med_geometry_type mgeoti;
1776   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1777   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1778   _field_pm_pt_pd.resize(nbProfiles);
1779   for(int i=0;i<nbProfiles;i++)
1780     {
1781       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1782     }
1783   if(type==ON_CELLS)
1784     {
1785       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1786       for(int i=0;i<nbProfiles2;i++)
1787         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1788     }
1789 }
1790
1791 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)
1792 {
1793   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1794   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1795   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1796     {
1797       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1798         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1799     }
1800   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1801     {
1802       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1803       ret->_field_pm_pt_pd.push_back(agg);
1804     }
1805   return ret;
1806 }
1807
1808 //////////////////////////////////////////////////
1809
1810 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1811 {
1812   if(!entities)
1813     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1814   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1815   if(!entities2)
1816     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1817   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1818   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1819 }
1820
1821 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1822 {
1823   _se.takeRef(se);
1824   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1825   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1826   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1827   _field_pm_pt_pd.resize(nbProfiles);
1828   for(int i=0;i<nbProfiles;i++)
1829     {
1830       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1831     }
1832 }
1833
1834 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1835 {
1836   return _se->getDynGT();
1837 }
1838
1839 std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const
1840 {
1841   return _se->getName();
1842 }
1843
1844 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1845 {
1846   throw INTERP_KERNEL::Exception("not implemented yet !");
1847 }
1848
1849 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1850 {
1851   gt=getDynGT();
1852   ent=MED_STRUCT_ELEMENT;
1853 }
1854
1855 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1856 {
1857   throw INTERP_KERNEL::Exception("not implemented yet !");
1858 }
1859
1860 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1861 {
1862   const char startLine[]="  ## ";
1863   std::string startLine2(bkOffset,' ');
1864   std::string startLine3(startLine2);
1865   startLine3+=startLine;
1866   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1867   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1868   int i=0;
1869   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1870     {
1871       if((*it).isNotNull())
1872         (*it)->simpleRepr(bkOffset,oss,i);
1873       else
1874         {
1875           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1876         }
1877     }
1878 }
1879
1880 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1881 {
1882   throw INTERP_KERNEL::Exception("not implemented yet !");
1883 }
1884
1885 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1886 {
1887   MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1888   ret->setFather(father);
1889   ret->deepCopyElements();
1890   return ret.retn();
1891 }
1892
1893 void MEDFileFieldPerMeshPerTypeDyn::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
1894 {
1895   throw INTERP_KERNEL::Exception("not implemented yet !");
1896 }
1897
1898 //////////////////////////////////////////////////
1899
1900 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1901 {
1902   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1903 }
1904
1905 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1906 {
1907   return new MEDFileFieldPerMesh(fath,mesh);
1908 }
1909
1910 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1911 {
1912   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1913 }
1914
1915 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1916 {
1917   std::vector<const BigMemoryObject *> ret;
1918   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1919     ret.push_back(*it);
1920   return ret;
1921 }
1922
1923 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1924 {
1925   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1926   ret->_father=father;
1927   std::size_t i=0;
1928   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1929     {
1930       if((*it).isNotNull())
1931         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1932     }
1933   return ret.retn();
1934 }
1935
1936 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1937 {
1938   std::string startLine(bkOffset,' ');
1939   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1940   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1941   int i=0;
1942   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1943     {
1944       if((*it).isNotNull())
1945         (*it)->simpleRepr(bkOffset,oss,i);
1946       else
1947         {
1948           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1949         }
1950     }
1951 }
1952
1953 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1954 {
1955   _mesh_name=mesh->getName();
1956   mesh->getTime(_mesh_iteration,_mesh_order);
1957 }
1958
1959 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1960 {
1961   int nbOfTypes=code.size()/3;
1962   int offset=0;
1963   for(int i=0;i<nbOfTypes;i++)
1964     {
1965       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1966       int nbOfCells=code[3*i+1];
1967       int pos=addNewEntryIfNecessary(type);
1968       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1969       offset+=nbOfCells;
1970     }
1971 }
1972
1973 /*!
1974  * This method is the most general one. No optimization is done here.
1975  * \param [in] multiTypePfl is the end user profile specified in high level API
1976  * \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].
1977  * \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.
1978  * \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.
1979  * \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.
1980  * \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.
1981  */
1982 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)
1983 {
1984   int nbOfTypes(code.size()/3);
1985   for(int i=0;i<nbOfTypes;i++)
1986     {
1987       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1988       int pos=addNewEntryIfNecessary(type);
1989       DataArrayInt *pfl=0;
1990       if(code[3*i+2]!=-1)
1991         pfl=idsPerType[code[3*i+2]];
1992       int nbOfTupes2=code2.size()/3;
1993       int found=0;
1994       for(;found<nbOfTupes2;found++)
1995         if(code[3*i]==code2[3*found])
1996           break;
1997       if(found==nbOfTupes2)
1998         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1999       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
2000     }
2001 }
2002
2003 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
2004 {
2005   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2006   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
2007 }
2008
2009 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2010 {
2011   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2012   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
2013 }
2014
2015 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
2016 {
2017   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2018     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
2019 }
2020
2021 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
2022 {
2023   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2024     (*it)->loadBigArraysRecursively(fid,nasc);
2025 }
2026
2027 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
2028 {
2029   int nbOfTypes=_field_pm_pt.size();
2030   for(int i=0;i<nbOfTypes;i++)
2031     {
2032       _field_pm_pt[i]->copyOptionsFrom(*this);
2033       _field_pm_pt[i]->writeLL(fid,nasc);
2034     }
2035 }
2036
2037 void MEDFileFieldPerMesh::getDimension(int& dim) const
2038 {
2039   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2040     (*it)->getDimension(dim);
2041 }
2042
2043 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
2044 {
2045   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2046     if(!(*it)->isUniqueLevel(dim))
2047       return false;
2048   return true;
2049 }
2050
2051 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
2052 {
2053   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2054     (*it)->fillTypesOfFieldAvailable(types);
2055 }
2056
2057 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
2058 {
2059   int sz=_field_pm_pt.size();
2060   std::vector< std::vector<std::pair<int,int> > > ret(sz);
2061   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
2062   for(int i=0;i<sz;i++)
2063     {
2064       types[i]=_field_pm_pt[i]->getGeoType();
2065       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
2066     }
2067   return ret;
2068 }
2069
2070 double MEDFileFieldPerMesh::getTime() const
2071 {
2072   int tmp1,tmp2;
2073   return _father->getTime(tmp1,tmp2);
2074 }
2075
2076 int MEDFileFieldPerMesh::getIteration() const
2077 {
2078   return _father->getIteration();
2079 }
2080
2081 int MEDFileFieldPerMesh::getOrder() const
2082 {
2083   return _father->getOrder();
2084 }
2085
2086 int MEDFileFieldPerMesh::getNumberOfComponents() const
2087 {
2088   return _father->getNumberOfComponents();
2089 }
2090
2091 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
2092 {
2093   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2094     {
2095       if((*it).isNull())
2096         continue;
2097       if((*it)->presenceOfMultiDiscPerGeoType())
2098         return true;
2099     }
2100   return false;
2101 }
2102
2103 bool MEDFileFieldPerMesh::presenceOfStructureElements() const
2104 {
2105   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2106     if((*it).isNotNull())
2107       {
2108         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2109         if(pt)
2110           return true;
2111       }
2112   return false;
2113 }
2114
2115 bool MEDFileFieldPerMesh::onlyStructureElements() const
2116 {
2117   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2118     if((*it).isNotNull())
2119       {
2120         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2121         if(!pt)
2122           return false;
2123       }
2124   return true;
2125 }
2126
2127 void MEDFileFieldPerMesh::killStructureElements()
2128 {
2129   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2130   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2131     {
2132       if((*it).isNotNull())
2133         {
2134           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2135           if(!pt)
2136             res.push_back(*it);
2137         }
2138     }
2139   _field_pm_pt=res;
2140 }
2141
2142 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2143 {
2144   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2145   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2146     {
2147       if((*it).isNotNull())
2148         {
2149           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2150           if(pt)
2151             res.push_back(*it);
2152         }
2153     }
2154   _field_pm_pt=res;
2155 }
2156
2157 void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName)
2158 {
2159   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2160   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2161     {
2162       if((*it).isNotNull())
2163         {
2164           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2165           if(!pt)
2166             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !");
2167           if(pt->getModelName()==seName)
2168             res.push_back(*it);
2169         }
2170     }
2171   _field_pm_pt=res;
2172 }
2173
2174 void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
2175 {
2176   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2177     {
2178       if((*it).isNotNull())
2179         {
2180           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2181           if(pt)
2182             {
2183               ps.push_back(std::pair<std::string,std::string>(getMeshName(),pt->getModelName()));
2184             }
2185           else
2186             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !");
2187         }
2188     }
2189 }
2190
2191 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2192 {
2193   if(!_father)
2194     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2195   return _father->getOrCreateAndGetArray();
2196 }
2197
2198 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2199 {
2200   if(!_father)
2201     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2202   return _father->getOrCreateAndGetArray();
2203 }
2204
2205 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2206 {
2207   return _father->getInfo();
2208 }
2209
2210 /*!
2211  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2212  * 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.
2213  * It returns 2 output vectors :
2214  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2215  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2216  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2217  */
2218 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)
2219 {
2220   int notNullPflsSz=0;
2221   int nbOfArrs=geoTypes.size();
2222   for(int i=0;i<nbOfArrs;i++)
2223     if(pfls[i])
2224       notNullPflsSz++;
2225   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2226   int nbOfDiffGeoTypes=geoTypes3.size();
2227   code.resize(3*nbOfDiffGeoTypes);
2228   notNullPfls.resize(notNullPflsSz);
2229   notNullPflsSz=0;
2230   int j=0;
2231   for(int i=0;i<nbOfDiffGeoTypes;i++)
2232     {
2233       int startZone=j;
2234       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2235       std::vector<const DataArrayInt *> notNullTmp;
2236       if(pfls[j])
2237         notNullTmp.push_back(pfls[j]);
2238       j++;
2239       for(;j<nbOfArrs;j++)
2240         if(geoTypes[j]==refType)
2241           {
2242             if(pfls[j])
2243               notNullTmp.push_back(pfls[j]);
2244           }
2245         else
2246           break;
2247       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2248       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2249       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2250       code[3*i]=(int)refType;
2251       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2252       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2253       if(notNullTmp.empty())
2254         code[3*i+2]=-1;
2255       else
2256         {
2257           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2258           code[3*i+2]=notNullPflsSz++;
2259         }
2260     }
2261 }
2262
2263 /*!
2264  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2265  */
2266 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)
2267 {
2268   int sz=dads.size();
2269   int ret=0;
2270   for(int i=0;i<sz;i++)
2271     {
2272       if(locs[i]==-1)
2273         {
2274           if(type!=ON_GAUSS_NE)
2275             ret+=dads[i].second-dads[i].first;
2276           else
2277             {
2278               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2279               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2280             }
2281         }
2282       else
2283         {
2284           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2285           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2286         }
2287     }
2288   return ret;
2289 }
2290
2291 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2292 {
2293   std::vector<std::string> ret;
2294   std::set<std::string> ret2;
2295   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2296     {
2297       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2298       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2299         if(ret2.find(*it2)==ret2.end())
2300           {
2301             ret.push_back(*it2);
2302             ret2.insert(*it2);
2303           }
2304     }
2305   return ret;
2306 }
2307
2308 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2309 {
2310   std::vector<std::string> ret;
2311   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2312     {
2313       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2314       ret.insert(ret.end(),tmp.begin(),tmp.end());
2315     }
2316   return ret;
2317 }
2318
2319 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2320 {
2321   std::vector<std::string> ret;
2322   std::set<std::string> ret2;
2323   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2324     {
2325       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2326       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2327         if(ret2.find(*it2)==ret2.end())
2328           {
2329             ret.push_back(*it2);
2330             ret2.insert(*it2);
2331           }
2332     }
2333   return ret;
2334 }
2335
2336 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2337 {
2338   std::vector<std::string> ret;
2339   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2340     {
2341       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2342       ret.insert(ret.end(),tmp.begin(),tmp.end());
2343     }
2344   return ret;
2345 }
2346
2347 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2348 {
2349   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2350     {
2351       if((*it).first==_mesh_name)
2352         {
2353           _mesh_name=(*it).second;
2354           return true;
2355         }
2356     }
2357   return false;
2358 }
2359
2360 void MEDFileFieldPerMesh::convertMedBallIntoClassic()
2361 {
2362   if(_field_pm_pt.size()!=1)
2363     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : Only managed for single mesh !");
2364   if(_field_pm_pt[0].isNull())
2365     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : null pointer !");
2366   MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<MEDFileFieldPerMeshPerTypeDyn *>((MEDFileFieldPerMeshPerTypeCommon *)_field_pm_pt[0]));
2367   if(!pt)
2368     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : this is expected to be marked as structure element !");
2369   if(pt->getNumberOfLoc()!=1)
2370     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : only one loc managed !");
2371   const MEDFileFieldPerMeshPerTypePerDisc *disc(pt->getLeafGivenLocId(0));
2372   if(!disc)
2373     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : internal error !");
2374   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> disc2(MEDFileFieldPerMeshPerTypePerDisc::New(*disc));
2375   disc2->setType(ON_NODES);
2376   MCAuto<MEDFileFieldPerMeshPerType> pt2(MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR));
2377   disc2->setFather(pt2);
2378   pt2->setFather(this);
2379   pt2->pushDiscretization(disc2);
2380   _field_pm_pt[0]=DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(pt2);
2381 }
2382
2383 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2384                                                       MEDFileFieldGlobsReal& glob)
2385 {
2386   if(_mesh_name!=meshName)
2387     return false;
2388   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2389   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2390   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2391   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2392   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2393   getUndergroundDataArrayExt(entries);
2394   DataArray *arr0(getOrCreateAndGetArray());//tony
2395   if(!arr0)
2396     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2397   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2398   if(!arr0)
2399     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2400   int sz=0;
2401   if(!arr)
2402     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2403   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2404     {
2405       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2406         {
2407           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2408           sz+=(*it).second.second-(*it).second.first;
2409         }
2410       else
2411         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2412     }
2413   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2414   ////////////////////
2415   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2416   int *workI2=explicitIdsOldInMesh->getPointer();
2417   int sz1=0,sz2=0,sid=1;
2418   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2419   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2420   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2421     {
2422       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2423       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2424       int *workI=explicitIdsOldInArr->getPointer();
2425       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2426         {
2427           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2428           (*itL2)->setLocId(sz2);
2429           (*itL2)->_tmp_work1=(*itL2)->getStart();
2430           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2431         }
2432       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2433     }
2434   explicitIdsOldInMesh->reAlloc(sz2);
2435   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2436   ////////////////////
2437   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2438   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2439   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2440   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2441     {
2442       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2443       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2444       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2445     }
2446   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2447   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2448   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2449     {
2450       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2451       int newStart=elt->getLocId();
2452       elt->setLocId((*it)->getGeoType());
2453       elt->setNewStart(newStart);
2454       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2455       entriesKeptNew.push_back(elt);
2456       entriesKeptNew2.push_back(elt);
2457     }
2458   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2459   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2460   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2461   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2462   bool ret=false;
2463   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2464     {
2465       sid=0;
2466       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2467         {
2468           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2469           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2470           }*/
2471       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2472                                                             glob,arr2,otherEntriesNew) || ret;
2473     }
2474   if(!ret)
2475     return false;
2476   // Assign new dispatching
2477   assignNewLeaves(otherEntriesNew);
2478   arr->deepCopyFrom(*arr2);
2479   return true;
2480 }
2481
2482 /*!
2483  * \param [in,out] globalNum a global numbering counter for the renumbering.
2484  * \param [out] its - list of pair (start,stop) kept
2485  */
2486 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2487 {
2488   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2489   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2490     {
2491       std::vector< std::pair<int,int> > its2;
2492       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2493         {
2494           ret.push_back(*it);
2495           its.insert(its.end(),its2.begin(),its2.end());
2496         }
2497     }
2498   _field_pm_pt=ret;
2499 }
2500
2501 /*!
2502  * \param [in,out] globalNum a global numbering counter for the renumbering.
2503  * \param [out] its - list of pair (start,stop) kept
2504  */
2505 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2506 {
2507   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2508   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2509     {
2510       std::vector< std::pair<int,int> > its2;
2511       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2512         {
2513           ret.push_back(*it);
2514           its.insert(its.end(),its2.begin(),its2.end());
2515         }
2516     }
2517   _field_pm_pt=ret;
2518 }
2519
2520 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2521 {
2522   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2523   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2524     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2525   //
2526   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2527   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2528   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2529   for(;it1!=types.end();it1++,it2++)
2530     {
2531       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2532       elt->setLeaves((*it1).second);
2533       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2534       *it2=elt2;
2535     }
2536   _field_pm_pt=fieldPmPt;
2537 }
2538
2539 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2540 {
2541   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2542     (*it)->changePflsRefsNamesGen(mapOfModif);
2543 }
2544
2545 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2546 {
2547   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2548     (*it)->changeLocsRefsNamesGen(mapOfModif);
2549 }
2550
2551 /*!
2552  * \param [in] mesh is the whole mesh
2553  */
2554 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2555 {
2556   if(_field_pm_pt.empty())
2557     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2558   //
2559   std::vector< std::pair<int,int> > dads;
2560   std::vector<const DataArrayInt *> pfls;
2561   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2562   std::vector<int> locs,code;
2563   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2564   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2565     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2566   // Sort by types
2567   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2568   if(code.empty())
2569     {
2570       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2571       throw INTERP_KERNEL::Exception(oss.str());
2572     }
2573   //
2574   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2575   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2576   if(type!=ON_NODES)
2577     {
2578       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2579       if(!arr)
2580         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2581       else
2582         {
2583           MCAuto<DataArrayInt> arr2(arr);
2584           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2585         }
2586     }
2587   else
2588     {
2589       if(code.size()!=3)
2590         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2591       int nb=code[1];
2592       if(code[2]==-1)
2593         {
2594           if(nb!=mesh->getNumberOfNodes())
2595             {
2596               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2597               oss << " nodes in mesh !";
2598               throw INTERP_KERNEL::Exception(oss.str());
2599             }
2600           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2601         }
2602       else
2603         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2604     }
2605 }
2606
2607 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2608 {
2609   if(_field_pm_pt.empty())
2610     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2611   //
2612   std::vector<std::pair<int,int> > dads;
2613   std::vector<const DataArrayInt *> pfls;
2614   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2615   std::vector<int> locs,code;
2616   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2617   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2618     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2619   // Sort by types
2620   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2621   if(code.empty())
2622     {
2623       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2624       throw INTERP_KERNEL::Exception(oss.str());
2625     }
2626   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2627   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2628   if(type!=ON_NODES)
2629     {
2630       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2631       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2632     }
2633   else
2634     {
2635       if(code.size()!=3)
2636         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2637       int nb=code[1];
2638       if(code[2]==-1)
2639         {
2640           if(nb!=mesh->getNumberOfNodes())
2641             {
2642               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2643               oss << " nodes in mesh !";
2644               throw INTERP_KERNEL::Exception(oss.str());
2645             }
2646         }
2647       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2648     }
2649   //
2650   return 0;
2651 }
2652
2653 void MEDFileFieldPerMesh::accept(MEDFileFieldVisitor& visitor) const
2654 {
2655   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2656     if((*it).isNotNull())
2657       {
2658         visitor.newPerMeshPerTypeEntry(*it);
2659         (*it)->accept(visitor);
2660         visitor.endPerMeshPerTypeEntry(*it);
2661       }
2662 }
2663
2664 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2665 {
2666   int globalSz=0;
2667   int nbOfEntries=0;
2668   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2669     {
2670       (*it)->getSizes(globalSz,nbOfEntries);
2671     }
2672   entries.resize(nbOfEntries);
2673   nbOfEntries=0;
2674   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2675     {
2676       (*it)->fillValues(nbOfEntries,entries);
2677     }
2678 }
2679
2680 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2681 {
2682   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2683     {
2684       if((*it)->getGeoType()==typ)
2685         return (*it)->getLeafGivenLocId(locId);
2686     }
2687   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2688   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2689   oss << "Possiblities are : ";
2690   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2691     {
2692       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2693       oss << "\"" << cm2.getRepr() << "\", ";
2694     }
2695   throw INTERP_KERNEL::Exception(oss.str());
2696 }
2697
2698 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2699 {
2700   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2701     {
2702       if((*it)->getGeoType()==typ)
2703         return (*it)->getLeafGivenLocId(locId);
2704     }
2705   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2706   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2707   oss << "Possiblities are : ";
2708   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2709     {
2710       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2711       oss << "\"" << cm2.getRepr() << "\", ";
2712     }
2713   throw INTERP_KERNEL::Exception(oss.str());
2714 }
2715
2716 /*!
2717  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2718  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2719  * \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.
2720  * \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.
2721  */
2722 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)
2723 {
2724   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2725   if(pms.empty())
2726     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2727   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2728     {
2729       if(!(*it).second)
2730         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2731       if(!(*it).second->getProfile().empty())
2732         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2733       if(!(*it).second->getLocalization().empty())
2734         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2735     }
2736   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2737   std::size_t i(0);
2738   std::vector< std::pair<int,int> > filteredDTS;
2739   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2740     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2741       if((*it2).first==gt)
2742         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2743   if(pms.size()!=filteredDTS.size())
2744     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2745   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2746   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2747   int zeStart(start),nval(0);
2748   for(;it1!=pms.end();it1++,it2++)
2749     {
2750       if((*it1).first!=(*it2).first)
2751         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2752       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2753       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2754       start+=e1-s1;
2755       nval+=((*it1).second)->getNumberOfVals();
2756     }
2757   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2758   return ret;
2759 }
2760
2761 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)
2762 {
2763   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2764   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2765   std::size_t i(0);
2766   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2767     {
2768       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2769       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2770         {
2771           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2772           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2773           if(!elt)
2774             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2775           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2776         }
2777     }
2778   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2779     {
2780       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2781       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2782       ret->_field_pm_pt.push_back(agg2);
2783     }
2784   return ret;
2785 }
2786
2787 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2788 {
2789   int i=0;
2790   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2791   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2792   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2793     {
2794       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2795       if(type==curType)
2796         return i;
2797       else
2798         {
2799           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2800           if(pos>pos2)
2801             it2=it+1;
2802         }
2803     }
2804   int ret=std::distance(_field_pm_pt.begin(),it2);
2805   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2806   return ret;
2807 }
2808
2809 /*!
2810  * 'dads' and 'locs' input parameters have the same number of elements
2811  * \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
2812  */
2813 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2814                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2815                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2816 {
2817   isPfl=false;
2818   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2819   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2820   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2821   const std::vector<std::string>& infos=getInfo();
2822   da->setInfoOnComponents(infos);
2823   da->setName("");
2824   if(type==ON_GAUSS_PT)
2825     {
2826       int offset=0;
2827       int nbOfArrs=dads.size();
2828       for(int i=0;i<nbOfArrs;i++)
2829         {
2830           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2831           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2832           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2833           MCAuto<DataArrayInt> di=DataArrayInt::New();
2834           di->alloc(nbOfElems,1);
2835           di->iota(offset);
2836           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2837           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2838           offset+=nbOfElems;
2839         }
2840     }
2841   arrOut=da;
2842   return ret.retn();
2843 }
2844
2845 /*!
2846  * 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.
2847  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2848  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2849  * The order of cells in the returned field is those imposed by the profile.
2850  * \param [in] mesh is the global mesh.
2851  */
2852 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2853                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2854                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2855                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2856 {
2857   if(da->isIota(mesh->getNumberOfCells()))
2858     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2859   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2860   m2->setName(mesh->getName().c_str());
2861   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2862   isPfl=true;
2863   return ret.retn();
2864 }
2865
2866 /*!
2867  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2868  */
2869 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2870                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2871                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2872 {
2873   if(da->isIota(mesh->getNumberOfNodes()))
2874     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2875   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2876   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2877   if(meshu)
2878     {
2879       if(meshu->getNodalConnectivity()==0)
2880         {
2881           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2882           int nb=da->getNbOfElems();
2883           const int *ptr=da->getConstPointer();
2884           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2885           meshuc->allocateCells(nb);
2886           for(int i=0;i<nb;i++)
2887             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2888           meshuc->finishInsertingCells();
2889           ret->setMesh(meshuc);
2890           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2891           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2892           disc->checkCoherencyBetween(meshuc,arrOut);
2893           return ret.retn();
2894         }
2895     }
2896   //
2897   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2898   isPfl=true;
2899   DataArrayInt *arr2=0;
2900   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2901   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2902   MCAuto<DataArrayInt> arr3(arr2);
2903   int nnodes=mesh2->getNumberOfNodes();
2904   if(nnodes==(int)da->getNbOfElems())
2905     {
2906       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2907       arrOut->renumberInPlace(da3->getConstPointer());
2908       mesh2->setName(mesh->getName().c_str());
2909       ret->setMesh(mesh2);
2910       return ret.retn();
2911     }
2912   else
2913     {
2914       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 !!!";
2915       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2916       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2917       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2918       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2919       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2920       throw INTERP_KERNEL::Exception(oss.str());
2921     }
2922   return 0;
2923 }
2924
2925 /*!
2926  * This method is the most light method of field retrieving.
2927  */
2928 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2929 {
2930   if(!pflIn)
2931     {
2932       pflOut=DataArrayInt::New();
2933       pflOut->alloc(nbOfElems,1);
2934       pflOut->iota(0);
2935     }
2936   else
2937     {
2938       pflOut=const_cast<DataArrayInt*>(pflIn);
2939       pflOut->incrRef();
2940     }
2941   MCAuto<DataArrayInt> safePfl(pflOut);
2942   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2943   const std::vector<std::string>& infos=getInfo();
2944   int nbOfComp=infos.size();
2945   for(int i=0;i<nbOfComp;i++)
2946     da->setInfoOnComponent(i,infos[i].c_str());
2947   safePfl->incrRef();
2948   return da.retn();
2949 }
2950
2951
2952 /// @cond INTERNAL
2953
2954 class MFFPMIter
2955 {
2956 public:
2957   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2958   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2959   virtual ~MFFPMIter() { }
2960   virtual void begin() = 0;
2961   virtual bool finished() const = 0;
2962   virtual void next() = 0;
2963   virtual int current() const = 0;
2964 };
2965
2966 class MFFPMIterSimple : public MFFPMIter
2967 {
2968 public:
2969   MFFPMIterSimple():_pos(0) { }
2970   void begin() { _pos=0; }
2971   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2972   void next() { _pos++; }
2973   int current() const { return _pos; }
2974 private:
2975   int _pos;
2976 };
2977
2978 class MFFPMIter2 : public MFFPMIter
2979 {
2980 public:
2981   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2982   void begin() { _it=_ids.begin(); }
2983   bool finished() const { return _it==_ids.end(); }
2984   void next() { _it++; }
2985   int current() const { return *_it; }
2986 private:
2987   std::vector<int> _ids;
2988   std::vector<int>::const_iterator _it;
2989 };
2990
2991 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
2992 {
2993   if(!entities)
2994     return new MFFPMIterSimple;
2995   else
2996     {
2997       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2998       if(entities2)
2999         {
3000           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
3001           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3002           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3003             {
3004               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
3005                 tmp.push_back((*it).second);
3006             }
3007           return new MFFPMIter2(tmp);
3008         }
3009       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
3010     }
3011 }
3012
3013 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
3014 {
3015   if(!entities)
3016     return true;
3017   else
3018     {
3019       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3020       if(entities2)
3021         {
3022           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3023           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3024             if((*it).first==ON_NODES)
3025               return true;
3026           return false;
3027         }
3028       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
3029     }
3030 }
3031
3032 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
3033 {
3034   std::size_t sz(cts.size());
3035   _ids.resize(sz);
3036   for(std::size_t i=0;i<sz;i++)
3037     {
3038       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
3039       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
3040         _ids[i]=(int)std::distance(typmai2,loc);
3041       else
3042         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
3043     }
3044 }
3045
3046 /// @endcond
3047
3048 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
3049     _father(fath)
3050 {
3051   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3052   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3053   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3054   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
3055   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
3056   for(iter0->begin();!iter0->finished();iter0->next())
3057     {
3058       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3059       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3060       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3061       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3062       if(nbProfile>0 || nbProfile2>0)
3063         {
3064           const PartDefinition *pd(0);
3065           if(mmu)
3066             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
3067           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
3068           if(nbProfile>0)
3069             _mesh_name=name0;
3070           else
3071             _mesh_name=name1;
3072         }
3073     }
3074   if(MFFPMIter::IsPresenceOfNode(entities))
3075     {
3076       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
3077       if(nbProfile>0)
3078         {
3079           const PartDefinition *pd(0);
3080           if(mmu)
3081             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
3082           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
3083           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
3084         }
3085     }
3086   if(!entities)
3087     return ;
3088   std::vector<int> dynGT(entities->getDynGTAvail());
3089   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
3090     {
3091       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
3092       if(nbPfl>0)
3093         {
3094           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
3095           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
3096         }
3097     }
3098 }
3099
3100 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
3101 {
3102   copyTinyInfoFrom(mesh);
3103 }
3104
3105 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3106 {
3107   if(id>=(int)_pfls.size())
3108     _pfls.resize(id+1);
3109   _pfls[id]=DataArrayInt::New();
3110   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
3111   _pfls[id]->setName(pflName);
3112   _pfls[id]->alloc(lgth,1);
3113   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
3114   _pfls[id]->applyLin(1,-1,0);//Converting into C format
3115 }
3116
3117 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
3118 {
3119   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3120   int sz;
3121   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
3122   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
3123   if(i>=(int)_pfls.size())
3124     _pfls.resize(i+1);
3125   _pfls[i]=DataArrayInt::New();
3126   _pfls[i]->alloc(sz,1);
3127   _pfls[i]->setName(pflCpp.c_str());
3128   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
3129   _pfls[i]->applyLin(1,-1,0);//Converting into C format
3130 }
3131
3132 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3133 {
3134   int nbOfPfls=_pfls.size();
3135   for(int i=0;i<nbOfPfls;i++)
3136     {
3137       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
3138       cpy->applyLin(1,1,0);
3139       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3140       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
3141       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
3142     }
3143   //
3144   int nbOfLocs=_locs.size();
3145   for(int i=0;i<nbOfLocs;i++)
3146     _locs[i]->writeLL(fid);
3147 }
3148
3149 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
3150 {
3151   std::vector<std::string> pfls=getPfls();
3152   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
3153     {
3154       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
3155       if(it2==pfls.end())
3156         {
3157           _pfls.push_back(*it);
3158         }
3159       else
3160         {
3161           int id=std::distance(pfls.begin(),it2);
3162           if(!(*it)->isEqual(*_pfls[id]))
3163             {
3164               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3165               throw INTERP_KERNEL::Exception(oss.str());
3166             }
3167         }
3168     }
3169   std::vector<std::string> locs=getLocs();
3170   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
3171     {
3172       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
3173       if(it2==locs.end())
3174         {
3175           _locs.push_back(*it);
3176         }
3177       else
3178         {
3179           int id=std::distance(locs.begin(),it2);
3180           if(!(*it)->isEqual(*_locs[id],eps))
3181             {
3182               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3183               throw INTERP_KERNEL::Exception(oss.str());
3184             }
3185         }
3186     }
3187 }
3188
3189 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
3190 {
3191   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
3192     getProfile((*it).c_str());
3193 }
3194
3195 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
3196 {
3197   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
3198     getLocalization((*it).c_str());
3199 }
3200
3201 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
3202 {
3203   std::vector<std::string> profiles=real.getPflsReallyUsed();
3204   int sz=profiles.size();
3205   _pfls.resize(sz);
3206   for(int i=0;i<sz;i++)
3207     loadProfileInFile(fid,i,profiles[i].c_str());
3208   //
3209   std::vector<std::string> locs=real.getLocsReallyUsed();
3210   sz=locs.size();
3211   _locs.resize(sz);
3212   for(int i=0;i<sz;i++)
3213     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
3214 }
3215
3216 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3217 {
3218   int nProfil=MEDnProfile(fid);
3219   for(int i=0;i<nProfil;i++)
3220     loadProfileInFile(fid,i);
3221   int sz=MEDnLocalization(fid);
3222   _locs.resize(sz);
3223   for(int i=0;i<sz;i++)
3224     {
3225       _locs[i]=MEDFileFieldLoc::New(fid,i,entities);
3226     }
3227 }
3228
3229 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
3230 {
3231   return new MEDFileFieldGlobs(fid);
3232 }
3233
3234 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
3235 {
3236   return new MEDFileFieldGlobs;
3237 }
3238
3239 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
3240 {
3241   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
3242 }
3243
3244 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
3245 {
3246   std::vector<const BigMemoryObject *> ret;
3247   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3248     ret.push_back((const DataArrayInt *)*it);
3249   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3250     ret.push_back((const MEDFileFieldLoc *)*it);
3251   return ret;
3252 }
3253
3254 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3255 {
3256   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3257   std::size_t i=0;
3258   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3259     {
3260       if((const DataArrayInt *)*it)
3261         ret->_pfls[i]=(*it)->deepCopy();
3262     }
3263   i=0;
3264   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3265     {
3266       if((const MEDFileFieldLoc*)*it)
3267         ret->_locs[i]=(*it)->deepCopy();
3268     }
3269   return ret.retn();
3270 }
3271
3272 /*!
3273  * \throw if a profile in \a pfls in not in \a this.
3274  * \throw if a localization in \a locs in not in \a this.
3275  * \sa MEDFileFieldGlobs::deepCpyPart
3276  */
3277 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3278 {
3279   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3280   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3281     {
3282       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3283       if(!pfl)
3284         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3285       pfl->incrRef();
3286       MCAuto<DataArrayInt> pfl2(pfl);
3287       ret->_pfls.push_back(pfl2);
3288     }
3289   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3290     {
3291       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3292       if(!loc)
3293         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3294       loc->incrRef();
3295       MCAuto<MEDFileFieldLoc> loc2(loc);
3296       ret->_locs.push_back(loc2);
3297     }
3298   ret->setFileName(getFileName());
3299   return ret.retn();
3300 }
3301
3302 /*!
3303  * \throw if a profile in \a pfls in not in \a this.
3304  * \throw if a localization in \a locs in not in \a this.
3305  * \sa MEDFileFieldGlobs::shallowCpyPart
3306  */
3307 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3308 {
3309   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3310   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3311     {
3312       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3313       if(!pfl)
3314         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3315       ret->_pfls.push_back(pfl->deepCopy());
3316     }
3317   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3318     {
3319       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3320       if(!loc)
3321         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3322       ret->_locs.push_back(loc->deepCopy());
3323     }
3324   ret->setFileName(getFileName());
3325   return ret.retn();
3326 }
3327
3328 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3329 {
3330 }
3331
3332 MEDFileFieldGlobs::MEDFileFieldGlobs()
3333 {
3334 }
3335
3336 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3337 {
3338 }
3339
3340 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3341 {
3342   oss << "Profiles :\n";
3343   std::size_t n=_pfls.size();
3344   for(std::size_t i=0;i<n;i++)
3345     {
3346       oss << "  - #" << i << " ";
3347       const DataArrayInt *pfl=_pfls[i];
3348       if(pfl)
3349         oss << "\"" << pfl->getName() << "\"\n";
3350       else
3351         oss << "EMPTY !\n";
3352     }
3353   n=_locs.size();
3354   oss << "Localizations :\n";
3355   for(std::size_t i=0;i<n;i++)
3356     {
3357       oss << "  - #" << i << " ";
3358       const MEDFileFieldLoc *loc=_locs[i];
3359       if(loc)
3360         loc->simpleRepr(oss);
3361       else
3362         oss<< "EMPTY !\n";
3363     }
3364 }
3365
3366 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3367 {
3368   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3369     {
3370       DataArrayInt *elt(*it);
3371       if(elt)
3372         {
3373           std::string name(elt->getName());
3374           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3375             {
3376               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3377                 {
3378                   elt->setName((*it2).second.c_str());
3379                   return;
3380                 }
3381             }
3382         }
3383     }
3384 }
3385
3386 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3387 {
3388   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3389     {
3390       MEDFileFieldLoc *elt(*it);
3391       if(elt)
3392         {
3393           std::string name(elt->getName());
3394           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3395             {
3396               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3397                 {
3398                   elt->setName((*it2).second.c_str());
3399                   return;
3400                 }
3401             }
3402         }
3403     }
3404 }
3405
3406 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3407 {
3408   if(locId<0 || locId>=(int)_locs.size())
3409     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3410   return _locs[locId]->getNbOfGaussPtPerCell();
3411 }
3412
3413 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3414 {
3415   return getLocalizationFromId(getLocalizationId(locName));
3416 }
3417
3418 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3419 {
3420   if(locId<0 || locId>=(int)_locs.size())
3421     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3422   return *_locs[locId];
3423 }
3424
3425 /// @cond INTERNAL
3426 namespace MEDCouplingImpl
3427 {
3428   class LocFinder
3429   {
3430   public:
3431     LocFinder(const std::string& loc):_loc(loc) { }
3432     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3433   private:
3434     const std::string &_loc;
3435   };
3436
3437   class PflFinder
3438   {
3439   public:
3440     PflFinder(const std::string& pfl):_pfl(pfl) { }
3441     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3442   private:
3443     const std::string& _pfl;
3444   };
3445 }
3446 /// @endcond
3447
3448 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3449 {
3450   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3451   if(it==_locs.end())
3452     {
3453       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3454       for(it=_locs.begin();it!=_locs.end();it++)
3455         oss << "\"" << (*it)->getName() << "\", ";
3456       throw INTERP_KERNEL::Exception(oss.str());
3457     }
3458   return std::distance(_locs.begin(),it);
3459 }
3460
3461 /*!
3462  * The returned value is never null.
3463  */
3464 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3465 {
3466   std::string pflNameCpp(pflName);
3467   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3468   if(it==_pfls.end())
3469     {
3470       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3471       for(it=_pfls.begin();it!=_pfls.end();it++)
3472         oss << "\"" << (*it)->getName() << "\", ";
3473       throw INTERP_KERNEL::Exception(oss.str());
3474     }
3475   return *it;
3476 }
3477
3478 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3479 {
3480   if(pflId<0 || pflId>=(int)_pfls.size())
3481     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3482   return _pfls[pflId];
3483 }
3484
3485 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3486 {
3487   if(locId<0 || locId>=(int)_locs.size())
3488     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3489   return *_locs[locId];
3490 }
3491
3492 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3493 {
3494   return getLocalizationFromId(getLocalizationId(locName));
3495 }
3496
3497 /*!
3498  * The returned value is never null.
3499  */
3500 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3501 {
3502   std::string pflNameCpp(pflName);
3503   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3504   if(it==_pfls.end())
3505     {
3506       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3507       for(it=_pfls.begin();it!=_pfls.end();it++)
3508         oss << "\"" << (*it)->getName() << "\", ";
3509       throw INTERP_KERNEL::Exception(oss.str());
3510     }
3511   return *it;
3512 }
3513
3514 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3515 {
3516   if(pflId<0 || pflId>=(int)_pfls.size())
3517     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3518   return _pfls[pflId];
3519 }
3520
3521 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3522 {
3523   std::vector< MCAuto<DataArrayInt> > newPfls;
3524   int i=0;
3525   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3526     {
3527       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3528         newPfls.push_back(*it);
3529     }
3530   _pfls=newPfls;
3531 }
3532
3533 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3534 {
3535   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3536   int i=0;
3537   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3538     {
3539       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3540         newLocs.push_back(*it);
3541     }
3542   _locs=newLocs;
3543 }
3544
3545 void MEDFileFieldGlobs::killStructureElementsInGlobs()
3546 {
3547   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3548   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3549     {
3550       if((*it).isNull())
3551         continue;
3552       if(!(*it)->isOnStructureElement())
3553         newLocs.push_back(*it);
3554     }
3555   _locs=newLocs;
3556 }
3557
3558 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3559 {
3560   int sz=_pfls.size();
3561   std::vector<std::string> ret(sz);
3562   for(int i=0;i<sz;i++)
3563     ret[i]=_pfls[i]->getName();
3564   return ret;
3565 }
3566
3567 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3568 {
3569   int sz=_locs.size();
3570   std::vector<std::string> ret(sz);
3571   for(int i=0;i<sz;i++)
3572     ret[i]=_locs[i]->getName();
3573   return ret;
3574 }
3575
3576 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3577 {
3578   std::vector<std::string> v=getPfls();
3579   std::string s(pflName);
3580   return std::find(v.begin(),v.end(),s)!=v.end();
3581 }
3582
3583 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3584 {
3585   std::vector<std::string> v=getLocs();
3586   std::string s(locName);
3587   return std::find(v.begin(),v.end(),s)!=v.end();
3588 }
3589
3590 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3591 {
3592   std::map<int,std::vector<int> > m;
3593   int i=0;
3594   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3595     {
3596       const DataArrayInt *tmp=(*it);
3597       if(tmp)
3598         {
3599           m[tmp->getHashCode()].push_back(i);
3600         }
3601     }
3602   std::vector< std::vector<int> > ret;
3603   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3604     {
3605       if((*it2).second.size()>1)
3606         {
3607           std::vector<int> ret0;
3608           bool equalityOrNot=false;
3609           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3610             {
3611               std::vector<int>::const_iterator it4=it3; it4++;
3612               for(;it4!=(*it2).second.end();it4++)
3613                 {
3614                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3615                     {
3616                       if(!equalityOrNot)
3617                         ret0.push_back(*it3);
3618                       ret0.push_back(*it4);
3619                       equalityOrNot=true;
3620                     }
3621                 }
3622             }
3623           if(!ret0.empty())
3624             ret.push_back(ret0);
3625         }
3626     }
3627   return ret;
3628 }
3629
3630 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3631 {
3632   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3633 }
3634
3635 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3636 {
3637   std::string name(pfl->getName());
3638   if(name.empty())
3639     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3640   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3641     if(name==(*it)->getName())
3642       {
3643         if(!pfl->isEqual(*(*it)))
3644           {
3645             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3646             throw INTERP_KERNEL::Exception(oss.str());
3647           }
3648       }
3649   pfl->incrRef();
3650   _pfls.push_back(pfl);
3651 }
3652
3653 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)
3654 {
3655   std::string name(locName);
3656   if(name.empty())
3657     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3658   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3659   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3660     if((*it)->isName(locName))
3661       {
3662         if(!(*it)->isEqual(*obj,1e-12))
3663           {
3664             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3665             throw INTERP_KERNEL::Exception(oss.str());
3666           }
3667       }
3668   _locs.push_back(obj);
3669 }
3670
3671 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3672 {
3673   std::vector<std::string> names=getPfls();
3674   return CreateNewNameNotIn("NewPfl_",names);
3675 }
3676
3677 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3678 {
3679   std::vector<std::string> names=getLocs();
3680   return CreateNewNameNotIn("NewLoc_",names);
3681 }
3682
3683 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3684 {
3685   for(std::size_t sz=0;sz<100000;sz++)
3686     {
3687       std::ostringstream tryName;
3688       tryName << prefix << sz;
3689       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3690         return tryName.str();
3691     }
3692   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3693 }
3694
3695 /*!
3696  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3697  *  \param [in] fname - the file name.
3698  */
3699 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3700 {
3701 }
3702
3703 /*!
3704  * Creates an empty MEDFileFieldGlobsReal.
3705  */
3706 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3707 {
3708 }
3709
3710 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3711 {
3712   return 0;
3713 }
3714
3715 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3716 {
3717   std::vector<const BigMemoryObject *> ret;
3718   ret.push_back((const MEDFileFieldGlobs *)_globals);
3719   return ret;
3720 }
3721
3722 /*!
3723  * Returns a string describing profiles and Gauss points held in \a this.
3724  *  \return std::string - the description string.
3725  */
3726 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3727 {
3728   const MEDFileFieldGlobs *glob=_globals;
3729   std::ostringstream oss2; oss2 << glob;
3730   std::string stars(oss2.str().length(),'*');
3731   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3732   if(glob)
3733     glob->simpleRepr(oss);
3734   else
3735     oss << "NO GLOBAL INFORMATION !\n";
3736 }
3737
3738 void MEDFileFieldGlobsReal::resetContent()
3739 {
3740   _globals=MEDFileFieldGlobs::New();
3741 }
3742
3743 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
3744 {
3745   contentNotNull()->killStructureElementsInGlobs();
3746 }
3747
3748 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3749 {
3750 }
3751
3752 /*!
3753  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3754  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3755  */
3756 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3757 {
3758   _globals=other._globals;
3759 }
3760
3761 /*!
3762  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3763  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3764  */
3765 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3766 {
3767   const MEDFileFieldGlobs *otherg(other._globals);
3768   if(!otherg)
3769     return ;
3770   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3771 }
3772
3773 /*!
3774  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3775  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3776  */
3777 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3778 {
3779   const MEDFileFieldGlobs *otherg(other._globals);
3780   if(!otherg)
3781     return ;
3782   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3783 }
3784
3785 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3786 {
3787   _globals=other._globals;
3788   if((const MEDFileFieldGlobs *)_globals)
3789     _globals=other._globals->deepCopy();
3790 }
3791
3792 /*!
3793  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3794  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3795  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3796  *         \a this and \a other MEDFileFieldGlobsReal.
3797  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3798  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3799  */
3800 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3801 {
3802   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3803   if(thisGlobals==otherGlobals)
3804     return ;
3805   if(!thisGlobals)
3806     {
3807       _globals=other._globals;
3808       return ;
3809     }
3810   _globals->appendGlobs(*other._globals,eps);
3811 }
3812
3813 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3814 {
3815   checkGlobsPflsPartCoherency();
3816   checkGlobsLocsPartCoherency();
3817 }
3818
3819 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3820 {
3821   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3822 }
3823
3824 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3825 {
3826   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3827 }
3828
3829 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3830 {
3831   contentNotNull()->loadProfileInFile(fid,id,pflName);
3832 }
3833
3834 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3835 {
3836   contentNotNull()->loadProfileInFile(fid,id);
3837 }
3838
3839 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3840 {
3841   contentNotNull()->loadGlobals(fid,*this);
3842 }
3843
3844 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3845 {
3846   contentNotNull()->loadAllGlobals(fid,entities);
3847 }
3848
3849 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3850 {
3851   contentNotNull()->writeGlobals(fid,opt);
3852 }
3853
3854 /*!
3855  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3856  * or getPflsReallyUsedMulti().
3857  *  \return std::vector<std::string> - a sequence of names of all profiles.
3858  */
3859 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3860 {
3861   return contentNotNull()->getPfls();
3862 }
3863
3864 /*!
3865  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3866  * or getLocsReallyUsedMulti().
3867  *  \return std::vector<std::string> - a sequence of names of all localizations.
3868  */
3869 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3870 {
3871   return contentNotNull()->getLocs();
3872 }
3873
3874 /*!
3875  * Checks if the profile with a given name exists.
3876  *  \param [in] pflName - the profile name of interest.
3877  *  \return bool - \c true if the profile named \a pflName exists.
3878  */
3879 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3880 {
3881   return contentNotNull()->existsPfl(pflName);
3882 }
3883
3884 /*!
3885  * Checks if the localization with a given name exists.
3886  *  \param [in] locName - the localization name of interest.
3887  *  \return bool - \c true if the localization named \a locName exists.
3888  */
3889 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3890 {
3891   return contentNotNull()->existsLoc(locName);
3892 }
3893
3894 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3895 {
3896   return contentNotNull()->createNewNameOfPfl();
3897 }
3898
3899 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3900 {
3901   return contentNotNull()->createNewNameOfLoc();
3902 }
3903
3904 /*!
3905  * Sets the name of a MED file.
3906  *  \param [inout] fileName - the file name.
3907  */
3908 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3909 {
3910   contentNotNull()->setFileName(fileName);
3911 }
3912
3913 /*!
3914  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3915  * in the same order.
3916  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3917  *          Each item of this sequence is a vector containing ids of equal profiles.
3918  */
3919 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3920 {
3921   return contentNotNull()->whichAreEqualProfiles();
3922 }
3923
3924 /*!
3925  * Finds equal localizations.
3926  *  \param [in] eps - a precision used to compare real values of the localizations.
3927  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3928  *          Each item of this sequence is a vector containing ids of equal localizations.
3929  */
3930 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3931 {
3932   return contentNotNull()->whichAreEqualLocs(eps);
3933 }
3934
3935 /*!
3936  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3937  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3938  *        this sequence is a pair whose 
3939  *        - the first item is a vector of profile names to replace by the second item,
3940  *        - the second item is a profile name to replace every profile name of the first item.
3941  */
3942 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3943 {
3944   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3945 }
3946
3947 /*!
3948  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3949  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3950  *        this sequence is a pair whose 
3951  *        - the first item is a vector of localization names to replace by the second item,
3952  *        - the second item is a localization name to replace every localization name of the first item.
3953  */
3954 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3955 {
3956   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3957 }
3958
3959 /*!
3960  * Replaces references to some profiles (a reference is a profile name) by references
3961  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3962  * them-selves accordingly. <br>
3963  * This method is a generalization of changePflName().
3964  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3965  *        this sequence is a pair whose 
3966  *        - the first item is a vector of profile names to replace by the second item,
3967  *        - the second item is a profile name to replace every profile of the first item.
3968  * \sa changePflsRefsNamesGen()
3969  * \sa changePflName()
3970  */
3971 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3972 {
3973   changePflsRefsNamesGen(mapOfModif);
3974   changePflsNamesInStruct(mapOfModif);
3975 }
3976
3977 /*!
3978  * Replaces references to some localizations (a reference is a localization name) by references
3979  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3980  * them-selves accordingly. <br>
3981  * This method is a generalization of changeLocName().
3982  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3983  *        this sequence is a pair whose 
3984  *        - the first item is a vector of localization names to replace by the second item,
3985  *        - the second item is a localization name to replace every localization of the first item.
3986  * \sa changeLocsRefsNamesGen()
3987  * \sa changeLocName()
3988  */
3989 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3990 {
3991   changeLocsRefsNamesGen(mapOfModif);
3992   changeLocsNamesInStruct(mapOfModif);
3993 }
3994
3995 /*!
3996  * Renames the profile having a given name and updates references to this profile.
3997  *  \param [in] oldName - the name of the profile to rename.
3998  *  \param [in] newName - a new name of the profile.
3999  * \sa changePflsNames().
4000  */
4001 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
4002 {
4003   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4004   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4005   mapOfModif[0]=p;
4006   changePflsNames(mapOfModif);
4007 }
4008
4009 /*!
4010  * Renames the localization having a given name and updates references to this localization.
4011  *  \param [in] oldName - the name of the localization to rename.
4012  *  \param [in] newName - a new name of the localization.
4013  * \sa changeLocsNames().
4014  */
4015 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
4016 {
4017   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4018   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4019   mapOfModif[0]=p;
4020   changeLocsNames(mapOfModif);
4021 }
4022
4023 /*!
4024  * Removes duplicated profiles. Returns a map used to update references to removed 
4025  * profiles via changePflsRefsNamesGen().
4026  * Equal profiles are found using whichAreEqualProfiles().
4027  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4028  *          a sequence describing the performed replacements of profiles. Each element of
4029  *          this sequence is a pair whose
4030  *          - the first item is a vector of profile names replaced by the second item,
4031  *          - the second item is a profile name replacing every profile of the first item.
4032  */
4033 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
4034 {
4035   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
4036   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4037   int i=0;
4038   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4039     {
4040       std::vector< std::string > tmp((*it).size());
4041       int j=0;
4042       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4043         tmp[j]=std::string(getProfileFromId(*it2)->getName());
4044       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4045       ret[i]=p;
4046       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4047       killProfileIds(tmp2);
4048     }
4049   changePflsRefsNamesGen(ret);
4050   return ret;
4051 }
4052
4053 /*!
4054  * Removes duplicated localizations. Returns a map used to update references to removed 
4055  * localizations via changeLocsRefsNamesGen().
4056  * Equal localizations are found using whichAreEqualLocs().
4057  *  \param [in] eps - a precision used to compare real values of the localizations.
4058  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4059  *          a sequence describing the performed replacements of localizations. Each element of
4060  *          this sequence is a pair whose
4061  *          - the first item is a vector of localization names replaced by the second item,
4062  *          - the second item is a localization name replacing every localization of the first item.
4063  */
4064 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
4065 {
4066   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
4067   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4068   int i=0;
4069   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4070     {
4071       std::vector< std::string > tmp((*it).size());
4072       int j=0;
4073       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4074         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
4075       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4076       ret[i]=p;
4077       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4078       killLocalizationIds(tmp2);
4079     }
4080   changeLocsRefsNamesGen(ret);
4081   return ret;
4082 }
4083
4084 /*!
4085  * Returns number of Gauss points per cell in a given localization.
4086  *  \param [in] locId - an id of the localization of interest.
4087  *  \return int - the number of the Gauss points per cell.
4088  */
4089 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
4090 {
4091   return contentNotNull()->getNbOfGaussPtPerCell(locId);
4092 }
4093
4094 /*!
4095  * Returns an id of a localization by its name.
4096  *  \param [in] loc - the localization name of interest.
4097  *  \return int - the id of the localization.
4098  *  \throw If there is no a localization named \a loc.
4099  */
4100 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
4101 {
4102   return contentNotNull()->getLocalizationId(loc);
4103 }
4104
4105 /*!
4106  * Returns the name of the MED file.
4107  *  \return const std::string&  - the MED file name.
4108  */
4109 std::string MEDFileFieldGlobsReal::getFileName() const
4110 {
4111   return contentNotNull()->getFileName();
4112 }
4113
4114 /*!
4115  * Returns a localization object by its name.
4116  *  \param [in] locName - the name of the localization of interest.
4117  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
4118  *  \throw If there is no a localization named \a locName.
4119  */
4120 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
4121 {
4122   return contentNotNull()->getLocalization(locName);
4123 }
4124
4125 /*!
4126  * Returns a localization object by its id.
4127  *  \param [in] locId - the id of the localization of interest.
4128  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
4129  *  \throw If there is no a localization with id \a locId.
4130  */
4131 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
4132 {
4133   return contentNotNull()->getLocalizationFromId(locId);
4134 }
4135
4136 /*!
4137  * Returns a profile array by its name.
4138  *  \param [in] pflName - the name of the profile of interest.
4139  *  \return const DataArrayInt * - the profile array having the name \a pflName.
4140  *  \throw If there is no a profile named \a pflName.
4141  */
4142 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
4143 {
4144   return contentNotNull()->getProfile(pflName);
4145 }
4146
4147 /*!
4148  * Returns a profile array by its id.
4149  *  \param [in] pflId - the id of the profile of interest.
4150  *  \return const DataArrayInt * - the profile array having the id \a pflId.
4151  *  \throw If there is no a profile with id \a pflId.
4152  */
4153 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
4154 {
4155   return contentNotNull()->getProfileFromId(pflId);
4156 }
4157
4158 /*!
4159  * Returns a localization object, apt for modification, by its id.
4160  *  \param [in] locId - the id of the localization of interest.
4161  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4162  *          having the id \a locId.
4163  *  \throw If there is no a localization with id \a locId.
4164  */
4165 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
4166 {
4167   return contentNotNull()->getLocalizationFromId(locId);
4168 }
4169
4170 /*!
4171  * Returns a localization object, apt for modification, by its name.
4172  *  \param [in] locName - the name of the localization of interest.
4173  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4174  *          having the name \a locName.
4175  *  \throw If there is no a localization named \a locName.
4176  */
4177 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
4178 {
4179   return contentNotNull()->getLocalization(locName);
4180 }
4181
4182 /*!
4183  * Returns a profile array, apt for modification, by its name.
4184  *  \param [in] pflName - the name of the profile of interest.
4185  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
4186  *  \throw If there is no a profile named \a pflName.
4187  */
4188 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
4189 {
4190   return contentNotNull()->getProfile(pflName);
4191 }
4192
4193 /*!
4194  * Returns a profile array, apt for modification, by its id.
4195  *  \param [in] pflId - the id of the profile of interest.
4196  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
4197  *  \throw If there is no a profile with id \a pflId.
4198  */
4199 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
4200 {
4201   return contentNotNull()->getProfileFromId(pflId);
4202 }
4203
4204 /*!
4205  * Removes profiles given by their ids. No data is updated to track this removal.
4206  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
4207  */
4208 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
4209 {
4210   contentNotNull()->killProfileIds(pflIds);
4211 }
4212
4213 /*!
4214  * Removes localizations given by their ids. No data is updated to track this removal.
4215  *  \param [in] locIds - a sequence of ids of the localizations to remove.
4216  */
4217 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
4218 {
4219   contentNotNull()->killLocalizationIds(locIds);
4220 }
4221
4222 /*!
4223  * Stores a profile array.
4224  *  \param [in] pfl - the profile array to store.
4225  *  \throw If the name of \a pfl is empty.
4226  *  \throw If a profile with the same name as that of \a pfl already exists but contains
4227  *         different ids.
4228  */
4229 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
4230 {
4231   contentNotNull()->appendProfile(pfl);
4232 }
4233
4234 /*!
4235  * Adds a new localization of Gauss points.
4236  *  \param [in] locName - the name of the new localization.
4237  *  \param [in] geoType - a geometrical type of the reference cell.
4238  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
4239  *         must be \c nbOfNodesPerCell * \c dimOfType.
4240  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
4241  *         must be  _wg_.size() * \c dimOfType.
4242  *  \param [in] w - the weights of Gauss points.
4243  *  \throw If \a locName is empty.
4244  *  \throw If a localization with the name \a locName already exists but is
4245  *         different form the new one.
4246  */
4247 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)
4248 {
4249   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
4250 }
4251
4252 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
4253 {
4254   MEDFileFieldGlobs *g(_globals);
4255   if(!g)
4256     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
4257   return g;
4258 }
4259
4260 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
4261 {
4262   const MEDFileFieldGlobs *g(_globals);
4263   if(!g)
4264     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4265   return g;
4266 }
4267
4268 //= MEDFileFieldNameScope
4269
4270 MEDFileFieldNameScope::MEDFileFieldNameScope()
4271 {
4272 }
4273
4274 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
4275 {
4276 }
4277
4278 /*!
4279  * Returns the name of \a this field.
4280  *  \return std::string - a string containing the field name.
4281  */
4282 std::string MEDFileFieldNameScope::getName() const
4283 {
4284   return _name;
4285 }
4286
4287 /*!
4288  * Sets name of \a this field
4289  *  \param [in] name - the new field name.
4290  */
4291 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4292 {
4293   _name=fieldName;
4294 }
4295
4296 std::string MEDFileFieldNameScope::getDtUnit() const
4297 {
4298   return _dt_unit;
4299 }
4300
4301 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4302 {
4303   _dt_unit=dtUnit;
4304 }
4305
4306 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4307 {
4308   _name=other._name;
4309   _dt_unit=other._dt_unit;
4310 }
4311
4312 //= MEDFileAnyTypeField1TSWithoutSDA
4313
4314 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4315 {
4316   _field_per_mesh.resize(other._field_per_mesh.size());
4317   std::size_t i=0;
4318   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4319     {
4320       if((const MEDFileFieldPerMesh *)*it)
4321         _field_per_mesh[i]=(*it)->deepCopy(this);
4322     }
4323 }
4324
4325 void MEDFileAnyTypeField1TSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
4326 {
4327   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4328     if((*it).isNotNull())
4329       {
4330         visitor.newMeshEntry(*it);
4331         (*it)->accept(visitor);
4332         visitor.endMeshEntry(*it);
4333       }
4334 }
4335
4336 /*!
4337  * Prints a string describing \a this field into a stream. This string is outputted 
4338  * by \c print Python command.
4339  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4340  *  \param [in,out] oss - the out stream.
4341  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4342  *          info id printed, else, not.
4343  */
4344 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4345 {
4346   std::string startOfLine(bkOffset,' ');
4347   oss << startOfLine << "Field ";
4348   if(bkOffset==0)
4349     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4350   oss << "on one time Step ";
4351   if(f1tsId>=0)
4352     oss << "(" << f1tsId << ") ";
4353   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4354   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4355   const DataArray *arr=getUndergroundDataArray();
4356   if(arr)
4357     {
4358       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4359       if(f1tsId<0)
4360         {
4361           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4362           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4363             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4364         }
4365       if(arr->isAllocated())
4366         {
4367           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4368         }
4369       else
4370         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4371     }
4372   else
4373     {
4374       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4375     }
4376   oss << startOfLine << "----------------------" << std::endl;
4377   if(!_field_per_mesh.empty())
4378     {
4379       int i=0;
4380       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4381         {
4382           const MEDFileFieldPerMesh *cur=(*it2);
4383           if(cur)
4384             cur->simpleRepr(bkOffset,oss,i);
4385           else
4386             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4387         }
4388     }
4389   else
4390     {
4391       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4392     }
4393   oss << startOfLine << "----------------------" << std::endl;
4394 }
4395
4396 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4397 {
4398   const DataArray *arr(getUndergroundDataArray());
4399   if(!arr)
4400     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4401   int nbOfCompo=arr->getNumberOfComponents();
4402   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4403   for(int i=0;i<nbOfCompo;i++)
4404     {
4405       ret[i]=deepCopy();
4406       std::vector<int> v(1,i);
4407       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4408       ret[i]->setArray(arr2);
4409     }
4410   return ret;
4411 }
4412
4413 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)
4414 {
4415 }
4416
4417 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4418 {
4419 }
4420
4421 /*!
4422  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4423  * empty. Returns -1 if this in on nodes.
4424  *  \return int - the dimension of \a this.
4425  */
4426 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4427 {
4428   int ret=-2;
4429   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4430     (*it)->getDimension(ret);
4431   return ret;
4432 }
4433
4434 /*!
4435  * Returns the mesh name.
4436  *  \return std::string - a string holding the mesh name.
4437  *  \throw If \c _field_per_mesh.empty()
4438  */
4439 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
4440 {
4441   if(_field_per_mesh.empty())
4442     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
4443   return _field_per_mesh[0]->getMeshName();
4444 }
4445
4446 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
4447 {
4448   std::string oldName(getMeshName());
4449   std::vector< std::pair<std::string,std::string> > v(1);
4450   v[0].first=oldName; v[0].second=newMeshName;
4451   changeMeshNames(v);
4452 }
4453
4454 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4455 {
4456   bool ret=false;
4457   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4458     {
4459       MEDFileFieldPerMesh *cur(*it);
4460       if(cur)
4461         ret=cur->changeMeshNames(modifTab) || ret;
4462     }
4463   return ret;
4464 }
4465
4466 /*!
4467  * Returns the number of iteration of the state of underlying mesh.
4468  *  \return int - the iteration number.
4469  *  \throw If \c _field_per_mesh.empty()
4470  */
4471 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4472 {
4473   if(_field_per_mesh.empty())
4474     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4475   return _field_per_mesh[0]->getMeshIteration();
4476 }
4477
4478 /*!
4479  * Returns the order number of iteration of the state of underlying mesh.
4480  *  \return int - the order number.
4481  *  \throw If \c _field_per_mesh.empty()
4482  */
4483 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4484 {
4485   if(_field_per_mesh.empty())
4486     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4487   return _field_per_mesh[0]->getMeshOrder();
4488 }
4489
4490 /*!
4491  * Checks if \a this field is tagged by a given iteration number and a given
4492  * iteration order number.
4493  *  \param [in] iteration - the iteration number of interest.
4494  *  \param [in] order - the iteration order number of interest.
4495  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4496  *          \a this->getOrder() == \a order.
4497  */
4498 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4499 {
4500   return iteration==_iteration && order==_order;
4501 }
4502
4503 /*!
4504  * Returns number of iteration and order number of iteration when
4505  * \a this field has been calculated.
4506  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4507  *          order number.
4508  */
4509 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4510 {
4511   std::pair<int,int> p;
4512   fillIteration(p);
4513   return p;
4514 }
4515
4516 /*!
4517  * Returns number of iteration and order number of iteration when
4518  * \a this field has been calculated.
4519  *  \param [in,out] p - a pair returning the iteration number and the iteration
4520  *          order number.
4521  */
4522 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4523 {
4524   p.first=_iteration;
4525   p.second=_order;
4526 }
4527
4528 /*!
4529  * Returns all types of spatial discretization of \a this field.
4530  *  \param [in,out] types - a sequence of types of \a this field.
4531  */
4532 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4533 {
4534   std::set<TypeOfField> types2;
4535   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4536     {
4537       (*it)->fillTypesOfFieldAvailable(types2);
4538     }
4539   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4540   std::copy(types2.begin(),types2.end(),bi);
4541 }
4542
4543 /*!
4544  * Returns all types of spatial discretization of \a this field.
4545  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4546  *          of \a this field.
4547  */
4548 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4549 {
4550   std::vector<TypeOfField> ret;
4551   fillTypesOfFieldAvailable(ret);
4552   return ret;
4553 }
4554
4555 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4556 {
4557   std::vector<std::string> ret;
4558   std::set<std::string> ret2;
4559   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4560     {
4561       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4562       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4563         if(ret2.find(*it2)==ret2.end())
4564           {
4565             ret.push_back(*it2);
4566             ret2.insert(*it2);
4567           }
4568     }
4569   return ret;
4570 }
4571
4572 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4573 {
4574   std::vector<std::string> ret;
4575   std::set<std::string> ret2;
4576   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4577     {
4578       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4579       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4580         if(ret2.find(*it2)==ret2.end())
4581           {
4582             ret.push_back(*it2);
4583             ret2.insert(*it2);
4584           }
4585     }
4586   return ret;
4587 }
4588
4589 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4590 {
4591   std::vector<std::string> ret;
4592   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4593     {
4594       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4595       ret.insert(ret.end(),tmp.begin(),tmp.end());
4596     }
4597   return ret;
4598 }
4599
4600 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4601 {
4602   std::vector<std::string> ret;
4603   std::set<std::string> ret2;
4604   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4605     {
4606       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4607       ret.insert(ret.end(),tmp.begin(),tmp.end());
4608     }
4609   return ret;
4610 }
4611
4612 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4613 {
4614   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4615     (*it)->changePflsRefsNamesGen(mapOfModif);
4616 }
4617
4618 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4619 {
4620   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4621     (*it)->changeLocsRefsNamesGen(mapOfModif);
4622 }
4623
4624 /*!
4625  * Returns all attributes of parts of \a this field lying on a given mesh.
4626  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4627  * item of every of returned sequences refers to the _i_-th part of \a this field.
4628  * Thus all sequences returned by this method are of the same length equal to number
4629  * of different types of supporting entities.<br>
4630  * A field part can include sub-parts with several different spatial discretizations,
4631  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4632  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4633  * of a nested sequence corresponds to a type of spatial discretization.<br>
4634  * This method allows for iteration over MEDFile DataStructure without any overhead.
4635  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4636  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4637  *          not checked if \a mname == \c NULL).
4638  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4639  *          a field part is returned. 
4640  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4641  *          This sequence is of the same length as \a types. 
4642  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4643  *          discretization. A profile name can be empty.
4644  *          Length of this and of nested sequences is the same as that of \a typesF.
4645  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4646  *          discretization. A localization name can be empty.
4647  *          Length of this and of nested sequences is the same as that of \a typesF.
4648  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4649  *          of ids of tuples within the data array, per each type of spatial
4650  *          discretization within one mesh entity type. 
4651  *          Length of this and of nested sequences is the same as that of \a typesF.
4652  *  \throw If no field is lying on \a mname.
4653  */
4654 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
4655 {
4656   int meshId=0;
4657   if(!mname.empty())
4658     meshId=getMeshIdFromMeshName(mname);
4659   else
4660     if(_field_per_mesh.empty())
4661       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4662   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4663 }
4664
4665 /*!
4666  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4667  * maximal absolute dimension and values returned via the out parameter \a levs are 
4668  * dimensions relative to the maximal absolute dimension. <br>
4669  * This method is designed for MEDFileField1TS instances that have a discretization
4670  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4671  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4672  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4673  * Only these 3 discretizations will be taken into account here. If \a this is
4674  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4675  * This method is useful to make the link between the dimension of the underlying mesh
4676  * and the levels of \a this, because it is possible that the highest dimension of \a this
4677  * field is not equal to the dimension of the underlying mesh.
4678  * 
4679  * Let's consider the following case:
4680  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4681  * TETRA4, HEXA8, TRI3 and SEG2.
4682  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4683  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4684  *
4685  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4686  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4687  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4688  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4689  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4690  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4691  * For example<br>
4692  * to retrieve the highest level of
4693  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4694  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4695  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4696  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4697  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4698  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4699  *          not checked if \a mname == \c NULL).
4700  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4701  *          absolute one. They are in decreasing order. This sequence is cleared before
4702  *          filling it in.
4703  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4704  *  \throw If no field is lying on \a mname.
4705  */
4706 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4707 {
4708   levs.clear();
4709   int meshId=getMeshIdFromMeshName(mname);
4710   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4711   std::vector< std::vector<TypeOfField> > typesF;
4712   std::vector< std::vector<std::string> > pfls, locs;
4713   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4714   if(types.empty())
4715     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4716   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4717   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4718     return -1;
4719   st.erase(INTERP_KERNEL::NORM_ERROR);
4720   std::set<int> ret1;
4721   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4722     {
4723       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4724       ret1.insert((int)cm.getDimension());
4725     }
4726   int ret=*std::max_element(ret1.begin(),ret1.end());
4727   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4728   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4729   return ret;
4730 }
4731
4732 void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic()
4733 {
4734   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it<_field_per_mesh.end();it++)
4735     if((*it).isNotNull())
4736       (*it)->convertMedBallIntoClassic();
4737 }
4738
4739 void MEDFileAnyTypeField1TSWithoutSDA::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
4740 {
4741   if(!pfl)
4742     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : null pfl !");
4743   std::string name(pfl->getName());
4744   pfl->checkAllocated();
4745   if(pfl->getNumberOfComponents()!=1)
4746     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : non mono compo array !");
4747   if(name.empty())
4748     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : empty pfl name !");
4749   if(_field_per_mesh.size()!=1)
4750     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single mesh supported !");
4751   MCAuto<MEDFileFieldPerMesh> fpm(_field_per_mesh[0]);
4752   if(fpm.isNull())
4753     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single not null mesh supported !");
4754   MEDFileFieldPerMeshPerTypePerDisc *disc(fpm->getLeafGivenTypeAndLocId(ct,0));
4755   if(disc->getType()!=tof)
4756     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : error !");
4757   int s(disc->getStart()),e(disc->getEnd()),nt(pfl->getNumberOfTuples());
4758   DataArray *arr(getUndergroundDataArray());
4759   int nt2(arr->getNumberOfTuples()),delta((e-s)-nt);
4760   if(delta<0)
4761     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : internal error !");
4762   MCAuto<DataArray> arr0(arr->selectByTupleIdSafeSlice(0,s,1)),arr1(arr->selectByTupleIdSafeSlice(s,e,1)),arr2(arr->selectByTupleIdSafeSlice(e,nt2,1));
4763   MCAuto<DataArray> arr11(arr1->selectByTupleIdSafe(pfl->begin(),pfl->end()));
4764   MCAuto<DataArray> arrOut(arr->buildNewEmptyInstance());
4765   arrOut->alloc(nt2-delta,arr->getNumberOfComponents());
4766   arrOut->copyStringInfoFrom(*arr);
4767   arrOut->setContigPartOfSelectedValuesSlice(0,arr0,0,s,1);
4768   arrOut->setContigPartOfSelectedValuesSlice(s,arr11,0,nt,1);
4769   arrOut->setContigPartOfSelectedValuesSlice(e-delta,arr2,0,nt2-e,1);
4770   setArray(arrOut);
4771   disc->setEnd(e-delta);
4772   disc->setProfile(name);
4773 }
4774
4775 /*!
4776  * \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.
4777  * \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.
4778  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4779  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4780  */
4781 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4782 {
4783   int mid=getMeshIdFromMeshName(mName);
4784   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4785 }
4786
4787 /*!
4788  * \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.
4789  * \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.
4790  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4791  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4792  */
4793 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4794 {
4795   int mid=getMeshIdFromMeshName(mName);
4796   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4797 }
4798
4799 /*!
4800  * \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.
4801  */
4802 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4803 {
4804   if(_field_per_mesh.empty())
4805     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4806   if(mName.empty())
4807     return 0;
4808   std::string mName2(mName);
4809   int ret=0;
4810   std::vector<std::string> msg;
4811   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4812     if(mName2==(*it)->getMeshName())
4813       return ret;
4814     else
4815       msg.push_back((*it)->getMeshName());
4816   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4817   oss << "Possible meshes are : ";
4818   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4819     oss << "\"" << (*it2) << "\" ";
4820   throw INTERP_KERNEL::Exception(oss.str());
4821 }
4822
4823 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4824 {
4825   if(!mesh)
4826     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4827   std::string tmp(mesh->getName());
4828   if(tmp.empty())
4829     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4830   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4831   int i=0;
4832   for(;it!=_field_per_mesh.end();it++,i++)
4833     {
4834       if((*it)->getMeshName()==tmp)
4835         return i;
4836     }
4837   int sz=_field_per_mesh.size();
4838   _field_per_mesh.resize(sz+1);
4839   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4840   return sz;
4841 }
4842
4843 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4844                                                                    MEDFileFieldGlobsReal& glob)
4845 {
4846   bool ret=false;
4847   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4848     {
4849       MEDFileFieldPerMesh *fpm(*it);
4850       if(fpm)
4851         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4852     }
4853   return ret;
4854 }
4855
4856 /*!
4857  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4858  * splitting that leads to single spatial discretization of this.
4859  *
4860  * \sa splitMultiDiscrPerGeoTypes
4861  */
4862 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4863 {
4864   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4865   std::vector< std::vector<TypeOfField> > typesF;
4866   std::vector< std::vector<std::string> > pfls,locs;
4867   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4868   std::set<TypeOfField> allEnt;
4869   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4870     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4871       allEnt.insert(*it2);
4872   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4873   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4874   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4875     {
4876       std::vector< std::pair<int,int> > its;
4877       ret[i]=shallowCpy();
4878       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4879       ret[i]->updateData(newLgth,its);
4880     }
4881   return ret;
4882 }
4883
4884 /*!
4885  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4886  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4887  *
4888  * \sa splitDiscretizations
4889  */
4890 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4891 {
4892   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4893   std::vector< std::vector<TypeOfField> > typesF;
4894   std::vector< std::vector<std::string> > pfls,locs;
4895   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4896   std::set<TypeOfField> allEnt;
4897   std::size_t nbOfMDPGT(0),ii(0);
4898   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4899     {
4900       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4901       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4902         allEnt.insert(*it2);
4903     }
4904   if(allEnt.size()!=1)
4905     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4906   if(nbOfMDPGT==0)
4907     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4908   if(nbOfMDPGT==1)
4909     {
4910       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4911       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4912       return ret0;
4913     }
4914   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4915   for(std::size_t i=0;i<nbOfMDPGT;i++)
4916     {
4917       std::vector< std::pair<int,int> > its;
4918       ret[i]=shallowCpy();
4919       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4920       ret[i]->updateData(newLgth,its);
4921     }
4922   return ret;
4923 }
4924
4925 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4926 {
4927   int globalCounter(0);
4928   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4929     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4930   return globalCounter;
4931 }
4932
4933 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4934 {
4935   int globalCounter(0);
4936   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4937     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4938   return globalCounter;
4939 }
4940
4941 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4942 {
4943   if(_nb_of_tuples_to_be_allocated>=0)
4944     {
4945       _nb_of_tuples_to_be_allocated=newLgth;
4946       const DataArray *oldArr(getUndergroundDataArray());
4947       if(oldArr)
4948         {
4949           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4950           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4951           setArray(newArr);
4952           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4953         }
4954       return ;
4955     }
4956   if(_nb_of_tuples_to_be_allocated==-1)
4957     return ;
4958   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4959     {
4960       const DataArray *oldArr(getUndergroundDataArray());
4961       if(!oldArr || !oldArr->isAllocated())
4962         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4963       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4964       newArr->alloc(newLgth,getNumberOfComponents());
4965       if(oldArr)
4966         newArr->copyStringInfoFrom(*oldArr);
4967       int pos=0;
4968       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4969         {
4970           if((*it).second<(*it).first)
4971             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4972           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4973           pos+=(*it).second-(*it).first;
4974         }
4975       setArray(newArr);
4976       return ;
4977     }
4978   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4979 }
4980
4981 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4982 {
4983   if(_field_per_mesh.empty())
4984     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4985   if(_field_per_mesh.size()>1)
4986     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4987   _field_per_mesh[0]->copyOptionsFrom(opts);
4988   _field_per_mesh[0]->writeLL(fid,nasc);
4989 }
4990
4991 /*!
4992  * 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.
4993  * If false is returned the memory allocation is not required.
4994  */
4995 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4996 {
4997   if(_nb_of_tuples_to_be_allocated>=0)
4998     {
4999       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
5000       _nb_of_tuples_to_be_allocated=-2;
5001       return true;
5002     }
5003   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
5004     return false;
5005   if(_nb_of_tuples_to_be_allocated==-1)
5006     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
5007   if(_nb_of_tuples_to_be_allocated<-3)
5008     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5009   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5010 }
5011
5012 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5013 {
5014   med_int numdt,numit;
5015   med_float dt;
5016   med_int nmesh;
5017   med_bool localMesh;
5018   med_int meshnumdt,meshnumit;
5019   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5020   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
5021   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
5022   if(_iteration!=numdt || _order!=numit)
5023     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
5024   _field_per_mesh.resize(nmesh);
5025   //
5026   MEDFileMesh *mm(0);
5027   if(ms)
5028     {
5029       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
5030       mm=ms->getMeshWithName(meshNameCpp);
5031     }
5032   //
5033   for(int i=0;i<nmesh;i++)
5034     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
5035   _nb_of_tuples_to_be_allocated=0;
5036   for(int i=0;i<nmesh;i++)
5037     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
5038 }
5039
5040 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
5041 {
5042   allocIfNecessaryTheArrayToReceiveDataFromFile();
5043   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5044     (*it)->loadBigArraysRecursively(fid,nasc);
5045 }
5046
5047 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
5048 {
5049   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
5050     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5051       (*it)->loadBigArraysRecursively(fid,nasc);
5052 }
5053
5054 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5055 {
5056   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
5057   loadBigArraysRecursively(fid,nasc);
5058 }
5059
5060 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
5061 {
5062   DataArray *thisArr(getUndergroundDataArray());
5063   if(thisArr && thisArr->isAllocated())
5064     {
5065       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
5066       thisArr->desallocate();
5067     }
5068 }
5069
5070 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
5071 {
5072   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
5073 }
5074
5075 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
5076 {
5077   std::vector<const BigMemoryObject *> ret;
5078   if(getUndergroundDataArray())
5079     ret.push_back(getUndergroundDataArray());
5080   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5081     ret.push_back((const MEDFileFieldPerMesh *)*it);
5082   return ret;
5083 }
5084
5085 /*!
5086  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
5087  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
5088  * "Sort By Type"), if not, an exception is thrown. 
5089  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
5090  *  \param [in] arr - the array of values.
5091  *  \param [in,out] glob - the global data where profiles and localization present in
5092  *          \a field, if any, are added.
5093  *  \throw If the name of \a field is empty.
5094  *  \throw If the data array of \a field is not set.
5095  *  \throw If \a this->_arr is already allocated but has different number of components
5096  *         than \a field.
5097  *  \throw If the underlying mesh of \a field has no name.
5098  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
5099  */
5100 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5101 {
5102   const MEDCouplingMesh *mesh=field->getMesh();
5103   //
5104   TypeOfField type=field->getTypeOfField();
5105   std::vector<DataArrayInt *> dummy;
5106   int start=copyTinyInfoFrom(field,arr);
5107   int pos=addNewEntryIfNecessary(mesh);
5108   if(type!=ON_NODES)
5109     {
5110       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
5111       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
5112     }
5113   else
5114     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
5115 }
5116
5117 /*!
5118  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
5119  * of a given mesh are used as the support of the given field (a real support is not used). 
5120  * Elements of the given mesh must be sorted suitable for writing to MED file. 
5121  * Order of underlying mesh entities of the given field specified by \a profile parameter
5122  * is not prescribed; this method permutes field values to have them sorted by element
5123  * type as required for writing to MED file. A new profile is added only if no equal
5124  * profile is missing. 
5125  *  \param [in] field - the field to add to \a this. The field double values are ignored.
5126  *  \param [in] arrOfVals - the values of the field \a field used.
5127  *  \param [in] mesh - the supporting mesh of \a field.
5128  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
5129  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
5130  *  \param [in,out] glob - the global data where profiles and localization present in
5131  *          \a field, if any, are added.
5132  *  \throw If either \a field or \a mesh or \a profile has an empty name.
5133  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5134  *  \throw If the data array of \a field is not set.
5135  *  \throw If \a this->_arr is already allocated but has different number of components
5136  *         than \a field.
5137  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5138  *  \sa setFieldNoProfileSBT()
5139  */
5140 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5141 {
5142   if(!field)
5143     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
5144   if(!arrOfVals || !arrOfVals->isAllocated())
5145     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
5146   TypeOfField type=field->getTypeOfField();
5147   std::vector<DataArrayInt *> idsInPflPerType;
5148   std::vector<DataArrayInt *> idsPerType;
5149   std::vector<int> code,code2;
5150   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5151   if(type!=ON_NODES)
5152     {
5153       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
5154       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
5155       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
5156       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
5157       // start of check
5158       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
5159       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
5160       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5161         {
5162           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5163           throw INTERP_KERNEL::Exception(oss.str());
5164         }
5165       // end of check
5166       int start=copyTinyInfoFrom(field,arrOfVals);
5167       code2=m->getDistributionOfTypes();
5168       //
5169       int pos=addNewEntryIfNecessary(m);
5170       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
5171     }
5172   else
5173     {
5174       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
5175         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
5176       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
5177       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
5178       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
5179       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5180         {
5181           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5182           throw INTERP_KERNEL::Exception(oss.str());
5183         }
5184       int start=copyTinyInfoFrom(field,arrOfVals);
5185       int pos=addNewEntryIfNecessary(m);
5186       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
5187     }
5188 }
5189
5190 /*!
5191  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
5192  */
5193 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
5194 {
5195   if(_nb_of_tuples_to_be_allocated>=0)
5196     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 !");
5197   DataArray *arr(getOrCreateAndGetArray());
5198   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
5199   _nb_of_tuples_to_be_allocated=-3;
5200 }
5201
5202 /*!
5203  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
5204  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
5205  * larger by the size of \a field. Returns an id of the first not filled
5206  * tuple of \a this->_arr.
5207  *  \param [in] field - the field to copy the info on components and the name from.
5208  *  \return int - the id of first not initialized tuple of \a this->_arr.
5209  *  \throw If the name of \a field is empty.
5210  *  \throw If the data array of \a field is not set.
5211  *  \throw If \a this->_arr is already allocated but has different number of components
5212  *         than \a field.
5213  */
5214 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5215 {
5216   if(!field)
5217     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
5218   std::string name(field->getName());
5219   setName(name.c_str());
5220   setDtUnit(field->getTimeUnit());
5221   if(name.empty())
5222     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
5223   if(!arr)
5224     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
5225   if(!arr->isAllocated())
5226     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
5227   _dt=field->getTime(_iteration,_order);
5228   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
5229   if(!getOrCreateAndGetArray()->isAllocated())
5230     {
5231       allocNotFromFile(arr->getNumberOfTuples());
5232       return 0;
5233     }
5234   else
5235     {
5236       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
5237       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
5238       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
5239       _nb_of_tuples_to_be_allocated=-3;
5240       return oldNbOfTuples;
5241     }
5242 }
5243
5244 /*!
5245  * Returns number of components in \a this field
5246  *  \return int - the number of components.
5247  */
5248 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
5249 {
5250   return getOrCreateAndGetArray()->getNumberOfComponents();
5251 }
5252
5253 /*!
5254  * Change info on components in \a this.
5255  * \throw If size of \a infos is not equal to the number of components already in \a this.
5256  */
5257 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
5258 {
5259   DataArray *arr=getOrCreateAndGetArray();
5260   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
5261 }
5262
5263 /*!
5264  * Returns info on components of \a this field.
5265  *  \return const std::vector<std::string>& - a sequence of strings each being an
5266  *          information on _i_-th component.
5267  */
5268 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
5269 {
5270   const DataArray *arr=getOrCreateAndGetArray();
5271   return arr->getInfoOnComponents();
5272 }
5273
5274 /*!
5275  * Returns a mutable info on components of \a this field.
5276  *  \return std::vector<std::string>& - a sequence of strings each being an
5277  *          information on _i_-th component.
5278  */
5279 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
5280 {
5281   DataArray *arr=getOrCreateAndGetArray();
5282   return arr->getInfoOnComponents();
5283 }
5284
5285 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
5286 {
5287   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5288     {
5289       const MEDFileFieldPerMesh *fpm(*it);
5290       if(!fpm)
5291         continue;
5292       if(fpm->presenceOfMultiDiscPerGeoType())
5293         return true;
5294     }
5295   return false;
5296 }
5297
5298 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
5299 {
5300   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5301     if((*it).isNotNull())
5302       if((*it)->presenceOfStructureElements())
5303         return true;
5304   return false;
5305 }
5306
5307 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
5308 {
5309   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5310     if((*it).isNotNull())
5311       if(!(*it)->onlyStructureElements())
5312         return false;
5313   return true;
5314 }
5315
5316 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
5317 {
5318   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5319     if((*it).isNotNull())
5320       (*it)->killStructureElements();
5321 }
5322
5323 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
5324 {
5325   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5326     if((*it).isNotNull())
5327       (*it)->keepOnlyStructureElements();
5328 }
5329
5330 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName)
5331 {
5332   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5333     if((*it).isNotNull())
5334       (*it)->keepOnlyOnSE(seName);
5335 }
5336
5337 void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
5338 {
5339   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5340     if((*it).isNotNull())
5341       (*it)->getMeshSENames(ps);
5342 }
5343
5344 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5345 {
5346   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 !";
5347   if(_field_per_mesh.empty())
5348     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
5349   if(_field_per_mesh.size()>1)
5350     throw INTERP_KERNEL::Exception(MSG0);
5351   if(_field_per_mesh[0].isNull())
5352     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
5353   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
5354   std::set<TypeOfField> types;
5355   pm->fillTypesOfFieldAvailable(types);
5356   if(types.size()!=1)
5357     throw INTERP_KERNEL::Exception(MSG0);
5358   TypeOfField type(*types.begin());
5359   int meshDimRelToMax(0);
5360   if(type==ON_NODES)
5361     meshDimRelToMax=0;
5362   else
5363     {
5364       int myDim(std::numeric_limits<int>::max());
5365       bool isUnique(pm->isUniqueLevel(myDim));
5366       if(!isUnique)
5367         throw INTERP_KERNEL::Exception(MSG0);
5368       meshDimRelToMax=myDim-mesh->getMeshDimension();
5369       if(meshDimRelToMax>0)
5370         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5371     }
5372   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5373 }
5374
5375 /*!
5376  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5377  *  \param [in] type - a spatial discretization of the new field.
5378  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5379  *  \param [in] mName - a name of the supporting mesh.
5380  *  \param [in] renumPol - specifies how to permute values of the result field according to
5381  *          the optional numbers of cells and nodes, if any. The valid values are
5382  *          - 0 - do not permute.
5383  *          - 1 - permute cells.
5384  *          - 2 - permute nodes.
5385  *          - 3 - permute cells and nodes.
5386  *
5387  *  \param [in] glob - the global data storing profiles and localization.
5388  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5389  *          caller is to delete this field using decrRef() as it is no more needed. 
5390  *  \throw If the MED file is not readable.
5391  *  \throw If there is no mesh named \a mName in the MED file.
5392  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5393  *  \throw If no field of \a this is lying on the mesh \a mName.
5394  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5395  */
5396 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5397 {
5398   MCAuto<MEDFileMesh> mm;
5399   if(mName.empty())
5400     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5401   else
5402     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5403   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5404 }
5405
5406 /*!
5407  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5408  *  \param [in] type - a spatial discretization of the new field.
5409  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5410  *  \param [in] renumPol - specifies how to permute values of the result field according to
5411  *          the optional numbers of cells and nodes, if any. The valid values are
5412  *          - 0 - do not permute.
5413  *          - 1 - permute cells.
5414  *          - 2 - permute nodes.
5415  *          - 3 - permute cells and nodes.
5416  *
5417  *  \param [in] glob - the global data storing profiles and localization.
5418  *  \param [in] mesh - the supporting mesh.
5419  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5420  *          caller is to delete this field using decrRef() as it is no more needed. 
5421  *  \throw If the MED file is not readable.
5422  *  \throw If no field of \a this is lying on \a mesh.
5423  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5424  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5425  */
5426 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5427 {
5428   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5429   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5430   if(meshDimRelToMax==1)
5431     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5432   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5433 }
5434
5435 /*!
5436  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5437  * given mesh. 
5438  *  \param [in] type - a spatial discretization of the new field.
5439  *  \param [in] mName - a name of the supporting mesh.
5440  *  \param [in] renumPol - specifies how to permute values of the result field according to
5441  *          the optional numbers of cells and nodes, if any. The valid values are
5442  *          - 0 - do not permute.
5443  *          - 1 - permute cells.
5444  *          - 2 - permute nodes.
5445  *          - 3 - permute cells and nodes.
5446  *
5447  *  \param [in] glob - the global data storing profiles and localization.
5448  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5449  *          caller is to delete this field using decrRef() as it is no more needed. 
5450  *  \throw If the MED file is not readable.
5451  *  \throw If there is no mesh named \a mName in the MED file.
5452  *  \throw If there are no mesh entities in the mesh.
5453  *  \throw If no field values of the given \a type are available.
5454  */
5455 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5456 {
5457   MCAuto<MEDFileMesh> mm;
5458   if(mName.empty())
5459     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5460   else
5461     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5462   int absDim=getDimension();
5463   int meshDimRelToMax=absDim-mm->getMeshDimension();
5464   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5465 }
5466
5467 /*!
5468  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5469  *  \param [in] type - a spatial discretization of the new field.
5470  *  \param [in] renumPol - specifies how to permute values of the result field according to
5471  *          the optional numbers of cells and nodes, if any. The valid values are
5472  *          - 0 - do not permute.
5473  *          - 1 - permute cells.
5474  *          - 2 - permute nodes.
5475  *          - 3 - permute cells and nodes.
5476  *
5477  *  \param [in] glob - the global data storing profiles and localization.
5478  *  \param [in] mesh - the supporting mesh.
5479  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5480  *         field according to \a renumPol.
5481  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5482  *         field according to \a renumPol.
5483  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5484  *          caller is to delete this field using decrRef() as it is no more needed. 
5485  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5486  *  \throw If no field of \a this is lying on \a mesh.
5487  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5488  */
5489 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
5490 {
5491   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5492   int meshId=getMeshIdFromMeshName(mesh->getName());
5493   bool isPfl=false;
5494   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5495   switch(renumPol)
5496   {
5497     case 0:
5498       {
5499         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5500         return ret.retn();
5501       }
5502     case 3:
5503     case 1:
5504       {
5505         if(isPfl)
5506           throw INTERP_KERNEL::Exception(msg1);
5507         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5508         if(cellRenum)
5509           {
5510             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5511               {
5512                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5513                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5514                 throw INTERP_KERNEL::Exception(oss.str());
5515               }
5516             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5517             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5518             std::vector<DataArray *> arrOut2(1,arrOut);
5519             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5520             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5521             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5522           }
5523         if(renumPol==1)
5524           return ret.retn();
5525       }
5526     case 2:
5527       {
5528         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5529         if(isPfl)
5530           throw INTERP_KERNEL::Exception(msg1);
5531         if(nodeRenum)
5532           {
5533             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5534               {
5535                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5536                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5537                 throw INTERP_KERNEL::Exception(oss.str());
5538               }
5539             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5540             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5541               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5542             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5543           }
5544         return ret.retn();
5545       }
5546     default:
5547       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5548   }
5549 }
5550
5551 /*!
5552  * Returns values and a profile of the field of a given type lying on a given support.
5553  *  \param [in] type - a spatial discretization of the field.
5554  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5555  *  \param [in] mesh - the supporting mesh.
5556  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5557  *          field of interest lies on. If the field lies on all entities of the given
5558  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5559  *          using decrRef() as it is no more needed.  
5560  *  \param [in] glob - the global data storing profiles and localization.
5561  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5562  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5563  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5564  *  \throw If no field of \a this is lying on \a mesh.
5565  *  \throw If no field values of the given \a type are available.
5566  */
5567 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5568 {
5569   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5570   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
5571   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5572   ret->setName(nasc.getName().c_str());
5573   return ret.retn();
5574 }
5575
5576 //= MEDFileField1TSWithoutSDA
5577
5578 /*!
5579  * Throws if a given value is not a valid (non-extended) relative dimension.
5580  *  \param [in] meshDimRelToMax - the relative dimension value.
5581  *  \throw If \a meshDimRelToMax > 0.
5582  */
5583 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5584 {
5585   if(meshDimRelToMax>0)
5586     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5587 }
5588
5589 /*!
5590  * Checks if elements of a given mesh are in the order suitable for writing 
5591  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5592  * vector describing types of elements and their number.
5593  *  \param [in] mesh - the mesh to check.
5594  *  \return std::vector<int> - a vector holding for each element type (1) item of
5595  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5596  *          These values are in full-interlace mode.
5597  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5598  */
5599 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5600 {
5601   if(!mesh)
5602     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5603   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5604   int nbOfTypes=geoTypes.size();
5605   std::vector<int> code(3*nbOfTypes);
5606   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5607   arr1->alloc(nbOfTypes,1);
5608   int *arrPtr=arr1->getPointer();
5609   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5610   for(int i=0;i<nbOfTypes;i++,it++)
5611     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5612   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5613   const int *arrPtr2=arr2->getConstPointer();
5614   int i=0;
5615   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5616     {
5617       int pos=arrPtr2[i];
5618       int nbCells=mesh->getNumberOfCellsWithType(*it);
5619       code[3*pos]=(int)(*it);
5620       code[3*pos+1]=nbCells;
5621       code[3*pos+2]=-1;//no profiles
5622     }
5623   std::vector<const DataArrayInt *> idsPerType;//no profiles
5624   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5625   if(da)
5626     {
5627       da->decrRef();
5628       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5629     }
5630   return code;
5631 }
5632
5633 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5634 {
5635   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5636 }
5637
5638 /*!
5639  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5640  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5641  * item of every of returned sequences refers to the _i_-th part of \a this field.
5642  * Thus all sequences returned by this method are of the same length equal to number
5643  * of different types of supporting entities.<br>
5644  * A field part can include sub-parts with several different spatial discretizations,
5645  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5646  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5647  * of a nested sequence corresponds to a type of spatial discretization.<br>
5648  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5649  * The overhead is due to selecting values into new instances of DataArrayDouble.
5650  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5651  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5652  *          not checked if \a mname == \c NULL).
5653  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5654  *          a field part is returned. 
5655  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5656  *          A field part can include sub-parts with several different spatial discretizations,
5657  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5658  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5659  *          This sequence is of the same length as \a types. 
5660  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5661  *          discretization. A profile name can be empty.
5662  *          Length of this and of nested sequences is the same as that of \a typesF.
5663  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5664  *          discretization. A localization name can be empty.
5665  *          Length of this and of nested sequences is the same as that of \a typesF.
5666  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5667  *          per each type of spatial discretization within one mesh entity type.
5668  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5669  *          Length of this and of nested sequences is the same as that of \a typesF.
5670  *  \throw If no field is lying on \a mname.
5671  */
5672 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
5673 {
5674   int meshId=0;
5675   if(!mname.empty())
5676     meshId=getMeshIdFromMeshName(mname);
5677   else
5678     if(_field_per_mesh.empty())
5679       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5680   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5681   int nbOfRet=ret0.size();
5682   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5683   for(int i=0;i<nbOfRet;i++)
5684     {
5685       const std::vector< std::pair<int,int> >& p=ret0[i];
5686       int nbOfRet1=p.size();
5687       ret[i].resize(nbOfRet1);
5688       for(int j=0;j<nbOfRet1;j++)
5689         {
5690           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5691           ret[i][j]=tmp;
5692         }
5693     }
5694   return ret;
5695 }
5696
5697 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5698 {
5699   return TYPE_STR;
5700 }
5701
5702 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5703 {
5704   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5705   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5706   ret->deepCpyLeavesFrom(*this);
5707   const DataArrayDouble *arr(_arr);
5708   if(arr)
5709     {
5710       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5711       ret->setArray(arr2);
5712     }
5713   return ret.retn();
5714 }
5715
5716 /*!
5717  * Returns a pointer to the underground DataArrayDouble instance and a
5718  * sequence describing parameters of a support of each part of \a this field. The
5719  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5720  * direct access to the field values. This method is intended for the field lying on one
5721  * mesh only.
5722  *  \param [in,out] entries - the sequence describing parameters of a support of each
5723  *         part of \a this field. Each item of this sequence consists of two parts. The
5724  *         first part describes a type of mesh entity and an id of discretization of a
5725  *         current field part. The second part describes a range of values [begin,end)
5726  *         within the returned array relating to the current field part.
5727  *  \return DataArrayDouble * - the pointer to the field values array.
5728  *  \throw If the number of underlying meshes is not equal to 1.
5729  *  \throw If no field values are available.
5730  *  \sa getUndergroundDataArray()
5731  */
5732 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5733 {
5734   if(_field_per_mesh.size()!=1)
5735     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5736   if(_field_per_mesh[0]==0)
5737     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5738   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5739   return getUndergroundDataArrayTemplate();
5740 }
5741
5742 /*!
5743  * Returns a pointer to the underground DataArrayDouble instance and a
5744  * sequence describing parameters of a support of each part of \a this field. The
5745  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5746  * direct access to the field values. This method is intended for the field lying on one
5747  * mesh only.
5748  *  \param [in,out] entries - the sequence describing parameters of a support of each
5749  *         part of \a this field. Each item of this sequence consists of two parts. The
5750  *         first part describes a type of mesh entity and an id of discretization of a
5751  *         current field part. The second part describes a range of values [begin,end)
5752  *         within the returned array relating to the current field part.
5753  *  \return DataArrayDouble * - the pointer to the field values array.
5754  *  \throw If the number of underlying meshes is not equal to 1.
5755  *  \throw If no field values are available.
5756  *  \sa getUndergroundDataArray()
5757  */
5758 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5759 {
5760   return getUndergroundDataArrayDoubleExt(entries);
5761 }
5762
5763 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,csit,iteration,order)
5764 {
5765   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5766   arr->setInfoAndChangeNbOfCompo(infos);
5767 }
5768
5769 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5770 {
5771 }
5772
5773 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5774 {
5775   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5776   ret->deepCpyLeavesFrom(*this);
5777   return ret.retn();
5778 }
5779
5780 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5781 {
5782   MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
5783   if(_arr.isNotNull())
5784     ret->_arr=_arr->deepCopy();
5785   return ret.retn();
5786 }
5787
5788 //= MEDFileIntField1TSWithoutSDA
5789
5790 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5791 {
5792   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5793 }
5794
5795 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5796 {
5797 }
5798
5799 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5800                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,csit,iteration,order)
5801 {
5802   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5803   arr->setInfoAndChangeNbOfCompo(infos);
5804 }
5805
5806 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5807 {
5808   return TYPE_STR;
5809 }
5810
5811 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5812 {
5813   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5814   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5815   ret->deepCpyLeavesFrom(*this);
5816   const DataArrayInt *arr(_arr);
5817   if(arr)
5818     {
5819       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5820       ret->setArray(arr2);
5821     }
5822   return ret.retn();
5823 }
5824
5825 /*!
5826  * Returns a pointer to the underground DataArrayInt instance and a
5827  * sequence describing parameters of a support of each part of \a this field. The
5828  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5829  * direct access to the field values. This method is intended for the field lying on one
5830  * mesh only.
5831  *  \param [in,out] entries - the sequence describing parameters of a support of each
5832  *         part of \a this field. Each item of this sequence consists of two parts. The
5833  *         first part describes a type of mesh entity and an id of discretization of a
5834  *         current field part. The second part describes a range of values [begin,end)
5835  *         within the returned array relating to the current field part.
5836  *  \return DataArrayInt * - the pointer to the field values array.
5837  *  \throw If the number of underlying meshes is not equal to 1.
5838  *  \throw If no field values are available.
5839  *  \sa getUndergroundDataArray()
5840  */
5841 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5842 {
5843   return getUndergroundDataArrayIntExt(entries);
5844 }
5845
5846 /*!
5847  * Returns a pointer to the underground DataArrayInt instance and a
5848  * sequence describing parameters of a support of each part of \a this field. The
5849  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5850  * direct access to the field values. This method is intended for the field lying on one
5851  * mesh only.
5852  *  \param [in,out] entries - the sequence describing parameters of a support of each
5853  *         part of \a this field. Each item of this sequence consists of two parts. The
5854  *         first part describes a type of mesh entity and an id of discretization of a
5855  *         current field part. The second part describes a range of values [begin,end)
5856  *         within the returned array relating to the current field part.
5857  *  \return DataArrayInt * - the pointer to the field values array.
5858  *  \throw If the number of underlying meshes is not equal to 1.
5859  *  \throw If no field values are available.
5860  *  \sa getUndergroundDataArray()
5861  */
5862 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5863 {
5864   if(_field_per_mesh.size()!=1)
5865     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5866   if(_field_per_mesh[0]==0)
5867     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5868   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5869   return getUndergroundDataArrayTemplate();
5870 }
5871
5872 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5873 {
5874   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5875   ret->deepCpyLeavesFrom(*this);
5876   return ret.retn();
5877 }
5878
5879 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5880 {
5881   MCAuto<MEDFileIntField1TSWithoutSDA> ret(shallowCpy());
5882   if(_arr.isNotNull())
5883     ret->_arr=_arr->deepCopy();
5884   return ret.retn();
5885 }
5886
5887 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5888 {
5889 }
5890
5891 //= MEDFileAnyTypeField1TS
5892
5893 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5894 {
5895   med_field_type typcha;
5896   //
5897   std::vector<std::string> infos;
5898   std::string dtunit,fieldName;
5899   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
5900   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5901   switch(typcha)
5902   {
5903     case MED_FLOAT64:
5904       {
5905         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5906         break;
5907       }
5908     case MED_INT32:
5909       {
5910         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5911         break;
5912       }
5913     default:
5914       {
5915         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
5916         throw INTERP_KERNEL::Exception(oss.str());
5917       }
5918   }
5919   ret->setDtUnit(dtunit.c_str());
5920   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5921   //
5922   med_int numdt,numit;
5923   med_float dt;
5924   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5925   ret->setTime(numdt,numit,dt);
5926   ret->_csit=1;
5927   if(loadAll)
5928     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5929   else
5930     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5931   return ret.retn();
5932 }
5933
5934 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5935 try:MEDFileFieldGlobsReal(fid)
5936 {
5937   _content=BuildContentFrom(fid,loadAll,ms);
5938   loadGlobals(fid);
5939 }
5940 catch(INTERP_KERNEL::Exception& e)
5941 {
5942     throw e;
5943 }
5944
5945 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5946 {
5947   med_field_type typcha;
5948   std::vector<std::string> infos;
5949   std::string dtunit;
5950   int iii=-1;
5951   int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit);
5952   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5953   switch(typcha)
5954   {
5955     case MED_FLOAT64:
5956       {
5957         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5958         break;
5959       }
5960     case MED_INT32:
5961       {
5962         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5963         break;
5964       }
5965     default:
5966       {
5967         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5968         throw INTERP_KERNEL::Exception(oss.str());
5969       }
5970   }
5971   ret->setDtUnit(dtunit.c_str());
5972   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5973   //
5974   if(nbSteps<1)
5975     {
5976       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5977       throw INTERP_KERNEL::Exception(oss.str());
5978     }
5979   //
5980   med_int numdt,numit;
5981   med_float dt;
5982   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5983   ret->setTime(numdt,numit,dt);
5984   ret->_csit=1;
5985   if(loadAll)
5986     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5987   else
5988     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5989   return ret.retn();
5990 }
5991
5992 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5993 try:MEDFileFieldGlobsReal(fid)
5994 {
5995   _content=BuildContentFrom(fid,fieldName,loadAll,ms);
5996   loadGlobals(fid);
5997 }
5998 catch(INTERP_KERNEL::Exception& e)
5999 {
6000     throw e;
6001 }
6002
6003 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
6004 {
6005   if(!c)
6006     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
6007   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
6008     {
6009       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6010       ret->_content=c; c->incrRef();
6011       return ret.retn();
6012     }
6013   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
6014     {
6015       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
6016       ret->_content=c; c->incrRef();
6017       return ret.retn();
6018     }
6019   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
6020 }
6021
6022 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
6023 {
6024   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
6025   ret->setFileName(FileNameFromFID(fid));
6026   return ret;
6027 }
6028
6029 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
6030 {
6031   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6032   return New(fid,loadAll);
6033 }
6034
6035 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
6036 {
6037   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
6038   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6039   ret->loadGlobals(fid);
6040   return ret.retn();
6041 }
6042
6043 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6044 {
6045   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6046   return New(fid,fieldName,loadAll);
6047 }
6048
6049 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6050 {
6051   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0));
6052   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6053   ret->loadGlobals(fid);
6054   return ret.retn();
6055 }
6056
6057 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6058 {
6059   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6060   return New(fid,fieldName,iteration,order,loadAll);
6061 }
6062
6063 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6064 {
6065   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0));
6066   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6067   ret->loadGlobals(fid);
6068   return ret.retn();
6069 }
6070
6071 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6072 {
6073   med_field_type typcha;
6074   std::vector<std::string> infos;
6075   std::string dtunit;
6076   int iii(-1);
6077   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit));
6078   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6079   switch(typcha)
6080   {
6081     case MED_FLOAT64:
6082       {
6083         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
6084         break;
6085       }
6086     case MED_INT32:
6087       {
6088         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
6089         break;
6090       }
6091     default:
6092       {
6093         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName,iteration,order) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
6094         throw INTERP_KERNEL::Exception(oss.str());
6095       }
6096   }
6097   ret->setDtUnit(dtunit.c_str());
6098   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6099   //
6100   bool found=false;
6101   std::vector< std::pair<int,int> > dtits(nbOfStep2);
6102   for(int i=0;i<nbOfStep2 && !found;i++)
6103     {
6104       med_int numdt,numit;
6105       med_float dt;
6106       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
6107       if(numdt==iteration && numit==order)
6108         {
6109           found=true;
6110           ret->_csit=i+1;
6111         }
6112       else
6113         dtits[i]=std::pair<int,int>(numdt,numit);
6114     }
6115   if(!found)
6116     {
6117       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
6118       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
6119         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
6120       throw INTERP_KERNEL::Exception(oss.str());
6121     }
6122   if(loadAll)
6123     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
6124   else
6125     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
6126   return ret.retn();
6127 }
6128
6129 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6130 try:MEDFileFieldGlobsReal(fid)
6131 {
6132   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms);
6133   loadGlobals(fid);
6134 }
6135 catch(INTERP_KERNEL::Exception& e)
6136 {
6137     throw e;
6138 }
6139
6140 /*!
6141  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6142  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6143  *
6144  * \warning this is a shallow copy constructor
6145  */
6146 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
6147 {
6148   if(!shallowCopyOfContent)
6149     {
6150       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
6151       otherPtr->incrRef();
6152       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
6153     }
6154   else
6155     {
6156       _content=other.shallowCpy();
6157     }
6158 }
6159
6160 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
6161 {
6162   if(checkFieldId)
6163     {
6164       int nbFields=MEDnField(fid);
6165       if(fieldIdCFormat>=nbFields)
6166         {
6167           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
6168           throw INTERP_KERNEL::Exception(oss.str());
6169         }
6170     }
6171   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
6172   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
6173   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
6174   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
6175   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
6176   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
6177   med_bool localMesh;
6178   int nbOfStep;
6179   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
6180   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
6181   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
6182   infos.clear(); infos.resize(ncomp);
6183   for(int j=0;j<ncomp;j++)
6184     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
6185   return nbOfStep;
6186 }
6187
6188 /*!
6189  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
6190  * 
6191  * \param [out]
6192  * \return in case of success the number of time steps available for the field with name \a fieldName.
6193  */
6194 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
6195 {
6196   int nbFields=MEDnField(fid);
6197   bool found=false;
6198   std::vector<std::string> fns(nbFields);
6199   int nbOfStep2(-1);
6200   for(int i=0;i<nbFields && !found;i++)
6201     {
6202       std::string tmp;
6203       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut);
6204       fns[i]=tmp;
6205       found=(tmp==fieldName);
6206       if(found)
6207         posCFormat=i;
6208     }
6209   if(!found)
6210     {
6211       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
6212       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
6213         oss << "\"" << *it << "\" ";
6214       throw INTERP_KERNEL::Exception(oss.str());
6215     }
6216   return nbOfStep2;
6217 }
6218
6219 /*!
6220  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6221  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6222  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6223  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6224  * to keep a valid instance.
6225  * 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.
6226  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
6227  * 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.
6228  *
6229  * \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.
6230  * \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.
6231  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6232  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6233  * \param [in] newLocName is the new localization name.
6234  * \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.
6235  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
6236  */
6237 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
6238 {
6239   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6240   std::string oldPflName=disc->getProfile();
6241   std::vector<std::string> vv=getPflsReallyUsedMulti();
6242   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
6243   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
6244     {
6245       disc->setProfile(newPflName);
6246       DataArrayInt *pfl=getProfile(oldPflName.c_str());
6247       pfl->setName(newPflName);
6248     }
6249   else
6250     {
6251       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
6252       throw INTERP_KERNEL::Exception(oss.str());
6253     }
6254 }
6255
6256 /*!
6257  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6258  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6259  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6260  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6261  * to keep a valid instance.
6262  * 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.
6263  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
6264  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
6265  * 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.
6266  *
6267  * \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.
6268  * \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.
6269  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6270  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6271  * \param [in] newLocName is the new localization name.
6272  * \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.
6273  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
6274  */
6275 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
6276 {
6277   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6278   std::string oldLocName=disc->getLocalization();
6279   std::vector<std::string> vv=getLocsReallyUsedMulti();
6280   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
6281   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
6282     {
6283       disc->setLocalization(newLocName);
6284       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
6285       loc.setName(newLocName);
6286     }
6287   else
6288     {
6289       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
6290       throw INTERP_KERNEL::Exception(oss.str());
6291     }
6292 }
6293
6294 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
6295 {
6296   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6297   if(!ret)
6298     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
6299   return ret;
6300 }
6301
6302 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
6303 {
6304   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6305   if(!ret)
6306     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
6307   return ret;
6308 }
6309
6310 /*!
6311  * This method alloc the arrays and load potentially huge arrays contained in this field.
6312  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
6313  * This method can be also called to refresh or reinit values from a file.
6314  * 
6315  * \throw If the fileName is not set or points to a non readable MED file.
6316  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6317  */
6318 void MEDFileAnyTypeField1TS::loadArrays()
6319 {
6320   if(getFileName().empty())
6321     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
6322   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6323   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
6324 }
6325
6326 /*!
6327  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
6328  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
6329  * this method does not throw if \a this does not come from file read.
6330  * 
6331  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
6332  */
6333 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
6334 {
6335   if(!getFileName().empty())
6336     {
6337       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6338       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
6339     }
6340 }
6341
6342 /*!
6343  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
6344  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
6345  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
6346  * 
6347  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
6348  */
6349 void MEDFileAnyTypeField1TS::unloadArrays()
6350 {
6351   contentNotNullBase()->unloadArrays();
6352 }
6353
6354 /*!
6355  * 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.
6356  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
6357  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
6358  * 
6359  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6360  */
6361 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
6362 {
6363   if(!getFileName().empty())
6364     contentNotNullBase()->unloadArrays();
6365 }
6366
6367 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6368 {
6369   int nbComp(getNumberOfComponents());
6370   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6371   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6372   for(int i=0;i<nbComp;i++)
6373     {
6374       std::string info=getInfo()[i];
6375       std::string c,u;
6376       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6377       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6378       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6379     }
6380   if(getName().empty())
6381     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6382   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6383   writeGlobals(fid,*this);
6384   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6385 }
6386
6387 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6388 {
6389   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6390 }
6391
6392 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6393 {
6394   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6395   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6396   return ret;
6397 }
6398
6399 /*!
6400  * Returns a string describing \a this field. This string is outputted 
6401  * by \c print Python command.
6402  */
6403 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6404 {
6405   std::ostringstream oss;
6406   contentNotNullBase()->simpleRepr(0,oss,-1);
6407   simpleReprGlobs(oss);
6408   return oss.str();
6409 }
6410
6411 /*!
6412  * This method returns all profiles whose name is non empty used.
6413  * \b WARNING If profile is used several times it will be reported \b only \b once.
6414  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6415  */
6416 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6417 {
6418   return contentNotNullBase()->getPflsReallyUsed2();
6419 }
6420
6421 /*!
6422  * This method returns all localizations whose name is non empty used.
6423  * \b WARNING If localization is used several times it will be reported \b only \b once.
6424  */
6425 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6426 {
6427   return contentNotNullBase()->getLocsReallyUsed2();
6428 }
6429
6430 /*!
6431  * This method returns all profiles whose name is non empty used.
6432  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6433  */
6434 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6435 {
6436   return contentNotNullBase()->getPflsReallyUsedMulti2();
6437 }
6438
6439 /*!
6440  * This method returns all localizations whose name is non empty used.
6441  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6442  */
6443 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6444 {
6445   return contentNotNullBase()->getLocsReallyUsedMulti2();
6446 }
6447
6448 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6449 {
6450   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6451 }
6452
6453 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6454 {
6455   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6456 }
6457
6458 int MEDFileAnyTypeField1TS::getDimension() const
6459 {
6460   return contentNotNullBase()->getDimension();
6461 }
6462
6463 int MEDFileAnyTypeField1TS::getIteration() const
6464 {
6465   return contentNotNullBase()->getIteration();
6466 }
6467
6468 int MEDFileAnyTypeField1TS::getOrder() const
6469 {
6470   return contentNotNullBase()->getOrder();
6471 }
6472
6473 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6474 {
6475   return contentNotNullBase()->getTime(iteration,order);
6476 }
6477
6478 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6479 {
6480   contentNotNullBase()->setTime(iteration,order,val);
6481 }
6482
6483 std::string MEDFileAnyTypeField1TS::getName() const
6484 {
6485   return contentNotNullBase()->getName();
6486 }
6487
6488 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6489 {
6490   contentNotNullBase()->setName(name);
6491 }
6492
6493 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6494 {
6495   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6496 }
6497
6498 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6499 {
6500   return contentNotNullBase()->getDtUnit();
6501 }
6502
6503 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6504 {
6505   contentNotNullBase()->setDtUnit(dtUnit);
6506 }
6507
6508 std::string MEDFileAnyTypeField1TS::getMeshName() const
6509 {
6510   return contentNotNullBase()->getMeshName();
6511 }
6512
6513 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6514 {
6515   contentNotNullBase()->setMeshName(newMeshName);
6516 }
6517
6518 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6519 {
6520   return contentNotNullBase()->changeMeshNames(modifTab);
6521 }
6522
6523 int MEDFileAnyTypeField1TS::getMeshIteration() const
6524 {
6525   return contentNotNullBase()->getMeshIteration();
6526 }
6527
6528 int MEDFileAnyTypeField1TS::getMeshOrder() const
6529 {
6530   return contentNotNullBase()->getMeshOrder();
6531 }
6532
6533 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6534 {
6535   return contentNotNullBase()->getNumberOfComponents();
6536 }
6537
6538 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6539 {
6540   return contentNotNullBase()->isDealingTS(iteration,order);
6541 }
6542
6543 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6544 {
6545   return contentNotNullBase()->getDtIt();
6546 }
6547
6548 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6549 {
6550   contentNotNullBase()->fillIteration(p);
6551 }
6552
6553 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6554 {
6555   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6556 }
6557
6558 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6559 {
6560   contentNotNullBase()->setInfo(infos);
6561 }
6562
6563 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6564 {
6565   return contentNotNullBase()->getInfo();
6566 }
6567 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6568 {
6569   return contentNotNullBase()->getInfo();
6570 }
6571
6572 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6573 {
6574   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6575 }
6576
6577 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6578 {
6579   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6580 }
6581
6582 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6583 {
6584   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6585 }
6586
6587 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6588 {
6589   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6590 }
6591
6592 void MEDFileAnyTypeField1TS::convertMedBallIntoClassic()
6593 {
6594   return contentNotNullBase()->convertMedBallIntoClassic();
6595 }
6596
6597 void MEDFileAnyTypeField1TS::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
6598 {
6599   return contentNotNullBase()->makeReduction(ct,tof,pfl);
6600 }
6601
6602 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6603 {
6604   return contentNotNullBase()->getTypesOfFieldAvailable();
6605 }
6606
6607 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,
6608                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6609 {
6610   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6611 }
6612
6613 /*!
6614  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6615  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6616  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6617  */
6618 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6619 {
6620   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6621   if(!content)
6622     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6623   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6624   std::size_t sz(contentsSplit.size());
6625   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6626   for(std::size_t i=0;i<sz;i++)
6627     {
6628       ret[i]=shallowCpy();
6629       ret[i]->_content=contentsSplit[i];
6630     }
6631   return ret;
6632 }
6633
6634 /*!
6635  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6636  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6637  */
6638 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6639 {
6640   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6641   if(!content)
6642     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6643   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6644   std::size_t sz(contentsSplit.size());
6645   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6646   for(std::size_t i=0;i<sz;i++)
6647     {
6648       ret[i]=shallowCpy();
6649       ret[i]->_content=contentsSplit[i];
6650     }
6651   return ret;
6652 }
6653
6654 /*!
6655  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6656  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6657  */
6658 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6659 {
6660   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6661   if(!content)
6662     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6663   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6664   std::size_t sz(contentsSplit.size());
6665   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6666   for(std::size_t i=0;i<sz;i++)
6667     {
6668       ret[i]=shallowCpy();
6669       ret[i]->_content=contentsSplit[i];
6670     }
6671   return ret;
6672 }
6673
6674 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6675 {
6676   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6677   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6678     ret->_content=_content->deepCopy();
6679   ret->deepCpyGlobs(*this);
6680   return ret.retn();
6681 }
6682
6683 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6684 {
6685   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6686 }
6687
6688 //= MEDFileField1TS
6689
6690 /*!
6691  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6692  * the first field that has been read from a specified MED file.
6693  *  \param [in] fileName - the name of the MED file to read.
6694  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6695  *          is to delete this field using decrRef() as it is no more needed.
6696  *  \throw If reading the file fails.
6697  */
6698 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6699 {
6700   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6701   return New(fid,loadAll);
6702 }
6703
6704 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
6705 {
6706   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
6707   ret->contentNotNull();
6708   return ret.retn();
6709 }
6710
6711 /*!
6712  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6713  * a given field that has been read from a specified MED file.
6714  *  \param [in] fileName - the name of the MED file to read.
6715  *  \param [in] fieldName - the name of the field to read.
6716  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6717  *          is to delete this field using decrRef() as it is no more needed.
6718  *  \throw If reading the file fails.
6719  *  \throw If there is no field named \a fieldName in the file.
6720  */
6721 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6722 {
6723   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6724   return New(fid,fieldName,loadAll);
6725 }
6726
6727 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6728 {
6729   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
6730   ret->contentNotNull();
6731   return ret.retn();
6732 }
6733
6734 /*!
6735  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6736  * a given field that has been read from a specified MED file.
6737  *  \param [in] fileName - the name of the MED file to read.
6738  *  \param [in] fieldName - the name of the field to read.
6739  *  \param [in] iteration - the iteration number of a required time step.
6740  *  \param [in] order - the iteration order number of required time step.
6741  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6742  *          is to delete this field using decrRef() as it is no more needed.
6743  *  \throw If reading the file fails.
6744  *  \throw If there is no field named \a fieldName in the file.
6745  *  \throw If the required time step is missing from the file.
6746  */
6747 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6748 {
6749   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6750   return New(fid,fieldName,iteration,order,loadAll);
6751 }
6752
6753 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6754 {
6755   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
6756   ret->contentNotNull();
6757   return ret.retn();
6758 }
6759
6760 /*!
6761  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6762  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6763  *
6764  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6765  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6766  * \warning this is a shallow copy constructor
6767  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6768  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6769  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6770  *          is to delete this field using decrRef() as it is no more needed.
6771  */
6772 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6773 {
6774   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6775   ret->contentNotNull();
6776   return ret.retn();
6777 }
6778
6779 /*!
6780  * Returns a new empty instance of MEDFileField1TS.
6781  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6782  *          is to delete this field using decrRef() as it is no more needed.
6783  */
6784 MEDFileField1TS *MEDFileField1TS::New()
6785 {
6786   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6787   ret->contentNotNull();
6788   return ret.retn();
6789 }
6790
6791 /*!
6792  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6793  * following the given input policy.
6794  *
6795  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6796  *                            By default (true) the globals are deeply copied.
6797  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6798  */
6799 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6800 {
6801   MCAuto<MEDFileIntField1TS> ret;
6802   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6803   if(content)
6804     {
6805       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6806       if(!contc)
6807         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6808       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6809       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6810     }
6811   else
6812     ret=MEDFileIntField1TS::New();
6813   if(isDeepCpyGlobs)
6814     ret->deepCpyGlobs(*this);
6815   else
6816     ret->shallowCpyGlobs(*this);
6817   return ret.retn();
6818 }
6819
6820 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6821 {
6822   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6823   if(!pt)
6824     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6825   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6826   if(!ret)
6827     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 !");
6828   return ret;
6829 }
6830
6831 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6832 {
6833   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6834   if(!pt)
6835     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6836   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6837   if(!ret)
6838     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 !");
6839   return ret;
6840 }
6841
6842 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6843 {
6844   if(!f)
6845     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6846   if(arr.isNull())
6847     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6848   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6849   if(!arrOutC)
6850     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6851   f->setArray(arrOutC);
6852 }
6853
6854 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6855 {
6856   if(arr.isNull())
6857     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6858   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6859   if(!arrOutC)
6860     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6861   arrOutC->incrRef();
6862   return arrOutC;
6863 }
6864
6865 /*!
6866  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6867  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6868  *
6869  * \return A new object that the caller is responsible to deallocate.
6870  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6871  */
6872 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6873 {
6874   if(!mm)
6875     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6876   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6877   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6878   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6879     {
6880       if((*it0)!=ON_NODES)
6881         {
6882           std::vector<int> levs;
6883           getNonEmptyLevels(mm->getName(),levs);
6884           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6885             {
6886               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6887               if(it2!=extractDef.end())
6888                 {
6889                   MCAuto<DataArrayInt> t((*it2).second);
6890                   if(t.isNull())
6891                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6892                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6893                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6894                   ret->setFieldNoProfileSBT(fOut);
6895                 }
6896             }
6897         }
6898       else
6899         {
6900           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6901           if(it2==extractDef.end())
6902             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6903           MCAuto<DataArrayInt> t((*it2).second);
6904           if(t.isNull())
6905             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6906           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6907           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6908           DataArrayDouble *arr(f->getArray());
6909           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6910           fOut->setArray(newArr);
6911           ret->setFieldNoProfileSBT(fOut);
6912         }
6913     }
6914   return ret.retn();
6915 }
6916
6917 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6918 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6919 {
6920 }
6921 catch(INTERP_KERNEL::Exception& e)
6922 { throw e; }
6923
6924 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6925 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6926 {
6927 }
6928 catch(INTERP_KERNEL::Exception& e)
6929 { throw e; }
6930
6931 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6932 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6933 {
6934 }
6935 catch(INTERP_KERNEL::Exception& e)
6936 { throw e; }
6937
6938 /*!
6939  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6940  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6941  *
6942  * \warning this is a shallow copy constructor
6943  */
6944 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6945 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6946 {
6947 }
6948 catch(INTERP_KERNEL::Exception& e)
6949 { throw e; }
6950
6951 MEDFileField1TS::MEDFileField1TS()
6952 {
6953   _content=new MEDFileField1TSWithoutSDA;
6954 }
6955
6956 /*!
6957  * 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
6958  * method should be called (getFieldOnMeshAtLevel for example).
6959  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6960  *
6961  * \param [in] mesh - the mesh the field is lying on
6962  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6963  *          caller is to delete this field using decrRef() as it is no more needed. 
6964  */
6965 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6966 {
6967   MCAuto<DataArray> arrOut;
6968   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6969   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6970   return ret.retn();
6971 }
6972
6973 /*!
6974  * Returns a new MEDCouplingFieldDouble of a given type lying on
6975  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6976  * has not been constructed via file reading, an exception is thrown.
6977  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6978  *  \param [in] type - a spatial discretization of interest.
6979  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6980  *  \param [in] renumPol - specifies how to permute values of the result field according to
6981  *          the optional numbers of cells and nodes, if any. The valid values are
6982  *          - 0 - do not permute.
6983  *          - 1 - permute cells.
6984  *          - 2 - permute nodes.
6985  *          - 3 - permute cells and nodes.
6986  *
6987  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6988  *          caller is to delete this field using decrRef() as it is no more needed. 
6989  *  \throw If \a this field has not been constructed via file reading.
6990  *  \throw If the MED file is not readable.
6991  *  \throw If there is no mesh in the MED file.
6992  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6993  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6994  *  \sa getFieldOnMeshAtLevel()
6995  */
6996 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6997 {
6998   if(getFileName().empty())
6999     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7000   MCAuto<DataArray> arrOut;
7001   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7002   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7003   return ret.retn();
7004 }
7005
7006 /*!
7007  * Returns a new MEDCouplingFieldDouble of a given type lying on
7008  * the top level cells of the first mesh in MED file. If \a this field 
7009  * has not been constructed via file reading, an exception is thrown.
7010  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7011  *  \param [in] type - a spatial discretization of interest.
7012  *  \param [in] renumPol - specifies how to permute values of the result field according to
7013  *          the optional numbers of cells and nodes, if any. The valid values are
7014  *          - 0 - do not permute.
7015  *          - 1 - permute cells.
7016  *          - 2 - permute nodes.
7017  *          - 3 - permute cells and nodes.
7018  *
7019  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7020  *          caller is to delete this field using decrRef() as it is no more needed. 
7021  *  \throw If \a this field has not been constructed via file reading.
7022  *  \throw If the MED file is not readable.
7023  *  \throw If there is no mesh in the MED file.
7024  *  \throw If no field values of the given \a type.
7025  *  \throw If no field values lying on the top level support.
7026  *  \sa getFieldAtLevel()
7027  */
7028 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7029 {
7030   if(getFileName().empty())
7031     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7032   MCAuto<DataArray> arrOut;
7033   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7034   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7035   return ret.retn();
7036 }
7037
7038 /*!
7039  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
7040  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7041  *  \param [in] type - a spatial discretization of the new field.
7042  *  \param [in] mesh - the supporting mesh.
7043  *  \param [in] renumPol - specifies how to permute values of the result field according to
7044  *          the optional numbers of cells and nodes, if any. The valid values are
7045  *          - 0 - do not permute.
7046  *          - 1 - permute cells.
7047  *          - 2 - permute nodes.
7048  *          - 3 - permute cells and nodes.
7049  *
7050  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7051  *          caller is to delete this field using decrRef() as it is no more needed. 
7052  *  \throw If no field of \a this is lying on \a mesh.
7053  *  \throw If the mesh is empty.
7054  *  \throw If no field values of the given \a type are available.
7055  *  \sa getFieldAtLevel()
7056  *  \sa getFieldOnMeshAtLevel() 
7057  */
7058 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7059 {
7060   MCAuto<DataArray> arrOut;
7061   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7062   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7063   return ret.retn();
7064 }
7065
7066 /*!
7067  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7068  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7069  *  \param [in] type - a spatial discretization of interest.
7070  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7071  *  \param [in] mesh - the supporting mesh.
7072  *  \param [in] renumPol - specifies how to permute values of the result field according to
7073  *          the optional numbers of cells and nodes, if any. The valid values are
7074  *          - 0 - do not permute.
7075  *          - 1 - permute cells.
7076  *          - 2 - permute nodes.
7077  *          - 3 - permute cells and nodes.
7078  *
7079  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7080  *          caller is to delete this field using decrRef() as it is no more needed. 
7081  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7082  *  \throw If no field of \a this is lying on \a mesh.
7083  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7084  *  \sa getFieldAtLevel()
7085  *  \sa getFieldOnMeshAtLevel() 
7086  */
7087 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7088 {
7089   MCAuto<DataArray> arrOut;
7090   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7091   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7092   return ret.retn();
7093 }
7094
7095 /*!
7096  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7097  * This method is called "Old" because in MED3 norm a field has only one meshName
7098  * attached, so this method is for readers of MED2 files. If \a this field 
7099  * has not been constructed via file reading, an exception is thrown.
7100  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7101  *  \param [in] type - a spatial discretization of interest.
7102  *  \param [in] mName - a name of the supporting mesh.
7103  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7104  *  \param [in] renumPol - specifies how to permute values of the result field according to
7105  *          the optional numbers of cells and nodes, if any. The valid values are
7106  *          - 0 - do not permute.
7107  *          - 1 - permute cells.
7108  *          - 2 - permute nodes.
7109  *          - 3 - permute cells and nodes.
7110  *
7111  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7112  *          caller is to delete this field using decrRef() as it is no more needed. 
7113  *  \throw If the MED file is not readable.
7114  *  \throw If there is no mesh named \a mName in the MED file.
7115  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7116  *  \throw If \a this field has not been constructed via file reading.
7117  *  \throw If no field of \a this is lying on the mesh named \a mName.
7118  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7119  *  \sa getFieldAtLevel()
7120  */
7121 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7122 {
7123   if(getFileName().empty())
7124     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7125   MCAuto<DataArray> arrOut;
7126   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
7127   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7128   return ret.retn();
7129 }
7130
7131 /*!
7132  * Returns values and a profile of the field of a given type lying on a given support.
7133  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7134  *  \param [in] type - a spatial discretization of the field.
7135  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7136  *  \param [in] mesh - the supporting mesh.
7137  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7138  *          field of interest lies on. If the field lies on all entities of the given
7139  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7140  *          using decrRef() as it is no more needed.  
7141  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
7142  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7143  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7144  *  \throw If no field of \a this is lying on \a mesh.
7145  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7146  */
7147 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7148 {
7149   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7150   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
7151 }
7152
7153 /*!
7154  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
7155  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
7156  * "Sort By Type"), if not, an exception is thrown. 
7157  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7158  *  \param [in] field - the field to add to \a this.
7159  *  \throw If the name of \a field is empty.
7160  *  \throw If the data array of \a field is not set.
7161  *  \throw If the data array is already allocated but has different number of components
7162  *         than \a field.
7163  *  \throw If the underlying mesh of \a field has no name.
7164  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7165  */
7166 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
7167 {
7168   setFileName("");
7169   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
7170 }
7171
7172 /*!
7173  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
7174  * can be an aggregation of several MEDCouplingFieldDouble instances.
7175  * The mesh support of input parameter \a field is ignored here, it can be NULL.
7176  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
7177  * and \a profile.
7178  *
7179  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7180  * A new profile is added only if no equal profile is missing.
7181  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7182  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
7183  *  \param [in] mesh - the supporting mesh of \a field.
7184  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7185  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7186  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7187  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7188  *  \throw If the data array of \a field is not set.
7189  *  \throw If the data array of \a this is already allocated but has different number of
7190  *         components than \a field.
7191  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7192  *  \sa setFieldNoProfileSBT()
7193  */
7194 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7195 {
7196   setFileName("");
7197   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7198 }
7199
7200 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
7201 {
7202   return new MEDFileField1TS(*this);
7203 }
7204
7205 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
7206 {
7207   return contentNotNull()->getUndergroundDataArrayTemplate();
7208 }
7209
7210 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7211 {
7212   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
7213 }
7214
7215 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
7216                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
7217 {
7218   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7219 }
7220
7221 //= MEDFileIntField1TS
7222
7223 MEDFileIntField1TS *MEDFileIntField1TS::New()
7224 {
7225   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
7226   ret->contentNotNull();
7227   return ret.retn();
7228 }
7229
7230 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
7231 {
7232   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7233   return MEDFileIntField1TS::New(fid,loadAll);
7234 }
7235
7236 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
7237 {
7238   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
7239   ret->contentNotNull();
7240   return ret.retn();
7241 }
7242
7243 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
7244 {
7245   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7246   return MEDFileIntField1TS::New(fid,fieldName,loadAll);
7247 }
7248
7249 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
7250 {
7251   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
7252   ret->contentNotNull();
7253   return ret.retn();
7254 }
7255
7256 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
7257 {
7258   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7259   return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
7260 }
7261
7262 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
7263 {
7264   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
7265   ret->contentNotNull();
7266   return ret.retn();
7267 }
7268
7269 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
7270 {
7271   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
7272   ret->contentNotNull();
7273   return ret.retn();
7274 }
7275
7276 MEDFileIntField1TS::MEDFileIntField1TS()
7277 {
7278   _content=new MEDFileIntField1TSWithoutSDA;
7279 }
7280
7281 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
7282 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
7283 {
7284 }
7285 catch(INTERP_KERNEL::Exception& e)
7286 { throw e; }
7287
7288 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7289 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
7290 {
7291 }
7292 catch(INTERP_KERNEL::Exception& e)
7293 { throw e; }
7294
7295 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
7296 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
7297 {
7298 }
7299 catch(INTERP_KERNEL::Exception& e)
7300 { throw e; }
7301
7302 /*!
7303  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7304  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7305  *
7306  * \warning this is a shallow copy constructor
7307  */
7308 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
7309 {
7310 }
7311
7312 MEDFileIntField1TS *MEDFileIntField1TS::shallowCpy() const
7313 {
7314   return new MEDFileIntField1TS(*this);
7315 }
7316
7317 /*!
7318  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
7319  * following the given input policy.
7320  *
7321  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
7322  *                            By default (true) the globals are deeply copied.
7323  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
7324  */
7325 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
7326 {
7327   MCAuto<MEDFileField1TS> ret;
7328   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
7329   if(content)
7330     {
7331       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
7332       if(!contc)
7333         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
7334       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
7335       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
7336     }
7337   else
7338     ret=MEDFileField1TS::New();
7339   if(isDeepCpyGlobs)
7340     ret->deepCpyGlobs(*this);
7341   else
7342     ret->shallowCpyGlobs(*this);
7343   return ret.retn();
7344 }
7345
7346 /*!
7347  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
7348  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
7349  * "Sort By Type"), if not, an exception is thrown. 
7350  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7351  *  \param [in] field - the field to add to \a this.
7352  *  \throw If the name of \a field is empty.
7353  *  \throw If the data array of \a field is not set.
7354  *  \throw If the data array is already allocated but has different number of components
7355  *         than \a field.
7356  *  \throw If the underlying mesh of \a field has no name.
7357  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7358  */
7359 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
7360 {
7361   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7362   setFileName("");
7363   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
7364 }
7365
7366 /*!
7367  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
7368  * can be an aggregation of several MEDCouplingFieldDouble instances.
7369  * The mesh support of input parameter \a field is ignored here, it can be NULL.
7370  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
7371  * and \a profile.
7372  *
7373  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7374  * A new profile is added only if no equal profile is missing.
7375  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7376  *  \param [in] field - the field to add to \a this.
7377  *  \param [in] mesh - the supporting mesh of \a field.
7378  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7379  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7380  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7381  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7382  *  \throw If the data array of \a field is not set.
7383  *  \throw If the data array of \a this is already allocated but has different number of
7384  *         components than \a field.
7385  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7386  *  \sa setFieldNoProfileSBT()
7387  */
7388 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7389 {
7390   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7391   setFileName("");
7392   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7393 }
7394
7395 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
7396 {
7397   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7398   if(!pt)
7399     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
7400   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
7401   if(!ret)
7402     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 !");
7403   return ret;
7404 }
7405
7406 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7407 {
7408   if(getFileName().empty())
7409     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7410   MCAuto<DataArray> arrOut;
7411   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7412   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7413   return ret2.retn();
7414 }
7415
7416 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
7417 {
7418   if(arr.isNull())
7419     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
7420   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
7421   if(!arrC)
7422     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
7423   arrC->incrRef();
7424   return arrC;
7425 }
7426
7427 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
7428 {
7429   int t1,t2;
7430   double t0(f->getTime(t1,t2));
7431   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
7432   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7433   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
7434   ret->setTime(t0,t1,t2); ret->setArray(arr2);
7435   return ret.retn();
7436 }
7437
7438 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
7439 {
7440   if(!f)
7441     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
7442   int t1,t2;
7443   double t0(f->getTime(t1,t2));
7444   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7445   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
7446   ret->setTime(t0,t1,t2);
7447   return ret;
7448 }
7449
7450 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
7451 {
7452   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
7453 }
7454
7455 /*!
7456  * 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
7457  * method should be called (getFieldOnMeshAtLevel for example).
7458  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
7459  *
7460  * \param [in] mesh - the mesh the field is lying on
7461  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
7462  *          caller is to delete this field using decrRef() as it is no more needed. 
7463  */
7464 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
7465 {
7466   MCAuto<DataArray> arrOut;
7467   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
7468   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7469   return ret2.retn();
7470 }
7471
7472 /*!
7473  * Returns a new MEDCouplingFieldInt of a given type lying on
7474  * the top level cells of the first mesh in MED file. If \a this field 
7475  * has not been constructed via file reading, an exception is thrown.
7476  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7477  *  \param [in] type - a spatial discretization of interest.
7478  *  \param [in] renumPol - specifies how to permute values of the result field according to
7479  *          the optional numbers of cells and nodes, if any. The valid values are
7480  *          - 0 - do not permute.
7481  *          - 1 - permute cells.
7482  *          - 2 - permute nodes.
7483  *          - 3 - permute cells and nodes.
7484  *
7485  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7486  *          caller is to delete this field using decrRef() as it is no more needed. 
7487  *  \throw If \a this field has not been constructed via file reading.
7488  *  \throw If the MED file is not readable.
7489  *  \throw If there is no mesh in the MED file.
7490  *  \throw If no field values of the given \a type.
7491  *  \throw If no field values lying on the top level support.
7492  *  \sa getFieldAtLevel()
7493  */
7494 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7495 {
7496   if(getFileName().empty())
7497     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7498   MCAuto<DataArray> arrOut;
7499   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7500   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7501   return ret2.retn();
7502 }
7503
7504 /*!
7505  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
7506  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7507  *  \param [in] type - a spatial discretization of the new field.
7508  *  \param [in] mesh - the supporting mesh.
7509  *  \param [in] renumPol - specifies how to permute values of the result field according to
7510  *          the optional numbers of cells and nodes, if any. The valid values are
7511  *          - 0 - do not permute.
7512  *          - 1 - permute cells.
7513  *          - 2 - permute nodes.
7514  *          - 3 - permute cells and nodes.
7515  *
7516  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7517  *          caller is to delete this field using decrRef() as it is no more needed. 
7518  *  \throw If no field of \a this is lying on \a mesh.
7519  *  \throw If the mesh is empty.
7520  *  \throw If no field values of the given \a type are available.
7521  *  \sa getFieldAtLevel()
7522  *  \sa getFieldOnMeshAtLevel() 
7523  */
7524 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7525 {
7526   MCAuto<DataArray> arrOut;
7527   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7528   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7529   return ret2.retn();
7530 }
7531
7532 /*!
7533  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7534  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7535  *  \param [in] type - a spatial discretization of interest.
7536  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7537  *  \param [in] mesh - the supporting mesh.
7538  *  \param [in] renumPol - specifies how to permute values of the result field according to
7539  *          the optional numbers of cells and nodes, if any. The valid values are
7540  *          - 0 - do not permute.
7541  *          - 1 - permute cells.
7542  *          - 2 - permute nodes.
7543  *          - 3 - permute cells and nodes.
7544  *
7545  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7546  *          caller is to delete this field using decrRef() as it is no more needed. 
7547  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7548  *  \throw If no field of \a this is lying on \a mesh.
7549  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7550  *  \sa getFieldAtLevel()
7551  *  \sa getFieldOnMeshAtLevel() 
7552  */
7553 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7554 {
7555   MCAuto<DataArray> arrOut;
7556   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7557   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7558   return ret2.retn();
7559 }
7560
7561 /*!
7562  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7563  * This method is called "Old" because in MED3 norm a field has only one meshName
7564  * attached, so this method is for readers of MED2 files. If \a this field 
7565  * has not been constructed via file reading, an exception is thrown.
7566  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7567  *  \param [in] type - a spatial discretization of interest.
7568  *  \param [in] mName - a name of the supporting mesh.
7569  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7570  *  \param [in] renumPol - specifies how to permute values of the result field according to
7571  *          the optional numbers of cells and nodes, if any. The valid values are
7572  *          - 0 - do not permute.
7573  *          - 1 - permute cells.
7574  *          - 2 - permute nodes.
7575  *          - 3 - permute cells and nodes.
7576  *
7577  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7578  *          caller is to delete this field using decrRef() as it is no more needed. 
7579  *  \throw If the MED file is not readable.
7580  *  \throw If there is no mesh named \a mName in the MED file.
7581  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7582  *  \throw If \a this field has not been constructed via file reading.
7583  *  \throw If no field of \a this is lying on the mesh named \a mName.
7584  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7585  *  \sa getFieldAtLevel()
7586  */
7587 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7588 {
7589   if(getFileName().empty())
7590     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7591   MCAuto<DataArray> arrOut;
7592   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7593   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7594   return ret2.retn();
7595 }
7596
7597 /*!
7598  * Returns values and a profile of the field of a given type lying on a given support.
7599  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7600  *  \param [in] type - a spatial discretization of the field.
7601  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7602  *  \param [in] mesh - the supporting mesh.
7603  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7604  *          field of interest lies on. If the field lies on all entities of the given
7605  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7606  *          using decrRef() as it is no more needed.  
7607  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7608  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7609  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7610  *  \throw If no field of \a this is lying on \a mesh.
7611  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7612  */
7613 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7614 {
7615   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7616   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7617 }
7618
7619 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7620 {
7621   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7622   if(!pt)
7623     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7624   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7625   if(!ret)
7626     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 !");
7627   return ret;
7628 }
7629
7630 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7631 {
7632   return contentNotNull()->getUndergroundDataArrayTemplate();
7633 }
7634
7635 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7636
7637 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7638 {
7639 }
7640
7641 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7642 {
7643 }
7644
7645 /*!
7646  * \param [in] fieldId field id in C mode
7647  */
7648 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7649 {
7650   med_field_type typcha;
7651   std::string dtunitOut;
7652   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut));
7653   setDtUnit(dtunitOut.c_str());
7654   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7655 }
7656
7657 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 MEDFileEntities *entities)
7658 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7659 {
7660   setDtUnit(dtunit.c_str());
7661   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7662 }
7663 catch(INTERP_KERNEL::Exception& e)
7664 {
7665     throw e;
7666 }
7667
7668 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7669 {
7670   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7671   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7672     ret+=(*it).capacity();
7673   return ret;
7674 }
7675
7676 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7677 {
7678   std::vector<const BigMemoryObject *> ret;
7679   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7680     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7681   return ret;
7682 }
7683
7684 /*!
7685  * 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
7686  * NULL.
7687  */
7688 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7689 {
7690   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7691   ret->setInfo(_infos);
7692   int sz=(int)_time_steps.size();
7693   for(const int *id=startIds;id!=endIds;id++)
7694     {
7695       if(*id>=0 && *id<sz)
7696         {
7697           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7698           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7699           if(tse)
7700             {
7701               tse->incrRef();
7702               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7703             }
7704           ret->pushBackTimeStep(tse2);
7705         }
7706       else
7707         {
7708           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7709           oss << " ! Should be in [0," << sz << ") !";
7710           throw INTERP_KERNEL::Exception(oss.str());
7711         }
7712     }
7713   if(ret->getNumberOfTS()>0)
7714     ret->synchronizeNameScope();
7715   ret->copyNameScope(*this);
7716   return ret.retn();
7717 }
7718
7719 /*!
7720  * 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
7721  * NULL.
7722  */
7723 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7724 {
7725   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7726   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7727   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7728   ret->setInfo(_infos);
7729   int sz=(int)_time_steps.size();
7730   int j=bg;
7731   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7732     {
7733       if(j>=0 && j<sz)
7734         {
7735           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7736           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7737           if(tse)
7738             {
7739               tse->incrRef();
7740               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7741             }
7742           ret->pushBackTimeStep(tse2);
7743         }
7744       else
7745         {
7746           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7747           oss << " ! Should be in [0," << sz << ") !";
7748           throw INTERP_KERNEL::Exception(oss.str());
7749         }
7750     }
7751   if(ret->getNumberOfTS()>0)
7752     ret->synchronizeNameScope();
7753   ret->copyNameScope(*this);
7754   return ret.retn();
7755 }
7756
7757 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7758 {
7759   int id=0;
7760   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7761   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7762     {
7763       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7764       if(!cur)
7765         continue;
7766       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7767       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7768         ids->pushBackSilent(id);
7769     }
7770   return buildFromTimeStepIds(ids->begin(),ids->end());
7771 }
7772
7773 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7774 {
7775   int id=0;
7776   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7777   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7778     {
7779       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7780       if(!cur)
7781         continue;
7782       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7783       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7784         ids->pushBackSilent(id);
7785     }
7786   return buildFromTimeStepIds(ids->begin(),ids->end());
7787 }
7788
7789 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
7790 {
7791   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7792     if((*it).isNotNull())
7793       if((*it)->presenceOfStructureElements())
7794         return true;
7795   return false;
7796 }
7797
7798 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
7799 {
7800   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7801     if((*it).isNotNull())
7802       if(!(*it)->onlyStructureElements())
7803         return false;
7804   return true;
7805 }
7806
7807 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
7808 {
7809   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7810   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7811     if((*it).isNotNull())
7812       {
7813         if((*it)->presenceOfStructureElements())
7814           {
7815             if(!(*it)->onlyStructureElements())
7816               {
7817                 (*it)->killStructureElements();
7818                 ret.push_back(*it);
7819               }
7820           }
7821         else
7822           {
7823             ret.push_back(*it);
7824           }
7825       }
7826   _time_steps=ret;
7827 }
7828
7829 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
7830 {
7831   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7832   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7833     if((*it).isNotNull())
7834       {
7835         if((*it)->presenceOfStructureElements())
7836           {
7837             if(!(*it)->onlyStructureElements())
7838               (*it)->keepOnlyStructureElements();
7839             ret.push_back(*it);
7840           }
7841       }
7842   _time_steps=ret;
7843 }
7844
7845 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
7846 {
7847   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7848   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7849     if((*it).isNotNull())
7850       (*it)->keepOnlyOnSE(seName);
7851 }
7852
7853 void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
7854 {
7855   std::vector< std::pair<std::string,std::string> > ps2;
7856   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7857     if((*it).isNotNull())
7858       {
7859         (*it)->getMeshSENames(ps2);
7860         break;
7861       }
7862   if(ps2.empty())
7863     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
7864   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7865     if((*it).isNotNull())
7866       {
7867         std::vector< std::pair<std::string,std::string> > ps3;
7868         (*it)->getMeshSENames(ps3);
7869         if(ps2!=ps3)
7870           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
7871       }
7872   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
7873     {
7874       std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
7875       if(it2==ps.end())
7876         ps.push_back(*it);
7877     }
7878 }
7879
7880 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7881 {
7882   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7883     {
7884       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7885       if(!cur)
7886         continue;
7887       if(cur->presenceOfMultiDiscPerGeoType())
7888         return true;
7889     }
7890   return false;
7891 }
7892
7893 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7894 {
7895   return _infos;
7896 }
7897
7898 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7899 {
7900   _infos=info;
7901 }
7902
7903 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7904 {
7905   int ret=0;
7906   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7907     {
7908       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7909       if(pt->isDealingTS(iteration,order))
7910         return ret;
7911     }
7912   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7913   std::vector< std::pair<int,int> > vp=getIterations();
7914   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7915     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7916   throw INTERP_KERNEL::Exception(oss.str());
7917 }
7918
7919 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7920 {
7921   return *_time_steps[getTimeStepPos(iteration,order)];
7922 }
7923
7924 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7925 {
7926   return *_time_steps[getTimeStepPos(iteration,order)];
7927 }
7928
7929 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7930 {
7931   if(_time_steps.empty())
7932     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7933   return _time_steps[0]->getMeshName();
7934 }
7935
7936 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7937 {
7938   std::string oldName(getMeshName());
7939   std::vector< std::pair<std::string,std::string> > v(1);
7940   v[0].first=oldName; v[0].second=newMeshName;
7941   changeMeshNames(v);
7942 }
7943
7944 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7945 {
7946   bool ret=false;
7947   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7948     {
7949       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7950       if(cur)
7951         ret=cur->changeMeshNames(modifTab) || ret;
7952     }
7953   return ret;
7954 }
7955
7956 /*!
7957  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7958  */
7959 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7960 {
7961   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7962 }
7963
7964 /*!
7965  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7966  */
7967 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7968 {
7969   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7970 }
7971
7972 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7973                                                                        MEDFileFieldGlobsReal& glob)
7974 {
7975   bool ret=false;
7976   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7977     {
7978       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7979       if(f1ts)
7980         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7981     }
7982   return ret;
7983 }
7984
7985 void MEDFileAnyTypeFieldMultiTSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
7986 {
7987   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7988     if((*it).isNotNull())
7989       {
7990         visitor.newTimeStepEntry(*it);
7991         (*it)->accept(visitor);
7992         visitor.endTimeStepEntry(*it);
7993       }
7994 }
7995
7996 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7997 {
7998   std::string startLine(bkOffset,' ');
7999   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
8000   if(fmtsId>=0)
8001     oss << " (" << fmtsId << ")";
8002   oss << " has the following name: \"" << _name << "\"." << std::endl;
8003   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
8004   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
8005     {
8006       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
8007     }
8008   int i=0;
8009   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8010     {
8011       std::string chapter(17,'0'+i);
8012       oss << startLine << chapter << std::endl;
8013       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
8014       if(cur)
8015         cur->simpleRepr(bkOffset+2,oss,i);
8016       else
8017         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
8018       oss << startLine << chapter << std::endl;
8019     }
8020 }
8021
8022 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
8023 {
8024   std::size_t sz=_time_steps.size();
8025   std::vector< std::pair<int,int> > ret(sz);
8026   ret1.resize(sz);
8027   for(std::size_t i=0;i<sz;i++)
8028     {
8029       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
8030       if(f1ts)
8031         {
8032           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
8033         }
8034       else
8035         {
8036           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
8037           throw INTERP_KERNEL::Exception(oss.str());
8038         }
8039     }
8040   return ret;
8041 }
8042
8043 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
8044 {
8045   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
8046   if(!tse2)
8047     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
8048   checkCoherencyOfType(tse2);
8049   if(_time_steps.empty())
8050     {
8051       setName(tse2->getName().c_str());
8052       setInfo(tse2->getInfo());
8053     }
8054   checkThatComponentsMatch(tse2->getInfo());
8055   if(getDtUnit().empty() && !tse->getDtUnit().empty())
8056     setDtUnit(tse->getDtUnit());
8057   _time_steps.push_back(tse);
8058 }
8059
8060 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
8061 {
8062   std::size_t nbOfCompo=_infos.size();
8063   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8064     {
8065       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
8066       if(cur)
8067         {
8068           if((cur->getInfo()).size()!=nbOfCompo)
8069             {
8070               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
8071               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
8072               throw INTERP_KERNEL::Exception(oss.str());
8073             }
8074           cur->copyNameScope(*this);
8075         }
8076     }
8077 }
8078
8079 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8080 {
8081   _time_steps.resize(nbPdt);
8082   for(int i=0;i<nbPdt;i++)
8083     {
8084       std::vector< std::pair<int,int> > ts;
8085       med_int numdt=0,numo=0;
8086       med_float dt=0.0;
8087       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
8088       switch(fieldTyp)
8089       {
8090         case MED_FLOAT64:
8091           {
8092             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
8093             break;
8094           }
8095         case MED_INT32:
8096           {
8097             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
8098             break;
8099           }
8100         default:
8101           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
8102       }
8103       if(loadAll)
8104         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
8105       else
8106         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
8107       synchronizeNameScope();
8108     }
8109 }
8110
8111 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
8112 {
8113   if(_time_steps.empty())
8114     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
8115   checkThatNbOfCompoOfTSMatchThis();
8116   std::vector<std::string> infos(getInfo());
8117   int nbComp=infos.size();
8118   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
8119   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
8120   for(int i=0;i<nbComp;i++)
8121     {
8122       std::string info=infos[i];
8123       std::string c,u;
8124       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
8125       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
8126       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
8127     }
8128   if(_name.empty())
8129     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
8130   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
8131   int nbOfTS=_time_steps.size();
8132   for(int i=0;i<nbOfTS;i++)
8133     _time_steps[i]->writeLL(fid,opts,*this);
8134 }
8135
8136 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
8137 {
8138   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8139     {
8140       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8141       if(elt)
8142         elt->loadBigArraysRecursively(fid,nasc);
8143     }
8144 }
8145
8146 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
8147 {
8148   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8149     {
8150       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8151       if(elt)
8152         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
8153     }
8154 }
8155
8156 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
8157 {
8158   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8159     {
8160       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8161       if(elt)
8162         elt->unloadArrays();
8163     }
8164 }
8165
8166 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
8167 {
8168   return _time_steps.size();
8169 }
8170
8171 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
8172 {
8173   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
8174   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8175     {
8176       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
8177       if(tmp)
8178         newTS.push_back(*it);
8179     }
8180   _time_steps=newTS;
8181 }
8182
8183 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
8184 {
8185   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
8186   int maxId=(int)_time_steps.size();
8187   int ii=0;
8188   std::set<int> idsToDel;
8189   for(const int *id=startIds;id!=endIds;id++,ii++)
8190     {
8191       if(*id>=0 && *id<maxId)
8192         {
8193           idsToDel.insert(*id);
8194         }
8195       else
8196         {
8197           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
8198           throw INTERP_KERNEL::Exception(oss.str());
8199         }
8200     }
8201   for(int iii=0;iii<maxId;iii++)
8202     if(idsToDel.find(iii)==idsToDel.end())
8203       newTS.push_back(_time_steps[iii]);
8204   _time_steps=newTS;
8205 }
8206
8207 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
8208 {
8209   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
8210   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
8211   if(nbOfEntriesToKill==0)
8212     return ;
8213   std::size_t sz=_time_steps.size();
8214   std::vector<bool> b(sz,true);
8215   int j=bg;
8216   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
8217     b[j]=false;
8218   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
8219   for(std::size_t i=0;i<sz;i++)
8220     if(b[i])
8221       newTS.push_back(_time_steps[i]);
8222   _time_steps=newTS;
8223 }
8224
8225 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
8226 {
8227   int ret=0;
8228   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
8229   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
8230     {
8231       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
8232       if(tmp)
8233         {
8234           int it2,ord;
8235           tmp->getTime(it2,ord);
8236           if(it2==iteration && order==ord)
8237             return ret;
8238           else
8239             oss << "(" << it2 << ","  << ord << "), ";
8240         }
8241     }
8242   throw INTERP_KERNEL::Exception(oss.str());
8243 }
8244
8245 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
8246 {
8247   int ret=0;
8248   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
8249   oss.precision(15);
8250   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
8251     {
8252       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
8253       if(tmp)
8254         {
8255           int it2,ord;
8256           double ti=tmp->getTime(it2,ord);
8257           if(fabs(time-ti)<eps)
8258             return ret;
8259           else
8260             oss << ti << ", ";
8261         }
8262     }
8263   throw INTERP_KERNEL::Exception(oss.str());
8264 }
8265
8266 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
8267 {
8268   int lgth=_time_steps.size();
8269   std::vector< std::pair<int,int> > ret(lgth);
8270   for(int i=0;i<lgth;i++)
8271     _time_steps[i]->fillIteration(ret[i]);
8272   return ret;
8273 }
8274
8275 /*!
8276  * 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'
8277  * This method returns two things.
8278  * - The absolute dimension of 'this' in first parameter. 
8279  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
8280  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
8281  *
8282  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
8283  * Only these 3 discretizations will be taken into account here.
8284  *
8285  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
8286  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
8287  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
8288  *
8289  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
8290  * 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'.
8291  * 
8292  * Let's consider the typical following case :
8293  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
8294  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
8295  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
8296  *   TETRA4 and SEG2
8297  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
8298  *
8299  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
8300  * 
8301  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
8302  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
8303  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
8304  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
8305  */
8306 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8307 {
8308   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
8309 }
8310
8311 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
8312 {
8313   if(pos<0 || pos>=(int)_time_steps.size())
8314     {
8315       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8316       throw INTERP_KERNEL::Exception(oss.str());
8317     }
8318   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8319   if(item==0)
8320     {
8321       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8322       oss << "\nTry to use following method eraseEmptyTS !";
8323       throw INTERP_KERNEL::Exception(oss.str());
8324     }
8325   return item;
8326 }
8327
8328 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
8329 {
8330   if(pos<0 || pos>=(int)_time_steps.size())
8331     {
8332       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8333       throw INTERP_KERNEL::Exception(oss.str());
8334     }
8335   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8336   if(item==0)
8337     {
8338       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8339       oss << "\nTry to use following method eraseEmptyTS !";
8340       throw INTERP_KERNEL::Exception(oss.str());
8341     }
8342   return item;
8343 }
8344
8345 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
8346 {
8347   std::vector<std::string> ret;
8348   std::set<std::string> ret2;
8349   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8350     {
8351       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
8352       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8353         if(ret2.find(*it2)==ret2.end())
8354           {
8355             ret.push_back(*it2);
8356             ret2.insert(*it2);
8357           }
8358     }
8359   return ret;
8360 }
8361
8362 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
8363 {
8364   std::vector<std::string> ret;
8365   std::set<std::string> ret2;
8366   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8367     {
8368       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8369       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8370         if(ret2.find(*it2)==ret2.end())
8371           {
8372             ret.push_back(*it2);
8373             ret2.insert(*it2);
8374           }
8375     }
8376   return ret;
8377 }
8378
8379 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
8380 {
8381   std::vector<std::string> ret;
8382   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8383     {
8384       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
8385       ret.insert(ret.end(),tmp.begin(),tmp.end());
8386     }
8387   return ret;
8388 }
8389
8390 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
8391 {
8392   std::vector<std::string> ret;
8393   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8394     {
8395       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
8396       ret.insert(ret.end(),tmp.begin(),tmp.end());
8397     }
8398   return ret;
8399 }
8400
8401 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8402 {
8403   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8404     (*it)->changePflsRefsNamesGen2(mapOfModif);
8405 }
8406
8407 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8408 {
8409   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8410     (*it)->changeLocsRefsNamesGen2(mapOfModif);
8411 }
8412
8413 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
8414 {
8415   int lgth=_time_steps.size();
8416   std::vector< std::vector<TypeOfField> > ret(lgth);
8417   for(int i=0;i<lgth;i++)
8418     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
8419   return ret;
8420 }
8421
8422 /*!
8423  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
8424  */
8425 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
8426 {
8427   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
8428 }
8429
8430 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
8431 {
8432   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
8433   std::size_t i=0;
8434   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8435     {
8436       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
8437         ret->_time_steps[i]=(*it)->deepCopy();
8438     }
8439   return ret.retn();
8440 }
8441
8442 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
8443 {
8444   std::size_t sz(_infos.size()),sz2(_time_steps.size());
8445   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
8446   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
8447   for(std::size_t i=0;i<sz;i++)
8448     {
8449       ret[i]=shallowCpy();
8450       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
8451     }
8452   for(std::size_t i=0;i<sz2;i++)
8453     {
8454       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
8455       if(ret1.size()!=sz)
8456         {
8457           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
8458           throw INTERP_KERNEL::Exception(oss.str());
8459         }
8460       ts[i]=ret1;
8461     }
8462   for(std::size_t i=0;i<sz;i++)
8463     for(std::size_t j=0;j<sz2;j++)
8464       ret[i]->_time_steps[j]=ts[j][i];
8465   return ret;
8466 }
8467
8468 /*!
8469  * This method splits into discretization each time steps in \a this.
8470  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
8471  */
8472 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
8473 {
8474   std::size_t sz(_time_steps.size());
8475   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8476   for(std::size_t i=0;i<sz;i++)
8477     {
8478       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8479       if(!timeStep)
8480         {
8481           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
8482           throw INTERP_KERNEL::Exception(oss.str());
8483         }
8484       items[i]=timeStep->splitDiscretizations();  
8485     }
8486   //
8487   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
8488   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
8489   std::vector< TypeOfField > types;
8490   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8491     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8492       {
8493         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
8494         if(ts.size()!=1)
8495           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
8496         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
8497         if(it2==types.end())
8498           types.push_back(ts[0]);
8499       }
8500   ret.resize(types.size()); ret2.resize(types.size());
8501   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8502     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8503       {
8504         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
8505         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
8506         ret2[pos].push_back(*it1);
8507       }
8508   for(std::size_t i=0;i<types.size();i++)
8509     {
8510       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8511       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
8512         elt->pushBackTimeStep(*it1);//also updates infos in elt
8513       ret[i]=elt;
8514       elt->MEDFileFieldNameScope::operator=(*this);
8515     }
8516   return ret;
8517 }
8518
8519 /*!
8520  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
8521  */
8522 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
8523 {
8524   std::size_t sz(_time_steps.size());
8525   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8526   std::size_t szOut(std::numeric_limits<std::size_t>::max());
8527   for(std::size_t i=0;i<sz;i++)
8528     {
8529       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8530       if(!timeStep)
8531         {
8532           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
8533           throw INTERP_KERNEL::Exception(oss.str());
8534         }
8535       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
8536       if(szOut==std::numeric_limits<std::size_t>::max())
8537         szOut=items[i].size();
8538       else
8539         if(items[i].size()!=szOut)
8540           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
8541     }
8542   if(szOut==std::numeric_limits<std::size_t>::max())
8543     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
8544   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
8545   for(std::size_t i=0;i<szOut;i++)
8546     {
8547       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8548       for(std::size_t j=0;j<sz;j++)
8549         elt->pushBackTimeStep(items[j][i]);
8550       ret[i]=elt;
8551       elt->MEDFileFieldNameScope::operator=(*this);
8552     }
8553   return ret;
8554 }
8555
8556 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
8557 {
8558   _name=field->getName();
8559   if(_name.empty())
8560     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
8561   if(!arr)
8562     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
8563   _infos=arr->getInfoOnComponents();
8564 }
8565
8566 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
8567 {
8568   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
8569   if(_name!=field->getName())
8570     {
8571       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
8572       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
8573       throw INTERP_KERNEL::Exception(oss.str());
8574     }
8575   if(!arr)
8576     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
8577   checkThatComponentsMatch(arr->getInfoOnComponents());
8578 }
8579
8580 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
8581 {
8582   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
8583   if(getInfo().size()!=compos.size())
8584     {
8585       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
8586       oss << " number of components of element to append (" << compos.size() << ") !";
8587       throw INTERP_KERNEL::Exception(oss.str());
8588     }
8589   if(_infos!=compos)
8590     {
8591       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
8592       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
8593       oss << " But compo in input fields are : ";
8594       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
8595       oss << " !";
8596       throw INTERP_KERNEL::Exception(oss.str());
8597     }
8598 }
8599
8600 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
8601 {
8602   std::size_t sz=_infos.size();
8603   int j=0;
8604   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
8605     {
8606       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8607       if(elt)
8608         if(elt->getInfo().size()!=sz)
8609           {
8610             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
8611             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
8612             throw INTERP_KERNEL::Exception(oss.str());
8613           }
8614     }
8615 }
8616
8617 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8618 {
8619   if(!field)
8620     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8621   if(!_time_steps.empty())
8622     checkCoherencyOfTinyInfo(field,arr);
8623   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8624   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8625   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8626   copyTinyInfoFrom(field,arr);
8627   _time_steps.push_back(obj);
8628 }
8629
8630 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8631 {
8632   if(!field)
8633     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8634   if(!_time_steps.empty())
8635     checkCoherencyOfTinyInfo(field,arr);
8636   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8637   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8638   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8639   copyTinyInfoFrom(field,arr);
8640   _time_steps.push_back(obj);
8641 }
8642
8643 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8644 {
8645   int sz=(int)_time_steps.size();
8646   if(i<0 || i>=sz)
8647     {
8648       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8649       throw INTERP_KERNEL::Exception(oss.str());
8650     }
8651   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8652   if(tsPtr)
8653     {
8654       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8655         {
8656           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8657           throw INTERP_KERNEL::Exception(oss.str());
8658         }
8659     }
8660   _time_steps[i]=ts;
8661 }
8662
8663 //= MEDFileFieldMultiTSWithoutSDA
8664
8665 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 MEDFileEntities *entities)
8666 {
8667   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8668 }
8669
8670 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8671 {
8672 }
8673
8674 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8675 {
8676 }
8677
8678 /*!
8679  * \param [in] fieldId field id in C mode
8680  */
8681 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8682 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8683 {
8684 }
8685 catch(INTERP_KERNEL::Exception& e)
8686 { throw e; }
8687
8688 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 MEDFileEntities *entities)
8689 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8690 {
8691 }
8692 catch(INTERP_KERNEL::Exception& e)
8693 { throw e; }
8694
8695 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8696 {
8697   return new MEDFileField1TSWithoutSDA;
8698 }
8699
8700 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8701 {
8702   if(!f1ts)
8703     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8704   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8705   if(!f1tsC)
8706     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8707 }
8708
8709 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8710 {
8711   return MEDFileField1TSWithoutSDA::TYPE_STR;
8712 }
8713
8714 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8715 {
8716   return new MEDFileFieldMultiTSWithoutSDA(*this);
8717 }
8718
8719 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8720 {
8721   return new MEDFileFieldMultiTSWithoutSDA;
8722 }
8723
8724 /*!
8725  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8726  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8727  */
8728 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
8729 {
8730   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8731   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8732   if(!myF1TSC)
8733     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8734   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8735 }
8736
8737 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8738 {
8739   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8740   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8741   int i=0;
8742   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8743     {
8744       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8745       if(eltToConv)
8746         {
8747           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8748           if(!eltToConvC)
8749             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8750           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8751           ret->setIteration(i,elt);
8752         }
8753     }
8754   return ret.retn();
8755 }
8756
8757 //= MEDFileAnyTypeFieldMultiTS
8758
8759 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8760 {
8761 }
8762
8763 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8764 try:MEDFileFieldGlobsReal(fid)
8765 {
8766   _content=BuildContentFrom(fid,loadAll,ms);
8767   loadGlobals(fid);
8768 }
8769 catch(INTERP_KERNEL::Exception& e)
8770 {
8771     throw e;
8772 }
8773
8774 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8775 {
8776   med_field_type typcha;
8777   std::vector<std::string> infos;
8778   std::string dtunit;
8779   int i(-1);
8780   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit);
8781   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8782   switch(typcha)
8783   {
8784     case MED_FLOAT64:
8785       {
8786         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8787         break;
8788       }
8789     case MED_INT32:
8790       {
8791         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8792         break;
8793       }
8794     default:
8795       {
8796         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
8797         throw INTERP_KERNEL::Exception(oss.str());
8798       }
8799   }
8800   ret->setDtUnit(dtunit.c_str());
8801   return ret.retn();
8802 }
8803
8804 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8805 {
8806   med_field_type typcha;
8807   //
8808   std::vector<std::string> infos;
8809   std::string dtunit,fieldName;
8810   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
8811   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8812   switch(typcha)
8813   {
8814     case MED_FLOAT64:
8815       {
8816         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8817         break;
8818       }
8819     case MED_INT32:
8820       {
8821         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8822         break;
8823       }
8824     default:
8825       {
8826         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
8827         throw INTERP_KERNEL::Exception(oss.str());
8828       }
8829   }
8830   ret->setDtUnit(dtunit.c_str());
8831   return ret.retn();
8832 }
8833
8834 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8835 {
8836   if(!c)
8837     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8838   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8839     {
8840       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8841       ret->_content=c;  c->incrRef();
8842       return ret.retn();
8843     }
8844   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8845     {
8846       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8847       ret->_content=c;  c->incrRef();
8848       return ret.retn();
8849     }
8850   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8851 }
8852
8853 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8854 {
8855   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8856   std::string fileName(FileNameFromFID(fid));
8857   ret->setFileName(fileName);
8858   return ret;
8859 }
8860
8861 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8862 try:MEDFileFieldGlobsReal(fid)
8863 {
8864   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8865   loadGlobals(fid);
8866 }
8867 catch(INTERP_KERNEL::Exception& e)
8868 {
8869     throw e;
8870 }
8871
8872 //= MEDFileIntFieldMultiTSWithoutSDA
8873
8874 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 MEDFileEntities *entities)
8875 {
8876   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8877 }
8878
8879 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8880 {
8881 }
8882
8883 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8884 {
8885 }
8886
8887 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 MEDFileEntities *entities)
8888 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8889 {
8890 }
8891 catch(INTERP_KERNEL::Exception& e)
8892 { throw e; }
8893
8894 /*!
8895  * \param [in] fieldId field id in C mode
8896  */
8897 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8898 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8899 {
8900 }
8901 catch(INTERP_KERNEL::Exception& e)
8902 { throw e; }
8903
8904 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8905 {
8906   return new MEDFileIntField1TSWithoutSDA;
8907 }
8908
8909 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8910 {
8911   if(!f1ts)
8912     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8913   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8914   if(!f1tsC)
8915     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8916 }
8917
8918 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8919 {
8920   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8921 }
8922
8923 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8924 {
8925   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8926 }
8927
8928 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8929 {
8930   return new MEDFileIntFieldMultiTSWithoutSDA;
8931 }
8932
8933 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8934 {
8935   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8936   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8937   int i=0;
8938   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8939     {
8940       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8941       if(eltToConv)
8942         {
8943           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8944           if(!eltToConvC)
8945             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8946           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8947           ret->setIteration(i,elt);
8948         }
8949     }
8950   return ret.retn();
8951 }
8952
8953 //= MEDFileAnyTypeFieldMultiTS
8954
8955 /*!
8956  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8957  * that has been read from a specified MED file.
8958  *  \param [in] fileName - the name of the MED file to read.
8959  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8960  *          is to delete this field using decrRef() as it is no more needed.
8961  *  \throw If reading the file fails.
8962  */
8963 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8964 {
8965   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8966   return New(fid,loadAll);
8967 }
8968
8969 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8970 {
8971   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8972   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8973   ret->loadGlobals(fid);
8974   return ret.retn();
8975 }
8976
8977 /*!
8978  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8979  * that has been read from a specified MED file.
8980  *  \param [in] fileName - the name of the MED file to read.
8981  *  \param [in] fieldName - the name of the field to read.
8982  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8983  *          is to delete this field using decrRef() as it is no more needed.
8984  *  \throw If reading the file fails.
8985  *  \throw If there is no field named \a fieldName in the file.
8986  */
8987 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8988 {
8989   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8990   return New(fid,fieldName,loadAll);
8991 }
8992
8993 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8994 {
8995   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8996   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8997   ret->loadGlobals(fid);
8998   return ret.retn();
8999 }
9000
9001 /*!
9002  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9003  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9004  *
9005  * \warning this is a shallow copy constructor
9006  */
9007 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9008 {
9009   if(!shallowCopyOfContent)
9010     {
9011       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
9012       otherPtr->incrRef();
9013       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
9014     }
9015   else
9016     {
9017       _content=other.shallowCpy();
9018     }
9019 }
9020
9021 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
9022 {
9023   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
9024   if(!ret)
9025     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
9026   return ret;
9027 }
9028
9029 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
9030 {
9031   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
9032   if(!ret)
9033     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
9034   return ret;
9035 }
9036
9037 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
9038 {
9039   return contentNotNullBase()->getPflsReallyUsed2();
9040 }
9041
9042 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
9043 {
9044   return contentNotNullBase()->getLocsReallyUsed2();
9045 }
9046
9047 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
9048 {
9049   return contentNotNullBase()->getPflsReallyUsedMulti2();
9050 }
9051
9052 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
9053 {
9054   return contentNotNullBase()->getLocsReallyUsedMulti2();
9055 }
9056
9057 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9058 {
9059   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
9060 }
9061
9062 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9063 {
9064   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
9065 }
9066
9067 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
9068 {
9069   return contentNotNullBase()->getNumberOfTS();
9070 }
9071
9072 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
9073 {
9074   contentNotNullBase()->eraseEmptyTS();
9075 }
9076
9077 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
9078 {
9079   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
9080 }
9081
9082 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
9083 {
9084   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
9085 }
9086
9087 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
9088 {
9089   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
9090   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9091   ret->_content=c;
9092   return ret.retn();
9093 }
9094
9095 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
9096 {
9097   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
9098   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9099   ret->_content=c;
9100   return ret.retn();
9101 }
9102
9103 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
9104 {
9105   return contentNotNullBase()->getIterations();
9106 }
9107
9108 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
9109 {
9110   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
9111     pushBackTimeStep(*it);
9112 }
9113
9114 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
9115 {
9116   if(!fmts)
9117     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
9118   int nbOfTS(fmts->getNumberOfTS());
9119   for(int i=0;i<nbOfTS;i++)
9120     {
9121       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
9122       pushBackTimeStep(elt);
9123     }
9124 }
9125
9126 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
9127 {
9128   if(!f1ts)
9129     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
9130   checkCoherencyOfType(f1ts);
9131   f1ts->incrRef();
9132   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
9133   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
9134   c->incrRef();
9135   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
9136   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
9137     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
9138   _content->pushBackTimeStep(cSafe);
9139   appendGlobs(*f1ts,1e-12);
9140 }
9141
9142 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
9143 {
9144   contentNotNullBase()->synchronizeNameScope();
9145 }
9146
9147 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
9148 {
9149   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
9150 }
9151
9152 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
9153 {
9154   return contentNotNullBase()->getPosGivenTime(time,eps);
9155 }
9156
9157 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
9158 {
9159   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
9160 }
9161
9162 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
9163 {
9164   return contentNotNullBase()->getTypesOfFieldAvailable();
9165 }
9166
9167 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
9168 {
9169   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
9170 }
9171
9172 std::string MEDFileAnyTypeFieldMultiTS::getName() const
9173 {
9174   return contentNotNullBase()->getName();
9175 }
9176
9177 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
9178 {
9179   contentNotNullBase()->setName(name);
9180 }
9181
9182 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
9183 {
9184   return contentNotNullBase()->getDtUnit();
9185 }
9186
9187 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
9188 {
9189   contentNotNullBase()->setDtUnit(dtUnit);
9190 }
9191
9192 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
9193 {
9194   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
9195 }
9196
9197 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
9198 {
9199   return contentNotNullBase()->getTimeSteps(ret1);
9200 }
9201
9202 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
9203 {
9204   return contentNotNullBase()->getMeshName();
9205 }
9206
9207 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
9208 {
9209   contentNotNullBase()->setMeshName(newMeshName);
9210 }
9211
9212 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9213 {
9214   return contentNotNullBase()->changeMeshNames(modifTab);
9215 }
9216
9217 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
9218 {
9219   return contentNotNullBase()->getInfo();
9220 }
9221
9222 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
9223 {
9224   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
9225 }
9226
9227 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
9228 {
9229   return contentNotNullBase()->setInfo(info);
9230 }
9231
9232 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
9233 {
9234   const std::vector<std::string> ret=getInfo();
9235   return (int)ret.size();
9236 }
9237
9238 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
9239 {
9240   writeGlobals(fid,*this);
9241   contentNotNullBase()->writeLL(fid,*this);
9242 }
9243
9244 /*!
9245  * This method alloc the arrays and load potentially huge arrays contained in this field.
9246  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9247  * This method can be also called to refresh or reinit values from a file.
9248  * 
9249  * \throw If the fileName is not set or points to a non readable MED file.
9250  */
9251 void MEDFileAnyTypeFieldMultiTS::loadArrays()
9252 {
9253   if(getFileName().empty())
9254     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
9255   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9256   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
9257 }
9258
9259 /*!
9260  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9261  * But once data loaded once, this method does nothing.
9262  * 
9263  * \throw If the fileName is not set or points to a non readable MED file.
9264  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
9265  */
9266 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
9267 {
9268   if(!getFileName().empty())
9269     {
9270       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9271       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
9272     }
9273 }
9274
9275 /*!
9276  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9277  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9278  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
9279  * 
9280  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
9281  */
9282 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
9283 {
9284   contentNotNullBase()->unloadArrays();
9285 }
9286
9287 /*!
9288  * 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.
9289  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
9290  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9291  * 
9292  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
9293  */
9294 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
9295 {
9296   if(!getFileName().empty())
9297     contentNotNullBase()->unloadArrays();
9298 }
9299
9300 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
9301 {
9302   std::ostringstream oss;
9303   contentNotNullBase()->simpleRepr(0,oss,-1);
9304   simpleReprGlobs(oss);
9305   return oss.str();
9306 }
9307
9308 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
9309 {
9310   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
9311 }
9312
9313 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
9314 {
9315   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
9316   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
9317   return ret;
9318 }
9319
9320 /*!
9321  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
9322  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
9323  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
9324  */
9325 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
9326 {
9327   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9328   if(!content)
9329     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
9330   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
9331   std::size_t sz(contentsSplit.size());
9332   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9333   for(std::size_t i=0;i<sz;i++)
9334     {
9335       ret[i]=shallowCpy();
9336       ret[i]->_content=contentsSplit[i];
9337     }
9338   return ret;
9339 }
9340
9341 /*!
9342  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
9343  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9344  */
9345 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
9346 {
9347   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9348   if(!content)
9349     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
9350   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
9351   std::size_t sz(contentsSplit.size());
9352   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9353   for(std::size_t i=0;i<sz;i++)
9354     {
9355       ret[i]=shallowCpy();
9356       ret[i]->_content=contentsSplit[i];
9357     }
9358   return ret;
9359 }
9360
9361 /*!
9362  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
9363  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9364  */
9365 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
9366 {
9367   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9368   if(!content)
9369     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
9370   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
9371   std::size_t sz(contentsSplit.size());
9372   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9373   for(std::size_t i=0;i<sz;i++)
9374     {
9375       ret[i]=shallowCpy();
9376       ret[i]->_content=contentsSplit[i];
9377     }
9378   return ret;
9379 }
9380
9381 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
9382 {
9383   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9384   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
9385     ret->_content=_content->deepCopy();
9386   ret->deepCpyGlobs(*this);
9387   return ret.retn();
9388 }
9389
9390 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
9391 {
9392   return _content;
9393 }
9394
9395 /*!
9396  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9397  *  \param [in] iteration - the iteration number of a required time step.
9398  *  \param [in] order - the iteration order number of required time step.
9399  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
9400  *          delete this field using decrRef() as it is no more needed.
9401  *  \throw If there is no required time step in \a this field.
9402  */
9403 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
9404 {
9405   int pos=getPosOfTimeStep(iteration,order);
9406   return getTimeStepAtPos(pos);
9407 }
9408
9409 /*!
9410  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9411  *  \param [in] time - the time of the time step of interest.
9412  *  \param [in] eps - a precision used to compare time values.
9413  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9414  *          delete this field using decrRef() as it is no more needed.
9415  *  \throw If there is no required time step in \a this field.
9416  */
9417 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
9418 {
9419   int pos=getPosGivenTime(time,eps);
9420   return getTimeStepAtPos(pos);
9421 }
9422
9423 /*!
9424  * 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.
9425  * The float64 value of time attached to the pair of integers are not considered here.
9426  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
9427  *
9428  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
9429  * \throw If there is a null pointer in \a vectFMTS.
9430  */
9431 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
9432 {
9433   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
9434   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9435   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9436   while(!lstFMTS.empty())
9437     {
9438       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9439       MEDFileAnyTypeFieldMultiTS *curIt(*it);
9440       if(!curIt)
9441         throw INTERP_KERNEL::Exception(msg);
9442       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
9443       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9444       elt.push_back(curIt); it=lstFMTS.erase(it);
9445       while(it!=lstFMTS.end())
9446         {
9447           curIt=*it;
9448           if(!curIt)
9449             throw INTERP_KERNEL::Exception(msg);
9450           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
9451           if(refIts==curIts)
9452             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9453           else
9454             it++;
9455         }
9456       ret.push_back(elt);
9457     }
9458   return ret;
9459 }
9460
9461 /*!
9462  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
9463  * All returned instances in a subvector can be safely loaded, rendered along time
9464  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
9465  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
9466  * 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).
9467  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
9468  * 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.
9469  *
9470  * \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().
9471  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
9472  * \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.
9473  * \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.
9474  *
9475  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
9476  * \throw If an element in \a vectFMTS change of spatial discretization along time.
9477  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
9478  * \thorw If some elements in \a vectFMTS do not have the same times steps.
9479  * \throw If mesh is null.
9480  * \throw If an element in \a vectFMTS is null.
9481  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
9482  */
9483 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
9484 {
9485   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
9486   if(!mesh)
9487     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
9488   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9489   if(vectFMTS.empty())
9490     return ret;
9491   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
9492   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
9493   if(!frstElt)
9494     throw INTERP_KERNEL::Exception(msg);
9495   std::size_t i=0;
9496   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
9497   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
9498   for(;it!=vectFMTS.end();it++,i++)
9499     {
9500       if(!(*it))
9501         throw INTERP_KERNEL::Exception(msg);
9502       TypeOfField tof0,tof1;
9503       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
9504         {
9505           if(tof1!=ON_NODES)
9506             vectFMTSNotNodes.push_back(*it);
9507           else
9508             vectFMTSNodes.push_back(*it);
9509         }
9510       else
9511         vectFMTSNotNodes.push_back(*it);
9512     }
9513   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
9514   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
9515   ret=retCell;
9516   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
9517     {
9518       i=0;
9519       bool isFetched(false);
9520       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
9521         {
9522           if((*it0).empty())
9523             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
9524           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
9525             { ret[i].push_back(*it2); isFetched=true; }
9526         }
9527       if(!isFetched)
9528         {
9529           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
9530           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
9531           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
9532         }
9533     }
9534   fsc=cmps;
9535   return ret;
9536 }
9537
9538 /*!
9539  * 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.
9540  * \param [out] cmps - same size than the returned vector.
9541  */
9542 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
9543 {
9544   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9545   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9546   while(!lstFMTS.empty())
9547     {
9548       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9549       MEDFileAnyTypeFieldMultiTS *ref(*it);
9550       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9551       elt.push_back(ref); it=lstFMTS.erase(it);
9552       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
9553       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
9554       while(it!=lstFMTS.end())
9555         {
9556           MEDFileAnyTypeFieldMultiTS *curIt(*it);
9557           if(cmp->isEqual(curIt))
9558             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9559           else
9560             it++;
9561         }
9562       ret.push_back(elt); cmps.push_back(cmp);
9563     }
9564   return ret;
9565 }
9566
9567 /*!
9568  * 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.
9569  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
9570  *
9571  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
9572  * \throw If \a f0 or \a f1 change of spatial discretization along time.
9573  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
9574  * \thorw If \a f0 and \a f1 do not have the same times steps.
9575  * \throw If mesh is null.
9576  * \throw If \a f0 or \a f1 is null.
9577  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
9578  */
9579 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
9580 {
9581   if(!mesh)
9582     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
9583   if(!f0 || !f1)
9584     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
9585   if(f0->getMeshName()!=mesh->getName())
9586     {
9587       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9588       throw INTERP_KERNEL::Exception(oss.str());
9589     }
9590   if(f1->getMeshName()!=mesh->getName())
9591     {
9592       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9593       throw INTERP_KERNEL::Exception(oss.str());
9594     }
9595   int nts=f0->getNumberOfTS();
9596   if(nts!=f1->getNumberOfTS())
9597     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
9598   if(nts==0)
9599     return nts;
9600   for(int i=0;i<nts;i++)
9601     {
9602       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
9603       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
9604       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
9605       if(tofs0.size()!=1 || tofs1.size()!=1)
9606         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
9607       if(i!=0)
9608         {
9609           if(tof0!=tofs0[0] || tof1!=tofs1[0])
9610             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
9611         }
9612       else
9613         { tof0=tofs0[0]; tof1=tofs1[0]; }
9614       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9615         {
9616           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() << ") !";
9617           throw INTERP_KERNEL::Exception(oss.str());
9618         }
9619       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9620         {
9621           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() << ") !";
9622           throw INTERP_KERNEL::Exception(oss.str());
9623         }
9624       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9625         {
9626           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() << ") !";
9627           throw INTERP_KERNEL::Exception(oss.str());
9628         }
9629     }
9630   return nts;
9631 }
9632
9633 /*!
9634  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9635  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9636  *
9637  * \return A new object that the caller is responsible to deallocate.
9638  */
9639 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9640 {
9641   if(!mm)
9642     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9643   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9644   int nbTS(getNumberOfTS());
9645   for(int i=0;i<nbTS;i++)
9646     {
9647       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9648       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9649       fmtsOut->pushBackTimeStep(f1tsOut);
9650     }
9651   return fmtsOut.retn();
9652 }
9653
9654 template<class T>
9655 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9656 {
9657   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9658   if(f1tss.empty())
9659     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9660   std::size_t sz(f1tss.size()),i(0);
9661   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9662   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9663     {
9664       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9665       if(!elt)
9666         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9667       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9668     }
9669   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9670   if(!retc)
9671     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9672   retc->aggregate(f1tsw,dts);
9673   ret->setDtUnit(f1tss[0]->getDtUnit());
9674   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9675 }
9676
9677 template<class T>
9678 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9679 {
9680   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9681   if(fmtss.empty())
9682     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9683   std::size_t sz(fmtss.size());
9684   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9685     {
9686       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9687       if(!elt)
9688         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9689     }
9690   int nbTS(fmtss[0]->getNumberOfTS());
9691   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9692     if((*it)->getNumberOfTS()!=nbTS)
9693       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9694   for(int iterTS=0;iterTS<nbTS;iterTS++)
9695     {
9696       std::size_t i(0);
9697       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9698       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9699       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9700         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9701       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9702       ret->pushBackTimeStep(f1ts);
9703       ret->setDtUnit(f1ts->getDtUnit());
9704     }
9705   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9706 }
9707
9708 /*!
9709  * \a dts and \a ftmss are expected to have same size.
9710  */
9711 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9712 {
9713   if(fmtss.empty())
9714     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9715   std::size_t sz(fmtss.size());
9716   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9717   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9718   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9719     {
9720       if(!(*it))
9721         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9722       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9723       if(elt1)
9724         {
9725           fmtss1.push_back(elt1);
9726           continue;
9727         }
9728       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9729       if(elt2)
9730         {
9731           fmtss2.push_back(elt2);
9732           continue;
9733         }
9734       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9735     }
9736   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9737     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9738   if(fmtss1.size()==sz)
9739     return AggregateHelperFMTS<double>(fmtss1,dts);
9740   if(fmtss2.size()!=sz)
9741     return AggregateHelperFMTS<int>(fmtss2,dts);
9742   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9743 }
9744
9745 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9746 {
9747   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9748 }
9749
9750 //= MEDFileFieldMultiTS
9751
9752 /*!
9753  * Returns a new empty instance of MEDFileFieldMultiTS.
9754  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9755  *          is to delete this field using decrRef() as it is no more needed.
9756  */
9757 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9758 {
9759   return new MEDFileFieldMultiTS;
9760 }
9761
9762 /*!
9763  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9764  * that has been read from a specified MED file.
9765  *  \param [in] fileName - the name of the MED file to read.
9766  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9767  *          is to delete this field using decrRef() as it is no more needed.
9768  *  \throw If reading the file fails.
9769  */
9770 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9771 {
9772   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9773   return New(fid,loadAll);
9774 }
9775
9776 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9777 {
9778   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9779   ret->contentNotNull();//to check that content type matches with \a this type.
9780   return ret.retn();
9781 }
9782
9783 /*!
9784  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9785  * that has been read from a specified MED file.
9786  *  \param [in] fileName - the name of the MED file to read.
9787  *  \param [in] fieldName - the name of the field to read.
9788  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9789  *          is to delete this field using decrRef() as it is no more needed.
9790  *  \throw If reading the file fails.
9791  *  \throw If there is no field named \a fieldName in the file.
9792  */
9793 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9794 {
9795   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9796   return New(fid,fieldName,loadAll);
9797 }
9798
9799 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9800 {
9801   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9802   ret->contentNotNull();//to check that content type matches with \a this type.
9803   return ret.retn();
9804 }
9805
9806 /*!
9807  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9808  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9809  *
9810  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9811  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9812  * \warning this is a shallow copy constructor
9813  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9814  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9815  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9816  *          is to delete this field using decrRef() as it is no more needed.
9817  */
9818 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9819 {
9820   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9821 }
9822
9823 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9824 {
9825   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9826   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9827   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
9828   ret->contentNotNull();//to check that content type matches with \a this type.
9829   return ret.retn();
9830 }
9831
9832 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9833 {
9834   return new MEDFileFieldMultiTS(*this);
9835 }
9836
9837 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9838 {
9839   if(!f1ts)
9840     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9841   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9842   if(!f1tsC)
9843     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9844 }
9845
9846 /*!
9847  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9848  * following the given input policy.
9849  *
9850  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9851  *                            By default (true) the globals are deeply copied.
9852  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9853  */
9854 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9855 {
9856   MCAuto<MEDFileIntFieldMultiTS> ret;
9857   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9858   if(content)
9859     {
9860       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9861       if(!contc)
9862         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9863       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9864       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9865     }
9866   else
9867     ret=MEDFileIntFieldMultiTS::New();
9868   if(isDeepCpyGlobs)
9869     ret->deepCpyGlobs(*this);
9870   else
9871     ret->shallowCpyGlobs(*this);
9872   return ret.retn();
9873 }
9874
9875 /*!
9876  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9877  *  \param [in] pos - a time step id.
9878  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9879  *          delete this field using decrRef() as it is no more needed.
9880  *  \throw If \a pos is not a valid time step id.
9881  */
9882 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9883 {
9884   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9885   if(!item)
9886     {
9887       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9888       throw INTERP_KERNEL::Exception(oss.str());
9889     }
9890   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9891   if(itemC)
9892     {
9893       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9894       ret->shallowCpyGlobs(*this);
9895       return ret.retn();
9896     }
9897   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9898   throw INTERP_KERNEL::Exception(oss.str());
9899 }
9900
9901 /*!
9902  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9903  * mesh entities of a given dimension of the first mesh in MED file.
9904  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9905  *  \param [in] type - a spatial discretization of interest.
9906  *  \param [in] iteration - the iteration number of a required time step.
9907  *  \param [in] order - the iteration order number of required time step.
9908  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9909  *  \param [in] renumPol - specifies how to permute values of the result field according to
9910  *          the optional numbers of cells and nodes, if any. The valid values are
9911  *          - 0 - do not permute.
9912  *          - 1 - permute cells.
9913  *          - 2 - permute nodes.
9914  *          - 3 - permute cells and nodes.
9915  *
9916  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9917  *          caller is to delete this field using decrRef() as it is no more needed. 
9918  *  \throw If the MED file is not readable.
9919  *  \throw If there is no mesh in the MED file.
9920  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9921  *  \throw If no field values of the required parameters are available.
9922  */
9923 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9924 {
9925   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9926   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9927   if(!myF1TSC)
9928     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9929   MCAuto<DataArray> arrOut;
9930   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9931   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9932   return ret.retn();
9933 }
9934
9935 /*!
9936  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9937  * the top level cells of the first mesh in MED file.
9938  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9939  *  \param [in] type - a spatial discretization of interest.
9940  *  \param [in] iteration - the iteration number of a required time step.
9941  *  \param [in] order - the iteration order number of required time step.
9942  *  \param [in] renumPol - specifies how to permute values of the result field according to
9943  *          the optional numbers of cells and nodes, if any. The valid values are
9944  *          - 0 - do not permute.
9945  *          - 1 - permute cells.
9946  *          - 2 - permute nodes.
9947  *          - 3 - permute cells and nodes.
9948  *
9949  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9950  *          caller is to delete this field using decrRef() as it is no more needed. 
9951  *  \throw If the MED file is not readable.
9952  *  \throw If there is no mesh in the MED file.
9953  *  \throw If no field values of the required parameters are available.
9954  */
9955 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9956 {
9957   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9958   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9959   if(!myF1TSC)
9960     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9961   MCAuto<DataArray> arrOut;
9962   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9963   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9964   return ret.retn();
9965 }
9966
9967 /*!
9968  * 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
9969  * method should be called (getFieldOnMeshAtLevel for example).
9970  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9971  *
9972  * \param [in] iteration - the iteration number of a required time step.
9973  * \param [in] order - the iteration order number of required time step.
9974  * \param [in] mesh - the mesh the field is lying on
9975  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9976  *          caller is to delete this field using decrRef() as it is no more needed. 
9977  */
9978 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9979 {
9980   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9981   MCAuto<DataArray> arrOut;
9982   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9983   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9984   return ret.retn();
9985 }
9986
9987 /*!
9988  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9989  * a given support.
9990  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9991  *  \param [in] type - a spatial discretization of interest.
9992  *  \param [in] iteration - the iteration number of a required time step.
9993  *  \param [in] order - the iteration order number of required time step.
9994  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9995  *  \param [in] mesh - the supporting mesh.
9996  *  \param [in] renumPol - specifies how to permute values of the result field according to
9997  *          the optional numbers of cells and nodes, if any. The valid values are
9998  *          - 0 - do not permute.
9999  *          - 1 - permute cells.
10000  *          - 2 - permute nodes.
10001  *          - 3 - permute cells and nodes.
10002  *
10003  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
10004  *          caller is to delete this field using decrRef() as it is no more needed. 
10005  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10006  *  \throw If no field of \a this is lying on \a mesh.
10007  *  \throw If no field values of the required parameters are available.
10008  */
10009 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10010 {
10011   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10012   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
10013   if(!myF1TSC)
10014     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
10015   MCAuto<DataArray> arrOut;
10016   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
10017   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
10018   return ret.retn();
10019 }
10020
10021 /*!
10022  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
10023  * given support. 
10024  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10025  *  \param [in] type - a spatial discretization of the new field.
10026  *  \param [in] iteration - the iteration number of a required time step.
10027  *  \param [in] order - the iteration order number of required time step.
10028  *  \param [in] mesh - the supporting mesh.
10029  *  \param [in] renumPol - specifies how to permute values of the result field according to
10030  *          the optional numbers of cells and nodes, if any. The valid values are
10031  *          - 0 - do not permute.
10032  *          - 1 - permute cells.
10033  *          - 2 - permute nodes.
10034  *          - 3 - permute cells and nodes.
10035  *
10036  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
10037  *          caller is to delete this field using decrRef() as it is no more needed. 
10038  *  \throw If no field of \a this is lying on \a mesh.
10039  *  \throw If no field values of the required parameters are available.
10040  */
10041 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10042 {
10043   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10044   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
10045   if(!myF1TSC)
10046     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
10047   MCAuto<DataArray> arrOut;
10048   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
10049   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
10050   return ret.retn();
10051 }
10052
10053 /*!
10054  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
10055  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10056  * This method is useful for MED2 file format when field on different mesh was autorized.
10057  */
10058 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
10059 {
10060   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10061   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
10062   if(!myF1TSC)
10063     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
10064   MCAuto<DataArray> arrOut;
10065   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
10066   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
10067   return ret.retn();
10068 }
10069
10070 /*!
10071  * Returns values and a profile of the field of a given type, of a given time step,
10072  * lying on a given support.
10073  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10074  *  \param [in] type - a spatial discretization of the field.
10075  *  \param [in] iteration - the iteration number of a required time step.
10076  *  \param [in] order - the iteration order number of required time step.
10077  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10078  *  \param [in] mesh - the supporting mesh.
10079  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10080  *          field of interest lies on. If the field lies on all entities of the given
10081  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10082  *          using decrRef() as it is no more needed.  
10083  *  \param [in] glob - the global data storing profiles and localization.
10084  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
10085  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10086  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10087  *  \throw If no field of \a this is lying on \a mesh.
10088  *  \throw If no field values of the required parameters are available.
10089  */
10090 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10091 {
10092   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10093   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
10094   if(!myF1TSC)
10095     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
10096   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10097   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
10098 }
10099
10100 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
10101 {
10102   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10103   if(!pt)
10104     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
10105   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
10106   if(!ret)
10107     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 !");
10108   return ret;
10109 }
10110
10111 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
10112 {
10113   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10114   if(!pt)
10115     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
10116   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
10117   if(!ret)
10118     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 !");
10119   return ret;
10120 }
10121
10122 /*!
10123  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
10124  * the given field is checked if its elements are sorted suitable for writing to MED file
10125  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10126  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10127  *  \param [in] field - the field to add to \a this.
10128  *  \throw If the name of \a field is empty.
10129  *  \throw If the data array of \a field is not set.
10130  *  \throw If existing time steps have different name or number of components than \a field.
10131  *  \throw If the underlying mesh of \a field has no name.
10132  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10133  */
10134 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
10135 {
10136   const DataArrayDouble *arr=0;
10137   if(field)
10138     arr=field->getArray();
10139   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
10140 }
10141
10142 /*!
10143  * Adds a MEDCouplingFieldDouble to \a this as another time step.
10144  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10145  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10146  * and \a profile.
10147  *
10148  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10149  * A new profile is added only if no equal profile is missing.
10150  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10151  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
10152  *  \param [in] mesh - the supporting mesh of \a field.
10153  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10154  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10155  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10156  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10157  *  \throw If the data array of \a field is not set.
10158  *  \throw If the data array of \a this is already allocated but has different number of
10159  *         components than \a field.
10160  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10161  *  \sa setFieldNoProfileSBT()
10162  */
10163 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10164 {
10165   const DataArrayDouble *arr=0;
10166   if(field)
10167     arr=field->getArray();
10168   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
10169 }
10170
10171 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
10172 {
10173   _content=new MEDFileFieldMultiTSWithoutSDA;
10174 }
10175
10176 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10177 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10178 {
10179 }
10180 catch(INTERP_KERNEL::Exception& e)
10181 { throw e; }
10182
10183 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10184 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10185 {
10186 }
10187 catch(INTERP_KERNEL::Exception& e)
10188 { throw e; }
10189
10190 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10191 {
10192 }
10193
10194 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
10195 {
10196   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
10197 }
10198
10199 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10200 {
10201   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10202 }
10203
10204 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
10205 {
10206   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
10207 }
10208
10209 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
10210 {
10211   return MEDFileFieldMultiTS::New();
10212 }
10213
10214 //= MEDFileAnyTypeFieldMultiTSIterator
10215
10216 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
10217 {
10218   if(fmts)
10219     {
10220       fmts->incrRef();
10221       _nb_iter=fmts->getNumberOfTS();
10222     }
10223 }
10224
10225 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
10226 {
10227 }
10228
10229 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
10230 {
10231   if(_iter_id<_nb_iter)
10232     {
10233       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
10234       if(fmts)
10235         return fmts->getTimeStepAtPos(_iter_id++);
10236       else
10237         return 0;
10238     }
10239   else
10240     return 0;
10241 }
10242
10243 //= MEDFileIntFieldMultiTS
10244
10245 /*!
10246  * Returns a new empty instance of MEDFileFieldMultiTS.
10247  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10248  *          is to delete this field using decrRef() as it is no more needed.
10249  */
10250 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
10251 {
10252   return new MEDFileIntFieldMultiTS;
10253 }
10254
10255 /*!
10256  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
10257  * that has been read from a specified MED file.
10258  *  \param [in] fileName - the name of the MED file to read.
10259  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10260  *          is to delete this field using decrRef() as it is no more needed.
10261  *  \throw If reading the file fails.
10262  */
10263 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
10264 {
10265   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10266   return New(fid,loadAll);
10267 }
10268
10269 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
10270 {
10271   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
10272   ret->contentNotNull();//to check that content type matches with \a this type.
10273   return ret.retn();
10274 }
10275
10276 /*!
10277  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
10278  * that has been read from a specified MED file.
10279  *  \param [in] fileName - the name of the MED file to read.
10280  *  \param [in] fieldName - the name of the field to read.
10281  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10282  *          is to delete this field using decrRef() as it is no more needed.
10283  *  \throw If reading the file fails.
10284  *  \throw If there is no field named \a fieldName in the file.
10285  */
10286 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
10287 {
10288   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10289   return New(fid,fieldName,loadAll);
10290 }
10291
10292 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
10293 {
10294   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
10295   ret->contentNotNull();//to check that content type matches with \a this type.
10296   return ret.retn();
10297 }
10298
10299 /*!
10300  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
10301  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
10302  *
10303  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
10304  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
10305  * \warning this is a shallow copy constructor
10306  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
10307  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
10308  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10309  *          is to delete this field using decrRef() as it is no more needed.
10310  */
10311 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
10312 {
10313   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
10314 }
10315
10316 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10317 {
10318   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10319   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10320   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
10321   ret->contentNotNull();//to check that content type matches with \a this type.
10322   return ret.retn();
10323 }
10324
10325 /*!
10326  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
10327  * following the given input policy.
10328  *
10329  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
10330  *                            By default (true) the globals are deeply copied.
10331  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
10332  */
10333 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
10334 {
10335   MCAuto<MEDFileFieldMultiTS> ret;
10336   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
10337   if(content)
10338     {
10339       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
10340       if(!contc)
10341         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
10342       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
10343       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
10344     }
10345   else
10346     ret=MEDFileFieldMultiTS::New();
10347   if(isDeepCpyGlobs)
10348     ret->deepCpyGlobs(*this);
10349   else
10350     ret->shallowCpyGlobs(*this);
10351   return ret.retn();
10352 }
10353
10354 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
10355 {
10356   return new MEDFileIntFieldMultiTS(*this);
10357 }
10358
10359 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
10360 {
10361   if(!f1ts)
10362     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
10363   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
10364   if(!f1tsC)
10365     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
10366 }
10367
10368 /*!
10369  * 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
10370  * method should be called (getFieldOnMeshAtLevel for example).
10371  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
10372  *
10373  * \param [in] iteration - the iteration number of a required time step.
10374  * \param [in] order - the iteration order number of required time step.
10375  * \param [in] mesh - the mesh the field is lying on
10376  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
10377  *          caller is to delete this field using decrRef() as it is no more needed. 
10378  */
10379 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
10380 {
10381   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10382   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10383   if(!myF1TSC)
10384     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
10385   MCAuto<DataArray> arrOut;
10386   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
10387   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
10388   return ret2.retn();
10389 }
10390
10391 /*!
10392  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10393  * mesh entities of a given dimension of the first mesh in MED file.
10394  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10395  *  \param [in] type - a spatial discretization of interest.
10396  *  \param [in] iteration - the iteration number of a required time step.
10397  *  \param [in] order - the iteration order number of required time step.
10398  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10399  *  \param [in] renumPol - specifies how to permute values of the result field according to
10400  *          the optional numbers of cells and nodes, if any. The valid values are
10401  *          - 0 - do not permute.
10402  *          - 1 - permute cells.
10403  *          - 2 - permute nodes.
10404  *          - 3 - permute cells and nodes.
10405  *
10406  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10407  *          caller is to delete this field using decrRef() as it is no more needed. 
10408  *  \throw If the MED file is not readable.
10409  *  \throw If there is no mesh in the MED file.
10410  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10411  *  \throw If no field values of the required parameters are available.
10412  */
10413 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
10414 {
10415   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10416   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10417   if(!myF1TSC)
10418     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
10419   MCAuto<DataArray> arr;
10420   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
10421   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10422   return ret2.retn();
10423 }
10424
10425 /*!
10426  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10427  * the top level cells of the first mesh in MED file.
10428  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10429  *  \param [in] type - a spatial discretization of interest.
10430  *  \param [in] iteration - the iteration number of a required time step.
10431  *  \param [in] order - the iteration order number of required time step.
10432  *  \param [in] renumPol - specifies how to permute values of the result field according to
10433  *          the optional numbers of cells and nodes, if any. The valid values are
10434  *          - 0 - do not permute.
10435  *          - 1 - permute cells.
10436  *          - 2 - permute nodes.
10437  *          - 3 - permute cells and nodes.
10438  *
10439  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10440  *          caller is to delete this field using decrRef() as it is no more needed. 
10441  *  \throw If the MED file is not readable.
10442  *  \throw If there is no mesh in the MED file.
10443  *  \throw If no field values of the required parameters are available.
10444  */
10445 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
10446 {
10447   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10448   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10449   if(!myF1TSC)
10450     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
10451   MCAuto<DataArray> arr;
10452   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
10453   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10454   return ret2.retn();
10455 }
10456
10457 /*!
10458  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10459  * a given support.
10460  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10461  *  \param [in] type - a spatial discretization of interest.
10462  *  \param [in] iteration - the iteration number of a required time step.
10463  *  \param [in] order - the iteration order number of required time step.
10464  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10465  *  \param [in] mesh - the supporting mesh.
10466  *  \param [in] renumPol - specifies how to permute values of the result field according to
10467  *          the optional numbers of cells and nodes, if any. The valid values are
10468  *          - 0 - do not permute.
10469  *          - 1 - permute cells.
10470  *          - 2 - permute nodes.
10471  *          - 3 - permute cells and nodes.
10472  *
10473  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10474  *          caller is to delete this field using decrRef() as it is no more needed. 
10475  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10476  *  \throw If no field of \a this is lying on \a mesh.
10477  *  \throw If no field values of the required parameters are available.
10478  */
10479 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10480 {
10481   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10482   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10483   if(!myF1TSC)
10484     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10485   MCAuto<DataArray> arr;
10486   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
10487   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10488   return ret2.retn();
10489 }
10490
10491 /*!
10492  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
10493  * given support. 
10494  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10495  *  \param [in] type - a spatial discretization of the new field.
10496  *  \param [in] iteration - the iteration number of a required time step.
10497  *  \param [in] order - the iteration order number of required time step.
10498  *  \param [in] mesh - the supporting mesh.
10499  *  \param [out] arrOut - the DataArrayInt containing values of field.
10500  *  \param [in] renumPol - specifies how to permute values of the result field according to
10501  *          the optional numbers of cells and nodes, if any. The valid values are
10502  *          - 0 - do not permute.
10503  *          - 1 - permute cells.
10504  *          - 2 - permute nodes.
10505  *          - 3 - permute cells and nodes.
10506  *
10507  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10508  *          caller is to delete this field using decrRef() as it is no more needed. 
10509  *  \throw If no field of \a this is lying on \a mesh.
10510  *  \throw If no field values of the required parameters are available.
10511  */
10512 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10513 {
10514   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10515   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10516   if(!myF1TSC)
10517     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10518   MCAuto<DataArray> arr;
10519   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
10520   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10521   return ret2.retn();
10522 }
10523
10524 /*!
10525  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
10526  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10527  * This method is useful for MED2 file format when field on different mesh was autorized.
10528  */
10529 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
10530 {
10531   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10532   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10533   if(!myF1TSC)
10534     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10535   MCAuto<DataArray> arr;
10536   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
10537   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10538   return ret2.retn();
10539 }
10540
10541 /*!
10542  * Returns values and a profile of the field of a given type, of a given time step,
10543  * lying on a given support.
10544  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10545  *  \param [in] type - a spatial discretization of the field.
10546  *  \param [in] iteration - the iteration number of a required time step.
10547  *  \param [in] order - the iteration order number of required time step.
10548  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10549  *  \param [in] mesh - the supporting mesh.
10550  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10551  *          field of interest lies on. If the field lies on all entities of the given
10552  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10553  *          using decrRef() as it is no more needed.  
10554  *  \param [in] glob - the global data storing profiles and localization.
10555  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
10556  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10557  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10558  *  \throw If no field of \a this is lying on \a mesh.
10559  *  \throw If no field values of the required parameters are available.
10560  */
10561 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10562 {
10563   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10564   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
10565   if(!myF1TSC)
10566     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
10567   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10568   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
10569 }
10570
10571 /*!
10572  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
10573  *  \param [in] pos - a time step id.
10574  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
10575  *          delete this field using decrRef() as it is no more needed.
10576  *  \throw If \a pos is not a valid time step id.
10577  */
10578 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
10579 {
10580   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
10581   if(!item)
10582     {
10583       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
10584       throw INTERP_KERNEL::Exception(oss.str());
10585     }
10586   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
10587   if(itemC)
10588     {
10589       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
10590       ret->shallowCpyGlobs(*this);
10591       return ret.retn();
10592     }
10593   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
10594   throw INTERP_KERNEL::Exception(oss.str());
10595 }
10596
10597 /*!
10598  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
10599  * the given field is checked if its elements are sorted suitable for writing to MED file
10600  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10601  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10602  *  \param [in] field - the field to add to \a this.
10603  *  \throw If the name of \a field is empty.
10604  *  \throw If the data array of \a field is not set.
10605  *  \throw If existing time steps have different name or number of components than \a field.
10606  *  \throw If the underlying mesh of \a field has no name.
10607  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10608  */
10609 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
10610 {
10611   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10612   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
10613 }
10614
10615 /*!
10616  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10617  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10618  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10619  * and \a profile.
10620  *
10621  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10622  * A new profile is added only if no equal profile is missing.
10623  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10624  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10625  *  \param [in] arrOfVals - the values of the field \a field used.
10626  *  \param [in] mesh - the supporting mesh of \a field.
10627  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10628  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10629  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10630  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10631  *  \throw If the data array of \a field is not set.
10632  *  \throw If the data array of \a this is already allocated but has different number of
10633  *         components than \a field.
10634  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10635  *  \sa setFieldNoProfileSBT()
10636  */
10637 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10638 {
10639   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10640   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10641 }
10642
10643 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10644 {
10645   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10646   if(!pt)
10647     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10648   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10649   if(!ret)
10650     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 !");
10651   return ret;
10652 }
10653
10654 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10655 {
10656   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10657   if(!pt)
10658     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10659   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10660   if(!ret)
10661     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 !");
10662   return ret;
10663 }
10664
10665 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10666 {
10667   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10668 }
10669
10670 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10671 {
10672 }
10673
10674 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10675 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10676 {
10677 }
10678 catch(INTERP_KERNEL::Exception& e)
10679 { throw e; }
10680
10681 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10682 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10683 {
10684 }
10685 catch(INTERP_KERNEL::Exception& e)
10686 { throw e; }
10687
10688 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10689 {
10690   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10691 }
10692
10693 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10694 {
10695   return MEDFileIntFieldMultiTS::New();
10696 }
10697
10698 //= MEDFileFields
10699
10700 MEDFileFields *MEDFileFields::New()
10701 {
10702   return new MEDFileFields;
10703 }
10704
10705 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10706 {
10707   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10708   return New(fid,loadAll);
10709 }
10710
10711 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
10712 {
10713   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10714   return NewWithDynGT(fid,se,loadAll);
10715 }
10716
10717 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
10718 {
10719   if(!se)
10720     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
10721   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
10722   return new MEDFileFields(fid,loadAll,0,entities);
10723 }
10724
10725 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10726 {
10727   return new MEDFileFields(fid,loadAll,0,0);
10728 }
10729
10730 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10731 {
10732   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10733   return new MEDFileFields(fid,loadAll,ms,0);
10734 }
10735
10736 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10737 {
10738   MEDFileUtilities::CheckFileForRead(fileName);
10739   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10740   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10741   return new MEDFileFields(fid,loadAll,0,ent);
10742 }
10743
10744 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10745 {
10746   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10747   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10748   return ret;
10749 }
10750
10751 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10752 {
10753   std::vector<const BigMemoryObject *> ret;
10754   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10755     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10756   return ret;
10757 }
10758
10759 MEDFileFields *MEDFileFields::deepCopy() const
10760 {
10761   MCAuto<MEDFileFields> ret(shallowCpy());
10762   std::size_t i(0);
10763   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10764     {
10765       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10766         ret->_fields[i]=(*it)->deepCopy();
10767     }
10768   ret->deepCpyGlobs(*this);
10769   return ret.retn();
10770 }
10771
10772 MEDFileFields *MEDFileFields::shallowCpy() const
10773 {
10774   return new MEDFileFields(*this);
10775 }
10776
10777 /*!
10778  * 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
10779  * 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.
10780  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10781  *
10782  * \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.
10783  * \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.
10784  * 
10785  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10786  */
10787 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10788 {
10789   std::set< std::pair<int,int> > s;
10790   bool firstShot=true;
10791   areThereSomeForgottenTS=false;
10792   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10793     {
10794       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10795         continue;
10796       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10797       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10798       if(firstShot)
10799         { s=s1; firstShot=false; }
10800       else
10801         {
10802           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10803           if(s!=s2)
10804             areThereSomeForgottenTS=true;
10805           s=s2;
10806         }
10807     }
10808   std::vector< std::pair<int,int> > ret;
10809   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10810   return ret;
10811 }
10812
10813 int MEDFileFields::getNumberOfFields() const
10814 {
10815   return _fields.size();
10816 }
10817
10818 std::vector<std::string> MEDFileFields::getFieldsNames() const
10819 {
10820   std::vector<std::string> ret(_fields.size());
10821   int i(0);
10822   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10823     {
10824       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10825       if(f)
10826         {
10827           ret[i]=f->getName();
10828         }
10829       else
10830         {
10831           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10832           throw INTERP_KERNEL::Exception(oss.str());
10833         }
10834     }
10835   return ret;
10836 }
10837
10838 std::vector<std::string> MEDFileFields::getMeshesNames() const
10839 {
10840   std::vector<std::string> ret;
10841   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10842     {
10843       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10844       if(cur)
10845         ret.push_back(cur->getMeshName());
10846     }
10847   return ret;
10848 }
10849
10850 std::string MEDFileFields::simpleRepr() const
10851 {
10852   std::ostringstream oss;
10853   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10854   simpleRepr(0,oss);
10855   return oss.str();
10856 }
10857
10858 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10859 {
10860   int nbOfFields(getNumberOfFields());
10861   std::string startLine(bkOffset,' ');
10862   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10863   int i=0;
10864   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10865     {
10866       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10867       if(cur)
10868         {
10869           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10870         }
10871       else
10872         {
10873           oss << startLine << "  - not defined !" << std::endl;
10874         }
10875     }
10876   i=0;
10877   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10878     {
10879       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10880       std::string chapter(17,'0'+i);
10881       oss << startLine << chapter << std::endl;
10882       if(cur)
10883         {
10884           cur->simpleRepr(bkOffset+2,oss,i);
10885         }
10886       else
10887         {
10888           oss << startLine << "  - not defined !" << std::endl;
10889         }
10890       oss << startLine << chapter << std::endl;
10891     }
10892   simpleReprGlobs(oss);
10893 }
10894
10895 MEDFileFields::MEDFileFields()
10896 {
10897 }
10898
10899 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10900 try:MEDFileFieldGlobsReal(fid)
10901 {
10902   int nbFields(MEDnField(fid));
10903   _fields.resize(nbFields);
10904   med_field_type typcha;
10905   for(int i=0;i<nbFields;i++)
10906     {
10907       std::vector<std::string> infos;
10908       std::string fieldName,dtunit;
10909       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit));
10910       switch(typcha)
10911       {
10912         case MED_FLOAT64:
10913           {
10914             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10915             break;
10916           }
10917         case MED_INT32:
10918           {
10919             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10920             break;
10921           }
10922         default:
10923           {
10924             std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << FileNameFromFID(fid) << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
10925             throw INTERP_KERNEL::Exception(oss.str());
10926           }
10927       }
10928     }
10929   loadAllGlobals(fid,entities);
10930 }
10931 catch(INTERP_KERNEL::Exception& e)
10932 {
10933     throw e;
10934 }
10935
10936 void MEDFileFields::writeLL(med_idt fid) const
10937 {
10938   int i=0;
10939   writeGlobals(fid,*this);
10940   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10941     {
10942       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10943       if(!elt)
10944         {
10945           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10946           throw INTERP_KERNEL::Exception(oss.str());
10947         }
10948       elt->writeLL(fid,*this);
10949     }
10950 }
10951
10952 /*!
10953  * This method alloc the arrays and load potentially huge arrays contained in this field.
10954  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10955  * This method can be also called to refresh or reinit values from a file.
10956  * 
10957  * \throw If the fileName is not set or points to a non readable MED file.
10958  */
10959 void MEDFileFields::loadArrays()
10960 {
10961   if(getFileName().empty())
10962     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10963   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10964   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10965     {
10966       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10967       if(elt)
10968         elt->loadBigArraysRecursively(fid,*elt);
10969     }
10970 }
10971
10972 /*!
10973  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10974  * But once data loaded once, this method does nothing.
10975  * 
10976  * \throw If the fileName is not set or points to a non readable MED file.
10977  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10978  */
10979 void MEDFileFields::loadArraysIfNecessary()
10980 {
10981   if(!getFileName().empty())
10982     {
10983       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10984       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10985         {
10986           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10987           if(elt)
10988             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10989         }
10990     }
10991 }
10992
10993 /*!
10994  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10995  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10996  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10997  * 
10998  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10999  */
11000 void MEDFileFields::unloadArrays()
11001 {
11002   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11003     {
11004       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
11005       if(elt)
11006         elt->unloadArrays();
11007     }
11008 }
11009
11010 /*!
11011  * 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.
11012  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
11013  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
11014  * 
11015  * \sa MEDFileFields::loadArraysIfNecessary
11016  */
11017 void MEDFileFields::unloadArraysWithoutDataLoss()
11018 {
11019   if(!getFileName().empty())
11020     unloadArrays();
11021 }
11022
11023 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
11024 {
11025   std::vector<std::string> ret;
11026   std::set<std::string> ret2;
11027   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11028     {
11029       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
11030       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
11031         if(ret2.find(*it2)==ret2.end())
11032           {
11033             ret.push_back(*it2);
11034             ret2.insert(*it2);
11035           }
11036     }
11037   return ret;
11038 }
11039
11040 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
11041 {
11042   std::vector<std::string> ret;
11043   std::set<std::string> ret2;
11044   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11045     {
11046       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
11047       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
11048         if(ret2.find(*it2)==ret2.end())
11049           {
11050             ret.push_back(*it2);
11051             ret2.insert(*it2);
11052           }
11053     }
11054   return ret;
11055 }
11056
11057 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
11058 {
11059   std::vector<std::string> ret;
11060   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11061     {
11062       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
11063       ret.insert(ret.end(),tmp.begin(),tmp.end());
11064     }
11065   return ret;
11066 }
11067
11068 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
11069 {
11070   std::vector<std::string> ret;
11071   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11072     {
11073       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
11074       ret.insert(ret.end(),tmp.begin(),tmp.end());
11075     }
11076   return ret;
11077 }
11078
11079 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
11080 {
11081   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
11082     (*it)->changePflsRefsNamesGen2(mapOfModif);
11083 }
11084
11085 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
11086 {
11087   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
11088     (*it)->changeLocsRefsNamesGen2(mapOfModif);
11089 }
11090
11091 void MEDFileFields::resize(int newSize)
11092 {
11093   _fields.resize(newSize);
11094 }
11095
11096 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
11097 {
11098   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
11099     pushField(*it);
11100 }
11101
11102 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
11103 {
11104   if(!field)
11105     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
11106   _fields.push_back(field->getContent());
11107   appendGlobs(*field,1e-12);
11108 }
11109
11110 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
11111 {
11112   if(!field)
11113     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
11114   if(i>=(int)_fields.size())
11115     _fields.resize(i+1);
11116   _fields[i]=field->getContent();
11117   appendGlobs(*field,1e-12);
11118 }
11119
11120 void MEDFileFields::destroyFieldAtPos(int i)
11121 {
11122   destroyFieldsAtPos(&i,&i+1);
11123 }
11124
11125 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
11126 {
11127   std::vector<bool> b(_fields.size(),true);
11128   for(const int *i=startIds;i!=endIds;i++)
11129     {
11130       if(*i<0 || *i>=(int)_fields.size())
11131         {
11132           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
11133           throw INTERP_KERNEL::Exception(oss.str());
11134         }
11135       b[*i]=false;
11136     }
11137   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
11138   std::size_t j=0;
11139   for(std::size_t i=0;i<_fields.size();i++)
11140     if(b[i])
11141       fields[j++]=_fields[i];
11142   _fields=fields;
11143 }
11144
11145 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
11146 {
11147   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
11148   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
11149   std::vector<bool> b(_fields.size(),true);
11150   int k=bg;
11151   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
11152     {
11153       if(k<0 || k>=(int)_fields.size())
11154         {
11155           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
11156           throw INTERP_KERNEL::Exception(oss.str());
11157         }
11158       b[k]=false;
11159     }
11160   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
11161   std::size_t j(0);
11162   for(std::size_t i=0;i<_fields.size();i++)
11163     if(b[i])
11164       fields[j++]=_fields[i];
11165   _fields=fields;
11166 }
11167
11168 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
11169 {
11170   bool ret(false);
11171   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11172     {
11173       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11174       if(cur)
11175         ret=cur->changeMeshNames(modifTab) || ret;
11176     }
11177   return ret;
11178 }
11179
11180 /*!
11181  * \param [in] meshName the name of the mesh that will be renumbered.
11182  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
11183  *             This code corresponds to the distribution of types in the corresponding mesh.
11184  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
11185  * \param [in] renumO2N the old to new renumber array.
11186  * \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 
11187  *         field in \a this.
11188  */
11189 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
11190 {
11191   bool ret(false);
11192   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11193     {
11194       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
11195       if(fmts)
11196         {
11197           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
11198         }
11199     }
11200   return ret;
11201 }
11202
11203 /*!
11204  * Return an extraction of \a this using \a extractDef map to specify the extraction.
11205  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
11206  *
11207  * \return A new object that the caller is responsible to deallocate.
11208  */
11209 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
11210 {
11211   if(!mm)
11212     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
11213   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
11214   int nbFields(getNumberOfFields());
11215   for(int i=0;i<nbFields;i++)
11216     {
11217       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
11218       if(!fmts)
11219         {
11220           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
11221           throw INTERP_KERNEL::Exception(oss.str());
11222         }
11223       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
11224       fsOut->pushField(fmtsOut);
11225     }
11226   return fsOut.retn();
11227 }
11228
11229 void MEDFileFields::accept(MEDFileFieldVisitor& visitor) const
11230 {
11231   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11232     if((*it).isNotNull())
11233       {
11234         visitor.newFieldEntry(*it);
11235         (*it)->accept(visitor);
11236         visitor.endFieldEntry(*it);
11237       }
11238 }
11239
11240 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
11241 {
11242   if(i<0 || i>=(int)_fields.size())
11243     {
11244       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
11245       throw INTERP_KERNEL::Exception(oss.str());
11246     }
11247   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
11248   if(!fmts)
11249     return 0;
11250   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
11251   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
11252   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
11253   if(fmtsC)
11254     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
11255   else if(fmtsC2)
11256     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
11257   else
11258     {
11259       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
11260       throw INTERP_KERNEL::Exception(oss.str());
11261     }
11262   ret->shallowCpyGlobs(*this);
11263   return ret.retn();
11264 }
11265
11266 /*!
11267  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
11268  * This method is accessible in python using __getitem__ with a list in input.
11269  * \return a new object that the caller should deal with.
11270  */
11271 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
11272 {
11273   MCAuto<MEDFileFields> ret=shallowCpy();
11274   std::size_t sz=std::distance(startIds,endIds);
11275   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
11276   int j=0;
11277   for(const int *i=startIds;i!=endIds;i++,j++)
11278     {
11279       if(*i<0 || *i>=(int)_fields.size())
11280         {
11281           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
11282           throw INTERP_KERNEL::Exception(oss.str());
11283         }
11284       fields[j]=_fields[*i];
11285     }
11286   ret->_fields=fields;
11287   return ret.retn();
11288 }
11289
11290 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
11291 {
11292   return getFieldAtPos(getPosFromFieldName(fieldName));
11293 }
11294
11295 /*!
11296  * This method removes, if any, fields in \a this having no time steps.
11297  * 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.
11298  * 
11299  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
11300  */
11301 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
11302 {
11303   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
11304   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11305     {
11306       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
11307       if(elt)
11308         {
11309           if(elt->getNumberOfTS()>0)
11310             newFields.push_back(*it);
11311         }
11312     }
11313   if(_fields.size()==newFields.size())
11314     return false;
11315   _fields=newFields;
11316   return true;
11317 }
11318
11319 /*!
11320  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
11321  * This method can be seen as a filter applied on \a this, that returns an object containing
11322  * 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
11323  * shallow copied from \a this.
11324  * 
11325  * \param [in] meshName - the name of the mesh on w
11326  * \return a new object that the caller should deal with.
11327  */
11328 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
11329 {
11330   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11331   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11332     {
11333       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11334       if(!cur)
11335         continue;
11336       if(cur->getMeshName()==meshName)
11337         {
11338           cur->incrRef();
11339           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
11340           ret->_fields.push_back(cur2);
11341         }
11342     }
11343   ret->shallowCpyOnlyUsedGlobs(*this);
11344   return ret.retn();
11345 }
11346
11347 /*!
11348  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
11349  * Input time steps are specified using a pair of integer (iteration, order).
11350  * 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,
11351  * but for each multitimestep only the time steps in \a timeSteps are kept.
11352  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
11353  * 
11354  * The returned object points to shallow copy of elements in \a this.
11355  * 
11356  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
11357  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
11358  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
11359  */
11360 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11361 {
11362   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11363   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11364     {
11365       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11366       if(!cur)
11367         continue;
11368       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
11369       ret->_fields.push_back(elt);
11370     }
11371   ret->shallowCpyOnlyUsedGlobs(*this);
11372   return ret.retn();
11373 }
11374
11375 /*!
11376  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
11377  */
11378 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11379 {
11380   MCAuto<MEDFileFields> ret=MEDFileFields::New();
11381   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11382     {
11383       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11384       if(!cur)
11385         continue;
11386       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
11387       if(elt->getNumberOfTS()!=0)
11388         ret->_fields.push_back(elt);
11389     }
11390   ret->shallowCpyOnlyUsedGlobs(*this);
11391   return ret.retn();
11392 }
11393
11394 bool MEDFileFields::presenceOfStructureElements() const
11395 {
11396   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11397     if((*it).isNotNull())
11398       if((*it)->presenceOfStructureElements())
11399         return true;
11400   return false;
11401 }
11402
11403 void MEDFileFields::killStructureElements()
11404 {
11405   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11406   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11407     if((*it).isNotNull())
11408       {
11409         if((*it)->presenceOfStructureElements())
11410           {
11411             if(!(*it)->onlyStructureElements())
11412               {
11413                 (*it)->killStructureElements();
11414                 ret.push_back(*it);
11415               }
11416           }
11417         else
11418           {
11419             ret.push_back(*it);
11420           }
11421       }
11422   _fields=ret;
11423 }
11424
11425 void MEDFileFields::keepOnlyStructureElements()
11426 {
11427   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11428   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11429     if((*it).isNotNull())
11430       {
11431         if((*it)->presenceOfStructureElements())
11432           {
11433             if(!(*it)->onlyStructureElements())
11434               (*it)->keepOnlyStructureElements();
11435             ret.push_back(*it);
11436           }
11437       }
11438   _fields=ret;
11439 }
11440
11441 void MEDFileFields::keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName)
11442 {
11443   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11444   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11445     if((*it).isNotNull())
11446       {
11447         if((*it)->getMeshName()!=meshName)
11448           continue;
11449         std::vector< std::pair<std::string,std::string> > ps;
11450         (*it)->getMeshSENames(ps);
11451         std::pair<std::string,std::string> p(meshName,seName);
11452         if(std::find(ps.begin(),ps.end(),p)!=ps.end())
11453           (*it)->keepOnlyOnSE(seName);
11454         ret.push_back(*it);
11455       }
11456   _fields=ret;
11457 }
11458
11459 void MEDFileFields::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
11460 {
11461   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11462     if((*it).isNotNull())
11463       (*it)->getMeshSENames(ps);
11464 }
11465
11466 void MEDFileFields::blowUpSE(MEDFileMeshes *ms, const MEDFileStructureElements *ses)
11467 {
11468   MEDFileBlowStrEltUp::DealWithSE(this,ms,ses);
11469 }
11470
11471 MCAuto<MEDFileFields> MEDFileFields::partOfThisOnStructureElements() const
11472 {
11473   MCAuto<MEDFileFields> ret(deepCopy());
11474   ret->keepOnlyStructureElements();
11475   return ret;
11476 }
11477
11478 MCAuto<MEDFileFields> MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const
11479 {
11480   MCAuto<MEDFileFields> ret(deepCopy());
11481   ret->keepOnlyOnMeshSE(meshName,seName);
11482   return ret;
11483 }
11484
11485 void MEDFileFields::aggregate(const MEDFileFields& other)
11486 {
11487   int nbFieldsToAdd(other.getNumberOfFields());
11488   std::vector<std::string> fsn(getFieldsNames());
11489   for(int i=0;i<nbFieldsToAdd;i++)
11490     {
11491       MCAuto<MEDFileAnyTypeFieldMultiTS> elt(other.getFieldAtPos(i));
11492       std::string name(elt->getName());
11493       if(std::find(fsn.begin(),fsn.end(),name)!=fsn.end())
11494         {
11495           std::ostringstream oss; oss << "MEDFileFields::aggregate : name \"" << name << "\" already appears !";
11496           throw INTERP_KERNEL::Exception(oss.str());
11497         }
11498       pushField(elt);
11499     }
11500 }
11501
11502 MEDFileFieldsIterator *MEDFileFields::iterator()
11503 {
11504   return new MEDFileFieldsIterator(this);
11505 }
11506
11507 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
11508 {
11509   std::string tmp(fieldName);
11510   std::vector<std::string> poss;
11511   for(std::size_t i=0;i<_fields.size();i++)
11512     {
11513       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
11514       if(f)
11515         {
11516           std::string fname(f->getName());
11517           if(tmp==fname)
11518             return i;
11519           else
11520             poss.push_back(fname);
11521         }
11522     }
11523   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
11524   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
11525   oss << " !";
11526   throw INTERP_KERNEL::Exception(oss.str());
11527 }
11528
11529 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
11530 {
11531   if(fs)
11532     {
11533       fs->incrRef();
11534       _nb_iter=fs->getNumberOfFields();
11535     }
11536 }
11537
11538 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
11539 {
11540 }
11541
11542 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
11543 {
11544   if(_iter_id<_nb_iter)
11545     {
11546       MEDFileFields *fs(_fs);
11547       if(fs)
11548         return fs->getFieldAtPos(_iter_id++);
11549       else
11550         return 0;
11551     }
11552   else
11553     return 0;
11554 }