Salome HOME
3f3d6f45a420435f36e78e9f18ff0d7e1e722879
[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   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   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         MEDFILESAFECALLERWR0(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   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   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       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
584       int nbi,tmp1;
585       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
586       if(_end-_start!=nbValsInFile*nbi)
587         {
588           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 !";
589           throw INTERP_KERNEL::Exception(oss.str());
590         }
591       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
592     }
593   else
594     {
595       if(!_profile.empty())
596         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
597       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
598       int profilesize,nbi;
599       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
600       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
601       if(spd)
602         {
603           int start,stop,step;
604           spd->getSlice(start,stop,step);
605           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
606           med_filter filter=MED_FILTER_INIT;
607           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
608                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
609                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
610                                    /*lastblocksize=useless because count=1*/0,&filter);
611           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
612           MEDfilterClose(&filter);
613           return ;
614         }
615       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
616       if(dpd)
617         {
618           dpd->checkConsistencyLight();
619           MCAuto<DataArrayInt> myIds(dpd->toDAI());
620           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
621           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
622           myIds->applyLin(1,-a);
623           int nbOfEltsToLoad(b-a+1);
624           med_filter filter=MED_FILTER_INIT;
625           {//TODO : manage int32 !
626             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
627             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
628             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
629                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
630                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
631                                      /*lastblocksize=useless because count=1*/0,&filter);
632             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
633             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
634             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
635             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
636           }
637           MEDfilterClose(&filter);
638         }
639       else
640         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
641     }
642 }
643
644 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
645 {
646   return _father;
647 }
648
649 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
650 {
651   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
652   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
653   std::string fieldName(nasc.getName()),meshName(getMeshName());
654   int iteration(getIteration()),order(getOrder()),profilesize,nbi;
655   TypeOfField type(getType());
656   med_geometry_type mgeoti;
657   med_entity_type menti;
658   _father->entriesForMEDfile(type,mgeoti,menti);
659   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
660   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
661   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
662   const PartDefinition *pd(_pd);
663   if(!pd)
664     {
665       _nval=zeNVal;
666     }
667   else
668     {
669       if(!_profile.empty())
670         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
671       _nval=pd->getNumberOfElems();
672     }
673   _start=start;
674   _end=start+_nval*nbi;
675   start=_end;
676   if(type==ON_CELLS && !_localization.empty())
677     {
678       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
679         setType(ON_GAUSS_PT);
680       else
681         {
682           setType(ON_GAUSS_NE);
683           _localization.clear();
684         }
685     }
686 }
687
688 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
689 {
690   std::string fieldName(nasc.getName()),meshName(getMeshName());
691   int iteration(getIteration()),order(getOrder());
692   TypeOfField type(getType());
693   med_geometry_type mgeoti;
694   med_entity_type menti;
695   _father->entriesForMEDfile(type,mgeoti,menti);
696   if(_start>_end)
697     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
698   if(_start==_end)
699     return ;
700   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
701   if(_start<0 || _start>=arr->getNumberOfTuples())
702     {
703       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
704       throw INTERP_KERNEL::Exception(oss.str());
705     }
706   if(_end<0 || _end>arr->getNumberOfTuples())
707     {
708       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
709       throw INTERP_KERNEL::Exception(oss.str());
710     }
711   int nbOfCompo(arr->getNumberOfComponents());
712   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
713   if(arrD)
714     {
715       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
716       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
717       return ;
718     }
719   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
720   if(arrI)
721     {
722       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
723       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
724       return ;
725     }
726   DataArrayFloat *arrF(dynamic_cast<DataArrayFloat *>(arr));
727   if(arrF)
728     {
729       float *startFeeding(arrF->getPointer()+_start*nbOfCompo);
730       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
731       return ;
732     }
733   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 FLOAT32 or INT32 !");
734 }
735
736 /*!
737  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
738  */
739 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
740 {
741   int delta=_end-_start;
742   _start=newValueOfStart;
743   _end=_start+delta;
744 }
745
746 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
747 {
748   return _father->getIteration();
749 }
750
751 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
752 {
753   return _father->getOrder();
754 }
755
756 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
757 {
758   return _father->getTime();
759 }
760
761 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
762 {
763   return _father->getMeshName();
764 }
765
766 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
767 {
768   const char startLine[]="    ## ";
769   std::string startLine2(bkOffset,' ');
770   startLine2+=startLine;
771   INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
772   oss << startLine2 << "Localization #" << id << "." << std::endl;
773   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
774   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
775   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
776   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
777 }
778
779 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
780 {
781   return _type;
782 }
783
784 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
785 {
786   return _father->getGeoType();
787 }
788
789 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
790 {
791   types.insert(_type);
792 }
793
794 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
795 {
796   _type=newType;
797 }
798
799 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
800 {
801   return _father->getNumberOfComponents();
802 }
803
804 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
805 {
806   return _end-_start;
807 }
808
809 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
810 {
811   return _father->getOrCreateAndGetArray();
812 }
813
814 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
815 {
816   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
817   return fath->getOrCreateAndGetArray();
818 }
819
820 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
821 {
822   return _father->getInfo();
823 }
824
825 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
826 {
827   return _profile;
828 }
829
830 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
831 {
832   _profile=newPflName;
833 }
834
835 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
836 {
837   return _localization;
838 }
839
840 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
841 {
842   _localization=newLocName;
843 }
844
845 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
846 {
847   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
848     {
849       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
850         {
851           _profile=(*it2).second;
852           return;
853         }
854     }
855 }
856
857 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
858 {
859   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
860     {
861       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
862         {
863           _localization=(*it2).second;
864           return;
865         }
866     }
867 }
868
869 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
870 {
871   if(type!=_type)
872     return ;
873   dads.push_back(std::pair<int,int>(_start,_end));
874   geoTypes.push_back(getGeoType());
875   if(_profile.empty())
876     pfls.push_back(0);
877   else
878     {
879       pfls.push_back(glob->getProfile(_profile.c_str()));
880     }
881   if(_localization.empty())
882     locs.push_back(-1);
883   else
884     {
885       locs.push_back(glob->getLocalizationId(_localization.c_str()));
886     }
887 }
888
889 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
890 {
891   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));
892   startEntryId++;
893 }
894
895 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
896 {
897   TypeOfField type=getType();
898   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
899   med_geometry_type mgeoti;
900   med_entity_type menti;
901   _father->entriesForMEDfile(getType(),mgeoti,menti);
902   const DataArray *arr(getOrCreateAndGetArray());
903   if(!arr)
904     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
905   if(!arr->isAllocated())
906     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
907   const DataArrayDouble *arrD(dynamic_cast<const DataArrayDouble *>(arr));
908   const DataArrayInt *arrI(dynamic_cast<const DataArrayInt *>(arr));
909   const DataArrayFloat *arrF(dynamic_cast<const DataArrayFloat *>(arr));
910   const unsigned char *locToWrite=0;
911   if(arrD)
912     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
913   else if(arrI)
914     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
915   else if(arrF)
916     locToWrite=reinterpret_cast<const unsigned char *>(arrF->getConstPointer()+_start*arr->getNumberOfComponents());
917   else
918     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 FLOAT32 and INT32 !");
919   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
920                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
921                                                    locToWrite));
922 }
923
924 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
925 {
926   type=_type;
927   pfl=_profile;
928   loc=_localization;
929   dad.first=_start; dad.second=_end;
930 }
931
932 /*!
933  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
934  *             This code corresponds to the distribution of types in the corresponding mesh.
935  * \param [out] ptToFill memory zone where the output will be stored.
936  * \return the size of data pushed into output param \a ptToFill
937  */
938 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
939 {
940   _loc_id=offset;
941   std::ostringstream oss;
942   std::size_t nbOfType=codeOfMesh.size()/3;
943   int found=-1;
944   for(std::size_t i=0;i<nbOfType && found==-1;i++)
945     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
946       found=(int)i;
947   if(found==-1)
948     {
949       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
950       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
951       throw INTERP_KERNEL::Exception(oss.str());
952     }
953   int *work=ptToFill;
954   if(_profile.empty())
955     {
956       if(_nval!=codeOfMesh[3*found+1])
957         {
958           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
959           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
960           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
961           throw INTERP_KERNEL::Exception(oss.str());
962         }
963       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
964         *work++=ii;
965     }
966   else
967     {
968       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
969       if(pfl->getNumberOfTuples()!=_nval)
970         {
971           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
972           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
973           oss << _nval;
974           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
975           throw INTERP_KERNEL::Exception(oss.str());
976         }
977       int offset2=codeOfMesh[3*found+2];
978       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
979         {
980           if(*pflId<codeOfMesh[3*found+1])
981             *work++=offset2+*pflId;
982         }
983     }
984   return _nval;
985 }
986
987 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
988 {
989   for(int i=_start;i<_end;i++)
990     *ptToFill++=i;
991   return _end-_start;
992 }
993
994 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
995 {
996   switch(type)
997   {
998     case ON_CELLS:
999       return -2;
1000     case ON_GAUSS_NE:
1001       return -1;
1002     case ON_GAUSS_PT:
1003       return locId;
1004     default:
1005       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
1006   }
1007 }
1008
1009 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
1010 {
1011   int id=0;
1012   std::map<std::pair<std::string,TypeOfField>,int> m;
1013   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
1014   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
1015     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
1016       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
1017   ret.resize(id);
1018   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
1019     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
1020   return ret;
1021 }
1022
1023 /*!
1024  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
1025  * 
1026  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
1027  * \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.
1028  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
1029  * \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)
1030  * \param [in,out] glob if necessary by the method, new profiles can be added to it
1031  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
1032  * \param [out] result All new entries will be appended on it.
1033  * \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 !)
1034  */
1035 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1036                                                        const DataArrayInt *explicitIdsInMesh,
1037                                                        const std::vector<int>& newCode,
1038                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
1039                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
1040 {
1041   if(entriesOnSameDisc.empty())
1042     return false;
1043   TypeOfField type=entriesOnSameDisc[0]->getType();
1044   int szEntities=0,szTuples=0;
1045   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
1046     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
1047   int nbi=szTuples/szEntities;
1048   if(szTuples%szEntities!=0)
1049     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
1050   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
1051   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
1052   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
1053   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
1054   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
1055   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
1056   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
1057   int id=0;
1058   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
1059     {
1060       int startOfEltIdOfChunk=(*it)->_start;
1061       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
1062       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
1063       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
1064       //
1065       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
1066       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
1067       //
1068       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
1069       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
1070     }
1071   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
1072   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
1073   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
1074   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
1075   //
1076   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
1077   //
1078   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
1079   arrPart->renumberInPlace(renumTupleIds->begin());
1080   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
1081   bool ret=false;
1082   const int *idIt=diffVals->begin();
1083   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
1084   int offset2=0;
1085   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
1086     {
1087       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
1088       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
1089       int nbEntityElts=subIds->getNumberOfTuples();
1090       bool ret2;
1091       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
1092           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
1093                                       offset+offset2,
1094                                       li,glob,ret2);
1095       ret=ret || ret2;
1096       result.push_back(eltToAdd);
1097       offset2+=nbEntityElts*nbi;
1098     }
1099   ret=ret || li.empty();
1100   return ret;
1101 }
1102
1103 /*!
1104  * \param [in] typeF type of field of new chunk
1105  * \param [in] geoType the geometric type of the chunk
1106  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
1107  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
1108  * \param [in] nbi number of integration points
1109  * \param [in] offset The offset in the **global array of data**.
1110  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
1111  *                 to the new chunk to create.
1112  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
1113  * \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
1114  *              and corresponding entry erased from \a entriesOnSameDisc.
1115  * \return a newly allocated chunk
1116  */
1117 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
1118                                                                                                   bool isPfl, int nbi, int offset,
1119                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1120                                                                                                   MEDFileFieldGlobsReal& glob,
1121                                                                                                   bool &notInExisting)
1122 {
1123   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1124   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1125   for(;it!=entriesOnSameDisc.end();it++)
1126     {
1127       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1128         {
1129           if(!isPfl)
1130             {
1131               if((*it)->_profile.empty())
1132                 break;
1133               else
1134                 if(!(*it)->_profile.empty())
1135                   {
1136                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1137                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1138                       break;
1139                   }
1140             }
1141         }
1142     }
1143   if(it==entriesOnSameDisc.end())
1144     {
1145       notInExisting=true;
1146       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1147       ret->_type=typeF;
1148       ret->_loc_id=(int)geoType;
1149       ret->_nval=nbMeshEntities;
1150       ret->_start=offset;
1151       ret->_end=ret->_start+ret->_nval*nbi;
1152       if(isPfl)
1153         {
1154           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1155           glob.appendProfile(idsOfMeshElt);
1156           ret->_profile=idsOfMeshElt->getName();
1157         }
1158       //tony treatment of localization
1159       return ret;
1160     }
1161   else
1162     {
1163       notInExisting=false;
1164       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1165       ret->_loc_id=(int)geoType;
1166       ret->setNewStart(offset);
1167       entriesOnSameDisc.erase(it);
1168       return ret;
1169     }
1170
1171 }
1172
1173 ////////////////////////////////////
1174
1175 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1176 {
1177 }
1178
1179 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1180 {
1181   _father=father;
1182 }
1183
1184 void MEDFileFieldPerMeshPerTypeCommon::accept(MEDFileFieldVisitor& visitor) const
1185 {
1186   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1187     if((*it).isNotNull())
1188       {
1189         visitor.newPerMeshPerTypePerDisc(*it);
1190       }
1191 }
1192
1193 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1194 {
1195   std::size_t i=0;
1196   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1197     {
1198       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1199         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1200     }
1201 }
1202
1203 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1204 {
1205   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1206 }
1207
1208 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1209 {
1210   std::vector<const BigMemoryObject *> ret;
1211   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1212     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1213   return ret;
1214 }
1215
1216 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1217 {
1218   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1219   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1220     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1221 }
1222
1223 /*!
1224  * This method is the most general one. No optimization is done here.
1225  * \param [in] multiTypePfl is the end user profile specified in high level API
1226  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1227  * \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.
1228  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1229  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1230  * \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.
1231  */
1232 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)
1233 {
1234   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1235   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1236     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1237 }
1238
1239 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1240 {
1241   _field_pm_pt_pd.resize(1);
1242   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1243   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1244 }
1245
1246 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1247 {
1248   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1249   if(!arr || !arr->isAllocated())
1250     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1251   _field_pm_pt_pd.resize(1);
1252   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1253   _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.
1254 }
1255
1256 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells)
1257 {
1258   TypeOfField type=field->getTypeOfField();
1259   if(type!=ON_GAUSS_PT)
1260     {
1261       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1262       int sz=_field_pm_pt_pd.size();
1263       bool found=false;
1264       for(int j=0;j<sz && !found;j++)
1265         {
1266           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1267             {
1268               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1269               found=true;
1270             }
1271         }
1272       if(!found)
1273         {
1274           _field_pm_pt_pd.resize(sz+1);
1275           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1276         }
1277       std::vector<int> ret(1,(int)sz);
1278       return ret;
1279     }
1280   else
1281     {
1282       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1283       int sz2=ret2.size();
1284       std::vector<int> ret3(sz2);
1285       int k=0;
1286       for(int i=0;i<sz2;i++)
1287         {
1288           int sz=_field_pm_pt_pd.size();
1289           int locIdToFind=ret2[i];
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                   ret3[k++]=j;
1297                   found=true;
1298                 }
1299             }
1300           if(!found)
1301             {
1302               _field_pm_pt_pd.resize(sz+1);
1303               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1304               ret3[k++]=sz;
1305             }
1306         }
1307       return ret3;
1308     }
1309 }
1310
1311 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells)
1312 {
1313   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1314   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1315   if(!disc2)
1316     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1317   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1318   if(!da)
1319     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1320   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1321   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1322   if(retTmp->presenceOfValue(-1))
1323     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1324   std::vector<int> ret(retTmp->begin(),retTmp->end());
1325   return ret;
1326 }
1327
1328 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells)
1329 {
1330   TypeOfField type=field->getTypeOfField();
1331   if(type!=ON_GAUSS_PT)
1332     {
1333       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1334       int sz=_field_pm_pt_pd.size();
1335       bool found=false;
1336       for(int j=0;j<sz && !found;j++)
1337         {
1338           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1339             {
1340               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1341               found=true;
1342             }
1343         }
1344       if(!found)
1345         {
1346           _field_pm_pt_pd.resize(sz+1);
1347           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1348         }
1349       std::vector<int> ret(1,0);
1350       return ret;
1351     }
1352   else
1353     {
1354       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1355       int sz2=ret2.size();
1356       std::vector<int> ret3(sz2);
1357       int k=0;
1358       for(int i=0;i<sz2;i++)
1359         {
1360           int sz=_field_pm_pt_pd.size();
1361           int locIdToFind=ret2[i];
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                   ret3[k++]=j;
1369                   found=true;
1370                 }
1371             }
1372           if(!found)
1373             {
1374               _field_pm_pt_pd.resize(sz+1);
1375               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1376               ret3[k++]=sz;
1377             }
1378         }
1379       return ret3;
1380     }
1381 }
1382
1383 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells)
1384 {
1385   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1386   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1387   if(!disc2)
1388     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1389   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1390   if(!da)
1391     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1392   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1393   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1394   if(retTmp->presenceOfValue(-1))
1395     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1396   std::vector<int> ret(retTmp->begin(),retTmp->end());
1397   return ret;
1398 }
1399
1400 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1401 {
1402   return _father;
1403 }
1404
1405 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1406 {
1407   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1408   int curDim((int)cm.getDimension());
1409   if(dim!=std::numeric_limits<int>::max())
1410     {
1411       if(dim!=curDim)
1412         return false;
1413     }
1414   else
1415     dim=curDim;
1416   return true;
1417 }
1418
1419 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1420 {
1421   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1422     {
1423       (*it)->fillTypesOfFieldAvailable(types);
1424     }
1425 }
1426
1427 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
1428 {
1429   int sz=_field_pm_pt_pd.size();
1430   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1431   for(int i=0;i<sz;i++)
1432     {
1433       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1434     }
1435 }
1436
1437 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1438 {
1439   return _father->getIteration();
1440 }
1441
1442 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1443 {
1444   return _father->getOrder();
1445 }
1446
1447 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1448 {
1449   return _father->getTime();
1450 }
1451
1452 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1453 {
1454   return _father->getMeshName();
1455 }
1456
1457 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1458 {
1459   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1460     {
1461       globalSz+=(*it)->getNumberOfTuples();
1462     }
1463   nbOfEntries+=(int)_field_pm_pt_pd.size();
1464 }
1465
1466 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1467 {
1468   return _father->getNumberOfComponents();
1469 }
1470
1471 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1472 {
1473   std::size_t nb(0);
1474   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1475     {
1476       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1477       if(fmtd)
1478         nb++;
1479     }
1480   return nb>1;
1481 }
1482
1483 void MEDFileFieldPerMeshPerTypeCommon::pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc)
1484 {
1485   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt;
1486   elt.takeRef(disc);
1487   _field_pm_pt_pd.push_back(elt);
1488 }
1489
1490 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1491 {
1492   return _father->getOrCreateAndGetArray();
1493 }
1494
1495 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1496 {
1497   const MEDFileFieldPerMesh *fath=_father;
1498   return fath->getOrCreateAndGetArray();
1499 }
1500
1501 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1502 {
1503   return _father->getInfo();
1504 }
1505
1506 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1507 {
1508   std::vector<std::string> ret;
1509   std::set<std::string> ret2;
1510   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1511     {
1512       std::string tmp=(*it1)->getProfile();
1513       if(!tmp.empty())
1514         if(ret2.find(tmp)==ret2.end())
1515           {
1516             ret.push_back(tmp);
1517             ret2.insert(tmp);
1518           }
1519     }
1520   return ret;
1521 }
1522
1523 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1524 {
1525   std::vector<std::string> ret;
1526   std::set<std::string> ret2;
1527   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1528     {
1529       std::string tmp=(*it1)->getLocalization();
1530       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1531         if(ret2.find(tmp)==ret2.end())
1532           {
1533             ret.push_back(tmp);
1534             ret2.insert(tmp);
1535           }
1536     }
1537   return ret;
1538 }
1539
1540 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1541 {
1542   std::vector<std::string> ret;
1543   std::set<std::string> ret2;
1544   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1545     {
1546       std::string tmp=(*it1)->getProfile();
1547       if(!tmp.empty())
1548         ret.push_back(tmp);
1549     }
1550   return ret;
1551 }
1552
1553 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1554 {
1555   std::vector<std::string> ret;
1556   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1557     {
1558       std::string tmp=(*it1)->getLocalization();
1559       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1560         ret.push_back(tmp);
1561     }
1562   return ret;
1563 }
1564
1565 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1566 {
1567   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1568     (*it1)->changePflsRefsNamesGen(mapOfModif);
1569 }
1570
1571 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1572 {
1573   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1574     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1575 }
1576
1577 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1578 {
1579   if(_field_pm_pt_pd.empty())
1580     {
1581       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1582       throw INTERP_KERNEL::Exception(oss.str());
1583     }
1584   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1585     return _field_pm_pt_pd[locId];
1586   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1587   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1588   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1589   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1590 }
1591
1592 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1593 {
1594   if(_field_pm_pt_pd.empty())
1595     {
1596       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1597       throw INTERP_KERNEL::Exception(oss.str());
1598     }
1599   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1600     return _field_pm_pt_pd[locId];
1601   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1602   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1603   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1604   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1605 }
1606
1607 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1608 {
1609   int i=0;
1610   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1611     {
1612       (*it)->fillValues(i,startEntryId,entries);
1613     }
1614 }
1615
1616 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1617 {
1618   _field_pm_pt_pd=leaves;
1619   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1620     (*it)->setFather(this);
1621 }
1622
1623 /*!
1624  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1625  *  \param [out] its - list of pair (start,stop) kept
1626  *  \return bool - false if the type of field \a tof is not contained in \a this.
1627  */
1628 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1629 {
1630   bool ret(false);
1631   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1632   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1633     if((*it)->getType()==tof)
1634       {
1635         newPmPtPd.push_back(*it);
1636         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1637         (*it)->setNewStart(globalNum);
1638         globalNum=(*it)->getEnd();
1639         its.push_back(bgEnd);
1640         ret=true;
1641       }
1642   if(ret)
1643     _field_pm_pt_pd=newPmPtPd;
1644   return ret;
1645 }
1646
1647 /*!
1648  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1649  *  \param [out] its - list of pair (start,stop) kept
1650  *  \return bool - false if the type of field \a tof is not contained in \a this.
1651  */
1652 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1653 {
1654   if(_field_pm_pt_pd.size()<=idOfDisc)
1655     return false;
1656   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1657   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1658   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1659   elt->setNewStart(globalNum);
1660   globalNum=elt->getEnd();
1661   its.push_back(bgEnd);
1662   _field_pm_pt_pd=newPmPtPd;
1663   return true;
1664 }
1665
1666 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1667 {
1668   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1669     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1670 }
1671
1672 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1673 {
1674   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1675     (*it)->loadBigArray(fid,nasc);
1676 }
1677
1678 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1679 {
1680   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1681     {
1682       (*it)->copyOptionsFrom(*this);
1683       (*it)->writeLL(fid,nasc);
1684     }
1685 }
1686
1687 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1688 {
1689   switch(ikType)
1690   {
1691     case ON_CELLS:
1692       medfGeoType=typmai3[(int)ikGeoType];
1693       return MED_CELL;
1694     case ON_NODES:
1695       medfGeoType=MED_NONE;
1696       return MED_NODE;
1697     case ON_GAUSS_NE:
1698       medfGeoType=typmai3[(int)ikGeoType];
1699       return MED_NODE_ELEMENT;
1700     case ON_GAUSS_PT:
1701       medfGeoType=typmai3[(int)ikGeoType];
1702       return MED_CELL;
1703     default:
1704       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1705   }
1706   return MED_UNDEF_ENTITY_TYPE;
1707 }
1708
1709 //////////////////////////////////////////////////
1710
1711 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1712 {
1713   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1714 }
1715
1716 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1717 {
1718   return new MEDFileFieldPerMeshPerType(fath,geoType);
1719 }
1720
1721 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1722 {
1723   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1724   ret->setFather(father);
1725   ret->deepCopyElements();
1726   return ret.retn();
1727 }
1728
1729 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
1730 {
1731   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1732     {
1733       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1734       if(meshDim!=(int)cm.getDimension())
1735         return ;
1736     }
1737   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1738     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1739 }
1740
1741 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1742 {
1743   return _geo_type;
1744 }
1745
1746 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1747 {
1748   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1749 }
1750
1751 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1752 {
1753   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1754   int curDim((int)cm.getDimension());
1755   dim=std::max(dim,curDim);
1756 }
1757
1758 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1759 {
1760   const char startLine[]="  ## ";
1761   std::string startLine2(bkOffset,' ');
1762   std::string startLine3(startLine2);
1763   startLine3+=startLine;
1764   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1765     {
1766       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1767       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1768     }
1769   else
1770     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1771   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1772   int i=0;
1773   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1774     {
1775       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1776       if(cur)
1777         cur->simpleRepr(bkOffset,oss,i);
1778       else
1779         {
1780           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1781         }
1782     }
1783 }
1784
1785 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1786 {
1787   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1788   return std::string(cm.getRepr());
1789 }
1790
1791 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1792 {
1793 }
1794
1795 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1796 {
1797   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1798   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1799   med_geometry_type mgeoti;
1800   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1801   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1802   _field_pm_pt_pd.resize(nbProfiles);
1803   for(int i=0;i<nbProfiles;i++)
1804     {
1805       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1806     }
1807   if(type==ON_CELLS)
1808     {
1809       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1810       for(int i=0;i<nbProfiles2;i++)
1811         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1812     }
1813 }
1814
1815 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)
1816 {
1817   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1818   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1819   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1820     {
1821       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1822         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1823     }
1824   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1825     {
1826       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1827       ret->_field_pm_pt_pd.push_back(agg);
1828     }
1829   return ret;
1830 }
1831
1832 //////////////////////////////////////////////////
1833
1834 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1835 {
1836   if(!entities)
1837     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1838   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1839   if(!entities2)
1840     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1841   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1842   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1843 }
1844
1845 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1846 {
1847   _se.takeRef(se);
1848   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1849   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1850   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1851   _field_pm_pt_pd.resize(nbProfiles);
1852   for(int i=0;i<nbProfiles;i++)
1853     {
1854       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1855     }
1856 }
1857
1858 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1859 {
1860   return _se->getDynGT();
1861 }
1862
1863 std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const
1864 {
1865   return _se->getName();
1866 }
1867
1868 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1869 {
1870   throw INTERP_KERNEL::Exception("not implemented yet !");
1871 }
1872
1873 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1874 {
1875   gt=getDynGT();
1876   ent=MED_STRUCT_ELEMENT;
1877 }
1878
1879 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1880 {
1881   throw INTERP_KERNEL::Exception("not implemented yet !");
1882 }
1883
1884 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1885 {
1886   const char startLine[]="  ## ";
1887   std::string startLine2(bkOffset,' ');
1888   std::string startLine3(startLine2);
1889   startLine3+=startLine;
1890   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1891   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1892   int i=0;
1893   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1894     {
1895       if((*it).isNotNull())
1896         (*it)->simpleRepr(bkOffset,oss,i);
1897       else
1898         {
1899           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1900         }
1901     }
1902 }
1903
1904 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1905 {
1906   throw INTERP_KERNEL::Exception("not implemented yet !");
1907 }
1908
1909 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1910 {
1911   MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1912   ret->setFather(father);
1913   ret->deepCopyElements();
1914   return ret.retn();
1915 }
1916
1917 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
1918 {
1919   throw INTERP_KERNEL::Exception("not implemented yet !");
1920 }
1921
1922 //////////////////////////////////////////////////
1923
1924 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1925 {
1926   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1927 }
1928
1929 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1930 {
1931   return new MEDFileFieldPerMesh(fath,mesh);
1932 }
1933
1934 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1935 {
1936   return _field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1937 }
1938
1939 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1940 {
1941   std::vector<const BigMemoryObject *> ret;
1942   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1943     ret.push_back(*it);
1944   return ret;
1945 }
1946
1947 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1948 {
1949   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1950   ret->_father=father;
1951   std::size_t i=0;
1952   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1953     {
1954       if((*it).isNotNull())
1955         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1956     }
1957   return ret.retn();
1958 }
1959
1960 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1961 {
1962   std::string startLine(bkOffset,' ');
1963   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << getMeshName() << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1964   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1965   int i=0;
1966   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1967     {
1968       if((*it).isNotNull())
1969         (*it)->simpleRepr(bkOffset,oss,i);
1970       else
1971         {
1972           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1973         }
1974     }
1975 }
1976
1977 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1978 {
1979   mesh->getTime(_mesh_iteration,_mesh_order);
1980 }
1981
1982 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1983 {
1984   int nbOfTypes=code.size()/3;
1985   int offset=0;
1986   for(int i=0;i<nbOfTypes;i++)
1987     {
1988       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1989       int nbOfCells=code[3*i+1];
1990       int pos=addNewEntryIfNecessary(type);
1991       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1992       offset+=nbOfCells;
1993     }
1994 }
1995
1996 /*!
1997  * This method is the most general one. No optimization is done here.
1998  * \param [in] multiTypePfl is the end user profile specified in high level API
1999  * \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].
2000  * \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.
2001  * \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.
2002  * \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.
2003  * \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.
2004  */
2005 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)
2006 {
2007   int nbOfTypes(code.size()/3);
2008   for(int i=0;i<nbOfTypes;i++)
2009     {
2010       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
2011       int pos=addNewEntryIfNecessary(type);
2012       DataArrayInt *pfl=0;
2013       if(code[3*i+2]!=-1)
2014         pfl=idsPerType[code[3*i+2]];
2015       int nbOfTupes2=code2.size()/3;
2016       int found=0;
2017       for(;found<nbOfTupes2;found++)
2018         if(code[3*i]==code2[3*found])
2019           break;
2020       if(found==nbOfTupes2)
2021         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
2022       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
2023     }
2024 }
2025
2026 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
2027 {
2028   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2029   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
2030 }
2031
2032 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2033 {
2034   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2035   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
2036 }
2037
2038 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
2039 {
2040   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2041     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
2042 }
2043
2044 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
2045 {
2046   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2047     (*it)->loadBigArraysRecursively(fid,nasc);
2048 }
2049
2050 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
2051 {
2052   int nbOfTypes=_field_pm_pt.size();
2053   for(int i=0;i<nbOfTypes;i++)
2054     {
2055       _field_pm_pt[i]->copyOptionsFrom(*this);
2056       _field_pm_pt[i]->writeLL(fid,nasc);
2057     }
2058 }
2059
2060 void MEDFileFieldPerMesh::getDimension(int& dim) const
2061 {
2062   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2063     (*it)->getDimension(dim);
2064 }
2065
2066 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
2067 {
2068   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2069     if(!(*it)->isUniqueLevel(dim))
2070       return false;
2071   return true;
2072 }
2073
2074 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
2075 {
2076   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2077     (*it)->fillTypesOfFieldAvailable(types);
2078 }
2079
2080 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
2081 {
2082   int sz=_field_pm_pt.size();
2083   std::vector< std::vector<std::pair<int,int> > > ret(sz);
2084   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
2085   for(int i=0;i<sz;i++)
2086     {
2087       types[i]=_field_pm_pt[i]->getGeoType();
2088       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
2089     }
2090   return ret;
2091 }
2092
2093 double MEDFileFieldPerMesh::getTime() const
2094 {
2095   int tmp1,tmp2;
2096   return _father->getTime(tmp1,tmp2);
2097 }
2098
2099 int MEDFileFieldPerMesh::getIteration() const
2100 {
2101   return _father->getIteration();
2102 }
2103
2104 int MEDFileFieldPerMesh::getOrder() const
2105 {
2106   return _father->getOrder();
2107 }
2108
2109 int MEDFileFieldPerMesh::getNumberOfComponents() const
2110 {
2111   return _father->getNumberOfComponents();
2112 }
2113
2114 std::string MEDFileFieldPerMesh::getMeshName() const
2115 {
2116   return _father->getMeshName();
2117 }
2118
2119 void MEDFileFieldPerMesh::setMeshName(const std::string& meshName)
2120 {
2121   _father->setMeshName(meshName);
2122 }
2123
2124 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
2125 {
2126   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2127     {
2128       if((*it).isNull())
2129         continue;
2130       if((*it)->presenceOfMultiDiscPerGeoType())
2131         return true;
2132     }
2133   return false;
2134 }
2135
2136 bool MEDFileFieldPerMesh::presenceOfStructureElements() const
2137 {
2138   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2139     if((*it).isNotNull())
2140       {
2141         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2142         if(pt)
2143           return true;
2144       }
2145   return false;
2146 }
2147
2148 bool MEDFileFieldPerMesh::onlyStructureElements() const
2149 {
2150   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2151     if((*it).isNotNull())
2152       {
2153         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2154         if(!pt)
2155           return false;
2156       }
2157   return true;
2158 }
2159
2160 void MEDFileFieldPerMesh::killStructureElements()
2161 {
2162   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2163   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2164     {
2165       if((*it).isNotNull())
2166         {
2167           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2168           if(!pt)
2169             res.push_back(*it);
2170         }
2171     }
2172   _field_pm_pt=res;
2173 }
2174
2175 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2176 {
2177   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2178   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2179     {
2180       if((*it).isNotNull())
2181         {
2182           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2183           if(pt)
2184             res.push_back(*it);
2185         }
2186     }
2187   _field_pm_pt=res;
2188 }
2189
2190 void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName)
2191 {
2192   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2193   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2194     {
2195       if((*it).isNotNull())
2196         {
2197           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2198           if(!pt)
2199             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !");
2200           if(pt->getModelName()==seName)
2201             res.push_back(*it);
2202         }
2203     }
2204   _field_pm_pt=res;
2205 }
2206
2207 void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
2208 {
2209   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2210     {
2211       if((*it).isNotNull())
2212         {
2213           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2214           if(pt)
2215             {
2216               ps.push_back(std::pair<std::string,std::string>(getMeshName(),pt->getModelName()));
2217             }
2218           else
2219             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !");
2220         }
2221     }
2222 }
2223
2224 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2225 {
2226   if(!_father)
2227     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2228   return _father->getOrCreateAndGetArray();
2229 }
2230
2231 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2232 {
2233   if(!_father)
2234     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2235   return _father->getOrCreateAndGetArray();
2236 }
2237
2238 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2239 {
2240   return _father->getInfo();
2241 }
2242
2243 /*!
2244  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2245  * 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.
2246  * It returns 2 output vectors :
2247  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2248  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2249  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2250  */
2251 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)
2252 {
2253   int notNullPflsSz=0;
2254   int nbOfArrs=geoTypes.size();
2255   for(int i=0;i<nbOfArrs;i++)
2256     if(pfls[i])
2257       notNullPflsSz++;
2258   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2259   int nbOfDiffGeoTypes=geoTypes3.size();
2260   code.resize(3*nbOfDiffGeoTypes);
2261   notNullPfls.resize(notNullPflsSz);
2262   notNullPflsSz=0;
2263   int j=0;
2264   for(int i=0;i<nbOfDiffGeoTypes;i++)
2265     {
2266       int startZone=j;
2267       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2268       std::vector<const DataArrayInt *> notNullTmp;
2269       if(pfls[j])
2270         notNullTmp.push_back(pfls[j]);
2271       j++;
2272       for(;j<nbOfArrs;j++)
2273         if(geoTypes[j]==refType)
2274           {
2275             if(pfls[j])
2276               notNullTmp.push_back(pfls[j]);
2277           }
2278         else
2279           break;
2280       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2281       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2282       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2283       code[3*i]=(int)refType;
2284       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2285       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2286       if(notNullTmp.empty())
2287         code[3*i+2]=-1;
2288       else
2289         {
2290           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2291           code[3*i+2]=notNullPflsSz++;
2292         }
2293     }
2294 }
2295
2296 /*!
2297  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2298  */
2299 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)
2300 {
2301   int sz=dads.size();
2302   int ret=0;
2303   for(int i=0;i<sz;i++)
2304     {
2305       if(locs[i]==-1)
2306         {
2307           if(type!=ON_GAUSS_NE)
2308             ret+=dads[i].second-dads[i].first;
2309           else
2310             {
2311               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2312               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2313             }
2314         }
2315       else
2316         {
2317           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2318           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2319         }
2320     }
2321   return ret;
2322 }
2323
2324 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2325 {
2326   std::vector<std::string> ret;
2327   std::set<std::string> ret2;
2328   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2329     {
2330       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2331       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2332         if(ret2.find(*it2)==ret2.end())
2333           {
2334             ret.push_back(*it2);
2335             ret2.insert(*it2);
2336           }
2337     }
2338   return ret;
2339 }
2340
2341 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2342 {
2343   std::vector<std::string> ret;
2344   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2345     {
2346       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2347       ret.insert(ret.end(),tmp.begin(),tmp.end());
2348     }
2349   return ret;
2350 }
2351
2352 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2353 {
2354   std::vector<std::string> ret;
2355   std::set<std::string> ret2;
2356   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2357     {
2358       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2359       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2360         if(ret2.find(*it2)==ret2.end())
2361           {
2362             ret.push_back(*it2);
2363             ret2.insert(*it2);
2364           }
2365     }
2366   return ret;
2367 }
2368
2369 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2370 {
2371   std::vector<std::string> ret;
2372   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2373     {
2374       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2375       ret.insert(ret.end(),tmp.begin(),tmp.end());
2376     }
2377   return ret;
2378 }
2379
2380 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2381 {
2382   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2383     {
2384       if((*it).first==getMeshName())
2385         {
2386           setMeshName((*it).second);
2387           return true;
2388         }
2389     }
2390   return false;
2391 }
2392
2393 void MEDFileFieldPerMesh::convertMedBallIntoClassic()
2394 {
2395   if(_field_pm_pt.size()!=1)
2396     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : Only managed for single mesh !");
2397   if(_field_pm_pt[0].isNull())
2398     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : null pointer !");
2399   MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<MEDFileFieldPerMeshPerTypeDyn *>((MEDFileFieldPerMeshPerTypeCommon *)_field_pm_pt[0]));
2400   if(!pt)
2401     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : this is expected to be marked as structure element !");
2402   if(pt->getNumberOfLoc()!=1)
2403     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : only one loc managed !");
2404   const MEDFileFieldPerMeshPerTypePerDisc *disc(pt->getLeafGivenLocId(0));
2405   if(!disc)
2406     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : internal error !");
2407   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> disc2(MEDFileFieldPerMeshPerTypePerDisc::New(*disc));
2408   disc2->setType(ON_NODES);
2409   MCAuto<MEDFileFieldPerMeshPerType> pt2(MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR));
2410   disc2->setFather(pt2);
2411   pt2->setFather(this);
2412   pt2->pushDiscretization(disc2);
2413   _field_pm_pt[0]=DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(pt2);
2414 }
2415
2416 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2417                                                       MEDFileFieldGlobsReal& glob)
2418 {
2419   if(getMeshName()!=meshName)
2420     return false;
2421   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2422   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2423   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2424   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2425   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2426   getUndergroundDataArrayExt(entries);
2427   DataArray *arr0(getOrCreateAndGetArray());//tony
2428   if(!arr0)
2429     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2430   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2431   if(!arr0)
2432     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2433   int sz=0;
2434   if(!arr)
2435     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2436   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2437     {
2438       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2439         {
2440           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2441           sz+=(*it).second.second-(*it).second.first;
2442         }
2443       else
2444         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2445     }
2446   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2447   ////////////////////
2448   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2449   int *workI2=explicitIdsOldInMesh->getPointer();
2450   int sz1=0,sz2=0,sid=1;
2451   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2452   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2453   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2454     {
2455       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2456       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2457       int *workI=explicitIdsOldInArr->getPointer();
2458       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2459         {
2460           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2461           (*itL2)->setLocId(sz2);
2462           (*itL2)->_tmp_work1=(*itL2)->getStart();
2463           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2464         }
2465       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2466     }
2467   explicitIdsOldInMesh->reAlloc(sz2);
2468   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2469   ////////////////////
2470   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2471   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2472   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2473   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2474     {
2475       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2476       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2477       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2478     }
2479   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2480   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2481   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2482     {
2483       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2484       int newStart=elt->getLocId();
2485       elt->setLocId((*it)->getGeoType());
2486       elt->setNewStart(newStart);
2487       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2488       entriesKeptNew.push_back(elt);
2489       entriesKeptNew2.push_back(elt);
2490     }
2491   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2492   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2493   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2494   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2495   bool ret=false;
2496   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2497     {
2498       sid=0;
2499       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2500         {
2501           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2502           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2503           }*/
2504       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2505                                                             glob,arr2,otherEntriesNew) || ret;
2506     }
2507   if(!ret)
2508     return false;
2509   // Assign new dispatching
2510   assignNewLeaves(otherEntriesNew);
2511   arr->deepCopyFrom(*arr2);
2512   return true;
2513 }
2514
2515 /*!
2516  * \param [in,out] globalNum a global numbering counter for the renumbering.
2517  * \param [out] its - list of pair (start,stop) kept
2518  */
2519 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2520 {
2521   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2522   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2523     {
2524       std::vector< std::pair<int,int> > its2;
2525       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2526         {
2527           ret.push_back(*it);
2528           its.insert(its.end(),its2.begin(),its2.end());
2529         }
2530     }
2531   _field_pm_pt=ret;
2532 }
2533
2534 /*!
2535  * \param [in,out] globalNum a global numbering counter for the renumbering.
2536  * \param [out] its - list of pair (start,stop) kept
2537  */
2538 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2539 {
2540   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2541   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2542     {
2543       std::vector< std::pair<int,int> > its2;
2544       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2545         {
2546           ret.push_back(*it);
2547           its.insert(its.end(),its2.begin(),its2.end());
2548         }
2549     }
2550   _field_pm_pt=ret;
2551 }
2552
2553 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2554 {
2555   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2556   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2557     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2558   //
2559   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2560   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2561   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2562   for(;it1!=types.end();it1++,it2++)
2563     {
2564       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2565       elt->setLeaves((*it1).second);
2566       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2567       *it2=elt2;
2568     }
2569   _field_pm_pt=fieldPmPt;
2570 }
2571
2572 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2573 {
2574   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2575     (*it)->changePflsRefsNamesGen(mapOfModif);
2576 }
2577
2578 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2579 {
2580   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2581     (*it)->changeLocsRefsNamesGen(mapOfModif);
2582 }
2583
2584 /*!
2585  * \param [in] mesh is the whole mesh
2586  */
2587 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2588 {
2589   if(_field_pm_pt.empty())
2590     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2591   //
2592   std::vector< std::pair<int,int> > dads;
2593   std::vector<const DataArrayInt *> pfls;
2594   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2595   std::vector<int> locs,code;
2596   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2597   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2598     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2599   // Sort by types
2600   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2601   if(code.empty())
2602     {
2603       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2604       throw INTERP_KERNEL::Exception(oss.str());
2605     }
2606   //
2607   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2608   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2609   if(type!=ON_NODES)
2610     {
2611       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2612       if(!arr)
2613         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2614       else
2615         {
2616           MCAuto<DataArrayInt> arr2(arr);
2617           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2618         }
2619     }
2620   else
2621     {
2622       if(code.size()!=3)
2623         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2624       int nb=code[1];
2625       if(code[2]==-1)
2626         {
2627           if(nb!=mesh->getNumberOfNodes())
2628             {
2629               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2630               oss << " nodes in mesh !";
2631               throw INTERP_KERNEL::Exception(oss.str());
2632             }
2633           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2634         }
2635       else
2636         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2637     }
2638 }
2639
2640 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2641 {
2642   if(_field_pm_pt.empty())
2643     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2644   //
2645   std::vector<std::pair<int,int> > dads;
2646   std::vector<const DataArrayInt *> pfls;
2647   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2648   std::vector<int> locs,code;
2649   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2650   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2651     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2652   // Sort by types
2653   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2654   if(code.empty())
2655     {
2656       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2657       throw INTERP_KERNEL::Exception(oss.str());
2658     }
2659   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2660   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2661   if(type!=ON_NODES)
2662     {
2663       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2664       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2665     }
2666   else
2667     {
2668       if(code.size()!=3)
2669         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2670       int nb=code[1];
2671       if(code[2]==-1)
2672         {
2673           if(nb!=mesh->getNumberOfNodes())
2674             {
2675               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2676               oss << " nodes in mesh !";
2677               throw INTERP_KERNEL::Exception(oss.str());
2678             }
2679         }
2680       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2681     }
2682   //
2683   return 0;
2684 }
2685
2686 void MEDFileFieldPerMesh::accept(MEDFileFieldVisitor& visitor) const
2687 {
2688   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2689     if((*it).isNotNull())
2690       {
2691         visitor.newPerMeshPerTypeEntry(*it);
2692         (*it)->accept(visitor);
2693         visitor.endPerMeshPerTypeEntry(*it);
2694       }
2695 }
2696
2697 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2698 {
2699   int globalSz=0;
2700   int nbOfEntries=0;
2701   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2702     {
2703       (*it)->getSizes(globalSz,nbOfEntries);
2704     }
2705   entries.resize(nbOfEntries);
2706   nbOfEntries=0;
2707   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2708     {
2709       (*it)->fillValues(nbOfEntries,entries);
2710     }
2711 }
2712
2713 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2714 {
2715   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2716     {
2717       if((*it)->getGeoType()==typ)
2718         return (*it)->getLeafGivenLocId(locId);
2719     }
2720   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2721   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2722   oss << "Possiblities are : ";
2723   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2724     {
2725       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2726       oss << "\"" << cm2.getRepr() << "\", ";
2727     }
2728   throw INTERP_KERNEL::Exception(oss.str());
2729 }
2730
2731 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2732 {
2733   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2734     {
2735       if((*it)->getGeoType()==typ)
2736         return (*it)->getLeafGivenLocId(locId);
2737     }
2738   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2739   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2740   oss << "Possiblities are : ";
2741   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2742     {
2743       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2744       oss << "\"" << cm2.getRepr() << "\", ";
2745     }
2746   throw INTERP_KERNEL::Exception(oss.str());
2747 }
2748
2749 /*!
2750  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2751  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2752  * \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.
2753  * \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.
2754  */
2755 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)
2756 {
2757   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2758   if(pms.empty())
2759     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2760   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2761     {
2762       if(!(*it).second)
2763         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2764       if(!(*it).second->getProfile().empty())
2765         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2766       if(!(*it).second->getLocalization().empty())
2767         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2768     }
2769   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2770   std::size_t i(0);
2771   std::vector< std::pair<int,int> > filteredDTS;
2772   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2773     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2774       if((*it2).first==gt)
2775         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2776   if(pms.size()!=filteredDTS.size())
2777     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2778   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2779   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2780   int zeStart(start),nval(0);
2781   for(;it1!=pms.end();it1++,it2++)
2782     {
2783       if((*it1).first!=(*it2).first)
2784         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2785       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2786       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2787       start+=e1-s1;
2788       nval+=((*it1).second)->getNumberOfVals();
2789     }
2790   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2791   return ret;
2792 }
2793
2794 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)
2795 {
2796   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2797   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2798   std::size_t i(0);
2799   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2800     {
2801       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2802       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2803         {
2804           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2805           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2806           if(!elt)
2807             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2808           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2809         }
2810     }
2811   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2812     {
2813       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2814       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2815       ret->_field_pm_pt.push_back(agg2);
2816     }
2817   return ret;
2818 }
2819
2820 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2821 {
2822   int i=0;
2823   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2824   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2825   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2826     {
2827       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2828       if(type==curType)
2829         return i;
2830       else
2831         {
2832           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2833           if(pos>pos2)
2834             it2=it+1;
2835         }
2836     }
2837   int ret=std::distance(_field_pm_pt.begin(),it2);
2838   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2839   return ret;
2840 }
2841
2842 /*!
2843  * 'dads' and 'locs' input parameters have the same number of elements
2844  * \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
2845  */
2846 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2847                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2848                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2849 {
2850   isPfl=false;
2851   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2852   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2853   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2854   const std::vector<std::string>& infos=getInfo();
2855   da->setInfoOnComponents(infos);
2856   da->setName("");
2857   if(type==ON_GAUSS_PT)
2858     {
2859       int offset=0;
2860       int nbOfArrs=dads.size();
2861       for(int i=0;i<nbOfArrs;i++)
2862         {
2863           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2864           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2865           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2866           MCAuto<DataArrayInt> di=DataArrayInt::New();
2867           di->alloc(nbOfElems,1);
2868           di->iota(offset);
2869           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2870           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2871           offset+=nbOfElems;
2872         }
2873     }
2874   arrOut=da;
2875   return ret.retn();
2876 }
2877
2878 /*!
2879  * 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.
2880  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2881  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2882  * The order of cells in the returned field is those imposed by the profile.
2883  * \param [in] mesh is the global mesh.
2884  */
2885 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2886                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2887                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2888                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2889 {
2890   if(da->isIota(mesh->getNumberOfCells()))
2891     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2892   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2893   m2->setName(mesh->getName().c_str());
2894   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2895   isPfl=true;
2896   return ret.retn();
2897 }
2898
2899 /*!
2900  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2901  */
2902 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2903                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2904                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2905 {
2906   if(da->isIota(mesh->getNumberOfNodes()))
2907     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2908   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2909   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2910   if(meshu)
2911     {
2912       if(meshu->getNodalConnectivity()==0)
2913         {
2914           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2915           int nb=da->getNbOfElems();
2916           const int *ptr=da->getConstPointer();
2917           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2918           meshuc->allocateCells(nb);
2919           for(int i=0;i<nb;i++)
2920             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2921           meshuc->finishInsertingCells();
2922           ret->setMesh(meshuc);
2923           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2924           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2925           disc->checkCoherencyBetween(meshuc,arrOut);
2926           return ret.retn();
2927         }
2928     }
2929   //
2930   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2931   isPfl=true;
2932   DataArrayInt *arr2=0;
2933   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2934   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2935   MCAuto<DataArrayInt> arr3(arr2);
2936   int nnodes=mesh2->getNumberOfNodes();
2937   if(nnodes==(int)da->getNbOfElems())
2938     {
2939       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2940       arrOut->renumberInPlace(da3->getConstPointer());
2941       mesh2->setName(mesh->getName().c_str());
2942       ret->setMesh(mesh2);
2943       return ret.retn();
2944     }
2945   else
2946     {
2947       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 !!!";
2948       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2949       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2950       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2951       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2952       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2953       throw INTERP_KERNEL::Exception(oss.str());
2954     }
2955   return 0;
2956 }
2957
2958 /*!
2959  * This method is the most light method of field retrieving.
2960  */
2961 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2962 {
2963   if(!pflIn)
2964     {
2965       pflOut=DataArrayInt::New();
2966       pflOut->alloc(nbOfElems,1);
2967       pflOut->iota(0);
2968     }
2969   else
2970     {
2971       pflOut=const_cast<DataArrayInt*>(pflIn);
2972       pflOut->incrRef();
2973     }
2974   MCAuto<DataArrayInt> safePfl(pflOut);
2975   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2976   const std::vector<std::string>& infos=getInfo();
2977   int nbOfComp=infos.size();
2978   for(int i=0;i<nbOfComp;i++)
2979     da->setInfoOnComponent(i,infos[i].c_str());
2980   safePfl->incrRef();
2981   return da.retn();
2982 }
2983
2984
2985 /// @cond INTERNAL
2986
2987 class MFFPMIter
2988 {
2989 public:
2990   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2991   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2992   virtual ~MFFPMIter() { }
2993   virtual void begin() = 0;
2994   virtual bool finished() const = 0;
2995   virtual void next() = 0;
2996   virtual int current() const = 0;
2997 };
2998
2999 class MFFPMIterSimple : public MFFPMIter
3000 {
3001 public:
3002   MFFPMIterSimple():_pos(0) { }
3003   void begin() { _pos=0; }
3004   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
3005   void next() { _pos++; }
3006   int current() const { return _pos; }
3007 private:
3008   int _pos;
3009 };
3010
3011 class MFFPMIter2 : public MFFPMIter
3012 {
3013 public:
3014   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
3015   void begin() { _it=_ids.begin(); }
3016   bool finished() const { return _it==_ids.end(); }
3017   void next() { _it++; }
3018   int current() const { return *_it; }
3019 private:
3020   std::vector<int> _ids;
3021   std::vector<int>::const_iterator _it;
3022 };
3023
3024 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
3025 {
3026   if(!entities)
3027     return new MFFPMIterSimple;
3028   else
3029     {
3030       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3031       if(entities2)
3032         {
3033           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
3034           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3035           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3036             {
3037               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
3038                 tmp.push_back((*it).second);
3039             }
3040           return new MFFPMIter2(tmp);
3041         }
3042       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
3043     }
3044 }
3045
3046 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
3047 {
3048   if(!entities)
3049     return true;
3050   else
3051     {
3052       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3053       if(entities2)
3054         {
3055           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3056           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3057             if((*it).first==ON_NODES)
3058               return true;
3059           return false;
3060         }
3061       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
3062     }
3063 }
3064
3065 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
3066 {
3067   std::size_t sz(cts.size());
3068   _ids.resize(sz);
3069   for(std::size_t i=0;i<sz;i++)
3070     {
3071       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
3072       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
3073         _ids[i]=(int)std::distance(typmai2,loc);
3074       else
3075         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
3076     }
3077 }
3078
3079 /// @endcond
3080
3081 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),
3082     _father(fath)
3083 {
3084   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3085   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3086   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3087   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
3088   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
3089   for(iter0->begin();!iter0->finished();iter0->next())
3090     {
3091       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3092       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3093       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3094       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3095       if(nbProfile>0 || nbProfile2>0)
3096         {
3097           const PartDefinition *pd(0);
3098           if(mmu)
3099             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
3100           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
3101           if(nbProfile>0)
3102             setMeshName(name0);
3103           else
3104             setMeshName(name1);
3105         }
3106     }
3107   if(MFFPMIter::IsPresenceOfNode(entities))
3108     {
3109       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
3110       if(nbProfile>0)
3111         {
3112           const PartDefinition *pd(0);
3113           if(mmu)
3114             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
3115           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
3116           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3117         }
3118     }
3119   if(!entities)
3120     return ;
3121   std::vector<int> dynGT(entities->getDynGTAvail());
3122   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
3123     {
3124       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
3125       if(nbPfl>0)
3126         {
3127           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
3128           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3129         }
3130     }
3131 }
3132
3133 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
3134 {
3135   copyTinyInfoFrom(mesh);
3136 }
3137
3138 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3139 {
3140   if(id>=(int)_pfls.size())
3141     _pfls.resize(id+1);
3142   _pfls[id]=DataArrayInt::New();
3143   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
3144   _pfls[id]->setName(pflName);
3145   _pfls[id]->alloc(lgth,1);
3146   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
3147   _pfls[id]->applyLin(1,-1,0);//Converting into C format
3148 }
3149
3150 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
3151 {
3152   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3153   int sz;
3154   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
3155   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
3156   if(i>=(int)_pfls.size())
3157     _pfls.resize(i+1);
3158   _pfls[i]=DataArrayInt::New();
3159   _pfls[i]->alloc(sz,1);
3160   _pfls[i]->setName(pflCpp.c_str());
3161   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
3162   _pfls[i]->applyLin(1,-1,0);//Converting into C format
3163 }
3164
3165 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3166 {
3167   int nbOfPfls=_pfls.size();
3168   for(int i=0;i<nbOfPfls;i++)
3169     {
3170       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
3171       cpy->applyLin(1,1,0);
3172       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3173       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
3174       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
3175     }
3176   //
3177   int nbOfLocs=_locs.size();
3178   for(int i=0;i<nbOfLocs;i++)
3179     _locs[i]->writeLL(fid);
3180 }
3181
3182 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
3183 {
3184   std::vector<std::string> pfls=getPfls();
3185   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
3186     {
3187       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
3188       if(it2==pfls.end())
3189         {
3190           _pfls.push_back(*it);
3191         }
3192       else
3193         {
3194           int id=std::distance(pfls.begin(),it2);
3195           if(!(*it)->isEqual(*_pfls[id]))
3196             {
3197               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3198               throw INTERP_KERNEL::Exception(oss.str());
3199             }
3200         }
3201     }
3202   std::vector<std::string> locs=getLocs();
3203   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
3204     {
3205       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
3206       if(it2==locs.end())
3207         {
3208           _locs.push_back(*it);
3209         }
3210       else
3211         {
3212           int id=std::distance(locs.begin(),it2);
3213           if(!(*it)->isEqual(*_locs[id],eps))
3214             {
3215               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3216               throw INTERP_KERNEL::Exception(oss.str());
3217             }
3218         }
3219     }
3220 }
3221
3222 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
3223 {
3224   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
3225     getProfile((*it).c_str());
3226 }
3227
3228 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
3229 {
3230   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
3231     getLocalization((*it).c_str());
3232 }
3233
3234 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
3235 {
3236   std::vector<std::string> profiles=real.getPflsReallyUsed();
3237   int sz=profiles.size();
3238   _pfls.resize(sz);
3239   for(int i=0;i<sz;i++)
3240     loadProfileInFile(fid,i,profiles[i].c_str());
3241   //
3242   std::vector<std::string> locs=real.getLocsReallyUsed();
3243   sz=locs.size();
3244   _locs.resize(sz);
3245   for(int i=0;i<sz;i++)
3246     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
3247 }
3248
3249 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3250 {
3251   int nProfil=MEDnProfile(fid);
3252   for(int i=0;i<nProfil;i++)
3253     loadProfileInFile(fid,i);
3254   int sz=MEDnLocalization(fid);
3255   _locs.resize(sz);
3256   for(int i=0;i<sz;i++)
3257     {
3258       _locs[i]=MEDFileFieldLoc::New(fid,i,entities);
3259     }
3260 }
3261
3262 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
3263 {
3264   return new MEDFileFieldGlobs(fid);
3265 }
3266
3267 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
3268 {
3269   return new MEDFileFieldGlobs;
3270 }
3271
3272 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
3273 {
3274   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
3275 }
3276
3277 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
3278 {
3279   std::vector<const BigMemoryObject *> ret;
3280   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3281     ret.push_back((const DataArrayInt *)*it);
3282   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3283     ret.push_back((const MEDFileFieldLoc *)*it);
3284   return ret;
3285 }
3286
3287 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3288 {
3289   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3290   std::size_t i=0;
3291   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3292     {
3293       if((const DataArrayInt *)*it)
3294         ret->_pfls[i]=(*it)->deepCopy();
3295     }
3296   i=0;
3297   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3298     {
3299       if((const MEDFileFieldLoc*)*it)
3300         ret->_locs[i]=(*it)->deepCopy();
3301     }
3302   return ret.retn();
3303 }
3304
3305 /*!
3306  * \throw if a profile in \a pfls in not in \a this.
3307  * \throw if a localization in \a locs in not in \a this.
3308  * \sa MEDFileFieldGlobs::deepCpyPart
3309  */
3310 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3311 {
3312   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3313   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3314     {
3315       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3316       if(!pfl)
3317         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3318       pfl->incrRef();
3319       MCAuto<DataArrayInt> pfl2(pfl);
3320       ret->_pfls.push_back(pfl2);
3321     }
3322   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3323     {
3324       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3325       if(!loc)
3326         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3327       loc->incrRef();
3328       MCAuto<MEDFileFieldLoc> loc2(loc);
3329       ret->_locs.push_back(loc2);
3330     }
3331   ret->setFileName(getFileName());
3332   return ret.retn();
3333 }
3334
3335 /*!
3336  * \throw if a profile in \a pfls in not in \a this.
3337  * \throw if a localization in \a locs in not in \a this.
3338  * \sa MEDFileFieldGlobs::shallowCpyPart
3339  */
3340 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3341 {
3342   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3343   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3344     {
3345       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3346       if(!pfl)
3347         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3348       ret->_pfls.push_back(pfl->deepCopy());
3349     }
3350   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3351     {
3352       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3353       if(!loc)
3354         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3355       ret->_locs.push_back(loc->deepCopy());
3356     }
3357   ret->setFileName(getFileName());
3358   return ret.retn();
3359 }
3360
3361 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3362 {
3363 }
3364
3365 MEDFileFieldGlobs::MEDFileFieldGlobs()
3366 {
3367 }
3368
3369 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3370 {
3371 }
3372
3373 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3374 {
3375   oss << "Profiles :\n";
3376   std::size_t n=_pfls.size();
3377   for(std::size_t i=0;i<n;i++)
3378     {
3379       oss << "  - #" << i << " ";
3380       const DataArrayInt *pfl=_pfls[i];
3381       if(pfl)
3382         oss << "\"" << pfl->getName() << "\"\n";
3383       else
3384         oss << "EMPTY !\n";
3385     }
3386   n=_locs.size();
3387   oss << "Localizations :\n";
3388   for(std::size_t i=0;i<n;i++)
3389     {
3390       oss << "  - #" << i << " ";
3391       const MEDFileFieldLoc *loc=_locs[i];
3392       if(loc)
3393         loc->simpleRepr(oss);
3394       else
3395         oss<< "EMPTY !\n";
3396     }
3397 }
3398
3399 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3400 {
3401   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3402     {
3403       DataArrayInt *elt(*it);
3404       if(elt)
3405         {
3406           std::string name(elt->getName());
3407           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3408             {
3409               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3410                 {
3411                   elt->setName((*it2).second.c_str());
3412                   return;
3413                 }
3414             }
3415         }
3416     }
3417 }
3418
3419 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3420 {
3421   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3422     {
3423       MEDFileFieldLoc *elt(*it);
3424       if(elt)
3425         {
3426           std::string name(elt->getName());
3427           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3428             {
3429               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3430                 {
3431                   elt->setName((*it2).second.c_str());
3432                   return;
3433                 }
3434             }
3435         }
3436     }
3437 }
3438
3439 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3440 {
3441   if(locId<0 || locId>=(int)_locs.size())
3442     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3443   return _locs[locId]->getNbOfGaussPtPerCell();
3444 }
3445
3446 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3447 {
3448   return getLocalizationFromId(getLocalizationId(locName));
3449 }
3450
3451 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3452 {
3453   if(locId<0 || locId>=(int)_locs.size())
3454     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3455   return *_locs[locId];
3456 }
3457
3458 /// @cond INTERNAL
3459 namespace MEDCouplingImpl
3460 {
3461   class LocFinder
3462   {
3463   public:
3464     LocFinder(const std::string& loc):_loc(loc) { }
3465     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3466   private:
3467     const std::string &_loc;
3468   };
3469
3470   class PflFinder
3471   {
3472   public:
3473     PflFinder(const std::string& pfl):_pfl(pfl) { }
3474     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3475   private:
3476     const std::string& _pfl;
3477   };
3478 }
3479 /// @endcond
3480
3481 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3482 {
3483   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3484   if(it==_locs.end())
3485     {
3486       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3487       for(it=_locs.begin();it!=_locs.end();it++)
3488         oss << "\"" << (*it)->getName() << "\", ";
3489       throw INTERP_KERNEL::Exception(oss.str());
3490     }
3491   return std::distance(_locs.begin(),it);
3492 }
3493
3494 /*!
3495  * The returned value is never null.
3496  */
3497 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3498 {
3499   std::string pflNameCpp(pflName);
3500   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3501   if(it==_pfls.end())
3502     {
3503       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3504       for(it=_pfls.begin();it!=_pfls.end();it++)
3505         oss << "\"" << (*it)->getName() << "\", ";
3506       throw INTERP_KERNEL::Exception(oss.str());
3507     }
3508   return *it;
3509 }
3510
3511 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3512 {
3513   if(pflId<0 || pflId>=(int)_pfls.size())
3514     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3515   return _pfls[pflId];
3516 }
3517
3518 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3519 {
3520   if(locId<0 || locId>=(int)_locs.size())
3521     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3522   return *_locs[locId];
3523 }
3524
3525 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3526 {
3527   return getLocalizationFromId(getLocalizationId(locName));
3528 }
3529
3530 /*!
3531  * The returned value is never null.
3532  */
3533 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3534 {
3535   std::string pflNameCpp(pflName);
3536   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3537   if(it==_pfls.end())
3538     {
3539       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3540       for(it=_pfls.begin();it!=_pfls.end();it++)
3541         oss << "\"" << (*it)->getName() << "\", ";
3542       throw INTERP_KERNEL::Exception(oss.str());
3543     }
3544   return *it;
3545 }
3546
3547 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3548 {
3549   if(pflId<0 || pflId>=(int)_pfls.size())
3550     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3551   return _pfls[pflId];
3552 }
3553
3554 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3555 {
3556   std::vector< MCAuto<DataArrayInt> > newPfls;
3557   int i=0;
3558   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3559     {
3560       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3561         newPfls.push_back(*it);
3562     }
3563   _pfls=newPfls;
3564 }
3565
3566 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3567 {
3568   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3569   int i=0;
3570   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3571     {
3572       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3573         newLocs.push_back(*it);
3574     }
3575   _locs=newLocs;
3576 }
3577
3578 void MEDFileFieldGlobs::killStructureElementsInGlobs()
3579 {
3580   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3581   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3582     {
3583       if((*it).isNull())
3584         continue;
3585       if(!(*it)->isOnStructureElement())
3586         newLocs.push_back(*it);
3587     }
3588   _locs=newLocs;
3589 }
3590
3591 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3592 {
3593   int sz=_pfls.size();
3594   std::vector<std::string> ret(sz);
3595   for(int i=0;i<sz;i++)
3596     ret[i]=_pfls[i]->getName();
3597   return ret;
3598 }
3599
3600 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3601 {
3602   int sz=_locs.size();
3603   std::vector<std::string> ret(sz);
3604   for(int i=0;i<sz;i++)
3605     ret[i]=_locs[i]->getName();
3606   return ret;
3607 }
3608
3609 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3610 {
3611   std::vector<std::string> v=getPfls();
3612   std::string s(pflName);
3613   return std::find(v.begin(),v.end(),s)!=v.end();
3614 }
3615
3616 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3617 {
3618   std::vector<std::string> v=getLocs();
3619   std::string s(locName);
3620   return std::find(v.begin(),v.end(),s)!=v.end();
3621 }
3622
3623 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3624 {
3625   std::map<int,std::vector<int> > m;
3626   int i=0;
3627   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3628     {
3629       const DataArrayInt *tmp=(*it);
3630       if(tmp)
3631         {
3632           m[tmp->getHashCode()].push_back(i);
3633         }
3634     }
3635   std::vector< std::vector<int> > ret;
3636   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3637     {
3638       if((*it2).second.size()>1)
3639         {
3640           std::vector<int> ret0;
3641           bool equalityOrNot=false;
3642           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3643             {
3644               std::vector<int>::const_iterator it4=it3; it4++;
3645               for(;it4!=(*it2).second.end();it4++)
3646                 {
3647                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3648                     {
3649                       if(!equalityOrNot)
3650                         ret0.push_back(*it3);
3651                       ret0.push_back(*it4);
3652                       equalityOrNot=true;
3653                     }
3654                 }
3655             }
3656           if(!ret0.empty())
3657             ret.push_back(ret0);
3658         }
3659     }
3660   return ret;
3661 }
3662
3663 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3664 {
3665   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3666 }
3667
3668 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3669 {
3670   std::string name(pfl->getName());
3671   if(name.empty())
3672     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3673   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3674     if(name==(*it)->getName())
3675       {
3676         if(!pfl->isEqual(*(*it)))
3677           {
3678             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3679             throw INTERP_KERNEL::Exception(oss.str());
3680           }
3681       }
3682   pfl->incrRef();
3683   _pfls.push_back(pfl);
3684 }
3685
3686 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)
3687 {
3688   std::string name(locName);
3689   if(name.empty())
3690     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3691   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3692   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3693     if((*it)->isName(locName))
3694       {
3695         if(!(*it)->isEqual(*obj,1e-12))
3696           {
3697             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3698             throw INTERP_KERNEL::Exception(oss.str());
3699           }
3700       }
3701   _locs.push_back(obj);
3702 }
3703
3704 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3705 {
3706   std::vector<std::string> names=getPfls();
3707   return CreateNewNameNotIn("NewPfl_",names);
3708 }
3709
3710 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3711 {
3712   std::vector<std::string> names=getLocs();
3713   return CreateNewNameNotIn("NewLoc_",names);
3714 }
3715
3716 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3717 {
3718   for(std::size_t sz=0;sz<100000;sz++)
3719     {
3720       std::ostringstream tryName;
3721       tryName << prefix << sz;
3722       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3723         return tryName.str();
3724     }
3725   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3726 }
3727
3728 /*!
3729  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3730  *  \param [in] fname - the file name.
3731  */
3732 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3733 {
3734 }
3735
3736 /*!
3737  * Creates an empty MEDFileFieldGlobsReal.
3738  */
3739 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3740 {
3741 }
3742
3743 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3744 {
3745   return 0;
3746 }
3747
3748 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3749 {
3750   std::vector<const BigMemoryObject *> ret;
3751   ret.push_back((const MEDFileFieldGlobs *)_globals);
3752   return ret;
3753 }
3754
3755 /*!
3756  * Returns a string describing profiles and Gauss points held in \a this.
3757  *  \return std::string - the description string.
3758  */
3759 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3760 {
3761   const MEDFileFieldGlobs *glob=_globals;
3762   std::ostringstream oss2; oss2 << glob;
3763   std::string stars(oss2.str().length(),'*');
3764   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3765   if(glob)
3766     glob->simpleRepr(oss);
3767   else
3768     oss << "NO GLOBAL INFORMATION !\n";
3769 }
3770
3771 void MEDFileFieldGlobsReal::resetContent()
3772 {
3773   _globals=MEDFileFieldGlobs::New();
3774 }
3775
3776 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
3777 {
3778   contentNotNull()->killStructureElementsInGlobs();
3779 }
3780
3781 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3782 {
3783 }
3784
3785 /*!
3786  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3787  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3788  */
3789 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3790 {
3791   _globals=other._globals;
3792 }
3793
3794 /*!
3795  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3796  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3797  */
3798 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3799 {
3800   const MEDFileFieldGlobs *otherg(other._globals);
3801   if(!otherg)
3802     return ;
3803   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3804 }
3805
3806 /*!
3807  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3808  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3809  */
3810 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3811 {
3812   const MEDFileFieldGlobs *otherg(other._globals);
3813   if(!otherg)
3814     return ;
3815   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3816 }
3817
3818 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3819 {
3820   _globals=other._globals;
3821   if((const MEDFileFieldGlobs *)_globals)
3822     _globals=other._globals->deepCopy();
3823 }
3824
3825 /*!
3826  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3827  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3828  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3829  *         \a this and \a other MEDFileFieldGlobsReal.
3830  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3831  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3832  */
3833 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3834 {
3835   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3836   if(thisGlobals==otherGlobals)
3837     return ;
3838   if(!thisGlobals)
3839     {
3840       _globals=other._globals;
3841       return ;
3842     }
3843   _globals->appendGlobs(*other._globals,eps);
3844 }
3845
3846 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3847 {
3848   checkGlobsPflsPartCoherency();
3849   checkGlobsLocsPartCoherency();
3850 }
3851
3852 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3853 {
3854   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3855 }
3856
3857 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3858 {
3859   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3860 }
3861
3862 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3863 {
3864   contentNotNull()->loadProfileInFile(fid,id,pflName);
3865 }
3866
3867 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3868 {
3869   contentNotNull()->loadProfileInFile(fid,id);
3870 }
3871
3872 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3873 {
3874   contentNotNull()->loadGlobals(fid,*this);
3875 }
3876
3877 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3878 {
3879   contentNotNull()->loadAllGlobals(fid,entities);
3880 }
3881
3882 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3883 {
3884   contentNotNull()->writeGlobals(fid,opt);
3885 }
3886
3887 /*!
3888  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3889  * or getPflsReallyUsedMulti().
3890  *  \return std::vector<std::string> - a sequence of names of all profiles.
3891  */
3892 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3893 {
3894   return contentNotNull()->getPfls();
3895 }
3896
3897 /*!
3898  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3899  * or getLocsReallyUsedMulti().
3900  *  \return std::vector<std::string> - a sequence of names of all localizations.
3901  */
3902 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3903 {
3904   return contentNotNull()->getLocs();
3905 }
3906
3907 /*!
3908  * Checks if the profile with a given name exists.
3909  *  \param [in] pflName - the profile name of interest.
3910  *  \return bool - \c true if the profile named \a pflName exists.
3911  */
3912 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3913 {
3914   return contentNotNull()->existsPfl(pflName);
3915 }
3916
3917 /*!
3918  * Checks if the localization with a given name exists.
3919  *  \param [in] locName - the localization name of interest.
3920  *  \return bool - \c true if the localization named \a locName exists.
3921  */
3922 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3923 {
3924   return contentNotNull()->existsLoc(locName);
3925 }
3926
3927 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3928 {
3929   return contentNotNull()->createNewNameOfPfl();
3930 }
3931
3932 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3933 {
3934   return contentNotNull()->createNewNameOfLoc();
3935 }
3936
3937 /*!
3938  * Sets the name of a MED file.
3939  *  \param [inout] fileName - the file name.
3940  */
3941 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3942 {
3943   contentNotNull()->setFileName(fileName);
3944 }
3945
3946 /*!
3947  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3948  * in the same order.
3949  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3950  *          Each item of this sequence is a vector containing ids of equal profiles.
3951  */
3952 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3953 {
3954   return contentNotNull()->whichAreEqualProfiles();
3955 }
3956
3957 /*!
3958  * Finds equal localizations.
3959  *  \param [in] eps - a precision used to compare real values of the localizations.
3960  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3961  *          Each item of this sequence is a vector containing ids of equal localizations.
3962  */
3963 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3964 {
3965   return contentNotNull()->whichAreEqualLocs(eps);
3966 }
3967
3968 /*!
3969  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3970  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3971  *        this sequence is a pair whose 
3972  *        - the first item is a vector of profile names to replace by the second item,
3973  *        - the second item is a profile name to replace every profile name of the first item.
3974  */
3975 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3976 {
3977   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3978 }
3979
3980 /*!
3981  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3982  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3983  *        this sequence is a pair whose 
3984  *        - the first item is a vector of localization names to replace by the second item,
3985  *        - the second item is a localization name to replace every localization name of the first item.
3986  */
3987 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3988 {
3989   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3990 }
3991
3992 /*!
3993  * Replaces references to some profiles (a reference is a profile name) by references
3994  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3995  * them-selves accordingly. <br>
3996  * This method is a generalization of changePflName().
3997  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3998  *        this sequence is a pair whose 
3999  *        - the first item is a vector of profile names to replace by the second item,
4000  *        - the second item is a profile name to replace every profile of the first item.
4001  * \sa changePflsRefsNamesGen()
4002  * \sa changePflName()
4003  */
4004 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4005 {
4006   changePflsRefsNamesGen(mapOfModif);
4007   changePflsNamesInStruct(mapOfModif);
4008 }
4009
4010 /*!
4011  * Replaces references to some localizations (a reference is a localization name) by references
4012  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
4013  * them-selves accordingly. <br>
4014  * This method is a generalization of changeLocName().
4015  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
4016  *        this sequence is a pair whose 
4017  *        - the first item is a vector of localization names to replace by the second item,
4018  *        - the second item is a localization name to replace every localization of the first item.
4019  * \sa changeLocsRefsNamesGen()
4020  * \sa changeLocName()
4021  */
4022 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4023 {
4024   changeLocsRefsNamesGen(mapOfModif);
4025   changeLocsNamesInStruct(mapOfModif);
4026 }
4027
4028 /*!
4029  * Renames the profile having a given name and updates references to this profile.
4030  *  \param [in] oldName - the name of the profile to rename.
4031  *  \param [in] newName - a new name of the profile.
4032  * \sa changePflsNames().
4033  */
4034 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
4035 {
4036   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4037   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4038   mapOfModif[0]=p;
4039   changePflsNames(mapOfModif);
4040 }
4041
4042 /*!
4043  * Renames the localization having a given name and updates references to this localization.
4044  *  \param [in] oldName - the name of the localization to rename.
4045  *  \param [in] newName - a new name of the localization.
4046  * \sa changeLocsNames().
4047  */
4048 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
4049 {
4050   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4051   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4052   mapOfModif[0]=p;
4053   changeLocsNames(mapOfModif);
4054 }
4055
4056 /*!
4057  * Removes duplicated profiles. Returns a map used to update references to removed 
4058  * profiles via changePflsRefsNamesGen().
4059  * Equal profiles are found using whichAreEqualProfiles().
4060  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4061  *          a sequence describing the performed replacements of profiles. Each element of
4062  *          this sequence is a pair whose
4063  *          - the first item is a vector of profile names replaced by the second item,
4064  *          - the second item is a profile name replacing every profile of the first item.
4065  */
4066 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
4067 {
4068   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
4069   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4070   int i=0;
4071   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4072     {
4073       std::vector< std::string > tmp((*it).size());
4074       int j=0;
4075       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4076         tmp[j]=std::string(getProfileFromId(*it2)->getName());
4077       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4078       ret[i]=p;
4079       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4080       killProfileIds(tmp2);
4081     }
4082   changePflsRefsNamesGen(ret);
4083   return ret;
4084 }
4085
4086 /*!
4087  * Removes duplicated localizations. Returns a map used to update references to removed 
4088  * localizations via changeLocsRefsNamesGen().
4089  * Equal localizations are found using whichAreEqualLocs().
4090  *  \param [in] eps - a precision used to compare real values of the localizations.
4091  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4092  *          a sequence describing the performed replacements of localizations. Each element of
4093  *          this sequence is a pair whose
4094  *          - the first item is a vector of localization names replaced by the second item,
4095  *          - the second item is a localization name replacing every localization of the first item.
4096  */
4097 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
4098 {
4099   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
4100   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4101   int i=0;
4102   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4103     {
4104       std::vector< std::string > tmp((*it).size());
4105       int j=0;
4106       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4107         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
4108       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4109       ret[i]=p;
4110       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4111       killLocalizationIds(tmp2);
4112     }
4113   changeLocsRefsNamesGen(ret);
4114   return ret;
4115 }
4116
4117 /*!
4118  * Returns number of Gauss points per cell in a given localization.
4119  *  \param [in] locId - an id of the localization of interest.
4120  *  \return int - the number of the Gauss points per cell.
4121  */
4122 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
4123 {
4124   return contentNotNull()->getNbOfGaussPtPerCell(locId);
4125 }
4126
4127 /*!
4128  * Returns an id of a localization by its name.
4129  *  \param [in] loc - the localization name of interest.
4130  *  \return int - the id of the localization.
4131  *  \throw If there is no a localization named \a loc.
4132  */
4133 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
4134 {
4135   return contentNotNull()->getLocalizationId(loc);
4136 }
4137
4138 /*!
4139  * Returns the name of the MED file.
4140  *  \return const std::string&  - the MED file name.
4141  */
4142 std::string MEDFileFieldGlobsReal::getFileName() const
4143 {
4144   return contentNotNull()->getFileName();
4145 }
4146
4147 /*!
4148  * Returns a localization object by its name.
4149  *  \param [in] locName - the name of the localization of interest.
4150  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
4151  *  \throw If there is no a localization named \a locName.
4152  */
4153 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
4154 {
4155   return contentNotNull()->getLocalization(locName);
4156 }
4157
4158 /*!
4159  * Returns a localization object by its id.
4160  *  \param [in] locId - the id of the localization of interest.
4161  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
4162  *  \throw If there is no a localization with id \a locId.
4163  */
4164 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
4165 {
4166   return contentNotNull()->getLocalizationFromId(locId);
4167 }
4168
4169 /*!
4170  * Returns a profile array by its name.
4171  *  \param [in] pflName - the name of the profile of interest.
4172  *  \return const DataArrayInt * - the profile array having the name \a pflName.
4173  *  \throw If there is no a profile named \a pflName.
4174  */
4175 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
4176 {
4177   return contentNotNull()->getProfile(pflName);
4178 }
4179
4180 /*!
4181  * Returns a profile array by its id.
4182  *  \param [in] pflId - the id of the profile of interest.
4183  *  \return const DataArrayInt * - the profile array having the id \a pflId.
4184  *  \throw If there is no a profile with id \a pflId.
4185  */
4186 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
4187 {
4188   return contentNotNull()->getProfileFromId(pflId);
4189 }
4190
4191 /*!
4192  * Returns a localization object, apt for modification, by its id.
4193  *  \param [in] locId - the id of the localization of interest.
4194  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4195  *          having the id \a locId.
4196  *  \throw If there is no a localization with id \a locId.
4197  */
4198 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
4199 {
4200   return contentNotNull()->getLocalizationFromId(locId);
4201 }
4202
4203 /*!
4204  * Returns a localization object, apt for modification, by its name.
4205  *  \param [in] locName - the name of the localization of interest.
4206  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4207  *          having the name \a locName.
4208  *  \throw If there is no a localization named \a locName.
4209  */
4210 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
4211 {
4212   return contentNotNull()->getLocalization(locName);
4213 }
4214
4215 /*!
4216  * Returns a profile array, apt for modification, by its name.
4217  *  \param [in] pflName - the name of the profile of interest.
4218  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
4219  *  \throw If there is no a profile named \a pflName.
4220  */
4221 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
4222 {
4223   return contentNotNull()->getProfile(pflName);
4224 }
4225
4226 /*!
4227  * Returns a profile array, apt for modification, by its id.
4228  *  \param [in] pflId - the id of the profile of interest.
4229  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
4230  *  \throw If there is no a profile with id \a pflId.
4231  */
4232 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
4233 {
4234   return contentNotNull()->getProfileFromId(pflId);
4235 }
4236
4237 /*!
4238  * Removes profiles given by their ids. No data is updated to track this removal.
4239  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
4240  */
4241 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
4242 {
4243   contentNotNull()->killProfileIds(pflIds);
4244 }
4245
4246 /*!
4247  * Removes localizations given by their ids. No data is updated to track this removal.
4248  *  \param [in] locIds - a sequence of ids of the localizations to remove.
4249  */
4250 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
4251 {
4252   contentNotNull()->killLocalizationIds(locIds);
4253 }
4254
4255 /*!
4256  * Stores a profile array.
4257  *  \param [in] pfl - the profile array to store.
4258  *  \throw If the name of \a pfl is empty.
4259  *  \throw If a profile with the same name as that of \a pfl already exists but contains
4260  *         different ids.
4261  */
4262 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
4263 {
4264   contentNotNull()->appendProfile(pfl);
4265 }
4266
4267 /*!
4268  * Adds a new localization of Gauss points.
4269  *  \param [in] locName - the name of the new localization.
4270  *  \param [in] geoType - a geometrical type of the reference cell.
4271  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
4272  *         must be \c nbOfNodesPerCell * \c dimOfType.
4273  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
4274  *         must be  _wg_.size() * \c dimOfType.
4275  *  \param [in] w - the weights of Gauss points.
4276  *  \throw If \a locName is empty.
4277  *  \throw If a localization with the name \a locName already exists but is
4278  *         different form the new one.
4279  */
4280 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)
4281 {
4282   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
4283 }
4284
4285 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
4286 {
4287   MEDFileFieldGlobs *g(_globals);
4288   if(!g)
4289     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
4290   return g;
4291 }
4292
4293 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
4294 {
4295   const MEDFileFieldGlobs *g(_globals);
4296   if(!g)
4297     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4298   return g;
4299 }
4300
4301 //= MEDFileFieldNameScope
4302
4303 MEDFileFieldNameScope::MEDFileFieldNameScope()
4304 {
4305 }
4306
4307 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName):_name(fieldName),_mesh_name(meshName)
4308 {
4309 }
4310
4311 /*!
4312  * Returns the name of \a this field.
4313  *  \return std::string - a string containing the field name.
4314  */
4315 std::string MEDFileFieldNameScope::getName() const
4316 {
4317   return _name;
4318 }
4319
4320 /*!
4321  * Sets name of \a this field
4322  *  \param [in] name - the new field name.
4323  */
4324 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4325 {
4326   _name=fieldName;
4327 }
4328
4329 std::string MEDFileFieldNameScope::getDtUnit() const
4330 {
4331   return _dt_unit;
4332 }
4333
4334 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4335 {
4336   _dt_unit=dtUnit;
4337 }
4338
4339 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4340 {
4341   _name=other._name;
4342   _mesh_name=other._mesh_name;
4343   _dt_unit=other._dt_unit;
4344 }
4345
4346 /*!
4347  * Returns the mesh name.
4348  *  \return std::string - a string holding the mesh name.
4349  *  \throw If \c _field_per_mesh.empty()
4350  */
4351 std::string MEDFileFieldNameScope::getMeshName() const
4352 {
4353   return _mesh_name;
4354 }
4355
4356 void MEDFileFieldNameScope::setMeshName(const std::string& meshName)
4357 {
4358   _mesh_name=meshName;
4359 }
4360
4361 //= MEDFileAnyTypeField1TSWithoutSDA
4362
4363 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4364 {
4365   _field_per_mesh.resize(other._field_per_mesh.size());
4366   std::size_t i=0;
4367   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4368     {
4369       if((const MEDFileFieldPerMesh *)*it)
4370         _field_per_mesh[i]=(*it)->deepCopy(this);
4371     }
4372 }
4373
4374 void MEDFileAnyTypeField1TSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
4375 {
4376   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4377     if((*it).isNotNull())
4378       {
4379         visitor.newMeshEntry(*it);
4380         (*it)->accept(visitor);
4381         visitor.endMeshEntry(*it);
4382       }
4383 }
4384
4385 /*!
4386  * Prints a string describing \a this field into a stream. This string is outputted 
4387  * by \c print Python command.
4388  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4389  *  \param [in,out] oss - the out stream.
4390  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4391  *          info id printed, else, not.
4392  */
4393 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4394 {
4395   std::string startOfLine(bkOffset,' ');
4396   oss << startOfLine << "Field ";
4397   if(bkOffset==0)
4398     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4399   oss << "on one time Step ";
4400   if(f1tsId>=0)
4401     oss << "(" << f1tsId << ") ";
4402   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4403   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4404   const DataArray *arr=getUndergroundDataArray();
4405   if(arr)
4406     {
4407       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4408       if(f1tsId<0)
4409         {
4410           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4411           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4412             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4413         }
4414       if(arr->isAllocated())
4415         {
4416           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4417         }
4418       else
4419         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4420     }
4421   else
4422     {
4423       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4424     }
4425   oss << startOfLine << "----------------------" << std::endl;
4426   if(!_field_per_mesh.empty())
4427     {
4428       int i=0;
4429       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4430         {
4431           const MEDFileFieldPerMesh *cur=(*it2);
4432           if(cur)
4433             cur->simpleRepr(bkOffset,oss,i);
4434           else
4435             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4436         }
4437     }
4438   else
4439     {
4440       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4441     }
4442   oss << startOfLine << "----------------------" << std::endl;
4443 }
4444
4445 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4446 {
4447   const DataArray *arr(getUndergroundDataArray());
4448   if(!arr)
4449     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4450   int nbOfCompo=arr->getNumberOfComponents();
4451   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4452   for(int i=0;i<nbOfCompo;i++)
4453     {
4454       ret[i]=deepCopy();
4455       std::vector<int> v(1,i);
4456       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4457       ret[i]->setArray(arr2);
4458     }
4459   return ret;
4460 }
4461
4462 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)
4463 {
4464 }
4465
4466 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4467 {
4468 }
4469
4470 /*!
4471  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4472  * empty. Returns -1 if this in on nodes.
4473  *  \return int - the dimension of \a this.
4474  */
4475 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4476 {
4477   int ret=-2;
4478   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4479     (*it)->getDimension(ret);
4480   return ret;
4481 }
4482
4483 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4484 {
4485   bool ret=false;
4486   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4487     {
4488       MEDFileFieldPerMesh *cur(*it);
4489       if(cur)
4490         ret=cur->changeMeshNames(modifTab) || ret;
4491     }
4492   return ret;
4493 }
4494
4495 /*!
4496  * Returns the number of iteration of the state of underlying mesh.
4497  *  \return int - the iteration number.
4498  *  \throw If \c _field_per_mesh.empty()
4499  */
4500 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4501 {
4502   if(_field_per_mesh.empty())
4503     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4504   return _field_per_mesh[0]->getMeshIteration();
4505 }
4506
4507 /*!
4508  * Returns the order number of iteration of the state of underlying mesh.
4509  *  \return int - the order number.
4510  *  \throw If \c _field_per_mesh.empty()
4511  */
4512 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4513 {
4514   if(_field_per_mesh.empty())
4515     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4516   return _field_per_mesh[0]->getMeshOrder();
4517 }
4518
4519 /*!
4520  * Checks if \a this field is tagged by a given iteration number and a given
4521  * iteration order number.
4522  *  \param [in] iteration - the iteration number of interest.
4523  *  \param [in] order - the iteration order number of interest.
4524  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4525  *          \a this->getOrder() == \a order.
4526  */
4527 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4528 {
4529   return iteration==_iteration && order==_order;
4530 }
4531
4532 /*!
4533  * Returns number of iteration and order number of iteration when
4534  * \a this field has been calculated.
4535  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4536  *          order number.
4537  */
4538 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4539 {
4540   std::pair<int,int> p;
4541   fillIteration(p);
4542   return p;
4543 }
4544
4545 /*!
4546  * Returns number of iteration and order number of iteration when
4547  * \a this field has been calculated.
4548  *  \param [in,out] p - a pair returning the iteration number and the iteration
4549  *          order number.
4550  */
4551 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4552 {
4553   p.first=_iteration;
4554   p.second=_order;
4555 }
4556
4557 /*!
4558  * Returns all types of spatial discretization of \a this field.
4559  *  \param [in,out] types - a sequence of types of \a this field.
4560  */
4561 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4562 {
4563   std::set<TypeOfField> types2;
4564   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4565     {
4566       (*it)->fillTypesOfFieldAvailable(types2);
4567     }
4568   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4569   std::copy(types2.begin(),types2.end(),bi);
4570 }
4571
4572 /*!
4573  * Returns all types of spatial discretization of \a this field.
4574  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4575  *          of \a this field.
4576  */
4577 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4578 {
4579   std::vector<TypeOfField> ret;
4580   fillTypesOfFieldAvailable(ret);
4581   return ret;
4582 }
4583
4584 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4585 {
4586   std::vector<std::string> ret;
4587   std::set<std::string> ret2;
4588   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4589     {
4590       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4591       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4592         if(ret2.find(*it2)==ret2.end())
4593           {
4594             ret.push_back(*it2);
4595             ret2.insert(*it2);
4596           }
4597     }
4598   return ret;
4599 }
4600
4601 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4602 {
4603   std::vector<std::string> ret;
4604   std::set<std::string> ret2;
4605   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4606     {
4607       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4608       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4609         if(ret2.find(*it2)==ret2.end())
4610           {
4611             ret.push_back(*it2);
4612             ret2.insert(*it2);
4613           }
4614     }
4615   return ret;
4616 }
4617
4618 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4619 {
4620   std::vector<std::string> ret;
4621   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4622     {
4623       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4624       ret.insert(ret.end(),tmp.begin(),tmp.end());
4625     }
4626   return ret;
4627 }
4628
4629 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4630 {
4631   std::vector<std::string> ret;
4632   std::set<std::string> ret2;
4633   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4634     {
4635       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4636       ret.insert(ret.end(),tmp.begin(),tmp.end());
4637     }
4638   return ret;
4639 }
4640
4641 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4642 {
4643   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4644     (*it)->changePflsRefsNamesGen(mapOfModif);
4645 }
4646
4647 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4648 {
4649   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4650     (*it)->changeLocsRefsNamesGen(mapOfModif);
4651 }
4652
4653 /*!
4654  * Returns all attributes of parts of \a this field lying on a given mesh.
4655  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4656  * item of every of returned sequences refers to the _i_-th part of \a this field.
4657  * Thus all sequences returned by this method are of the same length equal to number
4658  * of different types of supporting entities.<br>
4659  * A field part can include sub-parts with several different spatial discretizations,
4660  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4661  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4662  * of a nested sequence corresponds to a type of spatial discretization.<br>
4663  * This method allows for iteration over MEDFile DataStructure without any overhead.
4664  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4665  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4666  *          not checked if \a mname == \c NULL).
4667  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4668  *          a field part is returned. 
4669  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4670  *          This sequence is of the same length as \a types. 
4671  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4672  *          discretization. A profile name can be empty.
4673  *          Length of this and of nested sequences is the same as that of \a typesF.
4674  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4675  *          discretization. A localization name can be empty.
4676  *          Length of this and of nested sequences is the same as that of \a typesF.
4677  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4678  *          of ids of tuples within the data array, per each type of spatial
4679  *          discretization within one mesh entity type. 
4680  *          Length of this and of nested sequences is the same as that of \a typesF.
4681  *  \throw If no field is lying on \a mname.
4682  */
4683 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
4684 {
4685   if(_field_per_mesh.empty())
4686     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4687   return _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4688 }
4689
4690 /*!
4691  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4692  * maximal absolute dimension and values returned via the out parameter \a levs are 
4693  * dimensions relative to the maximal absolute dimension. <br>
4694  * This method is designed for MEDFileField1TS instances that have a discretization
4695  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4696  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4697  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4698  * Only these 3 discretizations will be taken into account here. If \a this is
4699  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4700  * This method is useful to make the link between the dimension of the underlying mesh
4701  * and the levels of \a this, because it is possible that the highest dimension of \a this
4702  * field is not equal to the dimension of the underlying mesh.
4703  * 
4704  * Let's consider the following case:
4705  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4706  * TETRA4, HEXA8, TRI3 and SEG2.
4707  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4708  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4709  *
4710  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4711  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4712  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4713  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4714  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4715  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4716  * For example<br>
4717  * to retrieve the highest level of
4718  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4719  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4720  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4721  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4722  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4723  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4724  *          not checked if \a mname == \c NULL).
4725  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4726  *          absolute one. They are in decreasing order. This sequence is cleared before
4727  *          filling it in.
4728  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4729  *  \throw If no field is lying on \a mname.
4730  */
4731 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4732 {
4733   levs.clear();
4734   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4735   std::vector< std::vector<TypeOfField> > typesF;
4736   std::vector< std::vector<std::string> > pfls, locs;
4737   if(_field_per_mesh.empty())
4738     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels : This is empty !");
4739   _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4740   if(types.empty())
4741     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4742   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4743   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4744     return -1;
4745   st.erase(INTERP_KERNEL::NORM_ERROR);
4746   std::set<int> ret1;
4747   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4748     {
4749       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4750       ret1.insert((int)cm.getDimension());
4751     }
4752   int ret=*std::max_element(ret1.begin(),ret1.end());
4753   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4754   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4755   return ret;
4756 }
4757
4758 void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic()
4759 {
4760   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it<_field_per_mesh.end();it++)
4761     if((*it).isNotNull())
4762       (*it)->convertMedBallIntoClassic();
4763 }
4764
4765 void MEDFileAnyTypeField1TSWithoutSDA::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
4766 {
4767   if(!pfl)
4768     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : null pfl !");
4769   std::string name(pfl->getName());
4770   pfl->checkAllocated();
4771   if(pfl->getNumberOfComponents()!=1)
4772     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : non mono compo array !");
4773   if(name.empty())
4774     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : empty pfl name !");
4775   if(_field_per_mesh.size()!=1)
4776     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single mesh supported !");
4777   MCAuto<MEDFileFieldPerMesh> fpm(_field_per_mesh[0]);
4778   if(fpm.isNull())
4779     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single not null mesh supported !");
4780   MEDFileFieldPerMeshPerTypePerDisc *disc(fpm->getLeafGivenTypeAndLocId(ct,0));
4781   if(disc->getType()!=tof)
4782     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : error !");
4783   int s(disc->getStart()),e(disc->getEnd()),nt(pfl->getNumberOfTuples());
4784   DataArray *arr(getUndergroundDataArray());
4785   int nt2(arr->getNumberOfTuples()),delta((e-s)-nt);
4786   if(delta<0)
4787     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : internal error !");
4788   MCAuto<DataArray> arr0(arr->selectByTupleIdSafeSlice(0,s,1)),arr1(arr->selectByTupleIdSafeSlice(s,e,1)),arr2(arr->selectByTupleIdSafeSlice(e,nt2,1));
4789   MCAuto<DataArray> arr11(arr1->selectByTupleIdSafe(pfl->begin(),pfl->end()));
4790   MCAuto<DataArray> arrOut(arr->buildNewEmptyInstance());
4791   arrOut->alloc(nt2-delta,arr->getNumberOfComponents());
4792   arrOut->copyStringInfoFrom(*arr);
4793   arrOut->setContigPartOfSelectedValuesSlice(0,arr0,0,s,1);
4794   arrOut->setContigPartOfSelectedValuesSlice(s,arr11,0,nt,1);
4795   arrOut->setContigPartOfSelectedValuesSlice(e-delta,arr2,0,nt2-e,1);
4796   setArray(arrOut);
4797   disc->setEnd(e-delta);
4798   disc->setProfile(name);
4799 }
4800
4801 /*!
4802  * \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.
4803  * \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.
4804  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4805  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4806  */
4807 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4808 {
4809   if(_field_per_mesh.empty())
4810     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4811   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4812 }
4813
4814 /*!
4815  * \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.
4816  * \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.
4817  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4818  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4819  */
4820 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4821 {
4822   if(_field_per_mesh.empty())
4823     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4824   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4825 }
4826
4827 /*!
4828  * \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.
4829  */
4830 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4831 {
4832   if(_field_per_mesh.empty())
4833     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4834   if(mName.empty())
4835     return 0;
4836   std::string mName2(mName);
4837   int ret=0;
4838   std::vector<std::string> msg;
4839   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4840     if(mName2==(*it)->getMeshName())
4841       return ret;
4842     else
4843       msg.push_back((*it)->getMeshName());
4844   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4845   oss << "Possible meshes are : ";
4846   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4847     oss << "\"" << (*it2) << "\" ";
4848   throw INTERP_KERNEL::Exception(oss.str());
4849 }
4850
4851 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4852 {
4853   if(!mesh)
4854     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4855   std::string tmp(mesh->getName());
4856   if(tmp.empty())
4857     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4858   setMeshName(tmp);
4859   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4860   int i=0;
4861   for(;it!=_field_per_mesh.end();it++,i++)
4862     {
4863       if((*it)->getMeshName()==tmp)
4864         return i;
4865     }
4866   int sz=_field_per_mesh.size();
4867   _field_per_mesh.resize(sz+1);
4868   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4869   return sz;
4870 }
4871
4872 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4873                                                                    MEDFileFieldGlobsReal& glob)
4874 {
4875   bool ret=false;
4876   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4877     {
4878       MEDFileFieldPerMesh *fpm(*it);
4879       if(fpm)
4880         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4881     }
4882   return ret;
4883 }
4884
4885 /*!
4886  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4887  * splitting that leads to single spatial discretization of this.
4888  *
4889  * \sa splitMultiDiscrPerGeoTypes
4890  */
4891 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4892 {
4893   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4894   std::vector< std::vector<TypeOfField> > typesF;
4895   std::vector< std::vector<std::string> > pfls,locs;
4896   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4897   std::set<TypeOfField> allEnt;
4898   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4899     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4900       allEnt.insert(*it2);
4901   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4902   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4903   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4904     {
4905       std::vector< std::pair<int,int> > its;
4906       ret[i]=shallowCpy();
4907       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4908       ret[i]->updateData(newLgth,its);
4909     }
4910   return ret;
4911 }
4912
4913 /*!
4914  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4915  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4916  *
4917  * \sa splitDiscretizations
4918  */
4919 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4920 {
4921   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4922   std::vector< std::vector<TypeOfField> > typesF;
4923   std::vector< std::vector<std::string> > pfls,locs;
4924   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4925   std::set<TypeOfField> allEnt;
4926   std::size_t nbOfMDPGT(0),ii(0);
4927   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4928     {
4929       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4930       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4931         allEnt.insert(*it2);
4932     }
4933   if(allEnt.size()!=1)
4934     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4935   if(nbOfMDPGT==0)
4936     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4937   if(nbOfMDPGT==1)
4938     {
4939       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4940       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4941       return ret0;
4942     }
4943   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4944   for(std::size_t i=0;i<nbOfMDPGT;i++)
4945     {
4946       std::vector< std::pair<int,int> > its;
4947       ret[i]=shallowCpy();
4948       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4949       ret[i]->updateData(newLgth,its);
4950     }
4951   return ret;
4952 }
4953
4954 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4955 {
4956   int globalCounter(0);
4957   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4958     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4959   return globalCounter;
4960 }
4961
4962 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4963 {
4964   int globalCounter(0);
4965   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4966     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4967   return globalCounter;
4968 }
4969
4970 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4971 {
4972   if(_nb_of_tuples_to_be_allocated>=0)
4973     {
4974       _nb_of_tuples_to_be_allocated=newLgth;
4975       const DataArray *oldArr(getUndergroundDataArray());
4976       if(oldArr)
4977         {
4978           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4979           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4980           setArray(newArr);
4981           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4982         }
4983       return ;
4984     }
4985   if(_nb_of_tuples_to_be_allocated==-1)
4986     return ;
4987   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4988     {
4989       const DataArray *oldArr(getUndergroundDataArray());
4990       if(!oldArr || !oldArr->isAllocated())
4991         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4992       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4993       newArr->alloc(newLgth,getNumberOfComponents());
4994       if(oldArr)
4995         newArr->copyStringInfoFrom(*oldArr);
4996       int pos=0;
4997       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4998         {
4999           if((*it).second<(*it).first)
5000             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
5001           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
5002           pos+=(*it).second-(*it).first;
5003         }
5004       setArray(newArr);
5005       return ;
5006     }
5007   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
5008 }
5009
5010 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
5011 {
5012   if(_field_per_mesh.empty())
5013     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
5014   if(_field_per_mesh.size()>1)
5015     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
5016   _field_per_mesh[0]->copyOptionsFrom(opts);
5017   _field_per_mesh[0]->writeLL(fid,nasc);
5018 }
5019
5020 /*!
5021  * 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.
5022  * If false is returned the memory allocation is not required.
5023  */
5024 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
5025 {
5026   if(_nb_of_tuples_to_be_allocated>=0)
5027     {
5028       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
5029       _nb_of_tuples_to_be_allocated=-2;
5030       return true;
5031     }
5032   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
5033     return false;
5034   if(_nb_of_tuples_to_be_allocated==-1)
5035     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
5036   if(_nb_of_tuples_to_be_allocated<-3)
5037     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5038   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5039 }
5040
5041 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5042 {
5043   med_int numdt,numit;
5044   med_float dt;
5045   med_int meshnumdt,meshnumit;
5046   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
5047   {
5048     med_bool localMesh;
5049     med_int nmesh;
5050     INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
5051     MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit)); // to check with Adrien for legacy MED files
5052   }
5053   //MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt,&meshnumdt,&meshnumit));
5054   if(_iteration!=numdt || _order!=numit)
5055     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
5056   _field_per_mesh.resize(1);
5057   //
5058   MEDFileMesh *mm(0);
5059   if(ms)
5060     {
5061       mm=ms->getMeshWithName(getMeshName());
5062     }
5063   //
5064   _field_per_mesh[0]=MEDFileFieldPerMesh::NewOnRead(fid,this,0,meshnumdt,meshnumit,nasc,mm,entities);
5065   _nb_of_tuples_to_be_allocated=0;
5066   _field_per_mesh[0]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
5067 }
5068
5069 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
5070 {
5071   allocIfNecessaryTheArrayToReceiveDataFromFile();
5072   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5073     (*it)->loadBigArraysRecursively(fid,nasc);
5074 }
5075
5076 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
5077 {
5078   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
5079     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5080       (*it)->loadBigArraysRecursively(fid,nasc);
5081 }
5082
5083 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5084 {
5085   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
5086   loadBigArraysRecursively(fid,nasc);
5087 }
5088
5089 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
5090 {
5091   DataArray *thisArr(getUndergroundDataArray());
5092   if(thisArr && thisArr->isAllocated())
5093     {
5094       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
5095       thisArr->desallocate();
5096     }
5097 }
5098
5099 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
5100 {
5101   return _mesh_name.capacity()+_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
5102 }
5103
5104 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
5105 {
5106   std::vector<const BigMemoryObject *> ret;
5107   if(getUndergroundDataArray())
5108     ret.push_back(getUndergroundDataArray());
5109   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5110     ret.push_back((const MEDFileFieldPerMesh *)*it);
5111   return ret;
5112 }
5113
5114 /*!
5115  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
5116  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
5117  * "Sort By Type"), if not, an exception is thrown. 
5118  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
5119  *  \param [in] arr - the array of values.
5120  *  \param [in,out] glob - the global data where profiles and localization present in
5121  *          \a field, if any, are added.
5122  *  \throw If the name of \a field is empty.
5123  *  \throw If the data array of \a field is not set.
5124  *  \throw If \a this->_arr is already allocated but has different number of components
5125  *         than \a field.
5126  *  \throw If the underlying mesh of \a field has no name.
5127  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
5128  */
5129 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5130 {
5131   const MEDCouplingMesh *mesh(field->getMesh());
5132   //
5133   TypeOfField type(field->getTypeOfField());
5134   std::vector<DataArrayInt *> dummy;
5135   if(mesh)
5136     setMeshName(mesh->getName());
5137   int start(copyTinyInfoFrom(th,field,arr));
5138   int pos(addNewEntryIfNecessary(mesh));
5139   if(type!=ON_NODES)
5140     {
5141       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
5142       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
5143     }
5144   else
5145     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
5146 }
5147
5148 /*!
5149  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
5150  * of a given mesh are used as the support of the given field (a real support is not used). 
5151  * Elements of the given mesh must be sorted suitable for writing to MED file. 
5152  * Order of underlying mesh entities of the given field specified by \a profile parameter
5153  * is not prescribed; this method permutes field values to have them sorted by element
5154  * type as required for writing to MED file. A new profile is added only if no equal
5155  * profile is missing. 
5156  *  \param [in] field - the field to add to \a this. The field double values are ignored.
5157  *  \param [in] arrOfVals - the values of the field \a field used.
5158  *  \param [in] mesh - the supporting mesh of \a field.
5159  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
5160  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
5161  *  \param [in,out] glob - the global data where profiles and localization present in
5162  *          \a field, if any, are added.
5163  *  \throw If either \a field or \a mesh or \a profile has an empty name.
5164  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5165  *  \throw If the data array of \a field is not set.
5166  *  \throw If \a this->_arr is already allocated but has different number of components
5167  *         than \a field.
5168  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5169  *  \sa setFieldNoProfileSBT()
5170  */
5171 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)
5172 {
5173   if(!field)
5174     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
5175   if(!arrOfVals || !arrOfVals->isAllocated())
5176     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
5177   TypeOfField type=field->getTypeOfField();
5178   std::vector<DataArrayInt *> idsInPflPerType;
5179   std::vector<DataArrayInt *> idsPerType;
5180   std::vector<int> code,code2;
5181   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5182   if(type!=ON_NODES)
5183     {
5184       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
5185       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
5186       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
5187       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
5188       // start of check
5189       MCAuto<MEDCouplingFieldTemplate> field2=field->clone(false);
5190       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
5191       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5192         {
5193           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5194           throw INTERP_KERNEL::Exception(oss.str());
5195         }
5196       // end of check
5197       int start(copyTinyInfoFrom(th,field,arrOfVals));
5198       code2=m->getDistributionOfTypes();
5199       //
5200       int pos=addNewEntryIfNecessary(m);
5201       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
5202     }
5203   else
5204     {
5205       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
5206         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
5207       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
5208       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
5209       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
5210       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5211         {
5212           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5213           throw INTERP_KERNEL::Exception(oss.str());
5214         }
5215       int start(copyTinyInfoFrom(th,field,arrOfVals));
5216       int pos(addNewEntryIfNecessary(m));
5217       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
5218     }
5219 }
5220
5221 /*!
5222  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
5223  */
5224 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
5225 {
5226   if(_nb_of_tuples_to_be_allocated>=0)
5227     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 !");
5228   DataArray *arr(getOrCreateAndGetArray());
5229   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
5230   _nb_of_tuples_to_be_allocated=-3;
5231 }
5232
5233 /*!
5234  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
5235  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
5236  * larger by the size of \a field. Returns an id of the first not filled
5237  * tuple of \a this->_arr.
5238  *  \param [in] field - the field to copy the info on components and the name from.
5239  *  \return int - the id of first not initialized tuple of \a this->_arr.
5240  *  \throw If the name of \a field is empty.
5241  *  \throw If the data array of \a field is not set.
5242  *  \throw If \a this->_arr is already allocated but has different number of components
5243  *         than \a field.
5244  */
5245 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
5246 {
5247   if(!field)
5248     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
5249   std::string name(field->getName());
5250   setName(name.c_str());
5251   if(field->getMesh())
5252     setMeshName(field->getMesh()->getName());
5253   setDtUnit(th->getTimeUnit());
5254   if(name.empty())
5255     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
5256   if(!arr)
5257     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
5258   if(!arr->isAllocated())
5259     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
5260   _dt=th->getTime(_iteration,_order);
5261   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
5262   if(!getOrCreateAndGetArray()->isAllocated())
5263     {
5264       allocNotFromFile(arr->getNumberOfTuples());
5265       return 0;
5266     }
5267   else
5268     {
5269       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
5270       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
5271       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
5272       _nb_of_tuples_to_be_allocated=-3;
5273       return oldNbOfTuples;
5274     }
5275 }
5276
5277 /*!
5278  * Returns number of components in \a this field
5279  *  \return int - the number of components.
5280  */
5281 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
5282 {
5283   return getOrCreateAndGetArray()->getNumberOfComponents();
5284 }
5285
5286 /*!
5287  * Change info on components in \a this.
5288  * \throw If size of \a infos is not equal to the number of components already in \a this.
5289  */
5290 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
5291 {
5292   DataArray *arr=getOrCreateAndGetArray();
5293   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
5294 }
5295
5296 /*!
5297  * Returns info on components of \a this field.
5298  *  \return const std::vector<std::string>& - a sequence of strings each being an
5299  *          information on _i_-th component.
5300  */
5301 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
5302 {
5303   const DataArray *arr=getOrCreateAndGetArray();
5304   return arr->getInfoOnComponents();
5305 }
5306
5307 /*!
5308  * Returns a mutable info on components of \a this field.
5309  *  \return std::vector<std::string>& - a sequence of strings each being an
5310  *          information on _i_-th component.
5311  */
5312 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
5313 {
5314   DataArray *arr=getOrCreateAndGetArray();
5315   return arr->getInfoOnComponents();
5316 }
5317
5318 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
5319 {
5320   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5321     {
5322       const MEDFileFieldPerMesh *fpm(*it);
5323       if(!fpm)
5324         continue;
5325       if(fpm->presenceOfMultiDiscPerGeoType())
5326         return true;
5327     }
5328   return false;
5329 }
5330
5331 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
5332 {
5333   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5334     if((*it).isNotNull())
5335       if((*it)->presenceOfStructureElements())
5336         return true;
5337   return false;
5338 }
5339
5340 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
5341 {
5342   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5343     if((*it).isNotNull())
5344       if(!(*it)->onlyStructureElements())
5345         return false;
5346   return true;
5347 }
5348
5349 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
5350 {
5351   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5352     if((*it).isNotNull())
5353       (*it)->killStructureElements();
5354 }
5355
5356 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
5357 {
5358   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5359     if((*it).isNotNull())
5360       (*it)->keepOnlyStructureElements();
5361 }
5362
5363 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName)
5364 {
5365   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5366     if((*it).isNotNull())
5367       (*it)->keepOnlyOnSE(seName);
5368 }
5369
5370 void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
5371 {
5372   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5373     if((*it).isNotNull())
5374       (*it)->getMeshSENames(ps);
5375 }
5376
5377 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5378 {
5379   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 !";
5380   if(_field_per_mesh.empty())
5381     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
5382   if(_field_per_mesh.size()>1)
5383     throw INTERP_KERNEL::Exception(MSG0);
5384   if(_field_per_mesh[0].isNull())
5385     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
5386   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
5387   std::set<TypeOfField> types;
5388   pm->fillTypesOfFieldAvailable(types);
5389   if(types.size()!=1)
5390     throw INTERP_KERNEL::Exception(MSG0);
5391   TypeOfField type(*types.begin());
5392   int meshDimRelToMax(0);
5393   if(type==ON_NODES)
5394     meshDimRelToMax=0;
5395   else
5396     {
5397       int myDim(std::numeric_limits<int>::max());
5398       bool isUnique(pm->isUniqueLevel(myDim));
5399       if(!isUnique)
5400         throw INTERP_KERNEL::Exception(MSG0);
5401       meshDimRelToMax=myDim-mesh->getMeshDimension();
5402       if(meshDimRelToMax>0)
5403         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5404     }
5405   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5406 }
5407
5408 /*!
5409  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5410  *  \param [in] type - a spatial discretization of the new field.
5411  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5412  *  \param [in] mName - a name of the supporting mesh.
5413  *  \param [in] renumPol - specifies how to permute values of the result field according to
5414  *          the optional numbers of cells and nodes, if any. The valid values are
5415  *          - 0 - do not permute.
5416  *          - 1 - permute cells.
5417  *          - 2 - permute nodes.
5418  *          - 3 - permute cells and nodes.
5419  *
5420  *  \param [in] glob - the global data storing profiles and localization.
5421  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5422  *          caller is to delete this field using decrRef() as it is no more needed. 
5423  *  \throw If the MED file is not readable.
5424  *  \throw If there is no mesh named \a mName in the MED file.
5425  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5426  *  \throw If no field of \a this is lying on the mesh \a mName.
5427  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5428  */
5429 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5430 {
5431   MCAuto<MEDFileMesh> mm;
5432   if(mName.empty())
5433     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5434   else
5435     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5436   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5437 }
5438
5439 /*!
5440  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5441  *  \param [in] type - a spatial discretization of the new field.
5442  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5443  *  \param [in] renumPol - specifies how to permute values of the result field according to
5444  *          the optional numbers of cells and nodes, if any. The valid values are
5445  *          - 0 - do not permute.
5446  *          - 1 - permute cells.
5447  *          - 2 - permute nodes.
5448  *          - 3 - permute cells and nodes.
5449  *
5450  *  \param [in] glob - the global data storing profiles and localization.
5451  *  \param [in] mesh - the supporting mesh.
5452  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5453  *          caller is to delete this field using decrRef() as it is no more needed. 
5454  *  \throw If the MED file is not readable.
5455  *  \throw If no field of \a this is lying on \a mesh.
5456  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5457  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5458  */
5459 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5460 {
5461   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5462   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5463   if(meshDimRelToMax==1)
5464     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5465   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5466 }
5467
5468 /*!
5469  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5470  * given mesh. 
5471  *  \param [in] type - a spatial discretization of the new field.
5472  *  \param [in] mName - a name of the supporting mesh.
5473  *  \param [in] renumPol - specifies how to permute values of the result field according to
5474  *          the optional numbers of cells and nodes, if any. The valid values are
5475  *          - 0 - do not permute.
5476  *          - 1 - permute cells.
5477  *          - 2 - permute nodes.
5478  *          - 3 - permute cells and nodes.
5479  *
5480  *  \param [in] glob - the global data storing profiles and localization.
5481  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5482  *          caller is to delete this field using decrRef() as it is no more needed. 
5483  *  \throw If the MED file is not readable.
5484  *  \throw If there is no mesh named \a mName in the MED file.
5485  *  \throw If there are no mesh entities in the mesh.
5486  *  \throw If no field values of the given \a type are available.
5487  */
5488 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5489 {
5490   MCAuto<MEDFileMesh> mm;
5491   if(mName.empty())
5492     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5493   else
5494     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5495   int absDim=getDimension();
5496   int meshDimRelToMax=absDim-mm->getMeshDimension();
5497   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5498 }
5499
5500 /*!
5501  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5502  *  \param [in] type - a spatial discretization of the new field.
5503  *  \param [in] renumPol - specifies how to permute values of the result field according to
5504  *          the optional numbers of cells and nodes, if any. The valid values are
5505  *          - 0 - do not permute.
5506  *          - 1 - permute cells.
5507  *          - 2 - permute nodes.
5508  *          - 3 - permute cells and nodes.
5509  *
5510  *  \param [in] glob - the global data storing profiles and localization.
5511  *  \param [in] mesh - the supporting mesh.
5512  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5513  *         field according to \a renumPol.
5514  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5515  *         field according to \a renumPol.
5516  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5517  *          caller is to delete this field using decrRef() as it is no more needed. 
5518  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5519  *  \throw If no field of \a this is lying on \a mesh.
5520  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5521  */
5522 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
5523 {
5524   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5525   bool isPfl=false;
5526   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[0]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5527   switch(renumPol)
5528   {
5529     case 0:
5530       {
5531         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5532         return ret.retn();
5533       }
5534     case 3:
5535     case 1:
5536       {
5537         if(isPfl)
5538           throw INTERP_KERNEL::Exception(msg1);
5539         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5540         if(cellRenum)
5541           {
5542             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5543               {
5544                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5545                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5546                 throw INTERP_KERNEL::Exception(oss.str());
5547               }
5548             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5549             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5550             std::vector<DataArray *> arrOut2(1,arrOut);
5551             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5552             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5553             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5554           }
5555         if(renumPol==1)
5556           return ret.retn();
5557       }
5558     case 2:
5559       {
5560         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5561         if(isPfl)
5562           throw INTERP_KERNEL::Exception(msg1);
5563         if(nodeRenum)
5564           {
5565             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5566               {
5567                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5568                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5569                 throw INTERP_KERNEL::Exception(oss.str());
5570               }
5571             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5572             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5573               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5574             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5575           }
5576         return ret.retn();
5577       }
5578     default:
5579       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5580   }
5581 }
5582
5583 /*!
5584  * Returns values and a profile of the field of a given type lying on a given support.
5585  *  \param [in] type - a spatial discretization of the field.
5586  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5587  *  \param [in] mesh - the supporting mesh.
5588  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5589  *          field of interest lies on. If the field lies on all entities of the given
5590  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5591  *          using decrRef() as it is no more needed.  
5592  *  \param [in] glob - the global data storing profiles and localization.
5593  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5594  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5595  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5596  *  \throw If no field of \a this is lying on \a mesh.
5597  *  \throw If no field values of the given \a type are available.
5598  */
5599 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5600 {
5601   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5602   MCAuto<DataArray> ret=_field_per_mesh[0]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5603   ret->setName(nasc.getName().c_str());
5604   return ret.retn();
5605 }
5606
5607 //= MEDFileField1TSWithoutSDA
5608
5609 /*!
5610  * Throws if a given value is not a valid (non-extended) relative dimension.
5611  *  \param [in] meshDimRelToMax - the relative dimension value.
5612  *  \throw If \a meshDimRelToMax > 0.
5613  */
5614 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5615 {
5616   if(meshDimRelToMax>0)
5617     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5618 }
5619
5620 /*!
5621  * Checks if elements of a given mesh are in the order suitable for writing 
5622  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5623  * vector describing types of elements and their number.
5624  *  \param [in] mesh - the mesh to check.
5625  *  \return std::vector<int> - a vector holding for each element type (1) item of
5626  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5627  *          These values are in full-interlace mode.
5628  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5629  */
5630 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5631 {
5632   if(!mesh)
5633     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5634   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5635   int nbOfTypes=geoTypes.size();
5636   std::vector<int> code(3*nbOfTypes);
5637   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5638   arr1->alloc(nbOfTypes,1);
5639   int *arrPtr=arr1->getPointer();
5640   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5641   for(int i=0;i<nbOfTypes;i++,it++)
5642     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5643   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5644   const int *arrPtr2=arr2->getConstPointer();
5645   int i=0;
5646   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5647     {
5648       int pos=arrPtr2[i];
5649       int nbCells=mesh->getNumberOfCellsWithType(*it);
5650       code[3*pos]=(int)(*it);
5651       code[3*pos+1]=nbCells;
5652       code[3*pos+2]=-1;//no profiles
5653     }
5654   std::vector<const DataArrayInt *> idsPerType;//no profiles
5655   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5656   if(da)
5657     {
5658       da->decrRef();
5659       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5660     }
5661   return code;
5662 }
5663
5664 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5665 {
5666   return new MEDFileField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5667 }
5668
5669 /*!
5670  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5671  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5672  * item of every of returned sequences refers to the _i_-th part of \a this field.
5673  * Thus all sequences returned by this method are of the same length equal to number
5674  * of different types of supporting entities.<br>
5675  * A field part can include sub-parts with several different spatial discretizations,
5676  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5677  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5678  * of a nested sequence corresponds to a type of spatial discretization.<br>
5679  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5680  * The overhead is due to selecting values into new instances of DataArrayDouble.
5681  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5682  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5683  *          not checked if \a mname == \c NULL).
5684  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5685  *          a field part is returned. 
5686  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5687  *          A field part can include sub-parts with several different spatial discretizations,
5688  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5689  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5690  *          This sequence is of the same length as \a types. 
5691  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5692  *          discretization. A profile name can be empty.
5693  *          Length of this and of nested sequences is the same as that of \a typesF.
5694  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5695  *          discretization. A localization name can be empty.
5696  *          Length of this and of nested sequences is the same as that of \a typesF.
5697  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5698  *          per each type of spatial discretization within one mesh entity type.
5699  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5700  *          Length of this and of nested sequences is the same as that of \a typesF.
5701  *  \throw If no field is lying on \a mname.
5702  */
5703 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
5704 {
5705   if(mname.empty())
5706     if(_field_per_mesh.empty())
5707       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5708   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
5709   int nbOfRet=ret0.size();
5710   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5711   for(int i=0;i<nbOfRet;i++)
5712     {
5713       const std::vector< std::pair<int,int> >& p=ret0[i];
5714       int nbOfRet1=p.size();
5715       ret[i].resize(nbOfRet1);
5716       for(int j=0;j<nbOfRet1;j++)
5717         {
5718           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5719           ret[i][j]=tmp;
5720         }
5721     }
5722   return ret;
5723 }
5724
5725 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5726 {
5727   return TYPE_STR;
5728 }
5729
5730 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5731 {
5732   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5733   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5734   ret->deepCpyLeavesFrom(*this);
5735   const DataArrayDouble *arr(_arr);
5736   if(arr)
5737     {
5738       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5739       ret->setArray(arr2);
5740     }
5741   return ret.retn();
5742 }
5743
5744 /*!
5745  * Returns a pointer to the underground DataArrayDouble instance and a
5746  * sequence describing parameters of a support of each part of \a this field. The
5747  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5748  * direct access to the field values. This method is intended for the field lying on one
5749  * mesh only.
5750  *  \param [in,out] entries - the sequence describing parameters of a support of each
5751  *         part of \a this field. Each item of this sequence consists of two parts. The
5752  *         first part describes a type of mesh entity and an id of discretization of a
5753  *         current field part. The second part describes a range of values [begin,end)
5754  *         within the returned array relating to the current field part.
5755  *  \return DataArrayDouble * - the pointer to the field values array.
5756  *  \throw If the number of underlying meshes is not equal to 1.
5757  *  \throw If no field values are available.
5758  *  \sa getUndergroundDataArray()
5759  */
5760 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5761 {
5762   return getUndergroundDataArrayTemplateExt(entries);
5763 }
5764
5765 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)
5766 {
5767   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5768   arr->setInfoAndChangeNbOfCompo(infos);
5769 }
5770
5771 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5772 {
5773 }
5774
5775 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5776 {
5777   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5778   ret->deepCpyLeavesFrom(*this);
5779   return ret.retn();
5780 }
5781
5782 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5783 {
5784   MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
5785   if(_arr.isNotNull())
5786     ret->_arr=_arr->deepCopy();
5787   return ret.retn();
5788 }
5789
5790 //= MEDFileIntField1TSWithoutSDA
5791
5792 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5793 {
5794   return new MEDFileIntField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5795 }
5796
5797 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA()
5798 {
5799 }
5800
5801 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
5802                                                            const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<int>(fieldName,meshName,csit,iteration,order,infos)
5803 {
5804   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5805   arr->setInfoAndChangeNbOfCompo(infos);
5806 }
5807
5808 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5809 {
5810   return TYPE_STR;
5811 }
5812
5813 /*!
5814  * Returns a pointer to the underground DataArrayInt instance and a
5815  * sequence describing parameters of a support of each part of \a this field. The
5816  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5817  * direct access to the field values. This method is intended for the field lying on one
5818  * mesh only.
5819  *  \param [in,out] entries - the sequence describing parameters of a support of each
5820  *         part of \a this field. Each item of this sequence consists of two parts. The
5821  *         first part describes a type of mesh entity and an id of discretization of a
5822  *         current field part. The second part describes a range of values [begin,end)
5823  *         within the returned array relating to the current field part.
5824  *  \return DataArrayInt * - the pointer to the field values array.
5825  *  \throw If the number of underlying meshes is not equal to 1.
5826  *  \throw If no field values are available.
5827  *  \sa getUndergroundDataArray()
5828  */
5829 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5830 {
5831   return getUndergroundDataArrayIntExt(entries);
5832 }
5833
5834 /*!
5835  * Returns a pointer to the underground DataArrayInt instance and a
5836  * sequence describing parameters of a support of each part of \a this field. The
5837  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5838  * direct access to the field values. This method is intended for the field lying on one
5839  * mesh only.
5840  *  \param [in,out] entries - the sequence describing parameters of a support of each
5841  *         part of \a this field. Each item of this sequence consists of two parts. The
5842  *         first part describes a type of mesh entity and an id of discretization of a
5843  *         current field part. The second part describes a range of values [begin,end)
5844  *         within the returned array relating to the current field part.
5845  *  \return DataArrayInt * - the pointer to the field values array.
5846  *  \throw If the number of underlying meshes is not equal to 1.
5847  *  \throw If no field values are available.
5848  *  \sa getUndergroundDataArray()
5849  */
5850 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5851 {
5852   if(_field_per_mesh.size()!=1)
5853     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5854   if(_field_per_mesh[0]==0)
5855     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5856   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5857   return getUndergroundDataArrayTemplate();
5858 }
5859
5860 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5861 {
5862   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5863   ret->deepCpyLeavesFrom(*this);
5864   return ret.retn();
5865 }
5866
5867 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5868 {
5869   MCAuto<MEDFileIntField1TSWithoutSDA> ret(shallowCpy());
5870   if(_arr.isNotNull())
5871     ret->_arr=_arr->deepCopy();
5872   return ret.retn();
5873 }
5874
5875 //= MEDFileFloatField1TSWithoutSDA
5876
5877 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5878 {
5879   return new MEDFileFloatField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5880 }
5881
5882 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA()
5883 {
5884 }
5885
5886 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
5887                                                                const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<float>(fieldName,meshName,csit,iteration,order,infos)
5888 {
5889   DataArrayFloat *arr(getOrCreateAndGetArrayTemplate());
5890   arr->setInfoAndChangeNbOfCompo(infos);
5891 }
5892
5893 const char *MEDFileFloatField1TSWithoutSDA::getTypeStr() const
5894 {
5895   return TYPE_STR;
5896 }
5897
5898 /*!
5899  * Returns a pointer to the underground DataArrayFloat instance and a
5900  * sequence describing parameters of a support of each part of \a this field. The
5901  * caller should not decrRef() the returned DataArrayFloat. This method allows for a
5902  * direct access to the field values. This method is intended for the field lying on one
5903  * mesh only.
5904  *  \param [in,out] entries - the sequence describing parameters of a support of each
5905  *         part of \a this field. Each item of this sequence consists of two parts. The
5906  *         first part describes a type of mesh entity and an id of discretization of a
5907  *         current field part. The second part describes a range of values [begin,end)
5908  *         within the returned array relating to the current field part.
5909  *  \return DataArrayFloat * - the pointer to the field values array.
5910  *  \throw If the number of underlying meshes is not equal to 1.
5911  *  \throw If no field values are available.
5912  *  \sa getUndergroundDataArray()
5913  */
5914 DataArray *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5915 {
5916   return getUndergroundDataArrayFloatExt(entries);
5917 }
5918
5919 /*!
5920  * Returns a pointer to the underground DataArrayFloat instance and a
5921  * sequence describing parameters of a support of each part of \a this field. The
5922  * caller should not decrRef() the returned DataArrayFloat. This method allows for a
5923  * direct access to the field values. This method is intended for the field lying on one
5924  * mesh only.
5925  *  \param [in,out] entries - the sequence describing parameters of a support of each
5926  *         part of \a this field. Each item of this sequence consists of two parts. The
5927  *         first part describes a type of mesh entity and an id of discretization of a
5928  *         current field part. The second part describes a range of values [begin,end)
5929  *         within the returned array relating to the current field part.
5930  *  \return DataArrayFloat * - the pointer to the field values array.
5931  *  \throw If the number of underlying meshes is not equal to 1.
5932  *  \throw If no field values are available.
5933  *  \sa getUndergroundDataArray()
5934  */
5935 DataArrayFloat *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayFloatExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5936 {
5937   if(_field_per_mesh.size()!=1)
5938     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5939   if(_field_per_mesh[0]==0)
5940     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5941   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5942   return getUndergroundDataArrayTemplate();
5943 }
5944
5945 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::shallowCpy() const
5946 {
5947   MCAuto<MEDFileFloatField1TSWithoutSDA> ret(new MEDFileFloatField1TSWithoutSDA(*this));
5948   ret->deepCpyLeavesFrom(*this);
5949   return ret.retn();
5950 }
5951
5952 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::deepCopy() const
5953 {
5954   MCAuto<MEDFileFloatField1TSWithoutSDA> ret(shallowCpy());
5955   if(_arr.isNotNull())
5956     ret->_arr=_arr->deepCopy();
5957   return ret.retn();
5958 }
5959
5960 //= MEDFileAnyTypeField1TS
5961
5962 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5963 {
5964 }
5965
5966 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5967 {
5968   med_field_type typcha;
5969   //
5970   std::vector<std::string> infos;
5971   std::string dtunit,fieldName,meshName;
5972   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
5973   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5974   switch(typcha)
5975   {
5976     case MED_FLOAT64:
5977       {
5978         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5979         break;
5980       }
5981     case MED_INT32:
5982       {
5983         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5984         break;
5985       }
5986     case MED_FLOAT32:
5987       {
5988         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5989         break;
5990       }
5991     default:
5992       {
5993         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] !";
5994         throw INTERP_KERNEL::Exception(oss.str());
5995       }
5996   }
5997   ret->setDtUnit(dtunit.c_str());
5998   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5999   //
6000   med_int numdt,numit;
6001   med_float dt;
6002   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
6003   ret->setTime(numdt,numit,dt);
6004   ret->_csit=1;
6005   if(loadAll)
6006     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6007   else
6008     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6009   return ret.retn();
6010 }
6011
6012 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6013 try:MEDFileFieldGlobsReal(fid)
6014 {
6015   _content=BuildContentFrom(fid,loadAll,ms,entities);
6016   loadGlobals(fid);
6017 }
6018 catch(INTERP_KERNEL::Exception& e)
6019 {
6020     throw e;
6021 }
6022
6023 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6024 {
6025   med_field_type typcha;
6026   std::vector<std::string> infos;
6027   std::string dtunit,meshName;
6028   int nbSteps(0);
6029   {
6030     int iii=-1;
6031     nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName);
6032   }
6033   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6034   switch(typcha)
6035   {
6036     case MED_FLOAT64:
6037       {
6038         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6039         break;
6040       }
6041     case MED_INT32:
6042       {
6043         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6044         break;
6045       }
6046     case MED_FLOAT32:
6047       {
6048         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6049         break;
6050       }
6051     default:
6052       {
6053         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] !";
6054         throw INTERP_KERNEL::Exception(oss.str());
6055       }
6056   }
6057   ret->setMeshName(meshName);
6058   ret->setDtUnit(dtunit.c_str());
6059   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6060   //
6061   if(nbSteps<1)
6062     {
6063       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
6064       throw INTERP_KERNEL::Exception(oss.str());
6065     }
6066   //
6067   med_int numdt,numit;
6068   med_float dt;
6069   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
6070   ret->setTime(numdt,numit,dt);
6071   ret->_csit=1;
6072   if(loadAll)
6073     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6074   else
6075     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6076   return ret.retn();
6077 }
6078
6079 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6080 try:MEDFileFieldGlobsReal(fid)
6081 {
6082   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
6083   loadGlobals(fid);
6084 }
6085 catch(INTERP_KERNEL::Exception& e)
6086 {
6087     throw e;
6088 }
6089
6090 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
6091 {
6092   if(!c)
6093     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
6094   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
6095     {
6096       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6097       ret->_content=c; c->incrRef();
6098       return ret.retn();
6099     }
6100   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
6101     {
6102       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
6103       ret->_content=c; c->incrRef();
6104       return ret.retn();
6105     }
6106   if(dynamic_cast<const MEDFileFloatField1TSWithoutSDA *>(c))
6107     {
6108       MCAuto<MEDFileFloatField1TS> ret(MEDFileFloatField1TS::New());
6109       ret->_content=c; c->incrRef();
6110       return ret.retn();
6111     }
6112   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
6113 }
6114
6115 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
6116 {
6117   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
6118   ret->setFileName(FileNameFromFID(fid));
6119   return ret;
6120 }
6121
6122 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
6123 {
6124   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6125   return New(fid,loadAll);
6126 }
6127
6128 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
6129 {
6130   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0,0));
6131   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6132   ret->loadGlobals(fid);
6133   return ret.retn();
6134 }
6135
6136 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6137 {
6138   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6139   return New(fid,fieldName,loadAll);
6140 }
6141
6142 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6143 {
6144   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
6145   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6146   ret->loadGlobals(fid);
6147   return ret.retn();
6148 }
6149
6150 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6151 {
6152   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6153   return New(fid,fieldName,iteration,order,loadAll);
6154 }
6155
6156 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6157 {
6158   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,0));
6159   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6160   ret->loadGlobals(fid);
6161   return ret.retn();
6162 }
6163
6164 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6165 {
6166   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6167   return NewAdv(fid,fieldName,iteration,order,loadAll,entities);
6168 }
6169
6170 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6171 {
6172   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,entities));
6173   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6174   ret->loadGlobals(fid);
6175   return ret.retn();
6176 }
6177
6178 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6179 {
6180   med_field_type typcha;
6181   std::vector<std::string> infos;
6182   std::string dtunit,meshName;
6183   int iii(-1);
6184   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName));
6185   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6186   switch(typcha)
6187   {
6188     case MED_FLOAT64:
6189       {
6190         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6191         break;
6192       }
6193     case MED_INT32:
6194       {
6195         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6196         break;
6197       }
6198     case MED_FLOAT32:
6199       {
6200         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6201         break;
6202       }
6203     default:
6204       {
6205         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] !";
6206         throw INTERP_KERNEL::Exception(oss.str());
6207       }
6208   }
6209   ret->setDtUnit(dtunit.c_str());
6210   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6211   //
6212   bool found=false;
6213   std::vector< std::pair<int,int> > dtits(nbOfStep2);
6214   for(int i=0;i<nbOfStep2 && !found;i++)
6215     {
6216       med_int numdt,numit;
6217       med_float dt;
6218       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
6219       if(numdt==iteration && numit==order)
6220         {
6221           found=true;
6222           ret->_csit=i+1;
6223         }
6224       else
6225         dtits[i]=std::pair<int,int>(numdt,numit);
6226     }
6227   if(!found)
6228     {
6229       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
6230       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
6231         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
6232       throw INTERP_KERNEL::Exception(oss.str());
6233     }
6234   if(loadAll)
6235     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6236   else
6237     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6238   return ret.retn();
6239 }
6240
6241 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6242 try:MEDFileFieldGlobsReal(fid)
6243 {
6244   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms,entities);
6245   loadGlobals(fid);
6246 }
6247 catch(INTERP_KERNEL::Exception& e)
6248 {
6249     throw e;
6250 }
6251
6252 /*!
6253  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6254  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6255  *
6256  * \warning this is a shallow copy constructor
6257  */
6258 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
6259 {
6260   if(!shallowCopyOfContent)
6261     {
6262       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
6263       otherPtr->incrRef();
6264       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
6265     }
6266   else
6267     {
6268       _content=other.shallowCpy();
6269     }
6270 }
6271
6272 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)
6273 {
6274   if(checkFieldId)
6275     {
6276       int nbFields=MEDnField(fid);
6277       if(fieldIdCFormat>=nbFields)
6278         {
6279           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
6280           throw INTERP_KERNEL::Exception(oss.str());
6281         }
6282     }
6283   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
6284   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6285   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6286   INTERP_KERNEL::AutoPtr<char> dtunit(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
6287   INTERP_KERNEL::AutoPtr<char> nomcha(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6288   INTERP_KERNEL::AutoPtr<char> nomMaa(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6289   med_bool localMesh;
6290   int nbOfStep;
6291   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
6292   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
6293   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
6294   meshName=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
6295   infos.clear(); infos.resize(ncomp);
6296   for(int j=0;j<ncomp;j++)
6297     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
6298   return nbOfStep;
6299 }
6300
6301 /*!
6302  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
6303  * 
6304  * \param [out]
6305  * \return in case of success the number of time steps available for the field with name \a fieldName.
6306  */
6307 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)
6308 {
6309   int nbFields=MEDnField(fid);
6310   bool found=false;
6311   std::vector<std::string> fns(nbFields);
6312   int nbOfStep2(-1);
6313   for(int i=0;i<nbFields && !found;i++)
6314     {
6315       std::string tmp,tmp2;
6316       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut,tmp2);
6317       fns[i]=tmp;
6318       found=(tmp==fieldName);
6319       if(found)
6320         {
6321           posCFormat=i;
6322           meshName=tmp2;
6323         }
6324     }
6325   if(!found)
6326     {
6327       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
6328       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
6329         oss << "\"" << *it << "\" ";
6330       throw INTERP_KERNEL::Exception(oss.str());
6331     }
6332   return nbOfStep2;
6333 }
6334
6335 /*!
6336  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6337  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6338  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6339  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6340  * to keep a valid instance.
6341  * 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.
6342  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
6343  * 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.
6344  *
6345  * \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.
6346  * \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.
6347  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6348  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6349  * \param [in] newLocName is the new localization name.
6350  * \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.
6351  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
6352  */
6353 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
6354 {
6355   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6356   std::string oldPflName=disc->getProfile();
6357   std::vector<std::string> vv=getPflsReallyUsedMulti();
6358   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
6359   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
6360     {
6361       disc->setProfile(newPflName);
6362       DataArrayInt *pfl=getProfile(oldPflName.c_str());
6363       pfl->setName(newPflName);
6364     }
6365   else
6366     {
6367       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
6368       throw INTERP_KERNEL::Exception(oss.str());
6369     }
6370 }
6371
6372 /*!
6373  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6374  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6375  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6376  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6377  * to keep a valid instance.
6378  * 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.
6379  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
6380  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
6381  * 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.
6382  *
6383  * \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.
6384  * \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.
6385  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6386  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6387  * \param [in] newLocName is the new localization name.
6388  * \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.
6389  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
6390  */
6391 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
6392 {
6393   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6394   std::string oldLocName=disc->getLocalization();
6395   std::vector<std::string> vv=getLocsReallyUsedMulti();
6396   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
6397   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
6398     {
6399       disc->setLocalization(newLocName);
6400       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
6401       loc.setName(newLocName);
6402     }
6403   else
6404     {
6405       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
6406       throw INTERP_KERNEL::Exception(oss.str());
6407     }
6408 }
6409
6410 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
6411 {
6412   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6413   if(!ret)
6414     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
6415   return ret;
6416 }
6417
6418 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
6419 {
6420   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6421   if(!ret)
6422     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
6423   return ret;
6424 }
6425
6426 /*!
6427  * This method alloc the arrays and load potentially huge arrays contained in this field.
6428  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
6429  * This method can be also called to refresh or reinit values from a file.
6430  * 
6431  * \throw If the fileName is not set or points to a non readable MED file.
6432  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6433  */
6434 void MEDFileAnyTypeField1TS::loadArrays()
6435 {
6436   if(getFileName().empty())
6437     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
6438   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6439   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
6440 }
6441
6442 /*!
6443  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
6444  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
6445  * this method does not throw if \a this does not come from file read.
6446  * 
6447  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
6448  */
6449 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
6450 {
6451   if(!getFileName().empty())
6452     {
6453       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6454       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
6455     }
6456 }
6457
6458 /*!
6459  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
6460  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
6461  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
6462  * 
6463  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
6464  */
6465 void MEDFileAnyTypeField1TS::unloadArrays()
6466 {
6467   contentNotNullBase()->unloadArrays();
6468 }
6469
6470 /*!
6471  * 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.
6472  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
6473  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
6474  * 
6475  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6476  */
6477 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
6478 {
6479   if(!getFileName().empty())
6480     contentNotNullBase()->unloadArrays();
6481 }
6482
6483 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6484 {
6485   int nbComp(getNumberOfComponents());
6486   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6487   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6488   for(int i=0;i<nbComp;i++)
6489     {
6490       std::string info=getInfo()[i];
6491       std::string c,u;
6492       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6493       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6494       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6495     }
6496   if(getName().empty())
6497     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6498   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6499   writeGlobals(fid,*this);
6500   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6501 }
6502
6503 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6504 {
6505   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6506 }
6507
6508 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6509 {
6510   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6511   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6512   return ret;
6513 }
6514
6515 /*!
6516  * Returns a string describing \a this field. This string is outputted 
6517  * by \c print Python command.
6518  */
6519 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6520 {
6521   std::ostringstream oss;
6522   contentNotNullBase()->simpleRepr(0,oss,-1);
6523   simpleReprGlobs(oss);
6524   return oss.str();
6525 }
6526
6527 /*!
6528  * This method returns all profiles whose name is non empty used.
6529  * \b WARNING If profile is used several times it will be reported \b only \b once.
6530  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6531  */
6532 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6533 {
6534   return contentNotNullBase()->getPflsReallyUsed2();
6535 }
6536
6537 /*!
6538  * This method returns all localizations whose name is non empty used.
6539  * \b WARNING If localization is used several times it will be reported \b only \b once.
6540  */
6541 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6542 {
6543   return contentNotNullBase()->getLocsReallyUsed2();
6544 }
6545
6546 /*!
6547  * This method returns all profiles whose name is non empty used.
6548  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6549  */
6550 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6551 {
6552   return contentNotNullBase()->getPflsReallyUsedMulti2();
6553 }
6554
6555 /*!
6556  * This method returns all localizations whose name is non empty used.
6557  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6558  */
6559 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6560 {
6561   return contentNotNullBase()->getLocsReallyUsedMulti2();
6562 }
6563
6564 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6565 {
6566   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6567 }
6568
6569 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6570 {
6571   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6572 }
6573
6574 int MEDFileAnyTypeField1TS::getDimension() const
6575 {
6576   return contentNotNullBase()->getDimension();
6577 }
6578
6579 int MEDFileAnyTypeField1TS::getIteration() const
6580 {
6581   return contentNotNullBase()->getIteration();
6582 }
6583
6584 int MEDFileAnyTypeField1TS::getOrder() const
6585 {
6586   return contentNotNullBase()->getOrder();
6587 }
6588
6589 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6590 {
6591   return contentNotNullBase()->getTime(iteration,order);
6592 }
6593
6594 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6595 {
6596   contentNotNullBase()->setTime(iteration,order,val);
6597 }
6598
6599 std::string MEDFileAnyTypeField1TS::getName() const
6600 {
6601   return contentNotNullBase()->getName();
6602 }
6603
6604 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6605 {
6606   contentNotNullBase()->setName(name);
6607 }
6608
6609 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6610 {
6611   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6612 }
6613
6614 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6615 {
6616   return contentNotNullBase()->getDtUnit();
6617 }
6618
6619 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6620 {
6621   contentNotNullBase()->setDtUnit(dtUnit);
6622 }
6623
6624 std::string MEDFileAnyTypeField1TS::getMeshName() const
6625 {
6626   return contentNotNullBase()->getMeshName();
6627 }
6628
6629 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6630 {
6631   contentNotNullBase()->setMeshName(newMeshName);
6632 }
6633
6634 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6635 {
6636   return contentNotNullBase()->changeMeshNames(modifTab);
6637 }
6638
6639 int MEDFileAnyTypeField1TS::getMeshIteration() const
6640 {
6641   return contentNotNullBase()->getMeshIteration();
6642 }
6643
6644 int MEDFileAnyTypeField1TS::getMeshOrder() const
6645 {
6646   return contentNotNullBase()->getMeshOrder();
6647 }
6648
6649 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6650 {
6651   return contentNotNullBase()->getNumberOfComponents();
6652 }
6653
6654 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6655 {
6656   return contentNotNullBase()->isDealingTS(iteration,order);
6657 }
6658
6659 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6660 {
6661   return contentNotNullBase()->getDtIt();
6662 }
6663
6664 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6665 {
6666   contentNotNullBase()->fillIteration(p);
6667 }
6668
6669 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6670 {
6671   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6672 }
6673
6674 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6675 {
6676   contentNotNullBase()->setInfo(infos);
6677 }
6678
6679 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6680 {
6681   return contentNotNullBase()->getInfo();
6682 }
6683 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6684 {
6685   return contentNotNullBase()->getInfo();
6686 }
6687
6688 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6689 {
6690   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6691 }
6692
6693 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6694 {
6695   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6696 }
6697
6698 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6699 {
6700   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6701 }
6702
6703 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6704 {
6705   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6706 }
6707
6708 void MEDFileAnyTypeField1TS::convertMedBallIntoClassic()
6709 {
6710   return contentNotNullBase()->convertMedBallIntoClassic();
6711 }
6712
6713 void MEDFileAnyTypeField1TS::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
6714 {
6715   return contentNotNullBase()->makeReduction(ct,tof,pfl);
6716 }
6717
6718 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6719 {
6720   return contentNotNullBase()->getTypesOfFieldAvailable();
6721 }
6722
6723 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,
6724                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6725 {
6726   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6727 }
6728
6729 /*!
6730  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6731  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6732  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6733  */
6734 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6735 {
6736   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6737   if(!content)
6738     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6739   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6740   std::size_t sz(contentsSplit.size());
6741   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6742   for(std::size_t i=0;i<sz;i++)
6743     {
6744       ret[i]=shallowCpy();
6745       ret[i]->_content=contentsSplit[i];
6746     }
6747   return ret;
6748 }
6749
6750 /*!
6751  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6752  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6753  */
6754 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6755 {
6756   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6757   if(!content)
6758     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6759   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6760   std::size_t sz(contentsSplit.size());
6761   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6762   for(std::size_t i=0;i<sz;i++)
6763     {
6764       ret[i]=shallowCpy();
6765       ret[i]->_content=contentsSplit[i];
6766     }
6767   return ret;
6768 }
6769
6770 /*!
6771  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6772  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6773  */
6774 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6775 {
6776   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6777   if(!content)
6778     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6779   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6780   std::size_t sz(contentsSplit.size());
6781   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6782   for(std::size_t i=0;i<sz;i++)
6783     {
6784       ret[i]=shallowCpy();
6785       ret[i]->_content=contentsSplit[i];
6786     }
6787   return ret;
6788 }
6789
6790 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6791 {
6792   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6793   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6794     ret->_content=_content->deepCopy();
6795   ret->deepCpyGlobs(*this);
6796   return ret.retn();
6797 }
6798
6799 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6800 {
6801   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
6802   return copyTinyInfoFrom(field->timeDiscrSafe(),ft,arr);
6803 }
6804
6805 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
6806 {
6807   return contentNotNullBase()->copyTinyInfoFrom(th,field,arr);
6808 }
6809
6810 //= MEDFileField1TS
6811
6812 /*!
6813  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6814  * following the given input policy.
6815  *
6816  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6817  *                            By default (true) the globals are deeply copied.
6818  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6819  */
6820 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6821 {
6822   MCAuto<MEDFileIntField1TS> ret;
6823   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6824   if(content)
6825     {
6826       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6827       if(!contc)
6828         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6829       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6830       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6831     }
6832   else
6833     ret=MEDFileIntField1TS::New();
6834   if(isDeepCpyGlobs)
6835     ret->deepCpyGlobs(*this);
6836   else
6837     ret->shallowCpyGlobs(*this);
6838   return ret.retn();
6839 }
6840
6841 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6842 try:MEDFileTemplateField1TS<double>(fid,loadAll,ms)
6843 {
6844 }
6845 catch(INTERP_KERNEL::Exception& e)
6846 { throw e; }
6847
6848 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6849 try:MEDFileTemplateField1TS<double>(fid,fieldName,loadAll,ms)
6850 {
6851 }
6852 catch(INTERP_KERNEL::Exception& e)
6853 { throw e; }
6854
6855 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6856 try:MEDFileTemplateField1TS<double>(fid,fieldName,iteration,order,loadAll,ms)
6857 {
6858 }
6859 catch(INTERP_KERNEL::Exception& e)
6860 { throw e; }
6861
6862 /*!
6863  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6864  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6865  *
6866  * \warning this is a shallow copy constructor
6867  */
6868 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6869 try:MEDFileTemplateField1TS<double>(other,shallowCopyOfContent)
6870 {
6871 }
6872 catch(INTERP_KERNEL::Exception& e)
6873 { throw e; }
6874
6875 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
6876 {
6877   return new MEDFileField1TS(*this);
6878 }
6879
6880 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6881                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6882 {
6883   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6884 }
6885
6886 //= MEDFileIntField1TS
6887
6888 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
6889 {
6890   if(!f)
6891     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
6892   int t1,t2;
6893   double t0(f->getTime(t1,t2));
6894   std::string tu(f->getTimeUnit());
6895   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
6896   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
6897   ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
6898   return ret;
6899 }
6900
6901 //= MEDFileFloatField1TS
6902
6903 //= MEDFileFloatField1TS
6904
6905 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6906
6907 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6908 {
6909 }
6910
6911 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileFieldNameScope(fieldName,meshName)
6912 {
6913 }
6914
6915 /*!
6916  * \param [in] fieldId field id in C mode
6917  */
6918 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6919 {
6920   med_field_type typcha;
6921   std::string dtunitOut,meshName;
6922   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut,meshName));
6923   setMeshName(meshName);
6924   setDtUnit(dtunitOut.c_str());
6925   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
6926 }
6927
6928 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)
6929 try:MEDFileFieldNameScope(fieldName,meshName),_infos(infos)
6930 {
6931   setDtUnit(dtunit.c_str());
6932   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
6933 }
6934 catch(INTERP_KERNEL::Exception& e)
6935 {
6936     throw e;
6937 }
6938
6939 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
6940 {
6941   std::size_t ret(_mesh_name.capacity()+_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
6942   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6943     ret+=(*it).capacity();
6944   return ret;
6945 }
6946
6947 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
6948 {
6949   std::vector<const BigMemoryObject *> ret;
6950   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6951     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
6952   return ret;
6953 }
6954
6955 /*!
6956  * 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
6957  * NULL.
6958  */
6959 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
6960 {
6961   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6962   ret->setInfo(_infos);
6963   int sz=(int)_time_steps.size();
6964   for(const int *id=startIds;id!=endIds;id++)
6965     {
6966       if(*id>=0 && *id<sz)
6967         {
6968           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6969           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6970           if(tse)
6971             {
6972               tse->incrRef();
6973               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6974             }
6975           ret->pushBackTimeStep(tse2);
6976         }
6977       else
6978         {
6979           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6980           oss << " ! Should be in [0," << sz << ") !";
6981           throw INTERP_KERNEL::Exception(oss.str());
6982         }
6983     }
6984   if(ret->getNumberOfTS()>0)
6985     ret->synchronizeNameScope();
6986   ret->copyNameScope(*this);
6987   return ret.retn();
6988 }
6989
6990 /*!
6991  * 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
6992  * NULL.
6993  */
6994 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
6995 {
6996   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6997   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6998   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6999   ret->setInfo(_infos);
7000   int sz=(int)_time_steps.size();
7001   int j=bg;
7002   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7003     {
7004       if(j>=0 && j<sz)
7005         {
7006           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7007           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7008           if(tse)
7009             {
7010               tse->incrRef();
7011               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7012             }
7013           ret->pushBackTimeStep(tse2);
7014         }
7015       else
7016         {
7017           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7018           oss << " ! Should be in [0," << sz << ") !";
7019           throw INTERP_KERNEL::Exception(oss.str());
7020         }
7021     }
7022   if(ret->getNumberOfTS()>0)
7023     ret->synchronizeNameScope();
7024   ret->copyNameScope(*this);
7025   return ret.retn();
7026 }
7027
7028 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7029 {
7030   int id=0;
7031   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7032   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7033     {
7034       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7035       if(!cur)
7036         continue;
7037       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7038       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7039         ids->pushBackSilent(id);
7040     }
7041   return buildFromTimeStepIds(ids->begin(),ids->end());
7042 }
7043
7044 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7045 {
7046   int id=0;
7047   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7048   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7049     {
7050       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7051       if(!cur)
7052         continue;
7053       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7054       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7055         ids->pushBackSilent(id);
7056     }
7057   return buildFromTimeStepIds(ids->begin(),ids->end());
7058 }
7059
7060 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
7061 {
7062   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7063     if((*it).isNotNull())
7064       if((*it)->presenceOfStructureElements())
7065         return true;
7066   return false;
7067 }
7068
7069 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
7070 {
7071   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7072     if((*it).isNotNull())
7073       if(!(*it)->onlyStructureElements())
7074         return false;
7075   return true;
7076 }
7077
7078 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
7079 {
7080   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7081   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7082     if((*it).isNotNull())
7083       {
7084         if((*it)->presenceOfStructureElements())
7085           {
7086             if(!(*it)->onlyStructureElements())
7087               {
7088                 (*it)->killStructureElements();
7089                 ret.push_back(*it);
7090               }
7091           }
7092         else
7093           {
7094             ret.push_back(*it);
7095           }
7096       }
7097   _time_steps=ret;
7098 }
7099
7100 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
7101 {
7102   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7103   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7104     if((*it).isNotNull())
7105       {
7106         if((*it)->presenceOfStructureElements())
7107           {
7108             if(!(*it)->onlyStructureElements())
7109               (*it)->keepOnlyStructureElements();
7110             ret.push_back(*it);
7111           }
7112       }
7113   _time_steps=ret;
7114 }
7115
7116 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
7117 {
7118   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7119   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7120     if((*it).isNotNull())
7121       (*it)->keepOnlyOnSE(seName);
7122 }
7123
7124 void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
7125 {
7126   std::vector< std::pair<std::string,std::string> > ps2;
7127   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7128     if((*it).isNotNull())
7129       {
7130         (*it)->getMeshSENames(ps2);
7131         break;
7132       }
7133   if(ps2.empty())
7134     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
7135   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7136     if((*it).isNotNull())
7137       {
7138         std::vector< std::pair<std::string,std::string> > ps3;
7139         (*it)->getMeshSENames(ps3);
7140         if(ps2!=ps3)
7141           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
7142       }
7143   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
7144     {
7145       std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
7146       if(it2==ps.end())
7147         ps.push_back(*it);
7148     }
7149 }
7150
7151 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7152 {
7153   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7154     {
7155       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7156       if(!cur)
7157         continue;
7158       if(cur->presenceOfMultiDiscPerGeoType())
7159         return true;
7160     }
7161   return false;
7162 }
7163
7164 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7165 {
7166   return _infos;
7167 }
7168
7169 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7170 {
7171   _infos=info;
7172 }
7173
7174 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7175 {
7176   int ret=0;
7177   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7178     {
7179       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7180       if(pt->isDealingTS(iteration,order))
7181         return ret;
7182     }
7183   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7184   std::vector< std::pair<int,int> > vp=getIterations();
7185   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7186     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7187   throw INTERP_KERNEL::Exception(oss.str());
7188 }
7189
7190 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7191 {
7192   return *_time_steps[getTimeStepPos(iteration,order)];
7193 }
7194
7195 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7196 {
7197   return *_time_steps[getTimeStepPos(iteration,order)];
7198 }
7199
7200 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7201 {
7202   bool ret(false);
7203   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
7204     {
7205       if((*it).first==getMeshName())
7206         {
7207           setMeshName((*it).second);
7208           ret=true;
7209         }
7210     }
7211   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7212     {
7213       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7214       if(cur)
7215         ret=cur->changeMeshNames(modifTab) || ret;
7216     }
7217   return ret;
7218 }
7219
7220 /*!
7221  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7222  */
7223 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7224 {
7225   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7226 }
7227
7228 /*!
7229  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7230  */
7231 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7232 {
7233   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7234 }
7235
7236 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7237                                                                        MEDFileFieldGlobsReal& glob)
7238 {
7239   bool ret=false;
7240   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7241     {
7242       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7243       if(f1ts)
7244         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7245     }
7246   return ret;
7247 }
7248
7249 void MEDFileAnyTypeFieldMultiTSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
7250 {
7251   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7252     if((*it).isNotNull())
7253       {
7254         visitor.newTimeStepEntry(*it);
7255         (*it)->accept(visitor);
7256         visitor.endTimeStepEntry(*it);
7257       }
7258 }
7259
7260 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7261 {
7262   std::string startLine(bkOffset,' ');
7263   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7264   if(fmtsId>=0)
7265     oss << " (" << fmtsId << ")";
7266   oss << " has the following name: \"" << _name << "\"." << std::endl;
7267   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7268   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7269     {
7270       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7271     }
7272   int i=0;
7273   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7274     {
7275       std::string chapter(17,'0'+i);
7276       oss << startLine << chapter << std::endl;
7277       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7278       if(cur)
7279         cur->simpleRepr(bkOffset+2,oss,i);
7280       else
7281         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7282       oss << startLine << chapter << std::endl;
7283     }
7284 }
7285
7286 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7287 {
7288   std::size_t sz=_time_steps.size();
7289   std::vector< std::pair<int,int> > ret(sz);
7290   ret1.resize(sz);
7291   for(std::size_t i=0;i<sz;i++)
7292     {
7293       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7294       if(f1ts)
7295         {
7296           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7297         }
7298       else
7299         {
7300           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7301           throw INTERP_KERNEL::Exception(oss.str());
7302         }
7303     }
7304   return ret;
7305 }
7306
7307 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7308 {
7309   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7310   if(!tse2)
7311     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7312   checkCoherencyOfType(tse2);
7313   if(_time_steps.empty())
7314     {
7315       setName(tse2->getName());
7316       setMeshName(tse2->getMeshName());
7317       setInfo(tse2->getInfo());
7318     }
7319   checkThatComponentsMatch(tse2->getInfo());
7320   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7321     setDtUnit(tse->getDtUnit());
7322   _time_steps.push_back(tse);
7323 }
7324
7325 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7326 {
7327   std::size_t nbOfCompo=_infos.size();
7328   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7329     {
7330       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7331       if(cur)
7332         {
7333           if((cur->getInfo()).size()!=nbOfCompo)
7334             {
7335               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7336               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7337               throw INTERP_KERNEL::Exception(oss.str());
7338             }
7339           cur->copyNameScope(*this);
7340         }
7341     }
7342 }
7343
7344 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7345 {
7346   _time_steps.resize(nbPdt);
7347   for(int i=0;i<nbPdt;i++)
7348     {
7349       std::vector< std::pair<int,int> > ts;
7350       med_int numdt=0,numo=0;
7351       med_float dt=0.0;
7352       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7353       switch(fieldTyp)
7354       {
7355         case MED_FLOAT64:
7356           {
7357             _time_steps[i]=MEDFileField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7358             break;
7359           }
7360         case MED_INT32:
7361           {
7362             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7363             break;
7364           }
7365         case MED_FLOAT32:
7366           {
7367             _time_steps[i]=MEDFileFloatField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7368             break;
7369           }
7370         default:
7371           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32, FLOAT32 !");
7372       }
7373       if(loadAll)
7374         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7375       else
7376         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7377       synchronizeNameScope();
7378     }
7379 }
7380
7381 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7382 {
7383   if(_time_steps.empty())
7384     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7385   checkThatNbOfCompoOfTSMatchThis();
7386   std::vector<std::string> infos(getInfo());
7387   int nbComp=infos.size();
7388   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7389   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7390   for(int i=0;i<nbComp;i++)
7391     {
7392       std::string info=infos[i];
7393       std::string c,u;
7394       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7395       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7396       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7397     }
7398   if(_name.empty())
7399     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7400   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7401   int nbOfTS=_time_steps.size();
7402   for(int i=0;i<nbOfTS;i++)
7403     _time_steps[i]->writeLL(fid,opts,*this);
7404 }
7405
7406 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7407 {
7408   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7409     {
7410       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7411       if(elt)
7412         elt->loadBigArraysRecursively(fid,nasc);
7413     }
7414 }
7415
7416 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7417 {
7418   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7419     {
7420       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7421       if(elt)
7422         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7423     }
7424 }
7425
7426 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7427 {
7428   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7429     {
7430       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7431       if(elt)
7432         elt->unloadArrays();
7433     }
7434 }
7435
7436 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7437 {
7438   return _time_steps.size();
7439 }
7440
7441 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7442 {
7443   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7444   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7445     {
7446       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7447       if(tmp)
7448         newTS.push_back(*it);
7449     }
7450   _time_steps=newTS;
7451 }
7452
7453 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7454 {
7455   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7456   int maxId=(int)_time_steps.size();
7457   int ii=0;
7458   std::set<int> idsToDel;
7459   for(const int *id=startIds;id!=endIds;id++,ii++)
7460     {
7461       if(*id>=0 && *id<maxId)
7462         {
7463           idsToDel.insert(*id);
7464         }
7465       else
7466         {
7467           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7468           throw INTERP_KERNEL::Exception(oss.str());
7469         }
7470     }
7471   for(int iii=0;iii<maxId;iii++)
7472     if(idsToDel.find(iii)==idsToDel.end())
7473       newTS.push_back(_time_steps[iii]);
7474   _time_steps=newTS;
7475 }
7476
7477 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7478 {
7479   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7480   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7481   if(nbOfEntriesToKill==0)
7482     return ;
7483   std::size_t sz=_time_steps.size();
7484   std::vector<bool> b(sz,true);
7485   int j=bg;
7486   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7487     b[j]=false;
7488   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7489   for(std::size_t i=0;i<sz;i++)
7490     if(b[i])
7491       newTS.push_back(_time_steps[i]);
7492   _time_steps=newTS;
7493 }
7494
7495 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7496 {
7497   int ret=0;
7498   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7499   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7500     {
7501       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7502       if(tmp)
7503         {
7504           int it2,ord;
7505           tmp->getTime(it2,ord);
7506           if(it2==iteration && order==ord)
7507             return ret;
7508           else
7509             oss << "(" << it2 << ","  << ord << "), ";
7510         }
7511     }
7512   throw INTERP_KERNEL::Exception(oss.str());
7513 }
7514
7515 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7516 {
7517   int ret=0;
7518   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7519   oss.precision(15);
7520   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7521     {
7522       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7523       if(tmp)
7524         {
7525           int it2,ord;
7526           double ti=tmp->getTime(it2,ord);
7527           if(fabs(time-ti)<eps)
7528             return ret;
7529           else
7530             oss << ti << ", ";
7531         }
7532     }
7533   throw INTERP_KERNEL::Exception(oss.str());
7534 }
7535
7536 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7537 {
7538   int lgth=_time_steps.size();
7539   std::vector< std::pair<int,int> > ret(lgth);
7540   for(int i=0;i<lgth;i++)
7541     _time_steps[i]->fillIteration(ret[i]);
7542   return ret;
7543 }
7544
7545 /*!
7546  * 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'
7547  * This method returns two things.
7548  * - The absolute dimension of 'this' in first parameter. 
7549  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7550  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7551  *
7552  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7553  * Only these 3 discretizations will be taken into account here.
7554  *
7555  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7556  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7557  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7558  *
7559  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7560  * 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'.
7561  * 
7562  * Let's consider the typical following case :
7563  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7564  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7565  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7566  *   TETRA4 and SEG2
7567  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7568  *
7569  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7570  * 
7571  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7572  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7573  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7574  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7575  */
7576 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7577 {
7578   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7579 }
7580
7581 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7582 {
7583   if(pos<0 || pos>=(int)_time_steps.size())
7584     {
7585       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7586       throw INTERP_KERNEL::Exception(oss.str());
7587     }
7588   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7589   if(item==0)
7590     {
7591       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7592       oss << "\nTry to use following method eraseEmptyTS !";
7593       throw INTERP_KERNEL::Exception(oss.str());
7594     }
7595   return item;
7596 }
7597
7598 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7599 {
7600   if(pos<0 || pos>=(int)_time_steps.size())
7601     {
7602       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7603       throw INTERP_KERNEL::Exception(oss.str());
7604     }
7605   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7606   if(item==0)
7607     {
7608       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7609       oss << "\nTry to use following method eraseEmptyTS !";
7610       throw INTERP_KERNEL::Exception(oss.str());
7611     }
7612   return item;
7613 }
7614
7615 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7616 {
7617   std::vector<std::string> ret;
7618   std::set<std::string> ret2;
7619   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7620     {
7621       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7622       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7623         if(ret2.find(*it2)==ret2.end())
7624           {
7625             ret.push_back(*it2);
7626             ret2.insert(*it2);
7627           }
7628     }
7629   return ret;
7630 }
7631
7632 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7633 {
7634   std::vector<std::string> ret;
7635   std::set<std::string> ret2;
7636   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7637     {
7638       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7639       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7640         if(ret2.find(*it2)==ret2.end())
7641           {
7642             ret.push_back(*it2);
7643             ret2.insert(*it2);
7644           }
7645     }
7646   return ret;
7647 }
7648
7649 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7650 {
7651   std::vector<std::string> ret;
7652   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7653     {
7654       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7655       ret.insert(ret.end(),tmp.begin(),tmp.end());
7656     }
7657   return ret;
7658 }
7659
7660 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7661 {
7662   std::vector<std::string> ret;
7663   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7664     {
7665       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7666       ret.insert(ret.end(),tmp.begin(),tmp.end());
7667     }
7668   return ret;
7669 }
7670
7671 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7672 {
7673   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7674     (*it)->changePflsRefsNamesGen2(mapOfModif);
7675 }
7676
7677 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7678 {
7679   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7680     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7681 }
7682
7683 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7684 {
7685   int lgth=_time_steps.size();
7686   std::vector< std::vector<TypeOfField> > ret(lgth);
7687   for(int i=0;i<lgth;i++)
7688     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7689   return ret;
7690 }
7691
7692 /*!
7693  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7694  */
7695 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
7696 {
7697   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7698 }
7699
7700 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7701 {
7702   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7703   std::size_t i=0;
7704   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7705     {
7706       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7707         ret->_time_steps[i]=(*it)->deepCopy();
7708     }
7709   return ret.retn();
7710 }
7711
7712 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7713 {
7714   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7715   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7716   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7717   for(std::size_t i=0;i<sz;i++)
7718     {
7719       ret[i]=shallowCpy();
7720       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7721     }
7722   for(std::size_t i=0;i<sz2;i++)
7723     {
7724       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7725       if(ret1.size()!=sz)
7726         {
7727           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7728           throw INTERP_KERNEL::Exception(oss.str());
7729         }
7730       ts[i]=ret1;
7731     }
7732   for(std::size_t i=0;i<sz;i++)
7733     for(std::size_t j=0;j<sz2;j++)
7734       ret[i]->_time_steps[j]=ts[j][i];
7735   return ret;
7736 }
7737
7738 /*!
7739  * This method splits into discretization each time steps in \a this.
7740  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7741  */
7742 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7743 {
7744   std::size_t sz(_time_steps.size());
7745   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7746   for(std::size_t i=0;i<sz;i++)
7747     {
7748       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7749       if(!timeStep)
7750         {
7751           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7752           throw INTERP_KERNEL::Exception(oss.str());
7753         }
7754       items[i]=timeStep->splitDiscretizations();  
7755     }
7756   //
7757   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7758   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7759   std::vector< TypeOfField > types;
7760   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7761     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7762       {
7763         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7764         if(ts.size()!=1)
7765           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7766         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7767         if(it2==types.end())
7768           types.push_back(ts[0]);
7769       }
7770   ret.resize(types.size()); ret2.resize(types.size());
7771   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7772     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7773       {
7774         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7775         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7776         ret2[pos].push_back(*it1);
7777       }
7778   for(std::size_t i=0;i<types.size();i++)
7779     {
7780       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7781       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7782         elt->pushBackTimeStep(*it1);//also updates infos in elt
7783       ret[i]=elt;
7784       elt->MEDFileFieldNameScope::operator=(*this);
7785     }
7786   return ret;
7787 }
7788
7789 /*!
7790  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7791  */
7792 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7793 {
7794   std::size_t sz(_time_steps.size());
7795   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7796   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7797   for(std::size_t i=0;i<sz;i++)
7798     {
7799       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7800       if(!timeStep)
7801         {
7802           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7803           throw INTERP_KERNEL::Exception(oss.str());
7804         }
7805       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7806       if(szOut==std::numeric_limits<std::size_t>::max())
7807         szOut=items[i].size();
7808       else
7809         if(items[i].size()!=szOut)
7810           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7811     }
7812   if(szOut==std::numeric_limits<std::size_t>::max())
7813     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7814   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7815   for(std::size_t i=0;i<szOut;i++)
7816     {
7817       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7818       for(std::size_t j=0;j<sz;j++)
7819         elt->pushBackTimeStep(items[j][i]);
7820       ret[i]=elt;
7821       elt->MEDFileFieldNameScope::operator=(*this);
7822     }
7823   return ret;
7824 }
7825
7826 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7827 {
7828   setName(field->getName());
7829   if(field->getMesh())
7830     setMeshName(field->getMesh()->getName());
7831   if(_name.empty())
7832     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7833   if(!arr)
7834     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7835   _infos=arr->getInfoOnComponents();
7836 }
7837
7838 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7839 {
7840   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7841   if(_name!=field->getName())
7842     {
7843       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7844       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7845       throw INTERP_KERNEL::Exception(oss.str());
7846     }
7847   if(!arr)
7848     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7849   checkThatComponentsMatch(arr->getInfoOnComponents());
7850 }
7851
7852 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7853 {
7854   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7855   if(getInfo().size()!=compos.size())
7856     {
7857       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7858       oss << " number of components of element to append (" << compos.size() << ") !";
7859       throw INTERP_KERNEL::Exception(oss.str());
7860     }
7861   if(_infos!=compos)
7862     {
7863       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7864       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7865       oss << " But compo in input fields are : ";
7866       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7867       oss << " !";
7868       throw INTERP_KERNEL::Exception(oss.str());
7869     }
7870 }
7871
7872 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7873 {
7874   std::size_t sz=_infos.size();
7875   int j=0;
7876   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7877     {
7878       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7879       if(elt)
7880         if(elt->getInfo().size()!=sz)
7881           {
7882             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7883             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7884             throw INTERP_KERNEL::Exception(oss.str());
7885           }
7886     }
7887 }
7888
7889 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7890 {
7891   if(!field)
7892     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7893   if(!_time_steps.empty())
7894     checkCoherencyOfTinyInfo(field,arr);
7895   MEDFileAnyTypeField1TSWithoutSDA *objC(createNew1TSWithoutSDAEmptyInstance());
7896   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7897   {
7898     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
7899     objC->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,arr,glob,*this);
7900   }
7901   copyTinyInfoFrom(field,arr);
7902   _time_steps.push_back(obj);
7903 }
7904
7905 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7906 {
7907   if(!field)
7908     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7909   if(!_time_steps.empty())
7910     checkCoherencyOfTinyInfo(field,arr);
7911   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7912   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7913   {
7914     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
7915     objC->setFieldProfile(field->timeDiscrSafe(),ft,arr,mesh,meshDimRelToMax,profile,glob,*this);
7916   }
7917   copyTinyInfoFrom(field,arr);
7918   setMeshName(objC->getMeshName());
7919   _time_steps.push_back(obj);
7920 }
7921
7922 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
7923 {
7924   int sz=(int)_time_steps.size();
7925   if(i<0 || i>=sz)
7926     {
7927       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7928       throw INTERP_KERNEL::Exception(oss.str());
7929     }
7930   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7931   if(tsPtr)
7932     {
7933       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7934         {
7935           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7936           throw INTERP_KERNEL::Exception(oss.str());
7937         }
7938     }
7939   _time_steps[i]=ts;
7940 }
7941
7942 //= MEDFileFieldMultiTSWithoutSDA
7943
7944 /*!
7945  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7946  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7947  */
7948 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
7949 {
7950   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7951   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7952   if(!myF1TSC)
7953     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7954   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7955 }
7956
7957 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
7958 {
7959   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7960   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7961   int i=0;
7962   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7963     {
7964       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7965       if(eltToConv)
7966         {
7967           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7968           if(!eltToConvC)
7969             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7970           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7971           ret->setIteration(i,elt);
7972         }
7973     }
7974   return ret.retn();
7975 }
7976
7977 //= MEDFileAnyTypeFieldMultiTS
7978
7979 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7980 {
7981 }
7982
7983 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
7984 try:MEDFileFieldGlobsReal(fid)
7985 {
7986   _content=BuildContentFrom(fid,loadAll,ms);
7987   loadGlobals(fid);
7988 }
7989 catch(INTERP_KERNEL::Exception& e)
7990 {
7991     throw e;
7992 }
7993
7994 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7995 {
7996   med_field_type typcha;
7997   std::vector<std::string> infos;
7998   std::string dtunit;
7999   std::string meshName;
8000   int i(-1);
8001   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit,meshName);
8002   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8003   switch(typcha)
8004   {
8005     case MED_FLOAT64:
8006       {
8007         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8008         break;
8009       }
8010     case MED_INT32:
8011       {
8012         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8013         break;
8014       }
8015     case MED_FLOAT32:
8016       {
8017         ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8018         break;
8019       }
8020     default:
8021       {
8022         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] !";
8023         throw INTERP_KERNEL::Exception(oss.str());
8024       }
8025   }
8026   ret->setMeshName(meshName);
8027   ret->setDtUnit(dtunit.c_str());
8028   return ret.retn();
8029 }
8030
8031 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8032 {
8033   med_field_type typcha;
8034   //
8035   std::vector<std::string> infos;
8036   std::string dtunit,fieldName,meshName;
8037   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
8038   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8039   switch(typcha)
8040   {
8041     case MED_FLOAT64:
8042       {
8043         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8044         break;
8045       }
8046     case MED_INT32:
8047       {
8048         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8049         break;
8050       }
8051     case MED_FLOAT32:
8052       {
8053         ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8054         break;
8055       }
8056     default:
8057       {
8058         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] !";
8059         throw INTERP_KERNEL::Exception(oss.str());
8060       }
8061   }
8062   ret->setMeshName(meshName);
8063   ret->setDtUnit(dtunit.c_str());
8064   return ret.retn();
8065 }
8066
8067 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8068 {
8069   if(!c)
8070     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8071   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8072     {
8073       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8074       ret->_content=c;  c->incrRef();
8075       return ret.retn();
8076     }
8077   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8078     {
8079       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8080       ret->_content=c;  c->incrRef();
8081       return ret.retn();
8082     }
8083   if(dynamic_cast<const MEDFileFloatFieldMultiTSWithoutSDA *>(c))
8084     {
8085       MCAuto<MEDFileFloatFieldMultiTS> ret(MEDFileFloatFieldMultiTS::New());
8086       ret->_content=c;  c->incrRef();
8087       return ret.retn();
8088     }
8089   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
8090 }
8091
8092 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8093 {
8094   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8095   std::string fileName(FileNameFromFID(fid));
8096   ret->setFileName(fileName);
8097   return ret;
8098 }
8099
8100 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8101 try:MEDFileFieldGlobsReal(fid)
8102 {
8103   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8104   loadGlobals(fid);
8105 }
8106 catch(INTERP_KERNEL::Exception& e)
8107 {
8108     throw e;
8109 }
8110
8111 //= MEDFileAnyTypeFieldMultiTS
8112
8113 /*!
8114  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8115  * that has been read from a specified MED file.
8116  *  \param [in] fileName - the name of the MED file to read.
8117  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8118  *          is to delete this field using decrRef() as it is no more needed.
8119  *  \throw If reading the file fails.
8120  */
8121 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8122 {
8123   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8124   return New(fid,loadAll);
8125 }
8126
8127 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8128 {
8129   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8130   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8131   ret->loadGlobals(fid);
8132   return ret.retn();
8133 }
8134
8135 /*!
8136  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8137  * that has been read from a specified MED file.
8138  *  \param [in] fileName - the name of the MED file to read.
8139  *  \param [in] fieldName - the name of the field to read.
8140  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8141  *          is to delete this field using decrRef() as it is no more needed.
8142  *  \throw If reading the file fails.
8143  *  \throw If there is no field named \a fieldName in the file.
8144  */
8145 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8146 {
8147   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8148   return New(fid,fieldName,loadAll);
8149 }
8150
8151 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8152 {
8153   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8154   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8155   ret->loadGlobals(fid);
8156   return ret.retn();
8157 }
8158
8159 /*!
8160  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8161  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8162  *
8163  * \warning this is a shallow copy constructor
8164  */
8165 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8166 {
8167   if(!shallowCopyOfContent)
8168     {
8169       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8170       otherPtr->incrRef();
8171       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8172     }
8173   else
8174     {
8175       _content=other.shallowCpy();
8176     }
8177 }
8178
8179 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8180 {
8181   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8182   if(!ret)
8183     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8184   return ret;
8185 }
8186
8187 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8188 {
8189   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8190   if(!ret)
8191     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8192   return ret;
8193 }
8194
8195 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8196 {
8197   return contentNotNullBase()->getPflsReallyUsed2();
8198 }
8199
8200 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8201 {
8202   return contentNotNullBase()->getLocsReallyUsed2();
8203 }
8204
8205 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8206 {
8207   return contentNotNullBase()->getPflsReallyUsedMulti2();
8208 }
8209
8210 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8211 {
8212   return contentNotNullBase()->getLocsReallyUsedMulti2();
8213 }
8214
8215 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8216 {
8217   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8218 }
8219
8220 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8221 {
8222   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8223 }
8224
8225 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8226 {
8227   return contentNotNullBase()->getNumberOfTS();
8228 }
8229
8230 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8231 {
8232   contentNotNullBase()->eraseEmptyTS();
8233 }
8234
8235 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8236 {
8237   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8238 }
8239
8240 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8241 {
8242   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8243 }
8244
8245 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8246 {
8247   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8248   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8249   ret->_content=c;
8250   return ret.retn();
8251 }
8252
8253 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8254 {
8255   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8256   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8257   ret->_content=c;
8258   return ret.retn();
8259 }
8260
8261 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8262 {
8263   return contentNotNullBase()->getIterations();
8264 }
8265
8266 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8267 {
8268   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8269     pushBackTimeStep(*it);
8270 }
8271
8272 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8273 {
8274   if(!fmts)
8275     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8276   int nbOfTS(fmts->getNumberOfTS());
8277   for(int i=0;i<nbOfTS;i++)
8278     {
8279       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8280       pushBackTimeStep(elt);
8281     }
8282 }
8283
8284 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8285 {
8286   if(!f1ts)
8287     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8288   checkCoherencyOfType(f1ts);
8289   f1ts->incrRef();
8290   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8291   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8292   c->incrRef();
8293   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8294   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8295     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8296   _content->pushBackTimeStep(cSafe);
8297   appendGlobs(*f1ts,1e-12);
8298 }
8299
8300 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8301 {
8302   contentNotNullBase()->synchronizeNameScope();
8303 }
8304
8305 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8306 {
8307   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8308 }
8309
8310 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8311 {
8312   return contentNotNullBase()->getPosGivenTime(time,eps);
8313 }
8314
8315 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8316 {
8317   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8318 }
8319
8320 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8321 {
8322   return contentNotNullBase()->getTypesOfFieldAvailable();
8323 }
8324
8325 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
8326 {
8327   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8328 }
8329
8330 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8331 {
8332   return contentNotNullBase()->getName();
8333 }
8334
8335 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8336 {
8337   contentNotNullBase()->setName(name);
8338 }
8339
8340 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8341 {
8342   return contentNotNullBase()->getDtUnit();
8343 }
8344
8345 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8346 {
8347   contentNotNullBase()->setDtUnit(dtUnit);
8348 }
8349
8350 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8351 {
8352   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8353 }
8354
8355 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8356 {
8357   return contentNotNullBase()->getTimeSteps(ret1);
8358 }
8359
8360 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8361 {
8362   return contentNotNullBase()->getMeshName();
8363 }
8364
8365 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8366 {
8367   contentNotNullBase()->setMeshName(newMeshName);
8368 }
8369
8370 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8371 {
8372   return contentNotNullBase()->changeMeshNames(modifTab);
8373 }
8374
8375 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8376 {
8377   return contentNotNullBase()->getInfo();
8378 }
8379
8380 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8381 {
8382   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8383 }
8384
8385 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8386 {
8387   return contentNotNullBase()->setInfo(info);
8388 }
8389
8390 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8391 {
8392   const std::vector<std::string> ret=getInfo();
8393   return (int)ret.size();
8394 }
8395
8396 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8397 {
8398   writeGlobals(fid,*this);
8399   contentNotNullBase()->writeLL(fid,*this);
8400 }
8401
8402 /*!
8403  * This method alloc the arrays and load potentially huge arrays contained in this field.
8404  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8405  * This method can be also called to refresh or reinit values from a file.
8406  * 
8407  * \throw If the fileName is not set or points to a non readable MED file.
8408  */
8409 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8410 {
8411   if(getFileName().empty())
8412     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8413   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8414   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8415 }
8416
8417 /*!
8418  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8419  * But once data loaded once, this method does nothing.
8420  * 
8421  * \throw If the fileName is not set or points to a non readable MED file.
8422  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8423  */
8424 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8425 {
8426   if(!getFileName().empty())
8427     {
8428       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8429       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8430     }
8431 }
8432
8433 /*!
8434  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8435  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8436  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8437  * 
8438  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8439  */
8440 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8441 {
8442   contentNotNullBase()->unloadArrays();
8443 }
8444
8445 /*!
8446  * 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.
8447  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8448  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8449  * 
8450  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8451  */
8452 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8453 {
8454   if(!getFileName().empty())
8455     contentNotNullBase()->unloadArrays();
8456 }
8457
8458 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8459 {
8460   std::ostringstream oss;
8461   contentNotNullBase()->simpleRepr(0,oss,-1);
8462   simpleReprGlobs(oss);
8463   return oss.str();
8464 }
8465
8466 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8467 {
8468   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8469 }
8470
8471 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8472 {
8473   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8474   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8475   return ret;
8476 }
8477
8478 /*!
8479  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8480  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8481  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8482  */
8483 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8484 {
8485   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8486   if(!content)
8487     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8488   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8489   std::size_t sz(contentsSplit.size());
8490   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8491   for(std::size_t i=0;i<sz;i++)
8492     {
8493       ret[i]=shallowCpy();
8494       ret[i]->_content=contentsSplit[i];
8495     }
8496   return ret;
8497 }
8498
8499 /*!
8500  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8501  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8502  */
8503 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8504 {
8505   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8506   if(!content)
8507     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8508   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8509   std::size_t sz(contentsSplit.size());
8510   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8511   for(std::size_t i=0;i<sz;i++)
8512     {
8513       ret[i]=shallowCpy();
8514       ret[i]->_content=contentsSplit[i];
8515     }
8516   return ret;
8517 }
8518
8519 /*!
8520  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8521  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8522  */
8523 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8524 {
8525   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8526   if(!content)
8527     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8528   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8529   std::size_t sz(contentsSplit.size());
8530   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8531   for(std::size_t i=0;i<sz;i++)
8532     {
8533       ret[i]=shallowCpy();
8534       ret[i]->_content=contentsSplit[i];
8535     }
8536   return ret;
8537 }
8538
8539 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8540 {
8541   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8542   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8543     ret->_content=_content->deepCopy();
8544   ret->deepCpyGlobs(*this);
8545   return ret.retn();
8546 }
8547
8548 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8549 {
8550   return _content;
8551 }
8552
8553 /*!
8554  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8555  *  \param [in] iteration - the iteration number of a required time step.
8556  *  \param [in] order - the iteration order number of required time step.
8557  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8558  *          delete this field using decrRef() as it is no more needed.
8559  *  \throw If there is no required time step in \a this field.
8560  */
8561 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8562 {
8563   int pos=getPosOfTimeStep(iteration,order);
8564   return getTimeStepAtPos(pos);
8565 }
8566
8567 /*!
8568  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8569  *  \param [in] time - the time of the time step of interest.
8570  *  \param [in] eps - a precision used to compare time values.
8571  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8572  *          delete this field using decrRef() as it is no more needed.
8573  *  \throw If there is no required time step in \a this field.
8574  */
8575 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8576 {
8577   int pos=getPosGivenTime(time,eps);
8578   return getTimeStepAtPos(pos);
8579 }
8580
8581 /*!
8582  * 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.
8583  * The float64 value of time attached to the pair of integers are not considered here.
8584  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8585  *
8586  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8587  * \throw If there is a null pointer in \a vectFMTS.
8588  */
8589 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8590 {
8591   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8592   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8593   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8594   while(!lstFMTS.empty())
8595     {
8596       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8597       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8598       if(!curIt)
8599         throw INTERP_KERNEL::Exception(msg);
8600       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8601       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8602       elt.push_back(curIt); it=lstFMTS.erase(it);
8603       while(it!=lstFMTS.end())
8604         {
8605           curIt=*it;
8606           if(!curIt)
8607             throw INTERP_KERNEL::Exception(msg);
8608           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8609           if(refIts==curIts)
8610             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8611           else
8612             it++;
8613         }
8614       ret.push_back(elt);
8615     }
8616   return ret;
8617 }
8618
8619 /*!
8620  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8621  * All returned instances in a subvector can be safely loaded, rendered along time
8622  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8623  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8624  * 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).
8625  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8626  * 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.
8627  *
8628  * \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().
8629  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8630  * \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.
8631  * \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.
8632  *
8633  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8634  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8635  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8636  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8637  * \throw If mesh is null.
8638  * \throw If an element in \a vectFMTS is null.
8639  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8640  */
8641 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8642 {
8643   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8644   if(!mesh)
8645     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8646   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8647   if(vectFMTS.empty())
8648     return ret;
8649   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8650   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8651   if(!frstElt)
8652     throw INTERP_KERNEL::Exception(msg);
8653   std::size_t i=0;
8654   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8655   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8656   for(;it!=vectFMTS.end();it++,i++)
8657     {
8658       if(!(*it))
8659         throw INTERP_KERNEL::Exception(msg);
8660       TypeOfField tof0,tof1;
8661       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8662         {
8663           if(tof1!=ON_NODES)
8664             vectFMTSNotNodes.push_back(*it);
8665           else
8666             vectFMTSNodes.push_back(*it);
8667         }
8668       else
8669         vectFMTSNotNodes.push_back(*it);
8670     }
8671   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8672   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8673   ret=retCell;
8674   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8675     {
8676       i=0;
8677       bool isFetched(false);
8678       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8679         {
8680           if((*it0).empty())
8681             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8682           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8683             { ret[i].push_back(*it2); isFetched=true; }
8684         }
8685       if(!isFetched)
8686         {
8687           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8688           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8689           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8690         }
8691     }
8692   fsc=cmps;
8693   return ret;
8694 }
8695
8696 /*!
8697  * 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.
8698  * \param [out] cmps - same size than the returned vector.
8699  */
8700 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8701 {
8702   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8703   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8704   while(!lstFMTS.empty())
8705     {
8706       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8707       MEDFileAnyTypeFieldMultiTS *ref(*it);
8708       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8709       elt.push_back(ref); it=lstFMTS.erase(it);
8710       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8711       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8712       while(it!=lstFMTS.end())
8713         {
8714           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8715           if(cmp->isEqual(curIt))
8716             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8717           else
8718             it++;
8719         }
8720       ret.push_back(elt); cmps.push_back(cmp);
8721     }
8722   return ret;
8723 }
8724
8725 /*!
8726  * 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.
8727  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8728  *
8729  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8730  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8731  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8732  * \thorw If \a f0 and \a f1 do not have the same times steps.
8733  * \throw If mesh is null.
8734  * \throw If \a f0 or \a f1 is null.
8735  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8736  */
8737 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8738 {
8739   if(!mesh)
8740     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8741   if(!f0 || !f1)
8742     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8743   if(f0->getMeshName()!=mesh->getName())
8744     {
8745       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8746       throw INTERP_KERNEL::Exception(oss.str());
8747     }
8748   if(f1->getMeshName()!=mesh->getName())
8749     {
8750       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8751       throw INTERP_KERNEL::Exception(oss.str());
8752     }
8753   int nts=f0->getNumberOfTS();
8754   if(nts!=f1->getNumberOfTS())
8755     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8756   if(nts==0)
8757     return nts;
8758   for(int i=0;i<nts;i++)
8759     {
8760       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8761       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8762       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8763       if(tofs0.size()!=1 || tofs1.size()!=1)
8764         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8765       if(i!=0)
8766         {
8767           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8768             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8769         }
8770       else
8771         { tof0=tofs0[0]; tof1=tofs1[0]; }
8772       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8773         {
8774           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() << ") !";
8775           throw INTERP_KERNEL::Exception(oss.str());
8776         }
8777       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8778         {
8779           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() << ") !";
8780           throw INTERP_KERNEL::Exception(oss.str());
8781         }
8782       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8783         {
8784           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() << ") !";
8785           throw INTERP_KERNEL::Exception(oss.str());
8786         }
8787     }
8788   return nts;
8789 }
8790
8791 template<class T>
8792 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
8793 {
8794   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
8795   if(f1tss.empty())
8796     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
8797   std::size_t sz(f1tss.size()),i(0);
8798   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
8799   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
8800     {
8801       typename MLFieldTraits<T>::F1TSType const *elt(*it);
8802       if(!elt)
8803         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
8804       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
8805     }
8806   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
8807   if(!retc)
8808     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
8809   retc->aggregate(f1tsw,dts);
8810   ret->setDtUnit(f1tss[0]->getDtUnit());
8811   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
8812 }
8813
8814 template<class T>
8815 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
8816 {
8817   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
8818   if(fmtss.empty())
8819     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
8820   std::size_t sz(fmtss.size());
8821   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
8822     {
8823       typename MLFieldTraits<T>::FMTSType const *elt(*it);
8824       if(!elt)
8825         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
8826     }
8827   int nbTS(fmtss[0]->getNumberOfTS());
8828   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
8829     if((*it)->getNumberOfTS()!=nbTS)
8830       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
8831   for(int iterTS=0;iterTS<nbTS;iterTS++)
8832     {
8833       std::size_t i(0);
8834       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
8835       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
8836       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
8837         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
8838       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
8839       ret->pushBackTimeStep(f1ts);
8840       ret->setDtUnit(f1ts->getDtUnit());
8841     }
8842   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
8843 }
8844
8845 /*!
8846  * \a dts and \a ftmss are expected to have same size.
8847  */
8848 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
8849 {
8850   if(fmtss.empty())
8851     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
8852   std::size_t sz(fmtss.size());
8853   std::vector<const MEDFileFieldMultiTS *> fmtss1;
8854   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
8855   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
8856     {
8857       if(!(*it))
8858         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
8859       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
8860       if(elt1)
8861         {
8862           fmtss1.push_back(elt1);
8863           continue;
8864         }
8865       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
8866       if(elt2)
8867         {
8868           fmtss2.push_back(elt2);
8869           continue;
8870         }
8871       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
8872     }
8873   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
8874     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
8875   if(fmtss1.size()==sz)
8876     return AggregateHelperFMTS<double>(fmtss1,dts);
8877   if(fmtss2.size()!=sz)
8878     return AggregateHelperFMTS<int>(fmtss2,dts);
8879   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
8880 }
8881
8882 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8883 {
8884   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8885 }
8886
8887 //= MEDFileFieldMultiTS
8888
8889 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8890 {
8891   return new MEDFileFieldMultiTS(*this);
8892 }
8893
8894 /*!
8895  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8896  * following the given input policy.
8897  *
8898  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8899  *                            By default (true) the globals are deeply copied.
8900  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8901  */
8902 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8903 {
8904   MCAuto<MEDFileIntFieldMultiTS> ret;
8905   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8906   if(content)
8907     {
8908       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8909       if(!contc)
8910         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8911       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8912       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
8913     }
8914   else
8915     ret=MEDFileIntFieldMultiTS::New();
8916   if(isDeepCpyGlobs)
8917     ret->deepCpyGlobs(*this);
8918   else
8919     ret->shallowCpyGlobs(*this);
8920   return ret.retn();
8921 }
8922
8923 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8924 try:MEDFileTemplateFieldMultiTS<double>(fid,loadAll,ms)
8925 {
8926 }
8927 catch(INTERP_KERNEL::Exception& e)
8928 { throw e; }
8929
8930 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8931 try:MEDFileTemplateFieldMultiTS<double>(fid,fieldName,loadAll,ms,entities)
8932 {
8933 }
8934 catch(INTERP_KERNEL::Exception& e)
8935 { throw e; }
8936
8937 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileTemplateFieldMultiTS<double>(other,shallowCopyOfContent)
8938 {
8939 }
8940
8941 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
8942 {
8943   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8944 }
8945
8946 //= MEDFileAnyTypeFieldMultiTSIterator
8947
8948 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8949 {
8950   if(fmts)
8951     {
8952       fmts->incrRef();
8953       _nb_iter=fmts->getNumberOfTS();
8954     }
8955 }
8956
8957 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
8958 {
8959 }
8960
8961 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
8962 {
8963   if(_iter_id<_nb_iter)
8964     {
8965       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
8966       if(fmts)
8967         return fmts->getTimeStepAtPos(_iter_id++);
8968       else
8969         return 0;
8970     }
8971   else
8972     return 0;
8973 }
8974
8975 //= MEDFileIntFieldMultiTS
8976
8977 //= MEDFileFields
8978
8979 MEDFileFields *MEDFileFields::New()
8980 {
8981   return new MEDFileFields;
8982 }
8983
8984 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
8985 {
8986   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8987   return New(fid,loadAll);
8988 }
8989
8990 MEDFileFields *MEDFileFields::NewAdv(const std::string& fileName, bool loadAll, const MEDFileEntities *entities)
8991 {
8992   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8993   return NewAdv(fid,loadAll,entities);
8994 }
8995
8996 MEDFileFields *MEDFileFields::NewAdv(med_idt fid, bool loadAll, const MEDFileEntities *entities)
8997 {
8998   return new MEDFileFields(fid,loadAll,0,entities);
8999 }
9000
9001 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
9002 {
9003   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9004   return NewWithDynGT(fid,se,loadAll);
9005 }
9006
9007 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
9008 {
9009   if(!se)
9010     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
9011   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
9012   return new MEDFileFields(fid,loadAll,0,entities);
9013 }
9014
9015 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
9016 {
9017   return new MEDFileFields(fid,loadAll,0,0);
9018 }
9019
9020 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9021 {
9022   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9023   return new MEDFileFields(fid,loadAll,ms,0);
9024 }
9025
9026 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9027 {
9028   MEDFileUtilities::CheckFileForRead(fileName);
9029   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9030   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9031   return new MEDFileFields(fid,loadAll,0,ent);
9032 }
9033
9034 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9035 {
9036   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9037   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9038   return ret;
9039 }
9040
9041 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9042 {
9043   std::vector<const BigMemoryObject *> ret;
9044   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9045     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9046   return ret;
9047 }
9048
9049 MEDFileFields *MEDFileFields::deepCopy() const
9050 {
9051   MCAuto<MEDFileFields> ret(shallowCpy());
9052   std::size_t i(0);
9053   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9054     {
9055       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9056         ret->_fields[i]=(*it)->deepCopy();
9057     }
9058   ret->deepCpyGlobs(*this);
9059   return ret.retn();
9060 }
9061
9062 MEDFileFields *MEDFileFields::shallowCpy() const
9063 {
9064   return new MEDFileFields(*this);
9065 }
9066
9067 /*!
9068  * 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
9069  * 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.
9070  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9071  *
9072  * \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.
9073  * \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.
9074  * 
9075  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9076  */
9077 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9078 {
9079   std::set< std::pair<int,int> > s;
9080   bool firstShot=true;
9081   areThereSomeForgottenTS=false;
9082   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9083     {
9084       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9085         continue;
9086       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9087       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9088       if(firstShot)
9089         { s=s1; firstShot=false; }
9090       else
9091         {
9092           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9093           if(s!=s2)
9094             areThereSomeForgottenTS=true;
9095           s=s2;
9096         }
9097     }
9098   std::vector< std::pair<int,int> > ret;
9099   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9100   return ret;
9101 }
9102
9103 int MEDFileFields::getNumberOfFields() const
9104 {
9105   return _fields.size();
9106 }
9107
9108 std::vector<std::string> MEDFileFields::getFieldsNames() const
9109 {
9110   std::vector<std::string> ret(_fields.size());
9111   int i(0);
9112   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9113     {
9114       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9115       if(f)
9116         {
9117           ret[i]=f->getName();
9118         }
9119       else
9120         {
9121           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9122           throw INTERP_KERNEL::Exception(oss.str());
9123         }
9124     }
9125   return ret;
9126 }
9127
9128 std::vector<std::string> MEDFileFields::getMeshesNames() const
9129 {
9130   std::vector<std::string> ret;
9131   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9132     {
9133       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9134       if(cur)
9135         ret.push_back(cur->getMeshName());
9136     }
9137   return ret;
9138 }
9139
9140 std::string MEDFileFields::simpleRepr() const
9141 {
9142   std::ostringstream oss;
9143   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9144   simpleRepr(0,oss);
9145   return oss.str();
9146 }
9147
9148 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9149 {
9150   int nbOfFields(getNumberOfFields());
9151   std::string startLine(bkOffset,' ');
9152   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9153   int i=0;
9154   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9155     {
9156       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9157       if(cur)
9158         {
9159           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9160         }
9161       else
9162         {
9163           oss << startLine << "  - not defined !" << std::endl;
9164         }
9165     }
9166   i=0;
9167   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9168     {
9169       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9170       std::string chapter(17,'0'+i);
9171       oss << startLine << chapter << std::endl;
9172       if(cur)
9173         {
9174           cur->simpleRepr(bkOffset+2,oss,i);
9175         }
9176       else
9177         {
9178           oss << startLine << "  - not defined !" << std::endl;
9179         }
9180       oss << startLine << chapter << std::endl;
9181     }
9182   simpleReprGlobs(oss);
9183 }
9184
9185 MEDFileFields::MEDFileFields()
9186 {
9187 }
9188
9189 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9190 try:MEDFileFieldGlobsReal(fid)
9191 {
9192   int nbFields(MEDnField(fid));
9193   _fields.resize(nbFields);
9194   med_field_type typcha;
9195   for(int i=0;i<nbFields;i++)
9196     {
9197       std::vector<std::string> infos;
9198       std::string fieldName,dtunit,meshName;
9199       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit,meshName));
9200       switch(typcha)
9201       {
9202         case MED_FLOAT64:
9203           {
9204             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9205             break;
9206           }
9207         case MED_INT32:
9208           {
9209             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9210             break;
9211           }
9212         case MED_FLOAT32:
9213           {
9214             _fields[i]=MEDFileFloatFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9215             break;
9216           }
9217         default:
9218           {
9219             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] !";
9220             throw INTERP_KERNEL::Exception(oss.str());
9221           }
9222       }
9223     }
9224   loadAllGlobals(fid,entities);
9225 }
9226 catch(INTERP_KERNEL::Exception& e)
9227 {
9228     throw e;
9229 }
9230
9231 void MEDFileFields::writeLL(med_idt fid) const
9232 {
9233   int i=0;
9234   writeGlobals(fid,*this);
9235   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9236     {
9237       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9238       if(!elt)
9239         {
9240           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9241           throw INTERP_KERNEL::Exception(oss.str());
9242         }
9243       elt->writeLL(fid,*this);
9244     }
9245 }
9246
9247 /*!
9248  * This method alloc the arrays and load potentially huge arrays contained in this field.
9249  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9250  * This method can be also called to refresh or reinit values from a file.
9251  * 
9252  * \throw If the fileName is not set or points to a non readable MED file.
9253  */
9254 void MEDFileFields::loadArrays()
9255 {
9256   if(getFileName().empty())
9257     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9258   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9259   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9260     {
9261       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9262       if(elt)
9263         elt->loadBigArraysRecursively(fid,*elt);
9264     }
9265 }
9266
9267 /*!
9268  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9269  * But once data loaded once, this method does nothing.
9270  * 
9271  * \throw If the fileName is not set or points to a non readable MED file.
9272  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9273  */
9274 void MEDFileFields::loadArraysIfNecessary()
9275 {
9276   if(!getFileName().empty())
9277     {
9278       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9279       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9280         {
9281           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9282           if(elt)
9283             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9284         }
9285     }
9286 }
9287
9288 /*!
9289  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9290  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9291  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9292  * 
9293  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9294  */
9295 void MEDFileFields::unloadArrays()
9296 {
9297   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9298     {
9299       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9300       if(elt)
9301         elt->unloadArrays();
9302     }
9303 }
9304
9305 /*!
9306  * 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.
9307  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9308  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9309  * 
9310  * \sa MEDFileFields::loadArraysIfNecessary
9311  */
9312 void MEDFileFields::unloadArraysWithoutDataLoss()
9313 {
9314   if(!getFileName().empty())
9315     unloadArrays();
9316 }
9317
9318 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9319 {
9320   std::vector<std::string> ret;
9321   std::set<std::string> ret2;
9322   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9323     {
9324       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9325       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9326         if(ret2.find(*it2)==ret2.end())
9327           {
9328             ret.push_back(*it2);
9329             ret2.insert(*it2);
9330           }
9331     }
9332   return ret;
9333 }
9334
9335 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9336 {
9337   std::vector<std::string> ret;
9338   std::set<std::string> ret2;
9339   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9340     {
9341       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
9342       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9343         if(ret2.find(*it2)==ret2.end())
9344           {
9345             ret.push_back(*it2);
9346             ret2.insert(*it2);
9347           }
9348     }
9349   return ret;
9350 }
9351
9352 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9353 {
9354   std::vector<std::string> ret;
9355   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9356     {
9357       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
9358       ret.insert(ret.end(),tmp.begin(),tmp.end());
9359     }
9360   return ret;
9361 }
9362
9363 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9364 {
9365   std::vector<std::string> ret;
9366   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9367     {
9368       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
9369       ret.insert(ret.end(),tmp.begin(),tmp.end());
9370     }
9371   return ret;
9372 }
9373
9374 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9375 {
9376   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9377     (*it)->changePflsRefsNamesGen2(mapOfModif);
9378 }
9379
9380 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9381 {
9382   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9383     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9384 }
9385
9386 void MEDFileFields::resize(int newSize)
9387 {
9388   _fields.resize(newSize);
9389 }
9390
9391 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
9392 {
9393   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9394     pushField(*it);
9395 }
9396
9397 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
9398 {
9399   if(!field)
9400     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9401   _fields.push_back(field->getContent());
9402   appendGlobs(*field,1e-12);
9403 }
9404
9405 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
9406 {
9407   if(!field)
9408     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9409   if(i>=(int)_fields.size())
9410     _fields.resize(i+1);
9411   _fields[i]=field->getContent();
9412   appendGlobs(*field,1e-12);
9413 }
9414
9415 void MEDFileFields::destroyFieldAtPos(int i)
9416 {
9417   destroyFieldsAtPos(&i,&i+1);
9418 }
9419
9420 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
9421 {
9422   std::vector<bool> b(_fields.size(),true);
9423   for(const int *i=startIds;i!=endIds;i++)
9424     {
9425       if(*i<0 || *i>=(int)_fields.size())
9426         {
9427           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9428           throw INTERP_KERNEL::Exception(oss.str());
9429         }
9430       b[*i]=false;
9431     }
9432   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9433   std::size_t j=0;
9434   for(std::size_t i=0;i<_fields.size();i++)
9435     if(b[i])
9436       fields[j++]=_fields[i];
9437   _fields=fields;
9438 }
9439
9440 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
9441 {
9442   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9443   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
9444   std::vector<bool> b(_fields.size(),true);
9445   int k=bg;
9446   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9447     {
9448       if(k<0 || k>=(int)_fields.size())
9449         {
9450           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9451           throw INTERP_KERNEL::Exception(oss.str());
9452         }
9453       b[k]=false;
9454     }
9455   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9456   std::size_t j(0);
9457   for(std::size_t i=0;i<_fields.size();i++)
9458     if(b[i])
9459       fields[j++]=_fields[i];
9460   _fields=fields;
9461 }
9462
9463 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9464 {
9465   bool ret(false);
9466   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9467     {
9468       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9469       if(cur)
9470         ret=cur->changeMeshNames(modifTab) || ret;
9471     }
9472   return ret;
9473 }
9474
9475 /*!
9476  * \param [in] meshName the name of the mesh that will be renumbered.
9477  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9478  *             This code corresponds to the distribution of types in the corresponding mesh.
9479  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9480  * \param [in] renumO2N the old to new renumber array.
9481  * \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 
9482  *         field in \a this.
9483  */
9484 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
9485 {
9486   bool ret(false);
9487   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9488     {
9489       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9490       if(fmts)
9491         {
9492           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9493         }
9494     }
9495   return ret;
9496 }
9497
9498 /*!
9499  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9500  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9501  *
9502  * \return A new object that the caller is responsible to deallocate.
9503  */
9504 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9505 {
9506   if(!mm)
9507     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
9508   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
9509   int nbFields(getNumberOfFields());
9510   for(int i=0;i<nbFields;i++)
9511     {
9512       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
9513       if(!fmts)
9514         {
9515           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
9516           throw INTERP_KERNEL::Exception(oss.str());
9517         }
9518       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
9519       fsOut->pushField(fmtsOut);
9520     }
9521   return fsOut.retn();
9522 }
9523
9524 void MEDFileFields::accept(MEDFileFieldVisitor& visitor) const
9525 {
9526   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9527     if((*it).isNotNull())
9528       {
9529         visitor.newFieldEntry(*it);
9530         (*it)->accept(visitor);
9531         visitor.endFieldEntry(*it);
9532       }
9533 }
9534
9535 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
9536 {
9537   if(i<0 || i>=(int)_fields.size())
9538     {
9539       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9540       throw INTERP_KERNEL::Exception(oss.str());
9541     }
9542   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9543   if(!fmts)
9544     return 0;
9545   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
9546   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
9547   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
9548   const MEDFileFloatFieldMultiTSWithoutSDA *fmtsC3(dynamic_cast<const MEDFileFloatFieldMultiTSWithoutSDA *>(fmts));
9549   if(fmtsC)
9550     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9551   else if(fmtsC2)
9552     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9553   else if(fmtsC3)
9554     ret=MEDFileFloatFieldMultiTS::New(*fmtsC3,false);
9555   else
9556     {
9557       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor float (FLOAT32) nor integer (INT32) !";
9558       throw INTERP_KERNEL::Exception(oss.str());
9559     }
9560   ret->shallowCpyGlobs(*this);
9561   return ret.retn();
9562 }
9563
9564 /*!
9565  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9566  * This method is accessible in python using __getitem__ with a list in input.
9567  * \return a new object that the caller should deal with.
9568  */
9569 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
9570 {
9571   MCAuto<MEDFileFields> ret=shallowCpy();
9572   std::size_t sz=std::distance(startIds,endIds);
9573   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9574   int j=0;
9575   for(const int *i=startIds;i!=endIds;i++,j++)
9576     {
9577       if(*i<0 || *i>=(int)_fields.size())
9578         {
9579           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9580           throw INTERP_KERNEL::Exception(oss.str());
9581         }
9582       fields[j]=_fields[*i];
9583     }
9584   ret->_fields=fields;
9585   return ret.retn();
9586 }
9587
9588 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
9589 {
9590   return getFieldAtPos(getPosFromFieldName(fieldName));
9591 }
9592
9593 /*!
9594  * This method removes, if any, fields in \a this having no time steps.
9595  * 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.
9596  * 
9597  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
9598  */
9599 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
9600 {
9601   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
9602   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9603     {
9604       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9605       if(elt)
9606         {
9607           if(elt->getNumberOfTS()>0)
9608             newFields.push_back(*it);
9609         }
9610     }
9611   if(_fields.size()==newFields.size())
9612     return false;
9613   _fields=newFields;
9614   return true;
9615 }
9616
9617 /*!
9618  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9619  * This method can be seen as a filter applied on \a this, that returns an object containing
9620  * 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
9621  * shallow copied from \a this.
9622  * 
9623  * \param [in] meshName - the name of the mesh on w
9624  * \return a new object that the caller should deal with.
9625  */
9626 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
9627 {
9628   MCAuto<MEDFileFields> ret(MEDFileFields::New());
9629   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9630     {
9631       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9632       if(!cur)
9633         continue;
9634       if(cur->getMeshName()==meshName)
9635         {
9636           cur->incrRef();
9637           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9638           ret->_fields.push_back(cur2);
9639         }
9640     }
9641   ret->shallowCpyOnlyUsedGlobs(*this);
9642   return ret.retn();
9643 }
9644
9645 /*!
9646  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9647  * Input time steps are specified using a pair of integer (iteration, order).
9648  * 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,
9649  * but for each multitimestep only the time steps in \a timeSteps are kept.
9650  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9651  * 
9652  * The returned object points to shallow copy of elements in \a this.
9653  * 
9654  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9655  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9656  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9657  */
9658 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
9659 {
9660   MCAuto<MEDFileFields> ret(MEDFileFields::New());
9661   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9662     {
9663       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9664       if(!cur)
9665         continue;
9666       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
9667       ret->_fields.push_back(elt);
9668     }
9669   ret->shallowCpyOnlyUsedGlobs(*this);
9670   return ret.retn();
9671 }
9672
9673 /*!
9674  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
9675  */
9676 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
9677 {
9678   MCAuto<MEDFileFields> ret=MEDFileFields::New();
9679   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9680     {
9681       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9682       if(!cur)
9683         continue;
9684       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
9685       if(elt->getNumberOfTS()!=0)
9686         ret->_fields.push_back(elt);
9687     }
9688   ret->shallowCpyOnlyUsedGlobs(*this);
9689   return ret.retn();
9690 }
9691
9692 bool MEDFileFields::presenceOfStructureElements() const
9693 {
9694   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9695     if((*it).isNotNull())
9696       if((*it)->presenceOfStructureElements())
9697         return true;
9698   return false;
9699 }
9700
9701 void MEDFileFields::killStructureElements()
9702 {
9703   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
9704   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9705     if((*it).isNotNull())
9706       {
9707         if((*it)->presenceOfStructureElements())
9708           {
9709             if(!(*it)->onlyStructureElements())
9710               {
9711                 (*it)->killStructureElements();
9712                 ret.push_back(*it);
9713               }
9714           }
9715         else
9716           {
9717             ret.push_back(*it);
9718           }
9719       }
9720   _fields=ret;
9721 }
9722
9723 void MEDFileFields::keepOnlyStructureElements()
9724 {
9725   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
9726   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9727     if((*it).isNotNull())
9728       {
9729         if((*it)->presenceOfStructureElements())
9730           {
9731             if(!(*it)->onlyStructureElements())
9732               (*it)->keepOnlyStructureElements();
9733             ret.push_back(*it);
9734           }
9735       }
9736   _fields=ret;
9737 }
9738
9739 void MEDFileFields::keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName)
9740 {
9741   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
9742   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9743     if((*it).isNotNull())
9744       {
9745         if((*it)->getMeshName()!=meshName)
9746           continue;
9747         std::vector< std::pair<std::string,std::string> > ps;
9748         (*it)->getMeshSENames(ps);
9749         std::pair<std::string,std::string> p(meshName,seName);
9750         if(std::find(ps.begin(),ps.end(),p)!=ps.end())
9751           (*it)->keepOnlyOnSE(seName);
9752         ret.push_back(*it);
9753       }
9754   _fields=ret;
9755 }
9756
9757 void MEDFileFields::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
9758 {
9759   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9760     if((*it).isNotNull())
9761       (*it)->getMeshSENames(ps);
9762 }
9763
9764 void MEDFileFields::blowUpSE(MEDFileMeshes *ms, const MEDFileStructureElements *ses)
9765 {
9766   MEDFileBlowStrEltUp::DealWithSE(this,ms,ses);
9767 }
9768
9769 MCAuto<MEDFileFields> MEDFileFields::partOfThisOnStructureElements() const
9770 {
9771   MCAuto<MEDFileFields> ret(deepCopy());
9772   ret->keepOnlyStructureElements();
9773   return ret;
9774 }
9775
9776 MCAuto<MEDFileFields> MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const
9777 {
9778   MCAuto<MEDFileFields> ret(deepCopy());
9779   ret->keepOnlyOnMeshSE(meshName,seName);
9780   return ret;
9781 }
9782
9783 void MEDFileFields::aggregate(const MEDFileFields& other)
9784 {
9785   int nbFieldsToAdd(other.getNumberOfFields());
9786   std::vector<std::string> fsn(getFieldsNames());
9787   for(int i=0;i<nbFieldsToAdd;i++)
9788     {
9789       MCAuto<MEDFileAnyTypeFieldMultiTS> elt(other.getFieldAtPos(i));
9790       std::string name(elt->getName());
9791       if(std::find(fsn.begin(),fsn.end(),name)!=fsn.end())
9792         {
9793           std::ostringstream oss; oss << "MEDFileFields::aggregate : name \"" << name << "\" already appears !";
9794           throw INTERP_KERNEL::Exception(oss.str());
9795         }
9796       pushField(elt);
9797     }
9798 }
9799
9800 MEDFileFieldsIterator *MEDFileFields::iterator()
9801 {
9802   return new MEDFileFieldsIterator(this);
9803 }
9804
9805 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
9806 {
9807   std::string tmp(fieldName);
9808   std::vector<std::string> poss;
9809   for(std::size_t i=0;i<_fields.size();i++)
9810     {
9811       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
9812       if(f)
9813         {
9814           std::string fname(f->getName());
9815           if(tmp==fname)
9816             return i;
9817           else
9818             poss.push_back(fname);
9819         }
9820     }
9821   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
9822   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
9823   oss << " !";
9824   throw INTERP_KERNEL::Exception(oss.str());
9825 }
9826
9827 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
9828 {
9829   if(fs)
9830     {
9831       fs->incrRef();
9832       _nb_iter=fs->getNumberOfFields();
9833     }
9834 }
9835
9836 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
9837 {
9838 }
9839
9840 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
9841 {
9842   if(_iter_id<_nb_iter)
9843     {
9844       MEDFileFields *fs(_fs);
9845       if(fs)
9846         return fs->getFieldAtPos(_iter_id++);
9847       else
9848         return 0;
9849     }
9850   else
9851     return 0;
9852 }