]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileField.cxx
Salome HOME
[EDF15323] : Make users using MED_DESCENDING_EDGE and MED_DESCENDING_FACE instead...
[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       med_entity_type mentiCpy(menti);
584       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
585       int nbi,tmp1;
586       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
587       if(nbValsInFile==0 && menti==MED_CELL)
588         {//
589           nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_FACE,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
590           if(nbValsInFile==0)
591             {
592               nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_EDGE,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
593               if(nbValsInFile!=0)
594                 { mentiCpy=MED_DESCENDING_EDGE; }
595             }
596           else
597             { mentiCpy=MED_DESCENDING_FACE; }
598         }
599       if(_end-_start!=nbValsInFile*nbi)
600         {
601           std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
602           throw INTERP_KERNEL::Exception(oss.str());
603         }
604       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,mentiCpy,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
605     }
606   else
607     {
608       if(!_profile.empty())
609         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
610       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
611       int profilesize,nbi;
612       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
613       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
614       if(spd)
615         {
616           int start,stop,step;
617           spd->getSlice(start,stop,step);
618           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
619           med_filter filter=MED_FILTER_INIT;
620           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
621                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
622                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
623                                    /*lastblocksize=useless because count=1*/0,&filter);
624           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
625           MEDfilterClose(&filter);
626           return ;
627         }
628       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
629       if(dpd)
630         {
631           dpd->checkConsistencyLight();
632           MCAuto<DataArrayInt> myIds(dpd->toDAI());
633           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
634           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
635           myIds->applyLin(1,-a);
636           int nbOfEltsToLoad(b-a+1);
637           med_filter filter=MED_FILTER_INIT;
638           {//TODO : manage int32 !
639             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
640             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
641             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
642                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
643                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
644                                      /*lastblocksize=useless because count=1*/0,&filter);
645             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
646             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
647             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
648             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
649           }
650           MEDfilterClose(&filter);
651         }
652       else
653         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
654     }
655 }
656
657 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
658 {
659   return _father;
660 }
661
662 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
663 {
664   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
665   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
666   std::string fieldName(nasc.getName()),meshName(getMeshName());
667   int iteration(getIteration()),order(getOrder()),profilesize,nbi;
668   TypeOfField type(getType());
669   med_geometry_type mgeoti;
670   med_entity_type menti;
671   _father->entriesForMEDfile(type,mgeoti,menti);
672   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
673   if(zeNVal==0 && type==ON_CELLS)
674     {//eheh maybe there's a surprise :)
675       int zeNVal1(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_FACE,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
676       if(zeNVal1==0)
677         {
678           int zeNVal2(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,MED_DESCENDING_EDGE,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
679           if(zeNVal2!=0)
680             zeNVal=zeNVal2;
681         }
682       else
683         {
684           zeNVal=zeNVal1;
685         }
686     }
687   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
688   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
689   const PartDefinition *pd(_pd);
690   if(!pd)
691     {
692       _nval=zeNVal;
693     }
694   else
695     {
696       if(!_profile.empty())
697         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
698       _nval=pd->getNumberOfElems();
699     }
700   _start=start;
701   _end=start+_nval*nbi;
702   start=_end;
703   if(type==ON_CELLS && !_localization.empty())
704     {
705       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
706         setType(ON_GAUSS_PT);
707       else
708         {
709           setType(ON_GAUSS_NE);
710           _localization.clear();
711         }
712     }
713 }
714
715 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
716 {
717   std::string fieldName(nasc.getName()),meshName(getMeshName());
718   int iteration(getIteration()),order(getOrder());
719   TypeOfField type(getType());
720   med_geometry_type mgeoti;
721   med_entity_type menti;
722   _father->entriesForMEDfile(type,mgeoti,menti);
723   if(_start>_end)
724     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
725   if(_start==_end)
726     return ;
727   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
728   if(_start<0 || _start>=arr->getNumberOfTuples())
729     {
730       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
731       throw INTERP_KERNEL::Exception(oss.str());
732     }
733   if(_end<0 || _end>arr->getNumberOfTuples())
734     {
735       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
736       throw INTERP_KERNEL::Exception(oss.str());
737     }
738   int nbOfCompo(arr->getNumberOfComponents());
739   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
740   if(arrD)
741     {
742       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
743       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
744       return ;
745     }
746   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
747   if(arrI)
748     {
749       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
750       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
751       return ;
752     }
753   DataArrayFloat *arrF(dynamic_cast<DataArrayFloat *>(arr));
754   if(arrF)
755     {
756       float *startFeeding(arrF->getPointer()+_start*nbOfCompo);
757       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
758       return ;
759     }
760   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 FLOAT32 or INT32 !");
761 }
762
763 /*!
764  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
765  */
766 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
767 {
768   int delta=_end-_start;
769   _start=newValueOfStart;
770   _end=_start+delta;
771 }
772
773 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
774 {
775   return _father->getIteration();
776 }
777
778 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
779 {
780   return _father->getOrder();
781 }
782
783 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
784 {
785   return _father->getTime();
786 }
787
788 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
789 {
790   return _father->getMeshName();
791 }
792
793 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
794 {
795   const char startLine[]="    ## ";
796   std::string startLine2(bkOffset,' ');
797   startLine2+=startLine;
798   INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
799   oss << startLine2 << "Localization #" << id << "." << std::endl;
800   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
801   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
802   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
803   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
804 }
805
806 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
807 {
808   return _type;
809 }
810
811 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
812 {
813   return _father->getGeoType();
814 }
815
816 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
817 {
818   types.insert(_type);
819 }
820
821 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
822 {
823   _type=newType;
824 }
825
826 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
827 {
828   return _father->getNumberOfComponents();
829 }
830
831 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
832 {
833   return _end-_start;
834 }
835
836 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
837 {
838   return _father->getOrCreateAndGetArray();
839 }
840
841 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
842 {
843   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
844   return fath->getOrCreateAndGetArray();
845 }
846
847 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
848 {
849   return _father->getInfo();
850 }
851
852 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
853 {
854   return _profile;
855 }
856
857 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
858 {
859   _profile=newPflName;
860 }
861
862 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
863 {
864   return _localization;
865 }
866
867 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
868 {
869   _localization=newLocName;
870 }
871
872 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
873 {
874   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
875     {
876       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
877         {
878           _profile=(*it2).second;
879           return;
880         }
881     }
882 }
883
884 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
885 {
886   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
887     {
888       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
889         {
890           _localization=(*it2).second;
891           return;
892         }
893     }
894 }
895
896 void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
897 {
898   if(type!=_type)
899     return ;
900   dads.push_back(std::pair<int,int>(_start,_end));
901   geoTypes.push_back(getGeoType());
902   if(_profile.empty())
903     pfls.push_back(0);
904   else
905     {
906       pfls.push_back(glob->getProfile(_profile.c_str()));
907     }
908   if(_localization.empty())
909     locs.push_back(-1);
910   else
911     {
912       locs.push_back(glob->getLocalizationId(_localization.c_str()));
913     }
914 }
915
916 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
917 {
918   entries[startEntryId]=std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int> ,std::pair<int,int> >(std::pair<INTERP_KERNEL::NormalizedCellType,int>(getGeoType(),discId),std::pair<int,int>(_start,_end));
919   startEntryId++;
920 }
921
922 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
923 {
924   TypeOfField type=getType();
925   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
926   med_geometry_type mgeoti;
927   med_entity_type menti;
928   _father->entriesForMEDfile(getType(),mgeoti,menti);
929   const DataArray *arr(getOrCreateAndGetArray());
930   if(!arr)
931     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
932   if(!arr->isAllocated())
933     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
934   const DataArrayDouble *arrD(dynamic_cast<const DataArrayDouble *>(arr));
935   const DataArrayInt *arrI(dynamic_cast<const DataArrayInt *>(arr));
936   const DataArrayFloat *arrF(dynamic_cast<const DataArrayFloat *>(arr));
937   const unsigned char *locToWrite=0;
938   if(arrD)
939     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
940   else if(arrI)
941     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
942   else if(arrF)
943     locToWrite=reinterpret_cast<const unsigned char *>(arrF->getConstPointer()+_start*arr->getNumberOfComponents());
944   else
945     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 FLOAT32 and INT32 !");
946   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
947                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
948                                                    locToWrite));
949 }
950
951 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
952 {
953   type=_type;
954   pfl=_profile;
955   loc=_localization;
956   dad.first=_start; dad.second=_end;
957 }
958
959 /*!
960  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
961  *             This code corresponds to the distribution of types in the corresponding mesh.
962  * \param [out] ptToFill memory zone where the output will be stored.
963  * \return the size of data pushed into output param \a ptToFill
964  */
965 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
966 {
967   _loc_id=offset;
968   std::ostringstream oss;
969   std::size_t nbOfType=codeOfMesh.size()/3;
970   int found=-1;
971   for(std::size_t i=0;i<nbOfType && found==-1;i++)
972     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
973       found=(int)i;
974   if(found==-1)
975     {
976       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
977       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
978       throw INTERP_KERNEL::Exception(oss.str());
979     }
980   int *work=ptToFill;
981   if(_profile.empty())
982     {
983       if(_nval!=codeOfMesh[3*found+1])
984         {
985           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
986           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
987           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
988           throw INTERP_KERNEL::Exception(oss.str());
989         }
990       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
991         *work++=ii;
992     }
993   else
994     {
995       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
996       if(pfl->getNumberOfTuples()!=_nval)
997         {
998           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
999           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
1000           oss << _nval;
1001           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
1002           throw INTERP_KERNEL::Exception(oss.str());
1003         }
1004       int offset2=codeOfMesh[3*found+2];
1005       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
1006         {
1007           if(*pflId<codeOfMesh[3*found+1])
1008             *work++=offset2+*pflId;
1009         }
1010     }
1011   return _nval;
1012 }
1013
1014 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
1015 {
1016   for(int i=_start;i<_end;i++)
1017     *ptToFill++=i;
1018   return _end-_start;
1019 }
1020
1021 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
1022 {
1023   switch(type)
1024   {
1025     case ON_CELLS:
1026       return -2;
1027     case ON_GAUSS_NE:
1028       return -1;
1029     case ON_GAUSS_PT:
1030       return locId;
1031     default:
1032       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
1033   }
1034 }
1035
1036 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
1037 {
1038   int id=0;
1039   std::map<std::pair<std::string,TypeOfField>,int> m;
1040   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
1041   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
1042     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
1043       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
1044   ret.resize(id);
1045   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
1046     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
1047   return ret;
1048 }
1049
1050 /*!
1051  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
1052  * 
1053  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
1054  * \param [in] entriesOnSameDisc some entries **on same localization** if not the result can be invalid. The _start and _end on them are relative to \a arr parameter.
1055  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
1056  * \param [in] newCode one of the input parameter to explicit the new geo type dispatch (in classical format same than those asked by MEDFileFields::renumberEntitiesLyingOnMesh)
1057  * \param [in,out] glob if necessary by the method, new profiles can be added to it
1058  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
1059  * \param [out] result All new entries will be appended on it.
1060  * \return false if the configuration of renumbering leads to an unnecessary resplit of input \a entriesOnSameDisc. If not true is returned (the most general case !)
1061  */
1062 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1063                                                        const DataArrayInt *explicitIdsInMesh,
1064                                                        const std::vector<int>& newCode,
1065                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
1066                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
1067 {
1068   if(entriesOnSameDisc.empty())
1069     return false;
1070   TypeOfField type=entriesOnSameDisc[0]->getType();
1071   int szEntities=0,szTuples=0;
1072   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
1073     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
1074   int nbi=szTuples/szEntities;
1075   if(szTuples%szEntities!=0)
1076     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
1077   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
1078   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
1079   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
1080   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
1081   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
1082   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
1083   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
1084   int id=0;
1085   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
1086     {
1087       int startOfEltIdOfChunk=(*it)->_start;
1088       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
1089       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
1090       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
1091       //
1092       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
1093       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
1094       //
1095       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
1096       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
1097     }
1098   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
1099   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
1100   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
1101   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
1102   //
1103   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
1104   //
1105   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
1106   arrPart->renumberInPlace(renumTupleIds->begin());
1107   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
1108   bool ret=false;
1109   const int *idIt=diffVals->begin();
1110   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
1111   int offset2=0;
1112   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
1113     {
1114       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
1115       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
1116       int nbEntityElts=subIds->getNumberOfTuples();
1117       bool ret2;
1118       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
1119           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
1120                                       offset+offset2,
1121                                       li,glob,ret2);
1122       ret=ret || ret2;
1123       result.push_back(eltToAdd);
1124       offset2+=nbEntityElts*nbi;
1125     }
1126   ret=ret || li.empty();
1127   return ret;
1128 }
1129
1130 /*!
1131  * \param [in] typeF type of field of new chunk
1132  * \param [in] geoType the geometric type of the chunk
1133  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
1134  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
1135  * \param [in] nbi number of integration points
1136  * \param [in] offset The offset in the **global array of data**.
1137  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
1138  *                 to the new chunk to create.
1139  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
1140  * \param [out] notInExisting If false the return newly allocated entry is not coming from \a entriesOnSameDisc. If true the output comes from copy of \a entriesOnSameDisc
1141  *              and corresponding entry erased from \a entriesOnSameDisc.
1142  * \return a newly allocated chunk
1143  */
1144 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
1145                                                                                                   bool isPfl, int nbi, int offset,
1146                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1147                                                                                                   MEDFileFieldGlobsReal& glob,
1148                                                                                                   bool &notInExisting)
1149 {
1150   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1151   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1152   for(;it!=entriesOnSameDisc.end();it++)
1153     {
1154       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1155         {
1156           if(!isPfl)
1157             {
1158               if((*it)->_profile.empty())
1159                 break;
1160               else
1161                 if(!(*it)->_profile.empty())
1162                   {
1163                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1164                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1165                       break;
1166                   }
1167             }
1168         }
1169     }
1170   if(it==entriesOnSameDisc.end())
1171     {
1172       notInExisting=true;
1173       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1174       ret->_type=typeF;
1175       ret->_loc_id=(int)geoType;
1176       ret->_nval=nbMeshEntities;
1177       ret->_start=offset;
1178       ret->_end=ret->_start+ret->_nval*nbi;
1179       if(isPfl)
1180         {
1181           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1182           glob.appendProfile(idsOfMeshElt);
1183           ret->_profile=idsOfMeshElt->getName();
1184         }
1185       //tony treatment of localization
1186       return ret;
1187     }
1188   else
1189     {
1190       notInExisting=false;
1191       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1192       ret->_loc_id=(int)geoType;
1193       ret->setNewStart(offset);
1194       entriesOnSameDisc.erase(it);
1195       return ret;
1196     }
1197
1198 }
1199
1200 ////////////////////////////////////
1201
1202 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1203 {
1204 }
1205
1206 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1207 {
1208   _father=father;
1209 }
1210
1211 void MEDFileFieldPerMeshPerTypeCommon::accept(MEDFileFieldVisitor& visitor) const
1212 {
1213   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1214     if((*it).isNotNull())
1215       {
1216         visitor.newPerMeshPerTypePerDisc(*it);
1217       }
1218 }
1219
1220 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1221 {
1222   std::size_t i=0;
1223   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1224     {
1225       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1226         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1227     }
1228 }
1229
1230 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1231 {
1232   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1233 }
1234
1235 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1236 {
1237   std::vector<const BigMemoryObject *> ret;
1238   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1239     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1240   return ret;
1241 }
1242
1243 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1244 {
1245   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1246   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1247     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1248 }
1249
1250 /*!
1251  * This method is the most general one. No optimization is done here.
1252  * \param [in] multiTypePfl is the end user profile specified in high level API
1253  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1254  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
1255  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1256  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1257  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
1258  */
1259 void MEDFileFieldPerMeshPerTypeCommon::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1260 {
1261   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1262   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1263     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1264 }
1265
1266 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1267 {
1268   _field_pm_pt_pd.resize(1);
1269   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1270   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1271 }
1272
1273 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1274 {
1275   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1276   if(!arr || !arr->isAllocated())
1277     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1278   _field_pm_pt_pd.resize(1);
1279   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1280   _field_pm_pt_pd[0]->assignFieldProfile(true,start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1281 }
1282
1283 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells)
1284 {
1285   TypeOfField type=field->getTypeOfField();
1286   if(type!=ON_GAUSS_PT)
1287     {
1288       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1289       int sz=_field_pm_pt_pd.size();
1290       bool found=false;
1291       for(int j=0;j<sz && !found;j++)
1292         {
1293           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1294             {
1295               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1296               found=true;
1297             }
1298         }
1299       if(!found)
1300         {
1301           _field_pm_pt_pd.resize(sz+1);
1302           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1303         }
1304       std::vector<int> ret(1,(int)sz);
1305       return ret;
1306     }
1307   else
1308     {
1309       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1310       int sz2=ret2.size();
1311       std::vector<int> ret3(sz2);
1312       int k=0;
1313       for(int i=0;i<sz2;i++)
1314         {
1315           int sz=_field_pm_pt_pd.size();
1316           int locIdToFind=ret2[i];
1317           bool found=false;
1318           for(int j=0;j<sz && !found;j++)
1319             {
1320               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1321                 {
1322                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1323                   ret3[k++]=j;
1324                   found=true;
1325                 }
1326             }
1327           if(!found)
1328             {
1329               _field_pm_pt_pd.resize(sz+1);
1330               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1331               ret3[k++]=sz;
1332             }
1333         }
1334       return ret3;
1335     }
1336 }
1337
1338 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, int offset, int nbOfCells)
1339 {
1340   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1341   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1342   if(!disc2)
1343     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1344   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1345   if(!da)
1346     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1347   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1348   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1349   if(retTmp->presenceOfValue(-1))
1350     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1351   std::vector<int> ret(retTmp->begin(),retTmp->end());
1352   return ret;
1353 }
1354
1355 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells)
1356 {
1357   TypeOfField type=field->getTypeOfField();
1358   if(type!=ON_GAUSS_PT)
1359     {
1360       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1361       int sz=_field_pm_pt_pd.size();
1362       bool found=false;
1363       for(int j=0;j<sz && !found;j++)
1364         {
1365           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1366             {
1367               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1368               found=true;
1369             }
1370         }
1371       if(!found)
1372         {
1373           _field_pm_pt_pd.resize(sz+1);
1374           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1375         }
1376       std::vector<int> ret(1,0);
1377       return ret;
1378     }
1379   else
1380     {
1381       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1382       int sz2=ret2.size();
1383       std::vector<int> ret3(sz2);
1384       int k=0;
1385       for(int i=0;i<sz2;i++)
1386         {
1387           int sz=_field_pm_pt_pd.size();
1388           int locIdToFind=ret2[i];
1389           bool found=false;
1390           for(int j=0;j<sz && !found;j++)
1391             {
1392               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1393                 {
1394                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1395                   ret3[k++]=j;
1396                   found=true;
1397                 }
1398             }
1399           if(!found)
1400             {
1401               _field_pm_pt_pd.resize(sz+1);
1402               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1403               ret3[k++]=sz;
1404             }
1405         }
1406       return ret3;
1407     }
1408 }
1409
1410 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldTemplate *field, const DataArrayInt *subCells)
1411 {
1412   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1413   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1414   if(!disc2)
1415     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1416   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1417   if(!da)
1418     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1419   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1420   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1421   if(retTmp->presenceOfValue(-1))
1422     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1423   std::vector<int> ret(retTmp->begin(),retTmp->end());
1424   return ret;
1425 }
1426
1427 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1428 {
1429   return _father;
1430 }
1431
1432 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1433 {
1434   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1435   int curDim((int)cm.getDimension());
1436   if(dim!=std::numeric_limits<int>::max())
1437     {
1438       if(dim!=curDim)
1439         return false;
1440     }
1441   else
1442     dim=curDim;
1443   return true;
1444 }
1445
1446 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1447 {
1448   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1449     {
1450       (*it)->fillTypesOfFieldAvailable(types);
1451     }
1452 }
1453
1454 void MEDFileFieldPerMeshPerTypeCommon::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1455 {
1456   int sz=_field_pm_pt_pd.size();
1457   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1458   for(int i=0;i<sz;i++)
1459     {
1460       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1461     }
1462 }
1463
1464 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1465 {
1466   return _father->getIteration();
1467 }
1468
1469 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1470 {
1471   return _father->getOrder();
1472 }
1473
1474 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1475 {
1476   return _father->getTime();
1477 }
1478
1479 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1480 {
1481   return _father->getMeshName();
1482 }
1483
1484 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1485 {
1486   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1487     {
1488       globalSz+=(*it)->getNumberOfTuples();
1489     }
1490   nbOfEntries+=(int)_field_pm_pt_pd.size();
1491 }
1492
1493 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1494 {
1495   return _father->getNumberOfComponents();
1496 }
1497
1498 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1499 {
1500   std::size_t nb(0);
1501   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1502     {
1503       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1504       if(fmtd)
1505         nb++;
1506     }
1507   return nb>1;
1508 }
1509
1510 void MEDFileFieldPerMeshPerTypeCommon::pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc)
1511 {
1512   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt;
1513   elt.takeRef(disc);
1514   _field_pm_pt_pd.push_back(elt);
1515 }
1516
1517 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1518 {
1519   return _father->getOrCreateAndGetArray();
1520 }
1521
1522 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1523 {
1524   const MEDFileFieldPerMesh *fath=_father;
1525   return fath->getOrCreateAndGetArray();
1526 }
1527
1528 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1529 {
1530   return _father->getInfo();
1531 }
1532
1533 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1534 {
1535   std::vector<std::string> ret;
1536   std::set<std::string> ret2;
1537   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1538     {
1539       std::string tmp=(*it1)->getProfile();
1540       if(!tmp.empty())
1541         if(ret2.find(tmp)==ret2.end())
1542           {
1543             ret.push_back(tmp);
1544             ret2.insert(tmp);
1545           }
1546     }
1547   return ret;
1548 }
1549
1550 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1551 {
1552   std::vector<std::string> ret;
1553   std::set<std::string> ret2;
1554   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1555     {
1556       std::string tmp=(*it1)->getLocalization();
1557       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1558         if(ret2.find(tmp)==ret2.end())
1559           {
1560             ret.push_back(tmp);
1561             ret2.insert(tmp);
1562           }
1563     }
1564   return ret;
1565 }
1566
1567 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1568 {
1569   std::vector<std::string> ret;
1570   std::set<std::string> ret2;
1571   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1572     {
1573       std::string tmp=(*it1)->getProfile();
1574       if(!tmp.empty())
1575         ret.push_back(tmp);
1576     }
1577   return ret;
1578 }
1579
1580 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1581 {
1582   std::vector<std::string> ret;
1583   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1584     {
1585       std::string tmp=(*it1)->getLocalization();
1586       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1587         ret.push_back(tmp);
1588     }
1589   return ret;
1590 }
1591
1592 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1593 {
1594   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1595     (*it1)->changePflsRefsNamesGen(mapOfModif);
1596 }
1597
1598 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1599 {
1600   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1601     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1602 }
1603
1604 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1605 {
1606   if(_field_pm_pt_pd.empty())
1607     {
1608       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1609       throw INTERP_KERNEL::Exception(oss.str());
1610     }
1611   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1612     return _field_pm_pt_pd[locId];
1613   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1614   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1615   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1616   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1617 }
1618
1619 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1620 {
1621   if(_field_pm_pt_pd.empty())
1622     {
1623       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1624       throw INTERP_KERNEL::Exception(oss.str());
1625     }
1626   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1627     return _field_pm_pt_pd[locId];
1628   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1629   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1630   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1631   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1632 }
1633
1634 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1635 {
1636   int i=0;
1637   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1638     {
1639       (*it)->fillValues(i,startEntryId,entries);
1640     }
1641 }
1642
1643 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1644 {
1645   _field_pm_pt_pd=leaves;
1646   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1647     (*it)->setFather(this);
1648 }
1649
1650 /*!
1651  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1652  *  \param [out] its - list of pair (start,stop) kept
1653  *  \return bool - false if the type of field \a tof is not contained in \a this.
1654  */
1655 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1656 {
1657   bool ret(false);
1658   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1659   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1660     if((*it)->getType()==tof)
1661       {
1662         newPmPtPd.push_back(*it);
1663         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1664         (*it)->setNewStart(globalNum);
1665         globalNum=(*it)->getEnd();
1666         its.push_back(bgEnd);
1667         ret=true;
1668       }
1669   if(ret)
1670     _field_pm_pt_pd=newPmPtPd;
1671   return ret;
1672 }
1673
1674 /*!
1675  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1676  *  \param [out] its - list of pair (start,stop) kept
1677  *  \return bool - false if the type of field \a tof is not contained in \a this.
1678  */
1679 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1680 {
1681   if(_field_pm_pt_pd.size()<=idOfDisc)
1682     return false;
1683   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1684   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1685   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1686   elt->setNewStart(globalNum);
1687   globalNum=elt->getEnd();
1688   its.push_back(bgEnd);
1689   _field_pm_pt_pd=newPmPtPd;
1690   return true;
1691 }
1692
1693 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1694 {
1695   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1696     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1697 }
1698
1699 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1700 {
1701   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1702     (*it)->loadBigArray(fid,nasc);
1703 }
1704
1705 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1706 {
1707   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1708     {
1709       (*it)->copyOptionsFrom(*this);
1710       (*it)->writeLL(fid,nasc);
1711     }
1712 }
1713
1714 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1715 {
1716   switch(ikType)
1717   {
1718     case ON_CELLS:
1719       medfGeoType=typmai3[(int)ikGeoType];
1720       return MED_CELL;
1721     case ON_NODES:
1722       medfGeoType=MED_NONE;
1723       return MED_NODE;
1724     case ON_GAUSS_NE:
1725       medfGeoType=typmai3[(int)ikGeoType];
1726       return MED_NODE_ELEMENT;
1727     case ON_GAUSS_PT:
1728       medfGeoType=typmai3[(int)ikGeoType];
1729       return MED_CELL;
1730     default:
1731       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1732   }
1733   return MED_UNDEF_ENTITY_TYPE;
1734 }
1735
1736 //////////////////////////////////////////////////
1737
1738 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1739 {
1740   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1741 }
1742
1743 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1744 {
1745   return new MEDFileFieldPerMeshPerType(fath,geoType);
1746 }
1747
1748 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1749 {
1750   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1751   ret->setFather(father);
1752   ret->deepCopyElements();
1753   return ret.retn();
1754 }
1755
1756 void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1757 {
1758   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1759     {
1760       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1761       if(meshDim!=(int)cm.getDimension())
1762         return ;
1763     }
1764   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1765     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1766 }
1767
1768 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1769 {
1770   return _geo_type;
1771 }
1772
1773 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1774 {
1775   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1776 }
1777
1778 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1779 {
1780   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1781   int curDim((int)cm.getDimension());
1782   dim=std::max(dim,curDim);
1783 }
1784
1785 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1786 {
1787   const char startLine[]="  ## ";
1788   std::string startLine2(bkOffset,' ');
1789   std::string startLine3(startLine2);
1790   startLine3+=startLine;
1791   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1792     {
1793       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1794       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1795     }
1796   else
1797     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1798   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1799   int i=0;
1800   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1801     {
1802       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1803       if(cur)
1804         cur->simpleRepr(bkOffset,oss,i);
1805       else
1806         {
1807           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1808         }
1809     }
1810 }
1811
1812 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1813 {
1814   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1815   return std::string(cm.getRepr());
1816 }
1817
1818 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1819 {
1820 }
1821
1822 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1823 {
1824   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1825   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1826   med_geometry_type mgeoti;
1827   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1828   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1829   _field_pm_pt_pd.resize(nbProfiles);
1830   for(int i=0;i<nbProfiles;i++)
1831     {
1832       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1833     }
1834   if(type==ON_CELLS)
1835     {
1836       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1837       for(int i=0;i<nbProfiles2;i++)
1838         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1839     }
1840   if(!_field_pm_pt_pd.empty() || type!=ON_CELLS)
1841     return ;
1842   // dark side of the force.
1843   {
1844     int nbProfiles1(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_FACE,mgeoti,pflName,locName));
1845     int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_EDGE,mgeoti,pflName,locName));
1846     if(nbProfiles1==0 && nbProfiles2==0)
1847       return ;// OK definitely nothing in field
1848     menti=nbProfiles1>=nbProfiles2?MED_DESCENDING_FACE:MED_DESCENDING_EDGE;//not enough words to describe the beauty
1849     nbProfiles=std::max(nbProfiles1,nbProfiles2);
1850     _field_pm_pt_pd.resize(nbProfiles);
1851     for(int i=0;i<nbProfiles;i++)
1852       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_CELLS,i,pd);
1853   }
1854 }
1855
1856 MCAuto<MEDFileFieldPerMeshPerType> MEDFileFieldPerMeshPerType::Aggregate(int &start, const std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
1857 {
1858   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1859   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1860   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1861     {
1862       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1863         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1864     }
1865   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1866     {
1867       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1868       ret->_field_pm_pt_pd.push_back(agg);
1869     }
1870   return ret;
1871 }
1872
1873 //////////////////////////////////////////////////
1874
1875 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1876 {
1877   if(!entities)
1878     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1879   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1880   if(!entities2)
1881     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1882   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1883   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1884 }
1885
1886 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1887 {
1888   _se.takeRef(se);
1889   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1890   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1891   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1892   _field_pm_pt_pd.resize(nbProfiles);
1893   for(int i=0;i<nbProfiles;i++)
1894     {
1895       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1896     }
1897 }
1898
1899 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1900 {
1901   return _se->getDynGT();
1902 }
1903
1904 std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const
1905 {
1906   return _se->getName();
1907 }
1908
1909 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1910 {
1911   throw INTERP_KERNEL::Exception("not implemented yet !");
1912 }
1913
1914 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1915 {
1916   gt=getDynGT();
1917   ent=MED_STRUCT_ELEMENT;
1918 }
1919
1920 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1921 {
1922   throw INTERP_KERNEL::Exception("not implemented yet !");
1923 }
1924
1925 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1926 {
1927   const char startLine[]="  ## ";
1928   std::string startLine2(bkOffset,' ');
1929   std::string startLine3(startLine2);
1930   startLine3+=startLine;
1931   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1932   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1933   int i=0;
1934   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1935     {
1936       if((*it).isNotNull())
1937         (*it)->simpleRepr(bkOffset,oss,i);
1938       else
1939         {
1940           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1941         }
1942     }
1943 }
1944
1945 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1946 {
1947   throw INTERP_KERNEL::Exception("not implemented yet !");
1948 }
1949
1950 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1951 {
1952   MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1953   ret->setFather(father);
1954   ret->deepCopyElements();
1955   return ret.retn();
1956 }
1957
1958 void MEDFileFieldPerMeshPerTypeDyn::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1959 {
1960   throw INTERP_KERNEL::Exception("not implemented yet !");
1961 }
1962
1963 //////////////////////////////////////////////////
1964
1965 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1966 {
1967   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1968 }
1969
1970 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1971 {
1972   return new MEDFileFieldPerMesh(fath,mesh);
1973 }
1974
1975 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1976 {
1977   return _field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1978 }
1979
1980 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1981 {
1982   std::vector<const BigMemoryObject *> ret;
1983   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1984     ret.push_back(*it);
1985   return ret;
1986 }
1987
1988 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1989 {
1990   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1991   ret->_father=father;
1992   std::size_t i=0;
1993   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1994     {
1995       if((*it).isNotNull())
1996         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1997     }
1998   return ret.retn();
1999 }
2000
2001 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
2002 {
2003   std::string startLine(bkOffset,' ');
2004   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << getMeshName() << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
2005   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
2006   int i=0;
2007   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2008     {
2009       if((*it).isNotNull())
2010         (*it)->simpleRepr(bkOffset,oss,i);
2011       else
2012         {
2013           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
2014         }
2015     }
2016 }
2017
2018 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
2019 {
2020   mesh->getTime(_mesh_iteration,_mesh_order);
2021 }
2022
2023 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2024 {
2025   int nbOfTypes=code.size()/3;
2026   int offset=0;
2027   for(int i=0;i<nbOfTypes;i++)
2028     {
2029       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
2030       int nbOfCells=code[3*i+1];
2031       int pos=addNewEntryIfNecessary(type);
2032       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
2033       offset+=nbOfCells;
2034     }
2035 }
2036
2037 /*!
2038  * This method is the most general one. No optimization is done here.
2039  * \param [in] multiTypePfl is the end user profile specified in high level API
2040  * \param [in] code is the code of \a mesh[multiTypePfl] mesh. It is of size of number of different geometric types into \a mesh[multiTypePfl].
2041  * \param [in] code2 is the code of the \b WHOLE mesh on the same level. So all types in \a code are in \a code2.
2042  * \param [in] idsInPflPerType is the selection into the \a multiTypePfl whole profile that corresponds to the given geometric type. This vector is always 3 times smaller than \a code.
2043  * \param [in] idsPerType is a vector containing the profiles needed to be created for MED file format. \b WARNING these processed MED file profiles can be subdivided again in case of Gauss points.
2044  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
2045  */
2046 void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<int>& code2, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldTemplate *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2047 {
2048   int nbOfTypes(code.size()/3);
2049   for(int i=0;i<nbOfTypes;i++)
2050     {
2051       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
2052       int pos=addNewEntryIfNecessary(type);
2053       DataArrayInt *pfl=0;
2054       if(code[3*i+2]!=-1)
2055         pfl=idsPerType[code[3*i+2]];
2056       int nbOfTupes2=code2.size()/3;
2057       int found=0;
2058       for(;found<nbOfTupes2;found++)
2059         if(code[3*i]==code2[3*found])
2060           break;
2061       if(found==nbOfTupes2)
2062         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
2063       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
2064     }
2065 }
2066
2067 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
2068 {
2069   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2070   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
2071 }
2072
2073 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2074 {
2075   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2076   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
2077 }
2078
2079 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
2080 {
2081   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2082     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
2083 }
2084
2085 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
2086 {
2087   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2088     (*it)->loadBigArraysRecursively(fid,nasc);
2089 }
2090
2091 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
2092 {
2093   int nbOfTypes=_field_pm_pt.size();
2094   for(int i=0;i<nbOfTypes;i++)
2095     {
2096       _field_pm_pt[i]->copyOptionsFrom(*this);
2097       _field_pm_pt[i]->writeLL(fid,nasc);
2098     }
2099 }
2100
2101 void MEDFileFieldPerMesh::getDimension(int& dim) const
2102 {
2103   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2104     (*it)->getDimension(dim);
2105 }
2106
2107 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
2108 {
2109   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2110     if(!(*it)->isUniqueLevel(dim))
2111       return false;
2112   return true;
2113 }
2114
2115 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
2116 {
2117   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2118     (*it)->fillTypesOfFieldAvailable(types);
2119 }
2120
2121 std::vector< std::vector< std::pair<int,int> > > MEDFileFieldPerMesh::getFieldSplitedByType(std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> > & locs) const
2122 {
2123   int sz=_field_pm_pt.size();
2124   std::vector< std::vector<std::pair<int,int> > > ret(sz);
2125   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
2126   for(int i=0;i<sz;i++)
2127     {
2128       types[i]=_field_pm_pt[i]->getGeoType();
2129       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
2130     }
2131   return ret;
2132 }
2133
2134 double MEDFileFieldPerMesh::getTime() const
2135 {
2136   int tmp1,tmp2;
2137   return _father->getTime(tmp1,tmp2);
2138 }
2139
2140 int MEDFileFieldPerMesh::getIteration() const
2141 {
2142   return _father->getIteration();
2143 }
2144
2145 int MEDFileFieldPerMesh::getOrder() const
2146 {
2147   return _father->getOrder();
2148 }
2149
2150 int MEDFileFieldPerMesh::getNumberOfComponents() const
2151 {
2152   return _father->getNumberOfComponents();
2153 }
2154
2155 std::string MEDFileFieldPerMesh::getMeshName() const
2156 {
2157   return _father->getMeshName();
2158 }
2159
2160 void MEDFileFieldPerMesh::setMeshName(const std::string& meshName)
2161 {
2162   _father->setMeshName(meshName);
2163 }
2164
2165 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
2166 {
2167   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2168     {
2169       if((*it).isNull())
2170         continue;
2171       if((*it)->presenceOfMultiDiscPerGeoType())
2172         return true;
2173     }
2174   return false;
2175 }
2176
2177 bool MEDFileFieldPerMesh::presenceOfStructureElements() const
2178 {
2179   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2180     if((*it).isNotNull())
2181       {
2182         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2183         if(pt)
2184           return true;
2185       }
2186   return false;
2187 }
2188
2189 bool MEDFileFieldPerMesh::onlyStructureElements() const
2190 {
2191   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2192     if((*it).isNotNull())
2193       {
2194         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2195         if(!pt)
2196           return false;
2197       }
2198   return true;
2199 }
2200
2201 void MEDFileFieldPerMesh::killStructureElements()
2202 {
2203   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2204   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2205     {
2206       if((*it).isNotNull())
2207         {
2208           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2209           if(!pt)
2210             res.push_back(*it);
2211         }
2212     }
2213   _field_pm_pt=res;
2214 }
2215
2216 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2217 {
2218   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2219   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2220     {
2221       if((*it).isNotNull())
2222         {
2223           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2224           if(pt)
2225             res.push_back(*it);
2226         }
2227     }
2228   _field_pm_pt=res;
2229 }
2230
2231 void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName)
2232 {
2233   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2234   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2235     {
2236       if((*it).isNotNull())
2237         {
2238           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2239           if(!pt)
2240             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !");
2241           if(pt->getModelName()==seName)
2242             res.push_back(*it);
2243         }
2244     }
2245   _field_pm_pt=res;
2246 }
2247
2248 void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
2249 {
2250   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2251     {
2252       if((*it).isNotNull())
2253         {
2254           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2255           if(pt)
2256             {
2257               ps.push_back(std::pair<std::string,std::string>(getMeshName(),pt->getModelName()));
2258             }
2259           else
2260             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !");
2261         }
2262     }
2263 }
2264
2265 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2266 {
2267   if(!_father)
2268     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2269   return _father->getOrCreateAndGetArray();
2270 }
2271
2272 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2273 {
2274   if(!_father)
2275     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2276   return _father->getOrCreateAndGetArray();
2277 }
2278
2279 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2280 {
2281   return _father->getInfo();
2282 }
2283
2284 /*!
2285  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2286  * Before the call of this method 'geoTypes','dads','pfls','locs' must be reorganized so that types in geoTypes are contiguous and ordered following typmai2 array.
2287  * It returns 2 output vectors :
2288  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2289  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2290  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2291  */
2292 void MEDFileFieldPerMesh::SortArraysPerType(const MEDFileFieldGlobsReal *glob, TypeOfField type, const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes, const std::vector< std::pair<int,int> >& dads, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& locs, std::vector<int>& code, std::vector<DataArrayInt *>& notNullPfls)
2293 {
2294   int notNullPflsSz=0;
2295   int nbOfArrs=geoTypes.size();
2296   for(int i=0;i<nbOfArrs;i++)
2297     if(pfls[i])
2298       notNullPflsSz++;
2299   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2300   int nbOfDiffGeoTypes=geoTypes3.size();
2301   code.resize(3*nbOfDiffGeoTypes);
2302   notNullPfls.resize(notNullPflsSz);
2303   notNullPflsSz=0;
2304   int j=0;
2305   for(int i=0;i<nbOfDiffGeoTypes;i++)
2306     {
2307       int startZone=j;
2308       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2309       std::vector<const DataArrayInt *> notNullTmp;
2310       if(pfls[j])
2311         notNullTmp.push_back(pfls[j]);
2312       j++;
2313       for(;j<nbOfArrs;j++)
2314         if(geoTypes[j]==refType)
2315           {
2316             if(pfls[j])
2317               notNullTmp.push_back(pfls[j]);
2318           }
2319         else
2320           break;
2321       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2322       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2323       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2324       code[3*i]=(int)refType;
2325       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2326       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2327       if(notNullTmp.empty())
2328         code[3*i+2]=-1;
2329       else
2330         {
2331           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2332           code[3*i+2]=notNullPflsSz++;
2333         }
2334     }
2335 }
2336
2337 /*!
2338  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2339  */
2340 int MEDFileFieldPerMesh::ComputeNbOfElems(const MEDFileFieldGlobsReal *glob, TypeOfField type, const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes, const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs)
2341 {
2342   int sz=dads.size();
2343   int ret=0;
2344   for(int i=0;i<sz;i++)
2345     {
2346       if(locs[i]==-1)
2347         {
2348           if(type!=ON_GAUSS_NE)
2349             ret+=dads[i].second-dads[i].first;
2350           else
2351             {
2352               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2353               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2354             }
2355         }
2356       else
2357         {
2358           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2359           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2360         }
2361     }
2362   return ret;
2363 }
2364
2365 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2366 {
2367   std::vector<std::string> ret;
2368   std::set<std::string> ret2;
2369   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2370     {
2371       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2372       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2373         if(ret2.find(*it2)==ret2.end())
2374           {
2375             ret.push_back(*it2);
2376             ret2.insert(*it2);
2377           }
2378     }
2379   return ret;
2380 }
2381
2382 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2383 {
2384   std::vector<std::string> ret;
2385   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2386     {
2387       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2388       ret.insert(ret.end(),tmp.begin(),tmp.end());
2389     }
2390   return ret;
2391 }
2392
2393 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2394 {
2395   std::vector<std::string> ret;
2396   std::set<std::string> ret2;
2397   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2398     {
2399       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2400       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2401         if(ret2.find(*it2)==ret2.end())
2402           {
2403             ret.push_back(*it2);
2404             ret2.insert(*it2);
2405           }
2406     }
2407   return ret;
2408 }
2409
2410 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2411 {
2412   std::vector<std::string> ret;
2413   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2414     {
2415       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2416       ret.insert(ret.end(),tmp.begin(),tmp.end());
2417     }
2418   return ret;
2419 }
2420
2421 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2422 {
2423   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2424     {
2425       if((*it).first==getMeshName())
2426         {
2427           setMeshName((*it).second);
2428           return true;
2429         }
2430     }
2431   return false;
2432 }
2433
2434 void MEDFileFieldPerMesh::convertMedBallIntoClassic()
2435 {
2436   if(_field_pm_pt.size()!=1)
2437     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : Only managed for single mesh !");
2438   if(_field_pm_pt[0].isNull())
2439     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : null pointer !");
2440   MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<MEDFileFieldPerMeshPerTypeDyn *>((MEDFileFieldPerMeshPerTypeCommon *)_field_pm_pt[0]));
2441   if(!pt)
2442     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : this is expected to be marked as structure element !");
2443   if(pt->getNumberOfLoc()!=1)
2444     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : only one loc managed !");
2445   const MEDFileFieldPerMeshPerTypePerDisc *disc(pt->getLeafGivenLocId(0));
2446   if(!disc)
2447     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : internal error !");
2448   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> disc2(MEDFileFieldPerMeshPerTypePerDisc::New(*disc));
2449   disc2->setType(ON_NODES);
2450   MCAuto<MEDFileFieldPerMeshPerType> pt2(MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR));
2451   disc2->setFather(pt2);
2452   pt2->setFather(this);
2453   pt2->pushDiscretization(disc2);
2454   _field_pm_pt[0]=DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(pt2);
2455 }
2456
2457 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2458                                                       MEDFileFieldGlobsReal& glob)
2459 {
2460   if(getMeshName()!=meshName)
2461     return false;
2462   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2463   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2464   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2465   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2466   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2467   getUndergroundDataArrayExt(entries);
2468   DataArray *arr0(getOrCreateAndGetArray());//tony
2469   if(!arr0)
2470     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2471   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2472   if(!arr0)
2473     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2474   int sz=0;
2475   if(!arr)
2476     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2477   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2478     {
2479       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2480         {
2481           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2482           sz+=(*it).second.second-(*it).second.first;
2483         }
2484       else
2485         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2486     }
2487   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2488   ////////////////////
2489   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2490   int *workI2=explicitIdsOldInMesh->getPointer();
2491   int sz1=0,sz2=0,sid=1;
2492   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2493   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2494   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2495     {
2496       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2497       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2498       int *workI=explicitIdsOldInArr->getPointer();
2499       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2500         {
2501           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2502           (*itL2)->setLocId(sz2);
2503           (*itL2)->_tmp_work1=(*itL2)->getStart();
2504           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2505         }
2506       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2507     }
2508   explicitIdsOldInMesh->reAlloc(sz2);
2509   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2510   ////////////////////
2511   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2512   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2513   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2514   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2515     {
2516       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2517       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2518       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2519     }
2520   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2521   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2522   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2523     {
2524       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2525       int newStart=elt->getLocId();
2526       elt->setLocId((*it)->getGeoType());
2527       elt->setNewStart(newStart);
2528       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2529       entriesKeptNew.push_back(elt);
2530       entriesKeptNew2.push_back(elt);
2531     }
2532   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2533   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2534   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2535   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2536   bool ret=false;
2537   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2538     {
2539       sid=0;
2540       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2541         {
2542           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2543           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2544           }*/
2545       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2546                                                             glob,arr2,otherEntriesNew) || ret;
2547     }
2548   if(!ret)
2549     return false;
2550   // Assign new dispatching
2551   assignNewLeaves(otherEntriesNew);
2552   arr->deepCopyFrom(*arr2);
2553   return true;
2554 }
2555
2556 /*!
2557  * \param [in,out] globalNum a global numbering counter for the renumbering.
2558  * \param [out] its - list of pair (start,stop) kept
2559  */
2560 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2561 {
2562   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2563   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2564     {
2565       std::vector< std::pair<int,int> > its2;
2566       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2567         {
2568           ret.push_back(*it);
2569           its.insert(its.end(),its2.begin(),its2.end());
2570         }
2571     }
2572   _field_pm_pt=ret;
2573 }
2574
2575 /*!
2576  * \param [in,out] globalNum a global numbering counter for the renumbering.
2577  * \param [out] its - list of pair (start,stop) kept
2578  */
2579 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2580 {
2581   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2582   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2583     {
2584       std::vector< std::pair<int,int> > its2;
2585       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2586         {
2587           ret.push_back(*it);
2588           its.insert(its.end(),its2.begin(),its2.end());
2589         }
2590     }
2591   _field_pm_pt=ret;
2592 }
2593
2594 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2595 {
2596   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2597   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2598     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2599   //
2600   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2601   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2602   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2603   for(;it1!=types.end();it1++,it2++)
2604     {
2605       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2606       elt->setLeaves((*it1).second);
2607       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2608       *it2=elt2;
2609     }
2610   _field_pm_pt=fieldPmPt;
2611 }
2612
2613 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2614 {
2615   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2616     (*it)->changePflsRefsNamesGen(mapOfModif);
2617 }
2618
2619 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2620 {
2621   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2622     (*it)->changeLocsRefsNamesGen(mapOfModif);
2623 }
2624
2625 /*!
2626  * \param [in] mesh is the whole mesh
2627  */
2628 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2629 {
2630   if(_field_pm_pt.empty())
2631     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2632   //
2633   std::vector< std::pair<int,int> > dads;
2634   std::vector<const DataArrayInt *> pfls;
2635   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2636   std::vector<int> locs,code;
2637   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2638   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2639     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2640   // Sort by types
2641   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2642   if(code.empty())
2643     {
2644       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2645       throw INTERP_KERNEL::Exception(oss.str());
2646     }
2647   //
2648   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2649   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2650   if(type!=ON_NODES)
2651     {
2652       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2653       if(!arr)
2654         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2655       else
2656         {
2657           MCAuto<DataArrayInt> arr2(arr);
2658           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2659         }
2660     }
2661   else
2662     {
2663       if(code.size()!=3)
2664         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2665       int nb=code[1];
2666       if(code[2]==-1)
2667         {
2668           if(nb!=mesh->getNumberOfNodes())
2669             {
2670               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2671               oss << " nodes in mesh !";
2672               throw INTERP_KERNEL::Exception(oss.str());
2673             }
2674           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2675         }
2676       else
2677         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2678     }
2679 }
2680
2681 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2682 {
2683   if(_field_pm_pt.empty())
2684     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2685   //
2686   std::vector<std::pair<int,int> > dads;
2687   std::vector<const DataArrayInt *> pfls;
2688   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2689   std::vector<int> locs,code;
2690   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2691   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2692     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2693   // Sort by types
2694   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2695   if(code.empty())
2696     {
2697       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2698       throw INTERP_KERNEL::Exception(oss.str());
2699     }
2700   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2701   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2702   if(type!=ON_NODES)
2703     {
2704       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2705       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2706     }
2707   else
2708     {
2709       if(code.size()!=3)
2710         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2711       int nb=code[1];
2712       if(code[2]==-1)
2713         {
2714           if(nb!=mesh->getNumberOfNodes())
2715             {
2716               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2717               oss << " nodes in mesh !";
2718               throw INTERP_KERNEL::Exception(oss.str());
2719             }
2720         }
2721       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2722     }
2723   //
2724   return 0;
2725 }
2726
2727 void MEDFileFieldPerMesh::accept(MEDFileFieldVisitor& visitor) const
2728 {
2729   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2730     if((*it).isNotNull())
2731       {
2732         visitor.newPerMeshPerTypeEntry(*it);
2733         (*it)->accept(visitor);
2734         visitor.endPerMeshPerTypeEntry(*it);
2735       }
2736 }
2737
2738 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2739 {
2740   int globalSz=0;
2741   int nbOfEntries=0;
2742   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2743     {
2744       (*it)->getSizes(globalSz,nbOfEntries);
2745     }
2746   entries.resize(nbOfEntries);
2747   nbOfEntries=0;
2748   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2749     {
2750       (*it)->fillValues(nbOfEntries,entries);
2751     }
2752 }
2753
2754 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2755 {
2756   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2757     {
2758       if((*it)->getGeoType()==typ)
2759         return (*it)->getLeafGivenLocId(locId);
2760     }
2761   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2762   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2763   oss << "Possiblities are : ";
2764   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2765     {
2766       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2767       oss << "\"" << cm2.getRepr() << "\", ";
2768     }
2769   throw INTERP_KERNEL::Exception(oss.str());
2770 }
2771
2772 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2773 {
2774   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2775     {
2776       if((*it)->getGeoType()==typ)
2777         return (*it)->getLeafGivenLocId(locId);
2778     }
2779   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2780   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2781   oss << "Possiblities are : ";
2782   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2783     {
2784       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2785       oss << "\"" << cm2.getRepr() << "\", ";
2786     }
2787   throw INTERP_KERNEL::Exception(oss.str());
2788 }
2789
2790 /*!
2791  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2792  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2793  * \param [in] dts - (Distribution of types) = level 1 : meshes to aggregate. Level 2 : all geo type. Level 3 pair specifying geo type and number of elem in geotype.
2794  * \param [out] extractInfo - Gives information about the where the data comes from. It is a vector of triplet. First element in the triplet the mesh pos. The 2nd one the start pos. The 3rd the end pos.
2795  */
2796 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> MEDFileFieldPerMeshPerTypePerDisc::Aggregate(int &start, const std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, TypeOfField tof, MEDFileFieldPerMeshPerType *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2797 {
2798   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2799   if(pms.empty())
2800     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2801   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2802     {
2803       if(!(*it).second)
2804         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2805       if(!(*it).second->getProfile().empty())
2806         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2807       if(!(*it).second->getLocalization().empty())
2808         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2809     }
2810   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2811   std::size_t i(0);
2812   std::vector< std::pair<int,int> > filteredDTS;
2813   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2814     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2815       if((*it2).first==gt)
2816         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2817   if(pms.size()!=filteredDTS.size())
2818     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2819   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2820   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2821   int zeStart(start),nval(0);
2822   for(;it1!=pms.end();it1++,it2++)
2823     {
2824       if((*it1).first!=(*it2).first)
2825         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2826       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2827       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2828       start+=e1-s1;
2829       nval+=((*it1).second)->getNumberOfVals();
2830     }
2831   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2832   return ret;
2833 }
2834
2835 MCAuto<MEDFileFieldPerMesh> MEDFileFieldPerMesh::Aggregate(int &start, const std::vector<const MEDFileFieldPerMesh *>& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2836 {
2837   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2838   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2839   std::size_t i(0);
2840   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2841     {
2842       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2843       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2844         {
2845           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2846           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2847           if(!elt)
2848             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2849           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2850         }
2851     }
2852   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2853     {
2854       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2855       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2856       ret->_field_pm_pt.push_back(agg2);
2857     }
2858   return ret;
2859 }
2860
2861 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2862 {
2863   int i=0;
2864   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2865   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2866   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2867     {
2868       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2869       if(type==curType)
2870         return i;
2871       else
2872         {
2873           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2874           if(pos>pos2)
2875             it2=it+1;
2876         }
2877     }
2878   int ret=std::distance(_field_pm_pt.begin(),it2);
2879   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2880   return ret;
2881 }
2882
2883 /*!
2884  * 'dads' and 'locs' input parameters have the same number of elements
2885  * \param [in] mesh is \b NOT the global mesh, but the possibly reduced mesh. \a mesh parameter will be directly aggregated in the returned field
2886  */
2887 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2888                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2889                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2890 {
2891   isPfl=false;
2892   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2893   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2894   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2895   const std::vector<std::string>& infos=getInfo();
2896   da->setInfoOnComponents(infos);
2897   da->setName("");
2898   if(type==ON_GAUSS_PT)
2899     {
2900       int offset=0;
2901       int nbOfArrs=dads.size();
2902       for(int i=0;i<nbOfArrs;i++)
2903         {
2904           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2905           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2906           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2907           MCAuto<DataArrayInt> di=DataArrayInt::New();
2908           di->alloc(nbOfElems,1);
2909           di->iota(offset);
2910           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2911           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2912           offset+=nbOfElems;
2913         }
2914     }
2915   arrOut=da;
2916   return ret.retn();
2917 }
2918
2919 /*!
2920  * This method is an extension of MEDFileFieldPerMesh::finishField method. It deals with profiles. This method should be called when type is different from ON_NODES.
2921  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2922  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2923  * The order of cells in the returned field is those imposed by the profile.
2924  * \param [in] mesh is the global mesh.
2925  */
2926 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2927                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2928                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2929                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2930 {
2931   if(da->isIota(mesh->getNumberOfCells()))
2932     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2933   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2934   m2->setName(mesh->getName().c_str());
2935   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2936   isPfl=true;
2937   return ret.retn();
2938 }
2939
2940 /*!
2941  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2942  */
2943 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2944                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2945                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2946 {
2947   if(da->isIota(mesh->getNumberOfNodes()))
2948     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2949   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2950   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2951   if(meshu)
2952     {
2953       if(meshu->getNodalConnectivity()==0)
2954         {
2955           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2956           int nb=da->getNbOfElems();
2957           const int *ptr=da->getConstPointer();
2958           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2959           meshuc->allocateCells(nb);
2960           for(int i=0;i<nb;i++)
2961             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2962           meshuc->finishInsertingCells();
2963           ret->setMesh(meshuc);
2964           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2965           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2966           disc->checkCoherencyBetween(meshuc,arrOut);
2967           return ret.retn();
2968         }
2969     }
2970   //
2971   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2972   isPfl=true;
2973   DataArrayInt *arr2=0;
2974   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2975   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2976   MCAuto<DataArrayInt> arr3(arr2);
2977   int nnodes=mesh2->getNumberOfNodes();
2978   if(nnodes==(int)da->getNbOfElems())
2979     {
2980       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2981       arrOut->renumberInPlace(da3->getConstPointer());
2982       mesh2->setName(mesh->getName().c_str());
2983       ret->setMesh(mesh2);
2984       return ret.retn();
2985     }
2986   else
2987     {
2988       std::ostringstream oss; oss << "MEDFileFieldPerMesh::finishFieldNode2 : The field on nodes lies on a node profile so that it is impossible to find a submesh having exactly the same nodes of that profile !!!";
2989       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2990       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2991       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2992       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2993       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2994       throw INTERP_KERNEL::Exception(oss.str());
2995     }
2996   return 0;
2997 }
2998
2999 /*!
3000  * This method is the most light method of field retrieving.
3001  */
3002 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
3003 {
3004   if(!pflIn)
3005     {
3006       pflOut=DataArrayInt::New();
3007       pflOut->alloc(nbOfElems,1);
3008       pflOut->iota(0);
3009     }
3010   else
3011     {
3012       pflOut=const_cast<DataArrayInt*>(pflIn);
3013       pflOut->incrRef();
3014     }
3015   MCAuto<DataArrayInt> safePfl(pflOut);
3016   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
3017   const std::vector<std::string>& infos=getInfo();
3018   int nbOfComp=infos.size();
3019   for(int i=0;i<nbOfComp;i++)
3020     da->setInfoOnComponent(i,infos[i].c_str());
3021   safePfl->incrRef();
3022   return da.retn();
3023 }
3024
3025
3026 /// @cond INTERNAL
3027
3028 class MFFPMIter
3029 {
3030 public:
3031   static MFFPMIter *NewCell(const MEDFileEntities *entities);
3032   static bool IsPresenceOfNode(const MEDFileEntities *entities);
3033   virtual ~MFFPMIter() { }
3034   virtual void begin() = 0;
3035   virtual bool finished() const = 0;
3036   virtual void next() = 0;
3037   virtual int current() const = 0;
3038 };
3039
3040 class MFFPMIterSimple : public MFFPMIter
3041 {
3042 public:
3043   MFFPMIterSimple():_pos(0) { }
3044   void begin() { _pos=0; }
3045   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
3046   void next() { _pos++; }
3047   int current() const { return _pos; }
3048 private:
3049   int _pos;
3050 };
3051
3052 class MFFPMIter2 : public MFFPMIter
3053 {
3054 public:
3055   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
3056   void begin() { _it=_ids.begin(); }
3057   bool finished() const { return _it==_ids.end(); }
3058   void next() { _it++; }
3059   int current() const { return *_it; }
3060 private:
3061   std::vector<int> _ids;
3062   std::vector<int>::const_iterator _it;
3063 };
3064
3065 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
3066 {
3067   if(!entities)
3068     return new MFFPMIterSimple;
3069   else
3070     {
3071       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3072       if(entities2)
3073         {
3074           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
3075           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3076           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3077             {
3078               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
3079                 tmp.push_back((*it).second);
3080             }
3081           return new MFFPMIter2(tmp);
3082         }
3083       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
3084     }
3085 }
3086
3087 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
3088 {
3089   if(!entities)
3090     return true;
3091   else
3092     {
3093       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3094       if(entities2)
3095         {
3096           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3097           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3098             if((*it).first==ON_NODES)
3099               return true;
3100           return false;
3101         }
3102       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
3103     }
3104 }
3105
3106 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
3107 {
3108   std::size_t sz(cts.size());
3109   _ids.resize(sz);
3110   for(std::size_t i=0;i<sz;i++)
3111     {
3112       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
3113       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
3114         _ids[i]=(int)std::distance(typmai2,loc);
3115       else
3116         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
3117     }
3118 }
3119
3120 /// @endcond
3121
3122 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
3123     _father(fath)
3124 {
3125   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3126   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3127   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3128   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
3129   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
3130   for(iter0->begin();!iter0->finished();iter0->next())
3131     {
3132       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3133       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3134       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3135       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3136       if(nbProfile>0 || nbProfile2>0)
3137         {
3138           const PartDefinition *pd(0);
3139           if(mmu)
3140             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
3141           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
3142           if(nbProfile>0)
3143             setMeshName(name0);
3144           else
3145             setMeshName(name1);
3146         }
3147     }
3148   if(MFFPMIter::IsPresenceOfNode(entities))
3149     {
3150       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
3151       if(nbProfile>0)
3152         {
3153           const PartDefinition *pd(0);
3154           if(mmu)
3155             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
3156           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
3157           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3158         }
3159     }
3160   if(!entities)
3161     return ;
3162   std::vector<int> dynGT(entities->getDynGTAvail());
3163   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
3164     {
3165       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
3166       if(nbPfl>0)
3167         {
3168           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
3169           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3170         }
3171     }
3172   if(!_field_pm_pt.empty())
3173     return;
3174   //for vicious users using MED_ARETE MED_FACE in fields. the last try. For Others not overhead to pay.
3175   iter0=MFFPMIter::NewCell(entities);
3176   for(iter0->begin();!iter0->finished();iter0->next())
3177     {
3178       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_FACE,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3179       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3180       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_DESCENDING_EDGE,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3181       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3182       if(nbProfile>0 || nbProfile2>0)
3183         {
3184           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,NULL));
3185           if(nbProfile>0)
3186             setMeshName(name0);
3187           else
3188             setMeshName(name1);
3189         }
3190     }
3191 }
3192
3193 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
3194 {
3195   copyTinyInfoFrom(mesh);
3196 }
3197
3198 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3199 {
3200   if(id>=(int)_pfls.size())
3201     _pfls.resize(id+1);
3202   _pfls[id]=DataArrayInt::New();
3203   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
3204   _pfls[id]->setName(pflName);
3205   _pfls[id]->alloc(lgth,1);
3206   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
3207   _pfls[id]->applyLin(1,-1,0);//Converting into C format
3208 }
3209
3210 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
3211 {
3212   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3213   int sz;
3214   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
3215   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
3216   if(i>=(int)_pfls.size())
3217     _pfls.resize(i+1);
3218   _pfls[i]=DataArrayInt::New();
3219   _pfls[i]->alloc(sz,1);
3220   _pfls[i]->setName(pflCpp.c_str());
3221   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
3222   _pfls[i]->applyLin(1,-1,0);//Converting into C format
3223 }
3224
3225 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3226 {
3227   int nbOfPfls=_pfls.size();
3228   for(int i=0;i<nbOfPfls;i++)
3229     {
3230       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
3231       cpy->applyLin(1,1,0);
3232       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3233       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
3234       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
3235     }
3236   //
3237   int nbOfLocs=_locs.size();
3238   for(int i=0;i<nbOfLocs;i++)
3239     _locs[i]->writeLL(fid);
3240 }
3241
3242 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
3243 {
3244   std::vector<std::string> pfls=getPfls();
3245   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
3246     {
3247       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
3248       if(it2==pfls.end())
3249         {
3250           _pfls.push_back(*it);
3251         }
3252       else
3253         {
3254           int id=std::distance(pfls.begin(),it2);
3255           if(!(*it)->isEqual(*_pfls[id]))
3256             {
3257               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3258               throw INTERP_KERNEL::Exception(oss.str());
3259             }
3260         }
3261     }
3262   std::vector<std::string> locs=getLocs();
3263   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
3264     {
3265       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
3266       if(it2==locs.end())
3267         {
3268           _locs.push_back(*it);
3269         }
3270       else
3271         {
3272           int id=std::distance(locs.begin(),it2);
3273           if(!(*it)->isEqual(*_locs[id],eps))
3274             {
3275               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3276               throw INTERP_KERNEL::Exception(oss.str());
3277             }
3278         }
3279     }
3280 }
3281
3282 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
3283 {
3284   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
3285     getProfile((*it).c_str());
3286 }
3287
3288 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
3289 {
3290   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
3291     getLocalization((*it).c_str());
3292 }
3293
3294 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
3295 {
3296   std::vector<std::string> profiles=real.getPflsReallyUsed();
3297   int sz=profiles.size();
3298   _pfls.resize(sz);
3299   for(int i=0;i<sz;i++)
3300     loadProfileInFile(fid,i,profiles[i].c_str());
3301   //
3302   std::vector<std::string> locs=real.getLocsReallyUsed();
3303   sz=locs.size();
3304   _locs.resize(sz);
3305   for(int i=0;i<sz;i++)
3306     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
3307 }
3308
3309 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3310 {
3311   int nProfil=MEDnProfile(fid);
3312   for(int i=0;i<nProfil;i++)
3313     loadProfileInFile(fid,i);
3314   int sz=MEDnLocalization(fid);
3315   _locs.resize(sz);
3316   for(int i=0;i<sz;i++)
3317     {
3318       _locs[i]=MEDFileFieldLoc::New(fid,i,entities);
3319     }
3320 }
3321
3322 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
3323 {
3324   return new MEDFileFieldGlobs(fid);
3325 }
3326
3327 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
3328 {
3329   return new MEDFileFieldGlobs;
3330 }
3331
3332 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
3333 {
3334   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
3335 }
3336
3337 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
3338 {
3339   std::vector<const BigMemoryObject *> ret;
3340   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3341     ret.push_back((const DataArrayInt *)*it);
3342   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3343     ret.push_back((const MEDFileFieldLoc *)*it);
3344   return ret;
3345 }
3346
3347 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3348 {
3349   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3350   std::size_t i=0;
3351   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3352     {
3353       if((const DataArrayInt *)*it)
3354         ret->_pfls[i]=(*it)->deepCopy();
3355     }
3356   i=0;
3357   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3358     {
3359       if((const MEDFileFieldLoc*)*it)
3360         ret->_locs[i]=(*it)->deepCopy();
3361     }
3362   return ret.retn();
3363 }
3364
3365 /*!
3366  * \throw if a profile in \a pfls in not in \a this.
3367  * \throw if a localization in \a locs in not in \a this.
3368  * \sa MEDFileFieldGlobs::deepCpyPart
3369  */
3370 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3371 {
3372   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3373   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3374     {
3375       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3376       if(!pfl)
3377         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3378       pfl->incrRef();
3379       MCAuto<DataArrayInt> pfl2(pfl);
3380       ret->_pfls.push_back(pfl2);
3381     }
3382   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3383     {
3384       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3385       if(!loc)
3386         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3387       loc->incrRef();
3388       MCAuto<MEDFileFieldLoc> loc2(loc);
3389       ret->_locs.push_back(loc2);
3390     }
3391   ret->setFileName(getFileName());
3392   return ret.retn();
3393 }
3394
3395 /*!
3396  * \throw if a profile in \a pfls in not in \a this.
3397  * \throw if a localization in \a locs in not in \a this.
3398  * \sa MEDFileFieldGlobs::shallowCpyPart
3399  */
3400 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3401 {
3402   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3403   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3404     {
3405       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3406       if(!pfl)
3407         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3408       ret->_pfls.push_back(pfl->deepCopy());
3409     }
3410   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3411     {
3412       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3413       if(!loc)
3414         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3415       ret->_locs.push_back(loc->deepCopy());
3416     }
3417   ret->setFileName(getFileName());
3418   return ret.retn();
3419 }
3420
3421 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3422 {
3423 }
3424
3425 MEDFileFieldGlobs::MEDFileFieldGlobs()
3426 {
3427 }
3428
3429 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3430 {
3431 }
3432
3433 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3434 {
3435   oss << "Profiles :\n";
3436   std::size_t n=_pfls.size();
3437   for(std::size_t i=0;i<n;i++)
3438     {
3439       oss << "  - #" << i << " ";
3440       const DataArrayInt *pfl=_pfls[i];
3441       if(pfl)
3442         oss << "\"" << pfl->getName() << "\"\n";
3443       else
3444         oss << "EMPTY !\n";
3445     }
3446   n=_locs.size();
3447   oss << "Localizations :\n";
3448   for(std::size_t i=0;i<n;i++)
3449     {
3450       oss << "  - #" << i << " ";
3451       const MEDFileFieldLoc *loc=_locs[i];
3452       if(loc)
3453         loc->simpleRepr(oss);
3454       else
3455         oss<< "EMPTY !\n";
3456     }
3457 }
3458
3459 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3460 {
3461   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3462     {
3463       DataArrayInt *elt(*it);
3464       if(elt)
3465         {
3466           std::string name(elt->getName());
3467           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3468             {
3469               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3470                 {
3471                   elt->setName((*it2).second.c_str());
3472                   return;
3473                 }
3474             }
3475         }
3476     }
3477 }
3478
3479 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3480 {
3481   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3482     {
3483       MEDFileFieldLoc *elt(*it);
3484       if(elt)
3485         {
3486           std::string name(elt->getName());
3487           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3488             {
3489               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3490                 {
3491                   elt->setName((*it2).second.c_str());
3492                   return;
3493                 }
3494             }
3495         }
3496     }
3497 }
3498
3499 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3500 {
3501   if(locId<0 || locId>=(int)_locs.size())
3502     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3503   return _locs[locId]->getNbOfGaussPtPerCell();
3504 }
3505
3506 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3507 {
3508   return getLocalizationFromId(getLocalizationId(locName));
3509 }
3510
3511 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3512 {
3513   if(locId<0 || locId>=(int)_locs.size())
3514     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3515   return *_locs[locId];
3516 }
3517
3518 /// @cond INTERNAL
3519 namespace MEDCouplingImpl
3520 {
3521   class LocFinder
3522   {
3523   public:
3524     LocFinder(const std::string& loc):_loc(loc) { }
3525     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3526   private:
3527     const std::string &_loc;
3528   };
3529
3530   class PflFinder
3531   {
3532   public:
3533     PflFinder(const std::string& pfl):_pfl(pfl) { }
3534     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3535   private:
3536     const std::string& _pfl;
3537   };
3538 }
3539 /// @endcond
3540
3541 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3542 {
3543   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3544   if(it==_locs.end())
3545     {
3546       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3547       for(it=_locs.begin();it!=_locs.end();it++)
3548         oss << "\"" << (*it)->getName() << "\", ";
3549       throw INTERP_KERNEL::Exception(oss.str());
3550     }
3551   return std::distance(_locs.begin(),it);
3552 }
3553
3554 /*!
3555  * The returned value is never null.
3556  */
3557 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3558 {
3559   std::string pflNameCpp(pflName);
3560   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3561   if(it==_pfls.end())
3562     {
3563       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3564       for(it=_pfls.begin();it!=_pfls.end();it++)
3565         oss << "\"" << (*it)->getName() << "\", ";
3566       throw INTERP_KERNEL::Exception(oss.str());
3567     }
3568   return *it;
3569 }
3570
3571 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3572 {
3573   if(pflId<0 || pflId>=(int)_pfls.size())
3574     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3575   return _pfls[pflId];
3576 }
3577
3578 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3579 {
3580   if(locId<0 || locId>=(int)_locs.size())
3581     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3582   return *_locs[locId];
3583 }
3584
3585 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3586 {
3587   return getLocalizationFromId(getLocalizationId(locName));
3588 }
3589
3590 /*!
3591  * The returned value is never null.
3592  */
3593 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3594 {
3595   std::string pflNameCpp(pflName);
3596   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3597   if(it==_pfls.end())
3598     {
3599       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3600       for(it=_pfls.begin();it!=_pfls.end();it++)
3601         oss << "\"" << (*it)->getName() << "\", ";
3602       throw INTERP_KERNEL::Exception(oss.str());
3603     }
3604   return *it;
3605 }
3606
3607 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3608 {
3609   if(pflId<0 || pflId>=(int)_pfls.size())
3610     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3611   return _pfls[pflId];
3612 }
3613
3614 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3615 {
3616   std::vector< MCAuto<DataArrayInt> > newPfls;
3617   int i=0;
3618   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3619     {
3620       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3621         newPfls.push_back(*it);
3622     }
3623   _pfls=newPfls;
3624 }
3625
3626 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3627 {
3628   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3629   int i=0;
3630   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3631     {
3632       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3633         newLocs.push_back(*it);
3634     }
3635   _locs=newLocs;
3636 }
3637
3638 void MEDFileFieldGlobs::killStructureElementsInGlobs()
3639 {
3640   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3641   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3642     {
3643       if((*it).isNull())
3644         continue;
3645       if(!(*it)->isOnStructureElement())
3646         newLocs.push_back(*it);
3647     }
3648   _locs=newLocs;
3649 }
3650
3651 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3652 {
3653   int sz=_pfls.size();
3654   std::vector<std::string> ret(sz);
3655   for(int i=0;i<sz;i++)
3656     ret[i]=_pfls[i]->getName();
3657   return ret;
3658 }
3659
3660 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3661 {
3662   int sz=_locs.size();
3663   std::vector<std::string> ret(sz);
3664   for(int i=0;i<sz;i++)
3665     ret[i]=_locs[i]->getName();
3666   return ret;
3667 }
3668
3669 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3670 {
3671   std::vector<std::string> v=getPfls();
3672   std::string s(pflName);
3673   return std::find(v.begin(),v.end(),s)!=v.end();
3674 }
3675
3676 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3677 {
3678   std::vector<std::string> v=getLocs();
3679   std::string s(locName);
3680   return std::find(v.begin(),v.end(),s)!=v.end();
3681 }
3682
3683 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3684 {
3685   std::map<int,std::vector<int> > m;
3686   int i=0;
3687   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3688     {
3689       const DataArrayInt *tmp=(*it);
3690       if(tmp)
3691         {
3692           m[tmp->getHashCode()].push_back(i);
3693         }
3694     }
3695   std::vector< std::vector<int> > ret;
3696   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3697     {
3698       if((*it2).second.size()>1)
3699         {
3700           std::vector<int> ret0;
3701           bool equalityOrNot=false;
3702           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3703             {
3704               std::vector<int>::const_iterator it4=it3; it4++;
3705               for(;it4!=(*it2).second.end();it4++)
3706                 {
3707                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3708                     {
3709                       if(!equalityOrNot)
3710                         ret0.push_back(*it3);
3711                       ret0.push_back(*it4);
3712                       equalityOrNot=true;
3713                     }
3714                 }
3715             }
3716           if(!ret0.empty())
3717             ret.push_back(ret0);
3718         }
3719     }
3720   return ret;
3721 }
3722
3723 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3724 {
3725   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3726 }
3727
3728 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3729 {
3730   std::string name(pfl->getName());
3731   if(name.empty())
3732     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3733   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3734     if(name==(*it)->getName())
3735       {
3736         if(!pfl->isEqual(*(*it)))
3737           {
3738             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3739             throw INTERP_KERNEL::Exception(oss.str());
3740           }
3741       }
3742   pfl->incrRef();
3743   _pfls.push_back(pfl);
3744 }
3745
3746 void MEDFileFieldGlobs::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
3747 {
3748   std::string name(locName);
3749   if(name.empty())
3750     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3751   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3752   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3753     if((*it)->isName(locName))
3754       {
3755         if(!(*it)->isEqual(*obj,1e-12))
3756           {
3757             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3758             throw INTERP_KERNEL::Exception(oss.str());
3759           }
3760       }
3761   _locs.push_back(obj);
3762 }
3763
3764 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3765 {
3766   std::vector<std::string> names=getPfls();
3767   return CreateNewNameNotIn("NewPfl_",names);
3768 }
3769
3770 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3771 {
3772   std::vector<std::string> names=getLocs();
3773   return CreateNewNameNotIn("NewLoc_",names);
3774 }
3775
3776 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3777 {
3778   for(std::size_t sz=0;sz<100000;sz++)
3779     {
3780       std::ostringstream tryName;
3781       tryName << prefix << sz;
3782       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3783         return tryName.str();
3784     }
3785   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3786 }
3787
3788 /*!
3789  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3790  *  \param [in] fname - the file name.
3791  */
3792 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3793 {
3794 }
3795
3796 /*!
3797  * Creates an empty MEDFileFieldGlobsReal.
3798  */
3799 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3800 {
3801 }
3802
3803 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3804 {
3805   return 0;
3806 }
3807
3808 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3809 {
3810   std::vector<const BigMemoryObject *> ret;
3811   ret.push_back((const MEDFileFieldGlobs *)_globals);
3812   return ret;
3813 }
3814
3815 /*!
3816  * Returns a string describing profiles and Gauss points held in \a this.
3817  *  \return std::string - the description string.
3818  */
3819 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3820 {
3821   const MEDFileFieldGlobs *glob=_globals;
3822   std::ostringstream oss2; oss2 << glob;
3823   std::string stars(oss2.str().length(),'*');
3824   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3825   if(glob)
3826     glob->simpleRepr(oss);
3827   else
3828     oss << "NO GLOBAL INFORMATION !\n";
3829 }
3830
3831 void MEDFileFieldGlobsReal::resetContent()
3832 {
3833   _globals=MEDFileFieldGlobs::New();
3834 }
3835
3836 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
3837 {
3838   contentNotNull()->killStructureElementsInGlobs();
3839 }
3840
3841 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3842 {
3843 }
3844
3845 /*!
3846  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3847  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3848  */
3849 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3850 {
3851   _globals=other._globals;
3852 }
3853
3854 /*!
3855  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3856  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3857  */
3858 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3859 {
3860   const MEDFileFieldGlobs *otherg(other._globals);
3861   if(!otherg)
3862     return ;
3863   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3864 }
3865
3866 /*!
3867  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3868  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3869  */
3870 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3871 {
3872   const MEDFileFieldGlobs *otherg(other._globals);
3873   if(!otherg)
3874     return ;
3875   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3876 }
3877
3878 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3879 {
3880   _globals=other._globals;
3881   if((const MEDFileFieldGlobs *)_globals)
3882     _globals=other._globals->deepCopy();
3883 }
3884
3885 /*!
3886  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3887  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3888  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3889  *         \a this and \a other MEDFileFieldGlobsReal.
3890  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3891  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3892  */
3893 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3894 {
3895   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3896   if(thisGlobals==otherGlobals)
3897     return ;
3898   if(!thisGlobals)
3899     {
3900       _globals=other._globals;
3901       return ;
3902     }
3903   _globals->appendGlobs(*other._globals,eps);
3904 }
3905
3906 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3907 {
3908   checkGlobsPflsPartCoherency();
3909   checkGlobsLocsPartCoherency();
3910 }
3911
3912 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3913 {
3914   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3915 }
3916
3917 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3918 {
3919   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3920 }
3921
3922 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3923 {
3924   contentNotNull()->loadProfileInFile(fid,id,pflName);
3925 }
3926
3927 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3928 {
3929   contentNotNull()->loadProfileInFile(fid,id);
3930 }
3931
3932 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3933 {
3934   contentNotNull()->loadGlobals(fid,*this);
3935 }
3936
3937 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3938 {
3939   contentNotNull()->loadAllGlobals(fid,entities);
3940 }
3941
3942 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3943 {
3944   contentNotNull()->writeGlobals(fid,opt);
3945 }
3946
3947 /*!
3948  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3949  * or getPflsReallyUsedMulti().
3950  *  \return std::vector<std::string> - a sequence of names of all profiles.
3951  */
3952 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3953 {
3954   return contentNotNull()->getPfls();
3955 }
3956
3957 /*!
3958  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3959  * or getLocsReallyUsedMulti().
3960  *  \return std::vector<std::string> - a sequence of names of all localizations.
3961  */
3962 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3963 {
3964   return contentNotNull()->getLocs();
3965 }
3966
3967 /*!
3968  * Checks if the profile with a given name exists.
3969  *  \param [in] pflName - the profile name of interest.
3970  *  \return bool - \c true if the profile named \a pflName exists.
3971  */
3972 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3973 {
3974   return contentNotNull()->existsPfl(pflName);
3975 }
3976
3977 /*!
3978  * Checks if the localization with a given name exists.
3979  *  \param [in] locName - the localization name of interest.
3980  *  \return bool - \c true if the localization named \a locName exists.
3981  */
3982 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3983 {
3984   return contentNotNull()->existsLoc(locName);
3985 }
3986
3987 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3988 {
3989   return contentNotNull()->createNewNameOfPfl();
3990 }
3991
3992 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3993 {
3994   return contentNotNull()->createNewNameOfLoc();
3995 }
3996
3997 /*!
3998  * Sets the name of a MED file.
3999  *  \param [inout] fileName - the file name.
4000  */
4001 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
4002 {
4003   contentNotNull()->setFileName(fileName);
4004 }
4005
4006 /*!
4007  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
4008  * in the same order.
4009  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
4010  *          Each item of this sequence is a vector containing ids of equal profiles.
4011  */
4012 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
4013 {
4014   return contentNotNull()->whichAreEqualProfiles();
4015 }
4016
4017 /*!
4018  * Finds equal localizations.
4019  *  \param [in] eps - a precision used to compare real values of the localizations.
4020  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
4021  *          Each item of this sequence is a vector containing ids of equal localizations.
4022  */
4023 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
4024 {
4025   return contentNotNull()->whichAreEqualLocs(eps);
4026 }
4027
4028 /*!
4029  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
4030  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
4031  *        this sequence is a pair whose 
4032  *        - the first item is a vector of profile names to replace by the second item,
4033  *        - the second item is a profile name to replace every profile name of the first item.
4034  */
4035 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4036 {
4037   contentNotNull()->changePflsNamesInStruct(mapOfModif);
4038 }
4039
4040 /*!
4041  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
4042  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
4043  *        this sequence is a pair whose 
4044  *        - the first item is a vector of localization names to replace by the second item,
4045  *        - the second item is a localization name to replace every localization name of the first item.
4046  */
4047 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4048 {
4049   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
4050 }
4051
4052 /*!
4053  * Replaces references to some profiles (a reference is a profile name) by references
4054  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
4055  * them-selves accordingly. <br>
4056  * This method is a generalization of changePflName().
4057  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
4058  *        this sequence is a pair whose 
4059  *        - the first item is a vector of profile names to replace by the second item,
4060  *        - the second item is a profile name to replace every profile of the first item.
4061  * \sa changePflsRefsNamesGen()
4062  * \sa changePflName()
4063  */
4064 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4065 {
4066   changePflsRefsNamesGen(mapOfModif);
4067   changePflsNamesInStruct(mapOfModif);
4068 }
4069
4070 /*!
4071  * Replaces references to some localizations (a reference is a localization name) by references
4072  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
4073  * them-selves accordingly. <br>
4074  * This method is a generalization of changeLocName().
4075  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
4076  *        this sequence is a pair whose 
4077  *        - the first item is a vector of localization names to replace by the second item,
4078  *        - the second item is a localization name to replace every localization of the first item.
4079  * \sa changeLocsRefsNamesGen()
4080  * \sa changeLocName()
4081  */
4082 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4083 {
4084   changeLocsRefsNamesGen(mapOfModif);
4085   changeLocsNamesInStruct(mapOfModif);
4086 }
4087
4088 /*!
4089  * Renames the profile having a given name and updates references to this profile.
4090  *  \param [in] oldName - the name of the profile to rename.
4091  *  \param [in] newName - a new name of the profile.
4092  * \sa changePflsNames().
4093  */
4094 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
4095 {
4096   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4097   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4098   mapOfModif[0]=p;
4099   changePflsNames(mapOfModif);
4100 }
4101
4102 /*!
4103  * Renames the localization having a given name and updates references to this localization.
4104  *  \param [in] oldName - the name of the localization to rename.
4105  *  \param [in] newName - a new name of the localization.
4106  * \sa changeLocsNames().
4107  */
4108 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
4109 {
4110   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4111   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4112   mapOfModif[0]=p;
4113   changeLocsNames(mapOfModif);
4114 }
4115
4116 /*!
4117  * Removes duplicated profiles. Returns a map used to update references to removed 
4118  * profiles via changePflsRefsNamesGen().
4119  * Equal profiles are found using whichAreEqualProfiles().
4120  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4121  *          a sequence describing the performed replacements of profiles. Each element of
4122  *          this sequence is a pair whose
4123  *          - the first item is a vector of profile names replaced by the second item,
4124  *          - the second item is a profile name replacing every profile of the first item.
4125  */
4126 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
4127 {
4128   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
4129   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4130   int i=0;
4131   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4132     {
4133       std::vector< std::string > tmp((*it).size());
4134       int j=0;
4135       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4136         tmp[j]=std::string(getProfileFromId(*it2)->getName());
4137       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4138       ret[i]=p;
4139       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4140       killProfileIds(tmp2);
4141     }
4142   changePflsRefsNamesGen(ret);
4143   return ret;
4144 }
4145
4146 /*!
4147  * Removes duplicated localizations. Returns a map used to update references to removed 
4148  * localizations via changeLocsRefsNamesGen().
4149  * Equal localizations are found using whichAreEqualLocs().
4150  *  \param [in] eps - a precision used to compare real values of the localizations.
4151  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4152  *          a sequence describing the performed replacements of localizations. Each element of
4153  *          this sequence is a pair whose
4154  *          - the first item is a vector of localization names replaced by the second item,
4155  *          - the second item is a localization name replacing every localization of the first item.
4156  */
4157 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
4158 {
4159   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
4160   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4161   int i=0;
4162   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4163     {
4164       std::vector< std::string > tmp((*it).size());
4165       int j=0;
4166       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4167         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
4168       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4169       ret[i]=p;
4170       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4171       killLocalizationIds(tmp2);
4172     }
4173   changeLocsRefsNamesGen(ret);
4174   return ret;
4175 }
4176
4177 /*!
4178  * Returns number of Gauss points per cell in a given localization.
4179  *  \param [in] locId - an id of the localization of interest.
4180  *  \return int - the number of the Gauss points per cell.
4181  */
4182 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
4183 {
4184   return contentNotNull()->getNbOfGaussPtPerCell(locId);
4185 }
4186
4187 /*!
4188  * Returns an id of a localization by its name.
4189  *  \param [in] loc - the localization name of interest.
4190  *  \return int - the id of the localization.
4191  *  \throw If there is no a localization named \a loc.
4192  */
4193 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
4194 {
4195   return contentNotNull()->getLocalizationId(loc);
4196 }
4197
4198 /*!
4199  * Returns the name of the MED file.
4200  *  \return const std::string&  - the MED file name.
4201  */
4202 std::string MEDFileFieldGlobsReal::getFileName() const
4203 {
4204   return contentNotNull()->getFileName();
4205 }
4206
4207 /*!
4208  * Returns a localization object by its name.
4209  *  \param [in] locName - the name of the localization of interest.
4210  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
4211  *  \throw If there is no a localization named \a locName.
4212  */
4213 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
4214 {
4215   return contentNotNull()->getLocalization(locName);
4216 }
4217
4218 /*!
4219  * Returns a localization object by its id.
4220  *  \param [in] locId - the id of the localization of interest.
4221  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
4222  *  \throw If there is no a localization with id \a locId.
4223  */
4224 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
4225 {
4226   return contentNotNull()->getLocalizationFromId(locId);
4227 }
4228
4229 /*!
4230  * Returns a profile array by its name.
4231  *  \param [in] pflName - the name of the profile of interest.
4232  *  \return const DataArrayInt * - the profile array having the name \a pflName.
4233  *  \throw If there is no a profile named \a pflName.
4234  */
4235 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
4236 {
4237   return contentNotNull()->getProfile(pflName);
4238 }
4239
4240 /*!
4241  * Returns a profile array by its id.
4242  *  \param [in] pflId - the id of the profile of interest.
4243  *  \return const DataArrayInt * - the profile array having the id \a pflId.
4244  *  \throw If there is no a profile with id \a pflId.
4245  */
4246 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
4247 {
4248   return contentNotNull()->getProfileFromId(pflId);
4249 }
4250
4251 /*!
4252  * Returns a localization object, apt for modification, by its id.
4253  *  \param [in] locId - the id of the localization of interest.
4254  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4255  *          having the id \a locId.
4256  *  \throw If there is no a localization with id \a locId.
4257  */
4258 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
4259 {
4260   return contentNotNull()->getLocalizationFromId(locId);
4261 }
4262
4263 /*!
4264  * Returns a localization object, apt for modification, by its name.
4265  *  \param [in] locName - the name of the localization of interest.
4266  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4267  *          having the name \a locName.
4268  *  \throw If there is no a localization named \a locName.
4269  */
4270 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
4271 {
4272   return contentNotNull()->getLocalization(locName);
4273 }
4274
4275 /*!
4276  * Returns a profile array, apt for modification, by its name.
4277  *  \param [in] pflName - the name of the profile of interest.
4278  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
4279  *  \throw If there is no a profile named \a pflName.
4280  */
4281 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
4282 {
4283   return contentNotNull()->getProfile(pflName);
4284 }
4285
4286 /*!
4287  * Returns a profile array, apt for modification, by its id.
4288  *  \param [in] pflId - the id of the profile of interest.
4289  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
4290  *  \throw If there is no a profile with id \a pflId.
4291  */
4292 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
4293 {
4294   return contentNotNull()->getProfileFromId(pflId);
4295 }
4296
4297 /*!
4298  * Removes profiles given by their ids. No data is updated to track this removal.
4299  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
4300  */
4301 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
4302 {
4303   contentNotNull()->killProfileIds(pflIds);
4304 }
4305
4306 /*!
4307  * Removes localizations given by their ids. No data is updated to track this removal.
4308  *  \param [in] locIds - a sequence of ids of the localizations to remove.
4309  */
4310 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
4311 {
4312   contentNotNull()->killLocalizationIds(locIds);
4313 }
4314
4315 /*!
4316  * Stores a profile array.
4317  *  \param [in] pfl - the profile array to store.
4318  *  \throw If the name of \a pfl is empty.
4319  *  \throw If a profile with the same name as that of \a pfl already exists but contains
4320  *         different ids.
4321  */
4322 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
4323 {
4324   contentNotNull()->appendProfile(pfl);
4325 }
4326
4327 /*!
4328  * Adds a new localization of Gauss points.
4329  *  \param [in] locName - the name of the new localization.
4330  *  \param [in] geoType - a geometrical type of the reference cell.
4331  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
4332  *         must be \c nbOfNodesPerCell * \c dimOfType.
4333  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
4334  *         must be  _wg_.size() * \c dimOfType.
4335  *  \param [in] w - the weights of Gauss points.
4336  *  \throw If \a locName is empty.
4337  *  \throw If a localization with the name \a locName already exists but is
4338  *         different form the new one.
4339  */
4340 void MEDFileFieldGlobsReal::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
4341 {
4342   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
4343 }
4344
4345 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
4346 {
4347   MEDFileFieldGlobs *g(_globals);
4348   if(!g)
4349     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
4350   return g;
4351 }
4352
4353 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
4354 {
4355   const MEDFileFieldGlobs *g(_globals);
4356   if(!g)
4357     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4358   return g;
4359 }
4360
4361 //= MEDFileFieldNameScope
4362
4363 MEDFileFieldNameScope::MEDFileFieldNameScope()
4364 {
4365 }
4366
4367 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName):_name(fieldName),_mesh_name(meshName)
4368 {
4369 }
4370
4371 /*!
4372  * Returns the name of \a this field.
4373  *  \return std::string - a string containing the field name.
4374  */
4375 std::string MEDFileFieldNameScope::getName() const
4376 {
4377   return _name;
4378 }
4379
4380 /*!
4381  * Sets name of \a this field
4382  *  \param [in] name - the new field name.
4383  */
4384 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4385 {
4386   _name=fieldName;
4387 }
4388
4389 std::string MEDFileFieldNameScope::getDtUnit() const
4390 {
4391   return _dt_unit;
4392 }
4393
4394 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4395 {
4396   _dt_unit=dtUnit;
4397 }
4398
4399 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4400 {
4401   _name=other._name;
4402   _mesh_name=other._mesh_name;
4403   _dt_unit=other._dt_unit;
4404 }
4405
4406 /*!
4407  * Returns the mesh name.
4408  *  \return std::string - a string holding the mesh name.
4409  *  \throw If \c _field_per_mesh.empty()
4410  */
4411 std::string MEDFileFieldNameScope::getMeshName() const
4412 {
4413   return _mesh_name;
4414 }
4415
4416 void MEDFileFieldNameScope::setMeshName(const std::string& meshName)
4417 {
4418   _mesh_name=meshName;
4419 }
4420
4421 //= MEDFileAnyTypeField1TSWithoutSDA
4422
4423 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4424 {
4425   _field_per_mesh.resize(other._field_per_mesh.size());
4426   std::size_t i=0;
4427   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4428     {
4429       if((const MEDFileFieldPerMesh *)*it)
4430         _field_per_mesh[i]=(*it)->deepCopy(this);
4431     }
4432 }
4433
4434 void MEDFileAnyTypeField1TSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
4435 {
4436   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4437     if((*it).isNotNull())
4438       {
4439         visitor.newMeshEntry(*it);
4440         (*it)->accept(visitor);
4441         visitor.endMeshEntry(*it);
4442       }
4443 }
4444
4445 /*!
4446  * Prints a string describing \a this field into a stream. This string is outputted 
4447  * by \c print Python command.
4448  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4449  *  \param [in,out] oss - the out stream.
4450  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4451  *          info id printed, else, not.
4452  */
4453 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4454 {
4455   std::string startOfLine(bkOffset,' ');
4456   oss << startOfLine << "Field ";
4457   if(bkOffset==0)
4458     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4459   oss << "on one time Step ";
4460   if(f1tsId>=0)
4461     oss << "(" << f1tsId << ") ";
4462   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4463   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4464   const DataArray *arr=getUndergroundDataArray();
4465   if(arr)
4466     {
4467       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4468       if(f1tsId<0)
4469         {
4470           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4471           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4472             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4473         }
4474       if(arr->isAllocated())
4475         {
4476           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4477         }
4478       else
4479         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4480     }
4481   else
4482     {
4483       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4484     }
4485   oss << startOfLine << "----------------------" << std::endl;
4486   if(!_field_per_mesh.empty())
4487     {
4488       int i=0;
4489       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4490         {
4491           const MEDFileFieldPerMesh *cur=(*it2);
4492           if(cur)
4493             cur->simpleRepr(bkOffset,oss,i);
4494           else
4495             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4496         }
4497     }
4498   else
4499     {
4500       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4501     }
4502   oss << startOfLine << "----------------------" << std::endl;
4503 }
4504
4505 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4506 {
4507   const DataArray *arr(getUndergroundDataArray());
4508   if(!arr)
4509     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4510   int nbOfCompo=arr->getNumberOfComponents();
4511   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4512   for(int i=0;i<nbOfCompo;i++)
4513     {
4514       ret[i]=deepCopy();
4515       std::vector<int> v(1,i);
4516       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4517       ret[i]->setArray(arr2);
4518     }
4519   return ret;
4520 }
4521
4522 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName,meshName),_iteration(iteration),_order(order),_csit(csit),_nb_of_tuples_to_be_allocated(-2)
4523 {
4524 }
4525
4526 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4527 {
4528 }
4529
4530 /*!
4531  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4532  * empty. Returns -1 if this in on nodes.
4533  *  \return int - the dimension of \a this.
4534  */
4535 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4536 {
4537   int ret=-2;
4538   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4539     (*it)->getDimension(ret);
4540   return ret;
4541 }
4542
4543 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4544 {
4545   bool ret=false;
4546   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4547     {
4548       MEDFileFieldPerMesh *cur(*it);
4549       if(cur)
4550         ret=cur->changeMeshNames(modifTab) || ret;
4551     }
4552   return ret;
4553 }
4554
4555 /*!
4556  * Returns the number of iteration of the state of underlying mesh.
4557  *  \return int - the iteration number.
4558  *  \throw If \c _field_per_mesh.empty()
4559  */
4560 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4561 {
4562   if(_field_per_mesh.empty())
4563     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4564   return _field_per_mesh[0]->getMeshIteration();
4565 }
4566
4567 /*!
4568  * Returns the order number of iteration of the state of underlying mesh.
4569  *  \return int - the order number.
4570  *  \throw If \c _field_per_mesh.empty()
4571  */
4572 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4573 {
4574   if(_field_per_mesh.empty())
4575     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4576   return _field_per_mesh[0]->getMeshOrder();
4577 }
4578
4579 /*!
4580  * Checks if \a this field is tagged by a given iteration number and a given
4581  * iteration order number.
4582  *  \param [in] iteration - the iteration number of interest.
4583  *  \param [in] order - the iteration order number of interest.
4584  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4585  *          \a this->getOrder() == \a order.
4586  */
4587 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4588 {
4589   return iteration==_iteration && order==_order;
4590 }
4591
4592 /*!
4593  * Returns number of iteration and order number of iteration when
4594  * \a this field has been calculated.
4595  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4596  *          order number.
4597  */
4598 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4599 {
4600   std::pair<int,int> p;
4601   fillIteration(p);
4602   return p;
4603 }
4604
4605 /*!
4606  * Returns number of iteration and order number of iteration when
4607  * \a this field has been calculated.
4608  *  \param [in,out] p - a pair returning the iteration number and the iteration
4609  *          order number.
4610  */
4611 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4612 {
4613   p.first=_iteration;
4614   p.second=_order;
4615 }
4616
4617 /*!
4618  * Returns all types of spatial discretization of \a this field.
4619  *  \param [in,out] types - a sequence of types of \a this field.
4620  */
4621 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4622 {
4623   std::set<TypeOfField> types2;
4624   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4625     {
4626       (*it)->fillTypesOfFieldAvailable(types2);
4627     }
4628   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4629   std::copy(types2.begin(),types2.end(),bi);
4630 }
4631
4632 /*!
4633  * Returns all types of spatial discretization of \a this field.
4634  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4635  *          of \a this field.
4636  */
4637 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4638 {
4639   std::vector<TypeOfField> ret;
4640   fillTypesOfFieldAvailable(ret);
4641   return ret;
4642 }
4643
4644 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4645 {
4646   std::vector<std::string> ret;
4647   std::set<std::string> ret2;
4648   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4649     {
4650       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4651       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4652         if(ret2.find(*it2)==ret2.end())
4653           {
4654             ret.push_back(*it2);
4655             ret2.insert(*it2);
4656           }
4657     }
4658   return ret;
4659 }
4660
4661 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4662 {
4663   std::vector<std::string> ret;
4664   std::set<std::string> ret2;
4665   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4666     {
4667       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4668       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4669         if(ret2.find(*it2)==ret2.end())
4670           {
4671             ret.push_back(*it2);
4672             ret2.insert(*it2);
4673           }
4674     }
4675   return ret;
4676 }
4677
4678 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4679 {
4680   std::vector<std::string> ret;
4681   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4682     {
4683       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4684       ret.insert(ret.end(),tmp.begin(),tmp.end());
4685     }
4686   return ret;
4687 }
4688
4689 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4690 {
4691   std::vector<std::string> ret;
4692   std::set<std::string> ret2;
4693   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4694     {
4695       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4696       ret.insert(ret.end(),tmp.begin(),tmp.end());
4697     }
4698   return ret;
4699 }
4700
4701 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4702 {
4703   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4704     (*it)->changePflsRefsNamesGen(mapOfModif);
4705 }
4706
4707 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4708 {
4709   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4710     (*it)->changeLocsRefsNamesGen(mapOfModif);
4711 }
4712
4713 /*!
4714  * Returns all attributes of parts of \a this field lying on a given mesh.
4715  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4716  * item of every of returned sequences refers to the _i_-th part of \a this field.
4717  * Thus all sequences returned by this method are of the same length equal to number
4718  * of different types of supporting entities.<br>
4719  * A field part can include sub-parts with several different spatial discretizations,
4720  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4721  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4722  * of a nested sequence corresponds to a type of spatial discretization.<br>
4723  * This method allows for iteration over MEDFile DataStructure without any overhead.
4724  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4725  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4726  *          not checked if \a mname == \c NULL).
4727  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4728  *          a field part is returned. 
4729  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4730  *          This sequence is of the same length as \a types. 
4731  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4732  *          discretization. A profile name can be empty.
4733  *          Length of this and of nested sequences is the same as that of \a typesF.
4734  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4735  *          discretization. A localization name can be empty.
4736  *          Length of this and of nested sequences is the same as that of \a typesF.
4737  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4738  *          of ids of tuples within the data array, per each type of spatial
4739  *          discretization within one mesh entity type. 
4740  *          Length of this and of nested sequences is the same as that of \a typesF.
4741  *  \throw If no field is lying on \a mname.
4742  */
4743 std::vector< std::vector< std::pair<int,int> > > MEDFileAnyTypeField1TSWithoutSDA::getFieldSplitedByType(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
4744 {
4745   if(_field_per_mesh.empty())
4746     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4747   return _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4748 }
4749
4750 /*!
4751  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4752  * maximal absolute dimension and values returned via the out parameter \a levs are 
4753  * dimensions relative to the maximal absolute dimension. <br>
4754  * This method is designed for MEDFileField1TS instances that have a discretization
4755  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4756  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4757  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4758  * Only these 3 discretizations will be taken into account here. If \a this is
4759  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4760  * This method is useful to make the link between the dimension of the underlying mesh
4761  * and the levels of \a this, because it is possible that the highest dimension of \a this
4762  * field is not equal to the dimension of the underlying mesh.
4763  * 
4764  * Let's consider the following case:
4765  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4766  * TETRA4, HEXA8, TRI3 and SEG2.
4767  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4768  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4769  *
4770  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4771  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4772  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4773  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4774  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4775  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4776  * For example<br>
4777  * to retrieve the highest level of
4778  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4779  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4780  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4781  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4782  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4783  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4784  *          not checked if \a mname == \c NULL).
4785  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4786  *          absolute one. They are in decreasing order. This sequence is cleared before
4787  *          filling it in.
4788  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4789  *  \throw If no field is lying on \a mname.
4790  */
4791 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4792 {
4793   levs.clear();
4794   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4795   std::vector< std::vector<TypeOfField> > typesF;
4796   std::vector< std::vector<std::string> > pfls, locs;
4797   if(_field_per_mesh.empty())
4798     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels : This is empty !");
4799   _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4800   if(types.empty())
4801     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4802   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4803   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4804     return -1;
4805   st.erase(INTERP_KERNEL::NORM_ERROR);
4806   std::set<int> ret1;
4807   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4808     {
4809       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4810       ret1.insert((int)cm.getDimension());
4811     }
4812   int ret=*std::max_element(ret1.begin(),ret1.end());
4813   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4814   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4815   return ret;
4816 }
4817
4818 void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic()
4819 {
4820   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it<_field_per_mesh.end();it++)
4821     if((*it).isNotNull())
4822       (*it)->convertMedBallIntoClassic();
4823 }
4824
4825 void MEDFileAnyTypeField1TSWithoutSDA::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
4826 {
4827   if(!pfl)
4828     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : null pfl !");
4829   std::string name(pfl->getName());
4830   pfl->checkAllocated();
4831   if(pfl->getNumberOfComponents()!=1)
4832     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : non mono compo array !");
4833   if(name.empty())
4834     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : empty pfl name !");
4835   if(_field_per_mesh.size()!=1)
4836     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single mesh supported !");
4837   MCAuto<MEDFileFieldPerMesh> fpm(_field_per_mesh[0]);
4838   if(fpm.isNull())
4839     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single not null mesh supported !");
4840   MEDFileFieldPerMeshPerTypePerDisc *disc(fpm->getLeafGivenTypeAndLocId(ct,0));
4841   if(disc->getType()!=tof)
4842     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : error !");
4843   int s(disc->getStart()),e(disc->getEnd()),nt(pfl->getNumberOfTuples());
4844   DataArray *arr(getUndergroundDataArray());
4845   int nt2(arr->getNumberOfTuples()),delta((e-s)-nt);
4846   if(delta<0)
4847     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : internal error !");
4848   MCAuto<DataArray> arr0(arr->selectByTupleIdSafeSlice(0,s,1)),arr1(arr->selectByTupleIdSafeSlice(s,e,1)),arr2(arr->selectByTupleIdSafeSlice(e,nt2,1));
4849   MCAuto<DataArray> arr11(arr1->selectByTupleIdSafe(pfl->begin(),pfl->end()));
4850   MCAuto<DataArray> arrOut(arr->buildNewEmptyInstance());
4851   arrOut->alloc(nt2-delta,arr->getNumberOfComponents());
4852   arrOut->copyStringInfoFrom(*arr);
4853   arrOut->setContigPartOfSelectedValuesSlice(0,arr0,0,s,1);
4854   arrOut->setContigPartOfSelectedValuesSlice(s,arr11,0,nt,1);
4855   arrOut->setContigPartOfSelectedValuesSlice(e-delta,arr2,0,nt2-e,1);
4856   setArray(arrOut);
4857   disc->setEnd(e-delta);
4858   disc->setProfile(name);
4859 }
4860
4861 /*!
4862  * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
4863  * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
4864  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4865  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4866  */
4867 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4868 {
4869   if(_field_per_mesh.empty())
4870     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4871   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4872 }
4873
4874 /*!
4875  * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
4876  * \param [in] typ is for the geometric cell type (or INTERP_KERNEL::NORM_ERROR for node field) entry to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set.
4877  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4878  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4879  */
4880 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4881 {
4882   if(_field_per_mesh.empty())
4883     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4884   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4885 }
4886
4887 /*!
4888  * \param [in] mName specifies the underlying mesh name. This value can be pointer 0 for users that do not deal with fields on multi mesh.
4889  */
4890 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4891 {
4892   if(_field_per_mesh.empty())
4893     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4894   if(mName.empty())
4895     return 0;
4896   std::string mName2(mName);
4897   int ret=0;
4898   std::vector<std::string> msg;
4899   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4900     if(mName2==(*it)->getMeshName())
4901       return ret;
4902     else
4903       msg.push_back((*it)->getMeshName());
4904   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4905   oss << "Possible meshes are : ";
4906   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4907     oss << "\"" << (*it2) << "\" ";
4908   throw INTERP_KERNEL::Exception(oss.str());
4909 }
4910
4911 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4912 {
4913   if(!mesh)
4914     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4915   std::string tmp(mesh->getName());
4916   if(tmp.empty())
4917     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4918   setMeshName(tmp);
4919   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4920   int i=0;
4921   for(;it!=_field_per_mesh.end();it++,i++)
4922     {
4923       if((*it)->getMeshName()==tmp)
4924         return i;
4925     }
4926   int sz=_field_per_mesh.size();
4927   _field_per_mesh.resize(sz+1);
4928   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4929   return sz;
4930 }
4931
4932 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4933                                                                    MEDFileFieldGlobsReal& glob)
4934 {
4935   bool ret=false;
4936   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4937     {
4938       MEDFileFieldPerMesh *fpm(*it);
4939       if(fpm)
4940         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4941     }
4942   return ret;
4943 }
4944
4945 /*!
4946  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4947  * splitting that leads to single spatial discretization of this.
4948  *
4949  * \sa splitMultiDiscrPerGeoTypes
4950  */
4951 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4952 {
4953   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4954   std::vector< std::vector<TypeOfField> > typesF;
4955   std::vector< std::vector<std::string> > pfls,locs;
4956   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4957   std::set<TypeOfField> allEnt;
4958   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4959     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4960       allEnt.insert(*it2);
4961   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4962   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4963   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4964     {
4965       std::vector< std::pair<int,int> > its;
4966       ret[i]=shallowCpy();
4967       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4968       ret[i]->updateData(newLgth,its);
4969     }
4970   return ret;
4971 }
4972
4973 /*!
4974  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4975  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4976  *
4977  * \sa splitDiscretizations
4978  */
4979 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4980 {
4981   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4982   std::vector< std::vector<TypeOfField> > typesF;
4983   std::vector< std::vector<std::string> > pfls,locs;
4984   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4985   std::set<TypeOfField> allEnt;
4986   std::size_t nbOfMDPGT(0),ii(0);
4987   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4988     {
4989       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4990       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4991         allEnt.insert(*it2);
4992     }
4993   if(allEnt.size()!=1)
4994     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4995   if(nbOfMDPGT==0)
4996     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4997   if(nbOfMDPGT==1)
4998     {
4999       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
5000       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
5001       return ret0;
5002     }
5003   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
5004   for(std::size_t i=0;i<nbOfMDPGT;i++)
5005     {
5006       std::vector< std::pair<int,int> > its;
5007       ret[i]=shallowCpy();
5008       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
5009       ret[i]->updateData(newLgth,its);
5010     }
5011   return ret;
5012 }
5013
5014 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
5015 {
5016   int globalCounter(0);
5017   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5018     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
5019   return globalCounter;
5020 }
5021
5022 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
5023 {
5024   int globalCounter(0);
5025   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5026     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
5027   return globalCounter;
5028 }
5029
5030 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
5031 {
5032   if(_nb_of_tuples_to_be_allocated>=0)
5033     {
5034       _nb_of_tuples_to_be_allocated=newLgth;
5035       const DataArray *oldArr(getUndergroundDataArray());
5036       if(oldArr)
5037         {
5038           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
5039           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
5040           setArray(newArr);
5041           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
5042         }
5043       return ;
5044     }
5045   if(_nb_of_tuples_to_be_allocated==-1)
5046     return ;
5047   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
5048     {
5049       const DataArray *oldArr(getUndergroundDataArray());
5050       if(!oldArr || !oldArr->isAllocated())
5051         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
5052       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
5053       newArr->alloc(newLgth,getNumberOfComponents());
5054       if(oldArr)
5055         newArr->copyStringInfoFrom(*oldArr);
5056       int pos=0;
5057       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
5058         {
5059           if((*it).second<(*it).first)
5060             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
5061           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
5062           pos+=(*it).second-(*it).first;
5063         }
5064       setArray(newArr);
5065       return ;
5066     }
5067   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
5068 }
5069
5070 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
5071 {
5072   if(_field_per_mesh.empty())
5073     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
5074   if(_field_per_mesh.size()>1)
5075     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
5076   _field_per_mesh[0]->copyOptionsFrom(opts);
5077   _field_per_mesh[0]->writeLL(fid,nasc);
5078 }
5079
5080 /*!
5081  * 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.
5082  * If false is returned the memory allocation is not required.
5083  */
5084 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
5085 {
5086   if(_nb_of_tuples_to_be_allocated>=0)
5087     {
5088       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
5089       _nb_of_tuples_to_be_allocated=-2;
5090       return true;
5091     }
5092   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
5093     return false;
5094   if(_nb_of_tuples_to_be_allocated==-1)
5095     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
5096   if(_nb_of_tuples_to_be_allocated<-3)
5097     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5098   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5099 }
5100
5101 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5102 {
5103   med_int numdt,numit;
5104   med_float dt;
5105   med_int meshnumdt,meshnumit;
5106   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
5107   {
5108     med_bool localMesh;
5109     med_int nmesh;
5110     INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
5111     MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit)); // to check with Adrien for legacy MED files
5112   }
5113   //MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt,&meshnumdt,&meshnumit));
5114   if(_iteration!=numdt || _order!=numit)
5115     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
5116   _field_per_mesh.resize(1);
5117   //
5118   MEDFileMesh *mm(0);
5119   if(ms)
5120     {
5121       mm=ms->getMeshWithName(getMeshName());
5122     }
5123   //
5124   _field_per_mesh[0]=MEDFileFieldPerMesh::NewOnRead(fid,this,0,meshnumdt,meshnumit,nasc,mm,entities);
5125   _nb_of_tuples_to_be_allocated=0;
5126   _field_per_mesh[0]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
5127 }
5128
5129 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
5130 {
5131   allocIfNecessaryTheArrayToReceiveDataFromFile();
5132   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5133     (*it)->loadBigArraysRecursively(fid,nasc);
5134 }
5135
5136 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
5137 {
5138   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
5139     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5140       (*it)->loadBigArraysRecursively(fid,nasc);
5141 }
5142
5143 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5144 {
5145   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
5146   loadBigArraysRecursively(fid,nasc);
5147 }
5148
5149 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
5150 {
5151   DataArray *thisArr(getUndergroundDataArray());
5152   if(thisArr && thisArr->isAllocated())
5153     {
5154       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
5155       thisArr->desallocate();
5156     }
5157 }
5158
5159 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
5160 {
5161   return _mesh_name.capacity()+_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
5162 }
5163
5164 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
5165 {
5166   std::vector<const BigMemoryObject *> ret;
5167   if(getUndergroundDataArray())
5168     ret.push_back(getUndergroundDataArray());
5169   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5170     ret.push_back((const MEDFileFieldPerMesh *)*it);
5171   return ret;
5172 }
5173
5174 /*!
5175  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
5176  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
5177  * "Sort By Type"), if not, an exception is thrown. 
5178  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
5179  *  \param [in] arr - the array of values.
5180  *  \param [in,out] glob - the global data where profiles and localization present in
5181  *          \a field, if any, are added.
5182  *  \throw If the name of \a field is empty.
5183  *  \throw If the data array of \a field is not set.
5184  *  \throw If \a this->_arr is already allocated but has different number of components
5185  *         than \a field.
5186  *  \throw If the underlying mesh of \a field has no name.
5187  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
5188  */
5189 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5190 {
5191   const MEDCouplingMesh *mesh(field->getMesh());
5192   //
5193   TypeOfField type(field->getTypeOfField());
5194   std::vector<DataArrayInt *> dummy;
5195   if(mesh)
5196     setMeshName(mesh->getName());
5197   int start(copyTinyInfoFrom(th,field,arr));
5198   int pos(addNewEntryIfNecessary(mesh));
5199   if(type!=ON_NODES)
5200     {
5201       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
5202       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
5203     }
5204   else
5205     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
5206 }
5207
5208 /*!
5209  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
5210  * of a given mesh are used as the support of the given field (a real support is not used). 
5211  * Elements of the given mesh must be sorted suitable for writing to MED file. 
5212  * Order of underlying mesh entities of the given field specified by \a profile parameter
5213  * is not prescribed; this method permutes field values to have them sorted by element
5214  * type as required for writing to MED file. A new profile is added only if no equal
5215  * profile is missing. 
5216  *  \param [in] field - the field to add to \a this. The field double values are ignored.
5217  *  \param [in] arrOfVals - the values of the field \a field used.
5218  *  \param [in] mesh - the supporting mesh of \a field.
5219  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
5220  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
5221  *  \param [in,out] glob - the global data where profiles and localization present in
5222  *          \a field, if any, are added.
5223  *  \throw If either \a field or \a mesh or \a profile has an empty name.
5224  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5225  *  \throw If the data array of \a field is not set.
5226  *  \throw If \a this->_arr is already allocated but has different number of components
5227  *         than \a field.
5228  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5229  *  \sa setFieldNoProfileSBT()
5230  */
5231 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)
5232 {
5233   if(!field)
5234     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
5235   if(!arrOfVals || !arrOfVals->isAllocated())
5236     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
5237   TypeOfField type=field->getTypeOfField();
5238   std::vector<DataArrayInt *> idsInPflPerType;
5239   std::vector<DataArrayInt *> idsPerType;
5240   std::vector<int> code,code2;
5241   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5242   if(type!=ON_NODES)
5243     {
5244       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
5245       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
5246       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
5247       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
5248       // start of check
5249       MCAuto<MEDCouplingFieldTemplate> field2=field->clone(false);
5250       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
5251       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5252         {
5253           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5254           throw INTERP_KERNEL::Exception(oss.str());
5255         }
5256       // end of check
5257       int start(copyTinyInfoFrom(th,field,arrOfVals));
5258       code2=m->getDistributionOfTypes();
5259       //
5260       int pos=addNewEntryIfNecessary(m);
5261       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
5262     }
5263   else
5264     {
5265       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
5266         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
5267       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
5268       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
5269       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
5270       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5271         {
5272           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5273           throw INTERP_KERNEL::Exception(oss.str());
5274         }
5275       int start(copyTinyInfoFrom(th,field,arrOfVals));
5276       int pos(addNewEntryIfNecessary(m));
5277       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
5278     }
5279 }
5280
5281 /*!
5282  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
5283  */
5284 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
5285 {
5286   if(_nb_of_tuples_to_be_allocated>=0)
5287     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 !");
5288   DataArray *arr(getOrCreateAndGetArray());
5289   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
5290   _nb_of_tuples_to_be_allocated=-3;
5291 }
5292
5293 /*!
5294  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
5295  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
5296  * larger by the size of \a field. Returns an id of the first not filled
5297  * tuple of \a this->_arr.
5298  *  \param [in] field - the field to copy the info on components and the name from.
5299  *  \return int - the id of first not initialized tuple of \a this->_arr.
5300  *  \throw If the name of \a field is empty.
5301  *  \throw If the data array of \a field is not set.
5302  *  \throw If \a this->_arr is already allocated but has different number of components
5303  *         than \a field.
5304  */
5305 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
5306 {
5307   if(!field)
5308     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
5309   std::string name(field->getName());
5310   setName(name.c_str());
5311   if(field->getMesh())
5312     setMeshName(field->getMesh()->getName());
5313   setDtUnit(th->getTimeUnit());
5314   if(name.empty())
5315     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
5316   if(!arr)
5317     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
5318   if(!arr->isAllocated())
5319     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
5320   _dt=th->getTime(_iteration,_order);
5321   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
5322   if(!getOrCreateAndGetArray()->isAllocated())
5323     {
5324       allocNotFromFile(arr->getNumberOfTuples());
5325       return 0;
5326     }
5327   else
5328     {
5329       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
5330       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
5331       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
5332       _nb_of_tuples_to_be_allocated=-3;
5333       return oldNbOfTuples;
5334     }
5335 }
5336
5337 /*!
5338  * Returns number of components in \a this field
5339  *  \return int - the number of components.
5340  */
5341 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
5342 {
5343   return getOrCreateAndGetArray()->getNumberOfComponents();
5344 }
5345
5346 /*!
5347  * Change info on components in \a this.
5348  * \throw If size of \a infos is not equal to the number of components already in \a this.
5349  */
5350 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
5351 {
5352   DataArray *arr=getOrCreateAndGetArray();
5353   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
5354 }
5355
5356 /*!
5357  * Returns info on components of \a this field.
5358  *  \return const std::vector<std::string>& - a sequence of strings each being an
5359  *          information on _i_-th component.
5360  */
5361 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
5362 {
5363   const DataArray *arr=getOrCreateAndGetArray();
5364   return arr->getInfoOnComponents();
5365 }
5366
5367 /*!
5368  * Returns a mutable info on components of \a this field.
5369  *  \return std::vector<std::string>& - a sequence of strings each being an
5370  *          information on _i_-th component.
5371  */
5372 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
5373 {
5374   DataArray *arr=getOrCreateAndGetArray();
5375   return arr->getInfoOnComponents();
5376 }
5377
5378 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
5379 {
5380   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5381     {
5382       const MEDFileFieldPerMesh *fpm(*it);
5383       if(!fpm)
5384         continue;
5385       if(fpm->presenceOfMultiDiscPerGeoType())
5386         return true;
5387     }
5388   return false;
5389 }
5390
5391 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
5392 {
5393   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5394     if((*it).isNotNull())
5395       if((*it)->presenceOfStructureElements())
5396         return true;
5397   return false;
5398 }
5399
5400 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
5401 {
5402   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5403     if((*it).isNotNull())
5404       if(!(*it)->onlyStructureElements())
5405         return false;
5406   return true;
5407 }
5408
5409 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
5410 {
5411   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5412     if((*it).isNotNull())
5413       (*it)->killStructureElements();
5414 }
5415
5416 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
5417 {
5418   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5419     if((*it).isNotNull())
5420       (*it)->keepOnlyStructureElements();
5421 }
5422
5423 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName)
5424 {
5425   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5426     if((*it).isNotNull())
5427       (*it)->keepOnlyOnSE(seName);
5428 }
5429
5430 void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
5431 {
5432   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5433     if((*it).isNotNull())
5434       (*it)->getMeshSENames(ps);
5435 }
5436
5437 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5438 {
5439   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 !";
5440   if(_field_per_mesh.empty())
5441     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
5442   if(_field_per_mesh.size()>1)
5443     throw INTERP_KERNEL::Exception(MSG0);
5444   if(_field_per_mesh[0].isNull())
5445     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
5446   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
5447   std::set<TypeOfField> types;
5448   pm->fillTypesOfFieldAvailable(types);
5449   if(types.size()!=1)
5450     throw INTERP_KERNEL::Exception(MSG0);
5451   TypeOfField type(*types.begin());
5452   int meshDimRelToMax(0);
5453   if(type==ON_NODES)
5454     meshDimRelToMax=0;
5455   else
5456     {
5457       int myDim(std::numeric_limits<int>::max());
5458       bool isUnique(pm->isUniqueLevel(myDim));
5459       if(!isUnique)
5460         throw INTERP_KERNEL::Exception(MSG0);
5461       meshDimRelToMax=myDim-mesh->getMeshDimension();
5462       if(meshDimRelToMax>0)
5463         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5464     }
5465   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5466 }
5467
5468 /*!
5469  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5470  *  \param [in] type - a spatial discretization of the new field.
5471  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5472  *  \param [in] mName - a name of the supporting mesh.
5473  *  \param [in] renumPol - specifies how to permute values of the result field according to
5474  *          the optional numbers of cells and nodes, if any. The valid values are
5475  *          - 0 - do not permute.
5476  *          - 1 - permute cells.
5477  *          - 2 - permute nodes.
5478  *          - 3 - permute cells and nodes.
5479  *
5480  *  \param [in] glob - the global data storing profiles and localization.
5481  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5482  *          caller is to delete this field using decrRef() as it is no more needed. 
5483  *  \throw If the MED file is not readable.
5484  *  \throw If there is no mesh named \a mName in the MED file.
5485  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5486  *  \throw If no field of \a this is lying on the mesh \a mName.
5487  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5488  */
5489 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5490 {
5491   MCAuto<MEDFileMesh> mm;
5492   if(mName.empty())
5493     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5494   else
5495     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5496   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5497 }
5498
5499 /*!
5500  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5501  *  \param [in] type - a spatial discretization of the new field.
5502  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5503  *  \param [in] renumPol - specifies how to permute values of the result field according to
5504  *          the optional numbers of cells and nodes, if any. The valid values are
5505  *          - 0 - do not permute.
5506  *          - 1 - permute cells.
5507  *          - 2 - permute nodes.
5508  *          - 3 - permute cells and nodes.
5509  *
5510  *  \param [in] glob - the global data storing profiles and localization.
5511  *  \param [in] mesh - the supporting mesh.
5512  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5513  *          caller is to delete this field using decrRef() as it is no more needed. 
5514  *  \throw If the MED file is not readable.
5515  *  \throw If no field of \a this is lying on \a mesh.
5516  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5517  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5518  */
5519 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5520 {
5521   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5522   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5523   if(meshDimRelToMax==1)
5524     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5525   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5526 }
5527
5528 /*!
5529  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5530  * given mesh. 
5531  *  \param [in] type - a spatial discretization of the new field.
5532  *  \param [in] mName - a name of the supporting mesh.
5533  *  \param [in] renumPol - specifies how to permute values of the result field according to
5534  *          the optional numbers of cells and nodes, if any. The valid values are
5535  *          - 0 - do not permute.
5536  *          - 1 - permute cells.
5537  *          - 2 - permute nodes.
5538  *          - 3 - permute cells and nodes.
5539  *
5540  *  \param [in] glob - the global data storing profiles and localization.
5541  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5542  *          caller is to delete this field using decrRef() as it is no more needed. 
5543  *  \throw If the MED file is not readable.
5544  *  \throw If there is no mesh named \a mName in the MED file.
5545  *  \throw If there are no mesh entities in the mesh.
5546  *  \throw If no field values of the given \a type are available.
5547  */
5548 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5549 {
5550   MCAuto<MEDFileMesh> mm;
5551   if(mName.empty())
5552     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5553   else
5554     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5555   int absDim=getDimension();
5556   int meshDimRelToMax=absDim-mm->getMeshDimension();
5557   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5558 }
5559
5560 /*!
5561  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5562  *  \param [in] type - a spatial discretization of the new field.
5563  *  \param [in] renumPol - specifies how to permute values of the result field according to
5564  *          the optional numbers of cells and nodes, if any. The valid values are
5565  *          - 0 - do not permute.
5566  *          - 1 - permute cells.
5567  *          - 2 - permute nodes.
5568  *          - 3 - permute cells and nodes.
5569  *
5570  *  \param [in] glob - the global data storing profiles and localization.
5571  *  \param [in] mesh - the supporting mesh.
5572  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5573  *         field according to \a renumPol.
5574  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5575  *         field according to \a renumPol.
5576  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5577  *          caller is to delete this field using decrRef() as it is no more needed. 
5578  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5579  *  \throw If no field of \a this is lying on \a mesh.
5580  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5581  */
5582 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
5583 {
5584   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5585   bool isPfl=false;
5586   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[0]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5587   switch(renumPol)
5588   {
5589     case 0:
5590       {
5591         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5592         return ret.retn();
5593       }
5594     case 3:
5595     case 1:
5596       {
5597         if(isPfl)
5598           throw INTERP_KERNEL::Exception(msg1);
5599         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5600         if(cellRenum)
5601           {
5602             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5603               {
5604                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5605                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5606                 throw INTERP_KERNEL::Exception(oss.str());
5607               }
5608             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5609             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5610             std::vector<DataArray *> arrOut2(1,arrOut);
5611             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5612             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5613             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5614           }
5615         if(renumPol==1)
5616           return ret.retn();
5617       }
5618     case 2:
5619       {
5620         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5621         if(isPfl)
5622           throw INTERP_KERNEL::Exception(msg1);
5623         if(nodeRenum)
5624           {
5625             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5626               {
5627                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5628                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5629                 throw INTERP_KERNEL::Exception(oss.str());
5630               }
5631             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5632             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5633               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5634             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5635           }
5636         return ret.retn();
5637       }
5638     default:
5639       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5640   }
5641 }
5642
5643 /*!
5644  * Returns values and a profile of the field of a given type lying on a given support.
5645  *  \param [in] type - a spatial discretization of the field.
5646  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5647  *  \param [in] mesh - the supporting mesh.
5648  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5649  *          field of interest lies on. If the field lies on all entities of the given
5650  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5651  *          using decrRef() as it is no more needed.  
5652  *  \param [in] glob - the global data storing profiles and localization.
5653  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5654  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5655  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5656  *  \throw If no field of \a this is lying on \a mesh.
5657  *  \throw If no field values of the given \a type are available.
5658  */
5659 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5660 {
5661   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5662   MCAuto<DataArray> ret=_field_per_mesh[0]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5663   ret->setName(nasc.getName().c_str());
5664   return ret.retn();
5665 }
5666
5667 //= MEDFileField1TSWithoutSDA
5668
5669 /*!
5670  * Throws if a given value is not a valid (non-extended) relative dimension.
5671  *  \param [in] meshDimRelToMax - the relative dimension value.
5672  *  \throw If \a meshDimRelToMax > 0.
5673  */
5674 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5675 {
5676   if(meshDimRelToMax>0)
5677     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5678 }
5679
5680 /*!
5681  * Checks if elements of a given mesh are in the order suitable for writing 
5682  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5683  * vector describing types of elements and their number.
5684  *  \param [in] mesh - the mesh to check.
5685  *  \return std::vector<int> - a vector holding for each element type (1) item of
5686  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5687  *          These values are in full-interlace mode.
5688  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5689  */
5690 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5691 {
5692   if(!mesh)
5693     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5694   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5695   int nbOfTypes=geoTypes.size();
5696   std::vector<int> code(3*nbOfTypes);
5697   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5698   arr1->alloc(nbOfTypes,1);
5699   int *arrPtr=arr1->getPointer();
5700   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5701   for(int i=0;i<nbOfTypes;i++,it++)
5702     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5703   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5704   const int *arrPtr2=arr2->getConstPointer();
5705   int i=0;
5706   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5707     {
5708       int pos=arrPtr2[i];
5709       int nbCells=mesh->getNumberOfCellsWithType(*it);
5710       code[3*pos]=(int)(*it);
5711       code[3*pos+1]=nbCells;
5712       code[3*pos+2]=-1;//no profiles
5713     }
5714   std::vector<const DataArrayInt *> idsPerType;//no profiles
5715   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5716   if(da)
5717     {
5718       da->decrRef();
5719       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5720     }
5721   return code;
5722 }
5723
5724 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5725 {
5726   return new MEDFileField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5727 }
5728
5729 /*!
5730  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5731  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5732  * item of every of returned sequences refers to the _i_-th part of \a this field.
5733  * Thus all sequences returned by this method are of the same length equal to number
5734  * of different types of supporting entities.<br>
5735  * A field part can include sub-parts with several different spatial discretizations,
5736  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5737  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5738  * of a nested sequence corresponds to a type of spatial discretization.<br>
5739  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5740  * The overhead is due to selecting values into new instances of DataArrayDouble.
5741  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5742  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5743  *          not checked if \a mname == \c NULL).
5744  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5745  *          a field part is returned. 
5746  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5747  *          A field part can include sub-parts with several different spatial discretizations,
5748  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5749  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5750  *          This sequence is of the same length as \a types. 
5751  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5752  *          discretization. A profile name can be empty.
5753  *          Length of this and of nested sequences is the same as that of \a typesF.
5754  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5755  *          discretization. A localization name can be empty.
5756  *          Length of this and of nested sequences is the same as that of \a typesF.
5757  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5758  *          per each type of spatial discretization within one mesh entity type.
5759  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5760  *          Length of this and of nested sequences is the same as that of \a typesF.
5761  *  \throw If no field is lying on \a mname.
5762  */
5763 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
5764 {
5765   if(mname.empty())
5766     if(_field_per_mesh.empty())
5767       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5768   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
5769   int nbOfRet=ret0.size();
5770   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5771   for(int i=0;i<nbOfRet;i++)
5772     {
5773       const std::vector< std::pair<int,int> >& p=ret0[i];
5774       int nbOfRet1=p.size();
5775       ret[i].resize(nbOfRet1);
5776       for(int j=0;j<nbOfRet1;j++)
5777         {
5778           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5779           ret[i][j]=tmp;
5780         }
5781     }
5782   return ret;
5783 }
5784
5785 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5786 {
5787   return TYPE_STR;
5788 }
5789
5790 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5791 {
5792   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5793   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5794   ret->deepCpyLeavesFrom(*this);
5795   const DataArrayDouble *arr(_arr);
5796   if(arr)
5797     {
5798       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5799       ret->setArray(arr2);
5800     }
5801   return ret.retn();
5802 }
5803
5804 /*!
5805  * Returns a pointer to the underground DataArrayDouble instance and a
5806  * sequence describing parameters of a support of each part of \a this field. The
5807  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5808  * direct access to the field values. This method is intended for the field lying on one
5809  * mesh only.
5810  *  \param [in,out] entries - the sequence describing parameters of a support of each
5811  *         part of \a this field. Each item of this sequence consists of two parts. The
5812  *         first part describes a type of mesh entity and an id of discretization of a
5813  *         current field part. The second part describes a range of values [begin,end)
5814  *         within the returned array relating to the current field part.
5815  *  \return DataArrayDouble * - the pointer to the field values array.
5816  *  \throw If the number of underlying meshes is not equal to 1.
5817  *  \throw If no field values are available.
5818  *  \sa getUndergroundDataArray()
5819  */
5820 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5821 {
5822   return getUndergroundDataArrayTemplateExt(entries);
5823 }
5824
5825 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)
5826 {
5827   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5828   arr->setInfoAndChangeNbOfCompo(infos);
5829 }
5830
5831 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5832 {
5833 }
5834
5835 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5836 {
5837   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5838   ret->deepCpyLeavesFrom(*this);
5839   return ret.retn();
5840 }
5841
5842 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5843 {
5844   MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
5845   if(_arr.isNotNull())
5846     ret->_arr=_arr->deepCopy();
5847   return ret.retn();
5848 }
5849
5850 //= MEDFileIntField1TSWithoutSDA
5851
5852 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5853 {
5854   return new MEDFileIntField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5855 }
5856
5857 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA()
5858 {
5859 }
5860
5861 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
5862                                                            const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<int>(fieldName,meshName,csit,iteration,order,infos)
5863 {
5864   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5865   arr->setInfoAndChangeNbOfCompo(infos);
5866 }
5867
5868 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5869 {
5870   return TYPE_STR;
5871 }
5872
5873 /*!
5874  * Returns a pointer to the underground DataArrayInt instance and a
5875  * sequence describing parameters of a support of each part of \a this field. The
5876  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5877  * direct access to the field values. This method is intended for the field lying on one
5878  * mesh only.
5879  *  \param [in,out] entries - the sequence describing parameters of a support of each
5880  *         part of \a this field. Each item of this sequence consists of two parts. The
5881  *         first part describes a type of mesh entity and an id of discretization of a
5882  *         current field part. The second part describes a range of values [begin,end)
5883  *         within the returned array relating to the current field part.
5884  *  \return DataArrayInt * - the pointer to the field values array.
5885  *  \throw If the number of underlying meshes is not equal to 1.
5886  *  \throw If no field values are available.
5887  *  \sa getUndergroundDataArray()
5888  */
5889 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5890 {
5891   return getUndergroundDataArrayIntExt(entries);
5892 }
5893
5894 /*!
5895  * Returns a pointer to the underground DataArrayInt instance and a
5896  * sequence describing parameters of a support of each part of \a this field. The
5897  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5898  * direct access to the field values. This method is intended for the field lying on one
5899  * mesh only.
5900  *  \param [in,out] entries - the sequence describing parameters of a support of each
5901  *         part of \a this field. Each item of this sequence consists of two parts. The
5902  *         first part describes a type of mesh entity and an id of discretization of a
5903  *         current field part. The second part describes a range of values [begin,end)
5904  *         within the returned array relating to the current field part.
5905  *  \return DataArrayInt * - the pointer to the field values array.
5906  *  \throw If the number of underlying meshes is not equal to 1.
5907  *  \throw If no field values are available.
5908  *  \sa getUndergroundDataArray()
5909  */
5910 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5911 {
5912   if(_field_per_mesh.size()!=1)
5913     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5914   if(_field_per_mesh[0]==0)
5915     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5916   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5917   return getUndergroundDataArrayTemplate();
5918 }
5919
5920 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5921 {
5922   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5923   ret->deepCpyLeavesFrom(*this);
5924   return ret.retn();
5925 }
5926
5927 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5928 {
5929   MCAuto<MEDFileIntField1TSWithoutSDA> ret(shallowCpy());
5930   if(_arr.isNotNull())
5931     ret->_arr=_arr->deepCopy();
5932   return ret.retn();
5933 }
5934
5935 //= MEDFileFloatField1TSWithoutSDA
5936
5937 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5938 {
5939   return new MEDFileFloatField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5940 }
5941
5942 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA()
5943 {
5944 }
5945
5946 MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
5947                                                                const std::vector<std::string>& infos):MEDFileField1TSNDTemplateWithoutSDA<float>(fieldName,meshName,csit,iteration,order,infos)
5948 {
5949   DataArrayFloat *arr(getOrCreateAndGetArrayTemplate());
5950   arr->setInfoAndChangeNbOfCompo(infos);
5951 }
5952
5953 const char *MEDFileFloatField1TSWithoutSDA::getTypeStr() const
5954 {
5955   return TYPE_STR;
5956 }
5957
5958 /*!
5959  * Returns a pointer to the underground DataArrayFloat instance and a
5960  * sequence describing parameters of a support of each part of \a this field. The
5961  * caller should not decrRef() the returned DataArrayFloat. This method allows for a
5962  * direct access to the field values. This method is intended for the field lying on one
5963  * mesh only.
5964  *  \param [in,out] entries - the sequence describing parameters of a support of each
5965  *         part of \a this field. Each item of this sequence consists of two parts. The
5966  *         first part describes a type of mesh entity and an id of discretization of a
5967  *         current field part. The second part describes a range of values [begin,end)
5968  *         within the returned array relating to the current field part.
5969  *  \return DataArrayFloat * - the pointer to the field values array.
5970  *  \throw If the number of underlying meshes is not equal to 1.
5971  *  \throw If no field values are available.
5972  *  \sa getUndergroundDataArray()
5973  */
5974 DataArray *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5975 {
5976   return getUndergroundDataArrayFloatExt(entries);
5977 }
5978
5979 /*!
5980  * Returns a pointer to the underground DataArrayFloat instance and a
5981  * sequence describing parameters of a support of each part of \a this field. The
5982  * caller should not decrRef() the returned DataArrayFloat. This method allows for a
5983  * direct access to the field values. This method is intended for the field lying on one
5984  * mesh only.
5985  *  \param [in,out] entries - the sequence describing parameters of a support of each
5986  *         part of \a this field. Each item of this sequence consists of two parts. The
5987  *         first part describes a type of mesh entity and an id of discretization of a
5988  *         current field part. The second part describes a range of values [begin,end)
5989  *         within the returned array relating to the current field part.
5990  *  \return DataArrayFloat * - the pointer to the field values array.
5991  *  \throw If the number of underlying meshes is not equal to 1.
5992  *  \throw If no field values are available.
5993  *  \sa getUndergroundDataArray()
5994  */
5995 DataArrayFloat *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayFloatExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5996 {
5997   if(_field_per_mesh.size()!=1)
5998     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5999   if(_field_per_mesh[0]==0)
6000     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
6001   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
6002   return getUndergroundDataArrayTemplate();
6003 }
6004
6005 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::shallowCpy() const
6006 {
6007   MCAuto<MEDFileFloatField1TSWithoutSDA> ret(new MEDFileFloatField1TSWithoutSDA(*this));
6008   ret->deepCpyLeavesFrom(*this);
6009   return ret.retn();
6010 }
6011
6012 MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::deepCopy() const
6013 {
6014   MCAuto<MEDFileFloatField1TSWithoutSDA> ret(shallowCpy());
6015   if(_arr.isNotNull())
6016     ret->_arr=_arr->deepCopy();
6017   return ret.retn();
6018 }
6019
6020 //= MEDFileAnyTypeField1TS
6021
6022 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
6023 {
6024 }
6025
6026 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6027 {
6028   med_field_type typcha;
6029   //
6030   std::vector<std::string> infos;
6031   std::string dtunit,fieldName,meshName;
6032   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
6033   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6034   switch(typcha)
6035   {
6036     case MED_FLOAT64:
6037       {
6038         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6039         break;
6040       }
6041     case MED_INT32:
6042       {
6043         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6044         break;
6045       }
6046     case MED_FLOAT32:
6047       {
6048         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6049         break;
6050       }
6051     default:
6052       {
6053         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
6054         throw INTERP_KERNEL::Exception(oss.str());
6055       }
6056   }
6057   ret->setDtUnit(dtunit.c_str());
6058   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6059   //
6060   med_int numdt,numit;
6061   med_float dt;
6062   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
6063   ret->setTime(numdt,numit,dt);
6064   ret->_csit=1;
6065   if(loadAll)
6066     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6067   else
6068     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6069   return ret.retn();
6070 }
6071
6072 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6073 try:MEDFileFieldGlobsReal(fid)
6074 {
6075   _content=BuildContentFrom(fid,loadAll,ms,entities);
6076   loadGlobals(fid);
6077 }
6078 catch(INTERP_KERNEL::Exception& e)
6079 {
6080     throw e;
6081 }
6082
6083 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6084 {
6085   med_field_type typcha;
6086   std::vector<std::string> infos;
6087   std::string dtunit,meshName;
6088   int nbSteps(0);
6089   {
6090     int iii=-1;
6091     nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName);
6092   }
6093   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6094   switch(typcha)
6095   {
6096     case MED_FLOAT64:
6097       {
6098         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6099         break;
6100       }
6101     case MED_INT32:
6102       {
6103         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6104         break;
6105       }
6106     case MED_FLOAT32:
6107       {
6108         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
6109         break;
6110       }
6111     default:
6112       {
6113         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] !";
6114         throw INTERP_KERNEL::Exception(oss.str());
6115       }
6116   }
6117   ret->setMeshName(meshName);
6118   ret->setDtUnit(dtunit.c_str());
6119   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6120   //
6121   if(nbSteps<1)
6122     {
6123       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
6124       throw INTERP_KERNEL::Exception(oss.str());
6125     }
6126   //
6127   med_int numdt,numit;
6128   med_float dt;
6129   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
6130   ret->setTime(numdt,numit,dt);
6131   ret->_csit=1;
6132   if(loadAll)
6133     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6134   else
6135     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6136   return ret.retn();
6137 }
6138
6139 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6140 try:MEDFileFieldGlobsReal(fid)
6141 {
6142   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
6143   loadGlobals(fid);
6144 }
6145 catch(INTERP_KERNEL::Exception& e)
6146 {
6147     throw e;
6148 }
6149
6150 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
6151 {
6152   if(!c)
6153     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
6154   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
6155     {
6156       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6157       ret->_content=c; c->incrRef();
6158       return ret.retn();
6159     }
6160   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
6161     {
6162       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
6163       ret->_content=c; c->incrRef();
6164       return ret.retn();
6165     }
6166   if(dynamic_cast<const MEDFileFloatField1TSWithoutSDA *>(c))
6167     {
6168       MCAuto<MEDFileFloatField1TS> ret(MEDFileFloatField1TS::New());
6169       ret->_content=c; c->incrRef();
6170       return ret.retn();
6171     }
6172   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
6173 }
6174
6175 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
6176 {
6177   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
6178   ret->setFileName(FileNameFromFID(fid));
6179   return ret;
6180 }
6181
6182 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
6183 {
6184   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6185   return New(fid,loadAll);
6186 }
6187
6188 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
6189 {
6190   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0,0));
6191   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6192   ret->loadGlobals(fid);
6193   return ret.retn();
6194 }
6195
6196 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6197 {
6198   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6199   return New(fid,fieldName,loadAll);
6200 }
6201
6202 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6203 {
6204   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
6205   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6206   ret->loadGlobals(fid);
6207   return ret.retn();
6208 }
6209
6210 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6211 {
6212   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6213   return New(fid,fieldName,iteration,order,loadAll);
6214 }
6215
6216 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6217 {
6218   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,0));
6219   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6220   ret->loadGlobals(fid);
6221   return ret.retn();
6222 }
6223
6224 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6225 {
6226   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6227   return NewAdv(fid,fieldName,iteration,order,loadAll,entities);
6228 }
6229
6230 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6231 {
6232   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,entities));
6233   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6234   ret->loadGlobals(fid);
6235   return ret.retn();
6236 }
6237
6238 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6239 {
6240   med_field_type typcha;
6241   std::vector<std::string> infos;
6242   std::string dtunit,meshName;
6243   int iii(-1);
6244   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName));
6245   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6246   switch(typcha)
6247   {
6248     case MED_FLOAT64:
6249       {
6250         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6251         break;
6252       }
6253     case MED_INT32:
6254       {
6255         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6256         break;
6257       }
6258     case MED_FLOAT32:
6259       {
6260         ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6261         break;
6262       }
6263     default:
6264       {
6265         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] !";
6266         throw INTERP_KERNEL::Exception(oss.str());
6267       }
6268   }
6269   ret->setDtUnit(dtunit.c_str());
6270   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6271   //
6272   bool found=false;
6273   std::vector< std::pair<int,int> > dtits(nbOfStep2);
6274   for(int i=0;i<nbOfStep2 && !found;i++)
6275     {
6276       med_int numdt,numit;
6277       med_float dt;
6278       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
6279       if(numdt==iteration && numit==order)
6280         {
6281           found=true;
6282           ret->_csit=i+1;
6283         }
6284       else
6285         dtits[i]=std::pair<int,int>(numdt,numit);
6286     }
6287   if(!found)
6288     {
6289       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
6290       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
6291         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
6292       throw INTERP_KERNEL::Exception(oss.str());
6293     }
6294   if(loadAll)
6295     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6296   else
6297     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6298   return ret.retn();
6299 }
6300
6301 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6302 try:MEDFileFieldGlobsReal(fid)
6303 {
6304   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms,entities);
6305   loadGlobals(fid);
6306 }
6307 catch(INTERP_KERNEL::Exception& e)
6308 {
6309     throw e;
6310 }
6311
6312 /*!
6313  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6314  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6315  *
6316  * \warning this is a shallow copy constructor
6317  */
6318 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
6319 {
6320   if(!shallowCopyOfContent)
6321     {
6322       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
6323       otherPtr->incrRef();
6324       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
6325     }
6326   else
6327     {
6328       _content=other.shallowCpy();
6329     }
6330 }
6331
6332 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)
6333 {
6334   if(checkFieldId)
6335     {
6336       int nbFields=MEDnField(fid);
6337       if(fieldIdCFormat>=nbFields)
6338         {
6339           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
6340           throw INTERP_KERNEL::Exception(oss.str());
6341         }
6342     }
6343   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
6344   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6345   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6346   INTERP_KERNEL::AutoPtr<char> dtunit(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
6347   INTERP_KERNEL::AutoPtr<char> nomcha(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6348   INTERP_KERNEL::AutoPtr<char> nomMaa(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6349   med_bool localMesh;
6350   int nbOfStep;
6351   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
6352   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
6353   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
6354   meshName=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
6355   infos.clear(); infos.resize(ncomp);
6356   for(int j=0;j<ncomp;j++)
6357     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
6358   return nbOfStep;
6359 }
6360
6361 /*!
6362  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
6363  * 
6364  * \param [out]
6365  * \return in case of success the number of time steps available for the field with name \a fieldName.
6366  */
6367 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)
6368 {
6369   int nbFields=MEDnField(fid);
6370   bool found=false;
6371   std::vector<std::string> fns(nbFields);
6372   int nbOfStep2(-1);
6373   for(int i=0;i<nbFields && !found;i++)
6374     {
6375       std::string tmp,tmp2;
6376       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut,tmp2);
6377       fns[i]=tmp;
6378       found=(tmp==fieldName);
6379       if(found)
6380         {
6381           posCFormat=i;
6382           meshName=tmp2;
6383         }
6384     }
6385   if(!found)
6386     {
6387       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
6388       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
6389         oss << "\"" << *it << "\" ";
6390       throw INTERP_KERNEL::Exception(oss.str());
6391     }
6392   return nbOfStep2;
6393 }
6394
6395 /*!
6396  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6397  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6398  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6399  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6400  * to keep a valid instance.
6401  * 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.
6402  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
6403  * 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.
6404  *
6405  * \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.
6406  * \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.
6407  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6408  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6409  * \param [in] newLocName is the new localization name.
6410  * \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.
6411  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
6412  */
6413 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
6414 {
6415   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6416   std::string oldPflName=disc->getProfile();
6417   std::vector<std::string> vv=getPflsReallyUsedMulti();
6418   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
6419   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
6420     {
6421       disc->setProfile(newPflName);
6422       DataArrayInt *pfl=getProfile(oldPflName.c_str());
6423       pfl->setName(newPflName);
6424     }
6425   else
6426     {
6427       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
6428       throw INTERP_KERNEL::Exception(oss.str());
6429     }
6430 }
6431
6432 /*!
6433  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6434  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6435  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6436  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6437  * to keep a valid instance.
6438  * If \b this do not have any leaf that correspond to the request of the input parameter (\b mName, \b typ, \b locId) an INTERP_KERNEL::Exception will be thrown.
6439  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
6440  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
6441  * 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.
6442  *
6443  * \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.
6444  * \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.
6445  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6446  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6447  * \param [in] newLocName is the new localization name.
6448  * \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.
6449  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
6450  */
6451 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
6452 {
6453   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6454   std::string oldLocName=disc->getLocalization();
6455   std::vector<std::string> vv=getLocsReallyUsedMulti();
6456   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
6457   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
6458     {
6459       disc->setLocalization(newLocName);
6460       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
6461       loc.setName(newLocName);
6462     }
6463   else
6464     {
6465       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
6466       throw INTERP_KERNEL::Exception(oss.str());
6467     }
6468 }
6469
6470 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
6471 {
6472   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6473   if(!ret)
6474     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
6475   return ret;
6476 }
6477
6478 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
6479 {
6480   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6481   if(!ret)
6482     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
6483   return ret;
6484 }
6485
6486 /*!
6487  * This method alloc the arrays and load potentially huge arrays contained in this field.
6488  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
6489  * This method can be also called to refresh or reinit values from a file.
6490  * 
6491  * \throw If the fileName is not set or points to a non readable MED file.
6492  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6493  */
6494 void MEDFileAnyTypeField1TS::loadArrays()
6495 {
6496   if(getFileName().empty())
6497     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
6498   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6499   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
6500 }
6501
6502 /*!
6503  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
6504  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
6505  * this method does not throw if \a this does not come from file read.
6506  * 
6507  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
6508  */
6509 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
6510 {
6511   if(!getFileName().empty())
6512     {
6513       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6514       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
6515     }
6516 }
6517
6518 /*!
6519  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
6520  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
6521  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
6522  * 
6523  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
6524  */
6525 void MEDFileAnyTypeField1TS::unloadArrays()
6526 {
6527   contentNotNullBase()->unloadArrays();
6528 }
6529
6530 /*!
6531  * 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.
6532  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
6533  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
6534  * 
6535  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6536  */
6537 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
6538 {
6539   if(!getFileName().empty())
6540     contentNotNullBase()->unloadArrays();
6541 }
6542
6543 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6544 {
6545   int nbComp(getNumberOfComponents());
6546   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6547   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6548   for(int i=0;i<nbComp;i++)
6549     {
6550       std::string info=getInfo()[i];
6551       std::string c,u;
6552       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6553       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6554       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6555     }
6556   if(getName().empty())
6557     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6558   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6559   writeGlobals(fid,*this);
6560   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6561 }
6562
6563 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6564 {
6565   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6566 }
6567
6568 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6569 {
6570   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6571   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6572   return ret;
6573 }
6574
6575 /*!
6576  * Returns a string describing \a this field. This string is outputted 
6577  * by \c print Python command.
6578  */
6579 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6580 {
6581   std::ostringstream oss;
6582   contentNotNullBase()->simpleRepr(0,oss,-1);
6583   simpleReprGlobs(oss);
6584   return oss.str();
6585 }
6586
6587 /*!
6588  * This method returns all profiles whose name is non empty used.
6589  * \b WARNING If profile is used several times it will be reported \b only \b once.
6590  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6591  */
6592 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6593 {
6594   return contentNotNullBase()->getPflsReallyUsed2();
6595 }
6596
6597 /*!
6598  * This method returns all localizations whose name is non empty used.
6599  * \b WARNING If localization is used several times it will be reported \b only \b once.
6600  */
6601 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6602 {
6603   return contentNotNullBase()->getLocsReallyUsed2();
6604 }
6605
6606 /*!
6607  * This method returns all profiles whose name is non empty used.
6608  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6609  */
6610 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6611 {
6612   return contentNotNullBase()->getPflsReallyUsedMulti2();
6613 }
6614
6615 /*!
6616  * This method returns all localizations whose name is non empty used.
6617  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6618  */
6619 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6620 {
6621   return contentNotNullBase()->getLocsReallyUsedMulti2();
6622 }
6623
6624 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6625 {
6626   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6627 }
6628
6629 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6630 {
6631   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6632 }
6633
6634 int MEDFileAnyTypeField1TS::getDimension() const
6635 {
6636   return contentNotNullBase()->getDimension();
6637 }
6638
6639 int MEDFileAnyTypeField1TS::getIteration() const
6640 {
6641   return contentNotNullBase()->getIteration();
6642 }
6643
6644 int MEDFileAnyTypeField1TS::getOrder() const
6645 {
6646   return contentNotNullBase()->getOrder();
6647 }
6648
6649 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6650 {
6651   return contentNotNullBase()->getTime(iteration,order);
6652 }
6653
6654 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6655 {
6656   contentNotNullBase()->setTime(iteration,order,val);
6657 }
6658
6659 std::string MEDFileAnyTypeField1TS::getName() const
6660 {
6661   return contentNotNullBase()->getName();
6662 }
6663
6664 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6665 {
6666   contentNotNullBase()->setName(name);
6667 }
6668
6669 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6670 {
6671   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6672 }
6673
6674 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6675 {
6676   return contentNotNullBase()->getDtUnit();
6677 }
6678
6679 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6680 {
6681   contentNotNullBase()->setDtUnit(dtUnit);
6682 }
6683
6684 std::string MEDFileAnyTypeField1TS::getMeshName() const
6685 {
6686   return contentNotNullBase()->getMeshName();
6687 }
6688
6689 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6690 {
6691   contentNotNullBase()->setMeshName(newMeshName);
6692 }
6693
6694 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6695 {
6696   return contentNotNullBase()->changeMeshNames(modifTab);
6697 }
6698
6699 int MEDFileAnyTypeField1TS::getMeshIteration() const
6700 {
6701   return contentNotNullBase()->getMeshIteration();
6702 }
6703
6704 int MEDFileAnyTypeField1TS::getMeshOrder() const
6705 {
6706   return contentNotNullBase()->getMeshOrder();
6707 }
6708
6709 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6710 {
6711   return contentNotNullBase()->getNumberOfComponents();
6712 }
6713
6714 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6715 {
6716   return contentNotNullBase()->isDealingTS(iteration,order);
6717 }
6718
6719 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6720 {
6721   return contentNotNullBase()->getDtIt();
6722 }
6723
6724 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6725 {
6726   contentNotNullBase()->fillIteration(p);
6727 }
6728
6729 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6730 {
6731   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6732 }
6733
6734 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6735 {
6736   contentNotNullBase()->setInfo(infos);
6737 }
6738
6739 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6740 {
6741   return contentNotNullBase()->getInfo();
6742 }
6743 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6744 {
6745   return contentNotNullBase()->getInfo();
6746 }
6747
6748 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6749 {
6750   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6751 }
6752
6753 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6754 {
6755   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6756 }
6757
6758 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6759 {
6760   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6761 }
6762
6763 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6764 {
6765   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6766 }
6767
6768 void MEDFileAnyTypeField1TS::convertMedBallIntoClassic()
6769 {
6770   return contentNotNullBase()->convertMedBallIntoClassic();
6771 }
6772
6773 void MEDFileAnyTypeField1TS::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
6774 {
6775   return contentNotNullBase()->makeReduction(ct,tof,pfl);
6776 }
6777
6778 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6779 {
6780   return contentNotNullBase()->getTypesOfFieldAvailable();
6781 }
6782
6783 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,
6784                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6785 {
6786   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6787 }
6788
6789 /*!
6790  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6791  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6792  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6793  */
6794 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6795 {
6796   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6797   if(!content)
6798     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6799   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6800   std::size_t sz(contentsSplit.size());
6801   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6802   for(std::size_t i=0;i<sz;i++)
6803     {
6804       ret[i]=shallowCpy();
6805       ret[i]->_content=contentsSplit[i];
6806     }
6807   return ret;
6808 }
6809
6810 /*!
6811  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6812  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6813  */
6814 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6815 {
6816   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6817   if(!content)
6818     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6819   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6820   std::size_t sz(contentsSplit.size());
6821   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6822   for(std::size_t i=0;i<sz;i++)
6823     {
6824       ret[i]=shallowCpy();
6825       ret[i]->_content=contentsSplit[i];
6826     }
6827   return ret;
6828 }
6829
6830 /*!
6831  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6832  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6833  */
6834 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6835 {
6836   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6837   if(!content)
6838     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6839   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6840   std::size_t sz(contentsSplit.size());
6841   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6842   for(std::size_t i=0;i<sz;i++)
6843     {
6844       ret[i]=shallowCpy();
6845       ret[i]->_content=contentsSplit[i];
6846     }
6847   return ret;
6848 }
6849
6850 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6851 {
6852   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6853   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6854     ret->_content=_content->deepCopy();
6855   ret->deepCpyGlobs(*this);
6856   return ret.retn();
6857 }
6858
6859 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6860 {
6861   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
6862   return copyTinyInfoFrom(field->timeDiscrSafe(),ft,arr);
6863 }
6864
6865 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const TimeHolder *th, const MEDCouplingFieldTemplate *field, const DataArray *arr)
6866 {
6867   return contentNotNullBase()->copyTinyInfoFrom(th,field,arr);
6868 }
6869
6870 //= MEDFileField1TS
6871
6872 /*!
6873  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6874  * following the given input policy.
6875  *
6876  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6877  *                            By default (true) the globals are deeply copied.
6878  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6879  */
6880 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6881 {
6882   MCAuto<MEDFileIntField1TS> ret;
6883   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6884   if(content)
6885     {
6886       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6887       if(!contc)
6888         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6889       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6890       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6891     }
6892   else
6893     ret=MEDFileIntField1TS::New();
6894   if(isDeepCpyGlobs)
6895     ret->deepCpyGlobs(*this);
6896   else
6897     ret->shallowCpyGlobs(*this);
6898   return ret.retn();
6899 }
6900
6901 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6902 try:MEDFileTemplateField1TS<double>(fid,loadAll,ms)
6903 {
6904 }
6905 catch(INTERP_KERNEL::Exception& e)
6906 { throw e; }
6907
6908 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6909 try:MEDFileTemplateField1TS<double>(fid,fieldName,loadAll,ms)
6910 {
6911 }
6912 catch(INTERP_KERNEL::Exception& e)
6913 { throw e; }
6914
6915 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6916 try:MEDFileTemplateField1TS<double>(fid,fieldName,iteration,order,loadAll,ms)
6917 {
6918 }
6919 catch(INTERP_KERNEL::Exception& e)
6920 { throw e; }
6921
6922 /*!
6923  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6924  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6925  *
6926  * \warning this is a shallow copy constructor
6927  */
6928 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6929 try:MEDFileTemplateField1TS<double>(other,shallowCopyOfContent)
6930 {
6931 }
6932 catch(INTERP_KERNEL::Exception& e)
6933 { throw e; }
6934
6935 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
6936 {
6937   return new MEDFileField1TS(*this);
6938 }
6939
6940 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6941                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6942 {
6943   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6944 }
6945
6946 //= MEDFileIntField1TS
6947
6948 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
6949 {
6950   if(!f)
6951     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
6952   int t1,t2;
6953   double t0(f->getTime(t1,t2));
6954   std::string tu(f->getTimeUnit());
6955   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
6956   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
6957   ret->setTime(t0,t1,t2); ret->setTimeUnit(tu);
6958   return ret;
6959 }
6960
6961 //= MEDFileFloatField1TS
6962
6963 //= MEDFileFloatField1TS
6964
6965 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6966
6967 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6968 {
6969 }
6970
6971 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileFieldNameScope(fieldName,meshName)
6972 {
6973 }
6974
6975 /*!
6976  * \param [in] fieldId field id in C mode
6977  */
6978 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6979 {
6980   med_field_type typcha;
6981   std::string dtunitOut,meshName;
6982   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut,meshName));
6983   setMeshName(meshName);
6984   setDtUnit(dtunitOut.c_str());
6985   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
6986 }
6987
6988 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)
6989 try:MEDFileFieldNameScope(fieldName,meshName),_infos(infos)
6990 {
6991   setDtUnit(dtunit.c_str());
6992   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
6993 }
6994 catch(INTERP_KERNEL::Exception& e)
6995 {
6996     throw e;
6997 }
6998
6999 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7000 {
7001   std::size_t ret(_mesh_name.capacity()+_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7002   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7003     ret+=(*it).capacity();
7004   return ret;
7005 }
7006
7007 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7008 {
7009   std::vector<const BigMemoryObject *> ret;
7010   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7011     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7012   return ret;
7013 }
7014
7015 /*!
7016  * 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
7017  * NULL.
7018  */
7019 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7020 {
7021   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7022   ret->setInfo(_infos);
7023   int sz=(int)_time_steps.size();
7024   for(const int *id=startIds;id!=endIds;id++)
7025     {
7026       if(*id>=0 && *id<sz)
7027         {
7028           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7029           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7030           if(tse)
7031             {
7032               tse->incrRef();
7033               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7034             }
7035           ret->pushBackTimeStep(tse2);
7036         }
7037       else
7038         {
7039           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7040           oss << " ! Should be in [0," << sz << ") !";
7041           throw INTERP_KERNEL::Exception(oss.str());
7042         }
7043     }
7044   if(ret->getNumberOfTS()>0)
7045     ret->synchronizeNameScope();
7046   ret->copyNameScope(*this);
7047   return ret.retn();
7048 }
7049
7050 /*!
7051  * 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
7052  * NULL.
7053  */
7054 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7055 {
7056   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7057   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7058   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7059   ret->setInfo(_infos);
7060   int sz=(int)_time_steps.size();
7061   int j=bg;
7062   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7063     {
7064       if(j>=0 && j<sz)
7065         {
7066           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7067           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7068           if(tse)
7069             {
7070               tse->incrRef();
7071               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7072             }
7073           ret->pushBackTimeStep(tse2);
7074         }
7075       else
7076         {
7077           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7078           oss << " ! Should be in [0," << sz << ") !";
7079           throw INTERP_KERNEL::Exception(oss.str());
7080         }
7081     }
7082   if(ret->getNumberOfTS()>0)
7083     ret->synchronizeNameScope();
7084   ret->copyNameScope(*this);
7085   return ret.retn();
7086 }
7087
7088 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7089 {
7090   int id=0;
7091   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7092   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7093     {
7094       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7095       if(!cur)
7096         continue;
7097       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7098       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7099         ids->pushBackSilent(id);
7100     }
7101   return buildFromTimeStepIds(ids->begin(),ids->end());
7102 }
7103
7104 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7105 {
7106   int id=0;
7107   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7108   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7109     {
7110       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7111       if(!cur)
7112         continue;
7113       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7114       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7115         ids->pushBackSilent(id);
7116     }
7117   return buildFromTimeStepIds(ids->begin(),ids->end());
7118 }
7119
7120 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
7121 {
7122   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7123     if((*it).isNotNull())
7124       if((*it)->presenceOfStructureElements())
7125         return true;
7126   return false;
7127 }
7128
7129 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
7130 {
7131   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7132     if((*it).isNotNull())
7133       if(!(*it)->onlyStructureElements())
7134         return false;
7135   return true;
7136 }
7137
7138 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
7139 {
7140   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7141   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7142     if((*it).isNotNull())
7143       {
7144         if((*it)->presenceOfStructureElements())
7145           {
7146             if(!(*it)->onlyStructureElements())
7147               {
7148                 (*it)->killStructureElements();
7149                 ret.push_back(*it);
7150               }
7151           }
7152         else
7153           {
7154             ret.push_back(*it);
7155           }
7156       }
7157   _time_steps=ret;
7158 }
7159
7160 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
7161 {
7162   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7163   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7164     if((*it).isNotNull())
7165       {
7166         if((*it)->presenceOfStructureElements())
7167           {
7168             if(!(*it)->onlyStructureElements())
7169               (*it)->keepOnlyStructureElements();
7170             ret.push_back(*it);
7171           }
7172       }
7173   _time_steps=ret;
7174 }
7175
7176 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
7177 {
7178   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7179   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7180     if((*it).isNotNull())
7181       (*it)->keepOnlyOnSE(seName);
7182 }
7183
7184 void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
7185 {
7186   std::vector< std::pair<std::string,std::string> > ps2;
7187   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7188     if((*it).isNotNull())
7189       {
7190         (*it)->getMeshSENames(ps2);
7191         break;
7192       }
7193   if(ps2.empty())
7194     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
7195   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7196     if((*it).isNotNull())
7197       {
7198         std::vector< std::pair<std::string,std::string> > ps3;
7199         (*it)->getMeshSENames(ps3);
7200         if(ps2!=ps3)
7201           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
7202       }
7203   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
7204     {
7205       std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
7206       if(it2==ps.end())
7207         ps.push_back(*it);
7208     }
7209 }
7210
7211 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7212 {
7213   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7214     {
7215       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7216       if(!cur)
7217         continue;
7218       if(cur->presenceOfMultiDiscPerGeoType())
7219         return true;
7220     }
7221   return false;
7222 }
7223
7224 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7225 {
7226   return _infos;
7227 }
7228
7229 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7230 {
7231   _infos=info;
7232 }
7233
7234 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7235 {
7236   int ret=0;
7237   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7238     {
7239       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7240       if(pt->isDealingTS(iteration,order))
7241         return ret;
7242     }
7243   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7244   std::vector< std::pair<int,int> > vp=getIterations();
7245   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7246     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7247   throw INTERP_KERNEL::Exception(oss.str());
7248 }
7249
7250 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7251 {
7252   return *_time_steps[getTimeStepPos(iteration,order)];
7253 }
7254
7255 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7256 {
7257   return *_time_steps[getTimeStepPos(iteration,order)];
7258 }
7259
7260 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7261 {
7262   bool ret(false);
7263   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
7264     {
7265       if((*it).first==getMeshName())
7266         {
7267           setMeshName((*it).second);
7268           ret=true;
7269         }
7270     }
7271   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7272     {
7273       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7274       if(cur)
7275         ret=cur->changeMeshNames(modifTab) || ret;
7276     }
7277   return ret;
7278 }
7279
7280 /*!
7281  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7282  */
7283 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7284 {
7285   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7286 }
7287
7288 /*!
7289  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7290  */
7291 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7292 {
7293   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7294 }
7295
7296 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7297                                                                        MEDFileFieldGlobsReal& glob)
7298 {
7299   bool ret=false;
7300   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7301     {
7302       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7303       if(f1ts)
7304         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7305     }
7306   return ret;
7307 }
7308
7309 void MEDFileAnyTypeFieldMultiTSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
7310 {
7311   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7312     if((*it).isNotNull())
7313       {
7314         visitor.newTimeStepEntry(*it);
7315         (*it)->accept(visitor);
7316         visitor.endTimeStepEntry(*it);
7317       }
7318 }
7319
7320 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7321 {
7322   std::string startLine(bkOffset,' ');
7323   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7324   if(fmtsId>=0)
7325     oss << " (" << fmtsId << ")";
7326   oss << " has the following name: \"" << _name << "\"." << std::endl;
7327   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7328   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7329     {
7330       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7331     }
7332   int i=0;
7333   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7334     {
7335       std::string chapter(17,'0'+i);
7336       oss << startLine << chapter << std::endl;
7337       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7338       if(cur)
7339         cur->simpleRepr(bkOffset+2,oss,i);
7340       else
7341         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7342       oss << startLine << chapter << std::endl;
7343     }
7344 }
7345
7346 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7347 {
7348   std::size_t sz=_time_steps.size();
7349   std::vector< std::pair<int,int> > ret(sz);
7350   ret1.resize(sz);
7351   for(std::size_t i=0;i<sz;i++)
7352     {
7353       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7354       if(f1ts)
7355         {
7356           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7357         }
7358       else
7359         {
7360           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7361           throw INTERP_KERNEL::Exception(oss.str());
7362         }
7363     }
7364   return ret;
7365 }
7366
7367 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7368 {
7369   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7370   if(!tse2)
7371     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7372   checkCoherencyOfType(tse2);
7373   if(_time_steps.empty())
7374     {
7375       setName(tse2->getName());
7376       setMeshName(tse2->getMeshName());
7377       setInfo(tse2->getInfo());
7378     }
7379   checkThatComponentsMatch(tse2->getInfo());
7380   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7381     setDtUnit(tse->getDtUnit());
7382   _time_steps.push_back(tse);
7383 }
7384
7385 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7386 {
7387   std::size_t nbOfCompo=_infos.size();
7388   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7389     {
7390       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7391       if(cur)
7392         {
7393           if((cur->getInfo()).size()!=nbOfCompo)
7394             {
7395               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7396               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7397               throw INTERP_KERNEL::Exception(oss.str());
7398             }
7399           cur->copyNameScope(*this);
7400         }
7401     }
7402 }
7403
7404 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7405 {
7406   _time_steps.resize(nbPdt);
7407   for(int i=0;i<nbPdt;i++)
7408     {
7409       std::vector< std::pair<int,int> > ts;
7410       med_int numdt=0,numo=0;
7411       med_float dt=0.0;
7412       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7413       switch(fieldTyp)
7414       {
7415         case MED_FLOAT64:
7416           {
7417             _time_steps[i]=MEDFileField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7418             break;
7419           }
7420         case MED_INT32:
7421           {
7422             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7423             break;
7424           }
7425         case MED_FLOAT32:
7426           {
7427             _time_steps[i]=MEDFileFloatField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
7428             break;
7429           }
7430         default:
7431           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32, FLOAT32 !");
7432       }
7433       if(loadAll)
7434         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7435       else
7436         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7437       synchronizeNameScope();
7438     }
7439 }
7440
7441 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7442 {
7443   if(_time_steps.empty())
7444     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7445   checkThatNbOfCompoOfTSMatchThis();
7446   std::vector<std::string> infos(getInfo());
7447   int nbComp=infos.size();
7448   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7449   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7450   for(int i=0;i<nbComp;i++)
7451     {
7452       std::string info=infos[i];
7453       std::string c,u;
7454       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7455       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7456       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7457     }
7458   if(_name.empty())
7459     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7460   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7461   int nbOfTS=_time_steps.size();
7462   for(int i=0;i<nbOfTS;i++)
7463     _time_steps[i]->writeLL(fid,opts,*this);
7464 }
7465
7466 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7467 {
7468   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7469     {
7470       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7471       if(elt)
7472         elt->loadBigArraysRecursively(fid,nasc);
7473     }
7474 }
7475
7476 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7477 {
7478   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7479     {
7480       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7481       if(elt)
7482         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7483     }
7484 }
7485
7486 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7487 {
7488   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7489     {
7490       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7491       if(elt)
7492         elt->unloadArrays();
7493     }
7494 }
7495
7496 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7497 {
7498   return _time_steps.size();
7499 }
7500
7501 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7502 {
7503   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7504   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7505     {
7506       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7507       if(tmp)
7508         newTS.push_back(*it);
7509     }
7510   _time_steps=newTS;
7511 }
7512
7513 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7514 {
7515   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7516   int maxId=(int)_time_steps.size();
7517   int ii=0;
7518   std::set<int> idsToDel;
7519   for(const int *id=startIds;id!=endIds;id++,ii++)
7520     {
7521       if(*id>=0 && *id<maxId)
7522         {
7523           idsToDel.insert(*id);
7524         }
7525       else
7526         {
7527           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7528           throw INTERP_KERNEL::Exception(oss.str());
7529         }
7530     }
7531   for(int iii=0;iii<maxId;iii++)
7532     if(idsToDel.find(iii)==idsToDel.end())
7533       newTS.push_back(_time_steps[iii]);
7534   _time_steps=newTS;
7535 }
7536
7537 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7538 {
7539   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7540   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7541   if(nbOfEntriesToKill==0)
7542     return ;
7543   std::size_t sz=_time_steps.size();
7544   std::vector<bool> b(sz,true);
7545   int j=bg;
7546   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7547     b[j]=false;
7548   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7549   for(std::size_t i=0;i<sz;i++)
7550     if(b[i])
7551       newTS.push_back(_time_steps[i]);
7552   _time_steps=newTS;
7553 }
7554
7555 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7556 {
7557   int ret=0;
7558   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7559   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7560     {
7561       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7562       if(tmp)
7563         {
7564           int it2,ord;
7565           tmp->getTime(it2,ord);
7566           if(it2==iteration && order==ord)
7567             return ret;
7568           else
7569             oss << "(" << it2 << ","  << ord << "), ";
7570         }
7571     }
7572   throw INTERP_KERNEL::Exception(oss.str());
7573 }
7574
7575 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7576 {
7577   int ret=0;
7578   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7579   oss.precision(15);
7580   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7581     {
7582       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7583       if(tmp)
7584         {
7585           int it2,ord;
7586           double ti=tmp->getTime(it2,ord);
7587           if(fabs(time-ti)<eps)
7588             return ret;
7589           else
7590             oss << ti << ", ";
7591         }
7592     }
7593   throw INTERP_KERNEL::Exception(oss.str());
7594 }
7595
7596 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7597 {
7598   int lgth=_time_steps.size();
7599   std::vector< std::pair<int,int> > ret(lgth);
7600   for(int i=0;i<lgth;i++)
7601     _time_steps[i]->fillIteration(ret[i]);
7602   return ret;
7603 }
7604
7605 /*!
7606  * 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'
7607  * This method returns two things.
7608  * - The absolute dimension of 'this' in first parameter. 
7609  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7610  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7611  *
7612  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7613  * Only these 3 discretizations will be taken into account here.
7614  *
7615  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7616  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7617  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7618  *
7619  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7620  * 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'.
7621  * 
7622  * Let's consider the typical following case :
7623  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7624  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7625  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7626  *   TETRA4 and SEG2
7627  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7628  *
7629  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7630  * 
7631  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7632  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7633  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7634  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7635  */
7636 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7637 {
7638   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7639 }
7640
7641 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7642 {
7643   if(pos<0 || pos>=(int)_time_steps.size())
7644     {
7645       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7646       throw INTERP_KERNEL::Exception(oss.str());
7647     }
7648   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7649   if(item==0)
7650     {
7651       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7652       oss << "\nTry to use following method eraseEmptyTS !";
7653       throw INTERP_KERNEL::Exception(oss.str());
7654     }
7655   return item;
7656 }
7657
7658 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7659 {
7660   if(pos<0 || pos>=(int)_time_steps.size())
7661     {
7662       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7663       throw INTERP_KERNEL::Exception(oss.str());
7664     }
7665   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7666   if(item==0)
7667     {
7668       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7669       oss << "\nTry to use following method eraseEmptyTS !";
7670       throw INTERP_KERNEL::Exception(oss.str());
7671     }
7672   return item;
7673 }
7674
7675 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7676 {
7677   std::vector<std::string> ret;
7678   std::set<std::string> ret2;
7679   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7680     {
7681       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7682       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7683         if(ret2.find(*it2)==ret2.end())
7684           {
7685             ret.push_back(*it2);
7686             ret2.insert(*it2);
7687           }
7688     }
7689   return ret;
7690 }
7691
7692 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7693 {
7694   std::vector<std::string> ret;
7695   std::set<std::string> ret2;
7696   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7697     {
7698       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7699       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7700         if(ret2.find(*it2)==ret2.end())
7701           {
7702             ret.push_back(*it2);
7703             ret2.insert(*it2);
7704           }
7705     }
7706   return ret;
7707 }
7708
7709 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7710 {
7711   std::vector<std::string> ret;
7712   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7713     {
7714       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7715       ret.insert(ret.end(),tmp.begin(),tmp.end());
7716     }
7717   return ret;
7718 }
7719
7720 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7721 {
7722   std::vector<std::string> ret;
7723   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7724     {
7725       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7726       ret.insert(ret.end(),tmp.begin(),tmp.end());
7727     }
7728   return ret;
7729 }
7730
7731 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7732 {
7733   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7734     (*it)->changePflsRefsNamesGen2(mapOfModif);
7735 }
7736
7737 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7738 {
7739   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7740     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7741 }
7742
7743 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7744 {
7745   int lgth=_time_steps.size();
7746   std::vector< std::vector<TypeOfField> > ret(lgth);
7747   for(int i=0;i<lgth;i++)
7748     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7749   return ret;
7750 }
7751
7752 /*!
7753  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7754  */
7755 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
7756 {
7757   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7758 }
7759
7760 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7761 {
7762   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7763   std::size_t i=0;
7764   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7765     {
7766       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7767         ret->_time_steps[i]=(*it)->deepCopy();
7768     }
7769   return ret.retn();
7770 }
7771
7772 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7773 {
7774   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7775   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7776   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7777   for(std::size_t i=0;i<sz;i++)
7778     {
7779       ret[i]=shallowCpy();
7780       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7781     }
7782   for(std::size_t i=0;i<sz2;i++)
7783     {
7784       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7785       if(ret1.size()!=sz)
7786         {
7787           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7788           throw INTERP_KERNEL::Exception(oss.str());
7789         }
7790       ts[i]=ret1;
7791     }
7792   for(std::size_t i=0;i<sz;i++)
7793     for(std::size_t j=0;j<sz2;j++)
7794       ret[i]->_time_steps[j]=ts[j][i];
7795   return ret;
7796 }
7797
7798 /*!
7799  * This method splits into discretization each time steps in \a this.
7800  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7801  */
7802 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7803 {
7804   std::size_t sz(_time_steps.size());
7805   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7806   for(std::size_t i=0;i<sz;i++)
7807     {
7808       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7809       if(!timeStep)
7810         {
7811           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7812           throw INTERP_KERNEL::Exception(oss.str());
7813         }
7814       items[i]=timeStep->splitDiscretizations();  
7815     }
7816   //
7817   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7818   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7819   std::vector< TypeOfField > types;
7820   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7821     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7822       {
7823         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7824         if(ts.size()!=1)
7825           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7826         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7827         if(it2==types.end())
7828           types.push_back(ts[0]);
7829       }
7830   ret.resize(types.size()); ret2.resize(types.size());
7831   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7832     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7833       {
7834         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7835         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7836         ret2[pos].push_back(*it1);
7837       }
7838   for(std::size_t i=0;i<types.size();i++)
7839     {
7840       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7841       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7842         elt->pushBackTimeStep(*it1);//also updates infos in elt
7843       ret[i]=elt;
7844       elt->MEDFileFieldNameScope::operator=(*this);
7845     }
7846   return ret;
7847 }
7848
7849 /*!
7850  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7851  */
7852 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7853 {
7854   std::size_t sz(_time_steps.size());
7855   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7856   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7857   for(std::size_t i=0;i<sz;i++)
7858     {
7859       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7860       if(!timeStep)
7861         {
7862           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7863           throw INTERP_KERNEL::Exception(oss.str());
7864         }
7865       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7866       if(szOut==std::numeric_limits<std::size_t>::max())
7867         szOut=items[i].size();
7868       else
7869         if(items[i].size()!=szOut)
7870           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7871     }
7872   if(szOut==std::numeric_limits<std::size_t>::max())
7873     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7874   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7875   for(std::size_t i=0;i<szOut;i++)
7876     {
7877       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7878       for(std::size_t j=0;j<sz;j++)
7879         elt->pushBackTimeStep(items[j][i]);
7880       ret[i]=elt;
7881       elt->MEDFileFieldNameScope::operator=(*this);
7882     }
7883   return ret;
7884 }
7885
7886 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7887 {
7888   setName(field->getName());
7889   if(field->getMesh())
7890     setMeshName(field->getMesh()->getName());
7891   if(_name.empty())
7892     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7893   if(!arr)
7894     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7895   _infos=arr->getInfoOnComponents();
7896 }
7897
7898 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7899 {
7900   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7901   if(_name!=field->getName())
7902     {
7903       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7904       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7905       throw INTERP_KERNEL::Exception(oss.str());
7906     }
7907   if(!arr)
7908     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7909   checkThatComponentsMatch(arr->getInfoOnComponents());
7910 }
7911
7912 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7913 {
7914   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7915   if(getInfo().size()!=compos.size())
7916     {
7917       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7918       oss << " number of components of element to append (" << compos.size() << ") !";
7919       throw INTERP_KERNEL::Exception(oss.str());
7920     }
7921   if(_infos!=compos)
7922     {
7923       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7924       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7925       oss << " But compo in input fields are : ";
7926       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7927       oss << " !";
7928       throw INTERP_KERNEL::Exception(oss.str());
7929     }
7930 }
7931
7932 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7933 {
7934   std::size_t sz=_infos.size();
7935   int j=0;
7936   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7937     {
7938       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7939       if(elt)
7940         if(elt->getInfo().size()!=sz)
7941           {
7942             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7943             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7944             throw INTERP_KERNEL::Exception(oss.str());
7945           }
7946     }
7947 }
7948
7949 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7950 {
7951   if(!field)
7952     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7953   if(!_time_steps.empty())
7954     checkCoherencyOfTinyInfo(field,arr);
7955   MEDFileAnyTypeField1TSWithoutSDA *objC(createNew1TSWithoutSDAEmptyInstance());
7956   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7957   {
7958     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*field));
7959     objC->setFieldNoProfileSBT(field->timeDiscrSafe(),ft,arr,glob,*this);
7960   }
7961   copyTinyInfoFrom(field,arr);
7962   _time_steps.push_back(obj);
7963 }
7964
7965 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7966 {
7967   if(!field)
7968     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7969   if(!_time_steps.empty())
7970     checkCoherencyOfTinyInfo(field,arr);
7971   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7972   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7973   {
7974     MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::NewWithoutCheck(*field));
7975     objC->setFieldProfile(field->timeDiscrSafe(),ft,arr,mesh,meshDimRelToMax,profile,glob,*this);
7976   }
7977   copyTinyInfoFrom(field,arr);
7978   setMeshName(objC->getMeshName());
7979   _time_steps.push_back(obj);
7980 }
7981
7982 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
7983 {
7984   int sz=(int)_time_steps.size();
7985   if(i<0 || i>=sz)
7986     {
7987       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7988       throw INTERP_KERNEL::Exception(oss.str());
7989     }
7990   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7991   if(tsPtr)
7992     {
7993       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7994         {
7995           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7996           throw INTERP_KERNEL::Exception(oss.str());
7997         }
7998     }
7999   _time_steps[i]=ts;
8000 }
8001
8002 //= MEDFileFieldMultiTSWithoutSDA
8003
8004 /*!
8005  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8006  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8007  */
8008 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
8009 {
8010   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8011   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8012   if(!myF1TSC)
8013     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8014   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8015 }
8016
8017 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8018 {
8019   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8020   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8021   int i=0;
8022   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8023     {
8024       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8025       if(eltToConv)
8026         {
8027           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8028           if(!eltToConvC)
8029             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8030           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8031           ret->setIteration(i,elt);
8032         }
8033     }
8034   return ret.retn();
8035 }
8036
8037 //= MEDFileAnyTypeFieldMultiTS
8038
8039 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8040 {
8041 }
8042
8043 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8044 try:MEDFileFieldGlobsReal(fid)
8045 {
8046   _content=BuildContentFrom(fid,loadAll,ms);
8047   loadGlobals(fid);
8048 }
8049 catch(INTERP_KERNEL::Exception& e)
8050 {
8051     throw e;
8052 }
8053
8054 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8055 {
8056   med_field_type typcha;
8057   std::vector<std::string> infos;
8058   std::string dtunit;
8059   std::string meshName;
8060   int i(-1);
8061   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit,meshName);
8062   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8063   switch(typcha)
8064   {
8065     case MED_FLOAT64:
8066       {
8067         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8068         break;
8069       }
8070     case MED_INT32:
8071       {
8072         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8073         break;
8074       }
8075     case MED_FLOAT32:
8076       {
8077         ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8078         break;
8079       }
8080     default:
8081       {
8082         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] !";
8083         throw INTERP_KERNEL::Exception(oss.str());
8084       }
8085   }
8086   ret->setMeshName(meshName);
8087   ret->setDtUnit(dtunit.c_str());
8088   return ret.retn();
8089 }
8090
8091 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8092 {
8093   med_field_type typcha;
8094   //
8095   std::vector<std::string> infos;
8096   std::string dtunit,fieldName,meshName;
8097   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
8098   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8099   switch(typcha)
8100   {
8101     case MED_FLOAT64:
8102       {
8103         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8104         break;
8105       }
8106     case MED_INT32:
8107       {
8108         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8109         break;
8110       }
8111     case MED_FLOAT32:
8112       {
8113         ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8114         break;
8115       }
8116     default:
8117       {
8118         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] !";
8119         throw INTERP_KERNEL::Exception(oss.str());
8120       }
8121   }
8122   ret->setMeshName(meshName);
8123   ret->setDtUnit(dtunit.c_str());
8124   return ret.retn();
8125 }
8126
8127 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8128 {
8129   if(!c)
8130     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8131   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8132     {
8133       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8134       ret->_content=c;  c->incrRef();
8135       return ret.retn();
8136     }
8137   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8138     {
8139       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8140       ret->_content=c;  c->incrRef();
8141       return ret.retn();
8142     }
8143   if(dynamic_cast<const MEDFileFloatFieldMultiTSWithoutSDA *>(c))
8144     {
8145       MCAuto<MEDFileFloatFieldMultiTS> ret(MEDFileFloatFieldMultiTS::New());
8146       ret->_content=c;  c->incrRef();
8147       return ret.retn();
8148     }
8149   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
8150 }
8151
8152 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8153 {
8154   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8155   std::string fileName(FileNameFromFID(fid));
8156   ret->setFileName(fileName);
8157   return ret;
8158 }
8159
8160 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8161 try:MEDFileFieldGlobsReal(fid)
8162 {
8163   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8164   loadGlobals(fid);
8165 }
8166 catch(INTERP_KERNEL::Exception& e)
8167 {
8168     throw e;
8169 }
8170
8171 //= MEDFileAnyTypeFieldMultiTS
8172
8173 /*!
8174  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8175  * that has been read from a specified MED file.
8176  *  \param [in] fileName - the name of the MED file to read.
8177  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8178  *          is to delete this field using decrRef() as it is no more needed.
8179  *  \throw If reading the file fails.
8180  */
8181 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8182 {
8183   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8184   return New(fid,loadAll);
8185 }
8186
8187 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8188 {
8189   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8190   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8191   ret->loadGlobals(fid);
8192   return ret.retn();
8193 }
8194
8195 /*!
8196  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8197  * that has been read from a specified MED file.
8198  *  \param [in] fileName - the name of the MED file to read.
8199  *  \param [in] fieldName - the name of the field to read.
8200  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8201  *          is to delete this field using decrRef() as it is no more needed.
8202  *  \throw If reading the file fails.
8203  *  \throw If there is no field named \a fieldName in the file.
8204  */
8205 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8206 {
8207   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8208   return New(fid,fieldName,loadAll);
8209 }
8210
8211 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8212 {
8213   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8214   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8215   ret->loadGlobals(fid);
8216   return ret.retn();
8217 }
8218
8219 /*!
8220  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8221  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8222  *
8223  * \warning this is a shallow copy constructor
8224  */
8225 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8226 {
8227   if(!shallowCopyOfContent)
8228     {
8229       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8230       otherPtr->incrRef();
8231       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8232     }
8233   else
8234     {
8235       _content=other.shallowCpy();
8236     }
8237 }
8238
8239 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8240 {
8241   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8242   if(!ret)
8243     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8244   return ret;
8245 }
8246
8247 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8248 {
8249   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8250   if(!ret)
8251     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8252   return ret;
8253 }
8254
8255 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8256 {
8257   return contentNotNullBase()->getPflsReallyUsed2();
8258 }
8259
8260 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8261 {
8262   return contentNotNullBase()->getLocsReallyUsed2();
8263 }
8264
8265 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8266 {
8267   return contentNotNullBase()->getPflsReallyUsedMulti2();
8268 }
8269
8270 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8271 {
8272   return contentNotNullBase()->getLocsReallyUsedMulti2();
8273 }
8274
8275 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8276 {
8277   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8278 }
8279
8280 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8281 {
8282   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8283 }
8284
8285 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8286 {
8287   return contentNotNullBase()->getNumberOfTS();
8288 }
8289
8290 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8291 {
8292   contentNotNullBase()->eraseEmptyTS();
8293 }
8294
8295 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8296 {
8297   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8298 }
8299
8300 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8301 {
8302   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8303 }
8304
8305 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8306 {
8307   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8308   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8309   ret->_content=c;
8310   return ret.retn();
8311 }
8312
8313 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8314 {
8315   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8316   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8317   ret->_content=c;
8318   return ret.retn();
8319 }
8320
8321 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8322 {
8323   return contentNotNullBase()->getIterations();
8324 }
8325
8326 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8327 {
8328   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8329     pushBackTimeStep(*it);
8330 }
8331
8332 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8333 {
8334   if(!fmts)
8335     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8336   int nbOfTS(fmts->getNumberOfTS());
8337   for(int i=0;i<nbOfTS;i++)
8338     {
8339       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8340       pushBackTimeStep(elt);
8341     }
8342 }
8343
8344 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8345 {
8346   if(!f1ts)
8347     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8348   checkCoherencyOfType(f1ts);
8349   f1ts->incrRef();
8350   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8351   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8352   c->incrRef();
8353   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8354   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8355     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8356   _content->pushBackTimeStep(cSafe);
8357   appendGlobs(*f1ts,1e-12);
8358 }
8359
8360 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8361 {
8362   contentNotNullBase()->synchronizeNameScope();
8363 }
8364
8365 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8366 {
8367   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8368 }
8369
8370 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8371 {
8372   return contentNotNullBase()->getPosGivenTime(time,eps);
8373 }
8374
8375 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8376 {
8377   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8378 }
8379
8380 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8381 {
8382   return contentNotNullBase()->getTypesOfFieldAvailable();
8383 }
8384
8385 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
8386 {
8387   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8388 }
8389
8390 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8391 {
8392   return contentNotNullBase()->getName();
8393 }
8394
8395 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8396 {
8397   contentNotNullBase()->setName(name);
8398 }
8399
8400 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8401 {
8402   return contentNotNullBase()->getDtUnit();
8403 }
8404
8405 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8406 {
8407   contentNotNullBase()->setDtUnit(dtUnit);
8408 }
8409
8410 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8411 {
8412   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8413 }
8414
8415 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8416 {
8417   return contentNotNullBase()->getTimeSteps(ret1);
8418 }
8419
8420 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8421 {
8422   return contentNotNullBase()->getMeshName();
8423 }
8424
8425 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8426 {
8427   contentNotNullBase()->setMeshName(newMeshName);
8428 }
8429
8430 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8431 {
8432   return contentNotNullBase()->changeMeshNames(modifTab);
8433 }
8434
8435 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8436 {
8437   return contentNotNullBase()->getInfo();
8438 }
8439
8440 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8441 {
8442   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8443 }
8444
8445 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8446 {
8447   return contentNotNullBase()->setInfo(info);
8448 }
8449
8450 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8451 {
8452   const std::vector<std::string> ret=getInfo();
8453   return (int)ret.size();
8454 }
8455
8456 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8457 {
8458   writeGlobals(fid,*this);
8459   contentNotNullBase()->writeLL(fid,*this);
8460 }
8461
8462 /*!
8463  * This method alloc the arrays and load potentially huge arrays contained in this field.
8464  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8465  * This method can be also called to refresh or reinit values from a file.
8466  * 
8467  * \throw If the fileName is not set or points to a non readable MED file.
8468  */
8469 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8470 {
8471   if(getFileName().empty())
8472     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8473   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8474   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8475 }
8476
8477 /*!
8478  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8479  * But once data loaded once, this method does nothing.
8480  * 
8481  * \throw If the fileName is not set or points to a non readable MED file.
8482  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8483  */
8484 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8485 {
8486   if(!getFileName().empty())
8487     {
8488       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8489       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8490     }
8491 }
8492
8493 /*!
8494  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8495  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8496  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8497  * 
8498  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8499  */
8500 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8501 {
8502   contentNotNullBase()->unloadArrays();
8503 }
8504
8505 /*!
8506  * 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.
8507  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8508  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8509  * 
8510  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8511  */
8512 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8513 {
8514   if(!getFileName().empty())
8515     contentNotNullBase()->unloadArrays();
8516 }
8517
8518 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8519 {
8520   std::ostringstream oss;
8521   contentNotNullBase()->simpleRepr(0,oss,-1);
8522   simpleReprGlobs(oss);
8523   return oss.str();
8524 }
8525
8526 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8527 {
8528   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8529 }
8530
8531 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8532 {
8533   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8534   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8535   return ret;
8536 }
8537
8538 /*!
8539  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8540  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8541  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8542  */
8543 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8544 {
8545   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8546   if(!content)
8547     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8548   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8549   std::size_t sz(contentsSplit.size());
8550   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8551   for(std::size_t i=0;i<sz;i++)
8552     {
8553       ret[i]=shallowCpy();
8554       ret[i]->_content=contentsSplit[i];
8555     }
8556   return ret;
8557 }
8558
8559 /*!
8560  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8561  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8562  */
8563 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8564 {
8565   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8566   if(!content)
8567     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8568   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8569   std::size_t sz(contentsSplit.size());
8570   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8571   for(std::size_t i=0;i<sz;i++)
8572     {
8573       ret[i]=shallowCpy();
8574       ret[i]->_content=contentsSplit[i];
8575     }
8576   return ret;
8577 }
8578
8579 /*!
8580  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8581  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8582  */
8583 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8584 {
8585   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8586   if(!content)
8587     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8588   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8589   std::size_t sz(contentsSplit.size());
8590   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8591   for(std::size_t i=0;i<sz;i++)
8592     {
8593       ret[i]=shallowCpy();
8594       ret[i]->_content=contentsSplit[i];
8595     }
8596   return ret;
8597 }
8598
8599 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8600 {
8601   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8602   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8603     ret->_content=_content->deepCopy();
8604   ret->deepCpyGlobs(*this);
8605   return ret.retn();
8606 }
8607
8608 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8609 {
8610   return _content;
8611 }
8612
8613 /*!
8614  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8615  *  \param [in] iteration - the iteration number of a required time step.
8616  *  \param [in] order - the iteration order number of required time step.
8617  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8618  *          delete this field using decrRef() as it is no more needed.
8619  *  \throw If there is no required time step in \a this field.
8620  */
8621 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8622 {
8623   int pos=getPosOfTimeStep(iteration,order);
8624   return getTimeStepAtPos(pos);
8625 }
8626
8627 /*!
8628  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8629  *  \param [in] time - the time of the time step of interest.
8630  *  \param [in] eps - a precision used to compare time values.
8631  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8632  *          delete this field using decrRef() as it is no more needed.
8633  *  \throw If there is no required time step in \a this field.
8634  */
8635 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8636 {
8637   int pos=getPosGivenTime(time,eps);
8638   return getTimeStepAtPos(pos);
8639 }
8640
8641 /*!
8642  * 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.
8643  * The float64 value of time attached to the pair of integers are not considered here.
8644  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8645  *
8646  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8647  * \throw If there is a null pointer in \a vectFMTS.
8648  */
8649 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8650 {
8651   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8652   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8653   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8654   while(!lstFMTS.empty())
8655     {
8656       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8657       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8658       if(!curIt)
8659         throw INTERP_KERNEL::Exception(msg);
8660       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8661       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8662       elt.push_back(curIt); it=lstFMTS.erase(it);
8663       while(it!=lstFMTS.end())
8664         {
8665           curIt=*it;
8666           if(!curIt)
8667             throw INTERP_KERNEL::Exception(msg);
8668           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8669           if(refIts==curIts)
8670             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8671           else
8672             it++;
8673         }
8674       ret.push_back(elt);
8675     }
8676   return ret;
8677 }
8678
8679 /*!
8680  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8681  * All returned instances in a subvector can be safely loaded, rendered along time
8682  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8683  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8684  * 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).
8685  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8686  * 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.
8687  *
8688  * \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().
8689  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8690  * \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.
8691  * \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.
8692  *
8693  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8694  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8695  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8696  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8697  * \throw If mesh is null.
8698  * \throw If an element in \a vectFMTS is null.
8699  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8700  */
8701 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8702 {
8703   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8704   if(!mesh)
8705     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8706   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8707   if(vectFMTS.empty())
8708     return ret;
8709   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8710   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8711   if(!frstElt)
8712     throw INTERP_KERNEL::Exception(msg);
8713   std::size_t i=0;
8714   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8715   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8716   for(;it!=vectFMTS.end();it++,i++)
8717     {
8718       if(!(*it))
8719         throw INTERP_KERNEL::Exception(msg);
8720       TypeOfField tof0,tof1;
8721       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8722         {
8723           if(tof1!=ON_NODES)
8724             vectFMTSNotNodes.push_back(*it);
8725           else
8726             vectFMTSNodes.push_back(*it);
8727         }
8728       else
8729         vectFMTSNotNodes.push_back(*it);
8730     }
8731   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8732   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8733   ret=retCell;
8734   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8735     {
8736       i=0;
8737       bool isFetched(false);
8738       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8739         {
8740           if((*it0).empty())
8741             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8742           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8743             { ret[i].push_back(*it2); isFetched=true; }
8744         }
8745       if(!isFetched)
8746         {
8747           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8748           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8749           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8750         }
8751     }
8752   fsc=cmps;
8753   return ret;
8754 }
8755
8756 /*!
8757  * 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.
8758  * \param [out] cmps - same size than the returned vector.
8759  */
8760 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8761 {
8762   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8763   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8764   while(!lstFMTS.empty())
8765     {
8766       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8767       MEDFileAnyTypeFieldMultiTS *ref(*it);
8768       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8769       elt.push_back(ref); it=lstFMTS.erase(it);
8770       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8771       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8772       while(it!=lstFMTS.end())
8773         {
8774           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8775           if(cmp->isEqual(curIt))
8776             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8777           else
8778             it++;
8779         }
8780       ret.push_back(elt); cmps.push_back(cmp);
8781     }
8782   return ret;
8783 }
8784
8785 /*!
8786  * 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.
8787  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8788  *
8789  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8790  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8791  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8792  * \thorw If \a f0 and \a f1 do not have the same times steps.
8793  * \throw If mesh is null.
8794  * \throw If \a f0 or \a f1 is null.
8795  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8796  */
8797 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8798 {
8799   if(!mesh)
8800     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8801   if(!f0 || !f1)
8802     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8803   if(f0->getMeshName()!=mesh->getName())
8804     {
8805       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8806       throw INTERP_KERNEL::Exception(oss.str());
8807     }
8808   if(f1->getMeshName()!=mesh->getName())
8809     {
8810       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8811       throw INTERP_KERNEL::Exception(oss.str());
8812     }
8813   int nts=f0->getNumberOfTS();
8814   if(nts!=f1->getNumberOfTS())
8815     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8816   if(nts==0)
8817     return nts;
8818   for(int i=0;i<nts;i++)
8819     {
8820       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8821       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8822       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8823       if(tofs0.size()!=1 || tofs1.size()!=1)
8824         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8825       if(i!=0)
8826         {
8827           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8828             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8829         }
8830       else
8831         { tof0=tofs0[0]; tof1=tofs1[0]; }
8832       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8833         {
8834           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() << ") !";
8835           throw INTERP_KERNEL::Exception(oss.str());
8836         }
8837       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8838         {
8839           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() << ") !";
8840           throw INTERP_KERNEL::Exception(oss.str());
8841         }
8842       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8843         {
8844           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() << ") !";
8845           throw INTERP_KERNEL::Exception(oss.str());
8846         }
8847     }
8848   return nts;
8849 }
8850
8851 template<class T>
8852 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
8853 {
8854   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
8855   if(f1tss.empty())
8856     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
8857   std::size_t sz(f1tss.size()),i(0);
8858   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
8859   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
8860     {
8861       typename MLFieldTraits<T>::F1TSType const *elt(*it);
8862       if(!elt)
8863         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
8864       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
8865     }
8866   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
8867   if(!retc)
8868     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
8869   retc->aggregate(f1tsw,dts);
8870   ret->setDtUnit(f1tss[0]->getDtUnit());
8871   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
8872 }
8873
8874 template<class T>
8875 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
8876 {
8877   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
8878   if(fmtss.empty())
8879     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
8880   std::size_t sz(fmtss.size());
8881   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
8882     {
8883       typename MLFieldTraits<T>::FMTSType const *elt(*it);
8884       if(!elt)
8885         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
8886     }
8887   int nbTS(fmtss[0]->getNumberOfTS());
8888   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
8889     if((*it)->getNumberOfTS()!=nbTS)
8890       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
8891   for(int iterTS=0;iterTS<nbTS;iterTS++)
8892     {
8893       std::size_t i(0);
8894       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
8895       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
8896       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
8897         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
8898       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
8899       ret->pushBackTimeStep(f1ts);
8900       ret->setDtUnit(f1ts->getDtUnit());
8901     }
8902   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
8903 }
8904
8905 /*!
8906  * \a dts and \a ftmss are expected to have same size.
8907  */
8908 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
8909 {
8910   if(fmtss.empty())
8911     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
8912   std::size_t sz(fmtss.size());
8913   std::vector<const MEDFileFieldMultiTS *> fmtss1;
8914   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
8915   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
8916     {
8917       if(!(*it))
8918         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
8919       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
8920       if(elt1)
8921         {
8922           fmtss1.push_back(elt1);
8923           continue;
8924         }
8925       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
8926       if(elt2)
8927         {
8928           fmtss2.push_back(elt2);
8929           continue;
8930         }
8931       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
8932     }
8933   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
8934     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
8935   if(fmtss1.size()==sz)
8936     return AggregateHelperFMTS<double>(fmtss1,dts);
8937   if(fmtss2.size()!=sz)
8938     return AggregateHelperFMTS<int>(fmtss2,dts);
8939   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
8940 }
8941
8942 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8943 {
8944   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8945 }
8946
8947 //= MEDFileFieldMultiTS
8948
8949 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8950 {
8951   return new MEDFileFieldMultiTS(*this);
8952 }
8953
8954 /*!
8955  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8956  * following the given input policy.
8957  *
8958  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8959  *                            By default (true) the globals are deeply copied.
8960  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8961  */
8962 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8963 {
8964   MCAuto<MEDFileIntFieldMultiTS> ret;
8965   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8966   if(content)
8967     {
8968       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8969       if(!contc)
8970         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8971       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8972       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
8973     }
8974   else
8975     ret=MEDFileIntFieldMultiTS::New();
8976   if(isDeepCpyGlobs)
8977     ret->deepCpyGlobs(*this);
8978   else
8979     ret->shallowCpyGlobs(*this);
8980   return ret.retn();
8981 }
8982
8983 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8984 try:MEDFileTemplateFieldMultiTS<double>(fid,loadAll,ms)
8985 {
8986 }
8987 catch(INTERP_KERNEL::Exception& e)
8988 { throw e; }
8989
8990 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8991 try:MEDFileTemplateFieldMultiTS<double>(fid,fieldName,loadAll,ms,entities)
8992 {
8993 }
8994 catch(INTERP_KERNEL::Exception& e)
8995 { throw e; }
8996
8997 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileTemplateFieldMultiTS<double>(other,shallowCopyOfContent)
8998 {
8999 }
9000
9001 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
9002 {
9003   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9004 }
9005
9006 //= MEDFileAnyTypeFieldMultiTSIterator
9007
9008 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9009 {
9010   if(fmts)
9011     {
9012       fmts->incrRef();
9013       _nb_iter=fmts->getNumberOfTS();
9014     }
9015 }
9016
9017 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9018 {
9019 }
9020
9021 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9022 {
9023   if(_iter_id<_nb_iter)
9024     {
9025       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9026       if(fmts)
9027         return fmts->getTimeStepAtPos(_iter_id++);
9028       else
9029         return 0;
9030     }
9031   else
9032     return 0;
9033 }
9034
9035 //= MEDFileIntFieldMultiTS
9036
9037 //= MEDFileFields
9038
9039 MEDFileFields *MEDFileFields::New()
9040 {
9041   return new MEDFileFields;
9042 }
9043
9044 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9045 {
9046   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9047   return New(fid,loadAll);
9048 }
9049
9050 MEDFileFields *MEDFileFields::NewAdv(const std::string& fileName, bool loadAll, const MEDFileEntities *entities)
9051 {
9052   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9053   return NewAdv(fid,loadAll,entities);
9054 }
9055
9056 MEDFileFields *MEDFileFields::NewAdv(med_idt fid, bool loadAll, const MEDFileEntities *entities)
9057 {
9058   return new MEDFileFields(fid,loadAll,0,entities);
9059 }
9060
9061 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
9062 {
9063   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9064   return NewWithDynGT(fid,se,loadAll);
9065 }
9066
9067 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
9068 {
9069   if(!se)
9070     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
9071   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
9072   return new MEDFileFields(fid,loadAll,0,entities);
9073 }
9074
9075 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
9076 {
9077   return new MEDFileFields(fid,loadAll,0,0);
9078 }
9079
9080 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9081 {
9082   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9083   return new MEDFileFields(fid,loadAll,ms,0);
9084 }
9085
9086 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9087 {
9088   MEDFileUtilities::CheckFileForRead(fileName);
9089   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9090   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9091   return new MEDFileFields(fid,loadAll,0,ent);
9092 }
9093
9094 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9095 {
9096   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9097   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9098   return ret;
9099 }
9100
9101 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9102 {
9103   std::vector<const BigMemoryObject *> ret;
9104   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9105     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9106   return ret;
9107 }
9108
9109 MEDFileFields *MEDFileFields::deepCopy() const
9110 {
9111   MCAuto<MEDFileFields> ret(shallowCpy());
9112   std::size_t i(0);
9113   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9114     {
9115       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9116         ret->_fields[i]=(*it)->deepCopy();
9117     }
9118   ret->deepCpyGlobs(*this);
9119   return ret.retn();
9120 }
9121
9122 MEDFileFields *MEDFileFields::shallowCpy() const
9123 {
9124   return new MEDFileFields(*this);
9125 }
9126
9127 /*!
9128  * 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
9129  * 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.
9130  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9131  *
9132  * \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.
9133  * \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.
9134  * 
9135  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9136  */
9137 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9138 {
9139   std::set< std::pair<int,int> > s;
9140   bool firstShot=true;
9141   areThereSomeForgottenTS=false;
9142   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9143     {
9144       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9145         continue;
9146       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9147       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9148       if(firstShot)
9149         { s=s1; firstShot=false; }
9150       else
9151         {
9152           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9153           if(s!=s2)
9154             areThereSomeForgottenTS=true;
9155           s=s2;
9156         }
9157     }
9158   std::vector< std::pair<int,int> > ret;
9159   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9160   return ret;
9161 }
9162
9163 int MEDFileFields::getNumberOfFields() const
9164 {
9165   return _fields.size();
9166 }
9167
9168 std::vector<std::string> MEDFileFields::getFieldsNames() const
9169 {
9170   std::vector<std::string> ret(_fields.size());
9171   int i(0);
9172   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9173     {
9174       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9175       if(f)
9176         {
9177           ret[i]=f->getName();
9178         }
9179       else
9180         {
9181           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9182           throw INTERP_KERNEL::Exception(oss.str());
9183         }
9184     }
9185   return ret;
9186 }
9187
9188 std::vector<std::string> MEDFileFields::getMeshesNames() const
9189 {
9190   std::vector<std::string> ret;
9191   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9192     {
9193       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9194       if(cur)
9195         ret.push_back(cur->getMeshName());
9196     }
9197   return ret;
9198 }
9199
9200 std::string MEDFileFields::simpleRepr() const
9201 {
9202   std::ostringstream oss;
9203   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9204   simpleRepr(0,oss);
9205   return oss.str();
9206 }
9207
9208 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9209 {
9210   int nbOfFields(getNumberOfFields());
9211   std::string startLine(bkOffset,' ');
9212   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9213   int i=0;
9214   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9215     {
9216       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9217       if(cur)
9218         {
9219           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9220         }
9221       else
9222         {
9223           oss << startLine << "  - not defined !" << std::endl;
9224         }
9225     }
9226   i=0;
9227   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9228     {
9229       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9230       std::string chapter(17,'0'+i);
9231       oss << startLine << chapter << std::endl;
9232       if(cur)
9233         {
9234           cur->simpleRepr(bkOffset+2,oss,i);
9235         }
9236       else
9237         {
9238           oss << startLine << "  - not defined !" << std::endl;
9239         }
9240       oss << startLine << chapter << std::endl;
9241     }
9242   simpleReprGlobs(oss);
9243 }
9244
9245 MEDFileFields::MEDFileFields()
9246 {
9247 }
9248
9249 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9250 try:MEDFileFieldGlobsReal(fid)
9251 {
9252   int nbFields(MEDnField(fid));
9253   _fields.resize(nbFields);
9254   med_field_type typcha;
9255   for(int i=0;i<nbFields;i++)
9256     {
9257       std::vector<std::string> infos;
9258       std::string fieldName,dtunit,meshName;
9259       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit,meshName));
9260       switch(typcha)
9261       {
9262         case MED_FLOAT64:
9263           {
9264             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9265             break;
9266           }
9267         case MED_INT32:
9268           {
9269             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9270             break;
9271           }
9272         case MED_FLOAT32:
9273           {
9274             _fields[i]=MEDFileFloatFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9275             break;
9276           }
9277         default:
9278           {
9279             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] !";
9280             throw INTERP_KERNEL::Exception(oss.str());
9281           }
9282       }
9283     }
9284   loadAllGlobals(fid,entities);
9285 }
9286 catch(INTERP_KERNEL::Exception& e)
9287 {
9288     throw e;
9289 }
9290
9291 void MEDFileFields::writeLL(med_idt fid) const
9292 {
9293   int i=0;
9294   writeGlobals(fid,*this);
9295   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9296     {
9297       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9298       if(!elt)
9299         {
9300           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9301           throw INTERP_KERNEL::Exception(oss.str());
9302         }
9303       elt->writeLL(fid,*this);
9304     }
9305 }
9306
9307 /*!
9308  * This method alloc the arrays and load potentially huge arrays contained in this field.
9309  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9310  * This method can be also called to refresh or reinit values from a file.
9311  * 
9312  * \throw If the fileName is not set or points to a non readable MED file.
9313  */
9314 void MEDFileFields::loadArrays()
9315 {
9316   if(getFileName().empty())
9317     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9318   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9319   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9320     {
9321       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9322       if(elt)
9323         elt->loadBigArraysRecursively(fid,*elt);
9324     }
9325 }
9326
9327 /*!
9328  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9329  * But once data loaded once, this method does nothing.
9330  * 
9331  * \throw If the fileName is not set or points to a non readable MED file.
9332  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9333  */
9334 void MEDFileFields::loadArraysIfNecessary()
9335 {
9336   if(!getFileName().empty())
9337     {
9338       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9339       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9340         {
9341           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9342           if(elt)
9343             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9344         }
9345     }
9346 }
9347
9348 /*!
9349  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9350  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9351  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9352  * 
9353  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9354  */
9355 void MEDFileFields::unloadArrays()
9356 {
9357   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9358     {
9359       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9360       if(elt)
9361         elt->unloadArrays();
9362     }
9363 }
9364
9365 /*!
9366  * 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.
9367  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9368  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9369  * 
9370  * \sa MEDFileFields::loadArraysIfNecessary
9371  */
9372 void MEDFileFields::unloadArraysWithoutDataLoss()
9373 {
9374   if(!getFileName().empty())
9375     unloadArrays();
9376 }
9377
9378 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9379 {
9380   std::vector<std::string> ret;
9381   std::set<std::string> ret2;
9382   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9383     {
9384       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9385       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9386         if(ret2.find(*it2)==ret2.end())
9387           {
9388             ret.push_back(*it2);
9389             ret2.insert(*it2);
9390           }
9391     }
9392   return ret;
9393 }
9394
9395 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9396 {
9397   std::vector<std::string> ret;
9398   std::set<std::string> ret2;
9399   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9400     {
9401       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
9402       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9403         if(ret2.find(*it2)==ret2.end())
9404           {
9405             ret.push_back(*it2);
9406             ret2.insert(*it2);
9407           }
9408     }
9409   return ret;
9410 }
9411
9412 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9413 {
9414   std::vector<std::string> ret;
9415   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9416     {
9417       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
9418       ret.insert(ret.end(),tmp.begin(),tmp.end());
9419     }
9420   return ret;
9421 }
9422
9423 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9424 {
9425   std::vector<std::string> ret;
9426   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9427     {
9428       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
9429       ret.insert(ret.end(),tmp.begin(),tmp.end());
9430     }
9431   return ret;
9432 }
9433
9434 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9435 {
9436   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9437     (*it)->changePflsRefsNamesGen2(mapOfModif);
9438 }
9439
9440 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9441 {
9442   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9443     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9444 }
9445
9446 void MEDFileFields::resize(int newSize)
9447 {
9448   _fields.resize(newSize);
9449 }
9450
9451 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
9452 {
9453   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9454     pushField(*it);
9455 }
9456
9457 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
9458 {
9459   if(!field)
9460     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9461   _fields.push_back(field->getContent());
9462   appendGlobs(*field,1e-12);
9463 }
9464
9465 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
9466 {
9467   if(!field)
9468     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9469   if(i>=(int)_fields.size())
9470     _fields.resize(i+1);
9471   _fields[i]=field->getContent();
9472   appendGlobs(*field,1e-12);
9473 }
9474
9475 void MEDFileFields::destroyFieldAtPos(int i)
9476 {
9477   destroyFieldsAtPos(&i,&i+1);
9478 }
9479
9480 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
9481 {
9482   std::vector<bool> b(_fields.size(),true);
9483   for(const int *i=startIds;i!=endIds;i++)
9484     {
9485       if(*i<0 || *i>=(int)_fields.size())
9486         {
9487           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9488           throw INTERP_KERNEL::Exception(oss.str());
9489         }
9490       b[*i]=false;
9491     }
9492   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9493   std::size_t j=0;
9494   for(std::size_t i=0;i<_fields.size();i++)
9495     if(b[i])
9496       fields[j++]=_fields[i];
9497   _fields=fields;
9498 }
9499
9500 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
9501 {
9502   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9503   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
9504   std::vector<bool> b(_fields.size(),true);
9505   int k=bg;
9506   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9507     {
9508       if(k<0 || k>=(int)_fields.size())
9509         {
9510           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9511           throw INTERP_KERNEL::Exception(oss.str());
9512         }
9513       b[k]=false;
9514     }
9515   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9516   std::size_t j(0);
9517   for(std::size_t i=0;i<_fields.size();i++)
9518     if(b[i])
9519       fields[j++]=_fields[i];
9520   _fields=fields;
9521 }
9522
9523 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9524 {
9525   bool ret(false);
9526   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9527     {
9528       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9529       if(cur)
9530         ret=cur->changeMeshNames(modifTab) || ret;
9531     }
9532   return ret;
9533 }
9534
9535 /*!
9536  * \param [in] meshName the name of the mesh that will be renumbered.
9537  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9538  *             This code corresponds to the distribution of types in the corresponding mesh.
9539  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9540  * \param [in] renumO2N the old to new renumber array.
9541  * \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 
9542  *         field in \a this.
9543  */
9544 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
9545 {
9546   bool ret(false);
9547   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9548     {
9549       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9550       if(fmts)
9551         {
9552           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9553         }
9554     }
9555   return ret;
9556 }
9557
9558 /*!
9559  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9560  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9561  *
9562  * \return A new object that the caller is responsible to deallocate.
9563  */
9564 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9565 {
9566   if(!mm)
9567     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
9568   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
9569   int nbFields(getNumberOfFields());
9570   for(int i=0;i<nbFields;i++)
9571     {
9572       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
9573       if(!fmts)
9574         {
9575           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
9576           throw INTERP_KERNEL::Exception(oss.str());
9577         }
9578       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
9579       fsOut->pushField(fmtsOut);
9580     }
9581   return fsOut.retn();
9582 }
9583
9584 void MEDFileFields::accept(MEDFileFieldVisitor& visitor) const
9585 {
9586   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9587     if((*it).isNotNull())
9588       {
9589         visitor.newFieldEntry(*it);
9590         (*it)->accept(visitor);
9591         visitor.endFieldEntry(*it);
9592       }
9593 }
9594
9595 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
9596 {
9597   if(i<0 || i>=(int)_fields.size())
9598     {
9599       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9600       throw INTERP_KERNEL::Exception(oss.str());
9601     }
9602   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9603   if(!fmts)
9604     return 0;
9605   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
9606   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
9607   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
9608   const MEDFileFloatFieldMultiTSWithoutSDA *fmtsC3(dynamic_cast<const MEDFileFloatFieldMultiTSWithoutSDA *>(fmts));
9609   if(fmtsC)
9610     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9611   else if(fmtsC2)
9612     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9613   else if(fmtsC3)
9614     ret=MEDFileFloatFieldMultiTS::New(*fmtsC3,false);
9615   else
9616     {
9617       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor float (FLOAT32) nor integer (INT32) !";
9618       throw INTERP_KERNEL::Exception(oss.str());
9619     }
9620   ret->shallowCpyGlobs(*this);
9621   return ret.retn();
9622 }
9623
9624 /*!
9625  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9626  * This method is accessible in python using __getitem__ with a list in input.
9627  * \return a new object that the caller should deal with.
9628  */
9629 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
9630 {
9631   MCAuto<MEDFileFields> ret=shallowCpy();
9632   std::size_t sz=std::distance(startIds,endIds);
9633   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9634   int j=0;
9635   for(const int *i=startIds;i!=endIds;i++,j++)
9636     {
9637       if(*i<0 || *i>=(int)_fields.size())
9638         {
9639           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9640           throw INTERP_KERNEL::Exception(oss.str());
9641         }
9642       fields[j]=_fields[*i];
9643     }
9644   ret->_fields=fields;
9645   return ret.retn();
9646 }
9647
9648 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
9649 {
9650   return getFieldAtPos(getPosFromFieldName(fieldName));
9651 }
9652
9653 /*!
9654  * This method removes, if any, fields in \a this having no time steps.
9655  * 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.
9656  * 
9657  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
9658  */
9659 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
9660 {
9661   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
9662   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9663     {
9664       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9665       if(elt)
9666         {
9667           if(elt->getNumberOfTS()>0)
9668             newFields.push_back(*it);
9669         }
9670     }
9671   if(_fields.size()==newFields.size())
9672     return false;
9673   _fields=newFields;
9674   return true;
9675 }
9676
9677 /*!
9678  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9679  * This method can be seen as a filter applied on \a this, that returns an object containing
9680  * 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
9681  * shallow copied from \a this.
9682  * 
9683  * \param [in] meshName - the name of the mesh on w
9684  * \return a new object that the caller should deal with.
9685  */
9686 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
9687 {
9688   MCAuto<MEDFileFields> ret(MEDFileFields::New());
9689   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9690     {
9691       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9692       if(!cur)
9693         continue;
9694       if(cur->getMeshName()==meshName)
9695         {
9696           cur->incrRef();
9697           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9698           ret->_fields.push_back(cur2);
9699         }
9700     }
9701   ret->shallowCpyOnlyUsedGlobs(*this);
9702   return ret.retn();
9703 }
9704
9705 /*!
9706  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9707  * Input time steps are specified using a pair of integer (iteration, order).
9708  * 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,
9709  * but for each multitimestep only the time steps in \a timeSteps are kept.
9710  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9711  * 
9712  * The returned object points to shallow copy of elements in \a this.
9713  * 
9714  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9715  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9716  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9717  */
9718 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
9719 {
9720   MCAuto<MEDFileFields> ret(MEDFileFields::New());
9721   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9722     {
9723       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9724       if(!cur)
9725         continue;
9726       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
9727       ret->_fields.push_back(elt);
9728     }
9729   ret->shallowCpyOnlyUsedGlobs(*this);
9730   return ret.retn();
9731 }
9732
9733 /*!
9734  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
9735  */
9736 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
9737 {
9738   MCAuto<MEDFileFields> ret=MEDFileFields::New();
9739   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9740     {
9741       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9742       if(!cur)
9743         continue;
9744       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
9745       if(elt->getNumberOfTS()!=0)
9746         ret->_fields.push_back(elt);
9747     }
9748   ret->shallowCpyOnlyUsedGlobs(*this);
9749   return ret.retn();
9750 }
9751
9752 bool MEDFileFields::presenceOfStructureElements() const
9753 {
9754   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9755     if((*it).isNotNull())
9756       if((*it)->presenceOfStructureElements())
9757         return true;
9758   return false;
9759 }
9760
9761 void MEDFileFields::killStructureElements()
9762 {
9763   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
9764   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9765     if((*it).isNotNull())
9766       {
9767         if((*it)->presenceOfStructureElements())
9768           {
9769             if(!(*it)->onlyStructureElements())
9770               {
9771                 (*it)->killStructureElements();
9772                 ret.push_back(*it);
9773               }
9774           }
9775         else
9776           {
9777             ret.push_back(*it);
9778           }
9779       }
9780   _fields=ret;
9781 }
9782
9783 void MEDFileFields::keepOnlyStructureElements()
9784 {
9785   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
9786   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9787     if((*it).isNotNull())
9788       {
9789         if((*it)->presenceOfStructureElements())
9790           {
9791             if(!(*it)->onlyStructureElements())
9792               (*it)->keepOnlyStructureElements();
9793             ret.push_back(*it);
9794           }
9795       }
9796   _fields=ret;
9797 }
9798
9799 void MEDFileFields::keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName)
9800 {
9801   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
9802   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9803     if((*it).isNotNull())
9804       {
9805         if((*it)->getMeshName()!=meshName)
9806           continue;
9807         std::vector< std::pair<std::string,std::string> > ps;
9808         (*it)->getMeshSENames(ps);
9809         std::pair<std::string,std::string> p(meshName,seName);
9810         if(std::find(ps.begin(),ps.end(),p)!=ps.end())
9811           (*it)->keepOnlyOnSE(seName);
9812         ret.push_back(*it);
9813       }
9814   _fields=ret;
9815 }
9816
9817 void MEDFileFields::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
9818 {
9819   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9820     if((*it).isNotNull())
9821       (*it)->getMeshSENames(ps);
9822 }
9823
9824 void MEDFileFields::blowUpSE(MEDFileMeshes *ms, const MEDFileStructureElements *ses)
9825 {
9826   MEDFileBlowStrEltUp::DealWithSE(this,ms,ses);
9827 }
9828
9829 MCAuto<MEDFileFields> MEDFileFields::partOfThisOnStructureElements() const
9830 {
9831   MCAuto<MEDFileFields> ret(deepCopy());
9832   ret->keepOnlyStructureElements();
9833   return ret;
9834 }
9835
9836 MCAuto<MEDFileFields> MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const
9837 {
9838   MCAuto<MEDFileFields> ret(deepCopy());
9839   ret->keepOnlyOnMeshSE(meshName,seName);
9840   return ret;
9841 }
9842
9843 void MEDFileFields::aggregate(const MEDFileFields& other)
9844 {
9845   int nbFieldsToAdd(other.getNumberOfFields());
9846   std::vector<std::string> fsn(getFieldsNames());
9847   for(int i=0;i<nbFieldsToAdd;i++)
9848     {
9849       MCAuto<MEDFileAnyTypeFieldMultiTS> elt(other.getFieldAtPos(i));
9850       std::string name(elt->getName());
9851       if(std::find(fsn.begin(),fsn.end(),name)!=fsn.end())
9852         {
9853           std::ostringstream oss; oss << "MEDFileFields::aggregate : name \"" << name << "\" already appears !";
9854           throw INTERP_KERNEL::Exception(oss.str());
9855         }
9856       pushField(elt);
9857     }
9858 }
9859
9860 MEDFileFieldsIterator *MEDFileFields::iterator()
9861 {
9862   return new MEDFileFieldsIterator(this);
9863 }
9864
9865 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
9866 {
9867   std::string tmp(fieldName);
9868   std::vector<std::string> poss;
9869   for(std::size_t i=0;i<_fields.size();i++)
9870     {
9871       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
9872       if(f)
9873         {
9874           std::string fname(f->getName());
9875           if(tmp==fname)
9876             return i;
9877           else
9878             poss.push_back(fname);
9879         }
9880     }
9881   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
9882   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
9883   oss << " !";
9884   throw INTERP_KERNEL::Exception(oss.str());
9885 }
9886
9887 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
9888 {
9889   if(fs)
9890     {
9891       fs->incrRef();
9892       _nb_iter=fs->getNumberOfFields();
9893     }
9894 }
9895
9896 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
9897 {
9898 }
9899
9900 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
9901 {
9902   if(_iter_id<_nb_iter)
9903     {
9904       MEDFileFields *fs(_fs);
9905       if(fs)
9906         return fs->getFieldAtPos(_iter_id++);
9907       else
9908         return 0;
9909     }
9910   else
9911     return 0;
9912 }