Salome HOME
c91a6ffc6f132c07381cac94ac381c35bdc2cad0
[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 (EDF R&D)
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 "MEDCouplingFieldDiscretization.hxx"
31
32 #include "InterpKernelAutoPtr.hxx"
33 #include "CellModel.hxx"
34
35 #include <algorithm>
36 #include <iterator>
37
38 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
39 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
40 extern med_geometry_type typmainoeud[1];
41 extern med_geometry_type typmai3[34];
42
43 using namespace MEDCoupling;
44
45 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<int>;
46 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<float>;
47 template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA<double>;
48 template class MEDCoupling::MEDFileField1TSNDTemplateWithoutSDA<int>;
49 template class MEDCoupling::MEDFileField1TSNDTemplateWithoutSDA<float>;
50 template class MEDCoupling::MEDFileNDTemplateFieldMultiTSWithoutSDA<int>;
51 template class MEDCoupling::MEDFileNDTemplateFieldMultiTSWithoutSDA<float>;
52 template class MEDCoupling::MEDFileTemplateField1TS<int>;
53 template class MEDCoupling::MEDFileTemplateField1TS<float>;
54 template class MEDCoupling::MEDFileTemplateField1TS<double>;
55 template class MEDCoupling::MEDFileNDTemplateField1TS<int>;
56 template class MEDCoupling::MEDFileNDTemplateField1TS<float>;
57 template class MEDCoupling::MEDFileTemplateFieldMultiTS<int>;
58 template class MEDCoupling::MEDFileTemplateFieldMultiTS<float>;
59 template class MEDCoupling::MEDFileTemplateFieldMultiTS<double>;
60 template class MEDCoupling::MEDFileNDTemplateFieldMultiTS<int>;
61 template class MEDCoupling::MEDFileNDTemplateFieldMultiTS<float>;
62
63 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
64 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
65 const char MEDFileFloatField1TSWithoutSDA::TYPE_STR[]="FLOAT32";
66
67 MEDFileGTKeeper::~MEDFileGTKeeper()
68 {
69 }
70
71 MEDFileGTKeeper *MEDFileGTKeeperSta::deepCopy() const
72 {
73   return new MEDFileGTKeeperSta(_geo_type);
74 }
75
76 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperSta::getGeoType() const
77 {
78   return _geo_type;
79 }
80
81 std::string MEDFileGTKeeperSta::getRepr() const
82 {
83   return INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr();
84 }
85
86 bool MEDFileGTKeeperSta::isEqual(const MEDFileGTKeeper *other) const
87 {
88   const MEDFileGTKeeperSta *otherC(dynamic_cast<const MEDFileGTKeeperSta *>(other));
89   if(!otherC)
90     return false;
91   return _geo_type==otherC->_geo_type;
92 }
93
94 MEDFileGTKeeperDyn::MEDFileGTKeeperDyn(const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileStructureElement *se):_mesh(mesh),_section(section),_se(se)
95 {
96   if(mesh)
97     mesh->incrRef();
98   if(section)
99     section->incrRef();
100   if(se)
101     se->incrRef();
102   if(_mesh.isNull() || _section.isNull() || _se.isNull())
103     throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn constructor : null pointer not allowed !");
104 }
105
106 MEDFileGTKeeper *MEDFileGTKeeperDyn::deepCopy() const
107 {
108   return new MEDFileGTKeeperDyn(_mesh,_section,_se);
109 }
110
111 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperDyn::getGeoType() const
112 {
113   throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn::getGeoType : not valid !");
114 }
115
116 std::string MEDFileGTKeeperDyn::getRepr() const
117 {
118   std::ostringstream oss;
119   oss << _se->getDynGT();
120   return oss.str();
121 }
122
123 bool MEDFileGTKeeperDyn::isEqual(const MEDFileGTKeeper *other) const
124 {
125   const MEDFileGTKeeperDyn *otherC(dynamic_cast<const MEDFileGTKeeperDyn *>(other));
126   if(!otherC)
127     return false;
128   return this==otherC;
129 }
130
131 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
132 {
133   return new MEDFileFieldLoc(fid,locName);
134 }
135
136 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id, const MEDFileEntities *entities)
137 {
138   return new MEDFileFieldLoc(fid,id,entities);
139 }
140
141 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)
142 {
143   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
144 }
145
146 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
147 {
148   med_geometry_type geotype;
149   med_geometry_type sectiongeotype;
150   int nsectionmeshcell;
151   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
152   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
153   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
154   _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
155   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
156   _nb_node_per_cell=cm.getNumberOfNodes();
157   _ref_coo.resize(_dim*_nb_node_per_cell);
158   _gs_coo.resize(_dim*_nb_gauss_pt);
159   _w.resize(_nb_gauss_pt);
160   MEDFILESAFECALLERRD0(MEDlocalizationRd,(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]));
161 }
162
163 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id, const MEDFileEntities *entities)
164 {
165   med_geometry_type geotype;
166   med_geometry_type sectiongeotype;
167   int nsectionmeshcell;
168   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
169   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
170   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
171   MEDFILESAFECALLERRD0(MEDlocalizationInfo,(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype));
172   _name=locName;
173   std::string sectionName(MEDLoaderBase::buildStringFromFortran(sectionmeshname,MED_NAME_SIZE));
174   if(sectionName.empty())
175     {
176       _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
177       const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
178       _nb_node_per_cell=cm.getNumberOfNodes();
179     }
180   else
181     {
182       const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
183       if(!entities2)
184         {
185           std::ostringstream oss; oss << "MEDFileFieldLoc cstr : for loc \"" << _name << "\" presence of non static type ! Expect entities !";
186           throw INTERP_KERNEL::Exception(oss.str());
187         }
188       const MEDFileStructureElement *se(entities2->getWithGT(geotype));
189       const MEDFileUMesh *um(entities2->getSupMeshWithName(se->getMeshName()));
190       const MEDFileUMesh *section(entities2->getSupMeshWithName(sectionName));
191       _gt=new MEDFileGTKeeperDyn(um,section,se);
192       {
193         int dummy;
194         MEDFILESAFECALLERRD0(MEDmeshGeotypeParameter,(fid,geotype,&dummy,&_nb_node_per_cell));
195       }
196     }
197   _ref_coo.resize(_dim*_nb_node_per_cell);
198   _gs_coo.resize(_dim*_nb_gauss_pt);
199   _w.resize(_nb_gauss_pt);
200   MEDFILESAFECALLERRD0(MEDlocalizationRd,(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]));
201 }
202
203 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
204                                  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)
205 {
206   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
207   _dim=cm.getDimension();
208   _nb_node_per_cell=cm.getNumberOfNodes();
209   _nb_gauss_pt=_w.size();
210 }
211
212
213 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)
214 {
215 }
216
217 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
218 {
219   return new MEDFileFieldLoc(*this);
220 }
221
222 bool MEDFileFieldLoc::isOnStructureElement() const
223 {
224   const MEDFileGTKeeper *gt(_gt);
225   if(!gt)
226     throw INTERP_KERNEL::Exception("MEDFileFieldLoc::isOnStructureElement : null pointer !");
227   const MEDFileGTKeeperDyn *gt2(dynamic_cast<const MEDFileGTKeeperDyn *>(gt));
228   return gt2!=NULL;
229 }
230
231 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
232 {
233   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
234 }
235
236 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
237 {
238   return std::vector<const BigMemoryObject *>();
239 }
240
241 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
242 {
243   static const char OFF7[]="\n    ";
244   oss << "\"" << _name << "\"" << OFF7;
245   oss << "GeoType=" << _gt->getRepr() << OFF7;
246   oss << "Dimension=" << _dim << OFF7;
247   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
248   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
249   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
250   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
251   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
252 }
253
254 void MEDFileFieldLoc::setName(const std::string& name)
255 {
256   _name=name;
257 }
258
259 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
260 {
261   if(_name!=other._name)
262     return false;
263   if(_dim!=other._dim)
264     return false;
265   if(_nb_gauss_pt!=other._nb_gauss_pt)
266     return false;
267   if(_nb_node_per_cell!=other._nb_node_per_cell)
268     return false;
269   if(!_gt->isEqual(other._gt))
270     return false;
271   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
272     return false;
273   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
274     return false;
275   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
276     return false;
277
278   return true;
279 }
280
281 void MEDFileFieldLoc::writeLL(med_idt fid) const
282 {
283   MEDFILESAFECALLERWR0(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));
284 }
285
286 std::string MEDFileFieldLoc::repr() const
287 {
288   std::ostringstream oss; oss.precision(15);
289   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
290   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
291   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
292   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
293   oss << "\n  - Ref coords are : ";
294   int sz=_ref_coo.size();
295   if(sz%_dim==0)
296     {
297       int nbOfTuples=sz/_dim;
298       for(int i=0;i<nbOfTuples;i++)
299         {
300           oss << "(";
301           for(int j=0;j<_dim;j++)
302             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
303           oss << ") ";
304         }
305     }
306   else
307     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
308   oss << "\n  - Gauss coords in reference element : ";
309   sz=_gs_coo.size();
310   if(sz%_dim==0)
311     {
312       int nbOfTuples=sz/_dim;
313       for(int i=0;i<nbOfTuples;i++)
314         {
315           oss << "(";
316           for(int j=0;j<_dim;j++)
317             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
318           oss << ") ";
319         }
320     }
321   else
322     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
323   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
324   return oss.str();
325 }
326
327 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
328 {
329   _type=field->getTypeOfField();
330   _start=start;
331   switch(_type)
332   {
333     case ON_CELLS:
334       {
335         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
336         _end=_start+nbOfCells;
337         _nval=nbOfCells;
338         break;
339       }
340     case ON_GAUSS_NE:
341       {
342         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
343         const int *arrPtr=arr->getConstPointer();
344         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
345         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
346         _nval=nbOfCells;
347         break;
348       }
349     case ON_GAUSS_PT:
350       {
351         const MEDCouplingFieldDiscretization *disc(field->getDiscretization());
352         const MEDCouplingGaussLocalization& gsLoc(field->getGaussLocalization(_loc_id));
353         const MEDCouplingFieldDiscretizationGauss *disc2(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc));
354         if(!disc2)
355           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
356         const DataArrayInt *dai(disc2->getArrayOfDiscIds());
357         MCAuto<DataArrayInt> dai2(disc2->getOffsetArr(field->getMesh()));
358         const int *dai2Ptr(dai2->getConstPointer());
359         int nbi(gsLoc.getWeights().size());
360         MCAuto<DataArrayInt> da2(dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1));
361         MCAuto<DataArrayInt> da3(da2->findIdsEqual(_loc_id));
362         const int *da3Ptr(da3->getConstPointer());
363         if(da3->getNumberOfTuples()!=nbOfCells)
364           {//profile : for gauss even in NoProfile !!!
365             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
366             _profile=oss.str();
367             da3->setName(_profile.c_str());
368             glob.appendProfile(da3);
369           }
370         MCAuto<DataArrayInt> da4(DataArrayInt::New());
371         _nval=da3->getNbOfElems();
372         da4->alloc(_nval*nbi,1);
373         int *da4Ptr(da4->getPointer());
374         for(int i=0;i<_nval;i++)
375           {
376             int ref=dai2Ptr[offset+da3Ptr[i]];
377             for(int j=0;j<nbi;j++)
378               *da4Ptr++=ref+j;
379           }
380         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
381         _localization=oss2.str();
382         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
383         _end=_start+_nval*nbi;
384         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
385         break;
386       }
387     default:
388       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
389   }
390   start=_end;
391 }
392
393 /*!
394  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
395  * \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).
396  * \param [in] multiTypePfl is the end user profile specified in high level API
397  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
398  * \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.
399  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
400  * \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.
401  */
402 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldTemplate *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
403 {
404   _profile.clear();
405   _type=field->getTypeOfField();
406   std::string pflName(multiTypePfl->getName());
407   std::ostringstream oss; oss << pflName;
408   if(_type!=ON_NODES)
409     {
410       if(!isPflAlone)
411         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
412     }
413   else
414     { oss << "_NODE"; }
415   if(locIds)
416     {
417       if(pflName.empty())
418         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
419       if(_type!=ON_GAUSS_PT)
420         {
421           locIds->setName(oss.str());
422           glob.appendProfile(locIds);
423           _profile=oss.str();
424         }
425     }
426   _start=start;
427   switch(_type)
428   {
429     case ON_NODES:
430       {
431         _nval=idsInPfl->getNumberOfTuples();
432         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
433         _end=_start+_nval;
434         break;
435       }
436     case ON_CELLS:
437       {
438         _nval=idsInPfl->getNumberOfTuples();
439         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
440         _end=_start+_nval;
441         break;
442       }
443     case ON_GAUSS_NE:
444       {
445         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
446         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
447         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
448         arr3->computeOffsetsFull();
449         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
450         int trueNval=tmp->getNumberOfTuples();
451         _nval=idsInPfl->getNumberOfTuples();
452         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
453         _end=_start+trueNval;
454         break;
455       }
456     case ON_GAUSS_PT:
457       {
458         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
459         if(!disc2)
460           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
461         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
462         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
463         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
464         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
465         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
466         //
467         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
468         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
469         //
470         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
471         int trueNval=0;
472         for(const int *pt=da4->begin();pt!=da4->end();pt++)
473           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
474         tmp->alloc(trueNval,1);
475         int *tmpPtr=tmp->getPointer();
476         for(const int *pt=da4->begin();pt!=da4->end();pt++)
477           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
478             *tmpPtr++=j;
479         //
480         _nval=da4->getNumberOfTuples();
481         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
482         _end=_start+trueNval;
483         oss << "_loc_" << _loc_id;
484         if(locIds)
485           {
486             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
487             da5->setName(oss.str());
488             glob.appendProfile(da5);
489             _profile=oss.str();
490           }
491         else
492           {
493             if(!da3->isIota(nbOfEltsInWholeMesh))
494               {
495                 da3->setName(oss.str());
496                 glob.appendProfile(da3);
497                 _profile=oss.str();
498               }
499           }
500         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
501         _localization=oss2.str();
502         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
503         break;
504       }
505     default:
506       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
507   }
508   start=_end;
509 }
510
511 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
512 {
513   _start=start;
514   _nval=arrr->getNumberOfTuples();
515   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
516   _end=_start+_nval;
517   start=_end;
518 }
519
520 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
521 {
522   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
523 }
524
525 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId)
526 {
527   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
528 }
529
530 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
531 {
532   return new MEDFileFieldPerMeshPerTypePerDisc(other);
533 }
534
535 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
536 {
537   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
538 }
539
540 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
541 {
542   std::vector<const BigMemoryObject *> ret(1);
543   ret[0]=(const PartDefinition*)_pd;
544   return ret;
545 }
546
547 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const
548 {
549   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(*this));
550   ret->_father=father;
551   return ret.retn();
552 }
553
554 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
555 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
556 {
557   if(pd)
558     pd->incrRef();
559 }
560 catch(INTERP_KERNEL::Exception& e)
561 {
562     throw e;
563 }
564
565 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
566 {
567 }
568
569 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)
570 {
571 }
572
573 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
574     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
575 {
576 }
577
578 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)
579 {
580   const PartDefinition *pd(_pd);
581   if(!pd)
582     {
583       med_entity_type mentiCpy(menti);
584       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
585       int nbi,tmp1;
586       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
587       if(nbValsInFile==0 && menti==MED_CELL)
588         {//
589           nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_FACE,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
590           if(nbValsInFile==0)
591             {
592               nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_EDGE,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
593               if(nbValsInFile!=0)
594                 { mentiCpy=MED_DESCENDING_EDGE; }
595             }
596           else
597             { mentiCpy=MED_DESCENDING_FACE; }
598         }
599       if(_end-_start!=nbValsInFile*nbi)
600         {
601           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 !";
602           throw INTERP_KERNEL::Exception(oss.str());
603         }
604       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,mentiCpy,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
605     }
606   else
607     {
608       if(!_profile.empty())
609         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
610       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
611       int profilesize,nbi;
612       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
613       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
614       if(spd)
615         {
616           int start,stop,step;
617           spd->getSlice(start,stop,step);
618           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
619           med_filter filter=MED_FILTER_INIT;
620           MEDFILESAFECALLERRD0(MEDfilterBlockOfEntityCr,(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
621                                                          MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
622                                                          /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
623                                                          /*lastblocksize=useless because count=1*/0,&filter));
624           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
625           MEDfilterClose(&filter);
626           return ;
627         }
628       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
629       if(dpd)
630         {
631           dpd->checkConsistencyLight();
632           MCAuto<DataArrayInt> myIds(dpd->toDAI());
633           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
634           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
635           myIds->applyLin(1,-a);
636           int nbOfEltsToLoad(b-a+1);
637           med_filter filter=MED_FILTER_INIT;
638           {//TODO : manage int32 !
639             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
640             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
641             MEDFILESAFECALLERRD0(MEDfilterBlockOfEntityCr,(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
642                                                            MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
643                                                            /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
644                                                            /*lastblocksize=useless because count=1*/0,&filter));
645             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
646             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
647             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
648             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
649           }
650           MEDfilterClose(&filter);
651         }
652       else
653         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
654     }
655 }
656
657 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
658 {
659   return _father;
660 }
661
662 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
663 {
664   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
665   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
666   std::string fieldName(nasc.getName()),meshName(getMeshName());
667   int iteration(getIteration()),order(getOrder()),profilesize,nbi;
668   TypeOfField type(getType());
669   med_geometry_type mgeoti;
670   med_entity_type menti;
671   _father->entriesForMEDfile(type,mgeoti,menti);
672   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
673   if(zeNVal==0 && type==ON_CELLS)
674     {//eheh maybe there's a surprise :)
675       int zeNVal1(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_FACE,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
676       if(zeNVal1==0)
677         {
678           int zeNVal2(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_EDGE,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
679           if(zeNVal2!=0)
680             zeNVal=zeNVal2;
681         }
682       else
683         {
684           zeNVal=zeNVal1;
685         }
686     }
687   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
688   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
689   const PartDefinition *pd(_pd);
690   if(!pd)
691     {
692       _nval=zeNVal;
693     }
694   else
695     {
696       if(!_profile.empty())
697         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
698       _nval=pd->getNumberOfElems();
699     }
700   _start=start;
701   _end=start+_nval*nbi;
702   start=_end;
703   if(type==ON_CELLS && !_localization.empty())
704     {
705       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
706         setType(ON_GAUSS_PT);
707       else
708         {
709           setType(ON_GAUSS_NE);
710           _localization.clear();
711         }
712     }
713 }
714
715 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
716 {
717   std::string fieldName(nasc.getName()),meshName(getMeshName());
718   int iteration(getIteration()),order(getOrder());
719   TypeOfField type(getType());
720   med_geometry_type mgeoti;
721   med_entity_type menti;
722   _father->entriesForMEDfile(type,mgeoti,menti);
723   if(_start>_end)
724     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
725   if(_start==_end)
726     return ;
727   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
728   if(_start<0 || _start>=arr->getNumberOfTuples())
729     {
730       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
731       throw INTERP_KERNEL::Exception(oss.str());
732     }
733   if(_end<0 || _end>arr->getNumberOfTuples())
734     {
735       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
736       throw INTERP_KERNEL::Exception(oss.str());
737     }
738   int nbOfCompo(arr->getNumberOfComponents());
739   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
740   if(arrD)
741     {
742       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
743       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
744       return ;
745     }
746   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
747   if(arrI)
748     {
749       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
750       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
751       return ;
752     }
753   DataArrayFloat *arrF(dynamic_cast<DataArrayFloat *>(arr));
754   if(arrF)
755     {
756       float *startFeeding(arrF->getPointer()+_start*nbOfCompo);
757       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
758       return ;
759     }
760   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 FLOAT32 or INT32 !");
761 }
762
763 /*!
764  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
765  */
766 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
767 {
768   int delta=_end-_start;
769   _start=newValueOfStart;
770   _end=_start+delta;
771 }
772
773 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
774 {
775   return _father->getIteration();
776 }
777
778 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
779 {
780   return _father->getOrder();
781 }
782
783 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
784 {
785   return _father->getTime();
786 }
787
788 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
789 {
790   return _father->getMeshName();
791 }
792
793 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
794 {
795   const char startLine[]="    ## ";
796   std::string startLine2(bkOffset,' ');
797   startLine2+=startLine;
798   INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
799   oss << startLine2 << "Localization #" << id << "." << std::endl;
800   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
801   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
802   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
803   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
804 }
805
806 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
807 {
808   return _type;
809 }
810
811 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
812 {
813   return _father->getGeoType();
814 }
815
816 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
817 {
818   types.insert(_type);
819 }
820
821 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
822 {
823   _type=newType;
824 }
825
826 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
827 {
828   return _father->getNumberOfComponents();
829 }
830
831 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
832 {
833   return _end-_start;
834 }
835
836 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
837 {
838   return _father->getOrCreateAndGetArray();
839 }
840
841 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
842 {
843   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
844   return fath->getOrCreateAndGetArray();
845 }
846
847 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
848 {
849   return _father->getInfo();
850 }
851
852 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
853 {
854   return _profile;
855 }
856
857 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
858 {
859   _profile=newPflName;
860 }
861
862 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
863 {
864   return _localization;
865 }
866
867 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
868 {
869   _localization=newLocName;
870 }
871
872 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
873 {
874   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
875     {
876       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
877         {
878           _profile=(*it2).second;
879           return;
880         }
881     }
882 }
883
884 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
885 {
886   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
887     {
888       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
889         {
890           _localization=(*it2).second;
891           return;
892         }
893     }
894 }
895
896 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
897 {
898   if(type!=_type)
899     return ;
900   dads.push_back(std::pair<int,int>(_start,_end));
901   geoTypes.push_back(getGeoType());
902   if(_profile.empty())
903     pfls.push_back(0);
904   else
905     {
906       pfls.push_back(glob->getProfile(_profile.c_str()));
907     }
908   if(_localization.empty())
909     locs.push_back(-1);
910   else
911     {
912       locs.push_back(glob->getLocalizationId(_localization.c_str()));
913     }
914 }
915
916 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
917 {
918   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));
919   startEntryId++;
920 }
921
922 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
923 {
924   TypeOfField type=getType();
925   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
926   med_geometry_type mgeoti;
927   med_entity_type menti;
928   _father->entriesForMEDfile(getType(),mgeoti,menti);
929   const DataArray *arr(getOrCreateAndGetArray());
930   if(!arr)
931     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
932   if(!arr->isAllocated())
933     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
934   const DataArrayDouble *arrD(dynamic_cast<const DataArrayDouble *>(arr));
935   const DataArrayInt *arrI(dynamic_cast<const DataArrayInt *>(arr));
936   const DataArrayFloat *arrF(dynamic_cast<const DataArrayFloat *>(arr));
937   const unsigned char *locToWrite=0;
938   if(arrD)
939     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
940   else if(arrI)
941     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
942   else if(arrF)
943     locToWrite=reinterpret_cast<const unsigned char *>(arrF->getConstPointer()+_start*arr->getNumberOfComponents());
944   else
945     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 FLOAT32 and INT32 !");
946   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
947                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
948                                                    locToWrite));
949 }
950
951 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
952 {
953   type=_type;
954   pfl=_profile;
955   loc=_localization;
956   dad.first=_start; dad.second=_end;
957 }
958
959 /*!
960  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
961  *             This code corresponds to the distribution of types in the corresponding mesh.
962  * \param [out] ptToFill memory zone where the output will be stored.
963  * \return the size of data pushed into output param \a ptToFill
964  */
965 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
966 {
967   _loc_id=offset;
968   std::ostringstream oss;
969   std::size_t nbOfType=codeOfMesh.size()/3;
970   int found=-1;
971   for(std::size_t i=0;i<nbOfType && found==-1;i++)
972     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
973       found=(int)i;
974   if(found==-1)
975     {
976       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
977       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
978       throw INTERP_KERNEL::Exception(oss.str());
979     }
980   int *work=ptToFill;
981   if(_profile.empty())
982     {
983       if(_nval!=codeOfMesh[3*found+1])
984         {
985           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
986           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
987           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
988           throw INTERP_KERNEL::Exception(oss.str());
989         }
990       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
991         *work++=ii;
992     }
993   else
994     {
995       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
996       if(pfl->getNumberOfTuples()!=_nval)
997         {
998           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
999           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
1000           oss << _nval;
1001           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
1002           throw INTERP_KERNEL::Exception(oss.str());
1003         }
1004       int offset2=codeOfMesh[3*found+2];
1005       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
1006         {
1007           if(*pflId<codeOfMesh[3*found+1])
1008             *work++=offset2+*pflId;
1009         }
1010     }
1011   return _nval;
1012 }
1013
1014 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
1015 {
1016   for(int i=_start;i<_end;i++)
1017     *ptToFill++=i;
1018   return _end-_start;
1019 }
1020
1021 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
1022 {
1023   switch(type)
1024   {
1025     case ON_CELLS:
1026       return -2;
1027     case ON_GAUSS_NE:
1028       return -1;
1029     case ON_GAUSS_PT:
1030       return locId;
1031     default:
1032       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
1033   }
1034 }
1035
1036 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
1037 {
1038   int id=0;
1039   std::map<std::pair<std::string,TypeOfField>,int> m;
1040   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
1041   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
1042     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
1043       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
1044   ret.resize(id);
1045   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
1046     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
1047   return ret;
1048 }
1049
1050 /*!
1051  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
1052  * 
1053  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
1054  * \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.
1055  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
1056  * \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)
1057  * \param [in,out] glob if necessary by the method, new profiles can be added to it
1058  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
1059  * \param [out] result All new entries will be appended on it.
1060  * \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 !)
1061  */
1062 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1063                                                        const DataArrayInt *explicitIdsInMesh,
1064                                                        const std::vector<int>& newCode,
1065                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
1066                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
1067 {
1068   if(entriesOnSameDisc.empty())
1069     return false;
1070   TypeOfField type=entriesOnSameDisc[0]->getType();
1071   int szEntities=0,szTuples=0;
1072   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
1073     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
1074   int nbi=szTuples/szEntities;
1075   if(szTuples%szEntities!=0)
1076     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
1077   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
1078   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
1079   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
1080   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
1081   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
1082   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
1083   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
1084   int id=0;
1085   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
1086     {
1087       int startOfEltIdOfChunk=(*it)->_start;
1088       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
1089       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
1090       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
1091       //
1092       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
1093       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
1094       //
1095       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
1096       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
1097     }
1098   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
1099   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
1100   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
1101   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
1102   //
1103   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
1104   //
1105   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
1106   arrPart->renumberInPlace(renumTupleIds->begin());
1107   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
1108   bool ret=false;
1109   const int *idIt=diffVals->begin();
1110   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
1111   int offset2=0;
1112   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
1113     {
1114       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
1115       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
1116       int nbEntityElts=subIds->getNumberOfTuples();
1117       bool ret2;
1118       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
1119           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
1120                                       offset+offset2,
1121                                       li,glob,ret2);
1122       ret=ret || ret2;
1123       result.push_back(eltToAdd);
1124       offset2+=nbEntityElts*nbi;
1125     }
1126   ret=ret || li.empty();
1127   return ret;
1128 }
1129
1130 /*!
1131  * \param [in] typeF type of field of new chunk
1132  * \param [in] geoType the geometric type of the chunk
1133  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
1134  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
1135  * \param [in] nbi number of integration points
1136  * \param [in] offset The offset in the **global array of data**.
1137  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
1138  *                 to the new chunk to create.
1139  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
1140  * \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
1141  *              and corresponding entry erased from \a entriesOnSameDisc.
1142  * \return a newly allocated chunk
1143  */
1144 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
1145                                                                                                   bool isPfl, int nbi, int offset,
1146                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1147                                                                                                   MEDFileFieldGlobsReal& glob,
1148                                                                                                   bool &notInExisting)
1149 {
1150   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1151   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1152   for(;it!=entriesOnSameDisc.end();it++)
1153     {
1154       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1155         {
1156           if(!isPfl)
1157             {
1158               if((*it)->_profile.empty())
1159                 break;
1160               else
1161                 if(!(*it)->_profile.empty())
1162                   {
1163                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1164                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1165                       break;
1166                   }
1167             }
1168         }
1169     }
1170   if(it==entriesOnSameDisc.end())
1171     {
1172       notInExisting=true;
1173       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1174       ret->_type=typeF;
1175       ret->_loc_id=(int)geoType;
1176       ret->_nval=nbMeshEntities;
1177       ret->_start=offset;
1178       ret->_end=ret->_start+ret->_nval*nbi;
1179       if(isPfl)
1180         {
1181           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1182           glob.appendProfile(idsOfMeshElt);
1183           ret->_profile=idsOfMeshElt->getName();
1184         }
1185       //tony treatment of localization
1186       return ret;
1187     }
1188   else
1189     {
1190       notInExisting=false;
1191       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1192       ret->_loc_id=(int)geoType;
1193       ret->setNewStart(offset);
1194       entriesOnSameDisc.erase(it);
1195       return ret;
1196     }
1197
1198 }
1199
1200 ////////////////////////////////////
1201
1202 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1203 {
1204 }
1205
1206 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1207 {
1208   _father=father;
1209 }
1210
1211 void MEDFileFieldPerMeshPerTypeCommon::accept(MEDFileFieldVisitor& visitor) const
1212 {
1213   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1214     if((*it).isNotNull())
1215       {
1216         visitor.newPerMeshPerTypePerDisc(*it);
1217       }
1218 }
1219
1220 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1221 {
1222   std::size_t i=0;
1223   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1224     {
1225       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1226         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1227     }
1228 }
1229
1230 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1231 {
1232   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1233 }
1234
1235 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1236 {
1237   std::vector<const BigMemoryObject *> ret;
1238   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1239     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1240   return ret;
1241 }
1242
1243 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1244 {
1245   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1246   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1247     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1248 }
1249
1250 /*!
1251  * This method is the most general one. No optimization is done here.
1252  * \param [in] multiTypePfl is the end user profile specified in high level API
1253  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1254  * \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.
1255  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1256  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1257  * \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.
1258  */
1259 void MEDFileFieldPerMeshPerTypeCommon::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1260 {
1261   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1262   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1263     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1264 }
1265
1266 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1267 {
1268   _field_pm_pt_pd.resize(1);
1269   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1270   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1271 }
1272
1273 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1274 {
1275   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1276   if(!arr || !arr->isAllocated())
1277     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1278   _field_pm_pt_pd.resize(1);
1279   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1280   _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.
1281 }
1282
1283 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells)
1284 {
1285   TypeOfField type=field->getTypeOfField();
1286   if(type!=ON_GAUSS_PT)
1287     {
1288       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1289       int sz=_field_pm_pt_pd.size();
1290       bool found=false;
1291       for(int j=0;j<sz && !found;j++)
1292         {
1293           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1294             {
1295               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1296               found=true;
1297             }
1298         }
1299       if(!found)
1300         {
1301           _field_pm_pt_pd.resize(sz+1);
1302           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1303         }
1304       std::vector<int> ret(1,(int)sz);
1305       return ret;
1306     }
1307   else
1308     {
1309       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1310       int sz2=ret2.size();
1311       std::vector<int> ret3(sz2);
1312       int k=0;
1313       for(int i=0;i<sz2;i++)
1314         {
1315           int sz=_field_pm_pt_pd.size();
1316           int locIdToFind=ret2[i];
1317           bool found=false;
1318           for(int j=0;j<sz && !found;j++)
1319             {
1320               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1321                 {
1322                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1323                   ret3[k++]=j;
1324                   found=true;
1325                 }
1326             }
1327           if(!found)
1328             {
1329               _field_pm_pt_pd.resize(sz+1);
1330               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1331               ret3[k++]=sz;
1332             }
1333         }
1334       return ret3;
1335     }
1336 }
1337
1338 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells)
1339 {
1340   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1341   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1342   if(!disc2)
1343     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1344   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1345   if(!da)
1346     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1347   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1348   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1349   if(retTmp->presenceOfValue(-1))
1350     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1351   std::vector<int> ret(retTmp->begin(),retTmp->end());
1352   return ret;
1353 }
1354
1355 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells)
1356 {
1357   TypeOfField type=field->getTypeOfField();
1358   if(type!=ON_GAUSS_PT)
1359     {
1360       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1361       int sz=_field_pm_pt_pd.size();
1362       bool found=false;
1363       for(int j=0;j<sz && !found;j++)
1364         {
1365           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1366             {
1367               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1368               found=true;
1369             }
1370         }
1371       if(!found)
1372         {
1373           _field_pm_pt_pd.resize(sz+1);
1374           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1375         }
1376       std::vector<int> ret(1,0);
1377       return ret;
1378     }
1379   else
1380     {
1381       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1382       int sz2=ret2.size();
1383       std::vector<int> ret3(sz2);
1384       int k=0;
1385       for(int i=0;i<sz2;i++)
1386         {
1387           int sz=_field_pm_pt_pd.size();
1388           int locIdToFind=ret2[i];
1389           bool found=false;
1390           for(int j=0;j<sz && !found;j++)
1391             {
1392               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1393                 {
1394                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1395                   ret3[k++]=j;
1396                   found=true;
1397                 }
1398             }
1399           if(!found)
1400             {
1401               _field_pm_pt_pd.resize(sz+1);
1402               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1403               ret3[k++]=sz;
1404             }
1405         }
1406       return ret3;
1407     }
1408 }
1409
1410 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells)
1411 {
1412   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1413   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1414   if(!disc2)
1415     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1416   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1417   if(!da)
1418     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1419   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1420   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1421   if(retTmp->presenceOfValue(-1))
1422     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1423   std::vector<int> ret(retTmp->begin(),retTmp->end());
1424   return ret;
1425 }
1426
1427 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1428 {
1429   return _father;
1430 }
1431
1432 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1433 {
1434   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1435   int curDim((int)cm.getDimension());
1436   if(dim!=std::numeric_limits<int>::max())
1437     {
1438       if(dim!=curDim)
1439         return false;
1440     }
1441   else
1442     dim=curDim;
1443   return true;
1444 }
1445
1446 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1447 {
1448   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1449     {
1450       (*it)->fillTypesOfFieldAvailable(types);
1451     }
1452 }
1453
1454 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
1455 {
1456   int sz=_field_pm_pt_pd.size();
1457   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1458   for(int i=0;i<sz;i++)
1459     {
1460       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1461     }
1462 }
1463
1464 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1465 {
1466   return _father->getIteration();
1467 }
1468
1469 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1470 {
1471   return _father->getOrder();
1472 }
1473
1474 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1475 {
1476   return _father->getTime();
1477 }
1478
1479 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1480 {
1481   return _father->getMeshName();
1482 }
1483
1484 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1485 {
1486   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1487     {
1488       globalSz+=(*it)->getNumberOfTuples();
1489     }
1490   nbOfEntries+=(int)_field_pm_pt_pd.size();
1491 }
1492
1493 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1494 {
1495   return _father->getNumberOfComponents();
1496 }
1497
1498 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1499 {
1500   std::size_t nb(0);
1501   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1502     {
1503       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1504       if(fmtd)
1505         nb++;
1506     }
1507   return nb>1;
1508 }
1509
1510 void MEDFileFieldPerMeshPerTypeCommon::pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc)
1511 {
1512   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt;
1513   elt.takeRef(disc);
1514   _field_pm_pt_pd.push_back(elt);
1515 }
1516
1517 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1518 {
1519   return _father->getOrCreateAndGetArray();
1520 }
1521
1522 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1523 {
1524   const MEDFileFieldPerMesh *fath=_father;
1525   return fath->getOrCreateAndGetArray();
1526 }
1527
1528 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1529 {
1530   return _father->getInfo();
1531 }
1532
1533 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1534 {
1535   std::vector<std::string> ret;
1536   std::set<std::string> ret2;
1537   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1538     {
1539       std::string tmp=(*it1)->getProfile();
1540       if(!tmp.empty())
1541         if(ret2.find(tmp)==ret2.end())
1542           {
1543             ret.push_back(tmp);
1544             ret2.insert(tmp);
1545           }
1546     }
1547   return ret;
1548 }
1549
1550 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1551 {
1552   std::vector<std::string> ret;
1553   std::set<std::string> ret2;
1554   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1555     {
1556       std::string tmp=(*it1)->getLocalization();
1557       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1558         if(ret2.find(tmp)==ret2.end())
1559           {
1560             ret.push_back(tmp);
1561             ret2.insert(tmp);
1562           }
1563     }
1564   return ret;
1565 }
1566
1567 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1568 {
1569   std::vector<std::string> ret;
1570   std::set<std::string> ret2;
1571   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1572     {
1573       std::string tmp=(*it1)->getProfile();
1574       if(!tmp.empty())
1575         ret.push_back(tmp);
1576     }
1577   return ret;
1578 }
1579
1580 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1581 {
1582   std::vector<std::string> ret;
1583   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1584     {
1585       std::string tmp=(*it1)->getLocalization();
1586       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1587         ret.push_back(tmp);
1588     }
1589   return ret;
1590 }
1591
1592 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1593 {
1594   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1595     (*it1)->changePflsRefsNamesGen(mapOfModif);
1596 }
1597
1598 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1599 {
1600   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1601     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1602 }
1603
1604 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1605 {
1606   if(_field_pm_pt_pd.empty())
1607     {
1608       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1609       throw INTERP_KERNEL::Exception(oss.str());
1610     }
1611   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1612     return _field_pm_pt_pd[locId];
1613   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1614   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1615   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1616   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1617 }
1618
1619 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1620 {
1621   if(_field_pm_pt_pd.empty())
1622     {
1623       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1624       throw INTERP_KERNEL::Exception(oss.str());
1625     }
1626   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1627     return _field_pm_pt_pd[locId];
1628   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1629   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1630   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1631   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1632 }
1633
1634 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1635 {
1636   int i=0;
1637   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1638     {
1639       (*it)->fillValues(i,startEntryId,entries);
1640     }
1641 }
1642
1643 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1644 {
1645   _field_pm_pt_pd=leaves;
1646   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1647     (*it)->setFather(this);
1648 }
1649
1650 /*!
1651  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1652  *  \param [out] its - list of pair (start,stop) kept
1653  *  \return bool - false if the type of field \a tof is not contained in \a this.
1654  */
1655 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1656 {
1657   bool ret(false);
1658   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1659   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1660     if((*it)->getType()==tof)
1661       {
1662         newPmPtPd.push_back(*it);
1663         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1664         (*it)->setNewStart(globalNum);
1665         globalNum=(*it)->getEnd();
1666         its.push_back(bgEnd);
1667         ret=true;
1668       }
1669   if(ret)
1670     _field_pm_pt_pd=newPmPtPd;
1671   return ret;
1672 }
1673
1674 /*!
1675  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1676  *  \param [out] its - list of pair (start,stop) kept
1677  *  \return bool - false if the type of field \a tof is not contained in \a this.
1678  */
1679 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1680 {
1681   if(_field_pm_pt_pd.size()<=idOfDisc)
1682     return false;
1683   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1684   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1685   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1686   elt->setNewStart(globalNum);
1687   globalNum=elt->getEnd();
1688   its.push_back(bgEnd);
1689   _field_pm_pt_pd=newPmPtPd;
1690   return true;
1691 }
1692
1693 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1694 {
1695   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1696     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1697 }
1698
1699 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1700 {
1701   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1702     (*it)->loadBigArray(fid,nasc);
1703 }
1704
1705 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1706 {
1707   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1708     {
1709       (*it)->copyOptionsFrom(*this);
1710       (*it)->writeLL(fid,nasc);
1711     }
1712 }
1713
1714 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1715 {
1716   switch(ikType)
1717   {
1718     case ON_CELLS:
1719       medfGeoType=typmai3[(int)ikGeoType];
1720       return MED_CELL;
1721     case ON_NODES:
1722       medfGeoType=MED_NONE;
1723       return MED_NODE;
1724     case ON_GAUSS_NE:
1725       medfGeoType=typmai3[(int)ikGeoType];
1726       return MED_NODE_ELEMENT;
1727     case ON_GAUSS_PT:
1728       medfGeoType=typmai3[(int)ikGeoType];
1729       return MED_CELL;
1730     default:
1731       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1732   }
1733   return MED_UNDEF_ENTITY_TYPE;
1734 }
1735
1736 //////////////////////////////////////////////////
1737
1738 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1739 {
1740   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1741 }
1742
1743 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1744 {
1745   return new MEDFileFieldPerMeshPerType(fath,geoType);
1746 }
1747
1748 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1749 {
1750   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1751   ret->setFather(father);
1752   ret->deepCopyElements();
1753   return ret.retn();
1754 }
1755
1756 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
1757 {
1758   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1759     {
1760       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1761       if(meshDim!=(int)cm.getDimension())
1762         return ;
1763     }
1764   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1765     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1766 }
1767
1768 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1769 {
1770   return _geo_type;
1771 }
1772
1773 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1774 {
1775   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1776 }
1777
1778 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1779 {
1780   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1781   int curDim((int)cm.getDimension());
1782   dim=std::max(dim,curDim);
1783 }
1784
1785 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1786 {
1787   const char startLine[]="  ## ";
1788   std::string startLine2(bkOffset,' ');
1789   std::string startLine3(startLine2);
1790   startLine3+=startLine;
1791   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1792     {
1793       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1794       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1795     }
1796   else
1797     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1798   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1799   int i=0;
1800   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1801     {
1802       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1803       if(cur)
1804         cur->simpleRepr(bkOffset,oss,i);
1805       else
1806         {
1807           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1808         }
1809     }
1810 }
1811
1812 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1813 {
1814   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1815   return std::string(cm.getRepr());
1816 }
1817
1818 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1819 {
1820 }
1821
1822 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1823 {
1824   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1825   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1826   med_geometry_type mgeoti;
1827   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1828   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1829   _field_pm_pt_pd.resize(nbProfiles);
1830   for(int i=0;i<nbProfiles;i++)
1831     {
1832       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1833     }
1834   if(type==ON_CELLS)
1835     {
1836       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1837       for(int i=0;i<nbProfiles2;i++)
1838         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1839     }
1840   if(!_field_pm_pt_pd.empty() || type!=ON_CELLS)
1841     return ;
1842   // dark side of the force.
1843   {
1844     int nbProfiles1(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_FACE,mgeoti,pflName,locName));
1845     int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_EDGE,mgeoti,pflName,locName));
1846     if(nbProfiles1==0 && nbProfiles2==0)
1847       return ;// OK definitely nothing in field
1848     menti=nbProfiles1>=nbProfiles2?MED_DESCENDING_FACE:MED_DESCENDING_EDGE;//not enough words to describe the beauty
1849     nbProfiles=std::max(nbProfiles1,nbProfiles2);
1850     _field_pm_pt_pd.resize(nbProfiles);
1851     for(int i=0;i<nbProfiles;i++)
1852       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_CELLS,i,pd);
1853   }
1854 }
1855
1856 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)
1857 {
1858   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1859   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1860   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1861     {
1862       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1863         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1864     }
1865   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1866     {
1867       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1868       ret->_field_pm_pt_pd.push_back(agg);
1869     }
1870   return ret;
1871 }
1872
1873 //////////////////////////////////////////////////
1874
1875 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1876 {
1877   if(!entities)
1878     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1879   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1880   if(!entities2)
1881     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1882   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1883   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1884 }
1885
1886 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1887 {
1888   _se.takeRef(se);
1889   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1890   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1891   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1892   _field_pm_pt_pd.resize(nbProfiles);
1893   for(int i=0;i<nbProfiles;i++)
1894     {
1895       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1896     }
1897 }
1898
1899 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1900 {
1901   return _se->getDynGT();
1902 }
1903
1904 std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const
1905 {
1906   return _se->getName();
1907 }
1908
1909 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1910 {
1911   throw INTERP_KERNEL::Exception("not implemented yet !");
1912 }
1913
1914 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1915 {
1916   gt=getDynGT();
1917   ent=MED_STRUCT_ELEMENT;
1918 }
1919
1920 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1921 {
1922   throw INTERP_KERNEL::Exception("not implemented yet !");
1923 }
1924
1925 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1926 {
1927   const char startLine[]="  ## ";
1928   std::string startLine2(bkOffset,' ');
1929   std::string startLine3(startLine2);
1930   startLine3+=startLine;
1931   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1932   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1933   int i=0;
1934   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1935     {
1936       if((*it).isNotNull())
1937         (*it)->simpleRepr(bkOffset,oss,i);
1938       else
1939         {
1940           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1941         }
1942     }
1943 }
1944
1945 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1946 {
1947   throw INTERP_KERNEL::Exception("not implemented yet !");
1948 }
1949
1950 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1951 {
1952   MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1953   ret->setFather(father);
1954   ret->deepCopyElements();
1955   return ret.retn();
1956 }
1957
1958 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
1959 {
1960   throw INTERP_KERNEL::Exception("not implemented yet !");
1961 }
1962
1963 //////////////////////////////////////////////////
1964
1965 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1966 {
1967   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1968 }
1969
1970 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1971 {
1972   return new MEDFileFieldPerMesh(fath,mesh);
1973 }
1974
1975 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1976 {
1977   return _field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1978 }
1979
1980 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1981 {
1982   std::vector<const BigMemoryObject *> ret;
1983   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1984     ret.push_back(*it);
1985   return ret;
1986 }
1987
1988 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1989 {
1990   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1991   ret->_father=father;
1992   std::size_t i=0;
1993   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1994     {
1995       if((*it).isNotNull())
1996         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1997     }
1998   return ret.retn();
1999 }
2000
2001 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
2002 {
2003   std::string startLine(bkOffset,' ');
2004   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << getMeshName() << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
2005   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
2006   int i=0;
2007   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2008     {
2009       if((*it).isNotNull())
2010         (*it)->simpleRepr(bkOffset,oss,i);
2011       else
2012         {
2013           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
2014         }
2015     }
2016 }
2017
2018 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
2019 {
2020   mesh->getTime(_mesh_iteration,_mesh_order);
2021 }
2022
2023 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2024 {
2025   int nbOfTypes=code.size()/3;
2026   int offset=0;
2027   for(int i=0;i<nbOfTypes;i++)
2028     {
2029       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
2030       int nbOfCells=code[3*i+1];
2031       int pos=addNewEntryIfNecessary(type);
2032       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
2033       offset+=nbOfCells;
2034     }
2035 }
2036
2037 /*!
2038  * This method is the most general one. No optimization is done here.
2039  * \param [in] multiTypePfl is the end user profile specified in high level API
2040  * \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].
2041  * \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.
2042  * \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.
2043  * \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.
2044  * \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.
2045  */
2046 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 MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2047 {
2048   int nbOfTypes(code.size()/3);
2049   for(int i=0;i<nbOfTypes;i++)
2050     {
2051       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
2052       int pos=addNewEntryIfNecessary(type);
2053       DataArrayInt *pfl=0;
2054       if(code[3*i+2]!=-1)
2055         pfl=idsPerType[code[3*i+2]];
2056       int nbOfTupes2=code2.size()/3;
2057       int found=0;
2058       for(;found<nbOfTupes2;found++)
2059         if(code[3*i]==code2[3*found])
2060           break;
2061       if(found==nbOfTupes2)
2062         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
2063       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
2064     }
2065 }
2066
2067 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
2068 {
2069   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2070   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
2071 }
2072
2073 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2074 {
2075   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2076   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
2077 }
2078
2079 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
2080 {
2081   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2082     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
2083 }
2084
2085 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
2086 {
2087   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2088     (*it)->loadBigArraysRecursively(fid,nasc);
2089 }
2090
2091 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
2092 {
2093   int nbOfTypes=_field_pm_pt.size();
2094   for(int i=0;i<nbOfTypes;i++)
2095     {
2096       _field_pm_pt[i]->copyOptionsFrom(*this);
2097       _field_pm_pt[i]->writeLL(fid,nasc);
2098     }
2099 }
2100
2101 void MEDFileFieldPerMesh::getDimension(int& dim) const
2102 {
2103   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2104     (*it)->getDimension(dim);
2105 }
2106
2107 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
2108 {
2109   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2110     if(!(*it)->isUniqueLevel(dim))
2111       return false;
2112   return true;
2113 }
2114
2115 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
2116 {
2117   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2118     (*it)->fillTypesOfFieldAvailable(types);
2119 }
2120
2121 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
2122 {
2123   int sz=_field_pm_pt.size();
2124   std::vector< std::vector<std::pair<int,int> > > ret(sz);
2125   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
2126   for(int i=0;i<sz;i++)
2127     {
2128       types[i]=_field_pm_pt[i]->getGeoType();
2129       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
2130     }
2131   return ret;
2132 }
2133
2134 double MEDFileFieldPerMesh::getTime() const
2135 {
2136   int tmp1,tmp2;
2137   return _father->getTime(tmp1,tmp2);
2138 }
2139
2140 int MEDFileFieldPerMesh::getIteration() const
2141 {
2142   return _father->getIteration();
2143 }
2144
2145 int MEDFileFieldPerMesh::getOrder() const
2146 {
2147   return _father->getOrder();
2148 }
2149
2150 int MEDFileFieldPerMesh::getNumberOfComponents() const
2151 {
2152   return _father->getNumberOfComponents();
2153 }
2154
2155 std::string MEDFileFieldPerMesh::getMeshName() const
2156 {
2157   return _father->getMeshName();
2158 }
2159
2160 void MEDFileFieldPerMesh::setMeshName(const std::string& meshName)
2161 {
2162   _father->setMeshName(meshName);
2163 }
2164
2165 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
2166 {
2167   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2168     {
2169       if((*it).isNull())
2170         continue;
2171       if((*it)->presenceOfMultiDiscPerGeoType())
2172         return true;
2173     }
2174   return false;
2175 }
2176
2177 bool MEDFileFieldPerMesh::presenceOfStructureElements() const
2178 {
2179   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2180     if((*it).isNotNull())
2181       {
2182         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2183         if(pt)
2184           return true;
2185       }
2186   return false;
2187 }
2188
2189 bool MEDFileFieldPerMesh::onlyStructureElements() const
2190 {
2191   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2192     if((*it).isNotNull())
2193       {
2194         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2195         if(!pt)
2196           return false;
2197       }
2198   return true;
2199 }
2200
2201 void MEDFileFieldPerMesh::killStructureElements()
2202 {
2203   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2204   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2205     {
2206       if((*it).isNotNull())
2207         {
2208           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2209           if(!pt)
2210             res.push_back(*it);
2211         }
2212     }
2213   _field_pm_pt=res;
2214 }
2215
2216 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2217 {
2218   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2219   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2220     {
2221       if((*it).isNotNull())
2222         {
2223           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2224           if(pt)
2225             res.push_back(*it);
2226         }
2227     }
2228   _field_pm_pt=res;
2229 }
2230
2231 void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName)
2232 {
2233   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2234   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2235     {
2236       if((*it).isNotNull())
2237         {
2238           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2239           if(!pt)
2240             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !");
2241           if(pt->getModelName()==seName)
2242             res.push_back(*it);
2243         }
2244     }
2245   _field_pm_pt=res;
2246 }
2247
2248 void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
2249 {
2250   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2251     {
2252       if((*it).isNotNull())
2253         {
2254           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2255           if(pt)
2256             {
2257               ps.push_back(std::pair<std::string,std::string>(getMeshName(),pt->getModelName()));
2258             }
2259           else
2260             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !");
2261         }
2262     }
2263 }
2264
2265 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2266 {
2267   if(!_father)
2268     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2269   return _father->getOrCreateAndGetArray();
2270 }
2271
2272 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2273 {
2274   if(!_father)
2275     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2276   return _father->getOrCreateAndGetArray();
2277 }
2278
2279 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2280 {
2281   return _father->getInfo();
2282 }
2283
2284 /*!
2285  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2286  * 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.
2287  * It returns 2 output vectors :
2288  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2289  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2290  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2291  */
2292 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)
2293 {
2294   int notNullPflsSz=0;
2295   int nbOfArrs=geoTypes.size();
2296   for(int i=0;i<nbOfArrs;i++)
2297     if(pfls[i])
2298       notNullPflsSz++;
2299   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2300   int nbOfDiffGeoTypes=geoTypes3.size();
2301   code.resize(3*nbOfDiffGeoTypes);
2302   notNullPfls.resize(notNullPflsSz);
2303   notNullPflsSz=0;
2304   int j=0;
2305   for(int i=0;i<nbOfDiffGeoTypes;i++)
2306     {
2307       int startZone=j;
2308       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2309       std::vector<const DataArrayInt *> notNullTmp;
2310       if(pfls[j])
2311         notNullTmp.push_back(pfls[j]);
2312       j++;
2313       for(;j<nbOfArrs;j++)
2314         if(geoTypes[j]==refType)
2315           {
2316             if(pfls[j])
2317               notNullTmp.push_back(pfls[j]);
2318           }
2319         else
2320           break;
2321       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2322       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2323       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2324       code[3*i]=(int)refType;
2325       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2326       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2327       if(notNullTmp.empty())
2328         code[3*i+2]=-1;
2329       else
2330         {
2331           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2332           code[3*i+2]=notNullPflsSz++;
2333         }
2334     }
2335 }
2336
2337 /*!
2338  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2339  */
2340 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)
2341 {
2342   int sz=dads.size();
2343   int ret=0;
2344   for(int i=0;i<sz;i++)
2345     {
2346       if(locs[i]==-1)
2347         {
2348           if(type!=ON_GAUSS_NE)
2349             ret+=dads[i].second-dads[i].first;
2350           else
2351             {
2352               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2353               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2354             }
2355         }
2356       else
2357         {
2358           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2359           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2360         }
2361     }
2362   return ret;
2363 }
2364
2365 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2366 {
2367   std::vector<std::string> ret;
2368   std::set<std::string> ret2;
2369   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2370     {
2371       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2372       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2373         if(ret2.find(*it2)==ret2.end())
2374           {
2375             ret.push_back(*it2);
2376             ret2.insert(*it2);
2377           }
2378     }
2379   return ret;
2380 }
2381
2382 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2383 {
2384   std::vector<std::string> ret;
2385   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2386     {
2387       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2388       ret.insert(ret.end(),tmp.begin(),tmp.end());
2389     }
2390   return ret;
2391 }
2392
2393 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2394 {
2395   std::vector<std::string> ret;
2396   std::set<std::string> ret2;
2397   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2398     {
2399       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2400       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2401         if(ret2.find(*it2)==ret2.end())
2402           {
2403             ret.push_back(*it2);
2404             ret2.insert(*it2);
2405           }
2406     }
2407   return ret;
2408 }
2409
2410 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2411 {
2412   std::vector<std::string> ret;
2413   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2414     {
2415       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2416       ret.insert(ret.end(),tmp.begin(),tmp.end());
2417     }
2418   return ret;
2419 }
2420
2421 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2422 {
2423   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2424     {
2425       if((*it).first==getMeshName())
2426         {
2427           setMeshName((*it).second);
2428           return true;
2429         }
2430     }
2431   return false;
2432 }
2433
2434 void MEDFileFieldPerMesh::convertMedBallIntoClassic()
2435 {
2436   if(_field_pm_pt.size()!=1)
2437     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : Only managed for single mesh !");
2438   if(_field_pm_pt[0].isNull())
2439     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : null pointer !");
2440   MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<MEDFileFieldPerMeshPerTypeDyn *>((MEDFileFieldPerMeshPerTypeCommon *)_field_pm_pt[0]));
2441   if(!pt)
2442     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : this is expected to be marked as structure element !");
2443   if(pt->getNumberOfLoc()!=1)
2444     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : only one loc managed !");
2445   const MEDFileFieldPerMeshPerTypePerDisc *disc(pt->getLeafGivenLocId(0));
2446   if(!disc)
2447     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : internal error !");
2448   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> disc2(MEDFileFieldPerMeshPerTypePerDisc::New(*disc));
2449   disc2->setType(ON_NODES);
2450   MCAuto<MEDFileFieldPerMeshPerType> pt2(MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR));
2451   disc2->setFather(pt2);
2452   pt2->setFather(this);
2453   pt2->pushDiscretization(disc2);
2454   _field_pm_pt[0]=DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(pt2);
2455 }
2456
2457 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2458                                                       MEDFileFieldGlobsReal& glob)
2459 {
2460   if(getMeshName()!=meshName)
2461     return false;
2462   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2463   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2464   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2465   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2466   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2467   getUndergroundDataArrayExt(entries);
2468   DataArray *arr0(getOrCreateAndGetArray());//tony
2469   if(!arr0)
2470     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2471   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2472   if(!arr0)
2473     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2474   int sz=0;
2475   if(!arr)
2476     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2477   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2478     {
2479       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2480         {
2481           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2482           sz+=(*it).second.second-(*it).second.first;
2483         }
2484       else
2485         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2486     }
2487   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2488   ////////////////////
2489   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2490   int *workI2=explicitIdsOldInMesh->getPointer();
2491   int sz1=0,sz2=0,sid=1;
2492   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2493   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2494   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2495     {
2496       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2497       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2498       int *workI=explicitIdsOldInArr->getPointer();
2499       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2500         {
2501           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2502           (*itL2)->setLocId(sz2);
2503           (*itL2)->_tmp_work1=(*itL2)->getStart();
2504           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2505         }
2506       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2507     }
2508   explicitIdsOldInMesh->reAlloc(sz2);
2509   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2510   ////////////////////
2511   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2512   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2513   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2514   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2515     {
2516       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2517       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2518       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2519     }
2520   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2521   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2522   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2523     {
2524       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2525       int newStart=elt->getLocId();
2526       elt->setLocId((*it)->getGeoType());
2527       elt->setNewStart(newStart);
2528       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2529       entriesKeptNew.push_back(elt);
2530       entriesKeptNew2.push_back(elt);
2531     }
2532   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2533   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2534   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2535   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2536   bool ret=false;
2537   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2538     {
2539       sid=0;
2540       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2541         {
2542           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2543           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2544           }*/
2545       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2546                                                             glob,arr2,otherEntriesNew) || ret;
2547     }
2548   if(!ret)
2549     return false;
2550   // Assign new dispatching
2551   assignNewLeaves(otherEntriesNew);
2552   arr->deepCopyFrom(*arr2);
2553   return true;
2554 }
2555
2556 /*!
2557  * \param [in,out] globalNum a global numbering counter for the renumbering.
2558  * \param [out] its - list of pair (start,stop) kept
2559  */
2560 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2561 {
2562   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2563   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2564     {
2565       std::vector< std::pair<int,int> > its2;
2566       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2567         {
2568           ret.push_back(*it);
2569           its.insert(its.end(),its2.begin(),its2.end());
2570         }
2571     }
2572   _field_pm_pt=ret;
2573 }
2574
2575 /*!
2576  * \param [in,out] globalNum a global numbering counter for the renumbering.
2577  * \param [out] its - list of pair (start,stop) kept
2578  */
2579 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2580 {
2581   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2582   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2583     {
2584       std::vector< std::pair<int,int> > its2;
2585       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2586         {
2587           ret.push_back(*it);
2588           its.insert(its.end(),its2.begin(),its2.end());
2589         }
2590     }
2591   _field_pm_pt=ret;
2592 }
2593
2594 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2595 {
2596   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2597   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2598     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2599   //
2600   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2601   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2602   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2603   for(;it1!=types.end();it1++,it2++)
2604     {
2605       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2606       elt->setLeaves((*it1).second);
2607       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2608       *it2=elt2;
2609     }
2610   _field_pm_pt=fieldPmPt;
2611 }
2612
2613 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2614 {
2615   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2616     (*it)->changePflsRefsNamesGen(mapOfModif);
2617 }
2618
2619 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2620 {
2621   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2622     (*it)->changeLocsRefsNamesGen(mapOfModif);
2623 }
2624
2625 /*!
2626  * \param [in] mesh is the whole mesh
2627  */
2628 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2629 {
2630   if(_field_pm_pt.empty())
2631     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2632   //
2633   std::vector< std::pair<int,int> > dads;
2634   std::vector<const DataArrayInt *> pfls;
2635   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2636   std::vector<int> locs,code;
2637   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2638   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2639     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2640   // Sort by types
2641   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2642   if(code.empty())
2643     {
2644       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2645       throw INTERP_KERNEL::Exception(oss.str());
2646     }
2647   //
2648   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2649   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2650   if(type!=ON_NODES)
2651     {
2652       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2653       if(!arr)
2654         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2655       else
2656         {
2657           MCAuto<DataArrayInt> arr2(arr);
2658           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2659         }
2660     }
2661   else
2662     {
2663       if(code.size()!=3)
2664         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2665       int nb=code[1];
2666       if(code[2]==-1)
2667         {
2668           if(nb!=mesh->getNumberOfNodes())
2669             {
2670               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2671               oss << " nodes in mesh !";
2672               throw INTERP_KERNEL::Exception(oss.str());
2673             }
2674           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2675         }
2676       else
2677         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2678     }
2679 }
2680
2681 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2682 {
2683   if(_field_pm_pt.empty())
2684     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2685   //
2686   std::vector<std::pair<int,int> > dads;
2687   std::vector<const DataArrayInt *> pfls;
2688   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2689   std::vector<int> locs,code;
2690   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2691   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2692     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2693   // Sort by types
2694   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2695   if(code.empty())
2696     {
2697       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2698       throw INTERP_KERNEL::Exception(oss.str());
2699     }
2700   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2701   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2702   if(type!=ON_NODES)
2703     {
2704       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2705       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2706     }
2707   else
2708     {
2709       if(code.size()!=3)
2710         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2711       int nb=code[1];
2712       if(code[2]==-1)
2713         {
2714           if(nb!=mesh->getNumberOfNodes())
2715             {
2716               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2717               oss << " nodes in mesh !";
2718               throw INTERP_KERNEL::Exception(oss.str());
2719             }
2720         }
2721       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2722     }
2723   //
2724   return 0;
2725 }
2726
2727 void MEDFileFieldPerMesh::accept(MEDFileFieldVisitor& visitor) const
2728 {
2729   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2730     if((*it).isNotNull())
2731       {
2732         visitor.newPerMeshPerTypeEntry(*it);
2733         (*it)->accept(visitor);
2734         visitor.endPerMeshPerTypeEntry(*it);
2735       }
2736 }
2737
2738 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2739 {
2740   int globalSz=0;
2741   int nbOfEntries=0;
2742   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2743     {
2744       (*it)->getSizes(globalSz,nbOfEntries);
2745     }
2746   entries.resize(nbOfEntries);
2747   nbOfEntries=0;
2748   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2749     {
2750       (*it)->fillValues(nbOfEntries,entries);
2751     }
2752 }
2753
2754 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2755 {
2756   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2757     {
2758       if((*it)->getGeoType()==typ)
2759         return (*it)->getLeafGivenLocId(locId);
2760     }
2761   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2762   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2763   oss << "Possiblities are : ";
2764   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2765     {
2766       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2767       oss << "\"" << cm2.getRepr() << "\", ";
2768     }
2769   throw INTERP_KERNEL::Exception(oss.str());
2770 }
2771
2772 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2773 {
2774   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2775     {
2776       if((*it)->getGeoType()==typ)
2777         return (*it)->getLeafGivenLocId(locId);
2778     }
2779   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2780   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2781   oss << "Possiblities are : ";
2782   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2783     {
2784       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2785       oss << "\"" << cm2.getRepr() << "\", ";
2786     }
2787   throw INTERP_KERNEL::Exception(oss.str());
2788 }
2789
2790 /*!
2791  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2792  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2793  * \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.
2794  * \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.
2795  */
2796 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)
2797 {
2798   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2799   if(pms.empty())
2800     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2801   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2802     {
2803       if(!(*it).second)
2804         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2805       if(!(*it).second->getProfile().empty())
2806         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2807       if(!(*it).second->getLocalization().empty())
2808         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2809     }
2810   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2811   std::size_t i(0);
2812   std::vector< std::pair<int,int> > filteredDTS;
2813   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2814     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2815       if((*it2).first==gt)
2816         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2817   if(pms.size()!=filteredDTS.size())
2818     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2819   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2820   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2821   int zeStart(start),nval(0);
2822   for(;it1!=pms.end();it1++,it2++)
2823     {
2824       if((*it1).first!=(*it2).first)
2825         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2826       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2827       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2828       start+=e1-s1;
2829       nval+=((*it1).second)->getNumberOfVals();
2830     }
2831   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2832   return ret;
2833 }
2834
2835 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)
2836 {
2837   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2838   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2839   std::size_t i(0);
2840   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2841     {
2842       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2843       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2844         {
2845           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2846           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2847           if(!elt)
2848             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2849           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2850         }
2851     }
2852   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2853     {
2854       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2855       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2856       ret->_field_pm_pt.push_back(agg2);
2857     }
2858   return ret;
2859 }
2860
2861 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2862 {
2863   int i=0;
2864   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2865   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2866   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2867     {
2868       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2869       if(type==curType)
2870         return i;
2871       else
2872         {
2873           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2874           if(pos>pos2)
2875             it2=it+1;
2876         }
2877     }
2878   int ret=std::distance(_field_pm_pt.begin(),it2);
2879   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2880   return ret;
2881 }
2882
2883 /*!
2884  * 'dads' and 'locs' input parameters have the same number of elements
2885  * \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
2886  */
2887 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2888                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2889                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2890 {
2891   isPfl=false;
2892   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2893   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2894   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2895   const std::vector<std::string>& infos=getInfo();
2896   da->setInfoOnComponents(infos);
2897   da->setName("");
2898   if(type==ON_GAUSS_PT)
2899     {
2900       int offset=0;
2901       int nbOfArrs=dads.size();
2902       for(int i=0;i<nbOfArrs;i++)
2903         {
2904           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2905           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2906           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2907           MCAuto<DataArrayInt> di=DataArrayInt::New();
2908           di->alloc(nbOfElems,1);
2909           di->iota(offset);
2910           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2911           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2912           offset+=nbOfElems;
2913         }
2914     }
2915   arrOut=da;
2916   return ret.retn();
2917 }
2918
2919 /*!
2920  * 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.
2921  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2922  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2923  * The order of cells in the returned field is those imposed by the profile.
2924  * \param [in] mesh is the global mesh.
2925  */
2926 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2927                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2928                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2929                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2930 {
2931   if(da->isIota(mesh->getNumberOfCells()))
2932     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2933   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2934   m2->setName(mesh->getName().c_str());
2935   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2936   isPfl=true;
2937   return ret.retn();
2938 }
2939
2940 /*!
2941  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2942  */
2943 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2944                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2945                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2946 {
2947   if(da->isIota(mesh->getNumberOfNodes()))
2948     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2949   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2950   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2951   if(meshu)
2952     {
2953       if(meshu->getNodalConnectivity()==0)
2954         {
2955           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2956           int nb=da->getNbOfElems();
2957           const int *ptr=da->getConstPointer();
2958           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2959           meshuc->allocateCells(nb);
2960           for(int i=0;i<nb;i++)
2961             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2962           meshuc->finishInsertingCells();
2963           ret->setMesh(meshuc);
2964           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2965           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2966           disc->checkCoherencyBetween(meshuc,arrOut);
2967           return ret.retn();
2968         }
2969     }
2970   //
2971   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2972   isPfl=true;
2973   DataArrayInt *arr2=0;
2974   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2975   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2976   MCAuto<DataArrayInt> arr3(arr2);
2977   int nnodes=mesh2->getNumberOfNodes();
2978   if(nnodes==(int)da->getNbOfElems())
2979     {
2980       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2981       arrOut->renumberInPlace(da3->getConstPointer());
2982       mesh2->setName(mesh->getName().c_str());
2983       ret->setMesh(mesh2);
2984       return ret.retn();
2985     }
2986   else
2987     {
2988       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 !!!";
2989       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2990       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2991       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2992       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2993       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2994       throw INTERP_KERNEL::Exception(oss.str());
2995     }
2996   return 0;
2997 }
2998
2999 /*!
3000  * This method is the most light method of field retrieving.
3001  */
3002 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
3003 {
3004   if(!pflIn)
3005     {
3006       pflOut=DataArrayInt::New();
3007       pflOut->alloc(nbOfElems,1);
3008       pflOut->iota(0);
3009     }
3010   else
3011     {
3012       pflOut=const_cast<DataArrayInt*>(pflIn);
3013       pflOut->incrRef();
3014     }
3015   MCAuto<DataArrayInt> safePfl(pflOut);
3016   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
3017   const std::vector<std::string>& infos=getInfo();
3018   int nbOfComp=infos.size();
3019   for(int i=0;i<nbOfComp;i++)
3020     da->setInfoOnComponent(i,infos[i].c_str());
3021   safePfl->incrRef();
3022   return da.retn();
3023 }
3024
3025
3026 /// @cond INTERNAL
3027
3028 class MFFPMIter
3029 {
3030 public:
3031   static MFFPMIter *NewCell(const MEDFileEntities *entities);
3032   static bool IsPresenceOfNode(const MEDFileEntities *entities);
3033   virtual ~MFFPMIter() { }
3034   virtual void begin() = 0;
3035   virtual bool finished() const = 0;
3036   virtual void next() = 0;
3037   virtual int current() const = 0;
3038 };
3039
3040 class MFFPMIterSimple : public MFFPMIter
3041 {
3042 public:
3043   MFFPMIterSimple():_pos(0) { }
3044   void begin() { _pos=0; }
3045   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
3046   void next() { _pos++; }
3047   int current() const { return _pos; }
3048 private:
3049   int _pos;
3050 };
3051
3052 class MFFPMIter2 : public MFFPMIter
3053 {
3054 public:
3055   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
3056   void begin() { _it=_ids.begin(); }
3057   bool finished() const { return _it==_ids.end(); }
3058   void next() { _it++; }
3059   int current() const { return *_it; }
3060 private:
3061   std::vector<int> _ids;
3062   std::vector<int>::const_iterator _it;
3063 };
3064
3065 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
3066 {
3067   if(!entities)
3068     return new MFFPMIterSimple;
3069   else
3070     {
3071       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3072       if(entities2)
3073         {
3074           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
3075           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3076           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3077             {
3078               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
3079                 tmp.push_back((*it).second);
3080             }
3081           return new MFFPMIter2(tmp);
3082         }
3083       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
3084     }
3085 }
3086
3087 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
3088 {
3089   if(!entities)
3090     return true;
3091   else
3092     {
3093       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3094       if(entities2)
3095         {
3096           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3097           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3098             if((*it).first==ON_NODES)
3099               return true;
3100           return false;
3101         }
3102       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
3103     }
3104 }
3105
3106 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
3107 {
3108   std::size_t sz(cts.size());
3109   _ids.resize(sz);
3110   for(std::size_t i=0;i<sz;i++)
3111     {
3112       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
3113       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
3114         _ids[i]=(int)std::distance(typmai2,loc);
3115       else
3116         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
3117     }
3118 }
3119
3120 /// @endcond
3121
3122 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),
3123     _father(fath)
3124 {
3125   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3126   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3127   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3128   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
3129   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
3130   for(iter0->begin();!iter0->finished();iter0->next())
3131     {
3132       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3133       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3134       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3135       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3136       if(nbProfile>0 || nbProfile2>0)
3137         {
3138           const PartDefinition *pd(0);
3139           if(mmu)
3140             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
3141           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
3142           if(nbProfile>0)
3143             setMeshName(name0);
3144           else
3145             setMeshName(name1);
3146         }
3147     }
3148   if(MFFPMIter::IsPresenceOfNode(entities))
3149     {
3150       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
3151       if(nbProfile>0)
3152         {
3153           const PartDefinition *pd(0);
3154           if(mmu)
3155             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
3156           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
3157           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3158         }
3159     }
3160   if(!entities)
3161     return ;
3162   std::vector<int> dynGT(entities->getDynGTAvail());
3163   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
3164     {
3165       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
3166       if(nbPfl>0)
3167         {
3168           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
3169           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3170         }
3171     }
3172   if(!_field_pm_pt.empty())
3173     return;
3174   //for vicious users using MED_ARETE MED_FACE in fields. the last try. For Others not overhead to pay.
3175   iter0=MFFPMIter::NewCell(entities);
3176   for(iter0->begin();!iter0->finished();iter0->next())
3177     {
3178       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_FACE,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3179       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3180       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_EDGE,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3181       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3182       if(nbProfile>0 || nbProfile2>0)
3183         {
3184           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,NULL));
3185           if(nbProfile>0)
3186             setMeshName(name0);
3187           else
3188             setMeshName(name1);
3189         }
3190     }
3191 }
3192
3193 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
3194 {
3195   copyTinyInfoFrom(mesh);
3196 }
3197
3198 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3199 {
3200   if(id>=(int)_pfls.size())
3201     _pfls.resize(id+1);
3202   _pfls[id]=DataArrayInt::New();
3203   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
3204   _pfls[id]->setName(pflName);
3205   _pfls[id]->alloc(lgth,1);
3206   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
3207   _pfls[id]->applyLin(1,-1,0);//Converting into C format
3208 }
3209
3210 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
3211 {
3212   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3213   int sz;
3214   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
3215   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
3216   if(i>=(int)_pfls.size())
3217     _pfls.resize(i+1);
3218   _pfls[i]=DataArrayInt::New();
3219   _pfls[i]->alloc(sz,1);
3220   _pfls[i]->setName(pflCpp.c_str());
3221   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
3222   _pfls[i]->applyLin(1,-1,0);//Converting into C format
3223 }
3224
3225 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3226 {
3227   int nbOfPfls=_pfls.size();
3228   for(int i=0;i<nbOfPfls;i++)
3229     {
3230       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
3231       cpy->applyLin(1,1,0);
3232       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3233       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
3234       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
3235     }
3236   //
3237   int nbOfLocs=_locs.size();
3238   for(int i=0;i<nbOfLocs;i++)
3239     _locs[i]->writeLL(fid);
3240 }
3241
3242 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
3243 {
3244   std::vector<std::string> pfls=getPfls();
3245   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
3246     {
3247       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
3248       if(it2==pfls.end())
3249         {
3250           _pfls.push_back(*it);
3251         }
3252       else
3253         {
3254           int id=std::distance(pfls.begin(),it2);
3255           if(!(*it)->isEqual(*_pfls[id]))
3256             {
3257               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3258               throw INTERP_KERNEL::Exception(oss.str());
3259             }
3260         }
3261     }
3262   std::vector<std::string> locs=getLocs();
3263   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
3264     {
3265       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
3266       if(it2==locs.end())
3267         {
3268           _locs.push_back(*it);
3269         }
3270       else
3271         {
3272           int id=std::distance(locs.begin(),it2);
3273           if(!(*it)->isEqual(*_locs[id],eps))
3274             {
3275               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3276               throw INTERP_KERNEL::Exception(oss.str());
3277             }
3278         }
3279     }
3280 }
3281
3282 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
3283 {
3284   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
3285     getProfile((*it).c_str());
3286 }
3287
3288 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
3289 {
3290   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
3291     getLocalization((*it).c_str());
3292 }
3293
3294 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
3295 {
3296   std::vector<std::string> profiles=real.getPflsReallyUsed();
3297   int sz=profiles.size();
3298   _pfls.resize(sz);
3299   for(int i=0;i<sz;i++)
3300     loadProfileInFile(fid,i,profiles[i].c_str());
3301   //
3302   std::vector<std::string> locs=real.getLocsReallyUsed();
3303   sz=locs.size();
3304   _locs.resize(sz);
3305   for(int i=0;i<sz;i++)
3306     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
3307 }
3308
3309 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3310 {
3311   int nProfil=MEDnProfile(fid);
3312   for(int i=0;i<nProfil;i++)
3313     loadProfileInFile(fid,i);
3314   int sz=MEDnLocalization(fid);
3315   _locs.resize(sz);
3316   for(int i=0;i<sz;i++)
3317     {
3318       _locs[i]=MEDFileFieldLoc::New(fid,i,entities);
3319     }
3320 }
3321
3322 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
3323 {
3324   return new MEDFileFieldGlobs(fid);
3325 }
3326
3327 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
3328 {
3329   return new MEDFileFieldGlobs;
3330 }
3331
3332 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
3333 {
3334   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
3335 }
3336
3337 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
3338 {
3339   std::vector<const BigMemoryObject *> ret;
3340   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3341     ret.push_back((const DataArrayInt *)*it);
3342   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3343     ret.push_back((const MEDFileFieldLoc *)*it);
3344   return ret;
3345 }
3346
3347 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3348 {
3349   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3350   std::size_t i=0;
3351   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3352     {
3353       if((const DataArrayInt *)*it)
3354         ret->_pfls[i]=(*it)->deepCopy();
3355     }
3356   i=0;
3357   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3358     {
3359       if((const MEDFileFieldLoc*)*it)
3360         ret->_locs[i]=(*it)->deepCopy();
3361     }
3362   return ret.retn();
3363 }
3364
3365 /*!
3366  * \throw if a profile in \a pfls in not in \a this.
3367  * \throw if a localization in \a locs in not in \a this.
3368  * \sa MEDFileFieldGlobs::deepCpyPart
3369  */
3370 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3371 {
3372   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3373   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3374     {
3375       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3376       if(!pfl)
3377         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3378       pfl->incrRef();
3379       MCAuto<DataArrayInt> pfl2(pfl);
3380       ret->_pfls.push_back(pfl2);
3381     }
3382   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3383     {
3384       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3385       if(!loc)
3386         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3387       loc->incrRef();
3388       MCAuto<MEDFileFieldLoc> loc2(loc);
3389       ret->_locs.push_back(loc2);
3390     }
3391   ret->setFileName(getFileName());
3392   return ret.retn();
3393 }
3394
3395 /*!
3396  * \throw if a profile in \a pfls in not in \a this.
3397  * \throw if a localization in \a locs in not in \a this.
3398  * \sa MEDFileFieldGlobs::shallowCpyPart
3399  */
3400 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3401 {
3402   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3403   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3404     {
3405       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3406       if(!pfl)
3407         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3408       ret->_pfls.push_back(pfl->deepCopy());
3409     }
3410   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3411     {
3412       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3413       if(!loc)
3414         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3415       ret->_locs.push_back(loc->deepCopy());
3416     }
3417   ret->setFileName(getFileName());
3418   return ret.retn();
3419 }
3420
3421 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3422 {
3423 }
3424
3425 MEDFileFieldGlobs::MEDFileFieldGlobs()
3426 {
3427 }
3428
3429 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3430 {
3431 }
3432
3433 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3434 {
3435   oss << "Profiles :\n";
3436   std::size_t n=_pfls.size();
3437   for(std::size_t i=0;i<n;i++)
3438     {
3439       oss << "  - #" << i << " ";
3440       const DataArrayInt *pfl=_pfls[i];
3441       if(pfl)
3442         oss << "\"" << pfl->getName() << "\"\n";
3443       else
3444         oss << "EMPTY !\n";
3445     }
3446   n=_locs.size();
3447   oss << "Localizations :\n";
3448   for(std::size_t i=0;i<n;i++)
3449     {
3450       oss << "  - #" << i << " ";
3451       const MEDFileFieldLoc *loc=_locs[i];
3452       if(loc)
3453         loc->simpleRepr(oss);
3454       else
3455         oss<< "EMPTY !\n";
3456     }
3457 }
3458
3459 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3460 {
3461   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3462     {
3463       DataArrayInt *elt(*it);
3464       if(elt)
3465         {
3466           std::string name(elt->getName());
3467           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3468             {
3469               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3470                 {
3471                   elt->setName((*it2).second.c_str());
3472                   return;
3473                 }
3474             }
3475         }
3476     }
3477 }
3478
3479 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3480 {
3481   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3482     {
3483       MEDFileFieldLoc *elt(*it);
3484       if(elt)
3485         {
3486           std::string name(elt->getName());
3487           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3488             {
3489               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3490                 {
3491                   elt->setName((*it2).second.c_str());
3492                   return;
3493                 }
3494             }
3495         }
3496     }
3497 }
3498
3499 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3500 {
3501   if(locId<0 || locId>=(int)_locs.size())
3502     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3503   return _locs[locId]->getNbOfGaussPtPerCell();
3504 }
3505
3506 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3507 {
3508   return getLocalizationFromId(getLocalizationId(locName));
3509 }
3510
3511 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3512 {
3513   if(locId<0 || locId>=(int)_locs.size())
3514     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3515   return *_locs[locId];
3516 }
3517
3518 /// @cond INTERNAL
3519 namespace MEDCouplingImpl
3520 {
3521   class LocFinder
3522   {
3523   public:
3524     LocFinder(const std::string& loc):_loc(loc) { }
3525     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3526   private:
3527     const std::string &_loc;
3528   };
3529
3530   class PflFinder
3531   {
3532   public:
3533     PflFinder(const std::string& pfl):_pfl(pfl) { }
3534     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3535   private:
3536     const std::string& _pfl;
3537   };
3538 }
3539 /// @endcond
3540
3541 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3542 {
3543   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3544   if(it==_locs.end())
3545     {
3546       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3547       for(it=_locs.begin();it!=_locs.end();it++)
3548         oss << "\"" << (*it)->getName() << "\", ";
3549       throw INTERP_KERNEL::Exception(oss.str());
3550     }
3551   return std::distance(_locs.begin(),it);
3552 }
3553
3554 /*!
3555  * The returned value is never null.
3556  */
3557 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3558 {
3559   std::string pflNameCpp(pflName);
3560   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3561   if(it==_pfls.end())
3562     {
3563       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3564       for(it=_pfls.begin();it!=_pfls.end();it++)
3565         oss << "\"" << (*it)->getName() << "\", ";
3566       throw INTERP_KERNEL::Exception(oss.str());
3567     }
3568   return *it;
3569 }
3570
3571 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3572 {
3573   if(pflId<0 || pflId>=(int)_pfls.size())
3574     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3575   return _pfls[pflId];
3576 }
3577
3578 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3579 {
3580   if(locId<0 || locId>=(int)_locs.size())
3581     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3582   return *_locs[locId];
3583 }
3584
3585 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3586 {
3587   return getLocalizationFromId(getLocalizationId(locName));
3588 }
3589
3590 /*!
3591  * The returned value is never null.
3592  */
3593 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3594 {
3595   std::string pflNameCpp(pflName);
3596   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3597   if(it==_pfls.end())
3598     {
3599       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3600       for(it=_pfls.begin();it!=_pfls.end();it++)
3601         oss << "\"" << (*it)->getName() << "\", ";
3602       throw INTERP_KERNEL::Exception(oss.str());
3603     }
3604   return *it;
3605 }
3606
3607 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3608 {
3609   if(pflId<0 || pflId>=(int)_pfls.size())
3610     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3611   return _pfls[pflId];
3612 }
3613
3614 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3615 {
3616   std::vector< MCAuto<DataArrayInt> > newPfls;
3617   int i=0;
3618   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3619     {
3620       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3621         newPfls.push_back(*it);
3622     }
3623   _pfls=newPfls;
3624 }
3625
3626 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3627 {
3628   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3629   int i=0;
3630   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3631     {
3632       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3633         newLocs.push_back(*it);
3634     }
3635   _locs=newLocs;
3636 }
3637
3638 void MEDFileFieldGlobs::killStructureElementsInGlobs()
3639 {
3640   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3641   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3642     {
3643       if((*it).isNull())
3644         continue;
3645       if(!(*it)->isOnStructureElement())
3646         newLocs.push_back(*it);
3647     }
3648   _locs=newLocs;
3649 }
3650
3651 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3652 {
3653   int sz=_pfls.size();
3654   std::vector<std::string> ret(sz);
3655   for(int i=0;i<sz;i++)
3656     ret[i]=_pfls[i]->getName();
3657   return ret;
3658 }
3659
3660 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3661 {
3662   int sz=_locs.size();
3663   std::vector<std::string> ret(sz);
3664   for(int i=0;i<sz;i++)
3665     ret[i]=_locs[i]->getName();
3666   return ret;
3667 }
3668
3669 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3670 {
3671   std::vector<std::string> v=getPfls();
3672   std::string s(pflName);
3673   return std::find(v.begin(),v.end(),s)!=v.end();
3674 }
3675
3676 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3677 {
3678   std::vector<std::string> v=getLocs();
3679   std::string s(locName);
3680   return std::find(v.begin(),v.end(),s)!=v.end();
3681 }
3682
3683 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3684 {
3685   std::map<int,std::vector<int> > m;
3686   int i=0;
3687   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3688     {
3689       const DataArrayInt *tmp=(*it);
3690       if(tmp)
3691         {
3692           m[tmp->getHashCode()].push_back(i);
3693         }
3694     }
3695   std::vector< std::vector<int> > ret;
3696   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3697     {
3698       if((*it2).second.size()>1)
3699         {
3700           std::vector<int> ret0;
3701           bool equalityOrNot=false;
3702           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3703             {
3704               std::vector<int>::const_iterator it4=it3; it4++;
3705               for(;it4!=(*it2).second.end();it4++)
3706                 {
3707                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3708                     {
3709                       if(!equalityOrNot)
3710                         ret0.push_back(*it3);
3711                       ret0.push_back(*it4);
3712                       equalityOrNot=true;
3713                     }
3714                 }
3715             }
3716           if(!ret0.empty())
3717             ret.push_back(ret0);
3718         }
3719     }
3720   return ret;
3721 }
3722
3723 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3724 {
3725   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3726 }
3727
3728 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3729 {
3730   std::string name(pfl->getName());
3731   if(name.empty())
3732     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3733   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3734     if(name==(*it)->getName())
3735       {
3736         if(!pfl->isEqual(*(*it)))
3737           {
3738             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3739             throw INTERP_KERNEL::Exception(oss.str());
3740           }
3741       }
3742   pfl->incrRef();
3743   _pfls.push_back(pfl);
3744 }
3745
3746 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)
3747 {
3748   std::string name(locName);
3749   if(name.empty())
3750     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3751   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3752   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3753     if((*it)->isName(locName))
3754       {
3755         if(!(*it)->isEqual(*obj,1e-12))
3756           {
3757             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3758             throw INTERP_KERNEL::Exception(oss.str());
3759           }
3760       }
3761   _locs.push_back(obj);
3762 }
3763
3764 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3765 {
3766   std::vector<std::string> names=getPfls();
3767   return CreateNewNameNotIn("NewPfl_",names);
3768 }
3769
3770 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3771 {
3772   std::vector<std::string> names=getLocs();
3773   return CreateNewNameNotIn("NewLoc_",names);
3774 }
3775
3776 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3777 {
3778   for(std::size_t sz=0;sz<100000;sz++)
3779     {
3780       std::ostringstream tryName;
3781       tryName << prefix << sz;
3782       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3783         return tryName.str();
3784     }
3785   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3786 }
3787
3788 /*!
3789  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3790  *  \param [in] fname - the file name.
3791  */
3792 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3793 {
3794 }
3795
3796 /*!
3797  * Creates an empty MEDFileFieldGlobsReal.
3798  */
3799 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3800 {
3801 }
3802
3803 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3804 {
3805   return 0;
3806 }
3807
3808 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3809 {
3810   std::vector<const BigMemoryObject *> ret;
3811   ret.push_back((const MEDFileFieldGlobs *)_globals);
3812   return ret;
3813 }
3814
3815 /*!
3816  * Returns a string describing profiles and Gauss points held in \a this.
3817  *  \return std::string - the description string.
3818  */
3819 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3820 {
3821   const MEDFileFieldGlobs *glob=_globals;
3822   std::ostringstream oss2; oss2 << glob;
3823   std::string stars(oss2.str().length(),'*');
3824   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3825   if(glob)
3826     glob->simpleRepr(oss);
3827   else
3828     oss << "NO GLOBAL INFORMATION !\n";
3829 }
3830
3831 void MEDFileFieldGlobsReal::resetContent()
3832 {
3833   _globals=MEDFileFieldGlobs::New();
3834 }
3835
3836 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
3837 {
3838   contentNotNull()->killStructureElementsInGlobs();
3839 }
3840
3841 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3842 {
3843 }
3844
3845 /*!
3846  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3847  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3848  */
3849 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3850 {
3851   _globals=other._globals;
3852 }
3853
3854 /*!
3855  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3856  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3857  */
3858 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3859 {
3860   const MEDFileFieldGlobs *otherg(other._globals);
3861   if(!otherg)
3862     return ;
3863   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3864 }
3865
3866 /*!
3867  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3868  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3869  */
3870 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3871 {
3872   const MEDFileFieldGlobs *otherg(other._globals);
3873   if(!otherg)
3874     return ;
3875   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3876 }
3877
3878 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3879 {
3880   _globals=other._globals;
3881   if((const MEDFileFieldGlobs *)_globals)
3882     _globals=other._globals->deepCopy();
3883 }
3884
3885 /*!
3886  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3887  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3888  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3889  *         \a this and \a other MEDFileFieldGlobsReal.
3890  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3891  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3892  */
3893 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3894 {
3895   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3896   if(thisGlobals==otherGlobals)
3897     return ;
3898   if(!thisGlobals)
3899     {
3900       _globals=other._globals;
3901       return ;
3902     }
3903   _globals->appendGlobs(*other._globals,eps);
3904 }
3905
3906 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3907 {
3908   checkGlobsPflsPartCoherency();
3909   checkGlobsLocsPartCoherency();
3910 }
3911
3912 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3913 {
3914   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3915 }
3916
3917 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3918 {
3919   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3920 }
3921
3922 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3923 {
3924   contentNotNull()->loadProfileInFile(fid,id,pflName);
3925 }
3926
3927 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3928 {
3929   contentNotNull()->loadProfileInFile(fid,id);
3930 }
3931
3932 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3933 {
3934   contentNotNull()->loadGlobals(fid,*this);
3935 }
3936
3937 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3938 {
3939   contentNotNull()->loadAllGlobals(fid,entities);
3940 }
3941
3942 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3943 {
3944   contentNotNull()->writeGlobals(fid,opt);
3945 }
3946
3947 /*!
3948  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3949  * or getPflsReallyUsedMulti().
3950  *  \return std::vector<std::string> - a sequence of names of all profiles.
3951  */
3952 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3953 {
3954   return contentNotNull()->getPfls();
3955 }
3956
3957 /*!
3958  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3959  * or getLocsReallyUsedMulti().
3960  *  \return std::vector<std::string> - a sequence of names of all localizations.
3961  */
3962 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3963 {
3964   return contentNotNull()->getLocs();
3965 }
3966
3967 /*!
3968  * Checks if the profile with a given name exists.
3969  *  \param [in] pflName - the profile name of interest.
3970  *  \return bool - \c true if the profile named \a pflName exists.
3971  */
3972 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3973 {
3974   return contentNotNull()->existsPfl(pflName);
3975 }
3976
3977 /*!
3978  * Checks if the localization with a given name exists.
3979  *  \param [in] locName - the localization name of interest.
3980  *  \return bool - \c true if the localization named \a locName exists.
3981  */
3982 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3983 {
3984   return contentNotNull()->existsLoc(locName);
3985 }
3986
3987 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3988 {
3989   return contentNotNull()->createNewNameOfPfl();
3990 }
3991
3992 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3993 {
3994   return contentNotNull()->createNewNameOfLoc();
3995 }
3996
3997 /*!
3998  * Sets the name of a MED file.
3999  *  \param [inout] fileName - the file name.
4000  */
4001 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
4002 {
4003   contentNotNull()->setFileName(fileName);
4004 }
4005
4006 /*!
4007  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
4008  * in the same order.
4009  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
4010  *          Each item of this sequence is a vector containing ids of equal profiles.
4011  */
4012 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
4013 {
4014   return contentNotNull()->whichAreEqualProfiles();
4015 }
4016
4017 /*!
4018  * Finds equal localizations.
4019  *  \param [in] eps - a precision used to compare real values of the localizations.
4020  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
4021  *          Each item of this sequence is a vector containing ids of equal localizations.
4022  */
4023 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
4024 {
4025   return contentNotNull()->whichAreEqualLocs(eps);
4026 }
4027
4028 /*!
4029  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
4030  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
4031  *        this sequence is a pair whose 
4032  *        - the first item is a vector of profile names to replace by the second item,
4033  *        - the second item is a profile name to replace every profile name of the first item.
4034  */
4035 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4036 {
4037   contentNotNull()->changePflsNamesInStruct(mapOfModif);
4038 }
4039
4040 /*!
4041  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
4042  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
4043  *        this sequence is a pair whose 
4044  *        - the first item is a vector of localization names to replace by the second item,
4045  *        - the second item is a localization name to replace every localization name of the first item.
4046  */
4047 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4048 {
4049   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
4050 }
4051
4052 /*!
4053  * Replaces references to some profiles (a reference is a profile name) by references
4054  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
4055  * them-selves accordingly. <br>
4056  * This method is a generalization of changePflName().
4057  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
4058  *        this sequence is a pair whose 
4059  *        - the first item is a vector of profile names to replace by the second item,
4060  *        - the second item is a profile name to replace every profile of the first item.
4061  * \sa changePflsRefsNamesGen()
4062  * \sa changePflName()
4063  */
4064 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4065 {
4066   changePflsRefsNamesGen(mapOfModif);
4067   changePflsNamesInStruct(mapOfModif);
4068 }
4069
4070 /*!
4071  * Replaces references to some localizations (a reference is a localization name) by references
4072  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
4073  * them-selves accordingly. <br>
4074  * This method is a generalization of changeLocName().
4075  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
4076  *        this sequence is a pair whose 
4077  *        - the first item is a vector of localization names to replace by the second item,
4078  *        - the second item is a localization name to replace every localization of the first item.
4079  * \sa changeLocsRefsNamesGen()
4080  * \sa changeLocName()
4081  */
4082 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4083 {
4084   changeLocsRefsNamesGen(mapOfModif);
4085   changeLocsNamesInStruct(mapOfModif);
4086 }
4087
4088 /*!
4089  * Renames the profile having a given name and updates references to this profile.
4090  *  \param [in] oldName - the name of the profile to rename.
4091  *  \param [in] newName - a new name of the profile.
4092  * \sa changePflsNames().
4093  */
4094 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
4095 {
4096   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4097   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4098   mapOfModif[0]=p;
4099   changePflsNames(mapOfModif);
4100 }
4101
4102 /*!
4103  * Renames the localization having a given name and updates references to this localization.
4104  *  \param [in] oldName - the name of the localization to rename.
4105  *  \param [in] newName - a new name of the localization.
4106  * \sa changeLocsNames().
4107  */
4108 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
4109 {
4110   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4111   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4112   mapOfModif[0]=p;
4113   changeLocsNames(mapOfModif);
4114 }
4115
4116 /*!
4117  * Removes duplicated profiles. Returns a map used to update references to removed 
4118  * profiles via changePflsRefsNamesGen().
4119  * Equal profiles are found using whichAreEqualProfiles().
4120  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4121  *          a sequence describing the performed replacements of profiles. Each element of
4122  *          this sequence is a pair whose
4123  *          - the first item is a vector of profile names replaced by the second item,
4124  *          - the second item is a profile name replacing every profile of the first item.
4125  */
4126 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
4127 {
4128   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
4129   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4130   int i=0;
4131   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4132     {
4133       std::vector< std::string > tmp((*it).size());
4134       int j=0;
4135       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4136         tmp[j]=std::string(getProfileFromId(*it2)->getName());
4137       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4138       ret[i]=p;
4139       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4140       killProfileIds(tmp2);
4141     }
4142   changePflsRefsNamesGen(ret);
4143   return ret;
4144 }
4145
4146 /*!
4147  * Removes duplicated localizations. Returns a map used to update references to removed 
4148  * localizations via changeLocsRefsNamesGen().
4149  * Equal localizations are found using whichAreEqualLocs().
4150  *  \param [in] eps - a precision used to compare real values of the localizations.
4151  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4152  *          a sequence describing the performed replacements of localizations. Each element of
4153  *          this sequence is a pair whose
4154  *          - the first item is a vector of localization names replaced by the second item,
4155  *          - the second item is a localization name replacing every localization of the first item.
4156  */
4157 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
4158 {
4159   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
4160   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4161   int i=0;
4162   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4163     {
4164       std::vector< std::string > tmp((*it).size());
4165       int j=0;
4166       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4167         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
4168       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4169       ret[i]=p;
4170       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4171       killLocalizationIds(tmp2);
4172     }
4173   changeLocsRefsNamesGen(ret);
4174   return ret;
4175 }
4176
4177 /*!
4178  * Returns number of Gauss points per cell in a given localization.
4179  *  \param [in] locId - an id of the localization of interest.
4180  *  \return int - the number of the Gauss points per cell.
4181  */
4182 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
4183 {
4184   return contentNotNull()->getNbOfGaussPtPerCell(locId);
4185 }
4186
4187 /*!
4188  * Returns an id of a localization by its name.
4189  *  \param [in] loc - the localization name of interest.
4190  *  \return int - the id of the localization.
4191  *  \throw If there is no a localization named \a loc.
4192  */
4193 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
4194 {
4195   return contentNotNull()->getLocalizationId(loc);
4196 }
4197
4198 /*!
4199  * Returns the name of the MED file.
4200  *  \return const std::string&  - the MED file name.
4201  */
4202 std::string MEDFileFieldGlobsReal::getFileName() const
4203 {
4204   return contentNotNull()->getFileName();
4205 }
4206
4207 /*!
4208  * Returns a localization object by its name.
4209  *  \param [in] locName - the name of the localization of interest.
4210  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
4211  *  \throw If there is no a localization named \a locName.
4212  */
4213 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
4214 {
4215   return contentNotNull()->getLocalization(locName);
4216 }
4217
4218 /*!
4219  * Returns a localization object by its id.
4220  *  \param [in] locId - the id of the localization of interest.
4221  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
4222  *  \throw If there is no a localization with id \a locId.
4223  */
4224 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
4225 {
4226   return contentNotNull()->getLocalizationFromId(locId);
4227 }
4228
4229 /*!
4230  * Returns a profile array by its name.
4231  *  \param [in] pflName - the name of the profile of interest.
4232  *  \return const DataArrayInt * - the profile array having the name \a pflName.
4233  *  \throw If there is no a profile named \a pflName.
4234  */
4235 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
4236 {
4237   return contentNotNull()->getProfile(pflName);
4238 }
4239
4240 /*!
4241  * Returns a profile array by its id.
4242  *  \param [in] pflId - the id of the profile of interest.
4243  *  \return const DataArrayInt * - the profile array having the id \a pflId.
4244  *  \throw If there is no a profile with id \a pflId.
4245  */
4246 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
4247 {
4248   return contentNotNull()->getProfileFromId(pflId);
4249 }
4250
4251 /*!
4252  * Returns a localization object, apt for modification, by its id.
4253  *  \param [in] locId - the id of the localization of interest.
4254  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4255  *          having the id \a locId.
4256  *  \throw If there is no a localization with id \a locId.
4257  */
4258 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
4259 {
4260   return contentNotNull()->getLocalizationFromId(locId);
4261 }
4262
4263 /*!
4264  * Returns a localization object, apt for modification, by its name.
4265  *  \param [in] locName - the name of the localization of interest.
4266  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4267  *          having the name \a locName.
4268  *  \throw If there is no a localization named \a locName.
4269  */
4270 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
4271 {
4272   return contentNotNull()->getLocalization(locName);
4273 }
4274
4275 /*!
4276  * Returns a profile array, apt for modification, by its name.
4277  *  \param [in] pflName - the name of the profile of interest.
4278  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
4279  *  \throw If there is no a profile named \a pflName.
4280  */
4281 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
4282 {
4283   return contentNotNull()->getProfile(pflName);
4284 }
4285
4286 /*!
4287  * Returns a profile array, apt for modification, by its id.
4288  *  \param [in] pflId - the id of the profile of interest.
4289  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
4290  *  \throw If there is no a profile with id \a pflId.
4291  */
4292 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
4293 {
4294   return contentNotNull()->getProfileFromId(pflId);
4295 }
4296
4297 /*!
4298  * Removes profiles given by their ids. No data is updated to track this removal.
4299  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
4300  */
4301 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
4302 {
4303   contentNotNull()->killProfileIds(pflIds);
4304 }
4305
4306 /*!
4307  * Removes localizations given by their ids. No data is updated to track this removal.
4308  *  \param [in] locIds - a sequence of ids of the localizations to remove.
4309  */
4310 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
4311 {
4312   contentNotNull()->killLocalizationIds(locIds);
4313 }
4314
4315 /*!
4316  * Stores a profile array.
4317  *  \param [in] pfl - the profile array to store.
4318  *  \throw If the name of \a pfl is empty.
4319  *  \throw If a profile with the same name as that of \a pfl already exists but contains
4320  *         different ids.
4321  */
4322 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
4323 {
4324   contentNotNull()->appendProfile(pfl);
4325 }
4326
4327 /*!
4328  * Adds a new localization of Gauss points.
4329  *  \param [in] locName - the name of the new localization.
4330  *  \param [in] geoType - a geometrical type of the reference cell.
4331  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
4332  *         must be \c nbOfNodesPerCell * \c dimOfType.
4333  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
4334  *         must be  _wg_.size() * \c dimOfType.
4335  *  \param [in] w - the weights of Gauss points.
4336  *  \throw If \a locName is empty.
4337  *  \throw If a localization with the name \a locName already exists but is
4338  *         different form the new one.
4339  */
4340 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)
4341 {
4342   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
4343 }
4344
4345 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
4346 {
4347   MEDFileFieldGlobs *g(_globals);
4348   if(!g)
4349     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
4350   return g;
4351 }
4352
4353 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
4354 {
4355   const MEDFileFieldGlobs *g(_globals);
4356   if(!g)
4357     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4358   return g;
4359 }
4360
4361 //= MEDFileFieldNameScope
4362
4363 MEDFileFieldNameScope::MEDFileFieldNameScope()
4364 {
4365 }
4366
4367 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName):_name(fieldName),_mesh_name(meshName)
4368 {
4369 }
4370
4371 /*!
4372  * Returns the name of \a this field.
4373  *  \return std::string - a string containing the field name.
4374  */
4375 std::string MEDFileFieldNameScope::getName() const
4376 {
4377   return _name;
4378 }
4379
4380 /*!
4381  * Sets name of \a this field
4382  *  \param [in] name - the new field name.
4383  */
4384 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4385 {
4386   _name=fieldName;
4387 }
4388
4389 std::string MEDFileFieldNameScope::getDtUnit() const
4390 {
4391   return _dt_unit;
4392 }
4393
4394 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4395 {
4396   _dt_unit=dtUnit;
4397 }
4398
4399 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4400 {
4401   _name=other._name;
4402   _mesh_name=other._mesh_name;
4403   _dt_unit=other._dt_unit;
4404 }
4405
4406 /*!
4407  * Returns the mesh name.
4408  *  \return std::string - a string holding the mesh name.
4409  *  \throw If \c _field_per_mesh.empty()
4410  */
4411 std::string MEDFileFieldNameScope::getMeshName() const
4412 {
4413   return _mesh_name;
4414 }
4415
4416 void MEDFileFieldNameScope::setMeshName(const std::string& meshName)
4417 {
4418   _mesh_name=meshName;
4419 }
4420
4421 //= MEDFileAnyTypeField1TSWithoutSDA
4422
4423 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4424 {
4425   _field_per_mesh.resize(other._field_per_mesh.size());
4426   std::size_t i=0;
4427   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4428     {
4429       if((const MEDFileFieldPerMesh *)*it)
4430         _field_per_mesh[i]=(*it)->deepCopy(this);
4431     }
4432 }
4433
4434 void MEDFileAnyTypeField1TSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
4435 {
4436   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4437     if((*it).isNotNull())
4438       {
4439         visitor.newMeshEntry(*it);
4440         (*it)->accept(visitor);
4441         visitor.endMeshEntry(*it);
4442       }
4443 }
4444
4445 /*!
4446  * Prints a string describing \a this field into a stream. This string is outputted 
4447  * by \c print Python command.
4448  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4449  *  \param [in,out] oss - the out stream.
4450  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4451  *          info id printed, else, not.
4452  */
4453 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4454 {
4455   std::string startOfLine(bkOffset,' ');
4456   oss << startOfLine << "Field ";
4457   if(bkOffset==0)
4458     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4459   oss << "on one time Step ";
4460   if(f1tsId>=0)
4461     oss << "(" << f1tsId << ") ";
4462   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4463   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4464   const DataArray *arr=getUndergroundDataArray();
4465   if(arr)
4466     {
4467       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4468       if(f1tsId<0)
4469         {
4470           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4471           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4472             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4473         }
4474       if(arr->isAllocated())
4475         {
4476           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4477         }
4478       else
4479         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4480     }
4481   else
4482     {
4483       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4484     }
4485   oss << startOfLine << "----------------------" << std::endl;
4486   if(!_field_per_mesh.empty())
4487     {
4488       int i=0;
4489       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4490         {
4491           const MEDFileFieldPerMesh *cur=(*it2);
4492           if(cur)
4493             cur->simpleRepr(bkOffset,oss,i);
4494           else
4495             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4496         }
4497     }
4498   else
4499     {
4500       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4501     }
4502   oss << startOfLine << "----------------------" << std::endl;
4503 }
4504
4505 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4506 {
4507   const DataArray *arr(getUndergroundDataArray());
4508   if(!arr)
4509     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4510   int nbOfCompo=arr->getNumberOfComponents();
4511   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4512   for(int i=0;i<nbOfCompo;i++)
4513     {
4514       ret[i]=deepCopy();
4515       std::vector<int> v(1,i);
4516       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4517       ret[i]->setArray(arr2);
4518     }
4519   return ret;
4520 }
4521
4522 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName,meshName),_iteration(iteration),_order(order),_csit(csit),_nb_of_tuples_to_be_allocated(-2)
4523 {
4524 }
4525
4526 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4527 {
4528 }
4529
4530 /*!
4531  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4532  * empty. Returns -1 if this in on nodes.
4533  *  \return int - the dimension of \a this.
4534  */
4535 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4536 {
4537   int ret=-2;
4538   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4539     (*it)->getDimension(ret);
4540   return ret;
4541 }
4542
4543 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4544 {
4545   bool ret=false;
4546   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4547     {
4548       MEDFileFieldPerMesh *cur(*it);
4549       if(cur)
4550         ret=cur->changeMeshNames(modifTab) || ret;
4551     }
4552   return ret;
4553 }
4554
4555 /*!
4556  * Returns the number of iteration of the state of underlying mesh.
4557  *  \return int - the iteration number.
4558  *  \throw If \c _field_per_mesh.empty()
4559  */
4560 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4561 {
4562   if(_field_per_mesh.empty())
4563     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4564   return _field_per_mesh[0]->getMeshIteration();
4565 }
4566
4567 /*!
4568  * Returns the order number of iteration of the state of underlying mesh.
4569  *  \return int - the order number.
4570  *  \throw If \c _field_per_mesh.empty()
4571  */
4572 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4573 {
4574   if(_field_per_mesh.empty())
4575     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4576   return _field_per_mesh[0]->getMeshOrder();
4577 }
4578
4579 /*!
4580  * Checks if \a this field is tagged by a given iteration number and a given
4581  * iteration order number.
4582  *  \param [in] iteration - the iteration number of interest.
4583  *  \param [in] order - the iteration order number of interest.
4584  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4585  *          \a this->getOrder() == \a order.
4586  */
4587 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4588 {
4589   return iteration==_iteration && order==_order;
4590 }
4591
4592 /*!
4593  * Returns number of iteration and order number of iteration when
4594  * \a this field has been calculated.
4595  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4596  *          order number.
4597  */
4598 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4599 {
4600   std::pair<int,int> p;
4601   fillIteration(p);
4602   return p;
4603 }
4604
4605 /*!
4606  * Returns number of iteration and order number of iteration when
4607  * \a this field has been calculated.
4608  *  \param [in,out] p - a pair returning the iteration number and the iteration
4609  *          order number.
4610  */
4611 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4612 {
4613   p.first=_iteration;
4614   p.second=_order;
4615 }
4616
4617 /*!
4618  * Returns all types of spatial discretization of \a this field.
4619  *  \param [in,out] types - a sequence of types of \a this field.
4620  */
4621 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4622 {
4623   std::set<TypeOfField> types2;
4624   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4625     {
4626       (*it)->fillTypesOfFieldAvailable(types2);
4627     }
4628   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4629   std::copy(types2.begin(),types2.end(),bi);
4630 }
4631
4632 /*!
4633  * Returns all types of spatial discretization of \a this field.
4634  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4635  *          of \a this field.
4636  */
4637 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4638 {
4639   std::vector<TypeOfField> ret;
4640   fillTypesOfFieldAvailable(ret);
4641   return ret;
4642 }
4643
4644 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4645 {
4646   std::vector<std::string> ret;
4647   std::set<std::string> ret2;
4648   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4649     {
4650       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4651       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4652         if(ret2.find(*it2)==ret2.end())
4653           {
4654             ret.push_back(*it2);
4655             ret2.insert(*it2);
4656           }
4657     }
4658   return ret;
4659 }
4660
4661 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4662 {
4663   std::vector<std::string> ret;
4664   std::set<std::string> ret2;
4665   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4666     {
4667       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4668       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4669         if(ret2.find(*it2)==ret2.end())
4670           {
4671             ret.push_back(*it2);
4672             ret2.insert(*it2);
4673           }
4674     }
4675   return ret;
4676 }
4677
4678 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4679 {
4680   std::vector<std::string> ret;
4681   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4682     {
4683       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4684       ret.insert(ret.end(),tmp.begin(),tmp.end());
4685     }
4686   return ret;
4687 }
4688
4689 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4690 {
4691   std::vector<std::string> ret;
4692   std::set<std::string> ret2;
4693   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4694     {
4695       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4696       ret.insert(ret.end(),tmp.begin(),tmp.end());
4697     }
4698   return ret;
4699 }
4700
4701 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4702 {
4703   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4704     (*it)->changePflsRefsNamesGen(mapOfModif);
4705 }
4706
4707 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4708 {
4709   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4710     (*it)->changeLocsRefsNamesGen(mapOfModif);
4711 }
4712
4713 /*!
4714  * Returns all attributes of parts of \a this field lying on a given mesh.
4715  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4716  * item of every of returned sequences refers to the _i_-th part of \a this field.
4717  * Thus all sequences returned by this method are of the same length equal to number
4718  * of different types of supporting entities.<br>
4719  * A field part can include sub-parts with several different spatial discretizations,
4720  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4721  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4722  * of a nested sequence corresponds to a type of spatial discretization.<br>
4723  * This method allows for iteration over MEDFile DataStructure without any overhead.
4724  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4725  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4726  *          not checked if \a mname == \c NULL).
4727  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4728  *          a field part is returned. 
4729  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4730  *          This sequence is of the same length as \a types. 
4731  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4732  *          discretization. A profile name can be empty.
4733  *          Length of this and of nested sequences is the same as that of \a typesF.
4734  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4735  *          discretization. A localization name can be empty.
4736  *          Length of this and of nested sequences is the same as that of \a typesF.
4737  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4738  *          of ids of tuples within the data array, per each type of spatial
4739  *          discretization within one mesh entity type. 
4740  *          Length of this and of nested sequences is the same as that of \a typesF.
4741  *  \throw If no field is lying on \a mname.
4742  */
4743 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
4744 {
4745   if(_field_per_mesh.empty())
4746     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4747   return _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4748 }
4749
4750 /*!
4751  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4752  * maximal absolute dimension and values returned via the out parameter \a levs are 
4753  * dimensions relative to the maximal absolute dimension. <br>
4754  * This method is designed for MEDFileField1TS instances that have a discretization
4755  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4756  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4757  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4758  * Only these 3 discretizations will be taken into account here. If \a this is
4759  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4760  * This method is useful to make the link between the dimension of the underlying mesh
4761  * and the levels of \a this, because it is possible that the highest dimension of \a this
4762  * field is not equal to the dimension of the underlying mesh.
4763  * 
4764  * Let's consider the following case:
4765  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4766  * TETRA4, HEXA8, TRI3 and SEG2.
4767  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4768  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4769  *
4770  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4771  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4772  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4773  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4774  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4775  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4776  * For example<br>
4777  * to retrieve the highest level of
4778  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4779  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4780  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4781  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4782  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4783  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4784  *          not checked if \a mname == \c NULL).
4785  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4786  *          absolute one. They are in decreasing order. This sequence is cleared before
4787  *          filling it in.
4788  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4789  *  \throw If no field is lying on \a mname.
4790  */
4791 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4792 {
4793   levs.clear();
4794   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4795   std::vector< std::vector<TypeOfField> > typesF;
4796   std::vector< std::vector<std::string> > pfls, locs;
4797   if(_field_per_mesh.empty())
4798     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels : This is empty !");
4799   _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4800   if(types.empty())
4801     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4802   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4803   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4804     return -1;
4805   st.erase(INTERP_KERNEL::NORM_ERROR);
4806   std::set<int> ret1;
4807   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4808     {
4809       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4810       ret1.insert((int)cm.getDimension());
4811     }
4812   int ret=*std::max_element(ret1.begin(),ret1.end());
4813   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4814   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4815   return ret;
4816 }
4817
4818 void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic()
4819 {
4820   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it<_field_per_mesh.end();it++)
4821     if((*it).isNotNull())
4822       (*it)->convertMedBallIntoClassic();
4823 }
4824
4825 void MEDFileAnyTypeField1TSWithoutSDA::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
4826 {
4827   if(!pfl)
4828     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : null pfl !");
4829   std::string name(pfl->getName());
4830   pfl->checkAllocated();
4831   if(pfl->getNumberOfComponents()!=1)
4832     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : non mono compo array !");
4833   if(name.empty())
4834     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : empty pfl name !");
4835   if(_field_per_mesh.size()!=1)
4836     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single mesh supported !");
4837   MCAuto<MEDFileFieldPerMesh> fpm(_field_per_mesh[0]);
4838   if(fpm.isNull())
4839     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single not null mesh supported !");
4840   MEDFileFieldPerMeshPerTypePerDisc *disc(fpm->getLeafGivenTypeAndLocId(ct,0));
4841   if(disc->getType()!=tof)
4842     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : error !");
4843   int s(disc->getStart()),e(disc->getEnd()),nt(pfl->getNumberOfTuples());
4844   DataArray *arr(getUndergroundDataArray());
4845   int nt2(arr->getNumberOfTuples()),delta((e-s)-nt);
4846   if(delta<0)
4847     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : internal error !");
4848   MCAuto<DataArray> arr0(arr->selectByTupleIdSafeSlice(0,s,1)),arr1(arr->selectByTupleIdSafeSlice(s,e,1)),arr2(arr->selectByTupleIdSafeSlice(e,nt2,1));
4849   MCAuto<DataArray> arr11(arr1->selectByTupleIdSafe(pfl->begin(),pfl->end()));
4850   MCAuto<DataArray> arrOut(arr->buildNewEmptyInstance());
4851   arrOut->alloc(nt2-delta,arr->getNumberOfComponents());
4852   arrOut->copyStringInfoFrom(*arr);
4853   arrOut->setContigPartOfSelectedValuesSlice(0,arr0,0,s,1);
4854   arrOut->setContigPartOfSelectedValuesSlice(s,arr11,0,nt,1);
4855   arrOut->setContigPartOfSelectedValuesSlice(e-delta,arr2,0,nt2-e,1);
4856   setArray(arrOut);
4857   disc->setEnd(e-delta);
4858   disc->setProfile(name);
4859 }
4860
4861 /*!
4862  * \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.
4863  * \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.
4864  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4865  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4866  */
4867 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4868 {
4869   if(_field_per_mesh.empty())
4870     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4871   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4872 }
4873
4874 /*!
4875  * \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.
4876  * \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.
4877  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4878  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4879  */
4880 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4881 {
4882   if(_field_per_mesh.empty())
4883     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4884   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4885 }
4886
4887 /*!
4888  * \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.
4889  */
4890 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4891 {
4892   if(_field_per_mesh.empty())
4893     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4894   if(mName.empty())
4895     return 0;
4896   std::string mName2(mName);
4897   int ret=0;
4898   std::vector<std::string> msg;
4899   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4900     if(mName2==(*it)->getMeshName())
4901       return ret;
4902     else
4903       msg.push_back((*it)->getMeshName());
4904   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4905   oss << "Possible meshes are : ";
4906   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4907     oss << "\"" << (*it2) << "\" ";
4908   throw INTERP_KERNEL::Exception(oss.str());
4909 }
4910
4911 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4912 {
4913   if(!mesh)
4914     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4915   std::string tmp(mesh->getName());
4916   if(tmp.empty())
4917     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4918   setMeshName(tmp);
4919   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4920   int i=0;
4921   for(;it!=_field_per_mesh.end();it++,i++)
4922     {
4923       if((*it)->getMeshName()==tmp)
4924         return i;
4925     }
4926   int sz=_field_per_mesh.size();
4927   _field_per_mesh.resize(sz+1);
4928   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4929   return sz;
4930 }
4931
4932 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4933                                                                    MEDFileFieldGlobsReal& glob)
4934 {
4935   bool ret=false;
4936   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4937     {
4938       MEDFileFieldPerMesh *fpm(*it);
4939       if(fpm)
4940         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4941     }
4942   return ret;
4943 }
4944
4945 /*!
4946  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4947  * splitting that leads to single spatial discretization of this.
4948  *
4949  * \sa splitMultiDiscrPerGeoTypes
4950  */
4951 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4952 {
4953   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4954   std::vector< std::vector<TypeOfField> > typesF;
4955   std::vector< std::vector<std::string> > pfls,locs;
4956   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4957   std::set<TypeOfField> allEnt;
4958   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4959     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4960       allEnt.insert(*it2);
4961   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4962   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4963   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4964     {
4965       std::vector< std::pair<int,int> > its;
4966       ret[i]=shallowCpy();
4967       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4968       ret[i]->updateData(newLgth,its);
4969     }
4970   return ret;
4971 }
4972
4973 /*!
4974  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4975  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4976  *
4977  * \sa splitDiscretizations
4978  */
4979 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4980 {
4981   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4982   std::vector< std::vector<TypeOfField> > typesF;
4983   std::vector< std::vector<std::string> > pfls,locs;
4984   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4985   std::set<TypeOfField> allEnt;
4986   std::size_t nbOfMDPGT(0),ii(0);
4987   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4988     {
4989       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4990       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4991         allEnt.insert(*it2);
4992     }
4993   if(allEnt.size()!=1)
4994     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4995   if(nbOfMDPGT==0)
4996     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4997   if(nbOfMDPGT==1)
4998     {
4999       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
5000       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
5001       return ret0;
5002     }
5003   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
5004   for(std::size_t i=0;i<nbOfMDPGT;i++)
5005     {
5006       std::vector< std::pair<int,int> > its;
5007       ret[i]=shallowCpy();
5008       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
5009       ret[i]->updateData(newLgth,its);
5010     }
5011   return ret;
5012 }
5013
5014 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
5015 {
5016   int globalCounter(0);
5017   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5018     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
5019   return globalCounter;
5020 }
5021
5022 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
5023 {
5024   int globalCounter(0);
5025   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5026     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
5027   return globalCounter;
5028 }
5029
5030 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
5031 {
5032   if(_nb_of_tuples_to_be_allocated>=0)
5033     {
5034       _nb_of_tuples_to_be_allocated=newLgth;
5035       const DataArray *oldArr(getUndergroundDataArray());
5036       if(oldArr)
5037         {
5038           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
5039           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
5040           setArray(newArr);
5041           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
5042         }
5043       return ;
5044     }
5045   if(_nb_of_tuples_to_be_allocated==-1)
5046     return ;
5047   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
5048     {
5049       const DataArray *oldArr(getUndergroundDataArray());
5050       if(!oldArr || !oldArr->isAllocated())
5051         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
5052       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
5053       newArr->alloc(newLgth,getNumberOfComponents());
5054       if(oldArr)
5055         newArr->copyStringInfoFrom(*oldArr);
5056       int pos=0;
5057       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
5058         {
5059           if((*it).second<(*it).first)
5060             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
5061           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
5062           pos+=(*it).second-(*it).first;
5063         }
5064       setArray(newArr);
5065       return ;
5066     }
5067   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
5068 }
5069
5070 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
5071 {
5072   if(_field_per_mesh.empty())
5073     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
5074   if(_field_per_mesh.size()>1)
5075     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
5076   _field_per_mesh[0]->copyOptionsFrom(opts);
5077   _field_per_mesh[0]->writeLL(fid,nasc);
5078 }
5079
5080 /*!
5081  * MED file does not support ' ' at the end of the field name. This method corrects the possibly invalid input \a nonCorrectFieldName to a correct one by right stripping input.
5082  */
5083 std::string MEDFileAnyTypeField1TSWithoutSDA::FieldNameToMEDFileConvention(const std::string& nonCorrectFieldName)
5084 {
5085   std::string::size_type pos0(nonCorrectFieldName.find_last_not_of(' '));
5086   if(pos0==std::string::npos)
5087     return nonCorrectFieldName;
5088   if(pos0+1==nonCorrectFieldName.length())
5089     return nonCorrectFieldName;
5090   return nonCorrectFieldName.substr(0,pos0+1);
5091 }
5092
5093 /*!
5094  * 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.
5095  * If false is returned the memory allocation is not required.
5096  */
5097 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
5098 {
5099   if(_nb_of_tuples_to_be_allocated>=0)
5100     {
5101       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
5102       _nb_of_tuples_to_be_allocated=-2;
5103       return true;
5104     }
5105   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
5106     return false;
5107   if(_nb_of_tuples_to_be_allocated==-1)
5108     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
5109   if(_nb_of_tuples_to_be_allocated<-3)
5110     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5111   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5112 }
5113
5114 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5115 {
5116   med_int numdt,numit;
5117   med_float dt;
5118   med_int meshnumdt,meshnumit;
5119   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
5120   {
5121     med_bool localMesh;
5122     med_int nmesh;
5123     INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
5124     MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit)); // to check with Adrien for legacy MED files
5125   }
5126   //MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt,&meshnumdt,&meshnumit));
5127   if(_iteration!=numdt || _order!=numit)
5128     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
5129   _field_per_mesh.resize(1);
5130   //
5131   MEDFileMesh *mm(0);
5132   if(ms)
5133     {
5134       mm=ms->getMeshWithName(getMeshName());
5135     }
5136   //
5137   _field_per_mesh[0]=MEDFileFieldPerMesh::NewOnRead(fid,this,0,meshnumdt,meshnumit,nasc,mm,entities);
5138   _nb_of_tuples_to_be_allocated=0;
5139   _field_per_mesh[0]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
5140 }
5141
5142 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
5143 {
5144   allocIfNecessaryTheArrayToReceiveDataFromFile();
5145   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5146     (*it)->loadBigArraysRecursively(fid,nasc);
5147 }
5148
5149 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
5150 {
5151   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
5152     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5153       (*it)->loadBigArraysRecursively(fid,nasc);
5154 }
5155
5156 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5157 {
5158   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
5159   loadBigArraysRecursively(fid,nasc);
5160 }
5161
5162 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
5163 {
5164   DataArray *thisArr(getUndergroundDataArray());
5165   if(thisArr && thisArr->isAllocated())
5166     {
5167       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
5168       thisArr->desallocate();
5169     }
5170 }
5171
5172 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
5173 {
5174   return _mesh_name.capacity()+_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
5175 }
5176
5177 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
5178 {
5179   std::vector<const BigMemoryObject *> ret;
5180   if(getUndergroundDataArray())
5181     ret.push_back(getUndergroundDataArray());
5182   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5183     ret.push_back((const MEDFileFieldPerMesh *)*it);
5184   return ret;
5185 }
5186
5187 /*!
5188  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
5189  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
5190  * "Sort By Type"), if not, an exception is thrown. 
5191  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
5192  *  \param [in] arr - the array of values.
5193  *  \param [in,out] glob - the global data where profiles and localization present in
5194  *          \a field, if any, are added.
5195  *  \throw If the name of \a field is empty.
5196  *  \throw If the data array of \a field is not set.
5197  *  \throw If \a this->_arr is already allocated but has different number of components
5198  *         than \a field.
5199  *  \throw If the underlying mesh of \a field has no name.
5200  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
5201  */
5202 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5203 {
5204   const MEDCouplingMesh *mesh(field->getMesh());
5205   //
5206   TypeOfField type(field->getTypeOfField());
5207   std::vector<DataArrayInt *> dummy;
5208   if(mesh)
5209     setMeshName(mesh->getName());
5210   int start(copyTinyInfoFrom(th,field,arr));
5211   int pos(addNewEntryIfNecessary(mesh));
5212   if(type!=ON_NODES)
5213     {
5214       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
5215       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
5216     }
5217   else
5218     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
5219 }
5220
5221 /*!
5222  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
5223  * of a given mesh are used as the support of the given field (a real support is not used). 
5224  * Elements of the given mesh must be sorted suitable for writing to MED file. 
5225  * Order of underlying mesh entities of the given field specified by \a profile parameter
5226  * is not prescribed; this method permutes field values to have them sorted by element
5227  * type as required for writing to MED file. A new profile is added only if no equal
5228  * profile is missing. 
5229  *  \param [in] field - the field to add to \a this. The field double values are ignored.
5230  *  \param [in] arrOfVals - the values of the field \a field used.
5231  *  \param [in] mesh - the supporting mesh of \a field.
5232  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
5233  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
5234  *  \param [in,out] glob - the global data where profiles and localization present in
5235  *          \a field, if any, are added.
5236  *  \throw If either \a field or \a mesh or \a profile has an empty name.
5237  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5238  *  \throw If the data array of \a field is not set.
5239  *  \throw If \a this->_arr is already allocated but has different number of components
5240  *         than \a field.
5241  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5242  *  \sa setFieldNoProfileSBT()
5243  */
5244 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5245 {
5246   if(!field)
5247     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
5248   if(!arrOfVals || !arrOfVals->isAllocated())
5249     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
5250   TypeOfField type=field->getTypeOfField();
5251   std::vector<DataArrayInt *> idsInPflPerType;
5252   std::vector<DataArrayInt *> idsPerType;
5253   std::vector<int> code,code2;
5254   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5255   if(type!=ON_NODES)
5256     {
5257       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
5258       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
5259       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
5260       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
5261       // start of check
5262       MCAuto<MEDCouplingFieldTemplate> field2=field->clone(false);
5263       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
5264       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5265         {
5266           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5267           throw INTERP_KERNEL::Exception(oss.str());
5268         }
5269       // end of check
5270       int start(copyTinyInfoFrom(th,field,arrOfVals));
5271       code2=m->getDistributionOfTypes();
5272       //
5273       int pos=addNewEntryIfNecessary(m);
5274       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
5275     }
5276   else
5277     {
5278       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
5279         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
5280       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
5281       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
5282       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
5283       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5284         {
5285           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5286           throw INTERP_KERNEL::Exception(oss.str());
5287         }
5288       int start(copyTinyInfoFrom(th,field,arrOfVals));
5289       int pos(addNewEntryIfNecessary(m));
5290       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
5291     }
5292 }
5293
5294 /*!
5295  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
5296  */
5297 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
5298 {
5299   if(_nb_of_tuples_to_be_allocated>=0)
5300     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 !");
5301   DataArray *arr(getOrCreateAndGetArray());
5302   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
5303   _nb_of_tuples_to_be_allocated=-3;
5304 }
5305
5306 /*!
5307  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
5308  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
5309  * larger by the size of \a field. Returns an id of the first not filled
5310  * tuple of \a this->_arr.
5311  *  \param [in] field - the field to copy the info on components and the name from.
5312  *  \return int - the id of first not initialized tuple of \a this->_arr.
5313  *  \throw If the name of \a field is empty.
5314  *  \throw If the data array of \a field is not set.
5315  *  \throw If \a this->_arr is already allocated but has different number of components
5316  *         than \a field.
5317  */
5318 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
5319 {
5320   if(!field)
5321     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
5322   std::string name(field->getName());
5323   setName(name.c_str());
5324   if(field->getMesh())
5325     setMeshName(field->getMesh()->getName());
5326   setDtUnit(th->getTimeUnit());
5327   if(name.empty())
5328     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
5329   if(!arr)
5330     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
5331   if(!arr->isAllocated())
5332     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
5333   _dt=th->getTime(_iteration,_order);
5334   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
5335   if(!getOrCreateAndGetArray()->isAllocated())
5336     {
5337       allocNotFromFile(arr->getNumberOfTuples());
5338       return 0;
5339     }
5340   else
5341     {
5342       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
5343       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
5344       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
5345       _nb_of_tuples_to_be_allocated=-3;
5346       return oldNbOfTuples;
5347     }
5348 }
5349
5350 /*!
5351  * Returns number of components in \a this field
5352  *  \return int - the number of components.
5353  */
5354 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
5355 {
5356   return getOrCreateAndGetArray()->getNumberOfComponents();
5357 }
5358
5359 /*!
5360  * Change info on components in \a this.
5361  * \throw If size of \a infos is not equal to the number of components already in \a this.
5362  */
5363 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
5364 {
5365   DataArray *arr=getOrCreateAndGetArray();
5366   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
5367 }
5368
5369 /*!
5370  * Returns info on components of \a this field.
5371  *  \return const std::vector<std::string>& - a sequence of strings each being an
5372  *          information on _i_-th component.
5373  */
5374 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
5375 {
5376   const DataArray *arr=getOrCreateAndGetArray();
5377   return arr->getInfoOnComponents();
5378 }
5379
5380 /*!
5381  * Returns a mutable info on components of \a this field.
5382  *  \return std::vector<std::string>& - a sequence of strings each being an
5383  *          information on _i_-th component.
5384  */
5385 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
5386 {
5387   DataArray *arr=getOrCreateAndGetArray();
5388   return arr->getInfoOnComponents();
5389 }
5390
5391 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
5392 {
5393   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5394     {
5395       const MEDFileFieldPerMesh *fpm(*it);
5396       if(!fpm)
5397         continue;
5398       if(fpm->presenceOfMultiDiscPerGeoType())
5399         return true;
5400     }
5401   return false;
5402 }
5403
5404 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
5405 {
5406   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5407     if((*it).isNotNull())
5408       if((*it)->presenceOfStructureElements())
5409         return true;
5410   return false;
5411 }
5412
5413 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
5414 {
5415   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5416     if((*it).isNotNull())
5417       if(!(*it)->onlyStructureElements())
5418         return false;
5419   return true;
5420 }
5421
5422 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
5423 {
5424   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5425     if((*it).isNotNull())
5426       (*it)->killStructureElements();
5427 }
5428
5429 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
5430 {
5431   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5432     if((*it).isNotNull())
5433       (*it)->keepOnlyStructureElements();
5434 }
5435
5436 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName)
5437 {
5438   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5439     if((*it).isNotNull())
5440       (*it)->keepOnlyOnSE(seName);
5441 }
5442
5443 void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
5444 {
5445   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5446     if((*it).isNotNull())
5447       (*it)->getMeshSENames(ps);
5448 }
5449
5450 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5451 {
5452   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 !";
5453   if(_field_per_mesh.empty())
5454     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
5455   if(_field_per_mesh.size()>1)
5456     throw INTERP_KERNEL::Exception(MSG0);
5457   if(_field_per_mesh[0].isNull())
5458     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
5459   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
5460   std::set<TypeOfField> types;
5461   pm->fillTypesOfFieldAvailable(types);
5462   if(types.size()!=1)
5463     throw INTERP_KERNEL::Exception(MSG0);
5464   TypeOfField type(*types.begin());
5465   int meshDimRelToMax(0);
5466   if(type==ON_NODES)
5467     meshDimRelToMax=0;
5468   else
5469     {
5470       int myDim(std::numeric_limits<int>::max());
5471       bool isUnique(pm->isUniqueLevel(myDim));
5472       if(!isUnique)
5473         throw INTERP_KERNEL::Exception(MSG0);
5474       meshDimRelToMax=myDim-mesh->getMeshDimension();
5475       if(meshDimRelToMax>0)
5476         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5477     }
5478   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5479 }
5480
5481 /*!
5482  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5483  *  \param [in] type - a spatial discretization of the new field.
5484  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5485  *  \param [in] mName - a name of the supporting mesh.
5486  *  \param [in] renumPol - specifies how to permute values of the result field according to
5487  *          the optional numbers of cells and nodes, if any. The valid values are
5488  *          - 0 - do not permute.
5489  *          - 1 - permute cells.
5490  *          - 2 - permute nodes.
5491  *          - 3 - permute cells and nodes.
5492  *
5493  *  \param [in] glob - the global data storing profiles and localization.
5494  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5495  *          caller is to delete this field using decrRef() as it is no more needed. 
5496  *  \throw If the MED file is not readable.
5497  *  \throw If there is no mesh named \a mName in the MED file.
5498  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5499  *  \throw If no field of \a this is lying on the mesh \a mName.
5500  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5501  */
5502 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5503 {
5504   MCAuto<MEDFileMesh> mm;
5505   if(mName.empty())
5506     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5507   else
5508     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5509   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5510 }
5511
5512 /*!
5513  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5514  *  \param [in] type - a spatial discretization of the new field.
5515  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5516  *  \param [in] renumPol - specifies how to permute values of the result field according to
5517  *          the optional numbers of cells and nodes, if any. The valid values are
5518  *          - 0 - do not permute.
5519  *          - 1 - permute cells.
5520  *          - 2 - permute nodes.
5521  *          - 3 - permute cells and nodes.
5522  *
5523  *  \param [in] glob - the global data storing profiles and localization.
5524  *  \param [in] mesh - the supporting mesh.
5525  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5526  *          caller is to delete this field using decrRef() as it is no more needed. 
5527  *  \throw If the MED file is not readable.
5528  *  \throw If no field of \a this is lying on \a mesh.
5529  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5530  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5531  */
5532 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5533 {
5534   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5535   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5536   if(meshDimRelToMax==1)
5537     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5538   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5539 }
5540
5541 /*!
5542  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5543  * given mesh. 
5544  *  \param [in] type - a spatial discretization of the new field.
5545  *  \param [in] mName - a name of the supporting mesh.
5546  *  \param [in] renumPol - specifies how to permute values of the result field according to
5547  *          the optional numbers of cells and nodes, if any. The valid values are
5548  *          - 0 - do not permute.
5549  *          - 1 - permute cells.
5550  *          - 2 - permute nodes.
5551  *          - 3 - permute cells and nodes.
5552  *
5553  *  \param [in] glob - the global data storing profiles and localization.
5554  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5555  *          caller is to delete this field using decrRef() as it is no more needed. 
5556  *  \throw If the MED file is not readable.
5557  *  \throw If there is no mesh named \a mName in the MED file.
5558  *  \throw If there are no mesh entities in the mesh.
5559  *  \throw If no field values of the given \a type are available.
5560  */
5561 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5562 {
5563   MCAuto<MEDFileMesh> mm;
5564   if(mName.empty())
5565     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5566   else
5567     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5568   int absDim=getDimension();
5569   int meshDimRelToMax=absDim-mm->getMeshDimension();
5570   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5571 }
5572
5573 /*!
5574  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5575  *  \param [in] type - a spatial discretization of the new field.
5576  *  \param [in] renumPol - specifies how to permute values of the result field according to
5577  *          the optional numbers of cells and nodes, if any. The valid values are
5578  *          - 0 - do not permute.
5579  *          - 1 - permute cells.
5580  *          - 2 - permute nodes.
5581  *          - 3 - permute cells and nodes.
5582  *
5583  *  \param [in] glob - the global data storing profiles and localization.
5584  *  \param [in] mesh - the supporting mesh.
5585  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5586  *         field according to \a renumPol.
5587  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5588  *         field according to \a renumPol.
5589  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5590  *          caller is to delete this field using decrRef() as it is no more needed. 
5591  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5592  *  \throw If no field of \a this is lying on \a mesh.
5593  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5594  */
5595 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
5596 {
5597   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5598   bool isPfl=false;
5599   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[0]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5600   switch(renumPol)
5601   {
5602     case 0:
5603       {
5604         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5605         return ret.retn();
5606       }
5607     case 3:
5608     case 1:
5609       {
5610         if(isPfl)
5611           throw INTERP_KERNEL::Exception(msg1);
5612         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5613         if(cellRenum)
5614           {
5615             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5616               {
5617                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5618                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5619                 throw INTERP_KERNEL::Exception(oss.str());
5620               }
5621             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5622             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5623             std::vector<DataArray *> arrOut2(1,arrOut);
5624             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5625             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5626             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5627           }
5628         if(renumPol==1)
5629           return ret.retn();
5630       }
5631     case 2:
5632       {
5633         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5634         if(isPfl)
5635           throw INTERP_KERNEL::Exception(msg1);
5636         if(nodeRenum)
5637           {
5638             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5639               {
5640                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5641                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5642                 throw INTERP_KERNEL::Exception(oss.str());
5643               }
5644             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5645             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5646               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5647             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5648           }
5649         return ret.retn();
5650       }
5651     default:
5652       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5653   }
5654 }
5655
5656 /*!
5657  * Returns values and a profile of the field of a given type lying on a given support.
5658  *  \param [in] type - a spatial discretization of the field.
5659  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5660  *  \param [in] mesh - the supporting mesh.
5661  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5662  *          field of interest lies on. If the field lies on all entities of the given
5663  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5664  *          using decrRef() as it is no more needed.  
5665  *  \param [in] glob - the global data storing profiles and localization.
5666  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5667  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5668  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5669  *  \throw If no field of \a this is lying on \a mesh.
5670  *  \throw If no field values of the given \a type are available.
5671  */
5672 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5673 {
5674   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5675   MCAuto<DataArray> ret=_field_per_mesh[0]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5676   ret->setName(nasc.getName().c_str());
5677   return ret.retn();
5678 }
5679
5680 //= MEDFileField1TSWithoutSDA
5681
5682 /*!
5683  * Throws if a given value is not a valid (non-extended) relative dimension.
5684  *  \param [in] meshDimRelToMax - the relative dimension value.
5685  *  \throw If \a meshDimRelToMax > 0.
5686  */
5687 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5688 {
5689   if(meshDimRelToMax>0)
5690     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5691 }
5692
5693 /*!
5694  * Checks if elements of a given mesh are in the order suitable for writing 
5695  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5696  * vector describing types of elements and their number.
5697  *  \param [in] mesh - the mesh to check.
5698  *  \return std::vector<int> - a vector holding for each element type (1) item of
5699  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5700  *          These values are in full-interlace mode.
5701  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5702  */
5703 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5704 {
5705   if(!mesh)
5706     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5707   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5708   int nbOfTypes=geoTypes.size();
5709   std::vector<int> code(3*nbOfTypes);
5710   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5711   arr1->alloc(nbOfTypes,1);
5712   int *arrPtr=arr1->getPointer();
5713   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5714   for(int i=0;i<nbOfTypes;i++,it++)
5715     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5716   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5717   const int *arrPtr2=arr2->getConstPointer();
5718   int i=0;
5719   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5720     {
5721       int pos=arrPtr2[i];
5722       int nbCells=mesh->getNumberOfCellsWithType(*it);
5723       code[3*pos]=(int)(*it);
5724       code[3*pos+1]=nbCells;
5725       code[3*pos+2]=-1;//no profiles
5726     }
5727   std::vector<const DataArrayInt *> idsPerType;//no profiles
5728   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5729   if(da)
5730     {
5731       da->decrRef();
5732       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5733     }
5734   return code;
5735 }
5736
5737 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5738 {
5739   return new MEDFileField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5740 }
5741
5742 /*!
5743  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5744  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5745  * item of every of returned sequences refers to the _i_-th part of \a this field.
5746  * Thus all sequences returned by this method are of the same length equal to number
5747  * of different types of supporting entities.<br>
5748  * A field part can include sub-parts with several different spatial discretizations,
5749  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5750  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5751  * of a nested sequence corresponds to a type of spatial discretization.<br>
5752  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5753  * The overhead is due to selecting values into new instances of DataArrayDouble.
5754  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5755  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5756  *          not checked if \a mname == \c NULL).
5757  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5758  *          a field part is returned. 
5759  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5760  *          A field part can include sub-parts with several different spatial discretizations,
5761  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5762  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5763  *          This sequence is of the same length as \a types. 
5764  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5765  *          discretization. A profile name can be empty.
5766  *          Length of this and of nested sequences is the same as that of \a typesF.
5767  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5768  *          discretization. A localization name can be empty.
5769  *          Length of this and of nested sequences is the same as that of \a typesF.
5770  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5771  *          per each type of spatial discretization within one mesh entity type.
5772  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5773  *          Length of this and of nested sequences is the same as that of \a typesF.
5774  *  \throw If no field is lying on \a mname.
5775  */
5776 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
5777 {
5778   if(mname.empty())
5779     if(_field_per_mesh.empty())
5780       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5781   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
5782   int nbOfRet=ret0.size();
5783   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5784   for(int i=0;i<nbOfRet;i++)
5785     {
5786       const std::vector< std::pair<int,int> >& p=ret0[i];
5787       int nbOfRet1=p.size();
5788       ret[i].resize(nbOfRet1);
5789       for(int j=0;j<nbOfRet1;j++)
5790         {
5791           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5792           ret[i][j]=tmp;
5793         }
5794     }
5795   return ret;
5796 }
5797
5798 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5799 {
5800   return TYPE_STR;
5801 }
5802
5803 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5804 {
5805   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5806   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5807   ret->deepCpyLeavesFrom(*this);
5808   const DataArrayDouble *arr(_arr);
5809   if(arr)
5810     {
5811       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5812       ret->setArray(arr2);
5813     }
5814   return ret.retn();
5815 }
5816
5817 /*!
5818  * Returns a pointer to the underground DataArrayDouble instance and a
5819  * sequence describing parameters of a support of each part of \a this field. The
5820  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5821  * direct access to the field values. This method is intended for the field lying on one
5822  * mesh only.
5823  *  \param [in,out] entries - the sequence describing parameters of a support of each
5824  *         part of \a this field. Each item of this sequence consists of two parts. The
5825  *         first part describes a type of mesh entity and an id of discretization of a
5826  *         current field part. The second part describes a range of values [begin,end)
5827  *         within the returned array relating to the current field part.
5828  *  \return DataArrayDouble * - the pointer to the field values array.
5829  *  \throw If the number of underlying meshes is not equal to 1.
5830  *  \throw If no field values are available.
5831  *  \sa getUndergroundDataArray()
5832  */
5833 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5834 {
5835   return getUndergroundDataArrayTemplateExt(entries);
5836 }
5837
5838 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,meshName,csit,iteration,order)
5839 {
5840   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5841   arr->setInfoAndChangeNbOfCompo(infos);
5842 }
5843
5844 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5845 {
5846 }
5847
5848 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5849 {
5850   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5851   ret->deepCpyLeavesFrom(*this);
5852   return ret.retn();
5853 }
5854
5855 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5856 {
5857   MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
5858   if(_arr.isNotNull())
5859     ret->_arr=_arr->deepCopy();
5860   return ret.retn();
5861 }
5862
5863 //= MEDFileIntField1TSWithoutSDA
5864
5865 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5866 {
5867   return new MEDFileIntField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5868 }
5869
5870 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA()
5871 {
5872 }
5873
5874 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
5875                                                            const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<int>(fieldName,meshName,csit,iteration,order,infos)
5876 {
5877   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5878   arr->setInfoAndChangeNbOfCompo(infos);
5879 }
5880
5881 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5882 {
5883   return TYPE_STR;
5884 }
5885
5886 /*!
5887  * Returns a pointer to the underground DataArrayInt instance and a
5888  * sequence describing parameters of a support of each part of \a this field. The
5889  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5890  * direct access to the field values. This method is intended for the field lying on one
5891  * mesh only.
5892  *  \param [in,out] entries - the sequence describing parameters of a support of each
5893  *         part of \a this field. Each item of this sequence consists of two parts. The
5894  *         first part describes a type of mesh entity and an id of discretization of a
5895  *         current field part. The second part describes a range of values [begin,end)
5896  *         within the returned array relating to the current field part.
5897  *  \return DataArrayInt * - the pointer to the field values array.
5898  *  \throw If the number of underlying meshes is not equal to 1.
5899  *  \throw If no field values are available.
5900  *  \sa getUndergroundDataArray()
5901  */
5902 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5903 {
5904   return getUndergroundDataArrayIntExt(entries);
5905 }
5906
5907 /*!
5908  * Returns a pointer to the underground DataArrayInt instance and a
5909  * sequence describing parameters of a support of each part of \a this field. The
5910  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5911  * direct access to the field values. This method is intended for the field lying on one
5912  * mesh only.
5913  *  \param [in,out] entries - the sequence describing parameters of a support of each
5914  *         part of \a this field. Each item of this sequence consists of two parts. The
5915  *         first part describes a type of mesh entity and an id of discretization of a
5916  *         current field part. The second part describes a range of values [begin,end)
5917  *         within the returned array relating to the current field part.
5918  *  \return DataArrayInt * - the pointer to the field values array.
5919  *  \throw If the number of underlying meshes is not equal to 1.
5920  *  \throw If no field values are available.
5921  *  \sa getUndergroundDataArray()
5922  */
5923 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5924 {
5925   if(_field_per_mesh.size()!=1)
5926     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5927   if(_field_per_mesh[0]==0)
5928     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5929   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5930   return getUndergroundDataArrayTemplate();
5931 }
5932
5933 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5934 {
5935   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5936   ret->deepCpyLeavesFrom(*this);
5937   return ret.retn();
5938 }
5939
5940 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5941 {
5942   MCAuto<MEDFileIntField1TSWithoutSDA> ret(shallowCpy());
5943   if(_arr.isNotNull())
5944     ret->_arr=_arr->deepCopy();
5945   return ret.retn();
5946 }
5947
5948 //= MEDFileFloatField1TSWithoutSDA
5949
5950 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5951 {
5952   return new MEDFileFloatField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5953 }
5954
5955 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA()
5956 {
5957 }
5958
5959 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
5960                                                                const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<float>(fieldName,meshName,csit,iteration,order,infos)
5961 {
5962   DataArrayFloat *arr(getOrCreateAndGetArrayTemplate());
5963   arr->setInfoAndChangeNbOfCompo(infos);
5964 }
5965
5966 const char *MEDFileFloatField1TSWithoutSDA::getTypeStr() const
5967 {
5968   return TYPE_STR;
5969 }
5970
5971 /*!
5972  * Returns a pointer to the underground DataArrayFloat instance and a
5973  * sequence describing parameters of a support of each part of \a this field. The
5974  * caller should not decrRef() the returned DataArrayFloat. This method allows for a
5975  * direct access to the field values. This method is intended for the field lying on one
5976  * mesh only.
5977  *  \param [in,out] entries - the sequence describing parameters of a support of each
5978  *         part of \a this field. Each item of this sequence consists of two parts. The
5979  *         first part describes a type of mesh entity and an id of discretization of a
5980  *         current field part. The second part describes a range of values [begin,end)
5981  *         within the returned array relating to the current field part.
5982  *  \return DataArrayFloat * - the pointer to the field values array.
5983  *  \throw If the number of underlying meshes is not equal to 1.
5984  *  \throw If no field values are available.
5985  *  \sa getUndergroundDataArray()
5986  */
5987 DataArray *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5988 {
5989   return getUndergroundDataArrayFloatExt(entries);
5990 }
5991
5992 /*!
5993  * Returns a pointer to the underground DataArrayFloat instance and a
5994  * sequence describing parameters of a support of each part of \a this field. The
5995  * caller should not decrRef() the returned DataArrayFloat. This method allows for a
5996  * direct access to the field values. This method is intended for the field lying on one
5997  * mesh only.
5998  *  \param [in,out] entries - the sequence describing parameters of a support of each
5999  *         part of \a this field. Each item of this sequence consists of two parts. The
6000  *         first part describes a type of mesh entity and an id of discretization of a
6001  *         current field part. The second part describes a range of values [begin,end)
6002  *         within the returned array relating to the current field part.
6003  *  \return DataArrayFloat * - the pointer to the field values array.
6004  *  \throw If the number of underlying meshes is not equal to 1.
6005  *  \throw If no field values are available.
6006  *  \sa getUndergroundDataArray()
6007  */
6008 DataArrayFloat *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayFloatExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6009 {
6010   if(_field_per_mesh.size()!=1)
6011     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
6012   if(_field_per_mesh[0]==0)
6013     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
6014   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
6015   return getUndergroundDataArrayTemplate();
6016 }
6017
6018 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::shallowCpy() const
6019 {
6020   MCAuto<MEDFileFloatField1TSWithoutSDA> ret(new MEDFileFloatField1TSWithoutSDA(*this));
6021   ret->deepCpyLeavesFrom(*this);
6022   return ret.retn();
6023 }
6024
6025 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::deepCopy() const
6026 {
6027   MCAuto<MEDFileFloatField1TSWithoutSDA> ret(shallowCpy());
6028   if(_arr.isNotNull())
6029     ret->_arr=_arr->deepCopy();
6030   return ret.retn();
6031 }
6032
6033 //= MEDFileAnyTypeField1TS
6034
6035 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
6036 {
6037 }
6038
6039 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6040 {
6041   med_field_type typcha;
6042   //
6043   std::vector<std::string> infos;
6044   std::string dtunit,fieldName,meshName;
6045   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
6046   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6047   switch(typcha)
6048   {
6049     case MED_FLOAT64:
6050       {
6051         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6052         break;
6053       }
6054     case MED_INT32:
6055       {
6056         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6057         break;
6058       }
6059     case MED_FLOAT32:
6060       {
6061         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6062         break;
6063       }
6064     case MED_INT:
6065       {
6066         if(sizeof(med_int)==sizeof(int))
6067           {
6068             ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6069             break;
6070           }
6071       }
6072     default:
6073       {
6074         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] !";
6075         throw INTERP_KERNEL::Exception(oss.str());
6076       }
6077   }
6078   ret->setDtUnit(dtunit.c_str());
6079   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6080   //
6081   med_int numdt,numit;
6082   med_float dt;
6083   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
6084   ret->setTime(numdt,numit,dt);
6085   ret->_csit=1;
6086   if(loadAll)
6087     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6088   else
6089     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6090   return ret.retn();
6091 }
6092
6093 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6094 try:MEDFileFieldGlobsReal(fid)
6095 {
6096   _content=BuildContentFrom(fid,loadAll,ms,entities);
6097   loadGlobals(fid);
6098 }
6099 catch(INTERP_KERNEL::Exception& e)
6100 {
6101     throw e;
6102 }
6103
6104 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6105 {
6106   med_field_type typcha;
6107   std::vector<std::string> infos;
6108   std::string dtunit,meshName;
6109   int nbSteps(0);
6110   {
6111     int iii=-1;
6112     nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName);
6113   }
6114   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6115   switch(typcha)
6116   {
6117     case MED_FLOAT64:
6118       {
6119         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6120         break;
6121       }
6122     case MED_INT32:
6123       {
6124         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6125         break;
6126       }
6127     case MED_FLOAT32:
6128       {
6129         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6130         break;
6131       }
6132     case MED_INT:
6133       {
6134         if(sizeof(med_int)==sizeof(int))
6135           {
6136             ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6137             break;
6138           }
6139       }
6140     default:
6141       {
6142         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, MED_FLOAT32] !";
6143         throw INTERP_KERNEL::Exception(oss.str());
6144       }
6145   }
6146   ret->setMeshName(meshName);
6147   ret->setDtUnit(dtunit.c_str());
6148   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6149   //
6150   if(nbSteps<1)
6151     {
6152       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
6153       throw INTERP_KERNEL::Exception(oss.str());
6154     }
6155   //
6156   med_int numdt,numit;
6157   med_float dt;
6158   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
6159   ret->setTime(numdt,numit,dt);
6160   ret->_csit=1;
6161   if(loadAll)
6162     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6163   else
6164     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6165   return ret.retn();
6166 }
6167
6168 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6169 try:MEDFileFieldGlobsReal(fid)
6170 {
6171   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
6172   loadGlobals(fid);
6173 }
6174 catch(INTERP_KERNEL::Exception& e)
6175 {
6176     throw e;
6177 }
6178
6179 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
6180 {
6181   if(!c)
6182     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
6183   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
6184     {
6185       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6186       ret->_content=c; c->incrRef();
6187       return ret.retn();
6188     }
6189   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
6190     {
6191       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
6192       ret->_content=c; c->incrRef();
6193       return ret.retn();
6194     }
6195   if(dynamic_cast<const MEDFileFloatField1TSWithoutSDA *>(c))
6196     {
6197       MCAuto<MEDFileFloatField1TS> ret(MEDFileFloatField1TS::New());
6198       ret->_content=c; c->incrRef();
6199       return ret.retn();
6200     }
6201   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
6202 }
6203
6204 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
6205 {
6206   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
6207   ret->setFileName(FileNameFromFID(fid));
6208   return ret;
6209 }
6210
6211 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
6212 {
6213   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6214   return New(fid,loadAll);
6215 }
6216
6217 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
6218 {
6219   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0,0));
6220   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6221   ret->loadGlobals(fid);
6222   return ret.retn();
6223 }
6224
6225 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6226 {
6227   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6228   return New(fid,fieldName,loadAll);
6229 }
6230
6231 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6232 {
6233   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
6234   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6235   ret->loadGlobals(fid);
6236   return ret.retn();
6237 }
6238
6239 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6240 {
6241   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6242   return New(fid,fieldName,iteration,order,loadAll);
6243 }
6244
6245 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6246 {
6247   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,0));
6248   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6249   ret->loadGlobals(fid);
6250   return ret.retn();
6251 }
6252
6253 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6254 {
6255   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6256   return NewAdv(fid,fieldName,iteration,order,loadAll,entities);
6257 }
6258
6259 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6260 {
6261   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,entities));
6262   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6263   ret->loadGlobals(fid);
6264   return ret.retn();
6265 }
6266
6267 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6268 {
6269   med_field_type typcha;
6270   std::vector<std::string> infos;
6271   std::string dtunit,meshName;
6272   int iii(-1);
6273   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName));
6274   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6275   switch(typcha)
6276   {
6277     case MED_FLOAT64:
6278       {
6279         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6280         break;
6281       }
6282     case MED_INT32:
6283       {
6284         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6285         break;
6286       }
6287     case MED_FLOAT32:
6288       {
6289         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6290         break;
6291       }
6292     case MED_INT:
6293       {
6294         if(sizeof(med_int)==sizeof(int))
6295           {
6296             ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6297             break;
6298           }
6299       }
6300     default:
6301       {
6302         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, MED_FLOAT32] !";
6303         throw INTERP_KERNEL::Exception(oss.str());
6304       }
6305   }
6306   ret->setDtUnit(dtunit.c_str());
6307   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6308   //
6309   bool found=false;
6310   std::vector< std::pair<int,int> > dtits(nbOfStep2);
6311   for(int i=0;i<nbOfStep2 && !found;i++)
6312     {
6313       med_int numdt,numit;
6314       med_float dt;
6315       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
6316       if(numdt==iteration && numit==order)
6317         {
6318           found=true;
6319           ret->_csit=i+1;
6320         }
6321       else
6322         dtits[i]=std::pair<int,int>(numdt,numit);
6323     }
6324   if(!found)
6325     {
6326       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
6327       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
6328         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
6329       throw INTERP_KERNEL::Exception(oss.str());
6330     }
6331   if(loadAll)
6332     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6333   else
6334     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6335   return ret.retn();
6336 }
6337
6338 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6339 try:MEDFileFieldGlobsReal(fid)
6340 {
6341   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms,entities);
6342   loadGlobals(fid);
6343 }
6344 catch(INTERP_KERNEL::Exception& e)
6345 {
6346     throw e;
6347 }
6348
6349 /*!
6350  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6351  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6352  *
6353  * \warning this is a shallow copy constructor
6354  */
6355 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
6356 {
6357   if(!shallowCopyOfContent)
6358     {
6359       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
6360       otherPtr->incrRef();
6361       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
6362     }
6363   else
6364     {
6365       _content=other.shallowCpy();
6366     }
6367 }
6368
6369 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, std::string& meshName)
6370 {
6371   if(checkFieldId)
6372     {
6373       int nbFields=MEDnField(fid);
6374       if(fieldIdCFormat>=nbFields)
6375         {
6376           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
6377           throw INTERP_KERNEL::Exception(oss.str());
6378         }
6379     }
6380   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
6381   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6382   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6383   INTERP_KERNEL::AutoPtr<char> dtunit(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
6384   INTERP_KERNEL::AutoPtr<char> nomcha(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6385   INTERP_KERNEL::AutoPtr<char> nomMaa(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6386   med_bool localMesh;
6387   int nbOfStep;
6388   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
6389   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
6390   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
6391   meshName=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
6392   infos.clear(); infos.resize(ncomp);
6393   for(int j=0;j<ncomp;j++)
6394     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
6395   return nbOfStep;
6396 }
6397
6398 /*!
6399  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
6400  * 
6401  * \param [out]
6402  * \return in case of success the number of time steps available for the field with name \a fieldName.
6403  */
6404 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut, std::string& meshName)
6405 {
6406   int nbFields=MEDnField(fid);
6407   bool found=false;
6408   std::vector<std::string> fns(nbFields);
6409   int nbOfStep2(-1);
6410   for(int i=0;i<nbFields && !found;i++)
6411     {
6412       std::string tmp,tmp2;
6413       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut,tmp2);
6414       fns[i]=tmp;
6415       found=(tmp==fieldName);
6416       if(found)
6417         {
6418           posCFormat=i;
6419           meshName=tmp2;
6420         }
6421     }
6422   if(!found)
6423     {
6424       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
6425       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
6426         oss << "\"" << *it << "\" ";
6427       throw INTERP_KERNEL::Exception(oss.str());
6428     }
6429   return nbOfStep2;
6430 }
6431
6432 /*!
6433  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6434  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6435  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6436  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6437  * to keep a valid instance.
6438  * 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.
6439  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
6440  * 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.
6441  *
6442  * \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.
6443  * \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.
6444  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6445  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6446  * \param [in] newLocName is the new localization name.
6447  * \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.
6448  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
6449  */
6450 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
6451 {
6452   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6453   std::string oldPflName=disc->getProfile();
6454   std::vector<std::string> vv=getPflsReallyUsedMulti();
6455   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
6456   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
6457     {
6458       disc->setProfile(newPflName);
6459       DataArrayInt *pfl=getProfile(oldPflName.c_str());
6460       pfl->setName(newPflName);
6461     }
6462   else
6463     {
6464       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
6465       throw INTERP_KERNEL::Exception(oss.str());
6466     }
6467 }
6468
6469 /*!
6470  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6471  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6472  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6473  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6474  * to keep a valid instance.
6475  * 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.
6476  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
6477  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
6478  * 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.
6479  *
6480  * \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.
6481  * \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.
6482  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6483  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6484  * \param [in] newLocName is the new localization name.
6485  * \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.
6486  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
6487  */
6488 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
6489 {
6490   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6491   std::string oldLocName=disc->getLocalization();
6492   std::vector<std::string> vv=getLocsReallyUsedMulti();
6493   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
6494   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
6495     {
6496       disc->setLocalization(newLocName);
6497       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
6498       loc.setName(newLocName);
6499     }
6500   else
6501     {
6502       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
6503       throw INTERP_KERNEL::Exception(oss.str());
6504     }
6505 }
6506
6507 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
6508 {
6509   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6510   if(!ret)
6511     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
6512   return ret;
6513 }
6514
6515 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
6516 {
6517   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6518   if(!ret)
6519     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
6520   return ret;
6521 }
6522
6523 /*!
6524  * This method alloc the arrays and load potentially huge arrays contained in this field.
6525  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
6526  * This method can be also called to refresh or reinit values from a file.
6527  * 
6528  * \throw If the fileName is not set or points to a non readable MED file.
6529  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6530  */
6531 void MEDFileAnyTypeField1TS::loadArrays()
6532 {
6533   if(getFileName().empty())
6534     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
6535   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6536   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
6537 }
6538
6539 /*!
6540  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
6541  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
6542  * this method does not throw if \a this does not come from file read.
6543  * 
6544  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
6545  */
6546 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
6547 {
6548   if(!getFileName().empty())
6549     {
6550       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6551       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
6552     }
6553 }
6554
6555 /*!
6556  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
6557  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
6558  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
6559  * 
6560  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
6561  */
6562 void MEDFileAnyTypeField1TS::unloadArrays()
6563 {
6564   contentNotNullBase()->unloadArrays();
6565 }
6566
6567 /*!
6568  * 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.
6569  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
6570  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
6571  * 
6572  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6573  */
6574 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
6575 {
6576   if(!getFileName().empty())
6577     contentNotNullBase()->unloadArrays();
6578 }
6579
6580 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6581 {
6582   int nbComp(getNumberOfComponents());
6583   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6584   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6585   for(int i=0;i<nbComp;i++)
6586     {
6587       std::string info=getInfo()[i];
6588       std::string c,u;
6589       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6590       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6591       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6592     }
6593   if(getName().empty())
6594     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6595   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6596   writeGlobals(fid,*this);
6597   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6598 }
6599
6600 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6601 {
6602   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6603 }
6604
6605 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6606 {
6607   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6608   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6609   return ret;
6610 }
6611
6612 /*!
6613  * Returns a string describing \a this field. This string is outputted 
6614  * by \c print Python command.
6615  */
6616 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6617 {
6618   std::ostringstream oss;
6619   contentNotNullBase()->simpleRepr(0,oss,-1);
6620   simpleReprGlobs(oss);
6621   return oss.str();
6622 }
6623
6624 /*!
6625  * This method returns all profiles whose name is non empty used.
6626  * \b WARNING If profile is used several times it will be reported \b only \b once.
6627  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6628  */
6629 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6630 {
6631   return contentNotNullBase()->getPflsReallyUsed2();
6632 }
6633
6634 /*!
6635  * This method returns all localizations whose name is non empty used.
6636  * \b WARNING If localization is used several times it will be reported \b only \b once.
6637  */
6638 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6639 {
6640   return contentNotNullBase()->getLocsReallyUsed2();
6641 }
6642
6643 /*!
6644  * This method returns all profiles whose name is non empty used.
6645  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6646  */
6647 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6648 {
6649   return contentNotNullBase()->getPflsReallyUsedMulti2();
6650 }
6651
6652 /*!
6653  * This method returns all localizations whose name is non empty used.
6654  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6655  */
6656 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6657 {
6658   return contentNotNullBase()->getLocsReallyUsedMulti2();
6659 }
6660
6661 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6662 {
6663   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6664 }
6665
6666 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6667 {
6668   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6669 }
6670
6671 int MEDFileAnyTypeField1TS::getDimension() const
6672 {
6673   return contentNotNullBase()->getDimension();
6674 }
6675
6676 int MEDFileAnyTypeField1TS::getIteration() const
6677 {
6678   return contentNotNullBase()->getIteration();
6679 }
6680
6681 int MEDFileAnyTypeField1TS::getOrder() const
6682 {
6683   return contentNotNullBase()->getOrder();
6684 }
6685
6686 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6687 {
6688   return contentNotNullBase()->getTime(iteration,order);
6689 }
6690
6691 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6692 {
6693   contentNotNullBase()->setTime(iteration,order,val);
6694 }
6695
6696 std::string MEDFileAnyTypeField1TS::getName() const
6697 {
6698   return contentNotNullBase()->getName();
6699 }
6700
6701 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6702 {
6703   contentNotNullBase()->setName(name);
6704 }
6705
6706 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6707 {
6708   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6709 }
6710
6711 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6712 {
6713   return contentNotNullBase()->getDtUnit();
6714 }
6715
6716 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6717 {
6718   contentNotNullBase()->setDtUnit(dtUnit);
6719 }
6720
6721 std::string MEDFileAnyTypeField1TS::getMeshName() const
6722 {
6723   return contentNotNullBase()->getMeshName();
6724 }
6725
6726 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6727 {
6728   contentNotNullBase()->setMeshName(newMeshName);
6729 }
6730
6731 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6732 {
6733   return contentNotNullBase()->changeMeshNames(modifTab);
6734 }
6735
6736 int MEDFileAnyTypeField1TS::getMeshIteration() const
6737 {
6738   return contentNotNullBase()->getMeshIteration();
6739 }
6740
6741 int MEDFileAnyTypeField1TS::getMeshOrder() const
6742 {
6743   return contentNotNullBase()->getMeshOrder();
6744 }
6745
6746 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6747 {
6748   return contentNotNullBase()->getNumberOfComponents();
6749 }
6750
6751 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6752 {
6753   return contentNotNullBase()->isDealingTS(iteration,order);
6754 }
6755
6756 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6757 {
6758   return contentNotNullBase()->getDtIt();
6759 }
6760
6761 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6762 {
6763   contentNotNullBase()->fillIteration(p);
6764 }
6765
6766 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6767 {
6768   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6769 }
6770
6771 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6772 {
6773   contentNotNullBase()->setInfo(infos);
6774 }
6775
6776 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6777 {
6778   return contentNotNullBase()->getInfo();
6779 }
6780 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6781 {
6782   return contentNotNullBase()->getInfo();
6783 }
6784
6785 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6786 {
6787   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6788 }
6789
6790 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6791 {
6792   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6793 }
6794
6795 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6796 {
6797   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6798 }
6799
6800 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6801 {
6802   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6803 }
6804
6805 void MEDFileAnyTypeField1TS::convertMedBallIntoClassic()
6806 {
6807   return contentNotNullBase()->convertMedBallIntoClassic();
6808 }
6809
6810 void MEDFileAnyTypeField1TS::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
6811 {
6812   return contentNotNullBase()->makeReduction(ct,tof,pfl);
6813 }
6814
6815 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6816 {
6817   return contentNotNullBase()->getTypesOfFieldAvailable();
6818 }
6819
6820 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,
6821                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6822 {
6823   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6824 }
6825
6826 /*!
6827  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6828  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6829  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6830  */
6831 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6832 {
6833   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6834   if(!content)
6835     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6836   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6837   std::size_t sz(contentsSplit.size());
6838   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6839   for(std::size_t i=0;i<sz;i++)
6840     {
6841       ret[i]=shallowCpy();
6842       ret[i]->_content=contentsSplit[i];
6843     }
6844   return ret;
6845 }
6846
6847 /*!
6848  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6849  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6850  */
6851 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6852 {
6853   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6854   if(!content)
6855     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6856   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6857   std::size_t sz(contentsSplit.size());
6858   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6859   for(std::size_t i=0;i<sz;i++)
6860     {
6861       ret[i]=shallowCpy();
6862       ret[i]->_content=contentsSplit[i];
6863     }
6864   return ret;
6865 }
6866
6867 /*!
6868  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6869  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6870  */
6871 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6872 {
6873   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6874   if(!content)
6875     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6876   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6877   std::size_t sz(contentsSplit.size());
6878   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6879   for(std::size_t i=0;i<sz;i++)
6880     {
6881       ret[i]=shallowCpy();
6882       ret[i]->_content=contentsSplit[i];
6883     }
6884   return ret;
6885 }
6886
6887 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6888 {
6889   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6890   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6891     ret->_content=_content->deepCopy();
6892   ret->deepCpyGlobs(*this);
6893   return ret.retn();
6894 }
6895
6896 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6897 {
6898   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
6899   return copyTinyInfoFrom(field->timeDiscrSafe(),ft,arr);
6900 }
6901
6902 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
6903 {
6904   return contentNotNullBase()->copyTinyInfoFrom(th,field,arr);
6905 }
6906
6907 //= MEDFileField1TS
6908
6909 /*!
6910  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6911  * following the given input policy.
6912  *
6913  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6914  *                            By default (true) the globals are deeply copied.
6915  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6916  */
6917 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6918 {
6919   MCAuto<MEDFileIntField1TS> ret;
6920   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6921   if(content)
6922     {
6923       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6924       if(!contc)
6925         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6926       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6927       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6928     }
6929   else
6930     ret=MEDFileIntField1TS::New();
6931   if(isDeepCpyGlobs)
6932     ret->deepCpyGlobs(*this);
6933   else
6934     ret->shallowCpyGlobs(*this);
6935   return ret.retn();
6936 }
6937
6938 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6939 try:MEDFileTemplateField1TS<double>(fid,loadAll,ms)
6940 {
6941 }
6942 catch(INTERP_KERNEL::Exception& e)
6943 { throw e; }
6944
6945 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6946 try:MEDFileTemplateField1TS<double>(fid,fieldName,loadAll,ms)
6947 {
6948 }
6949 catch(INTERP_KERNEL::Exception& e)
6950 { throw e; }
6951
6952 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6953 try:MEDFileTemplateField1TS<double>(fid,fieldName,iteration,order,loadAll,ms)
6954 {
6955 }
6956 catch(INTERP_KERNEL::Exception& e)
6957 { throw e; }
6958
6959 /*!
6960  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6961  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6962  *
6963  * \warning this is a shallow copy constructor
6964  */
6965 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6966 try:MEDFileTemplateField1TS<double>(other,shallowCopyOfContent)
6967 {
6968 }
6969 catch(INTERP_KERNEL::Exception& e)
6970 { throw e; }
6971
6972 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
6973 {
6974   return new MEDFileField1TS(*this);
6975 }
6976
6977 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6978                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6979 {
6980   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6981 }
6982
6983 //= MEDFileIntField1TS
6984
6985 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
6986 {
6987   if(!f)
6988     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
6989   int t1,t2;
6990   double t0(f->getTime(t1,t2));
6991   std::string tu(f->getTimeUnit());
6992   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
6993   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
6994   ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
6995   return ret;
6996 }
6997
6998 //= MEDFileFloatField1TS
6999
7000 //= MEDFileFloatField1TS
7001
7002 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7003
7004 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7005 {
7006 }
7007
7008 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileFieldNameScope(fieldName,meshName)
7009 {
7010 }
7011
7012 /*!
7013  * \param [in] fieldId field id in C mode
7014  */
7015 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7016 {
7017   med_field_type typcha;
7018   std::string dtunitOut,meshName;
7019   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut,meshName));
7020   setMeshName(meshName);
7021   setDtUnit(dtunitOut.c_str());
7022   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7023 }
7024
7025 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7026 try:MEDFileFieldNameScope(fieldName,meshName),_infos(infos)
7027 {
7028   setDtUnit(dtunit.c_str());
7029   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7030 }
7031 catch(INTERP_KERNEL::Exception& e)
7032 {
7033     throw e;
7034 }
7035
7036 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7037 {
7038   std::size_t ret(_mesh_name.capacity()+_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7039   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7040     ret+=(*it).capacity();
7041   return ret;
7042 }
7043
7044 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7045 {
7046   std::vector<const BigMemoryObject *> ret;
7047   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7048     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7049   return ret;
7050 }
7051
7052 /*!
7053  * 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
7054  * NULL.
7055  */
7056 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7057 {
7058   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7059   ret->setInfo(_infos);
7060   int sz=(int)_time_steps.size();
7061   for(const int *id=startIds;id!=endIds;id++)
7062     {
7063       if(*id>=0 && *id<sz)
7064         {
7065           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7066           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7067           if(tse)
7068             {
7069               tse->incrRef();
7070               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7071             }
7072           ret->pushBackTimeStep(tse2);
7073         }
7074       else
7075         {
7076           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7077           oss << " ! Should be in [0," << sz << ") !";
7078           throw INTERP_KERNEL::Exception(oss.str());
7079         }
7080     }
7081   if(ret->getNumberOfTS()>0)
7082     ret->synchronizeNameScope();
7083   ret->copyNameScope(*this);
7084   return ret.retn();
7085 }
7086
7087 /*!
7088  * 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
7089  * NULL.
7090  */
7091 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7092 {
7093   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7094   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7095   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7096   ret->setInfo(_infos);
7097   int sz=(int)_time_steps.size();
7098   int j=bg;
7099   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7100     {
7101       if(j>=0 && j<sz)
7102         {
7103           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7104           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7105           if(tse)
7106             {
7107               tse->incrRef();
7108               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7109             }
7110           ret->pushBackTimeStep(tse2);
7111         }
7112       else
7113         {
7114           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7115           oss << " ! Should be in [0," << sz << ") !";
7116           throw INTERP_KERNEL::Exception(oss.str());
7117         }
7118     }
7119   if(ret->getNumberOfTS()>0)
7120     ret->synchronizeNameScope();
7121   ret->copyNameScope(*this);
7122   return ret.retn();
7123 }
7124
7125 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7126 {
7127   int id=0;
7128   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7129   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7130     {
7131       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7132       if(!cur)
7133         continue;
7134       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7135       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7136         ids->pushBackSilent(id);
7137     }
7138   return buildFromTimeStepIds(ids->begin(),ids->end());
7139 }
7140
7141 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7142 {
7143   int id=0;
7144   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7145   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7146     {
7147       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7148       if(!cur)
7149         continue;
7150       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7151       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7152         ids->pushBackSilent(id);
7153     }
7154   return buildFromTimeStepIds(ids->begin(),ids->end());
7155 }
7156
7157 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
7158 {
7159   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7160     if((*it).isNotNull())
7161       if((*it)->presenceOfStructureElements())
7162         return true;
7163   return false;
7164 }
7165
7166 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
7167 {
7168   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7169     if((*it).isNotNull())
7170       if(!(*it)->onlyStructureElements())
7171         return false;
7172   return true;
7173 }
7174
7175 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
7176 {
7177   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7178   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7179     if((*it).isNotNull())
7180       {
7181         if((*it)->presenceOfStructureElements())
7182           {
7183             if(!(*it)->onlyStructureElements())
7184               {
7185                 (*it)->killStructureElements();
7186                 ret.push_back(*it);
7187               }
7188           }
7189         else
7190           {
7191             ret.push_back(*it);
7192           }
7193       }
7194   _time_steps=ret;
7195 }
7196
7197 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
7198 {
7199   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7200   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7201     if((*it).isNotNull())
7202       {
7203         if((*it)->presenceOfStructureElements())
7204           {
7205             if(!(*it)->onlyStructureElements())
7206               (*it)->keepOnlyStructureElements();
7207             ret.push_back(*it);
7208           }
7209       }
7210   _time_steps=ret;
7211 }
7212
7213 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
7214 {
7215   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7216   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7217     if((*it).isNotNull())
7218       (*it)->keepOnlyOnSE(seName);
7219 }
7220
7221 void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
7222 {
7223   std::vector< std::pair<std::string,std::string> > ps2;
7224   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7225     if((*it).isNotNull())
7226       {
7227         (*it)->getMeshSENames(ps2);
7228         break;
7229       }
7230   if(ps2.empty())
7231     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
7232   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7233     if((*it).isNotNull())
7234       {
7235         std::vector< std::pair<std::string,std::string> > ps3;
7236         (*it)->getMeshSENames(ps3);
7237         if(ps2!=ps3)
7238           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
7239       }
7240   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
7241     {
7242       std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
7243       if(it2==ps.end())
7244         ps.push_back(*it);
7245     }
7246 }
7247
7248 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7249 {
7250   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7251     {
7252       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7253       if(!cur)
7254         continue;
7255       if(cur->presenceOfMultiDiscPerGeoType())
7256         return true;
7257     }
7258   return false;
7259 }
7260
7261 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7262 {
7263   return _infos;
7264 }
7265
7266 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7267 {
7268   _infos=info;
7269 }
7270
7271 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7272 {
7273   int ret=0;
7274   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7275     {
7276       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7277       if(pt->isDealingTS(iteration,order))
7278         return ret;
7279     }
7280   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7281   std::vector< std::pair<int,int> > vp=getIterations();
7282   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7283     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7284   throw INTERP_KERNEL::Exception(oss.str());
7285 }
7286
7287 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7288 {
7289   return *_time_steps[getTimeStepPos(iteration,order)];
7290 }
7291
7292 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7293 {
7294   return *_time_steps[getTimeStepPos(iteration,order)];
7295 }
7296
7297 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7298 {
7299   bool ret(false);
7300   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
7301     {
7302       if((*it).first==getMeshName())
7303         {
7304           setMeshName((*it).second);
7305           ret=true;
7306         }
7307     }
7308   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7309     {
7310       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7311       if(cur)
7312         ret=cur->changeMeshNames(modifTab) || ret;
7313     }
7314   return ret;
7315 }
7316
7317 /*!
7318  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7319  */
7320 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7321 {
7322   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7323 }
7324
7325 /*!
7326  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7327  */
7328 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7329 {
7330   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7331 }
7332
7333 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7334                                                                        MEDFileFieldGlobsReal& glob)
7335 {
7336   bool ret=false;
7337   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7338     {
7339       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7340       if(f1ts)
7341         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7342     }
7343   return ret;
7344 }
7345
7346 void MEDFileAnyTypeFieldMultiTSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
7347 {
7348   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7349     if((*it).isNotNull())
7350       {
7351         visitor.newTimeStepEntry(*it);
7352         (*it)->accept(visitor);
7353         visitor.endTimeStepEntry(*it);
7354       }
7355 }
7356
7357 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7358 {
7359   std::string startLine(bkOffset,' ');
7360   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7361   if(fmtsId>=0)
7362     oss << " (" << fmtsId << ")";
7363   oss << " has the following name: \"" << _name << "\"." << std::endl;
7364   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7365   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7366     {
7367       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7368     }
7369   int i=0;
7370   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7371     {
7372       std::string chapter(17,'0'+i);
7373       oss << startLine << chapter << std::endl;
7374       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7375       if(cur)
7376         cur->simpleRepr(bkOffset+2,oss,i);
7377       else
7378         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7379       oss << startLine << chapter << std::endl;
7380     }
7381 }
7382
7383 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7384 {
7385   std::size_t sz=_time_steps.size();
7386   std::vector< std::pair<int,int> > ret(sz);
7387   ret1.resize(sz);
7388   for(std::size_t i=0;i<sz;i++)
7389     {
7390       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7391       if(f1ts)
7392         {
7393           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7394         }
7395       else
7396         {
7397           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7398           throw INTERP_KERNEL::Exception(oss.str());
7399         }
7400     }
7401   return ret;
7402 }
7403
7404 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7405 {
7406   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7407   if(!tse2)
7408     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7409   checkCoherencyOfType(tse2);
7410   if(_time_steps.empty())
7411     {
7412       setName(tse2->getName());
7413       setMeshName(tse2->getMeshName());
7414       setInfo(tse2->getInfo());
7415     }
7416   checkThatComponentsMatch(tse2->getInfo());
7417   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7418     setDtUnit(tse->getDtUnit());
7419   _time_steps.push_back(tse);
7420 }
7421
7422 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7423 {
7424   std::size_t nbOfCompo=_infos.size();
7425   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7426     {
7427       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7428       if(cur)
7429         {
7430           if((cur->getInfo()).size()!=nbOfCompo)
7431             {
7432               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7433               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7434               throw INTERP_KERNEL::Exception(oss.str());
7435             }
7436           cur->copyNameScope(*this);
7437         }
7438     }
7439 }
7440
7441 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7442 {
7443   _time_steps.resize(nbPdt);
7444   for(int i=0;i<nbPdt;i++)
7445     {
7446       std::vector< std::pair<int,int> > ts;
7447       med_int numdt=0,numo=0;
7448       med_float dt=0.0;
7449       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7450       switch(fieldTyp)
7451       {
7452         case MED_FLOAT64:
7453           {
7454             _time_steps[i]=MEDFileField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7455             break;
7456           }
7457         case MED_INT32:
7458           {
7459             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7460             break;
7461           }
7462         case MED_FLOAT32:
7463           {
7464             _time_steps[i]=MEDFileFloatField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7465             break;
7466           }
7467         case MED_INT:
7468           {
7469             if(sizeof(med_int)==sizeof(int))
7470               {
7471                 _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7472                 break;
7473               }
7474           }
7475         default:
7476           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32, FLOAT32 !");
7477       }
7478       if(loadAll)
7479         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7480       else
7481         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7482       synchronizeNameScope();
7483     }
7484 }
7485
7486 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7487 {
7488   if(_time_steps.empty())
7489     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7490   checkThatNbOfCompoOfTSMatchThis();
7491   std::vector<std::string> infos(getInfo());
7492   int nbComp=infos.size();
7493   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7494   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7495   for(int i=0;i<nbComp;i++)
7496     {
7497       std::string info=infos[i];
7498       std::string c,u;
7499       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7500       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7501       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7502     }
7503   if(_name.empty())
7504     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7505   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7506   int nbOfTS=_time_steps.size();
7507   for(int i=0;i<nbOfTS;i++)
7508     _time_steps[i]->writeLL(fid,opts,*this);
7509 }
7510
7511 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7512 {
7513   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7514     {
7515       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7516       if(elt)
7517         elt->loadBigArraysRecursively(fid,nasc);
7518     }
7519 }
7520
7521 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7522 {
7523   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7524     {
7525       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7526       if(elt)
7527         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7528     }
7529 }
7530
7531 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7532 {
7533   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7534     {
7535       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7536       if(elt)
7537         elt->unloadArrays();
7538     }
7539 }
7540
7541 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7542 {
7543   return _time_steps.size();
7544 }
7545
7546 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7547 {
7548   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7549   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7550     {
7551       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7552       if(tmp)
7553         newTS.push_back(*it);
7554     }
7555   _time_steps=newTS;
7556 }
7557
7558 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7559 {
7560   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7561   int maxId=(int)_time_steps.size();
7562   int ii=0;
7563   std::set<int> idsToDel;
7564   for(const int *id=startIds;id!=endIds;id++,ii++)
7565     {
7566       if(*id>=0 && *id<maxId)
7567         {
7568           idsToDel.insert(*id);
7569         }
7570       else
7571         {
7572           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7573           throw INTERP_KERNEL::Exception(oss.str());
7574         }
7575     }
7576   for(int iii=0;iii<maxId;iii++)
7577     if(idsToDel.find(iii)==idsToDel.end())
7578       newTS.push_back(_time_steps[iii]);
7579   _time_steps=newTS;
7580 }
7581
7582 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7583 {
7584   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7585   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7586   if(nbOfEntriesToKill==0)
7587     return ;
7588   std::size_t sz=_time_steps.size();
7589   std::vector<bool> b(sz,true);
7590   int j=bg;
7591   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7592     b[j]=false;
7593   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7594   for(std::size_t i=0;i<sz;i++)
7595     if(b[i])
7596       newTS.push_back(_time_steps[i]);
7597   _time_steps=newTS;
7598 }
7599
7600 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7601 {
7602   int ret=0;
7603   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7604   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7605     {
7606       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7607       if(tmp)
7608         {
7609           int it2,ord;
7610           tmp->getTime(it2,ord);
7611           if(it2==iteration && order==ord)
7612             return ret;
7613           else
7614             oss << "(" << it2 << ","  << ord << "), ";
7615         }
7616     }
7617   throw INTERP_KERNEL::Exception(oss.str());
7618 }
7619
7620 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7621 {
7622   int ret=0;
7623   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7624   oss.precision(15);
7625   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7626     {
7627       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7628       if(tmp)
7629         {
7630           int it2,ord;
7631           double ti=tmp->getTime(it2,ord);
7632           if(fabs(time-ti)<eps)
7633             return ret;
7634           else
7635             oss << ti << ", ";
7636         }
7637     }
7638   throw INTERP_KERNEL::Exception(oss.str());
7639 }
7640
7641 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7642 {
7643   int lgth=_time_steps.size();
7644   std::vector< std::pair<int,int> > ret(lgth);
7645   for(int i=0;i<lgth;i++)
7646     _time_steps[i]->fillIteration(ret[i]);
7647   return ret;
7648 }
7649
7650 /*!
7651  * 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'
7652  * This method returns two things.
7653  * - The absolute dimension of 'this' in first parameter. 
7654  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7655  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7656  *
7657  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7658  * Only these 3 discretizations will be taken into account here.
7659  *
7660  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7661  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7662  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7663  *
7664  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7665  * 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'.
7666  * 
7667  * Let's consider the typical following case :
7668  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7669  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7670  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7671  *   TETRA4 and SEG2
7672  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7673  *
7674  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7675  * 
7676  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7677  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7678  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7679  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7680  */
7681 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7682 {
7683   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7684 }
7685
7686 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7687 {
7688   if(pos<0 || pos>=(int)_time_steps.size())
7689     {
7690       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7691       throw INTERP_KERNEL::Exception(oss.str());
7692     }
7693   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7694   if(item==0)
7695     {
7696       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7697       oss << "\nTry to use following method eraseEmptyTS !";
7698       throw INTERP_KERNEL::Exception(oss.str());
7699     }
7700   return item;
7701 }
7702
7703 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7704 {
7705   if(pos<0 || pos>=(int)_time_steps.size())
7706     {
7707       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7708       throw INTERP_KERNEL::Exception(oss.str());
7709     }
7710   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7711   if(item==0)
7712     {
7713       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7714       oss << "\nTry to use following method eraseEmptyTS !";
7715       throw INTERP_KERNEL::Exception(oss.str());
7716     }
7717   return item;
7718 }
7719
7720 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7721 {
7722   std::vector<std::string> ret;
7723   std::set<std::string> ret2;
7724   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7725     {
7726       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7727       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7728         if(ret2.find(*it2)==ret2.end())
7729           {
7730             ret.push_back(*it2);
7731             ret2.insert(*it2);
7732           }
7733     }
7734   return ret;
7735 }
7736
7737 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7738 {
7739   std::vector<std::string> ret;
7740   std::set<std::string> ret2;
7741   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7742     {
7743       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7744       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7745         if(ret2.find(*it2)==ret2.end())
7746           {
7747             ret.push_back(*it2);
7748             ret2.insert(*it2);
7749           }
7750     }
7751   return ret;
7752 }
7753
7754 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7755 {
7756   std::vector<std::string> ret;
7757   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7758     {
7759       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7760       ret.insert(ret.end(),tmp.begin(),tmp.end());
7761     }
7762   return ret;
7763 }
7764
7765 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7766 {
7767   std::vector<std::string> ret;
7768   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7769     {
7770       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7771       ret.insert(ret.end(),tmp.begin(),tmp.end());
7772     }
7773   return ret;
7774 }
7775
7776 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7777 {
7778   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7779     (*it)->changePflsRefsNamesGen2(mapOfModif);
7780 }
7781
7782 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7783 {
7784   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7785     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7786 }
7787
7788 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7789 {
7790   int lgth=_time_steps.size();
7791   std::vector< std::vector<TypeOfField> > ret(lgth);
7792   for(int i=0;i<lgth;i++)
7793     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7794   return ret;
7795 }
7796
7797 /*!
7798  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7799  */
7800 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
7801 {
7802   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7803 }
7804
7805 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7806 {
7807   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7808   std::size_t i=0;
7809   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7810     {
7811       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7812         ret->_time_steps[i]=(*it)->deepCopy();
7813     }
7814   return ret.retn();
7815 }
7816
7817 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7818 {
7819   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7820   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7821   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7822   for(std::size_t i=0;i<sz;i++)
7823     {
7824       ret[i]=shallowCpy();
7825       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7826     }
7827   for(std::size_t i=0;i<sz2;i++)
7828     {
7829       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7830       if(ret1.size()!=sz)
7831         {
7832           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7833           throw INTERP_KERNEL::Exception(oss.str());
7834         }
7835       ts[i]=ret1;
7836     }
7837   for(std::size_t i=0;i<sz;i++)
7838     for(std::size_t j=0;j<sz2;j++)
7839       ret[i]->_time_steps[j]=ts[j][i];
7840   return ret;
7841 }
7842
7843 /*!
7844  * This method splits into discretization each time steps in \a this.
7845  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7846  */
7847 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7848 {
7849   std::size_t sz(_time_steps.size());
7850   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7851   for(std::size_t i=0;i<sz;i++)
7852     {
7853       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7854       if(!timeStep)
7855         {
7856           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7857           throw INTERP_KERNEL::Exception(oss.str());
7858         }
7859       items[i]=timeStep->splitDiscretizations();  
7860     }
7861   //
7862   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7863   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7864   std::vector< TypeOfField > types;
7865   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7866     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7867       {
7868         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7869         if(ts.size()!=1)
7870           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7871         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7872         if(it2==types.end())
7873           types.push_back(ts[0]);
7874       }
7875   ret.resize(types.size()); ret2.resize(types.size());
7876   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7877     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7878       {
7879         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7880         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7881         ret2[pos].push_back(*it1);
7882       }
7883   for(std::size_t i=0;i<types.size();i++)
7884     {
7885       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7886       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7887         elt->pushBackTimeStep(*it1);//also updates infos in elt
7888       ret[i]=elt;
7889       elt->MEDFileFieldNameScope::operator=(*this);
7890     }
7891   return ret;
7892 }
7893
7894 /*!
7895  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7896  */
7897 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7898 {
7899   std::size_t sz(_time_steps.size());
7900   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7901   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7902   for(std::size_t i=0;i<sz;i++)
7903     {
7904       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7905       if(!timeStep)
7906         {
7907           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7908           throw INTERP_KERNEL::Exception(oss.str());
7909         }
7910       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7911       if(szOut==std::numeric_limits<std::size_t>::max())
7912         szOut=items[i].size();
7913       else
7914         if(items[i].size()!=szOut)
7915           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7916     }
7917   if(szOut==std::numeric_limits<std::size_t>::max())
7918     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7919   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7920   for(std::size_t i=0;i<szOut;i++)
7921     {
7922       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7923       for(std::size_t j=0;j<sz;j++)
7924         elt->pushBackTimeStep(items[j][i]);
7925       ret[i]=elt;
7926       elt->MEDFileFieldNameScope::operator=(*this);
7927     }
7928   return ret;
7929 }
7930
7931 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7932 {
7933   setName(field->getName());
7934   if(field->getMesh())
7935     setMeshName(field->getMesh()->getName());
7936   if(_name.empty())
7937     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7938   if(!arr)
7939     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7940   _infos=arr->getInfoOnComponents();
7941 }
7942
7943 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7944 {
7945   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7946   if(_name!=field->getName())
7947     {
7948       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7949       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7950       throw INTERP_KERNEL::Exception(oss.str());
7951     }
7952   if(!arr)
7953     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7954   checkThatComponentsMatch(arr->getInfoOnComponents());
7955 }
7956
7957 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7958 {
7959   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7960   if(getInfo().size()!=compos.size())
7961     {
7962       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7963       oss << " number of components of element to append (" << compos.size() << ") !";
7964       throw INTERP_KERNEL::Exception(oss.str());
7965     }
7966   if(_infos!=compos)
7967     {
7968       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7969       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7970       oss << " But compo in input fields are : ";
7971       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7972       oss << " !";
7973       throw INTERP_KERNEL::Exception(oss.str());
7974     }
7975 }
7976
7977 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7978 {
7979   std::size_t sz=_infos.size();
7980   int j=0;
7981   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7982     {
7983       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7984       if(elt)
7985         if(elt->getInfo().size()!=sz)
7986           {
7987             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7988             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7989             throw INTERP_KERNEL::Exception(oss.str());
7990           }
7991     }
7992 }
7993
7994 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7995 {
7996   if(!field)
7997     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7998   if(!_time_steps.empty())
7999     checkCoherencyOfTinyInfo(field,arr);
8000   MEDFileAnyTypeField1TSWithoutSDA *objC(createNew1TSWithoutSDAEmptyInstance());
8001   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8002   {
8003     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
8004     objC->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,arr,glob,*this);
8005   }
8006   copyTinyInfoFrom(field,arr);
8007   _time_steps.push_back(obj);
8008 }
8009
8010 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8011 {
8012   if(!field)
8013     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8014   if(!_time_steps.empty())
8015     checkCoherencyOfTinyInfo(field,arr);
8016   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8017   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8018   {
8019     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
8020     objC->setFieldProfile(field->timeDiscrSafe(),ft,arr,mesh,meshDimRelToMax,profile,glob,*this);
8021   }
8022   copyTinyInfoFrom(field,arr);
8023   setMeshName(objC->getMeshName());
8024   _time_steps.push_back(obj);
8025 }
8026
8027 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8028 {
8029   int sz=(int)_time_steps.size();
8030   if(i<0 || i>=sz)
8031     {
8032       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8033       throw INTERP_KERNEL::Exception(oss.str());
8034     }
8035   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8036   if(tsPtr)
8037     {
8038       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8039         {
8040           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8041           throw INTERP_KERNEL::Exception(oss.str());
8042         }
8043     }
8044   _time_steps[i]=ts;
8045 }
8046
8047 //= MEDFileFieldMultiTSWithoutSDA
8048
8049 /*!
8050  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8051  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8052  */
8053 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
8054 {
8055   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8056   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8057   if(!myF1TSC)
8058     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8059   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8060 }
8061
8062 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8063 {
8064   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8065   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8066   int i=0;
8067   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8068     {
8069       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8070       if(eltToConv)
8071         {
8072           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8073           if(!eltToConvC)
8074             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8075           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8076           ret->setIteration(i,elt);
8077         }
8078     }
8079   return ret.retn();
8080 }
8081
8082 //= MEDFileAnyTypeFieldMultiTS
8083
8084 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8085 {
8086 }
8087
8088 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8089 try:MEDFileFieldGlobsReal(fid)
8090 {
8091   _content=BuildContentFrom(fid,loadAll,ms);
8092   loadGlobals(fid);
8093 }
8094 catch(INTERP_KERNEL::Exception& e)
8095 {
8096     throw e;
8097 }
8098
8099 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8100 {
8101   med_field_type typcha;
8102   std::vector<std::string> infos;
8103   std::string dtunit;
8104   std::string meshName;
8105   int i(-1);
8106   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit,meshName);
8107   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8108   switch(typcha)
8109   {
8110     case MED_FLOAT64:
8111       {
8112         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8113         break;
8114       }
8115     case MED_INT32:
8116       {
8117         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8118         break;
8119       }
8120     case MED_FLOAT32:
8121       {
8122         ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8123         break;
8124       }
8125     case MED_INT:
8126       {
8127         if(sizeof(med_int)==sizeof(int))
8128           {
8129             ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8130             break;
8131           }
8132       }
8133     default:
8134       {
8135         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, MED_FLOAT32] !";
8136         throw INTERP_KERNEL::Exception(oss.str());
8137       }
8138   }
8139   ret->setMeshName(meshName);
8140   ret->setDtUnit(dtunit.c_str());
8141   return ret.retn();
8142 }
8143
8144 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8145 {
8146   med_field_type typcha;
8147   //
8148   std::vector<std::string> infos;
8149   std::string dtunit,fieldName,meshName;
8150   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
8151   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8152   switch(typcha)
8153   {
8154     case MED_FLOAT64:
8155       {
8156         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8157         break;
8158       }
8159     case MED_INT32:
8160       {
8161         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8162         break;
8163       }
8164     case MED_FLOAT32:
8165       {
8166         ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8167         break;
8168       }
8169     case MED_INT:
8170       {
8171         if(sizeof(med_int)==sizeof(int))
8172           {
8173             ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8174             break;
8175           }
8176       }
8177     default:
8178       {
8179         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, MED_FLOAT32] !";
8180         throw INTERP_KERNEL::Exception(oss.str());
8181       }
8182   }
8183   ret->setMeshName(meshName);
8184   ret->setDtUnit(dtunit.c_str());
8185   return ret.retn();
8186 }
8187
8188 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8189 {
8190   if(!c)
8191     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8192   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8193     {
8194       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8195       ret->_content=c;  c->incrRef();
8196       return ret.retn();
8197     }
8198   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8199     {
8200       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8201       ret->_content=c;  c->incrRef();
8202       return ret.retn();
8203     }
8204   if(dynamic_cast<const MEDFileFloatFieldMultiTSWithoutSDA *>(c))
8205     {
8206       MCAuto<MEDFileFloatFieldMultiTS> ret(MEDFileFloatFieldMultiTS::New());
8207       ret->_content=c;  c->incrRef();
8208       return ret.retn();
8209     }
8210   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
8211 }
8212
8213 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8214 {
8215   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8216   std::string fileName(FileNameFromFID(fid));
8217   ret->setFileName(fileName);
8218   return ret;
8219 }
8220
8221 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8222 try:MEDFileFieldGlobsReal(fid)
8223 {
8224   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8225   loadGlobals(fid);
8226 }
8227 catch(INTERP_KERNEL::Exception& e)
8228 {
8229     throw e;
8230 }
8231
8232 //= MEDFileAnyTypeFieldMultiTS
8233
8234 /*!
8235  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8236  * that has been read from a specified MED file.
8237  *  \param [in] fileName - the name of the MED file to read.
8238  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8239  *          is to delete this field using decrRef() as it is no more needed.
8240  *  \throw If reading the file fails.
8241  */
8242 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8243 {
8244   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8245   return New(fid,loadAll);
8246 }
8247
8248 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8249 {
8250   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8251   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8252   ret->loadGlobals(fid);
8253   return ret.retn();
8254 }
8255
8256 /*!
8257  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8258  * that has been read from a specified MED file.
8259  *  \param [in] fileName - the name of the MED file to read.
8260  *  \param [in] fieldName - the name of the field to read.
8261  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8262  *          is to delete this field using decrRef() as it is no more needed.
8263  *  \throw If reading the file fails.
8264  *  \throw If there is no field named \a fieldName in the file.
8265  */
8266 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8267 {
8268   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8269   return New(fid,fieldName,loadAll);
8270 }
8271
8272 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8273 {
8274   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8275   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8276   ret->loadGlobals(fid);
8277   return ret.retn();
8278 }
8279
8280 /*!
8281  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8282  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8283  *
8284  * \warning this is a shallow copy constructor
8285  */
8286 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8287 {
8288   if(!shallowCopyOfContent)
8289     {
8290       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8291       otherPtr->incrRef();
8292       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8293     }
8294   else
8295     {
8296       _content=other.shallowCpy();
8297     }
8298 }
8299
8300 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8301 {
8302   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8303   if(!ret)
8304     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8305   return ret;
8306 }
8307
8308 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8309 {
8310   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8311   if(!ret)
8312     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8313   return ret;
8314 }
8315
8316 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8317 {
8318   return contentNotNullBase()->getPflsReallyUsed2();
8319 }
8320
8321 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8322 {
8323   return contentNotNullBase()->getLocsReallyUsed2();
8324 }
8325
8326 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8327 {
8328   return contentNotNullBase()->getPflsReallyUsedMulti2();
8329 }
8330
8331 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8332 {
8333   return contentNotNullBase()->getLocsReallyUsedMulti2();
8334 }
8335
8336 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8337 {
8338   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8339 }
8340
8341 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8342 {
8343   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8344 }
8345
8346 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8347 {
8348   return contentNotNullBase()->getNumberOfTS();
8349 }
8350
8351 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8352 {
8353   contentNotNullBase()->eraseEmptyTS();
8354 }
8355
8356 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8357 {
8358   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8359 }
8360
8361 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8362 {
8363   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8364 }
8365
8366 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8367 {
8368   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8369   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8370   ret->_content=c;
8371   return ret.retn();
8372 }
8373
8374 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8375 {
8376   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8377   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8378   ret->_content=c;
8379   return ret.retn();
8380 }
8381
8382 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8383 {
8384   return contentNotNullBase()->getIterations();
8385 }
8386
8387 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8388 {
8389   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8390     pushBackTimeStep(*it);
8391 }
8392
8393 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8394 {
8395   if(!fmts)
8396     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8397   int nbOfTS(fmts->getNumberOfTS());
8398   for(int i=0;i<nbOfTS;i++)
8399     {
8400       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8401       pushBackTimeStep(elt);
8402     }
8403 }
8404
8405 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8406 {
8407   if(!f1ts)
8408     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8409   checkCoherencyOfType(f1ts);
8410   f1ts->incrRef();
8411   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8412   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8413   c->incrRef();
8414   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8415   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8416     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8417   _content->pushBackTimeStep(cSafe);
8418   appendGlobs(*f1ts,1e-12);
8419 }
8420
8421 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8422 {
8423   contentNotNullBase()->synchronizeNameScope();
8424 }
8425
8426 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8427 {
8428   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8429 }
8430
8431 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8432 {
8433   return contentNotNullBase()->getPosGivenTime(time,eps);
8434 }
8435
8436 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8437 {
8438   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8439 }
8440
8441 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8442 {
8443   return contentNotNullBase()->getTypesOfFieldAvailable();
8444 }
8445
8446 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
8447 {
8448   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8449 }
8450
8451 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8452 {
8453   return contentNotNullBase()->getName();
8454 }
8455
8456 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8457 {
8458   contentNotNullBase()->setName(name);
8459 }
8460
8461 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8462 {
8463   return contentNotNullBase()->getDtUnit();
8464 }
8465
8466 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8467 {
8468   contentNotNullBase()->setDtUnit(dtUnit);
8469 }
8470
8471 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8472 {
8473   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8474 }
8475
8476 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8477 {
8478   return contentNotNullBase()->getTimeSteps(ret1);
8479 }
8480
8481 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8482 {
8483   return contentNotNullBase()->getMeshName();
8484 }
8485
8486 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8487 {
8488   contentNotNullBase()->setMeshName(newMeshName);
8489 }
8490
8491 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8492 {
8493   return contentNotNullBase()->changeMeshNames(modifTab);
8494 }
8495
8496 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8497 {
8498   return contentNotNullBase()->getInfo();
8499 }
8500
8501 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8502 {
8503   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8504 }
8505
8506 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8507 {
8508   return contentNotNullBase()->setInfo(info);
8509 }
8510
8511 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8512 {
8513   const std::vector<std::string> ret=getInfo();
8514   return (int)ret.size();
8515 }
8516
8517 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8518 {
8519   writeGlobals(fid,*this);
8520   contentNotNullBase()->writeLL(fid,*this);
8521 }
8522
8523 /*!
8524  * This method alloc the arrays and load potentially huge arrays contained in this field.
8525  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8526  * This method can be also called to refresh or reinit values from a file.
8527  * 
8528  * \throw If the fileName is not set or points to a non readable MED file.
8529  */
8530 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8531 {
8532   if(getFileName().empty())
8533     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8534   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8535   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8536 }
8537
8538 /*!
8539  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8540  * But once data loaded once, this method does nothing.
8541  * 
8542  * \throw If the fileName is not set or points to a non readable MED file.
8543  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8544  */
8545 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8546 {
8547   if(!getFileName().empty())
8548     {
8549       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8550       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8551     }
8552 }
8553
8554 /*!
8555  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8556  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8557  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8558  * 
8559  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8560  */
8561 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8562 {
8563   contentNotNullBase()->unloadArrays();
8564 }
8565
8566 /*!
8567  * 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.
8568  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8569  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8570  * 
8571  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8572  */
8573 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8574 {
8575   if(!getFileName().empty())
8576     contentNotNullBase()->unloadArrays();
8577 }
8578
8579 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8580 {
8581   std::ostringstream oss;
8582   contentNotNullBase()->simpleRepr(0,oss,-1);
8583   simpleReprGlobs(oss);
8584   return oss.str();
8585 }
8586
8587 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8588 {
8589   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8590 }
8591
8592 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8593 {
8594   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8595   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8596   return ret;
8597 }
8598
8599 /*!
8600  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8601  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8602  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8603  */
8604 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8605 {
8606   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8607   if(!content)
8608     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8609   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8610   std::size_t sz(contentsSplit.size());
8611   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8612   for(std::size_t i=0;i<sz;i++)
8613     {
8614       ret[i]=shallowCpy();
8615       ret[i]->_content=contentsSplit[i];
8616     }
8617   return ret;
8618 }
8619
8620 /*!
8621  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8622  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8623  */
8624 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8625 {
8626   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8627   if(!content)
8628     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8629   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8630   std::size_t sz(contentsSplit.size());
8631   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8632   for(std::size_t i=0;i<sz;i++)
8633     {
8634       ret[i]=shallowCpy();
8635       ret[i]->_content=contentsSplit[i];
8636     }
8637   return ret;
8638 }
8639
8640 /*!
8641  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8642  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8643  */
8644 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8645 {
8646   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8647   if(!content)
8648     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8649   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8650   std::size_t sz(contentsSplit.size());
8651   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8652   for(std::size_t i=0;i<sz;i++)
8653     {
8654       ret[i]=shallowCpy();
8655       ret[i]->_content=contentsSplit[i];
8656     }
8657   return ret;
8658 }
8659
8660 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8661 {
8662   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8663   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8664     ret->_content=_content->deepCopy();
8665   ret->deepCpyGlobs(*this);
8666   return ret.retn();
8667 }
8668
8669 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8670 {
8671   return _content;
8672 }
8673
8674 /*!
8675  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8676  *  \param [in] iteration - the iteration number of a required time step.
8677  *  \param [in] order - the iteration order number of required time step.
8678  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8679  *          delete this field using decrRef() as it is no more needed.
8680  *  \throw If there is no required time step in \a this field.
8681  */
8682 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8683 {
8684   int pos=getPosOfTimeStep(iteration,order);
8685   return getTimeStepAtPos(pos);
8686 }
8687
8688 /*!
8689  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8690  *  \param [in] time - the time of the time step of interest.
8691  *  \param [in] eps - a precision used to compare time values.
8692  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8693  *          delete this field using decrRef() as it is no more needed.
8694  *  \throw If there is no required time step in \a this field.
8695  */
8696 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8697 {
8698   int pos=getPosGivenTime(time,eps);
8699   return getTimeStepAtPos(pos);
8700 }
8701
8702 /*!
8703  * 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.
8704  * The float64 value of time attached to the pair of integers are not considered here.
8705  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8706  *
8707  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8708  * \throw If there is a null pointer in \a vectFMTS.
8709  */
8710 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8711 {
8712   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8713   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8714   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8715   while(!lstFMTS.empty())
8716     {
8717       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8718       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8719       if(!curIt)
8720         throw INTERP_KERNEL::Exception(msg);
8721       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8722       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8723       elt.push_back(curIt); it=lstFMTS.erase(it);
8724       while(it!=lstFMTS.end())
8725         {
8726           curIt=*it;
8727           if(!curIt)
8728             throw INTERP_KERNEL::Exception(msg);
8729           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8730           if(refIts==curIts)
8731             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8732           else
8733             it++;
8734         }
8735       ret.push_back(elt);
8736     }
8737   return ret;
8738 }
8739
8740 /*!
8741  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8742  * All returned instances in a subvector can be safely loaded, rendered along time
8743  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8744  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8745  * 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).
8746  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8747  * 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.
8748  *
8749  * \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().
8750  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8751  * \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.
8752  * \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.
8753  *
8754  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8755  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8756  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8757  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8758  * \throw If mesh is null.
8759  * \throw If an element in \a vectFMTS is null.
8760  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8761  */
8762 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8763 {
8764   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8765   if(!mesh)
8766     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8767   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8768   if(vectFMTS.empty())
8769     return ret;
8770   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8771   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8772   if(!frstElt)
8773     throw INTERP_KERNEL::Exception(msg);
8774   std::size_t i=0;
8775   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8776   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8777   for(;it!=vectFMTS.end();it++,i++)
8778     {
8779       if(!(*it))
8780         throw INTERP_KERNEL::Exception(msg);
8781       TypeOfField tof0,tof1;
8782       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8783         {
8784           if(tof1!=ON_NODES)
8785             vectFMTSNotNodes.push_back(*it);
8786           else
8787             vectFMTSNodes.push_back(*it);
8788         }
8789       else
8790         vectFMTSNotNodes.push_back(*it);
8791     }
8792   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8793   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8794   ret=retCell;
8795   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8796     {
8797       i=0;
8798       bool isFetched(false);
8799       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8800         {
8801           if((*it0).empty())
8802             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8803           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8804             { ret[i].push_back(*it2); isFetched=true; }
8805         }
8806       if(!isFetched)
8807         {
8808           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8809           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8810           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8811         }
8812     }
8813   fsc=cmps;
8814   return ret;
8815 }
8816
8817 /*!
8818  * 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.
8819  * \param [out] cmps - same size than the returned vector.
8820  */
8821 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8822 {
8823   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8824   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8825   while(!lstFMTS.empty())
8826     {
8827       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8828       MEDFileAnyTypeFieldMultiTS *ref(*it);
8829       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8830       elt.push_back(ref); it=lstFMTS.erase(it);
8831       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8832       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8833       while(it!=lstFMTS.end())
8834         {
8835           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8836           if(cmp->isEqual(curIt))
8837             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8838           else
8839             it++;
8840         }
8841       ret.push_back(elt); cmps.push_back(cmp);
8842     }
8843   return ret;
8844 }
8845
8846 /*!
8847  * 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.
8848  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8849  *
8850  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8851  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8852  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8853  * \thorw If \a f0 and \a f1 do not have the same times steps.
8854  * \throw If mesh is null.
8855  * \throw If \a f0 or \a f1 is null.
8856  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8857  */
8858 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8859 {
8860   if(!mesh)
8861     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8862   if(!f0 || !f1)
8863     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8864   if(f0->getMeshName()!=mesh->getName())
8865     {
8866       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8867       throw INTERP_KERNEL::Exception(oss.str());
8868     }
8869   if(f1->getMeshName()!=mesh->getName())
8870     {
8871       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8872       throw INTERP_KERNEL::Exception(oss.str());
8873     }
8874   int nts=f0->getNumberOfTS();
8875   if(nts!=f1->getNumberOfTS())
8876     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8877   if(nts==0)
8878     return nts;
8879   for(int i=0;i<nts;i++)
8880     {
8881       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8882       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8883       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8884       if(tofs0.size()!=1 || tofs1.size()!=1)
8885         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8886       if(i!=0)
8887         {
8888           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8889             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8890         }
8891       else
8892         { tof0=tofs0[0]; tof1=tofs1[0]; }
8893       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8894         {
8895           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() << ") !";
8896           throw INTERP_KERNEL::Exception(oss.str());
8897         }
8898       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8899         {
8900           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() << ") !";
8901           throw INTERP_KERNEL::Exception(oss.str());
8902         }
8903       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8904         {
8905           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() << ") !";
8906           throw INTERP_KERNEL::Exception(oss.str());
8907         }
8908     }
8909   return nts;
8910 }
8911
8912 template<class T>
8913 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
8914 {
8915   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
8916   if(f1tss.empty())
8917     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
8918   std::size_t sz(f1tss.size()),i(0);
8919   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
8920   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
8921     {
8922       typename MLFieldTraits<T>::F1TSType const *elt(*it);
8923       if(!elt)
8924         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
8925       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
8926     }
8927   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
8928   if(!retc)
8929     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
8930   retc->aggregate(f1tsw,dts);
8931   ret->setDtUnit(f1tss[0]->getDtUnit());
8932   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
8933 }
8934
8935 template<class T>
8936 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
8937 {
8938   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
8939   if(fmtss.empty())
8940     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
8941   std::size_t sz(fmtss.size());
8942   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
8943     {
8944       typename MLFieldTraits<T>::FMTSType const *elt(*it);
8945       if(!elt)
8946         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
8947     }
8948   int nbTS(fmtss[0]->getNumberOfTS());
8949   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
8950     if((*it)->getNumberOfTS()!=nbTS)
8951       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
8952   for(int iterTS=0;iterTS<nbTS;iterTS++)
8953     {
8954       std::size_t i(0);
8955       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
8956       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
8957       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
8958         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
8959       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
8960       ret->pushBackTimeStep(f1ts);
8961       ret->setDtUnit(f1ts->getDtUnit());
8962     }
8963   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
8964 }
8965
8966 /*!
8967  * \a dts and \a ftmss are expected to have same size.
8968  */
8969 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
8970 {
8971   if(fmtss.empty())
8972     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
8973   std::size_t sz(fmtss.size());
8974   std::vector<const MEDFileFieldMultiTS *> fmtss1;
8975   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
8976   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
8977     {
8978       if(!(*it))
8979         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
8980       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
8981       if(elt1)
8982         {
8983           fmtss1.push_back(elt1);
8984           continue;
8985         }
8986       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
8987       if(elt2)
8988         {
8989           fmtss2.push_back(elt2);
8990           continue;
8991         }
8992       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
8993     }
8994   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
8995     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
8996   if(fmtss1.size()==sz)
8997     return AggregateHelperFMTS<double>(fmtss1,dts);
8998   if(fmtss2.size()!=sz)
8999     return AggregateHelperFMTS<int>(fmtss2,dts);
9000   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9001 }
9002
9003 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9004 {
9005   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9006 }
9007
9008 //= MEDFileFieldMultiTS
9009
9010 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9011 {
9012   return new MEDFileFieldMultiTS(*this);
9013 }
9014
9015 /*!
9016  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9017  * following the given input policy.
9018  *
9019  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9020  *                            By default (true) the globals are deeply copied.
9021  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9022  */
9023 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9024 {
9025   MCAuto<MEDFileIntFieldMultiTS> ret;
9026   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9027   if(content)
9028     {
9029       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9030       if(!contc)
9031         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9032       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9033       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9034     }
9035   else
9036     ret=MEDFileIntFieldMultiTS::New();
9037   if(isDeepCpyGlobs)
9038     ret->deepCpyGlobs(*this);
9039   else
9040     ret->shallowCpyGlobs(*this);
9041   return ret.retn();
9042 }
9043
9044 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
9045 try:MEDFileTemplateFieldMultiTS<double>(fid,loadAll,ms)
9046 {
9047 }
9048 catch(INTERP_KERNEL::Exception& e)
9049 { throw e; }
9050
9051 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9052 try:MEDFileTemplateFieldMultiTS<double>(fid,fieldName,loadAll,ms,entities)
9053 {
9054 }
9055 catch(INTERP_KERNEL::Exception& e)
9056 { throw e; }
9057
9058 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileTemplateFieldMultiTS<double>(other,shallowCopyOfContent)
9059 {
9060 }
9061
9062 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
9063 {
9064   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9065 }
9066
9067 //= MEDFileAnyTypeFieldMultiTSIterator
9068
9069 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9070 {
9071   if(fmts)
9072     {
9073       fmts->incrRef();
9074       _nb_iter=fmts->getNumberOfTS();
9075     }
9076 }
9077
9078 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9079 {
9080 }
9081
9082 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9083 {
9084   if(_iter_id<_nb_iter)
9085     {
9086       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9087       if(fmts)
9088         return fmts->getTimeStepAtPos(_iter_id++);
9089       else
9090         return 0;
9091     }
9092   else
9093     return 0;
9094 }
9095
9096 //= MEDFileIntFieldMultiTS
9097
9098 //= MEDFileFields
9099
9100 MEDFileFields *MEDFileFields::New()
9101 {
9102   return new MEDFileFields;
9103 }
9104
9105 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9106 {
9107   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9108   return New(fid,loadAll);
9109 }
9110
9111 MEDFileFields *MEDFileFields::NewAdv(const std::string& fileName, bool loadAll, const MEDFileEntities *entities)
9112 {
9113   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9114   return NewAdv(fid,loadAll,entities);
9115 }
9116
9117 MEDFileFields *MEDFileFields::NewAdv(med_idt fid, bool loadAll, const MEDFileEntities *entities)
9118 {
9119   return new MEDFileFields(fid,loadAll,0,entities);
9120 }
9121
9122 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
9123 {
9124   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9125   return NewWithDynGT(fid,se,loadAll);
9126 }
9127
9128 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
9129 {
9130   if(!se)
9131     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
9132   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
9133   return new MEDFileFields(fid,loadAll,0,entities);
9134 }
9135
9136 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
9137 {
9138   return new MEDFileFields(fid,loadAll,0,0);
9139 }
9140
9141 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9142 {
9143   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9144   return new MEDFileFields(fid,loadAll,ms,0);
9145 }
9146
9147 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9148 {
9149   MEDFileUtilities::CheckFileForRead(fileName);
9150   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9151   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9152   return new MEDFileFields(fid,loadAll,0,ent);
9153 }
9154
9155 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9156 {
9157   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9158   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9159   return ret;
9160 }
9161
9162 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9163 {
9164   std::vector<const BigMemoryObject *> ret;
9165   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9166     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9167   return ret;
9168 }
9169
9170 MEDFileFields *MEDFileFields::deepCopy() const
9171 {
9172   MCAuto<MEDFileFields> ret(shallowCpy());
9173   std::size_t i(0);
9174   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9175     {
9176       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9177         ret->_fields[i]=(*it)->deepCopy();
9178     }
9179   ret->deepCpyGlobs(*this);
9180   return ret.retn();
9181 }
9182
9183 MEDFileFields *MEDFileFields::shallowCpy() const
9184 {
9185   return new MEDFileFields(*this);
9186 }
9187
9188 /*!
9189  * 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
9190  * 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.
9191  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9192  *
9193  * \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.
9194  * \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.
9195  * 
9196  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9197  */
9198 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9199 {
9200   std::set< std::pair<int,int> > s;
9201   bool firstShot=true;
9202   areThereSomeForgottenTS=false;
9203   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9204     {
9205       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9206         continue;
9207       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9208       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9209       if(firstShot)
9210         { s=s1; firstShot=false; }
9211       else
9212         {
9213           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9214           if(s!=s2)
9215             areThereSomeForgottenTS=true;
9216           s=s2;
9217         }
9218     }
9219   std::vector< std::pair<int,int> > ret;
9220   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9221   return ret;
9222 }
9223
9224 int MEDFileFields::getNumberOfFields() const
9225 {
9226   return _fields.size();
9227 }
9228
9229 std::vector<std::string> MEDFileFields::getFieldsNames() const
9230 {
9231   std::vector<std::string> ret(_fields.size());
9232   int i(0);
9233   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9234     {
9235       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9236       if(f)
9237         {
9238           ret[i]=f->getName();
9239         }
9240       else
9241         {
9242           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9243           throw INTERP_KERNEL::Exception(oss.str());
9244         }
9245     }
9246   return ret;
9247 }
9248
9249 std::vector<std::string> MEDFileFields::getMeshesNames() const
9250 {
9251   std::vector<std::string> ret;
9252   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9253     {
9254       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9255       if(cur)
9256         ret.push_back(cur->getMeshName());
9257     }
9258   return ret;
9259 }
9260
9261 std::string MEDFileFields::simpleRepr() const
9262 {
9263   std::ostringstream oss;
9264   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9265   simpleRepr(0,oss);
9266   return oss.str();
9267 }
9268
9269 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9270 {
9271   int nbOfFields(getNumberOfFields());
9272   std::string startLine(bkOffset,' ');
9273   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9274   int i=0;
9275   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9276     {
9277       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9278       if(cur)
9279         {
9280           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9281         }
9282       else
9283         {
9284           oss << startLine << "  - not defined !" << std::endl;
9285         }
9286     }
9287   i=0;
9288   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9289     {
9290       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9291       std::string chapter(17,'0'+i);
9292       oss << startLine << chapter << std::endl;
9293       if(cur)
9294         {
9295           cur->simpleRepr(bkOffset+2,oss,i);
9296         }
9297       else
9298         {
9299           oss << startLine << "  - not defined !" << std::endl;
9300         }
9301       oss << startLine << chapter << std::endl;
9302     }
9303   simpleReprGlobs(oss);
9304 }
9305
9306 MEDFileFields::MEDFileFields()
9307 {
9308 }
9309
9310 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9311 try:MEDFileFieldGlobsReal(fid)
9312 {
9313   int nbFields(MEDnField(fid));
9314   _fields.resize(nbFields);
9315   med_field_type typcha;
9316   for(int i=0;i<nbFields;i++)
9317     {
9318       std::vector<std::string> infos;
9319       std::string fieldName,dtunit,meshName;
9320       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit,meshName));
9321       switch(typcha)
9322       {
9323         case MED_FLOAT64:
9324           {
9325             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9326             break;
9327           }
9328         case MED_INT32:
9329           {
9330             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9331             break;
9332           }
9333         case MED_FLOAT32:
9334           {
9335             _fields[i]=MEDFileFloatFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9336             break;
9337           }
9338         case MED_INT:
9339           {
9340             if(sizeof(med_int)==sizeof(int))
9341               {
9342                 _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9343                 break;
9344               }
9345           }
9346         default:
9347           {
9348             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, MED_FLOAT32] !";
9349             throw INTERP_KERNEL::Exception(oss.str());
9350           }
9351       }
9352     }
9353   loadAllGlobals(fid,entities);
9354 }
9355 catch(INTERP_KERNEL::Exception& e)
9356 {
9357     throw e;
9358 }
9359
9360 void MEDFileFields::writeLL(med_idt fid) const
9361 {
9362   int i=0;
9363   writeGlobals(fid,*this);
9364   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9365     {
9366       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9367       if(!elt)
9368         {
9369           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9370           throw INTERP_KERNEL::Exception(oss.str());
9371         }
9372       elt->writeLL(fid,*this);
9373     }
9374 }
9375
9376 /*!
9377  * This method alloc the arrays and load potentially huge arrays contained in this field.
9378  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9379  * This method can be also called to refresh or reinit values from a file.
9380  * 
9381  * \throw If the fileName is not set or points to a non readable MED file.
9382  */
9383 void MEDFileFields::loadArrays()
9384 {
9385   if(getFileName().empty())
9386     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9387   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9388   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9389     {
9390       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9391       if(elt)
9392         elt->loadBigArraysRecursively(fid,*elt);
9393     }
9394 }
9395
9396 /*!
9397  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9398  * But once data loaded once, this method does nothing.
9399  * 
9400  * \throw If the fileName is not set or points to a non readable MED file.
9401  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9402  */
9403 void MEDFileFields::loadArraysIfNecessary()
9404 {
9405   if(!getFileName().empty())
9406     {
9407       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9408       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9409         {
9410           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9411           if(elt)
9412             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9413         }
9414     }
9415 }
9416
9417 /*!
9418  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9419  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9420  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9421  * 
9422  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9423  */
9424 void MEDFileFields::unloadArrays()
9425 {
9426   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9427     {
9428       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9429       if(elt)
9430         elt->unloadArrays();
9431     }
9432 }
9433
9434 /*!
9435  * 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.
9436  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9437  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9438  * 
9439  * \sa MEDFileFields::loadArraysIfNecessary
9440  */
9441 void MEDFileFields::unloadArraysWithoutDataLoss()
9442 {
9443   if(!getFileName().empty())
9444     unloadArrays();
9445 }
9446
9447 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9448 {
9449   std::vector<std::string> ret;
9450   std::set<std::string> ret2;
9451   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9452     {
9453       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9454       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9455         if(ret2.find(*it2)==ret2.end())
9456           {
9457             ret.push_back(*it2);
9458             ret2.insert(*it2);
9459           }
9460     }
9461   return ret;
9462 }
9463
9464 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9465 {
9466   std::vector<std::string> ret;
9467   std::set<std::string> ret2;
9468   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9469     {
9470       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
9471       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9472         if(ret2.find(*it2)==ret2.end())
9473           {
9474             ret.push_back(*it2);
9475             ret2.insert(*it2);
9476           }
9477     }
9478   return ret;
9479 }
9480
9481 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9482 {
9483   std::vector<std::string> ret;
9484   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9485     {
9486       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
9487       ret.insert(ret.end(),tmp.begin(),tmp.end());
9488     }
9489   return ret;
9490 }
9491
9492 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9493 {
9494   std::vector<std::string> ret;
9495   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9496     {
9497       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
9498       ret.insert(ret.end(),tmp.begin(),tmp.end());
9499     }
9500   return ret;
9501 }
9502
9503 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9504 {
9505   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9506     (*it)->changePflsRefsNamesGen2(mapOfModif);
9507 }
9508
9509 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9510 {
9511   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9512     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9513 }
9514
9515 void MEDFileFields::resize(int newSize)
9516 {
9517   _fields.resize(newSize);
9518 }
9519
9520 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
9521 {
9522   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9523     pushField(*it);
9524 }
9525
9526 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
9527 {
9528   if(!field)
9529     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9530   _fields.push_back(field->getContent());
9531   appendGlobs(*field,1e-12);
9532 }
9533
9534 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
9535 {
9536   if(!field)
9537     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9538   if(i>=(int)_fields.size())
9539     _fields.resize(i+1);
9540   _fields[i]=field->getContent();
9541   appendGlobs(*field,1e-12);
9542 }
9543
9544 void MEDFileFields::destroyFieldAtPos(int i)
9545 {
9546   destroyFieldsAtPos(&i,&i+1);
9547 }
9548
9549 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
9550 {
9551   std::vector<bool> b(_fields.size(),true);
9552   for(const int *i=startIds;i!=endIds;i++)
9553     {
9554       if(*i<0 || *i>=(int)_fields.size())
9555         {
9556           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9557           throw INTERP_KERNEL::Exception(oss.str());
9558         }
9559       b[*i]=false;
9560     }
9561   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9562   std::size_t j=0;
9563   for(std::size_t i=0;i<_fields.size();i++)
9564     if(b[i])
9565       fields[j++]=_fields[i];
9566   _fields=fields;
9567 }
9568
9569 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
9570 {
9571   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9572   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
9573   std::vector<bool> b(_fields.size(),true);
9574   int k=bg;
9575   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9576     {
9577       if(k<0 || k>=(int)_fields.size())
9578         {
9579           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9580           throw INTERP_KERNEL::Exception(oss.str());
9581         }
9582       b[k]=false;
9583     }
9584   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9585   std::size_t j(0);
9586   for(std::size_t i=0;i<_fields.size();i++)
9587     if(b[i])
9588       fields[j++]=_fields[i];
9589   _fields=fields;
9590 }
9591
9592 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9593 {
9594   bool ret(false);
9595   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9596     {
9597       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9598       if(cur)
9599         ret=cur->changeMeshNames(modifTab) || ret;
9600     }
9601   return ret;
9602 }
9603
9604 /*!
9605  * \param [in] meshName the name of the mesh that will be renumbered.
9606  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9607  *             This code corresponds to the distribution of types in the corresponding mesh.
9608  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9609  * \param [in] renumO2N the old to new renumber array.
9610  * \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 
9611  *         field in \a this.
9612  */
9613 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
9614 {
9615   bool ret(false);
9616   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9617     {
9618       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9619       if(fmts)
9620         {
9621           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9622         }
9623     }
9624   return ret;
9625 }
9626
9627 /*!
9628  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9629  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9630  *
9631  * \return A new object that the caller is responsible to deallocate.
9632  */
9633 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9634 {
9635   if(!mm)
9636     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
9637   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
9638   int nbFields(getNumberOfFields());
9639   for(int i=0;i<nbFields;i++)
9640     {
9641       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
9642       if(!fmts)
9643         {
9644           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
9645           throw INTERP_KERNEL::Exception(oss.str());
9646         }
9647       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
9648       fsOut->pushField(fmtsOut);
9649     }
9650   return fsOut.retn();
9651 }
9652
9653 void MEDFileFields::accept(MEDFileFieldVisitor& visitor) const
9654 {
9655   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9656     if((*it).isNotNull())
9657       {
9658         visitor.newFieldEntry(*it);
9659         (*it)->accept(visitor);
9660         visitor.endFieldEntry(*it);
9661       }
9662 }
9663
9664 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
9665 {
9666   if(i<0 || i>=(int)_fields.size())
9667     {
9668       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9669       throw INTERP_KERNEL::Exception(oss.str());
9670     }
9671   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9672   if(!fmts)
9673     return 0;
9674   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
9675   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
9676   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
9677   const MEDFileFloatFieldMultiTSWithoutSDA *fmtsC3(dynamic_cast<const MEDFileFloatFieldMultiTSWithoutSDA *>(fmts));
9678   if(fmtsC)
9679     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9680   else if(fmtsC2)
9681     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9682   else if(fmtsC3)
9683     ret=MEDFileFloatFieldMultiTS::New(*fmtsC3,false);
9684   else
9685     {
9686       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor float (FLOAT32) nor integer (INT32) !";
9687       throw INTERP_KERNEL::Exception(oss.str());
9688     }
9689   ret->shallowCpyGlobs(*this);
9690   return ret.retn();
9691 }
9692
9693 /*!
9694  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9695  * This method is accessible in python using __getitem__ with a list in input.
9696  * \return a new object that the caller should deal with.
9697  */
9698 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
9699 {
9700   MCAuto<MEDFileFields> ret=shallowCpy();
9701   std::size_t sz=std::distance(startIds,endIds);
9702   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9703   int j=0;
9704   for(const int *i=startIds;i!=endIds;i++,j++)
9705     {
9706       if(*i<0 || *i>=(int)_fields.size())
9707         {
9708           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9709           throw INTERP_KERNEL::Exception(oss.str());
9710         }
9711       fields[j]=_fields[*i];
9712     }
9713   ret->_fields=fields;
9714   return ret.retn();
9715 }
9716
9717 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
9718 {
9719   return getFieldAtPos(getPosFromFieldName(fieldName));
9720 }
9721
9722 /*!
9723  * This method removes, if any, fields in \a this having no time steps.
9724  * 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.
9725  * 
9726  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
9727  */
9728 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
9729 {
9730   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
9731   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9732     {
9733       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9734       if(elt)
9735         {
9736           if(elt->getNumberOfTS()>0)
9737             newFields.push_back(*it);
9738         }
9739     }
9740   if(_fields.size()==newFields.size())
9741     return false;
9742   _fields=newFields;
9743   return true;
9744 }
9745
9746 /*!
9747  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9748  * This method can be seen as a filter applied on \a this, that returns an object containing
9749  * 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
9750  * shallow copied from \a this.
9751  * 
9752  * \param [in] meshName - the name of the mesh on w
9753  * \return a new object that the caller should deal with.
9754  */
9755 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
9756 {
9757   MCAuto<MEDFileFields> ret(MEDFileFields::New());
9758   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9759     {
9760       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9761       if(!cur)
9762         continue;
9763       if(cur->getMeshName()==meshName)
9764         {
9765           cur->incrRef();
9766           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9767           ret->_fields.push_back(cur2);
9768         }
9769     }
9770   ret->shallowCpyOnlyUsedGlobs(*this);
9771   return ret.retn();
9772 }
9773
9774 /*!
9775  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9776  * Input time steps are specified using a pair of integer (iteration, order).
9777  * 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,
9778  * but for each multitimestep only the time steps in \a timeSteps are kept.
9779  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9780  * 
9781  * The returned object points to shallow copy of elements in \a this.
9782  * 
9783  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9784  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9785  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9786  */
9787 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
9788 {
9789   MCAuto<MEDFileFields> ret(MEDFileFields::New());
9790   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9791     {
9792       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9793       if(!cur)
9794         continue;
9795       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
9796       ret->_fields.push_back(elt);
9797     }
9798   ret->shallowCpyOnlyUsedGlobs(*this);
9799   return ret.retn();
9800 }
9801
9802 /*!
9803  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
9804  */
9805 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
9806 {
9807   MCAuto<MEDFileFields> ret=MEDFileFields::New();
9808   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9809     {
9810       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9811       if(!cur)
9812         continue;
9813       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
9814       if(elt->getNumberOfTS()!=0)
9815         ret->_fields.push_back(elt);
9816     }
9817   ret->shallowCpyOnlyUsedGlobs(*this);
9818   return ret.retn();
9819 }
9820
9821 bool MEDFileFields::presenceOfStructureElements() const
9822 {
9823   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9824     if((*it).isNotNull())
9825       if((*it)->presenceOfStructureElements())
9826         return true;
9827   return false;
9828 }
9829
9830 void MEDFileFields::killStructureElements()
9831 {
9832   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
9833   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9834     if((*it).isNotNull())
9835       {
9836         if((*it)->presenceOfStructureElements())
9837           {
9838             if(!(*it)->onlyStructureElements())
9839               {
9840                 (*it)->killStructureElements();
9841                 ret.push_back(*it);
9842               }
9843           }
9844         else
9845           {
9846             ret.push_back(*it);
9847           }
9848       }
9849   _fields=ret;
9850 }
9851
9852 void MEDFileFields::keepOnlyStructureElements()
9853 {
9854   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
9855   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9856     if((*it).isNotNull())
9857       {
9858         if((*it)->presenceOfStructureElements())
9859           {
9860             if(!(*it)->onlyStructureElements())
9861               (*it)->keepOnlyStructureElements();
9862             ret.push_back(*it);
9863           }
9864       }
9865   _fields=ret;
9866 }
9867
9868 void MEDFileFields::keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName)
9869 {
9870   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
9871   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9872     if((*it).isNotNull())
9873       {
9874         if((*it)->getMeshName()!=meshName)
9875           continue;
9876         std::vector< std::pair<std::string,std::string> > ps;
9877         (*it)->getMeshSENames(ps);
9878         std::pair<std::string,std::string> p(meshName,seName);
9879         if(std::find(ps.begin(),ps.end(),p)!=ps.end())
9880           (*it)->keepOnlyOnSE(seName);
9881         ret.push_back(*it);
9882       }
9883   _fields=ret;
9884 }
9885
9886 void MEDFileFields::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
9887 {
9888   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9889     if((*it).isNotNull())
9890       (*it)->getMeshSENames(ps);
9891 }
9892
9893 void MEDFileFields::blowUpSE(MEDFileMeshes *ms, const MEDFileStructureElements *ses)
9894 {
9895   MEDFileBlowStrEltUp::DealWithSE(this,ms,ses);
9896 }
9897
9898 MCAuto<MEDFileFields> MEDFileFields::partOfThisOnStructureElements() const
9899 {
9900   MCAuto<MEDFileFields> ret(deepCopy());
9901   ret->keepOnlyStructureElements();
9902   return ret;
9903 }
9904
9905 MCAuto<MEDFileFields> MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const
9906 {
9907   MCAuto<MEDFileFields> ret(deepCopy());
9908   ret->keepOnlyOnMeshSE(meshName,seName);
9909   return ret;
9910 }
9911
9912 void MEDFileFields::aggregate(const MEDFileFields& other)
9913 {
9914   int nbFieldsToAdd(other.getNumberOfFields());
9915   std::vector<std::string> fsn(getFieldsNames());
9916   for(int i=0;i<nbFieldsToAdd;i++)
9917     {
9918       MCAuto<MEDFileAnyTypeFieldMultiTS> elt(other.getFieldAtPos(i));
9919       std::string name(elt->getName());
9920       if(std::find(fsn.begin(),fsn.end(),name)!=fsn.end())
9921         {
9922           std::ostringstream oss; oss << "MEDFileFields::aggregate : name \"" << name << "\" already appears !";
9923           throw INTERP_KERNEL::Exception(oss.str());
9924         }
9925       pushField(elt);
9926     }
9927 }
9928
9929 MEDFileFieldsIterator *MEDFileFields::iterator()
9930 {
9931   return new MEDFileFieldsIterator(this);
9932 }
9933
9934 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
9935 {
9936   std::string tmp(fieldName);
9937   std::vector<std::string> poss;
9938   for(std::size_t i=0;i<_fields.size();i++)
9939     {
9940       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
9941       if(f)
9942         {
9943           std::string fname(f->getName());
9944           if(tmp==fname)
9945             return i;
9946           else
9947             poss.push_back(fname);
9948         }
9949     }
9950   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
9951   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
9952   oss << " !";
9953   throw INTERP_KERNEL::Exception(oss.str());
9954 }
9955
9956 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
9957 {
9958   if(fs)
9959     {
9960       fs->incrRef();
9961       _nb_iter=fs->getNumberOfFields();
9962     }
9963 }
9964
9965 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
9966 {
9967 }
9968
9969 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
9970 {
9971   if(_iter_id<_nb_iter)
9972     {
9973       MEDFileFields *fs(_fs);
9974       if(fs)
9975         return fs->getFieldAtPos(_iter_id++);
9976       else
9977         return 0;
9978     }
9979   else
9980     return 0;
9981 }