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