Salome HOME
MeshName is also stored in MEDFileFieldMultiTS now. Add it into ref.
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.txx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDLoaderTraits.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileFieldOverView.hxx"
27 #include "MEDFileBlowStrEltUp.hxx"
28 #include "MEDFileFieldVisitor.hxx"
29
30 #include "MEDCouplingFieldDouble.hxx"
31 #include "MEDCouplingFieldTemplate.hxx"
32 #include "MEDCouplingFieldDiscretization.hxx"
33
34 #include "InterpKernelAutoPtr.hxx"
35 #include "CellModel.hxx"
36
37 #include <algorithm>
38 #include <iterator>
39
40 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
41 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
42 extern med_geometry_type typmainoeud[1];
43 extern med_geometry_type typmai3[34];
44
45 using namespace MEDCoupling;
46
47 template class MEDFileField1TSTemplateWithoutSDA<int>;
48 template class MEDFileField1TSTemplateWithoutSDA<double>;
49
50 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
51 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
52
53 MEDFileGTKeeper::~MEDFileGTKeeper()
54 {
55 }
56
57 MEDFileGTKeeper *MEDFileGTKeeperSta::deepCopy() const
58 {
59   return new MEDFileGTKeeperSta(_geo_type);
60 }
61
62 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperSta::getGeoType() const
63 {
64   return _geo_type;
65 }
66
67 std::string MEDFileGTKeeperSta::getRepr() const
68 {
69   return INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr();
70 }
71
72 bool MEDFileGTKeeperSta::isEqual(const MEDFileGTKeeper *other) const
73 {
74   const MEDFileGTKeeperSta *otherC(dynamic_cast<const MEDFileGTKeeperSta *>(other));
75   if(!otherC)
76     return false;
77   return _geo_type==otherC->_geo_type;
78 }
79
80 MEDFileGTKeeperDyn::MEDFileGTKeeperDyn(const MEDFileUMesh *mesh, const MEDFileUMesh *section, const MEDFileStructureElement *se):_mesh(mesh),_section(section),_se(se)
81 {
82   if(mesh)
83     mesh->incrRef();
84   if(section)
85     section->incrRef();
86   if(se)
87     se->incrRef();
88   if(_mesh.isNull() || _section.isNull() || _se.isNull())
89     throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn constructor : null pointer not allowed !");
90 }
91
92 MEDFileGTKeeper *MEDFileGTKeeperDyn::deepCopy() const
93 {
94   return new MEDFileGTKeeperDyn(_mesh,_section,_se);
95 }
96
97 INTERP_KERNEL::NormalizedCellType MEDFileGTKeeperDyn::getGeoType() const
98 {
99   throw INTERP_KERNEL::Exception("MEDFileGTKeeperDyn::getGeoType : not valid !");
100 }
101
102 std::string MEDFileGTKeeperDyn::getRepr() const
103 {
104   std::ostringstream oss;
105   oss << _se->getDynGT();
106   return oss.str();
107 }
108
109 bool MEDFileGTKeeperDyn::isEqual(const MEDFileGTKeeper *other) const
110 {
111   const MEDFileGTKeeperDyn *otherC(dynamic_cast<const MEDFileGTKeeperDyn *>(other));
112   if(!otherC)
113     return false;
114   return this==otherC;
115 }
116
117 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
118 {
119   return new MEDFileFieldLoc(fid,locName);
120 }
121
122 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id, const MEDFileEntities *entities)
123 {
124   return new MEDFileFieldLoc(fid,id,entities);
125 }
126
127 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
128 {
129   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
130 }
131
132 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
133 {
134   med_geometry_type geotype;
135   med_geometry_type sectiongeotype;
136   int nsectionmeshcell;
137   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
138   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
139   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
140   _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
141   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
142   _nb_node_per_cell=cm.getNumberOfNodes();
143   _ref_coo.resize(_dim*_nb_node_per_cell);
144   _gs_coo.resize(_dim*_nb_gauss_pt);
145   _w.resize(_nb_gauss_pt);
146   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
147 }
148
149 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id, const MEDFileEntities *entities)
150 {
151   med_geometry_type geotype;
152   med_geometry_type sectiongeotype;
153   int nsectionmeshcell;
154   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
155   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
156   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
157   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
158   _name=locName;
159   std::string sectionName(MEDLoaderBase::buildStringFromFortran(sectionmeshname,MED_NAME_SIZE));
160   if(sectionName.empty())
161     {
162       _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
163       const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
164       _nb_node_per_cell=cm.getNumberOfNodes();
165     }
166   else
167     {
168       const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
169       if(!entities2)
170         {
171           std::ostringstream oss; oss << "MEDFileFieldLoc cstr : for loc \"" << _name << "\" presence of non static type ! Expect entities !";
172           throw INTERP_KERNEL::Exception(oss.str());
173         }
174       const MEDFileStructureElement *se(entities2->getWithGT(geotype));
175       const MEDFileUMesh *um(entities2->getSupMeshWithName(se->getMeshName()));
176       const MEDFileUMesh *section(entities2->getSupMeshWithName(sectionName));
177       _gt=new MEDFileGTKeeperDyn(um,section,se);
178       {
179         int dummy;
180         MEDFILESAFECALLERWR0(MEDmeshGeotypeParameter,(fid,geotype,&dummy,&_nb_node_per_cell));
181       }
182     }
183   _ref_coo.resize(_dim*_nb_node_per_cell);
184   _gs_coo.resize(_dim*_nb_gauss_pt);
185   _w.resize(_nb_gauss_pt);
186   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
187 }
188
189 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
190                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_gt(new MEDFileGTKeeperSta(geoType)),_ref_coo(refCoo),_gs_coo(gsCoo),_w(w)
191 {
192   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
193   _dim=cm.getDimension();
194   _nb_node_per_cell=cm.getNumberOfNodes();
195   _nb_gauss_pt=_w.size();
196 }
197
198
199 MEDFileFieldLoc::MEDFileFieldLoc(const MEDFileFieldLoc& other):_dim(other._dim),_nb_gauss_pt(other._nb_gauss_pt),_gt(other._gt->deepCopy()),_nb_node_per_cell(other._nb_node_per_cell),_name(other._name),_ref_coo(other._ref_coo),_gs_coo(other._gs_coo),_w(other._w)
200 {
201 }
202
203 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
204 {
205   return new MEDFileFieldLoc(*this);
206 }
207
208 bool MEDFileFieldLoc::isOnStructureElement() const
209 {
210   const MEDFileGTKeeper *gt(_gt);
211   if(!gt)
212     throw INTERP_KERNEL::Exception("MEDFileFieldLoc::isOnStructureElement : null pointer !");
213   const MEDFileGTKeeperDyn *gt2(dynamic_cast<const MEDFileGTKeeperDyn *>(gt));
214   return gt2!=NULL;
215 }
216
217 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
218 {
219   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
220 }
221
222 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
223 {
224   return std::vector<const BigMemoryObject *>();
225 }
226
227 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
228 {
229   static const char OFF7[]="\n    ";
230   oss << "\"" << _name << "\"" << OFF7;
231   oss << "GeoType=" << _gt->getRepr() << OFF7;
232   oss << "Dimension=" << _dim << OFF7;
233   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
234   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
235   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
236   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
237   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
238 }
239
240 void MEDFileFieldLoc::setName(const std::string& name)
241 {
242   _name=name;
243 }
244
245 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
246 {
247   if(_name!=other._name)
248     return false;
249   if(_dim!=other._dim)
250     return false;
251   if(_nb_gauss_pt!=other._nb_gauss_pt)
252     return false;
253   if(_nb_node_per_cell!=other._nb_node_per_cell)
254     return false;
255   if(!_gt->isEqual(other._gt))
256     return false;
257   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
258     return false;
259   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
260     return false;
261   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
262     return false;
263
264   return true;
265 }
266
267 void MEDFileFieldLoc::writeLL(med_idt fid) const
268 {
269   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)getGeoType()],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
270 }
271
272 std::string MEDFileFieldLoc::repr() const
273 {
274   std::ostringstream oss; oss.precision(15);
275   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
276   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
277   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
278   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
279   oss << "\n  - Ref coords are : ";
280   int sz=_ref_coo.size();
281   if(sz%_dim==0)
282     {
283       int nbOfTuples=sz/_dim;
284       for(int i=0;i<nbOfTuples;i++)
285         {
286           oss << "(";
287           for(int j=0;j<_dim;j++)
288             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
289           oss << ") ";
290         }
291     }
292   else
293     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
294   oss << "\n  - Gauss coords in reference element : ";
295   sz=_gs_coo.size();
296   if(sz%_dim==0)
297     {
298       int nbOfTuples=sz/_dim;
299       for(int i=0;i<nbOfTuples;i++)
300         {
301           oss << "(";
302           for(int j=0;j<_dim;j++)
303             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
304           oss << ") ";
305         }
306     }
307   else
308     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
309   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
310   return oss.str();
311 }
312
313 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
314 {
315   _type=field->getTypeOfField();
316   _start=start;
317   switch(_type)
318   {
319     case ON_CELLS:
320       {
321         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
322         _end=_start+nbOfCells;
323         _nval=nbOfCells;
324         break;
325       }
326     case ON_GAUSS_NE:
327       {
328         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
329         const int *arrPtr=arr->getConstPointer();
330         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
331         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
332         _nval=nbOfCells;
333         break;
334       }
335     case ON_GAUSS_PT:
336       {
337         const MEDCouplingFieldDiscretization *disc(field->getDiscretization());
338         const MEDCouplingGaussLocalization& gsLoc(field->getGaussLocalization(_loc_id));
339         const MEDCouplingFieldDiscretizationGauss *disc2(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc));
340         if(!disc2)
341           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
342         const DataArrayInt *dai(disc2->getArrayOfDiscIds());
343         MCAuto<DataArrayInt> dai2(disc2->getOffsetArr(field->getMesh()));
344         const int *dai2Ptr(dai2->getConstPointer());
345         int nbi(gsLoc.getWeights().size());
346         MCAuto<DataArrayInt> da2(dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1));
347         MCAuto<DataArrayInt> da3(da2->findIdsEqual(_loc_id));
348         const int *da3Ptr(da3->getConstPointer());
349         if(da3->getNumberOfTuples()!=nbOfCells)
350           {//profile : for gauss even in NoProfile !!!
351             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
352             _profile=oss.str();
353             da3->setName(_profile.c_str());
354             glob.appendProfile(da3);
355           }
356         MCAuto<DataArrayInt> da4(DataArrayInt::New());
357         _nval=da3->getNbOfElems();
358         da4->alloc(_nval*nbi,1);
359         int *da4Ptr(da4->getPointer());
360         for(int i=0;i<_nval;i++)
361           {
362             int ref=dai2Ptr[offset+da3Ptr[i]];
363             for(int j=0;j<nbi;j++)
364               *da4Ptr++=ref+j;
365           }
366         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
367         _localization=oss2.str();
368         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
369         _end=_start+_nval*nbi;
370         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
371         break;
372       }
373     default:
374       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
375   }
376   start=_end;
377 }
378
379 /*!
380  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
381  * \param [in] pflName input containing name of profile if any. 0 if no profile (except for GAUSS_PT where a no profile can hide a profile when splitted by loc_id).
382  * \param [in] multiTypePfl is the end user profile specified in high level API
383  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
384  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
385  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
386  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
387  */
388 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
389 {
390   _profile.clear();
391   _type=field->getTypeOfField();
392   std::string pflName(multiTypePfl->getName());
393   std::ostringstream oss; oss << pflName;
394   if(_type!=ON_NODES)
395     {
396       if(!isPflAlone)
397         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
398     }
399   else
400     { oss << "_NODE"; }
401   if(locIds)
402     {
403       if(pflName.empty())
404         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
405       if(_type!=ON_GAUSS_PT)
406         {
407           locIds->setName(oss.str());
408           glob.appendProfile(locIds);
409           _profile=oss.str();
410         }
411     }
412   _start=start;
413   switch(_type)
414   {
415     case ON_NODES:
416       {
417         _nval=idsInPfl->getNumberOfTuples();
418         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
419         _end=_start+_nval;
420         break;
421       }
422     case ON_CELLS:
423       {
424         _nval=idsInPfl->getNumberOfTuples();
425         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
426         _end=_start+_nval;
427         break;
428       }
429     case ON_GAUSS_NE:
430       {
431         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
432         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
433         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
434         arr3->computeOffsetsFull();
435         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
436         int trueNval=tmp->getNumberOfTuples();
437         _nval=idsInPfl->getNumberOfTuples();
438         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
439         _end=_start+trueNval;
440         break;
441       }
442     case ON_GAUSS_PT:
443       {
444         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
445         if(!disc2)
446           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
447         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
448         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
449         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
450         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
451         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
452         //
453         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
454         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
455         //
456         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
457         int trueNval=0;
458         for(const int *pt=da4->begin();pt!=da4->end();pt++)
459           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
460         tmp->alloc(trueNval,1);
461         int *tmpPtr=tmp->getPointer();
462         for(const int *pt=da4->begin();pt!=da4->end();pt++)
463           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
464             *tmpPtr++=j;
465         //
466         _nval=da4->getNumberOfTuples();
467         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
468         _end=_start+trueNval;
469         oss << "_loc_" << _loc_id;
470         if(locIds)
471           {
472             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
473             da5->setName(oss.str());
474             glob.appendProfile(da5);
475             _profile=oss.str();
476           }
477         else
478           {
479             if(!da3->isIota(nbOfEltsInWholeMesh))
480               {
481                 da3->setName(oss.str());
482                 glob.appendProfile(da3);
483                 _profile=oss.str();
484               }
485           }
486         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
487         _localization=oss2.str();
488         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
489         break;
490       }
491     default:
492       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
493   }
494   start=_end;
495 }
496
497 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
498 {
499   _start=start;
500   _nval=arrr->getNumberOfTuples();
501   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
502   _end=_start+_nval;
503   start=_end;
504 }
505
506 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
507 {
508   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
509 }
510
511 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId)
512 {
513   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
514 }
515
516 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
517 {
518   return new MEDFileFieldPerMeshPerTypePerDisc(other);
519 }
520
521 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
522 {
523   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
524 }
525
526 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
527 {
528   std::vector<const BigMemoryObject *> ret(1);
529   ret[0]=(const PartDefinition*)_pd;
530   return ret;
531 }
532
533 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const
534 {
535   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(*this));
536   ret->_father=father;
537   return ret.retn();
538 }
539
540 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
541 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
542 {
543   if(pd)
544     pd->incrRef();
545 }
546 catch(INTERP_KERNEL::Exception& e)
547 {
548     throw e;
549 }
550
551 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
552 {
553 }
554
555 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_profile_it(other._profile_it),_pd(other._pd),_tmp_work1(other._tmp_work1)
556 {
557 }
558
559 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
560     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
561 {
562 }
563
564 void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const std::string& fieldName, int nbOfCompo, int iteration, int order, med_entity_type menti, med_geometry_type mgeoti, unsigned char *startFeedingPtr)
565 {
566   const PartDefinition *pd(_pd);
567   if(!pd)
568     {
569       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
570       int nbi,tmp1;
571       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
572       if(_end-_start!=nbValsInFile*nbi)
573         {
574           std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
575           throw INTERP_KERNEL::Exception(oss.str());
576         }
577       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
578     }
579   else
580     {
581       if(!_profile.empty())
582         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
583       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
584       int profilesize,nbi;
585       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
586       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
587       if(spd)
588         {
589           int start,stop,step;
590           spd->getSlice(start,stop,step);
591           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
592           med_filter filter=MED_FILTER_INIT;
593           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
594                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
595                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
596                                    /*lastblocksize=useless because count=1*/0,&filter);
597           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
598           MEDfilterClose(&filter);
599           return ;
600         }
601       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
602       if(dpd)
603         {
604           dpd->checkConsistencyLight();
605           MCAuto<DataArrayInt> myIds(dpd->toDAI());
606           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
607           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
608           myIds->applyLin(1,-a);
609           int nbOfEltsToLoad(b-a+1);
610           med_filter filter=MED_FILTER_INIT;
611           {//TODO : manage int32 !
612             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
613             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
614             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
615                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
616                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
617                                      /*lastblocksize=useless because count=1*/0,&filter);
618             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
619             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
620             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
621             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
622           }
623           MEDfilterClose(&filter);
624         }
625       else
626         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
627     }
628 }
629
630 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
631 {
632   return _father;
633 }
634
635 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
636 {
637   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
638   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
639   std::string fieldName(nasc.getName()),meshName(getMeshName());
640   int iteration(getIteration()),order(getOrder()),profilesize,nbi;
641   TypeOfField type(getType());
642   med_geometry_type mgeoti;
643   med_entity_type menti;
644   _father->entriesForMEDfile(type,mgeoti,menti);
645   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
646   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
647   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
648   const PartDefinition *pd(_pd);
649   if(!pd)
650     {
651       _nval=zeNVal;
652     }
653   else
654     {
655       if(!_profile.empty())
656         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
657       _nval=pd->getNumberOfElems();
658     }
659   _start=start;
660   _end=start+_nval*nbi;
661   start=_end;
662   if(type==ON_CELLS && !_localization.empty())
663     {
664       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
665         setType(ON_GAUSS_PT);
666       else
667         {
668           setType(ON_GAUSS_NE);
669           _localization.clear();
670         }
671     }
672 }
673
674 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
675 {
676   std::string fieldName(nasc.getName()),meshName(getMeshName());
677   int iteration(getIteration()),order(getOrder());
678   TypeOfField type(getType());
679   med_geometry_type mgeoti;
680   med_entity_type menti;
681   _father->entriesForMEDfile(type,mgeoti,menti);
682   if(_start>_end)
683     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
684   if(_start==_end)
685     return ;
686   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
687   if(_start<0 || _start>=arr->getNumberOfTuples())
688     {
689       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
690       throw INTERP_KERNEL::Exception(oss.str());
691     }
692   if(_end<0 || _end>arr->getNumberOfTuples())
693     {
694       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
695       throw INTERP_KERNEL::Exception(oss.str());
696     }
697   int nbOfCompo(arr->getNumberOfComponents());
698   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
699   if(arrD)
700     {
701       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
702       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
703       return ;
704     }
705   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
706   if(arrI)
707     {
708       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
709       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
710       return ;
711     }
712   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
713 }
714
715 /*!
716  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
717  */
718 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
719 {
720   int delta=_end-_start;
721   _start=newValueOfStart;
722   _end=_start+delta;
723 }
724
725 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
726 {
727   return _father->getIteration();
728 }
729
730 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
731 {
732   return _father->getOrder();
733 }
734
735 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
736 {
737   return _father->getTime();
738 }
739
740 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
741 {
742   return _father->getMeshName();
743 }
744
745 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
746 {
747   const char startLine[]="    ## ";
748   std::string startLine2(bkOffset,' ');
749   startLine2+=startLine;
750   INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
751   oss << startLine2 << "Localization #" << id << "." << std::endl;
752   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
753   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
754   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
755   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
756 }
757
758 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
759 {
760   return _type;
761 }
762
763 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
764 {
765   return _father->getGeoType();
766 }
767
768 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
769 {
770   types.insert(_type);
771 }
772
773 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
774 {
775   _type=newType;
776 }
777
778 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
779 {
780   return _father->getNumberOfComponents();
781 }
782
783 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
784 {
785   return _end-_start;
786 }
787
788 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
789 {
790   return _father->getOrCreateAndGetArray();
791 }
792
793 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
794 {
795   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
796   return fath->getOrCreateAndGetArray();
797 }
798
799 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
800 {
801   return _father->getInfo();
802 }
803
804 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
805 {
806   return _profile;
807 }
808
809 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
810 {
811   _profile=newPflName;
812 }
813
814 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
815 {
816   return _localization;
817 }
818
819 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
820 {
821   _localization=newLocName;
822 }
823
824 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
825 {
826   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
827     {
828       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
829         {
830           _profile=(*it2).second;
831           return;
832         }
833     }
834 }
835
836 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
837 {
838   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
839     {
840       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
841         {
842           _localization=(*it2).second;
843           return;
844         }
845     }
846 }
847
848 void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
849 {
850   if(type!=_type)
851     return ;
852   dads.push_back(std::pair<int,int>(_start,_end));
853   geoTypes.push_back(getGeoType());
854   if(_profile.empty())
855     pfls.push_back(0);
856   else
857     {
858       pfls.push_back(glob->getProfile(_profile.c_str()));
859     }
860   if(_localization.empty())
861     locs.push_back(-1);
862   else
863     {
864       locs.push_back(glob->getLocalizationId(_localization.c_str()));
865     }
866 }
867
868 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
869 {
870   entries[startEntryId]=std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int> ,std::pair<int,int> >(std::pair<INTERP_KERNEL::NormalizedCellType,int>(getGeoType(),discId),std::pair<int,int>(_start,_end));
871   startEntryId++;
872 }
873
874 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
875 {
876   TypeOfField type=getType();
877   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
878   med_geometry_type mgeoti;
879   med_entity_type menti;
880   _father->entriesForMEDfile(getType(),mgeoti,menti);
881   const DataArray *arr(getOrCreateAndGetArray());
882   if(!arr)
883     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
884   if(!arr->isAllocated())
885     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
886   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
887   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
888   const unsigned char *locToWrite=0;
889   if(arrD)
890     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
891   else if(arrI)
892     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
893   else
894     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
895   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
896                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
897                                                    locToWrite));
898 }
899
900 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
901 {
902   type=_type;
903   pfl=_profile;
904   loc=_localization;
905   dad.first=_start; dad.second=_end;
906 }
907
908 /*!
909  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
910  *             This code corresponds to the distribution of types in the corresponding mesh.
911  * \param [out] ptToFill memory zone where the output will be stored.
912  * \return the size of data pushed into output param \a ptToFill
913  */
914 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
915 {
916   _loc_id=offset;
917   std::ostringstream oss;
918   std::size_t nbOfType=codeOfMesh.size()/3;
919   int found=-1;
920   for(std::size_t i=0;i<nbOfType && found==-1;i++)
921     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
922       found=(int)i;
923   if(found==-1)
924     {
925       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
926       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
927       throw INTERP_KERNEL::Exception(oss.str());
928     }
929   int *work=ptToFill;
930   if(_profile.empty())
931     {
932       if(_nval!=codeOfMesh[3*found+1])
933         {
934           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
935           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
936           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
937           throw INTERP_KERNEL::Exception(oss.str());
938         }
939       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
940         *work++=ii;
941     }
942   else
943     {
944       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
945       if(pfl->getNumberOfTuples()!=_nval)
946         {
947           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
948           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
949           oss << _nval;
950           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
951           throw INTERP_KERNEL::Exception(oss.str());
952         }
953       int offset2=codeOfMesh[3*found+2];
954       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
955         {
956           if(*pflId<codeOfMesh[3*found+1])
957             *work++=offset2+*pflId;
958         }
959     }
960   return _nval;
961 }
962
963 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
964 {
965   for(int i=_start;i<_end;i++)
966     *ptToFill++=i;
967   return _end-_start;
968 }
969
970 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
971 {
972   switch(type)
973   {
974     case ON_CELLS:
975       return -2;
976     case ON_GAUSS_NE:
977       return -1;
978     case ON_GAUSS_PT:
979       return locId;
980     default:
981       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
982   }
983 }
984
985 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
986 {
987   int id=0;
988   std::map<std::pair<std::string,TypeOfField>,int> m;
989   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
990   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
991     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
992       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
993   ret.resize(id);
994   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
995     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
996   return ret;
997 }
998
999 /*!
1000  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
1001  * 
1002  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
1003  * \param [in] entriesOnSameDisc some entries **on same localization** if not the result can be invalid. The _start and _end on them are relative to \a arr parameter.
1004  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
1005  * \param [in] newCode one of the input parameter to explicit the new geo type dispatch (in classical format same than those asked by MEDFileFields::renumberEntitiesLyingOnMesh)
1006  * \param [in,out] glob if necessary by the method, new profiles can be added to it
1007  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
1008  * \param [out] result All new entries will be appended on it.
1009  * \return false if the configuration of renumbering leads to an unnecessary resplit of input \a entriesOnSameDisc. If not true is returned (the most general case !)
1010  */
1011 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1012                                                        const DataArrayInt *explicitIdsInMesh,
1013                                                        const std::vector<int>& newCode,
1014                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
1015                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
1016 {
1017   if(entriesOnSameDisc.empty())
1018     return false;
1019   TypeOfField type=entriesOnSameDisc[0]->getType();
1020   int szEntities=0,szTuples=0;
1021   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
1022     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
1023   int nbi=szTuples/szEntities;
1024   if(szTuples%szEntities!=0)
1025     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
1026   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
1027   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
1028   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
1029   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
1030   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
1031   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
1032   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
1033   int id=0;
1034   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
1035     {
1036       int startOfEltIdOfChunk=(*it)->_start;
1037       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
1038       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
1039       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
1040       //
1041       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
1042       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
1043       //
1044       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
1045       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
1046     }
1047   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
1048   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
1049   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
1050   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
1051   //
1052   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
1053   //
1054   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
1055   arrPart->renumberInPlace(renumTupleIds->begin());
1056   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
1057   bool ret=false;
1058   const int *idIt=diffVals->begin();
1059   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
1060   int offset2=0;
1061   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
1062     {
1063       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
1064       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
1065       int nbEntityElts=subIds->getNumberOfTuples();
1066       bool ret2;
1067       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
1068           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
1069                                       offset+offset2,
1070                                       li,glob,ret2);
1071       ret=ret || ret2;
1072       result.push_back(eltToAdd);
1073       offset2+=nbEntityElts*nbi;
1074     }
1075   ret=ret || li.empty();
1076   return ret;
1077 }
1078
1079 /*!
1080  * \param [in] typeF type of field of new chunk
1081  * \param [in] geoType the geometric type of the chunk
1082  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
1083  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
1084  * \param [in] nbi number of integration points
1085  * \param [in] offset The offset in the **global array of data**.
1086  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
1087  *                 to the new chunk to create.
1088  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
1089  * \param [out] notInExisting If false the return newly allocated entry is not coming from \a entriesOnSameDisc. If true the output comes from copy of \a entriesOnSameDisc
1090  *              and corresponding entry erased from \a entriesOnSameDisc.
1091  * \return a newly allocated chunk
1092  */
1093 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
1094                                                                                                   bool isPfl, int nbi, int offset,
1095                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
1096                                                                                                   MEDFileFieldGlobsReal& glob,
1097                                                                                                   bool &notInExisting)
1098 {
1099   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1100   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1101   for(;it!=entriesOnSameDisc.end();it++)
1102     {
1103       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1104         {
1105           if(!isPfl)
1106             {
1107               if((*it)->_profile.empty())
1108                 break;
1109               else
1110                 if(!(*it)->_profile.empty())
1111                   {
1112                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1113                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1114                       break;
1115                   }
1116             }
1117         }
1118     }
1119   if(it==entriesOnSameDisc.end())
1120     {
1121       notInExisting=true;
1122       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1123       ret->_type=typeF;
1124       ret->_loc_id=(int)geoType;
1125       ret->_nval=nbMeshEntities;
1126       ret->_start=offset;
1127       ret->_end=ret->_start+ret->_nval*nbi;
1128       if(isPfl)
1129         {
1130           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1131           glob.appendProfile(idsOfMeshElt);
1132           ret->_profile=idsOfMeshElt->getName();
1133         }
1134       //tony treatment of localization
1135       return ret;
1136     }
1137   else
1138     {
1139       notInExisting=false;
1140       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1141       ret->_loc_id=(int)geoType;
1142       ret->setNewStart(offset);
1143       entriesOnSameDisc.erase(it);
1144       return ret;
1145     }
1146
1147 }
1148
1149 ////////////////////////////////////
1150
1151 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1152 {
1153 }
1154
1155 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1156 {
1157   _father=father;
1158 }
1159
1160 void MEDFileFieldPerMeshPerTypeCommon::accept(MEDFileFieldVisitor& visitor) const
1161 {
1162   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1163     if((*it).isNotNull())
1164       {
1165         visitor.newPerMeshPerTypePerDisc(*it);
1166       }
1167 }
1168
1169 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1170 {
1171   std::size_t i=0;
1172   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1173     {
1174       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1175         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1176     }
1177 }
1178
1179 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1180 {
1181   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1182 }
1183
1184 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1185 {
1186   std::vector<const BigMemoryObject *> ret;
1187   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1188     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1189   return ret;
1190 }
1191
1192 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1193 {
1194   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1195   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1196     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1197 }
1198
1199 /*!
1200  * This method is the most general one. No optimization is done here.
1201  * \param [in] multiTypePfl is the end user profile specified in high level API
1202  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1203  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
1204  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1205  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1206  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
1207  */
1208 void MEDFileFieldPerMeshPerTypeCommon::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1209 {
1210   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1211   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1212     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1213 }
1214
1215 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1216 {
1217   _field_pm_pt_pd.resize(1);
1218   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1219   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1220 }
1221
1222 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1223 {
1224   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1225   if(!arr || !arr->isAllocated())
1226     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1227   _field_pm_pt_pd.resize(1);
1228   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1229   _field_pm_pt_pd[0]->assignFieldProfile(true,start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1230 }
1231
1232 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1233 {
1234   TypeOfField type=field->getTypeOfField();
1235   if(type!=ON_GAUSS_PT)
1236     {
1237       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1238       int sz=_field_pm_pt_pd.size();
1239       bool found=false;
1240       for(int j=0;j<sz && !found;j++)
1241         {
1242           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1243             {
1244               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1245               found=true;
1246             }
1247         }
1248       if(!found)
1249         {
1250           _field_pm_pt_pd.resize(sz+1);
1251           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1252         }
1253       std::vector<int> ret(1,(int)sz);
1254       return ret;
1255     }
1256   else
1257     {
1258       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1259       int sz2=ret2.size();
1260       std::vector<int> ret3(sz2);
1261       int k=0;
1262       for(int i=0;i<sz2;i++)
1263         {
1264           int sz=_field_pm_pt_pd.size();
1265           int locIdToFind=ret2[i];
1266           bool found=false;
1267           for(int j=0;j<sz && !found;j++)
1268             {
1269               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1270                 {
1271                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1272                   ret3[k++]=j;
1273                   found=true;
1274                 }
1275             }
1276           if(!found)
1277             {
1278               _field_pm_pt_pd.resize(sz+1);
1279               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1280               ret3[k++]=sz;
1281             }
1282         }
1283       return ret3;
1284     }
1285 }
1286
1287 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1288 {
1289   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1290   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1291   if(!disc2)
1292     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1293   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1294   if(!da)
1295     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1296   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1297   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1298   if(retTmp->presenceOfValue(-1))
1299     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1300   std::vector<int> ret(retTmp->begin(),retTmp->end());
1301   return ret;
1302 }
1303
1304 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1305 {
1306   TypeOfField type=field->getTypeOfField();
1307   if(type!=ON_GAUSS_PT)
1308     {
1309       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1310       int sz=_field_pm_pt_pd.size();
1311       bool found=false;
1312       for(int j=0;j<sz && !found;j++)
1313         {
1314           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1315             {
1316               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1317               found=true;
1318             }
1319         }
1320       if(!found)
1321         {
1322           _field_pm_pt_pd.resize(sz+1);
1323           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1324         }
1325       std::vector<int> ret(1,0);
1326       return ret;
1327     }
1328   else
1329     {
1330       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1331       int sz2=ret2.size();
1332       std::vector<int> ret3(sz2);
1333       int k=0;
1334       for(int i=0;i<sz2;i++)
1335         {
1336           int sz=_field_pm_pt_pd.size();
1337           int locIdToFind=ret2[i];
1338           bool found=false;
1339           for(int j=0;j<sz && !found;j++)
1340             {
1341               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1342                 {
1343                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1344                   ret3[k++]=j;
1345                   found=true;
1346                 }
1347             }
1348           if(!found)
1349             {
1350               _field_pm_pt_pd.resize(sz+1);
1351               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1352               ret3[k++]=sz;
1353             }
1354         }
1355       return ret3;
1356     }
1357 }
1358
1359 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1360 {
1361   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1362   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1363   if(!disc2)
1364     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1365   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1366   if(!da)
1367     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1368   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1369   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1370   if(retTmp->presenceOfValue(-1))
1371     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1372   std::vector<int> ret(retTmp->begin(),retTmp->end());
1373   return ret;
1374 }
1375
1376 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1377 {
1378   return _father;
1379 }
1380
1381 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1382 {
1383   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1384   int curDim((int)cm.getDimension());
1385   if(dim!=std::numeric_limits<int>::max())
1386     {
1387       if(dim!=curDim)
1388         return false;
1389     }
1390   else
1391     dim=curDim;
1392   return true;
1393 }
1394
1395 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1396 {
1397   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1398     {
1399       (*it)->fillTypesOfFieldAvailable(types);
1400     }
1401 }
1402
1403 void MEDFileFieldPerMeshPerTypeCommon::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1404 {
1405   int sz=_field_pm_pt_pd.size();
1406   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1407   for(int i=0;i<sz;i++)
1408     {
1409       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1410     }
1411 }
1412
1413 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1414 {
1415   return _father->getIteration();
1416 }
1417
1418 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1419 {
1420   return _father->getOrder();
1421 }
1422
1423 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1424 {
1425   return _father->getTime();
1426 }
1427
1428 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1429 {
1430   return _father->getMeshName();
1431 }
1432
1433 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1434 {
1435   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1436     {
1437       globalSz+=(*it)->getNumberOfTuples();
1438     }
1439   nbOfEntries+=(int)_field_pm_pt_pd.size();
1440 }
1441
1442 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1443 {
1444   return _father->getNumberOfComponents();
1445 }
1446
1447 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1448 {
1449   std::size_t nb(0);
1450   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1451     {
1452       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1453       if(fmtd)
1454         nb++;
1455     }
1456   return nb>1;
1457 }
1458
1459 void MEDFileFieldPerMeshPerTypeCommon::pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc)
1460 {
1461   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt;
1462   elt.takeRef(disc);
1463   _field_pm_pt_pd.push_back(elt);
1464 }
1465
1466 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1467 {
1468   return _father->getOrCreateAndGetArray();
1469 }
1470
1471 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1472 {
1473   const MEDFileFieldPerMesh *fath=_father;
1474   return fath->getOrCreateAndGetArray();
1475 }
1476
1477 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1478 {
1479   return _father->getInfo();
1480 }
1481
1482 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1483 {
1484   std::vector<std::string> ret;
1485   std::set<std::string> ret2;
1486   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1487     {
1488       std::string tmp=(*it1)->getProfile();
1489       if(!tmp.empty())
1490         if(ret2.find(tmp)==ret2.end())
1491           {
1492             ret.push_back(tmp);
1493             ret2.insert(tmp);
1494           }
1495     }
1496   return ret;
1497 }
1498
1499 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1500 {
1501   std::vector<std::string> ret;
1502   std::set<std::string> ret2;
1503   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1504     {
1505       std::string tmp=(*it1)->getLocalization();
1506       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1507         if(ret2.find(tmp)==ret2.end())
1508           {
1509             ret.push_back(tmp);
1510             ret2.insert(tmp);
1511           }
1512     }
1513   return ret;
1514 }
1515
1516 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1517 {
1518   std::vector<std::string> ret;
1519   std::set<std::string> ret2;
1520   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1521     {
1522       std::string tmp=(*it1)->getProfile();
1523       if(!tmp.empty())
1524         ret.push_back(tmp);
1525     }
1526   return ret;
1527 }
1528
1529 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1530 {
1531   std::vector<std::string> ret;
1532   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1533     {
1534       std::string tmp=(*it1)->getLocalization();
1535       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1536         ret.push_back(tmp);
1537     }
1538   return ret;
1539 }
1540
1541 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1542 {
1543   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1544     (*it1)->changePflsRefsNamesGen(mapOfModif);
1545 }
1546
1547 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1548 {
1549   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1550     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1551 }
1552
1553 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1554 {
1555   if(_field_pm_pt_pd.empty())
1556     {
1557       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1558       throw INTERP_KERNEL::Exception(oss.str());
1559     }
1560   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1561     return _field_pm_pt_pd[locId];
1562   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1563   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1564   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1565   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1566 }
1567
1568 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1569 {
1570   if(_field_pm_pt_pd.empty())
1571     {
1572       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1573       throw INTERP_KERNEL::Exception(oss.str());
1574     }
1575   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1576     return _field_pm_pt_pd[locId];
1577   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1578   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1579   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1580   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1581 }
1582
1583 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1584 {
1585   int i=0;
1586   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1587     {
1588       (*it)->fillValues(i,startEntryId,entries);
1589     }
1590 }
1591
1592 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1593 {
1594   _field_pm_pt_pd=leaves;
1595   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1596     (*it)->setFather(this);
1597 }
1598
1599 /*!
1600  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1601  *  \param [out] its - list of pair (start,stop) kept
1602  *  \return bool - false if the type of field \a tof is not contained in \a this.
1603  */
1604 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1605 {
1606   bool ret(false);
1607   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1608   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1609     if((*it)->getType()==tof)
1610       {
1611         newPmPtPd.push_back(*it);
1612         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1613         (*it)->setNewStart(globalNum);
1614         globalNum=(*it)->getEnd();
1615         its.push_back(bgEnd);
1616         ret=true;
1617       }
1618   if(ret)
1619     _field_pm_pt_pd=newPmPtPd;
1620   return ret;
1621 }
1622
1623 /*!
1624  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1625  *  \param [out] its - list of pair (start,stop) kept
1626  *  \return bool - false if the type of field \a tof is not contained in \a this.
1627  */
1628 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1629 {
1630   if(_field_pm_pt_pd.size()<=idOfDisc)
1631     return false;
1632   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1633   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1634   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1635   elt->setNewStart(globalNum);
1636   globalNum=elt->getEnd();
1637   its.push_back(bgEnd);
1638   _field_pm_pt_pd=newPmPtPd;
1639   return true;
1640 }
1641
1642 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1643 {
1644   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1645     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1646 }
1647
1648 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1649 {
1650   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1651     (*it)->loadBigArray(fid,nasc);
1652 }
1653
1654 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1655 {
1656   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1657     {
1658       (*it)->copyOptionsFrom(*this);
1659       (*it)->writeLL(fid,nasc);
1660     }
1661 }
1662
1663 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1664 {
1665   switch(ikType)
1666   {
1667     case ON_CELLS:
1668       medfGeoType=typmai3[(int)ikGeoType];
1669       return MED_CELL;
1670     case ON_NODES:
1671       medfGeoType=MED_NONE;
1672       return MED_NODE;
1673     case ON_GAUSS_NE:
1674       medfGeoType=typmai3[(int)ikGeoType];
1675       return MED_NODE_ELEMENT;
1676     case ON_GAUSS_PT:
1677       medfGeoType=typmai3[(int)ikGeoType];
1678       return MED_CELL;
1679     default:
1680       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1681   }
1682   return MED_UNDEF_ENTITY_TYPE;
1683 }
1684
1685 //////////////////////////////////////////////////
1686
1687 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1688 {
1689   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1690 }
1691
1692 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1693 {
1694   return new MEDFileFieldPerMeshPerType(fath,geoType);
1695 }
1696
1697 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1698 {
1699   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1700   ret->setFather(father);
1701   ret->deepCopyElements();
1702   return ret.retn();
1703 }
1704
1705 void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1706 {
1707   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1708     {
1709       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1710       if(meshDim!=(int)cm.getDimension())
1711         return ;
1712     }
1713   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1714     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1715 }
1716
1717 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1718 {
1719   return _geo_type;
1720 }
1721
1722 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1723 {
1724   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1725 }
1726
1727 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1728 {
1729   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1730   int curDim((int)cm.getDimension());
1731   dim=std::max(dim,curDim);
1732 }
1733
1734 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1735 {
1736   const char startLine[]="  ## ";
1737   std::string startLine2(bkOffset,' ');
1738   std::string startLine3(startLine2);
1739   startLine3+=startLine;
1740   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1741     {
1742       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1743       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1744     }
1745   else
1746     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1747   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1748   int i=0;
1749   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1750     {
1751       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1752       if(cur)
1753         cur->simpleRepr(bkOffset,oss,i);
1754       else
1755         {
1756           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1757         }
1758     }
1759 }
1760
1761 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1762 {
1763   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1764   return std::string(cm.getRepr());
1765 }
1766
1767 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1768 {
1769 }
1770
1771 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1772 {
1773   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1774   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1775   med_geometry_type mgeoti;
1776   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1777   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1778   _field_pm_pt_pd.resize(nbProfiles);
1779   for(int i=0;i<nbProfiles;i++)
1780     {
1781       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1782     }
1783   if(type==ON_CELLS)
1784     {
1785       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1786       for(int i=0;i<nbProfiles2;i++)
1787         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1788     }
1789 }
1790
1791 MCAuto<MEDFileFieldPerMeshPerType> MEDFileFieldPerMeshPerType::Aggregate(int &start, const std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
1792 {
1793   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1794   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1795   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1796     {
1797       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1798         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1799     }
1800   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1801     {
1802       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1803       ret->_field_pm_pt_pd.push_back(agg);
1804     }
1805   return ret;
1806 }
1807
1808 //////////////////////////////////////////////////
1809
1810 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1811 {
1812   if(!entities)
1813     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1814   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1815   if(!entities2)
1816     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1817   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1818   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1819 }
1820
1821 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1822 {
1823   _se.takeRef(se);
1824   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1825   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1826   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1827   _field_pm_pt_pd.resize(nbProfiles);
1828   for(int i=0;i<nbProfiles;i++)
1829     {
1830       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1831     }
1832 }
1833
1834 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1835 {
1836   return _se->getDynGT();
1837 }
1838
1839 std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const
1840 {
1841   return _se->getName();
1842 }
1843
1844 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1845 {
1846   throw INTERP_KERNEL::Exception("not implemented yet !");
1847 }
1848
1849 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1850 {
1851   gt=getDynGT();
1852   ent=MED_STRUCT_ELEMENT;
1853 }
1854
1855 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1856 {
1857   throw INTERP_KERNEL::Exception("not implemented yet !");
1858 }
1859
1860 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1861 {
1862   const char startLine[]="  ## ";
1863   std::string startLine2(bkOffset,' ');
1864   std::string startLine3(startLine2);
1865   startLine3+=startLine;
1866   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1867   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1868   int i=0;
1869   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1870     {
1871       if((*it).isNotNull())
1872         (*it)->simpleRepr(bkOffset,oss,i);
1873       else
1874         {
1875           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1876         }
1877     }
1878 }
1879
1880 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1881 {
1882   throw INTERP_KERNEL::Exception("not implemented yet !");
1883 }
1884
1885 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1886 {
1887   MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1888   ret->setFather(father);
1889   ret->deepCopyElements();
1890   return ret.retn();
1891 }
1892
1893 void MEDFileFieldPerMeshPerTypeDyn::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1894 {
1895   throw INTERP_KERNEL::Exception("not implemented yet !");
1896 }
1897
1898 //////////////////////////////////////////////////
1899
1900 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1901 {
1902   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1903 }
1904
1905 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1906 {
1907   return new MEDFileFieldPerMesh(fath,mesh);
1908 }
1909
1910 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1911 {
1912   return _field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1913 }
1914
1915 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1916 {
1917   std::vector<const BigMemoryObject *> ret;
1918   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1919     ret.push_back(*it);
1920   return ret;
1921 }
1922
1923 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1924 {
1925   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1926   ret->_father=father;
1927   std::size_t i=0;
1928   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1929     {
1930       if((*it).isNotNull())
1931         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1932     }
1933   return ret.retn();
1934 }
1935
1936 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1937 {
1938   std::string startLine(bkOffset,' ');
1939   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << getMeshName() << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1940   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1941   int i=0;
1942   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1943     {
1944       if((*it).isNotNull())
1945         (*it)->simpleRepr(bkOffset,oss,i);
1946       else
1947         {
1948           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1949         }
1950     }
1951 }
1952
1953 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1954 {
1955   mesh->getTime(_mesh_iteration,_mesh_order);
1956 }
1957
1958 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1959 {
1960   int nbOfTypes=code.size()/3;
1961   int offset=0;
1962   for(int i=0;i<nbOfTypes;i++)
1963     {
1964       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1965       int nbOfCells=code[3*i+1];
1966       int pos=addNewEntryIfNecessary(type);
1967       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1968       offset+=nbOfCells;
1969     }
1970 }
1971
1972 /*!
1973  * This method is the most general one. No optimization is done here.
1974  * \param [in] multiTypePfl is the end user profile specified in high level API
1975  * \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].
1976  * \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.
1977  * \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.
1978  * \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.
1979  * \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.
1980  */
1981 void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<int>& code2, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1982 {
1983   int nbOfTypes(code.size()/3);
1984   for(int i=0;i<nbOfTypes;i++)
1985     {
1986       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1987       int pos=addNewEntryIfNecessary(type);
1988       DataArrayInt *pfl=0;
1989       if(code[3*i+2]!=-1)
1990         pfl=idsPerType[code[3*i+2]];
1991       int nbOfTupes2=code2.size()/3;
1992       int found=0;
1993       for(;found<nbOfTupes2;found++)
1994         if(code[3*i]==code2[3*found])
1995           break;
1996       if(found==nbOfTupes2)
1997         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1998       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1999     }
2000 }
2001
2002 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
2003 {
2004   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2005   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
2006 }
2007
2008 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
2009 {
2010   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
2011   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
2012 }
2013
2014 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
2015 {
2016   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2017     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
2018 }
2019
2020 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
2021 {
2022   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2023     (*it)->loadBigArraysRecursively(fid,nasc);
2024 }
2025
2026 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
2027 {
2028   int nbOfTypes=_field_pm_pt.size();
2029   for(int i=0;i<nbOfTypes;i++)
2030     {
2031       _field_pm_pt[i]->copyOptionsFrom(*this);
2032       _field_pm_pt[i]->writeLL(fid,nasc);
2033     }
2034 }
2035
2036 void MEDFileFieldPerMesh::getDimension(int& dim) const
2037 {
2038   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2039     (*it)->getDimension(dim);
2040 }
2041
2042 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
2043 {
2044   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2045     if(!(*it)->isUniqueLevel(dim))
2046       return false;
2047   return true;
2048 }
2049
2050 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
2051 {
2052   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2053     (*it)->fillTypesOfFieldAvailable(types);
2054 }
2055
2056 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
2057 {
2058   int sz=_field_pm_pt.size();
2059   std::vector< std::vector<std::pair<int,int> > > ret(sz);
2060   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
2061   for(int i=0;i<sz;i++)
2062     {
2063       types[i]=_field_pm_pt[i]->getGeoType();
2064       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
2065     }
2066   return ret;
2067 }
2068
2069 double MEDFileFieldPerMesh::getTime() const
2070 {
2071   int tmp1,tmp2;
2072   return _father->getTime(tmp1,tmp2);
2073 }
2074
2075 int MEDFileFieldPerMesh::getIteration() const
2076 {
2077   return _father->getIteration();
2078 }
2079
2080 int MEDFileFieldPerMesh::getOrder() const
2081 {
2082   return _father->getOrder();
2083 }
2084
2085 int MEDFileFieldPerMesh::getNumberOfComponents() const
2086 {
2087   return _father->getNumberOfComponents();
2088 }
2089
2090 std::string MEDFileFieldPerMesh::getMeshName() const
2091 {
2092   return _father->getMeshName();
2093 }
2094
2095 void MEDFileFieldPerMesh::setMeshName(const std::string& meshName)
2096 {
2097   _father->setMeshName(meshName);
2098 }
2099
2100 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
2101 {
2102   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2103     {
2104       if((*it).isNull())
2105         continue;
2106       if((*it)->presenceOfMultiDiscPerGeoType())
2107         return true;
2108     }
2109   return false;
2110 }
2111
2112 bool MEDFileFieldPerMesh::presenceOfStructureElements() const
2113 {
2114   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2115     if((*it).isNotNull())
2116       {
2117         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2118         if(pt)
2119           return true;
2120       }
2121   return false;
2122 }
2123
2124 bool MEDFileFieldPerMesh::onlyStructureElements() const
2125 {
2126   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2127     if((*it).isNotNull())
2128       {
2129         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2130         if(!pt)
2131           return false;
2132       }
2133   return true;
2134 }
2135
2136 void MEDFileFieldPerMesh::killStructureElements()
2137 {
2138   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2139   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2140     {
2141       if((*it).isNotNull())
2142         {
2143           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2144           if(!pt)
2145             res.push_back(*it);
2146         }
2147     }
2148   _field_pm_pt=res;
2149 }
2150
2151 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2152 {
2153   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2154   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2155     {
2156       if((*it).isNotNull())
2157         {
2158           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2159           if(pt)
2160             res.push_back(*it);
2161         }
2162     }
2163   _field_pm_pt=res;
2164 }
2165
2166 void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName)
2167 {
2168   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2169   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2170     {
2171       if((*it).isNotNull())
2172         {
2173           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2174           if(!pt)
2175             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !");
2176           if(pt->getModelName()==seName)
2177             res.push_back(*it);
2178         }
2179     }
2180   _field_pm_pt=res;
2181 }
2182
2183 void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
2184 {
2185   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2186     {
2187       if((*it).isNotNull())
2188         {
2189           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2190           if(pt)
2191             {
2192               ps.push_back(std::pair<std::string,std::string>(getMeshName(),pt->getModelName()));
2193             }
2194           else
2195             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !");
2196         }
2197     }
2198 }
2199
2200 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2201 {
2202   if(!_father)
2203     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2204   return _father->getOrCreateAndGetArray();
2205 }
2206
2207 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2208 {
2209   if(!_father)
2210     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2211   return _father->getOrCreateAndGetArray();
2212 }
2213
2214 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2215 {
2216   return _father->getInfo();
2217 }
2218
2219 /*!
2220  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2221  * 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.
2222  * It returns 2 output vectors :
2223  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2224  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2225  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2226  */
2227 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)
2228 {
2229   int notNullPflsSz=0;
2230   int nbOfArrs=geoTypes.size();
2231   for(int i=0;i<nbOfArrs;i++)
2232     if(pfls[i])
2233       notNullPflsSz++;
2234   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2235   int nbOfDiffGeoTypes=geoTypes3.size();
2236   code.resize(3*nbOfDiffGeoTypes);
2237   notNullPfls.resize(notNullPflsSz);
2238   notNullPflsSz=0;
2239   int j=0;
2240   for(int i=0;i<nbOfDiffGeoTypes;i++)
2241     {
2242       int startZone=j;
2243       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2244       std::vector<const DataArrayInt *> notNullTmp;
2245       if(pfls[j])
2246         notNullTmp.push_back(pfls[j]);
2247       j++;
2248       for(;j<nbOfArrs;j++)
2249         if(geoTypes[j]==refType)
2250           {
2251             if(pfls[j])
2252               notNullTmp.push_back(pfls[j]);
2253           }
2254         else
2255           break;
2256       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2257       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2258       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2259       code[3*i]=(int)refType;
2260       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2261       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2262       if(notNullTmp.empty())
2263         code[3*i+2]=-1;
2264       else
2265         {
2266           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2267           code[3*i+2]=notNullPflsSz++;
2268         }
2269     }
2270 }
2271
2272 /*!
2273  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2274  */
2275 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)
2276 {
2277   int sz=dads.size();
2278   int ret=0;
2279   for(int i=0;i<sz;i++)
2280     {
2281       if(locs[i]==-1)
2282         {
2283           if(type!=ON_GAUSS_NE)
2284             ret+=dads[i].second-dads[i].first;
2285           else
2286             {
2287               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2288               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2289             }
2290         }
2291       else
2292         {
2293           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2294           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2295         }
2296     }
2297   return ret;
2298 }
2299
2300 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2301 {
2302   std::vector<std::string> ret;
2303   std::set<std::string> ret2;
2304   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2305     {
2306       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2307       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2308         if(ret2.find(*it2)==ret2.end())
2309           {
2310             ret.push_back(*it2);
2311             ret2.insert(*it2);
2312           }
2313     }
2314   return ret;
2315 }
2316
2317 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2318 {
2319   std::vector<std::string> ret;
2320   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2321     {
2322       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2323       ret.insert(ret.end(),tmp.begin(),tmp.end());
2324     }
2325   return ret;
2326 }
2327
2328 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2329 {
2330   std::vector<std::string> ret;
2331   std::set<std::string> ret2;
2332   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2333     {
2334       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2335       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2336         if(ret2.find(*it2)==ret2.end())
2337           {
2338             ret.push_back(*it2);
2339             ret2.insert(*it2);
2340           }
2341     }
2342   return ret;
2343 }
2344
2345 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2346 {
2347   std::vector<std::string> ret;
2348   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2349     {
2350       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2351       ret.insert(ret.end(),tmp.begin(),tmp.end());
2352     }
2353   return ret;
2354 }
2355
2356 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2357 {
2358   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2359     {
2360       if((*it).first==getMeshName())
2361         {
2362           setMeshName((*it).second);
2363           return true;
2364         }
2365     }
2366   return false;
2367 }
2368
2369 void MEDFileFieldPerMesh::convertMedBallIntoClassic()
2370 {
2371   if(_field_pm_pt.size()!=1)
2372     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : Only managed for single mesh !");
2373   if(_field_pm_pt[0].isNull())
2374     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : null pointer !");
2375   MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<MEDFileFieldPerMeshPerTypeDyn *>((MEDFileFieldPerMeshPerTypeCommon *)_field_pm_pt[0]));
2376   if(!pt)
2377     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : this is expected to be marked as structure element !");
2378   if(pt->getNumberOfLoc()!=1)
2379     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : only one loc managed !");
2380   const MEDFileFieldPerMeshPerTypePerDisc *disc(pt->getLeafGivenLocId(0));
2381   if(!disc)
2382     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : internal error !");
2383   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> disc2(MEDFileFieldPerMeshPerTypePerDisc::New(*disc));
2384   disc2->setType(ON_NODES);
2385   MCAuto<MEDFileFieldPerMeshPerType> pt2(MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR));
2386   disc2->setFather(pt2);
2387   pt2->setFather(this);
2388   pt2->pushDiscretization(disc2);
2389   _field_pm_pt[0]=DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(pt2);
2390 }
2391
2392 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2393                                                       MEDFileFieldGlobsReal& glob)
2394 {
2395   if(getMeshName()!=meshName)
2396     return false;
2397   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2398   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2399   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2400   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2401   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2402   getUndergroundDataArrayExt(entries);
2403   DataArray *arr0(getOrCreateAndGetArray());//tony
2404   if(!arr0)
2405     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2406   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2407   if(!arr0)
2408     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2409   int sz=0;
2410   if(!arr)
2411     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2412   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2413     {
2414       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2415         {
2416           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2417           sz+=(*it).second.second-(*it).second.first;
2418         }
2419       else
2420         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2421     }
2422   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2423   ////////////////////
2424   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2425   int *workI2=explicitIdsOldInMesh->getPointer();
2426   int sz1=0,sz2=0,sid=1;
2427   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2428   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2429   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2430     {
2431       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2432       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2433       int *workI=explicitIdsOldInArr->getPointer();
2434       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2435         {
2436           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2437           (*itL2)->setLocId(sz2);
2438           (*itL2)->_tmp_work1=(*itL2)->getStart();
2439           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2440         }
2441       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2442     }
2443   explicitIdsOldInMesh->reAlloc(sz2);
2444   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2445   ////////////////////
2446   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2447   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2448   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2449   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2450     {
2451       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2452       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2453       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2454     }
2455   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2456   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2457   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2458     {
2459       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2460       int newStart=elt->getLocId();
2461       elt->setLocId((*it)->getGeoType());
2462       elt->setNewStart(newStart);
2463       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2464       entriesKeptNew.push_back(elt);
2465       entriesKeptNew2.push_back(elt);
2466     }
2467   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2468   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2469   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2470   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2471   bool ret=false;
2472   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2473     {
2474       sid=0;
2475       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2476         {
2477           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2478           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2479           }*/
2480       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2481                                                             glob,arr2,otherEntriesNew) || ret;
2482     }
2483   if(!ret)
2484     return false;
2485   // Assign new dispatching
2486   assignNewLeaves(otherEntriesNew);
2487   arr->deepCopyFrom(*arr2);
2488   return true;
2489 }
2490
2491 /*!
2492  * \param [in,out] globalNum a global numbering counter for the renumbering.
2493  * \param [out] its - list of pair (start,stop) kept
2494  */
2495 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2496 {
2497   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2498   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2499     {
2500       std::vector< std::pair<int,int> > its2;
2501       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2502         {
2503           ret.push_back(*it);
2504           its.insert(its.end(),its2.begin(),its2.end());
2505         }
2506     }
2507   _field_pm_pt=ret;
2508 }
2509
2510 /*!
2511  * \param [in,out] globalNum a global numbering counter for the renumbering.
2512  * \param [out] its - list of pair (start,stop) kept
2513  */
2514 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2515 {
2516   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2517   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2518     {
2519       std::vector< std::pair<int,int> > its2;
2520       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2521         {
2522           ret.push_back(*it);
2523           its.insert(its.end(),its2.begin(),its2.end());
2524         }
2525     }
2526   _field_pm_pt=ret;
2527 }
2528
2529 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2530 {
2531   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2532   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2533     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2534   //
2535   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2536   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2537   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2538   for(;it1!=types.end();it1++,it2++)
2539     {
2540       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2541       elt->setLeaves((*it1).second);
2542       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2543       *it2=elt2;
2544     }
2545   _field_pm_pt=fieldPmPt;
2546 }
2547
2548 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2549 {
2550   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2551     (*it)->changePflsRefsNamesGen(mapOfModif);
2552 }
2553
2554 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2555 {
2556   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2557     (*it)->changeLocsRefsNamesGen(mapOfModif);
2558 }
2559
2560 /*!
2561  * \param [in] mesh is the whole mesh
2562  */
2563 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2564 {
2565   if(_field_pm_pt.empty())
2566     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2567   //
2568   std::vector< std::pair<int,int> > dads;
2569   std::vector<const DataArrayInt *> pfls;
2570   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2571   std::vector<int> locs,code;
2572   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2573   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2574     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2575   // Sort by types
2576   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2577   if(code.empty())
2578     {
2579       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2580       throw INTERP_KERNEL::Exception(oss.str());
2581     }
2582   //
2583   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2584   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2585   if(type!=ON_NODES)
2586     {
2587       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2588       if(!arr)
2589         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2590       else
2591         {
2592           MCAuto<DataArrayInt> arr2(arr);
2593           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2594         }
2595     }
2596   else
2597     {
2598       if(code.size()!=3)
2599         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2600       int nb=code[1];
2601       if(code[2]==-1)
2602         {
2603           if(nb!=mesh->getNumberOfNodes())
2604             {
2605               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2606               oss << " nodes in mesh !";
2607               throw INTERP_KERNEL::Exception(oss.str());
2608             }
2609           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2610         }
2611       else
2612         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2613     }
2614 }
2615
2616 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2617 {
2618   if(_field_pm_pt.empty())
2619     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2620   //
2621   std::vector<std::pair<int,int> > dads;
2622   std::vector<const DataArrayInt *> pfls;
2623   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2624   std::vector<int> locs,code;
2625   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2626   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2627     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2628   // Sort by types
2629   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2630   if(code.empty())
2631     {
2632       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2633       throw INTERP_KERNEL::Exception(oss.str());
2634     }
2635   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2636   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2637   if(type!=ON_NODES)
2638     {
2639       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2640       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2641     }
2642   else
2643     {
2644       if(code.size()!=3)
2645         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2646       int nb=code[1];
2647       if(code[2]==-1)
2648         {
2649           if(nb!=mesh->getNumberOfNodes())
2650             {
2651               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2652               oss << " nodes in mesh !";
2653               throw INTERP_KERNEL::Exception(oss.str());
2654             }
2655         }
2656       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2657     }
2658   //
2659   return 0;
2660 }
2661
2662 void MEDFileFieldPerMesh::accept(MEDFileFieldVisitor& visitor) const
2663 {
2664   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2665     if((*it).isNotNull())
2666       {
2667         visitor.newPerMeshPerTypeEntry(*it);
2668         (*it)->accept(visitor);
2669         visitor.endPerMeshPerTypeEntry(*it);
2670       }
2671 }
2672
2673 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2674 {
2675   int globalSz=0;
2676   int nbOfEntries=0;
2677   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2678     {
2679       (*it)->getSizes(globalSz,nbOfEntries);
2680     }
2681   entries.resize(nbOfEntries);
2682   nbOfEntries=0;
2683   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2684     {
2685       (*it)->fillValues(nbOfEntries,entries);
2686     }
2687 }
2688
2689 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2690 {
2691   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2692     {
2693       if((*it)->getGeoType()==typ)
2694         return (*it)->getLeafGivenLocId(locId);
2695     }
2696   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2697   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2698   oss << "Possiblities are : ";
2699   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2700     {
2701       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2702       oss << "\"" << cm2.getRepr() << "\", ";
2703     }
2704   throw INTERP_KERNEL::Exception(oss.str());
2705 }
2706
2707 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2708 {
2709   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2710     {
2711       if((*it)->getGeoType()==typ)
2712         return (*it)->getLeafGivenLocId(locId);
2713     }
2714   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2715   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2716   oss << "Possiblities are : ";
2717   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2718     {
2719       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2720       oss << "\"" << cm2.getRepr() << "\", ";
2721     }
2722   throw INTERP_KERNEL::Exception(oss.str());
2723 }
2724
2725 /*!
2726  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2727  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2728  * \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.
2729  * \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.
2730  */
2731 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)
2732 {
2733   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2734   if(pms.empty())
2735     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2736   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2737     {
2738       if(!(*it).second)
2739         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2740       if(!(*it).second->getProfile().empty())
2741         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2742       if(!(*it).second->getLocalization().empty())
2743         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2744     }
2745   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2746   std::size_t i(0);
2747   std::vector< std::pair<int,int> > filteredDTS;
2748   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2749     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2750       if((*it2).first==gt)
2751         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2752   if(pms.size()!=filteredDTS.size())
2753     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2754   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2755   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2756   int zeStart(start),nval(0);
2757   for(;it1!=pms.end();it1++,it2++)
2758     {
2759       if((*it1).first!=(*it2).first)
2760         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2761       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2762       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2763       start+=e1-s1;
2764       nval+=((*it1).second)->getNumberOfVals();
2765     }
2766   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2767   return ret;
2768 }
2769
2770 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)
2771 {
2772   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2773   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2774   std::size_t i(0);
2775   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2776     {
2777       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2778       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2779         {
2780           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2781           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2782           if(!elt)
2783             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2784           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2785         }
2786     }
2787   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2788     {
2789       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2790       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2791       ret->_field_pm_pt.push_back(agg2);
2792     }
2793   return ret;
2794 }
2795
2796 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2797 {
2798   int i=0;
2799   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2800   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2801   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2802     {
2803       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2804       if(type==curType)
2805         return i;
2806       else
2807         {
2808           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2809           if(pos>pos2)
2810             it2=it+1;
2811         }
2812     }
2813   int ret=std::distance(_field_pm_pt.begin(),it2);
2814   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2815   return ret;
2816 }
2817
2818 /*!
2819  * 'dads' and 'locs' input parameters have the same number of elements
2820  * \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
2821  */
2822 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2823                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2824                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2825 {
2826   isPfl=false;
2827   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2828   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2829   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2830   const std::vector<std::string>& infos=getInfo();
2831   da->setInfoOnComponents(infos);
2832   da->setName("");
2833   if(type==ON_GAUSS_PT)
2834     {
2835       int offset=0;
2836       int nbOfArrs=dads.size();
2837       for(int i=0;i<nbOfArrs;i++)
2838         {
2839           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2840           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2841           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2842           MCAuto<DataArrayInt> di=DataArrayInt::New();
2843           di->alloc(nbOfElems,1);
2844           di->iota(offset);
2845           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2846           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2847           offset+=nbOfElems;
2848         }
2849     }
2850   arrOut=da;
2851   return ret.retn();
2852 }
2853
2854 /*!
2855  * 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.
2856  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2857  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2858  * The order of cells in the returned field is those imposed by the profile.
2859  * \param [in] mesh is the global mesh.
2860  */
2861 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2862                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2863                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2864                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2865 {
2866   if(da->isIota(mesh->getNumberOfCells()))
2867     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2868   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2869   m2->setName(mesh->getName().c_str());
2870   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2871   isPfl=true;
2872   return ret.retn();
2873 }
2874
2875 /*!
2876  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2877  */
2878 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2879                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2880                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2881 {
2882   if(da->isIota(mesh->getNumberOfNodes()))
2883     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2884   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2885   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2886   if(meshu)
2887     {
2888       if(meshu->getNodalConnectivity()==0)
2889         {
2890           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2891           int nb=da->getNbOfElems();
2892           const int *ptr=da->getConstPointer();
2893           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2894           meshuc->allocateCells(nb);
2895           for(int i=0;i<nb;i++)
2896             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2897           meshuc->finishInsertingCells();
2898           ret->setMesh(meshuc);
2899           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2900           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2901           disc->checkCoherencyBetween(meshuc,arrOut);
2902           return ret.retn();
2903         }
2904     }
2905   //
2906   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2907   isPfl=true;
2908   DataArrayInt *arr2=0;
2909   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2910   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2911   MCAuto<DataArrayInt> arr3(arr2);
2912   int nnodes=mesh2->getNumberOfNodes();
2913   if(nnodes==(int)da->getNbOfElems())
2914     {
2915       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2916       arrOut->renumberInPlace(da3->getConstPointer());
2917       mesh2->setName(mesh->getName().c_str());
2918       ret->setMesh(mesh2);
2919       return ret.retn();
2920     }
2921   else
2922     {
2923       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 !!!";
2924       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2925       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2926       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2927       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2928       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2929       throw INTERP_KERNEL::Exception(oss.str());
2930     }
2931   return 0;
2932 }
2933
2934 /*!
2935  * This method is the most light method of field retrieving.
2936  */
2937 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2938 {
2939   if(!pflIn)
2940     {
2941       pflOut=DataArrayInt::New();
2942       pflOut->alloc(nbOfElems,1);
2943       pflOut->iota(0);
2944     }
2945   else
2946     {
2947       pflOut=const_cast<DataArrayInt*>(pflIn);
2948       pflOut->incrRef();
2949     }
2950   MCAuto<DataArrayInt> safePfl(pflOut);
2951   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2952   const std::vector<std::string>& infos=getInfo();
2953   int nbOfComp=infos.size();
2954   for(int i=0;i<nbOfComp;i++)
2955     da->setInfoOnComponent(i,infos[i].c_str());
2956   safePfl->incrRef();
2957   return da.retn();
2958 }
2959
2960
2961 /// @cond INTERNAL
2962
2963 class MFFPMIter
2964 {
2965 public:
2966   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2967   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2968   virtual ~MFFPMIter() { }
2969   virtual void begin() = 0;
2970   virtual bool finished() const = 0;
2971   virtual void next() = 0;
2972   virtual int current() const = 0;
2973 };
2974
2975 class MFFPMIterSimple : public MFFPMIter
2976 {
2977 public:
2978   MFFPMIterSimple():_pos(0) { }
2979   void begin() { _pos=0; }
2980   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2981   void next() { _pos++; }
2982   int current() const { return _pos; }
2983 private:
2984   int _pos;
2985 };
2986
2987 class MFFPMIter2 : public MFFPMIter
2988 {
2989 public:
2990   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2991   void begin() { _it=_ids.begin(); }
2992   bool finished() const { return _it==_ids.end(); }
2993   void next() { _it++; }
2994   int current() const { return *_it; }
2995 private:
2996   std::vector<int> _ids;
2997   std::vector<int>::const_iterator _it;
2998 };
2999
3000 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
3001 {
3002   if(!entities)
3003     return new MFFPMIterSimple;
3004   else
3005     {
3006       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3007       if(entities2)
3008         {
3009           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
3010           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3011           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3012             {
3013               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
3014                 tmp.push_back((*it).second);
3015             }
3016           return new MFFPMIter2(tmp);
3017         }
3018       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
3019     }
3020 }
3021
3022 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
3023 {
3024   if(!entities)
3025     return true;
3026   else
3027     {
3028       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
3029       if(entities2)
3030         {
3031           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
3032           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
3033             if((*it).first==ON_NODES)
3034               return true;
3035           return false;
3036         }
3037       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
3038     }
3039 }
3040
3041 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
3042 {
3043   std::size_t sz(cts.size());
3044   _ids.resize(sz);
3045   for(std::size_t i=0;i<sz;i++)
3046     {
3047       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
3048       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
3049         _ids[i]=(int)std::distance(typmai2,loc);
3050       else
3051         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
3052     }
3053 }
3054
3055 /// @endcond
3056
3057 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),
3058     _father(fath)
3059 {
3060   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3061   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3062   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
3063   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
3064   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
3065   for(iter0->begin();!iter0->finished();iter0->next())
3066     {
3067       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3068       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3069       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
3070       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
3071       if(nbProfile>0 || nbProfile2>0)
3072         {
3073           const PartDefinition *pd(0);
3074           if(mmu)
3075             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
3076           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
3077           if(nbProfile>0)
3078             setMeshName(name0);
3079           else
3080             setMeshName(name1);
3081         }
3082     }
3083   if(MFFPMIter::IsPresenceOfNode(entities))
3084     {
3085       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
3086       if(nbProfile>0)
3087         {
3088           const PartDefinition *pd(0);
3089           if(mmu)
3090             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
3091           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
3092           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3093         }
3094     }
3095   if(!entities)
3096     return ;
3097   std::vector<int> dynGT(entities->getDynGTAvail());
3098   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
3099     {
3100       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
3101       if(nbPfl>0)
3102         {
3103           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
3104           setMeshName(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE));
3105         }
3106     }
3107 }
3108
3109 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
3110 {
3111   copyTinyInfoFrom(mesh);
3112 }
3113
3114 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3115 {
3116   if(id>=(int)_pfls.size())
3117     _pfls.resize(id+1);
3118   _pfls[id]=DataArrayInt::New();
3119   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
3120   _pfls[id]->setName(pflName);
3121   _pfls[id]->alloc(lgth,1);
3122   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
3123   _pfls[id]->applyLin(1,-1,0);//Converting into C format
3124 }
3125
3126 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
3127 {
3128   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3129   int sz;
3130   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
3131   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
3132   if(i>=(int)_pfls.size())
3133     _pfls.resize(i+1);
3134   _pfls[i]=DataArrayInt::New();
3135   _pfls[i]->alloc(sz,1);
3136   _pfls[i]->setName(pflCpp.c_str());
3137   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
3138   _pfls[i]->applyLin(1,-1,0);//Converting into C format
3139 }
3140
3141 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3142 {
3143   int nbOfPfls=_pfls.size();
3144   for(int i=0;i<nbOfPfls;i++)
3145     {
3146       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
3147       cpy->applyLin(1,1,0);
3148       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3149       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
3150       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
3151     }
3152   //
3153   int nbOfLocs=_locs.size();
3154   for(int i=0;i<nbOfLocs;i++)
3155     _locs[i]->writeLL(fid);
3156 }
3157
3158 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
3159 {
3160   std::vector<std::string> pfls=getPfls();
3161   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
3162     {
3163       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
3164       if(it2==pfls.end())
3165         {
3166           _pfls.push_back(*it);
3167         }
3168       else
3169         {
3170           int id=std::distance(pfls.begin(),it2);
3171           if(!(*it)->isEqual(*_pfls[id]))
3172             {
3173               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3174               throw INTERP_KERNEL::Exception(oss.str());
3175             }
3176         }
3177     }
3178   std::vector<std::string> locs=getLocs();
3179   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
3180     {
3181       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
3182       if(it2==locs.end())
3183         {
3184           _locs.push_back(*it);
3185         }
3186       else
3187         {
3188           int id=std::distance(locs.begin(),it2);
3189           if(!(*it)->isEqual(*_locs[id],eps))
3190             {
3191               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3192               throw INTERP_KERNEL::Exception(oss.str());
3193             }
3194         }
3195     }
3196 }
3197
3198 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
3199 {
3200   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
3201     getProfile((*it).c_str());
3202 }
3203
3204 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
3205 {
3206   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
3207     getLocalization((*it).c_str());
3208 }
3209
3210 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
3211 {
3212   std::vector<std::string> profiles=real.getPflsReallyUsed();
3213   int sz=profiles.size();
3214   _pfls.resize(sz);
3215   for(int i=0;i<sz;i++)
3216     loadProfileInFile(fid,i,profiles[i].c_str());
3217   //
3218   std::vector<std::string> locs=real.getLocsReallyUsed();
3219   sz=locs.size();
3220   _locs.resize(sz);
3221   for(int i=0;i<sz;i++)
3222     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
3223 }
3224
3225 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3226 {
3227   int nProfil=MEDnProfile(fid);
3228   for(int i=0;i<nProfil;i++)
3229     loadProfileInFile(fid,i);
3230   int sz=MEDnLocalization(fid);
3231   _locs.resize(sz);
3232   for(int i=0;i<sz;i++)
3233     {
3234       _locs[i]=MEDFileFieldLoc::New(fid,i,entities);
3235     }
3236 }
3237
3238 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
3239 {
3240   return new MEDFileFieldGlobs(fid);
3241 }
3242
3243 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
3244 {
3245   return new MEDFileFieldGlobs;
3246 }
3247
3248 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
3249 {
3250   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
3251 }
3252
3253 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
3254 {
3255   std::vector<const BigMemoryObject *> ret;
3256   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3257     ret.push_back((const DataArrayInt *)*it);
3258   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3259     ret.push_back((const MEDFileFieldLoc *)*it);
3260   return ret;
3261 }
3262
3263 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3264 {
3265   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3266   std::size_t i=0;
3267   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3268     {
3269       if((const DataArrayInt *)*it)
3270         ret->_pfls[i]=(*it)->deepCopy();
3271     }
3272   i=0;
3273   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3274     {
3275       if((const MEDFileFieldLoc*)*it)
3276         ret->_locs[i]=(*it)->deepCopy();
3277     }
3278   return ret.retn();
3279 }
3280
3281 /*!
3282  * \throw if a profile in \a pfls in not in \a this.
3283  * \throw if a localization in \a locs in not in \a this.
3284  * \sa MEDFileFieldGlobs::deepCpyPart
3285  */
3286 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3287 {
3288   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3289   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3290     {
3291       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3292       if(!pfl)
3293         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3294       pfl->incrRef();
3295       MCAuto<DataArrayInt> pfl2(pfl);
3296       ret->_pfls.push_back(pfl2);
3297     }
3298   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3299     {
3300       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3301       if(!loc)
3302         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3303       loc->incrRef();
3304       MCAuto<MEDFileFieldLoc> loc2(loc);
3305       ret->_locs.push_back(loc2);
3306     }
3307   ret->setFileName(getFileName());
3308   return ret.retn();
3309 }
3310
3311 /*!
3312  * \throw if a profile in \a pfls in not in \a this.
3313  * \throw if a localization in \a locs in not in \a this.
3314  * \sa MEDFileFieldGlobs::shallowCpyPart
3315  */
3316 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3317 {
3318   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3319   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3320     {
3321       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3322       if(!pfl)
3323         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3324       ret->_pfls.push_back(pfl->deepCopy());
3325     }
3326   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3327     {
3328       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3329       if(!loc)
3330         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3331       ret->_locs.push_back(loc->deepCopy());
3332     }
3333   ret->setFileName(getFileName());
3334   return ret.retn();
3335 }
3336
3337 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3338 {
3339 }
3340
3341 MEDFileFieldGlobs::MEDFileFieldGlobs()
3342 {
3343 }
3344
3345 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3346 {
3347 }
3348
3349 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3350 {
3351   oss << "Profiles :\n";
3352   std::size_t n=_pfls.size();
3353   for(std::size_t i=0;i<n;i++)
3354     {
3355       oss << "  - #" << i << " ";
3356       const DataArrayInt *pfl=_pfls[i];
3357       if(pfl)
3358         oss << "\"" << pfl->getName() << "\"\n";
3359       else
3360         oss << "EMPTY !\n";
3361     }
3362   n=_locs.size();
3363   oss << "Localizations :\n";
3364   for(std::size_t i=0;i<n;i++)
3365     {
3366       oss << "  - #" << i << " ";
3367       const MEDFileFieldLoc *loc=_locs[i];
3368       if(loc)
3369         loc->simpleRepr(oss);
3370       else
3371         oss<< "EMPTY !\n";
3372     }
3373 }
3374
3375 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3376 {
3377   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3378     {
3379       DataArrayInt *elt(*it);
3380       if(elt)
3381         {
3382           std::string name(elt->getName());
3383           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3384             {
3385               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3386                 {
3387                   elt->setName((*it2).second.c_str());
3388                   return;
3389                 }
3390             }
3391         }
3392     }
3393 }
3394
3395 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3396 {
3397   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3398     {
3399       MEDFileFieldLoc *elt(*it);
3400       if(elt)
3401         {
3402           std::string name(elt->getName());
3403           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3404             {
3405               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3406                 {
3407                   elt->setName((*it2).second.c_str());
3408                   return;
3409                 }
3410             }
3411         }
3412     }
3413 }
3414
3415 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3416 {
3417   if(locId<0 || locId>=(int)_locs.size())
3418     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3419   return _locs[locId]->getNbOfGaussPtPerCell();
3420 }
3421
3422 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3423 {
3424   return getLocalizationFromId(getLocalizationId(locName));
3425 }
3426
3427 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3428 {
3429   if(locId<0 || locId>=(int)_locs.size())
3430     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3431   return *_locs[locId];
3432 }
3433
3434 /// @cond INTERNAL
3435 namespace MEDCouplingImpl
3436 {
3437   class LocFinder
3438   {
3439   public:
3440     LocFinder(const std::string& loc):_loc(loc) { }
3441     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3442   private:
3443     const std::string &_loc;
3444   };
3445
3446   class PflFinder
3447   {
3448   public:
3449     PflFinder(const std::string& pfl):_pfl(pfl) { }
3450     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3451   private:
3452     const std::string& _pfl;
3453   };
3454 }
3455 /// @endcond
3456
3457 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3458 {
3459   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3460   if(it==_locs.end())
3461     {
3462       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3463       for(it=_locs.begin();it!=_locs.end();it++)
3464         oss << "\"" << (*it)->getName() << "\", ";
3465       throw INTERP_KERNEL::Exception(oss.str());
3466     }
3467   return std::distance(_locs.begin(),it);
3468 }
3469
3470 /*!
3471  * The returned value is never null.
3472  */
3473 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3474 {
3475   std::string pflNameCpp(pflName);
3476   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3477   if(it==_pfls.end())
3478     {
3479       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3480       for(it=_pfls.begin();it!=_pfls.end();it++)
3481         oss << "\"" << (*it)->getName() << "\", ";
3482       throw INTERP_KERNEL::Exception(oss.str());
3483     }
3484   return *it;
3485 }
3486
3487 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3488 {
3489   if(pflId<0 || pflId>=(int)_pfls.size())
3490     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3491   return _pfls[pflId];
3492 }
3493
3494 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3495 {
3496   if(locId<0 || locId>=(int)_locs.size())
3497     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3498   return *_locs[locId];
3499 }
3500
3501 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3502 {
3503   return getLocalizationFromId(getLocalizationId(locName));
3504 }
3505
3506 /*!
3507  * The returned value is never null.
3508  */
3509 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3510 {
3511   std::string pflNameCpp(pflName);
3512   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3513   if(it==_pfls.end())
3514     {
3515       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3516       for(it=_pfls.begin();it!=_pfls.end();it++)
3517         oss << "\"" << (*it)->getName() << "\", ";
3518       throw INTERP_KERNEL::Exception(oss.str());
3519     }
3520   return *it;
3521 }
3522
3523 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3524 {
3525   if(pflId<0 || pflId>=(int)_pfls.size())
3526     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3527   return _pfls[pflId];
3528 }
3529
3530 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3531 {
3532   std::vector< MCAuto<DataArrayInt> > newPfls;
3533   int i=0;
3534   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3535     {
3536       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3537         newPfls.push_back(*it);
3538     }
3539   _pfls=newPfls;
3540 }
3541
3542 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3543 {
3544   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3545   int i=0;
3546   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3547     {
3548       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3549         newLocs.push_back(*it);
3550     }
3551   _locs=newLocs;
3552 }
3553
3554 void MEDFileFieldGlobs::killStructureElementsInGlobs()
3555 {
3556   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3557   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3558     {
3559       if((*it).isNull())
3560         continue;
3561       if(!(*it)->isOnStructureElement())
3562         newLocs.push_back(*it);
3563     }
3564   _locs=newLocs;
3565 }
3566
3567 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3568 {
3569   int sz=_pfls.size();
3570   std::vector<std::string> ret(sz);
3571   for(int i=0;i<sz;i++)
3572     ret[i]=_pfls[i]->getName();
3573   return ret;
3574 }
3575
3576 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3577 {
3578   int sz=_locs.size();
3579   std::vector<std::string> ret(sz);
3580   for(int i=0;i<sz;i++)
3581     ret[i]=_locs[i]->getName();
3582   return ret;
3583 }
3584
3585 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3586 {
3587   std::vector<std::string> v=getPfls();
3588   std::string s(pflName);
3589   return std::find(v.begin(),v.end(),s)!=v.end();
3590 }
3591
3592 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3593 {
3594   std::vector<std::string> v=getLocs();
3595   std::string s(locName);
3596   return std::find(v.begin(),v.end(),s)!=v.end();
3597 }
3598
3599 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3600 {
3601   std::map<int,std::vector<int> > m;
3602   int i=0;
3603   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3604     {
3605       const DataArrayInt *tmp=(*it);
3606       if(tmp)
3607         {
3608           m[tmp->getHashCode()].push_back(i);
3609         }
3610     }
3611   std::vector< std::vector<int> > ret;
3612   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3613     {
3614       if((*it2).second.size()>1)
3615         {
3616           std::vector<int> ret0;
3617           bool equalityOrNot=false;
3618           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3619             {
3620               std::vector<int>::const_iterator it4=it3; it4++;
3621               for(;it4!=(*it2).second.end();it4++)
3622                 {
3623                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3624                     {
3625                       if(!equalityOrNot)
3626                         ret0.push_back(*it3);
3627                       ret0.push_back(*it4);
3628                       equalityOrNot=true;
3629                     }
3630                 }
3631             }
3632           if(!ret0.empty())
3633             ret.push_back(ret0);
3634         }
3635     }
3636   return ret;
3637 }
3638
3639 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3640 {
3641   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3642 }
3643
3644 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3645 {
3646   std::string name(pfl->getName());
3647   if(name.empty())
3648     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3649   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3650     if(name==(*it)->getName())
3651       {
3652         if(!pfl->isEqual(*(*it)))
3653           {
3654             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3655             throw INTERP_KERNEL::Exception(oss.str());
3656           }
3657       }
3658   pfl->incrRef();
3659   _pfls.push_back(pfl);
3660 }
3661
3662 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)
3663 {
3664   std::string name(locName);
3665   if(name.empty())
3666     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3667   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3668   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3669     if((*it)->isName(locName))
3670       {
3671         if(!(*it)->isEqual(*obj,1e-12))
3672           {
3673             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3674             throw INTERP_KERNEL::Exception(oss.str());
3675           }
3676       }
3677   _locs.push_back(obj);
3678 }
3679
3680 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3681 {
3682   std::vector<std::string> names=getPfls();
3683   return CreateNewNameNotIn("NewPfl_",names);
3684 }
3685
3686 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3687 {
3688   std::vector<std::string> names=getLocs();
3689   return CreateNewNameNotIn("NewLoc_",names);
3690 }
3691
3692 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3693 {
3694   for(std::size_t sz=0;sz<100000;sz++)
3695     {
3696       std::ostringstream tryName;
3697       tryName << prefix << sz;
3698       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3699         return tryName.str();
3700     }
3701   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3702 }
3703
3704 /*!
3705  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3706  *  \param [in] fname - the file name.
3707  */
3708 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3709 {
3710 }
3711
3712 /*!
3713  * Creates an empty MEDFileFieldGlobsReal.
3714  */
3715 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3716 {
3717 }
3718
3719 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3720 {
3721   return 0;
3722 }
3723
3724 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3725 {
3726   std::vector<const BigMemoryObject *> ret;
3727   ret.push_back((const MEDFileFieldGlobs *)_globals);
3728   return ret;
3729 }
3730
3731 /*!
3732  * Returns a string describing profiles and Gauss points held in \a this.
3733  *  \return std::string - the description string.
3734  */
3735 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3736 {
3737   const MEDFileFieldGlobs *glob=_globals;
3738   std::ostringstream oss2; oss2 << glob;
3739   std::string stars(oss2.str().length(),'*');
3740   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3741   if(glob)
3742     glob->simpleRepr(oss);
3743   else
3744     oss << "NO GLOBAL INFORMATION !\n";
3745 }
3746
3747 void MEDFileFieldGlobsReal::resetContent()
3748 {
3749   _globals=MEDFileFieldGlobs::New();
3750 }
3751
3752 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
3753 {
3754   contentNotNull()->killStructureElementsInGlobs();
3755 }
3756
3757 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3758 {
3759 }
3760
3761 /*!
3762  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3763  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3764  */
3765 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3766 {
3767   _globals=other._globals;
3768 }
3769
3770 /*!
3771  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3772  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3773  */
3774 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3775 {
3776   const MEDFileFieldGlobs *otherg(other._globals);
3777   if(!otherg)
3778     return ;
3779   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3780 }
3781
3782 /*!
3783  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3784  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3785  */
3786 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3787 {
3788   const MEDFileFieldGlobs *otherg(other._globals);
3789   if(!otherg)
3790     return ;
3791   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3792 }
3793
3794 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3795 {
3796   _globals=other._globals;
3797   if((const MEDFileFieldGlobs *)_globals)
3798     _globals=other._globals->deepCopy();
3799 }
3800
3801 /*!
3802  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3803  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3804  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3805  *         \a this and \a other MEDFileFieldGlobsReal.
3806  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3807  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3808  */
3809 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3810 {
3811   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3812   if(thisGlobals==otherGlobals)
3813     return ;
3814   if(!thisGlobals)
3815     {
3816       _globals=other._globals;
3817       return ;
3818     }
3819   _globals->appendGlobs(*other._globals,eps);
3820 }
3821
3822 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3823 {
3824   checkGlobsPflsPartCoherency();
3825   checkGlobsLocsPartCoherency();
3826 }
3827
3828 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3829 {
3830   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3831 }
3832
3833 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3834 {
3835   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3836 }
3837
3838 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3839 {
3840   contentNotNull()->loadProfileInFile(fid,id,pflName);
3841 }
3842
3843 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3844 {
3845   contentNotNull()->loadProfileInFile(fid,id);
3846 }
3847
3848 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3849 {
3850   contentNotNull()->loadGlobals(fid,*this);
3851 }
3852
3853 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
3854 {
3855   contentNotNull()->loadAllGlobals(fid,entities);
3856 }
3857
3858 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3859 {
3860   contentNotNull()->writeGlobals(fid,opt);
3861 }
3862
3863 /*!
3864  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3865  * or getPflsReallyUsedMulti().
3866  *  \return std::vector<std::string> - a sequence of names of all profiles.
3867  */
3868 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3869 {
3870   return contentNotNull()->getPfls();
3871 }
3872
3873 /*!
3874  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3875  * or getLocsReallyUsedMulti().
3876  *  \return std::vector<std::string> - a sequence of names of all localizations.
3877  */
3878 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3879 {
3880   return contentNotNull()->getLocs();
3881 }
3882
3883 /*!
3884  * Checks if the profile with a given name exists.
3885  *  \param [in] pflName - the profile name of interest.
3886  *  \return bool - \c true if the profile named \a pflName exists.
3887  */
3888 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3889 {
3890   return contentNotNull()->existsPfl(pflName);
3891 }
3892
3893 /*!
3894  * Checks if the localization with a given name exists.
3895  *  \param [in] locName - the localization name of interest.
3896  *  \return bool - \c true if the localization named \a locName exists.
3897  */
3898 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3899 {
3900   return contentNotNull()->existsLoc(locName);
3901 }
3902
3903 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3904 {
3905   return contentNotNull()->createNewNameOfPfl();
3906 }
3907
3908 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3909 {
3910   return contentNotNull()->createNewNameOfLoc();
3911 }
3912
3913 /*!
3914  * Sets the name of a MED file.
3915  *  \param [inout] fileName - the file name.
3916  */
3917 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3918 {
3919   contentNotNull()->setFileName(fileName);
3920 }
3921
3922 /*!
3923  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3924  * in the same order.
3925  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3926  *          Each item of this sequence is a vector containing ids of equal profiles.
3927  */
3928 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3929 {
3930   return contentNotNull()->whichAreEqualProfiles();
3931 }
3932
3933 /*!
3934  * Finds equal localizations.
3935  *  \param [in] eps - a precision used to compare real values of the localizations.
3936  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3937  *          Each item of this sequence is a vector containing ids of equal localizations.
3938  */
3939 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3940 {
3941   return contentNotNull()->whichAreEqualLocs(eps);
3942 }
3943
3944 /*!
3945  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3946  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3947  *        this sequence is a pair whose 
3948  *        - the first item is a vector of profile names to replace by the second item,
3949  *        - the second item is a profile name to replace every profile name of the first item.
3950  */
3951 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3952 {
3953   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3954 }
3955
3956 /*!
3957  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3958  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3959  *        this sequence is a pair whose 
3960  *        - the first item is a vector of localization names to replace by the second item,
3961  *        - the second item is a localization name to replace every localization name of the first item.
3962  */
3963 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3964 {
3965   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3966 }
3967
3968 /*!
3969  * Replaces references to some profiles (a reference is a profile name) by references
3970  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3971  * them-selves accordingly. <br>
3972  * This method is a generalization of changePflName().
3973  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3974  *        this sequence is a pair whose 
3975  *        - the first item is a vector of profile names to replace by the second item,
3976  *        - the second item is a profile name to replace every profile of the first item.
3977  * \sa changePflsRefsNamesGen()
3978  * \sa changePflName()
3979  */
3980 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3981 {
3982   changePflsRefsNamesGen(mapOfModif);
3983   changePflsNamesInStruct(mapOfModif);
3984 }
3985
3986 /*!
3987  * Replaces references to some localizations (a reference is a localization name) by references
3988  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3989  * them-selves accordingly. <br>
3990  * This method is a generalization of changeLocName().
3991  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3992  *        this sequence is a pair whose 
3993  *        - the first item is a vector of localization names to replace by the second item,
3994  *        - the second item is a localization name to replace every localization of the first item.
3995  * \sa changeLocsRefsNamesGen()
3996  * \sa changeLocName()
3997  */
3998 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3999 {
4000   changeLocsRefsNamesGen(mapOfModif);
4001   changeLocsNamesInStruct(mapOfModif);
4002 }
4003
4004 /*!
4005  * Renames the profile having a given name and updates references to this profile.
4006  *  \param [in] oldName - the name of the profile to rename.
4007  *  \param [in] newName - a new name of the profile.
4008  * \sa changePflsNames().
4009  */
4010 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
4011 {
4012   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4013   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4014   mapOfModif[0]=p;
4015   changePflsNames(mapOfModif);
4016 }
4017
4018 /*!
4019  * Renames the localization having a given name and updates references to this localization.
4020  *  \param [in] oldName - the name of the localization to rename.
4021  *  \param [in] newName - a new name of the localization.
4022  * \sa changeLocsNames().
4023  */
4024 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
4025 {
4026   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
4027   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
4028   mapOfModif[0]=p;
4029   changeLocsNames(mapOfModif);
4030 }
4031
4032 /*!
4033  * Removes duplicated profiles. Returns a map used to update references to removed 
4034  * profiles via changePflsRefsNamesGen().
4035  * Equal profiles are found using whichAreEqualProfiles().
4036  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4037  *          a sequence describing the performed replacements of profiles. Each element of
4038  *          this sequence is a pair whose
4039  *          - the first item is a vector of profile names replaced by the second item,
4040  *          - the second item is a profile name replacing every profile of the first item.
4041  */
4042 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
4043 {
4044   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
4045   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4046   int i=0;
4047   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4048     {
4049       std::vector< std::string > tmp((*it).size());
4050       int j=0;
4051       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4052         tmp[j]=std::string(getProfileFromId(*it2)->getName());
4053       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4054       ret[i]=p;
4055       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4056       killProfileIds(tmp2);
4057     }
4058   changePflsRefsNamesGen(ret);
4059   return ret;
4060 }
4061
4062 /*!
4063  * Removes duplicated localizations. Returns a map used to update references to removed 
4064  * localizations via changeLocsRefsNamesGen().
4065  * Equal localizations are found using whichAreEqualLocs().
4066  *  \param [in] eps - a precision used to compare real values of the localizations.
4067  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
4068  *          a sequence describing the performed replacements of localizations. Each element of
4069  *          this sequence is a pair whose
4070  *          - the first item is a vector of localization names replaced by the second item,
4071  *          - the second item is a localization name replacing every localization of the first item.
4072  */
4073 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
4074 {
4075   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
4076   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
4077   int i=0;
4078   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
4079     {
4080       std::vector< std::string > tmp((*it).size());
4081       int j=0;
4082       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
4083         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
4084       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
4085       ret[i]=p;
4086       std::vector<int> tmp2((*it).begin()+1,(*it).end());
4087       killLocalizationIds(tmp2);
4088     }
4089   changeLocsRefsNamesGen(ret);
4090   return ret;
4091 }
4092
4093 /*!
4094  * Returns number of Gauss points per cell in a given localization.
4095  *  \param [in] locId - an id of the localization of interest.
4096  *  \return int - the number of the Gauss points per cell.
4097  */
4098 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
4099 {
4100   return contentNotNull()->getNbOfGaussPtPerCell(locId);
4101 }
4102
4103 /*!
4104  * Returns an id of a localization by its name.
4105  *  \param [in] loc - the localization name of interest.
4106  *  \return int - the id of the localization.
4107  *  \throw If there is no a localization named \a loc.
4108  */
4109 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
4110 {
4111   return contentNotNull()->getLocalizationId(loc);
4112 }
4113
4114 /*!
4115  * Returns the name of the MED file.
4116  *  \return const std::string&  - the MED file name.
4117  */
4118 std::string MEDFileFieldGlobsReal::getFileName() const
4119 {
4120   return contentNotNull()->getFileName();
4121 }
4122
4123 /*!
4124  * Returns a localization object by its name.
4125  *  \param [in] locName - the name of the localization of interest.
4126  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
4127  *  \throw If there is no a localization named \a locName.
4128  */
4129 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
4130 {
4131   return contentNotNull()->getLocalization(locName);
4132 }
4133
4134 /*!
4135  * Returns a localization object by its id.
4136  *  \param [in] locId - the id of the localization of interest.
4137  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
4138  *  \throw If there is no a localization with id \a locId.
4139  */
4140 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
4141 {
4142   return contentNotNull()->getLocalizationFromId(locId);
4143 }
4144
4145 /*!
4146  * Returns a profile array by its name.
4147  *  \param [in] pflName - the name of the profile of interest.
4148  *  \return const DataArrayInt * - the profile array having the name \a pflName.
4149  *  \throw If there is no a profile named \a pflName.
4150  */
4151 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
4152 {
4153   return contentNotNull()->getProfile(pflName);
4154 }
4155
4156 /*!
4157  * Returns a profile array by its id.
4158  *  \param [in] pflId - the id of the profile of interest.
4159  *  \return const DataArrayInt * - the profile array having the id \a pflId.
4160  *  \throw If there is no a profile with id \a pflId.
4161  */
4162 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
4163 {
4164   return contentNotNull()->getProfileFromId(pflId);
4165 }
4166
4167 /*!
4168  * Returns a localization object, apt for modification, by its id.
4169  *  \param [in] locId - the id of the localization of interest.
4170  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4171  *          having the id \a locId.
4172  *  \throw If there is no a localization with id \a locId.
4173  */
4174 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
4175 {
4176   return contentNotNull()->getLocalizationFromId(locId);
4177 }
4178
4179 /*!
4180  * Returns a localization object, apt for modification, by its name.
4181  *  \param [in] locName - the name of the localization of interest.
4182  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4183  *          having the name \a locName.
4184  *  \throw If there is no a localization named \a locName.
4185  */
4186 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
4187 {
4188   return contentNotNull()->getLocalization(locName);
4189 }
4190
4191 /*!
4192  * Returns a profile array, apt for modification, by its name.
4193  *  \param [in] pflName - the name of the profile of interest.
4194  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
4195  *  \throw If there is no a profile named \a pflName.
4196  */
4197 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
4198 {
4199   return contentNotNull()->getProfile(pflName);
4200 }
4201
4202 /*!
4203  * Returns a profile array, apt for modification, by its id.
4204  *  \param [in] pflId - the id of the profile of interest.
4205  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
4206  *  \throw If there is no a profile with id \a pflId.
4207  */
4208 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
4209 {
4210   return contentNotNull()->getProfileFromId(pflId);
4211 }
4212
4213 /*!
4214  * Removes profiles given by their ids. No data is updated to track this removal.
4215  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
4216  */
4217 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
4218 {
4219   contentNotNull()->killProfileIds(pflIds);
4220 }
4221
4222 /*!
4223  * Removes localizations given by their ids. No data is updated to track this removal.
4224  *  \param [in] locIds - a sequence of ids of the localizations to remove.
4225  */
4226 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
4227 {
4228   contentNotNull()->killLocalizationIds(locIds);
4229 }
4230
4231 /*!
4232  * Stores a profile array.
4233  *  \param [in] pfl - the profile array to store.
4234  *  \throw If the name of \a pfl is empty.
4235  *  \throw If a profile with the same name as that of \a pfl already exists but contains
4236  *         different ids.
4237  */
4238 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
4239 {
4240   contentNotNull()->appendProfile(pfl);
4241 }
4242
4243 /*!
4244  * Adds a new localization of Gauss points.
4245  *  \param [in] locName - the name of the new localization.
4246  *  \param [in] geoType - a geometrical type of the reference cell.
4247  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
4248  *         must be \c nbOfNodesPerCell * \c dimOfType.
4249  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
4250  *         must be  _wg_.size() * \c dimOfType.
4251  *  \param [in] w - the weights of Gauss points.
4252  *  \throw If \a locName is empty.
4253  *  \throw If a localization with the name \a locName already exists but is
4254  *         different form the new one.
4255  */
4256 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)
4257 {
4258   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
4259 }
4260
4261 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
4262 {
4263   MEDFileFieldGlobs *g(_globals);
4264   if(!g)
4265     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
4266   return g;
4267 }
4268
4269 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
4270 {
4271   const MEDFileFieldGlobs *g(_globals);
4272   if(!g)
4273     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4274   return g;
4275 }
4276
4277 //= MEDFileFieldNameScope
4278
4279 MEDFileFieldNameScope::MEDFileFieldNameScope()
4280 {
4281 }
4282
4283 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName):_name(fieldName),_mesh_name(meshName)
4284 {
4285 }
4286
4287 /*!
4288  * Returns the name of \a this field.
4289  *  \return std::string - a string containing the field name.
4290  */
4291 std::string MEDFileFieldNameScope::getName() const
4292 {
4293   return _name;
4294 }
4295
4296 /*!
4297  * Sets name of \a this field
4298  *  \param [in] name - the new field name.
4299  */
4300 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4301 {
4302   _name=fieldName;
4303 }
4304
4305 std::string MEDFileFieldNameScope::getDtUnit() const
4306 {
4307   return _dt_unit;
4308 }
4309
4310 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4311 {
4312   _dt_unit=dtUnit;
4313 }
4314
4315 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4316 {
4317   _name=other._name;
4318   _mesh_name=other._mesh_name;
4319   _dt_unit=other._dt_unit;
4320 }
4321
4322 /*!
4323  * Returns the mesh name.
4324  *  \return std::string - a string holding the mesh name.
4325  *  \throw If \c _field_per_mesh.empty()
4326  */
4327 std::string MEDFileFieldNameScope::getMeshName() const
4328 {
4329   return _mesh_name;
4330 }
4331
4332 void MEDFileFieldNameScope::setMeshName(const std::string& meshName)
4333 {
4334   _mesh_name=meshName;
4335 }
4336
4337 //= MEDFileAnyTypeField1TSWithoutSDA
4338
4339 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4340 {
4341   _field_per_mesh.resize(other._field_per_mesh.size());
4342   std::size_t i=0;
4343   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4344     {
4345       if((const MEDFileFieldPerMesh *)*it)
4346         _field_per_mesh[i]=(*it)->deepCopy(this);
4347     }
4348 }
4349
4350 void MEDFileAnyTypeField1TSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
4351 {
4352   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4353     if((*it).isNotNull())
4354       {
4355         visitor.newMeshEntry(*it);
4356         (*it)->accept(visitor);
4357         visitor.endMeshEntry(*it);
4358       }
4359 }
4360
4361 /*!
4362  * Prints a string describing \a this field into a stream. This string is outputted 
4363  * by \c print Python command.
4364  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4365  *  \param [in,out] oss - the out stream.
4366  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4367  *          info id printed, else, not.
4368  */
4369 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4370 {
4371   std::string startOfLine(bkOffset,' ');
4372   oss << startOfLine << "Field ";
4373   if(bkOffset==0)
4374     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4375   oss << "on one time Step ";
4376   if(f1tsId>=0)
4377     oss << "(" << f1tsId << ") ";
4378   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4379   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4380   const DataArray *arr=getUndergroundDataArray();
4381   if(arr)
4382     {
4383       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4384       if(f1tsId<0)
4385         {
4386           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4387           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4388             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4389         }
4390       if(arr->isAllocated())
4391         {
4392           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4393         }
4394       else
4395         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4396     }
4397   else
4398     {
4399       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4400     }
4401   oss << startOfLine << "----------------------" << std::endl;
4402   if(!_field_per_mesh.empty())
4403     {
4404       int i=0;
4405       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4406         {
4407           const MEDFileFieldPerMesh *cur=(*it2);
4408           if(cur)
4409             cur->simpleRepr(bkOffset,oss,i);
4410           else
4411             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4412         }
4413     }
4414   else
4415     {
4416       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4417     }
4418   oss << startOfLine << "----------------------" << std::endl;
4419 }
4420
4421 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4422 {
4423   const DataArray *arr(getUndergroundDataArray());
4424   if(!arr)
4425     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4426   int nbOfCompo=arr->getNumberOfComponents();
4427   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4428   for(int i=0;i<nbOfCompo;i++)
4429     {
4430       ret[i]=deepCopy();
4431       std::vector<int> v(1,i);
4432       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4433       ret[i]->setArray(arr2);
4434     }
4435   return ret;
4436 }
4437
4438 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)
4439 {
4440 }
4441
4442 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4443 {
4444 }
4445
4446 /*!
4447  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4448  * empty. Returns -1 if this in on nodes.
4449  *  \return int - the dimension of \a this.
4450  */
4451 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4452 {
4453   int ret=-2;
4454   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4455     (*it)->getDimension(ret);
4456   return ret;
4457 }
4458
4459 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4460 {
4461   bool ret=false;
4462   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4463     {
4464       MEDFileFieldPerMesh *cur(*it);
4465       if(cur)
4466         ret=cur->changeMeshNames(modifTab) || ret;
4467     }
4468   return ret;
4469 }
4470
4471 /*!
4472  * Returns the number of iteration of the state of underlying mesh.
4473  *  \return int - the iteration number.
4474  *  \throw If \c _field_per_mesh.empty()
4475  */
4476 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4477 {
4478   if(_field_per_mesh.empty())
4479     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4480   return _field_per_mesh[0]->getMeshIteration();
4481 }
4482
4483 /*!
4484  * Returns the order number of iteration of the state of underlying mesh.
4485  *  \return int - the order number.
4486  *  \throw If \c _field_per_mesh.empty()
4487  */
4488 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4489 {
4490   if(_field_per_mesh.empty())
4491     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4492   return _field_per_mesh[0]->getMeshOrder();
4493 }
4494
4495 /*!
4496  * Checks if \a this field is tagged by a given iteration number and a given
4497  * iteration order number.
4498  *  \param [in] iteration - the iteration number of interest.
4499  *  \param [in] order - the iteration order number of interest.
4500  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4501  *          \a this->getOrder() == \a order.
4502  */
4503 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4504 {
4505   return iteration==_iteration && order==_order;
4506 }
4507
4508 /*!
4509  * Returns number of iteration and order number of iteration when
4510  * \a this field has been calculated.
4511  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4512  *          order number.
4513  */
4514 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4515 {
4516   std::pair<int,int> p;
4517   fillIteration(p);
4518   return p;
4519 }
4520
4521 /*!
4522  * Returns number of iteration and order number of iteration when
4523  * \a this field has been calculated.
4524  *  \param [in,out] p - a pair returning the iteration number and the iteration
4525  *          order number.
4526  */
4527 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4528 {
4529   p.first=_iteration;
4530   p.second=_order;
4531 }
4532
4533 /*!
4534  * Returns all types of spatial discretization of \a this field.
4535  *  \param [in,out] types - a sequence of types of \a this field.
4536  */
4537 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4538 {
4539   std::set<TypeOfField> types2;
4540   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4541     {
4542       (*it)->fillTypesOfFieldAvailable(types2);
4543     }
4544   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4545   std::copy(types2.begin(),types2.end(),bi);
4546 }
4547
4548 /*!
4549  * Returns all types of spatial discretization of \a this field.
4550  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4551  *          of \a this field.
4552  */
4553 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4554 {
4555   std::vector<TypeOfField> ret;
4556   fillTypesOfFieldAvailable(ret);
4557   return ret;
4558 }
4559
4560 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4561 {
4562   std::vector<std::string> ret;
4563   std::set<std::string> ret2;
4564   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4565     {
4566       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4567       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4568         if(ret2.find(*it2)==ret2.end())
4569           {
4570             ret.push_back(*it2);
4571             ret2.insert(*it2);
4572           }
4573     }
4574   return ret;
4575 }
4576
4577 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4578 {
4579   std::vector<std::string> ret;
4580   std::set<std::string> ret2;
4581   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4582     {
4583       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4584       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4585         if(ret2.find(*it2)==ret2.end())
4586           {
4587             ret.push_back(*it2);
4588             ret2.insert(*it2);
4589           }
4590     }
4591   return ret;
4592 }
4593
4594 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4595 {
4596   std::vector<std::string> ret;
4597   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4598     {
4599       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4600       ret.insert(ret.end(),tmp.begin(),tmp.end());
4601     }
4602   return ret;
4603 }
4604
4605 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4606 {
4607   std::vector<std::string> ret;
4608   std::set<std::string> ret2;
4609   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4610     {
4611       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4612       ret.insert(ret.end(),tmp.begin(),tmp.end());
4613     }
4614   return ret;
4615 }
4616
4617 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4618 {
4619   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4620     (*it)->changePflsRefsNamesGen(mapOfModif);
4621 }
4622
4623 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4624 {
4625   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4626     (*it)->changeLocsRefsNamesGen(mapOfModif);
4627 }
4628
4629 /*!
4630  * Returns all attributes of parts of \a this field lying on a given mesh.
4631  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4632  * item of every of returned sequences refers to the _i_-th part of \a this field.
4633  * Thus all sequences returned by this method are of the same length equal to number
4634  * of different types of supporting entities.<br>
4635  * A field part can include sub-parts with several different spatial discretizations,
4636  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4637  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4638  * of a nested sequence corresponds to a type of spatial discretization.<br>
4639  * This method allows for iteration over MEDFile DataStructure without any overhead.
4640  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4641  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4642  *          not checked if \a mname == \c NULL).
4643  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4644  *          a field part is returned. 
4645  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4646  *          This sequence is of the same length as \a types. 
4647  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4648  *          discretization. A profile name can be empty.
4649  *          Length of this and of nested sequences is the same as that of \a typesF.
4650  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4651  *          discretization. A localization name can be empty.
4652  *          Length of this and of nested sequences is the same as that of \a typesF.
4653  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4654  *          of ids of tuples within the data array, per each type of spatial
4655  *          discretization within one mesh entity type. 
4656  *          Length of this and of nested sequences is the same as that of \a typesF.
4657  *  \throw If no field is lying on \a mname.
4658  */
4659 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
4660 {
4661   if(_field_per_mesh.empty())
4662     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4663   return _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4664 }
4665
4666 /*!
4667  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4668  * maximal absolute dimension and values returned via the out parameter \a levs are 
4669  * dimensions relative to the maximal absolute dimension. <br>
4670  * This method is designed for MEDFileField1TS instances that have a discretization
4671  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4672  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4673  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4674  * Only these 3 discretizations will be taken into account here. If \a this is
4675  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4676  * This method is useful to make the link between the dimension of the underlying mesh
4677  * and the levels of \a this, because it is possible that the highest dimension of \a this
4678  * field is not equal to the dimension of the underlying mesh.
4679  * 
4680  * Let's consider the following case:
4681  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4682  * TETRA4, HEXA8, TRI3 and SEG2.
4683  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4684  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4685  *
4686  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4687  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4688  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4689  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4690  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4691  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4692  * For example<br>
4693  * to retrieve the highest level of
4694  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4695  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4696  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4697  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4698  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4699  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4700  *          not checked if \a mname == \c NULL).
4701  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4702  *          absolute one. They are in decreasing order. This sequence is cleared before
4703  *          filling it in.
4704  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4705  *  \throw If no field is lying on \a mname.
4706  */
4707 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4708 {
4709   levs.clear();
4710   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4711   std::vector< std::vector<TypeOfField> > typesF;
4712   std::vector< std::vector<std::string> > pfls, locs;
4713   if(_field_per_mesh.empty())
4714     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels : This is empty !");
4715   _field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
4716   if(types.empty())
4717     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4718   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4719   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4720     return -1;
4721   st.erase(INTERP_KERNEL::NORM_ERROR);
4722   std::set<int> ret1;
4723   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4724     {
4725       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4726       ret1.insert((int)cm.getDimension());
4727     }
4728   int ret=*std::max_element(ret1.begin(),ret1.end());
4729   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4730   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4731   return ret;
4732 }
4733
4734 void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic()
4735 {
4736   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it<_field_per_mesh.end();it++)
4737     if((*it).isNotNull())
4738       (*it)->convertMedBallIntoClassic();
4739 }
4740
4741 void MEDFileAnyTypeField1TSWithoutSDA::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
4742 {
4743   if(!pfl)
4744     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : null pfl !");
4745   std::string name(pfl->getName());
4746   pfl->checkAllocated();
4747   if(pfl->getNumberOfComponents()!=1)
4748     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : non mono compo array !");
4749   if(name.empty())
4750     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : empty pfl name !");
4751   if(_field_per_mesh.size()!=1)
4752     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single mesh supported !");
4753   MCAuto<MEDFileFieldPerMesh> fpm(_field_per_mesh[0]);
4754   if(fpm.isNull())
4755     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : only single not null mesh supported !");
4756   MEDFileFieldPerMeshPerTypePerDisc *disc(fpm->getLeafGivenTypeAndLocId(ct,0));
4757   if(disc->getType()!=tof)
4758     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : error !");
4759   int s(disc->getStart()),e(disc->getEnd()),nt(pfl->getNumberOfTuples());
4760   DataArray *arr(getUndergroundDataArray());
4761   int nt2(arr->getNumberOfTuples()),delta((e-s)-nt);
4762   if(delta<0)
4763     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::makeReduction : internal error !");
4764   MCAuto<DataArray> arr0(arr->selectByTupleIdSafeSlice(0,s,1)),arr1(arr->selectByTupleIdSafeSlice(s,e,1)),arr2(arr->selectByTupleIdSafeSlice(e,nt2,1));
4765   MCAuto<DataArray> arr11(arr1->selectByTupleIdSafe(pfl->begin(),pfl->end()));
4766   MCAuto<DataArray> arrOut(arr->buildNewEmptyInstance());
4767   arrOut->alloc(nt2-delta,arr->getNumberOfComponents());
4768   arrOut->copyStringInfoFrom(*arr);
4769   arrOut->setContigPartOfSelectedValuesSlice(0,arr0,0,s,1);
4770   arrOut->setContigPartOfSelectedValuesSlice(s,arr11,0,nt,1);
4771   arrOut->setContigPartOfSelectedValuesSlice(e-delta,arr2,0,nt2-e,1);
4772   setArray(arrOut);
4773   disc->setEnd(e-delta);
4774   disc->setProfile(name);
4775 }
4776
4777 /*!
4778  * \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.
4779  * \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.
4780  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4781  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4782  */
4783 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4784 {
4785   if(_field_per_mesh.empty())
4786     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4787   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4788 }
4789
4790 /*!
4791  * \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.
4792  * \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.
4793  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4794  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4795  */
4796 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4797 {
4798   if(_field_per_mesh.empty())
4799     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId : This is empty !");
4800   return _field_per_mesh[0]->getLeafGivenTypeAndLocId(typ,locId);
4801 }
4802
4803 /*!
4804  * \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.
4805  */
4806 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4807 {
4808   if(_field_per_mesh.empty())
4809     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4810   if(mName.empty())
4811     return 0;
4812   std::string mName2(mName);
4813   int ret=0;
4814   std::vector<std::string> msg;
4815   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4816     if(mName2==(*it)->getMeshName())
4817       return ret;
4818     else
4819       msg.push_back((*it)->getMeshName());
4820   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4821   oss << "Possible meshes are : ";
4822   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4823     oss << "\"" << (*it2) << "\" ";
4824   throw INTERP_KERNEL::Exception(oss.str());
4825 }
4826
4827 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4828 {
4829   if(!mesh)
4830     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4831   std::string tmp(mesh->getName());
4832   if(tmp.empty())
4833     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4834   setMeshName(tmp);
4835   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4836   int i=0;
4837   for(;it!=_field_per_mesh.end();it++,i++)
4838     {
4839       if((*it)->getMeshName()==tmp)
4840         return i;
4841     }
4842   int sz=_field_per_mesh.size();
4843   _field_per_mesh.resize(sz+1);
4844   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4845   return sz;
4846 }
4847
4848 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4849                                                                    MEDFileFieldGlobsReal& glob)
4850 {
4851   bool ret=false;
4852   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4853     {
4854       MEDFileFieldPerMesh *fpm(*it);
4855       if(fpm)
4856         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4857     }
4858   return ret;
4859 }
4860
4861 /*!
4862  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4863  * splitting that leads to single spatial discretization of this.
4864  *
4865  * \sa splitMultiDiscrPerGeoTypes
4866  */
4867 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4868 {
4869   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4870   std::vector< std::vector<TypeOfField> > typesF;
4871   std::vector< std::vector<std::string> > pfls,locs;
4872   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4873   std::set<TypeOfField> allEnt;
4874   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4875     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4876       allEnt.insert(*it2);
4877   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4878   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4879   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4880     {
4881       std::vector< std::pair<int,int> > its;
4882       ret[i]=shallowCpy();
4883       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4884       ret[i]->updateData(newLgth,its);
4885     }
4886   return ret;
4887 }
4888
4889 /*!
4890  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4891  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4892  *
4893  * \sa splitDiscretizations
4894  */
4895 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4896 {
4897   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4898   std::vector< std::vector<TypeOfField> > typesF;
4899   std::vector< std::vector<std::string> > pfls,locs;
4900   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4901   std::set<TypeOfField> allEnt;
4902   std::size_t nbOfMDPGT(0),ii(0);
4903   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4904     {
4905       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4906       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4907         allEnt.insert(*it2);
4908     }
4909   if(allEnt.size()!=1)
4910     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4911   if(nbOfMDPGT==0)
4912     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4913   if(nbOfMDPGT==1)
4914     {
4915       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4916       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4917       return ret0;
4918     }
4919   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4920   for(std::size_t i=0;i<nbOfMDPGT;i++)
4921     {
4922       std::vector< std::pair<int,int> > its;
4923       ret[i]=shallowCpy();
4924       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4925       ret[i]->updateData(newLgth,its);
4926     }
4927   return ret;
4928 }
4929
4930 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4931 {
4932   int globalCounter(0);
4933   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4934     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4935   return globalCounter;
4936 }
4937
4938 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4939 {
4940   int globalCounter(0);
4941   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4942     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4943   return globalCounter;
4944 }
4945
4946 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4947 {
4948   if(_nb_of_tuples_to_be_allocated>=0)
4949     {
4950       _nb_of_tuples_to_be_allocated=newLgth;
4951       const DataArray *oldArr(getUndergroundDataArray());
4952       if(oldArr)
4953         {
4954           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4955           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4956           setArray(newArr);
4957           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4958         }
4959       return ;
4960     }
4961   if(_nb_of_tuples_to_be_allocated==-1)
4962     return ;
4963   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4964     {
4965       const DataArray *oldArr(getUndergroundDataArray());
4966       if(!oldArr || !oldArr->isAllocated())
4967         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4968       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4969       newArr->alloc(newLgth,getNumberOfComponents());
4970       if(oldArr)
4971         newArr->copyStringInfoFrom(*oldArr);
4972       int pos=0;
4973       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4974         {
4975           if((*it).second<(*it).first)
4976             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4977           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4978           pos+=(*it).second-(*it).first;
4979         }
4980       setArray(newArr);
4981       return ;
4982     }
4983   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4984 }
4985
4986 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4987 {
4988   if(_field_per_mesh.empty())
4989     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4990   if(_field_per_mesh.size()>1)
4991     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4992   _field_per_mesh[0]->copyOptionsFrom(opts);
4993   _field_per_mesh[0]->writeLL(fid,nasc);
4994 }
4995
4996 /*!
4997  * 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.
4998  * If false is returned the memory allocation is not required.
4999  */
5000 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
5001 {
5002   if(_nb_of_tuples_to_be_allocated>=0)
5003     {
5004       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
5005       _nb_of_tuples_to_be_allocated=-2;
5006       return true;
5007     }
5008   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
5009     return false;
5010   if(_nb_of_tuples_to_be_allocated==-1)
5011     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
5012   if(_nb_of_tuples_to_be_allocated<-3)
5013     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5014   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
5015 }
5016
5017 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5018 {
5019   med_int numdt,numit;
5020   med_float dt;
5021   med_int meshnumdt,meshnumit;
5022   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
5023   {
5024     med_bool localMesh;
5025     med_int nmesh;
5026     INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
5027     MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit)); // to check with Adrien for legacy MED files
5028   }
5029   //MEDFILESAFECALLERRD0(MEDfieldComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt,&meshnumdt,&meshnumit));
5030   if(_iteration!=numdt || _order!=numit)
5031     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
5032   _field_per_mesh.resize(1);
5033   //
5034   MEDFileMesh *mm(0);
5035   if(ms)
5036     {
5037       mm=ms->getMeshWithName(getMeshName());
5038     }
5039   //
5040   _field_per_mesh[0]=MEDFileFieldPerMesh::NewOnRead(fid,this,0,meshnumdt,meshnumit,nasc,mm,entities);
5041   _nb_of_tuples_to_be_allocated=0;
5042   _field_per_mesh[0]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
5043 }
5044
5045 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
5046 {
5047   allocIfNecessaryTheArrayToReceiveDataFromFile();
5048   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5049     (*it)->loadBigArraysRecursively(fid,nasc);
5050 }
5051
5052 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
5053 {
5054   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
5055     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5056       (*it)->loadBigArraysRecursively(fid,nasc);
5057 }
5058
5059 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5060 {
5061   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
5062   loadBigArraysRecursively(fid,nasc);
5063 }
5064
5065 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
5066 {
5067   DataArray *thisArr(getUndergroundDataArray());
5068   if(thisArr && thisArr->isAllocated())
5069     {
5070       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
5071       thisArr->desallocate();
5072     }
5073 }
5074
5075 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
5076 {
5077   return _mesh_name.capacity()+_dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
5078 }
5079
5080 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
5081 {
5082   std::vector<const BigMemoryObject *> ret;
5083   if(getUndergroundDataArray())
5084     ret.push_back(getUndergroundDataArray());
5085   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5086     ret.push_back((const MEDFileFieldPerMesh *)*it);
5087   return ret;
5088 }
5089
5090 /*!
5091  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
5092  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
5093  * "Sort By Type"), if not, an exception is thrown. 
5094  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
5095  *  \param [in] arr - the array of values.
5096  *  \param [in,out] glob - the global data where profiles and localization present in
5097  *          \a field, if any, are added.
5098  *  \throw If the name of \a field is empty.
5099  *  \throw If the data array of \a field is not set.
5100  *  \throw If \a this->_arr is already allocated but has different number of components
5101  *         than \a field.
5102  *  \throw If the underlying mesh of \a field has no name.
5103  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
5104  */
5105 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5106 {
5107   const MEDCouplingMesh *mesh=field->getMesh();
5108   //
5109   TypeOfField type=field->getTypeOfField();
5110   std::vector<DataArrayInt *> dummy;
5111   if(mesh)
5112     setMeshName(mesh->getName());
5113   int start=copyTinyInfoFrom(field,arr);
5114   int pos=addNewEntryIfNecessary(mesh);
5115   if(type!=ON_NODES)
5116     {
5117       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
5118       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
5119     }
5120   else
5121     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
5122 }
5123
5124 /*!
5125  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
5126  * of a given mesh are used as the support of the given field (a real support is not used). 
5127  * Elements of the given mesh must be sorted suitable for writing to MED file. 
5128  * Order of underlying mesh entities of the given field specified by \a profile parameter
5129  * is not prescribed; this method permutes field values to have them sorted by element
5130  * type as required for writing to MED file. A new profile is added only if no equal
5131  * profile is missing. 
5132  *  \param [in] field - the field to add to \a this. The field double values are ignored.
5133  *  \param [in] arrOfVals - the values of the field \a field used.
5134  *  \param [in] mesh - the supporting mesh of \a field.
5135  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
5136  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
5137  *  \param [in,out] glob - the global data where profiles and localization present in
5138  *          \a field, if any, are added.
5139  *  \throw If either \a field or \a mesh or \a profile has an empty name.
5140  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5141  *  \throw If the data array of \a field is not set.
5142  *  \throw If \a this->_arr is already allocated but has different number of components
5143  *         than \a field.
5144  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5145  *  \sa setFieldNoProfileSBT()
5146  */
5147 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
5148 {
5149   if(!field)
5150     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
5151   if(!arrOfVals || !arrOfVals->isAllocated())
5152     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
5153   TypeOfField type=field->getTypeOfField();
5154   std::vector<DataArrayInt *> idsInPflPerType;
5155   std::vector<DataArrayInt *> idsPerType;
5156   std::vector<int> code,code2;
5157   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5158   if(type!=ON_NODES)
5159     {
5160       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
5161       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
5162       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
5163       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
5164       // start of check
5165       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
5166       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
5167       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5168         {
5169           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5170           throw INTERP_KERNEL::Exception(oss.str());
5171         }
5172       // end of check
5173       int start=copyTinyInfoFrom(field,arrOfVals);
5174       code2=m->getDistributionOfTypes();
5175       //
5176       int pos=addNewEntryIfNecessary(m);
5177       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
5178     }
5179   else
5180     {
5181       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
5182         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
5183       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
5184       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
5185       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
5186       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
5187         {
5188           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
5189           throw INTERP_KERNEL::Exception(oss.str());
5190         }
5191       int start=copyTinyInfoFrom(field,arrOfVals);
5192       int pos=addNewEntryIfNecessary(m);
5193       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
5194     }
5195 }
5196
5197 /*!
5198  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
5199  */
5200 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
5201 {
5202   if(_nb_of_tuples_to_be_allocated>=0)
5203     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 !");
5204   DataArray *arr(getOrCreateAndGetArray());
5205   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
5206   _nb_of_tuples_to_be_allocated=-3;
5207 }
5208
5209 /*!
5210  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
5211  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
5212  * larger by the size of \a field. Returns an id of the first not filled
5213  * tuple of \a this->_arr.
5214  *  \param [in] field - the field to copy the info on components and the name from.
5215  *  \return int - the id of first not initialized tuple of \a this->_arr.
5216  *  \throw If the name of \a field is empty.
5217  *  \throw If the data array of \a field is not set.
5218  *  \throw If \a this->_arr is already allocated but has different number of components
5219  *         than \a field.
5220  */
5221 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5222 {
5223   if(!field)
5224     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
5225   std::string name(field->getName());
5226   setName(name.c_str());
5227   if(field->getMesh())
5228     setMeshName(field->getMesh()->getName());
5229   setDtUnit(field->getTimeUnit());
5230   if(name.empty())
5231     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
5232   if(!arr)
5233     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
5234   if(!arr->isAllocated())
5235     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
5236   _dt=field->getTime(_iteration,_order);
5237   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
5238   if(!getOrCreateAndGetArray()->isAllocated())
5239     {
5240       allocNotFromFile(arr->getNumberOfTuples());
5241       return 0;
5242     }
5243   else
5244     {
5245       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
5246       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
5247       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
5248       _nb_of_tuples_to_be_allocated=-3;
5249       return oldNbOfTuples;
5250     }
5251 }
5252
5253 /*!
5254  * Returns number of components in \a this field
5255  *  \return int - the number of components.
5256  */
5257 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
5258 {
5259   return getOrCreateAndGetArray()->getNumberOfComponents();
5260 }
5261
5262 /*!
5263  * Change info on components in \a this.
5264  * \throw If size of \a infos is not equal to the number of components already in \a this.
5265  */
5266 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
5267 {
5268   DataArray *arr=getOrCreateAndGetArray();
5269   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
5270 }
5271
5272 /*!
5273  * Returns info on components of \a this field.
5274  *  \return const std::vector<std::string>& - a sequence of strings each being an
5275  *          information on _i_-th component.
5276  */
5277 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
5278 {
5279   const DataArray *arr=getOrCreateAndGetArray();
5280   return arr->getInfoOnComponents();
5281 }
5282
5283 /*!
5284  * Returns a mutable info on components of \a this field.
5285  *  \return std::vector<std::string>& - a sequence of strings each being an
5286  *          information on _i_-th component.
5287  */
5288 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
5289 {
5290   DataArray *arr=getOrCreateAndGetArray();
5291   return arr->getInfoOnComponents();
5292 }
5293
5294 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
5295 {
5296   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5297     {
5298       const MEDFileFieldPerMesh *fpm(*it);
5299       if(!fpm)
5300         continue;
5301       if(fpm->presenceOfMultiDiscPerGeoType())
5302         return true;
5303     }
5304   return false;
5305 }
5306
5307 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
5308 {
5309   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5310     if((*it).isNotNull())
5311       if((*it)->presenceOfStructureElements())
5312         return true;
5313   return false;
5314 }
5315
5316 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
5317 {
5318   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5319     if((*it).isNotNull())
5320       if(!(*it)->onlyStructureElements())
5321         return false;
5322   return true;
5323 }
5324
5325 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
5326 {
5327   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5328     if((*it).isNotNull())
5329       (*it)->killStructureElements();
5330 }
5331
5332 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
5333 {
5334   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5335     if((*it).isNotNull())
5336       (*it)->keepOnlyStructureElements();
5337 }
5338
5339 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName)
5340 {
5341   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5342     if((*it).isNotNull())
5343       (*it)->keepOnlyOnSE(seName);
5344 }
5345
5346 void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
5347 {
5348   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5349     if((*it).isNotNull())
5350       (*it)->getMeshSENames(ps);
5351 }
5352
5353 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5354 {
5355   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 !";
5356   if(_field_per_mesh.empty())
5357     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
5358   if(_field_per_mesh.size()>1)
5359     throw INTERP_KERNEL::Exception(MSG0);
5360   if(_field_per_mesh[0].isNull())
5361     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
5362   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
5363   std::set<TypeOfField> types;
5364   pm->fillTypesOfFieldAvailable(types);
5365   if(types.size()!=1)
5366     throw INTERP_KERNEL::Exception(MSG0);
5367   TypeOfField type(*types.begin());
5368   int meshDimRelToMax(0);
5369   if(type==ON_NODES)
5370     meshDimRelToMax=0;
5371   else
5372     {
5373       int myDim(std::numeric_limits<int>::max());
5374       bool isUnique(pm->isUniqueLevel(myDim));
5375       if(!isUnique)
5376         throw INTERP_KERNEL::Exception(MSG0);
5377       meshDimRelToMax=myDim-mesh->getMeshDimension();
5378       if(meshDimRelToMax>0)
5379         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5380     }
5381   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5382 }
5383
5384 /*!
5385  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5386  *  \param [in] type - a spatial discretization of the new field.
5387  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5388  *  \param [in] mName - a name of the supporting mesh.
5389  *  \param [in] renumPol - specifies how to permute values of the result field according to
5390  *          the optional numbers of cells and nodes, if any. The valid values are
5391  *          - 0 - do not permute.
5392  *          - 1 - permute cells.
5393  *          - 2 - permute nodes.
5394  *          - 3 - permute cells and nodes.
5395  *
5396  *  \param [in] glob - the global data storing profiles and localization.
5397  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5398  *          caller is to delete this field using decrRef() as it is no more needed. 
5399  *  \throw If the MED file is not readable.
5400  *  \throw If there is no mesh named \a mName in the MED file.
5401  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5402  *  \throw If no field of \a this is lying on the mesh \a mName.
5403  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5404  */
5405 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5406 {
5407   MCAuto<MEDFileMesh> mm;
5408   if(mName.empty())
5409     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5410   else
5411     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5412   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5413 }
5414
5415 /*!
5416  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5417  *  \param [in] type - a spatial discretization of the new field.
5418  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5419  *  \param [in] renumPol - specifies how to permute values of the result field according to
5420  *          the optional numbers of cells and nodes, if any. The valid values are
5421  *          - 0 - do not permute.
5422  *          - 1 - permute cells.
5423  *          - 2 - permute nodes.
5424  *          - 3 - permute cells and nodes.
5425  *
5426  *  \param [in] glob - the global data storing profiles and localization.
5427  *  \param [in] mesh - the supporting mesh.
5428  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5429  *          caller is to delete this field using decrRef() as it is no more needed. 
5430  *  \throw If the MED file is not readable.
5431  *  \throw If no field of \a this is lying on \a mesh.
5432  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5433  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5434  */
5435 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5436 {
5437   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5438   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5439   if(meshDimRelToMax==1)
5440     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5441   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5442 }
5443
5444 /*!
5445  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5446  * given mesh. 
5447  *  \param [in] type - a spatial discretization of the new field.
5448  *  \param [in] mName - a name of the supporting mesh.
5449  *  \param [in] renumPol - specifies how to permute values of the result field according to
5450  *          the optional numbers of cells and nodes, if any. The valid values are
5451  *          - 0 - do not permute.
5452  *          - 1 - permute cells.
5453  *          - 2 - permute nodes.
5454  *          - 3 - permute cells and nodes.
5455  *
5456  *  \param [in] glob - the global data storing profiles and localization.
5457  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5458  *          caller is to delete this field using decrRef() as it is no more needed. 
5459  *  \throw If the MED file is not readable.
5460  *  \throw If there is no mesh named \a mName in the MED file.
5461  *  \throw If there are no mesh entities in the mesh.
5462  *  \throw If no field values of the given \a type are available.
5463  */
5464 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5465 {
5466   MCAuto<MEDFileMesh> mm;
5467   if(mName.empty())
5468     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5469   else
5470     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5471   int absDim=getDimension();
5472   int meshDimRelToMax=absDim-mm->getMeshDimension();
5473   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5474 }
5475
5476 /*!
5477  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5478  *  \param [in] type - a spatial discretization of the new field.
5479  *  \param [in] renumPol - specifies how to permute values of the result field according to
5480  *          the optional numbers of cells and nodes, if any. The valid values are
5481  *          - 0 - do not permute.
5482  *          - 1 - permute cells.
5483  *          - 2 - permute nodes.
5484  *          - 3 - permute cells and nodes.
5485  *
5486  *  \param [in] glob - the global data storing profiles and localization.
5487  *  \param [in] mesh - the supporting mesh.
5488  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5489  *         field according to \a renumPol.
5490  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5491  *         field according to \a renumPol.
5492  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5493  *          caller is to delete this field using decrRef() as it is no more needed. 
5494  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5495  *  \throw If no field of \a this is lying on \a mesh.
5496  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5497  */
5498 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
5499 {
5500   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5501   bool isPfl=false;
5502   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[0]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5503   switch(renumPol)
5504   {
5505     case 0:
5506       {
5507         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5508         return ret.retn();
5509       }
5510     case 3:
5511     case 1:
5512       {
5513         if(isPfl)
5514           throw INTERP_KERNEL::Exception(msg1);
5515         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5516         if(cellRenum)
5517           {
5518             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5519               {
5520                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5521                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5522                 throw INTERP_KERNEL::Exception(oss.str());
5523               }
5524             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5525             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5526             std::vector<DataArray *> arrOut2(1,arrOut);
5527             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5528             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5529             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5530           }
5531         if(renumPol==1)
5532           return ret.retn();
5533       }
5534     case 2:
5535       {
5536         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5537         if(isPfl)
5538           throw INTERP_KERNEL::Exception(msg1);
5539         if(nodeRenum)
5540           {
5541             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5542               {
5543                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5544                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5545                 throw INTERP_KERNEL::Exception(oss.str());
5546               }
5547             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5548             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5549               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5550             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5551           }
5552         return ret.retn();
5553       }
5554     default:
5555       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5556   }
5557 }
5558
5559 /*!
5560  * Returns values and a profile of the field of a given type lying on a given support.
5561  *  \param [in] type - a spatial discretization of the field.
5562  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5563  *  \param [in] mesh - the supporting mesh.
5564  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5565  *          field of interest lies on. If the field lies on all entities of the given
5566  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5567  *          using decrRef() as it is no more needed.  
5568  *  \param [in] glob - the global data storing profiles and localization.
5569  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5570  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5571  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5572  *  \throw If no field of \a this is lying on \a mesh.
5573  *  \throw If no field values of the given \a type are available.
5574  */
5575 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5576 {
5577   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5578   MCAuto<DataArray> ret=_field_per_mesh[0]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5579   ret->setName(nasc.getName().c_str());
5580   return ret.retn();
5581 }
5582
5583 //= MEDFileField1TSWithoutSDA
5584
5585 /*!
5586  * Throws if a given value is not a valid (non-extended) relative dimension.
5587  *  \param [in] meshDimRelToMax - the relative dimension value.
5588  *  \throw If \a meshDimRelToMax > 0.
5589  */
5590 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5591 {
5592   if(meshDimRelToMax>0)
5593     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5594 }
5595
5596 /*!
5597  * Checks if elements of a given mesh are in the order suitable for writing 
5598  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5599  * vector describing types of elements and their number.
5600  *  \param [in] mesh - the mesh to check.
5601  *  \return std::vector<int> - a vector holding for each element type (1) item of
5602  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5603  *          These values are in full-interlace mode.
5604  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5605  */
5606 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5607 {
5608   if(!mesh)
5609     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5610   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5611   int nbOfTypes=geoTypes.size();
5612   std::vector<int> code(3*nbOfTypes);
5613   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5614   arr1->alloc(nbOfTypes,1);
5615   int *arrPtr=arr1->getPointer();
5616   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5617   for(int i=0;i<nbOfTypes;i++,it++)
5618     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5619   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5620   const int *arrPtr2=arr2->getConstPointer();
5621   int i=0;
5622   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5623     {
5624       int pos=arrPtr2[i];
5625       int nbCells=mesh->getNumberOfCellsWithType(*it);
5626       code[3*pos]=(int)(*it);
5627       code[3*pos+1]=nbCells;
5628       code[3*pos+2]=-1;//no profiles
5629     }
5630   std::vector<const DataArrayInt *> idsPerType;//no profiles
5631   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5632   if(da)
5633     {
5634       da->decrRef();
5635       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5636     }
5637   return code;
5638 }
5639
5640 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5641 {
5642   return new MEDFileField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5643 }
5644
5645 /*!
5646  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5647  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5648  * item of every of returned sequences refers to the _i_-th part of \a this field.
5649  * Thus all sequences returned by this method are of the same length equal to number
5650  * of different types of supporting entities.<br>
5651  * A field part can include sub-parts with several different spatial discretizations,
5652  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5653  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5654  * of a nested sequence corresponds to a type of spatial discretization.<br>
5655  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5656  * The overhead is due to selecting values into new instances of DataArrayDouble.
5657  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5658  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5659  *          not checked if \a mname == \c NULL).
5660  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5661  *          a field part is returned. 
5662  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5663  *          A field part can include sub-parts with several different spatial discretizations,
5664  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5665  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5666  *          This sequence is of the same length as \a types. 
5667  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5668  *          discretization. A profile name can be empty.
5669  *          Length of this and of nested sequences is the same as that of \a typesF.
5670  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5671  *          discretization. A localization name can be empty.
5672  *          Length of this and of nested sequences is the same as that of \a typesF.
5673  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5674  *          per each type of spatial discretization within one mesh entity type.
5675  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5676  *          Length of this and of nested sequences is the same as that of \a typesF.
5677  *  \throw If no field is lying on \a mname.
5678  */
5679 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
5680 {
5681   if(mname.empty())
5682     if(_field_per_mesh.empty())
5683       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5684   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[0]->getFieldSplitedByType(types,typesF,pfls,locs);
5685   int nbOfRet=ret0.size();
5686   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5687   for(int i=0;i<nbOfRet;i++)
5688     {
5689       const std::vector< std::pair<int,int> >& p=ret0[i];
5690       int nbOfRet1=p.size();
5691       ret[i].resize(nbOfRet1);
5692       for(int j=0;j<nbOfRet1;j++)
5693         {
5694           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5695           ret[i][j]=tmp;
5696         }
5697     }
5698   return ret;
5699 }
5700
5701 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5702 {
5703   return TYPE_STR;
5704 }
5705
5706 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5707 {
5708   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5709   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5710   ret->deepCpyLeavesFrom(*this);
5711   const DataArrayDouble *arr(_arr);
5712   if(arr)
5713     {
5714       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5715       ret->setArray(arr2);
5716     }
5717   return ret.retn();
5718 }
5719
5720 /*!
5721  * Returns a pointer to the underground DataArrayDouble instance and a
5722  * sequence describing parameters of a support of each part of \a this field. The
5723  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5724  * direct access to the field values. This method is intended for the field lying on one
5725  * mesh only.
5726  *  \param [in,out] entries - the sequence describing parameters of a support of each
5727  *         part of \a this field. Each item of this sequence consists of two parts. The
5728  *         first part describes a type of mesh entity and an id of discretization of a
5729  *         current field part. The second part describes a range of values [begin,end)
5730  *         within the returned array relating to the current field part.
5731  *  \return DataArrayDouble * - the pointer to the field values array.
5732  *  \throw If the number of underlying meshes is not equal to 1.
5733  *  \throw If no field values are available.
5734  *  \sa getUndergroundDataArray()
5735  */
5736 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5737 {
5738   if(_field_per_mesh.size()!=1)
5739     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5740   if(_field_per_mesh[0]==0)
5741     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5742   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5743   return getUndergroundDataArrayTemplate();
5744 }
5745
5746 /*!
5747  * Returns a pointer to the underground DataArrayDouble instance and a
5748  * sequence describing parameters of a support of each part of \a this field. The
5749  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5750  * direct access to the field values. This method is intended for the field lying on one
5751  * mesh only.
5752  *  \param [in,out] entries - the sequence describing parameters of a support of each
5753  *         part of \a this field. Each item of this sequence consists of two parts. The
5754  *         first part describes a type of mesh entity and an id of discretization of a
5755  *         current field part. The second part describes a range of values [begin,end)
5756  *         within the returned array relating to the current field part.
5757  *  \return DataArrayDouble * - the pointer to the field values array.
5758  *  \throw If the number of underlying meshes is not equal to 1.
5759  *  \throw If no field values are available.
5760  *  \sa getUndergroundDataArray()
5761  */
5762 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5763 {
5764   return getUndergroundDataArrayDoubleExt(entries);
5765 }
5766
5767 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)
5768 {
5769   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5770   arr->setInfoAndChangeNbOfCompo(infos);
5771 }
5772
5773 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5774 {
5775 }
5776
5777 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5778 {
5779   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5780   ret->deepCpyLeavesFrom(*this);
5781   return ret.retn();
5782 }
5783
5784 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5785 {
5786   MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
5787   if(_arr.isNotNull())
5788     ret->_arr=_arr->deepCopy();
5789   return ret.retn();
5790 }
5791
5792 //= MEDFileIntField1TSWithoutSDA
5793
5794 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5795 {
5796   return new MEDFileIntField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos);
5797 }
5798
5799 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5800 {
5801 }
5802
5803 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order,
5804                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,meshName,csit,iteration,order)
5805 {
5806   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5807   arr->setInfoAndChangeNbOfCompo(infos);
5808 }
5809
5810 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5811 {
5812   return TYPE_STR;
5813 }
5814
5815 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5816 {
5817   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5818   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5819   ret->deepCpyLeavesFrom(*this);
5820   const DataArrayInt *arr(_arr);
5821   if(arr)
5822     {
5823       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5824       ret->setArray(arr2);
5825     }
5826   return ret.retn();
5827 }
5828
5829 /*!
5830  * Returns a pointer to the underground DataArrayInt instance and a
5831  * sequence describing parameters of a support of each part of \a this field. The
5832  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5833  * direct access to the field values. This method is intended for the field lying on one
5834  * mesh only.
5835  *  \param [in,out] entries - the sequence describing parameters of a support of each
5836  *         part of \a this field. Each item of this sequence consists of two parts. The
5837  *         first part describes a type of mesh entity and an id of discretization of a
5838  *         current field part. The second part describes a range of values [begin,end)
5839  *         within the returned array relating to the current field part.
5840  *  \return DataArrayInt * - the pointer to the field values array.
5841  *  \throw If the number of underlying meshes is not equal to 1.
5842  *  \throw If no field values are available.
5843  *  \sa getUndergroundDataArray()
5844  */
5845 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5846 {
5847   return getUndergroundDataArrayIntExt(entries);
5848 }
5849
5850 /*!
5851  * Returns a pointer to the underground DataArrayInt instance and a
5852  * sequence describing parameters of a support of each part of \a this field. The
5853  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5854  * direct access to the field values. This method is intended for the field lying on one
5855  * mesh only.
5856  *  \param [in,out] entries - the sequence describing parameters of a support of each
5857  *         part of \a this field. Each item of this sequence consists of two parts. The
5858  *         first part describes a type of mesh entity and an id of discretization of a
5859  *         current field part. The second part describes a range of values [begin,end)
5860  *         within the returned array relating to the current field part.
5861  *  \return DataArrayInt * - the pointer to the field values array.
5862  *  \throw If the number of underlying meshes is not equal to 1.
5863  *  \throw If no field values are available.
5864  *  \sa getUndergroundDataArray()
5865  */
5866 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5867 {
5868   if(_field_per_mesh.size()!=1)
5869     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5870   if(_field_per_mesh[0]==0)
5871     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5872   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5873   return getUndergroundDataArrayTemplate();
5874 }
5875
5876 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5877 {
5878   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5879   ret->deepCpyLeavesFrom(*this);
5880   return ret.retn();
5881 }
5882
5883 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5884 {
5885   MCAuto<MEDFileIntField1TSWithoutSDA> ret(shallowCpy());
5886   if(_arr.isNotNull())
5887     ret->_arr=_arr->deepCopy();
5888   return ret.retn();
5889 }
5890
5891 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5892 {
5893 }
5894
5895 //= MEDFileAnyTypeField1TS
5896
5897 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5898 {
5899   med_field_type typcha;
5900   //
5901   std::vector<std::string> infos;
5902   std::string dtunit,fieldName,meshName;
5903   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
5904   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5905   switch(typcha)
5906   {
5907     case MED_FLOAT64:
5908       {
5909         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5910         break;
5911       }
5912     case MED_INT32:
5913       {
5914         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5915         break;
5916       }
5917     default:
5918       {
5919         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] !";
5920         throw INTERP_KERNEL::Exception(oss.str());
5921       }
5922   }
5923   ret->setDtUnit(dtunit.c_str());
5924   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5925   //
5926   med_int numdt,numit;
5927   med_float dt;
5928   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5929   ret->setTime(numdt,numit,dt);
5930   ret->_csit=1;
5931   if(loadAll)
5932     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
5933   else
5934     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
5935   return ret.retn();
5936 }
5937
5938 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5939 try:MEDFileFieldGlobsReal(fid)
5940 {
5941   _content=BuildContentFrom(fid,loadAll,ms,entities);
5942   loadGlobals(fid);
5943 }
5944 catch(INTERP_KERNEL::Exception& e)
5945 {
5946     throw e;
5947 }
5948
5949 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5950 {
5951   med_field_type typcha;
5952   std::vector<std::string> infos;
5953   std::string dtunit,meshName;
5954   int iii=-1;
5955   int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName);
5956   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5957   switch(typcha)
5958   {
5959     case MED_FLOAT64:
5960       {
5961         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5962         break;
5963       }
5964     case MED_INT32:
5965       {
5966         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5967         break;
5968       }
5969     default:
5970       {
5971         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] !";
5972         throw INTERP_KERNEL::Exception(oss.str());
5973       }
5974   }
5975   ret->setMeshName(meshName);
5976   ret->setDtUnit(dtunit.c_str());
5977   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5978   //
5979   if(nbSteps<1)
5980     {
5981       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5982       throw INTERP_KERNEL::Exception(oss.str());
5983     }
5984   //
5985   med_int numdt,numit;
5986   med_float dt;
5987   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5988   ret->setTime(numdt,numit,dt);
5989   ret->_csit=1;
5990   if(loadAll)
5991     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
5992   else
5993     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
5994   return ret.retn();
5995 }
5996
5997 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
5998 try:MEDFileFieldGlobsReal(fid)
5999 {
6000   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
6001   loadGlobals(fid);
6002 }
6003 catch(INTERP_KERNEL::Exception& e)
6004 {
6005     throw e;
6006 }
6007
6008 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
6009 {
6010   if(!c)
6011     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
6012   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
6013     {
6014       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6015       ret->_content=c; c->incrRef();
6016       return ret.retn();
6017     }
6018   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
6019     {
6020       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
6021       ret->_content=c; c->incrRef();
6022       return ret.retn();
6023     }
6024   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
6025 }
6026
6027 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
6028 {
6029   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
6030   ret->setFileName(FileNameFromFID(fid));
6031   return ret;
6032 }
6033
6034 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
6035 {
6036   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6037   return New(fid,loadAll);
6038 }
6039
6040 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
6041 {
6042   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0,0));
6043   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6044   ret->loadGlobals(fid);
6045   return ret.retn();
6046 }
6047
6048 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6049 {
6050   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6051   return New(fid,fieldName,loadAll);
6052 }
6053
6054 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6055 {
6056   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
6057   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6058   ret->loadGlobals(fid);
6059   return ret.retn();
6060 }
6061
6062 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6063 {
6064   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6065   return New(fid,fieldName,iteration,order,loadAll);
6066 }
6067
6068 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6069 {
6070   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,0));
6071   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6072   ret->loadGlobals(fid);
6073   return ret.retn();
6074 }
6075
6076 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6077 {
6078   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6079   return NewAdv(fid,fieldName,iteration,order,loadAll,entities);
6080 }
6081
6082 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::NewAdv(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileEntities *entities)
6083 {
6084   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0,entities));
6085   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
6086   ret->loadGlobals(fid);
6087   return ret.retn();
6088 }
6089
6090 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6091 {
6092   med_field_type typcha;
6093   std::vector<std::string> infos;
6094   std::string dtunit,meshName;
6095   int iii(-1);
6096   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName));
6097   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
6098   switch(typcha)
6099   {
6100     case MED_FLOAT64:
6101       {
6102         ret=MEDFileField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6103         break;
6104       }
6105     case MED_INT32:
6106       {
6107         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
6108         break;
6109       }
6110     default:
6111       {
6112         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] !";
6113         throw INTERP_KERNEL::Exception(oss.str());
6114       }
6115   }
6116   ret->setDtUnit(dtunit.c_str());
6117   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
6118   //
6119   bool found=false;
6120   std::vector< std::pair<int,int> > dtits(nbOfStep2);
6121   for(int i=0;i<nbOfStep2 && !found;i++)
6122     {
6123       med_int numdt,numit;
6124       med_float dt;
6125       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
6126       if(numdt==iteration && numit==order)
6127         {
6128           found=true;
6129           ret->_csit=i+1;
6130         }
6131       else
6132         dtits[i]=std::pair<int,int>(numdt,numit);
6133     }
6134   if(!found)
6135     {
6136       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
6137       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
6138         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
6139       throw INTERP_KERNEL::Exception(oss.str());
6140     }
6141   if(loadAll)
6142     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6143   else
6144     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,entities);
6145   return ret.retn();
6146 }
6147
6148 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
6149 try:MEDFileFieldGlobsReal(fid)
6150 {
6151   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms,entities);
6152   loadGlobals(fid);
6153 }
6154 catch(INTERP_KERNEL::Exception& e)
6155 {
6156     throw e;
6157 }
6158
6159 /*!
6160  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6161  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6162  *
6163  * \warning this is a shallow copy constructor
6164  */
6165 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
6166 {
6167   if(!shallowCopyOfContent)
6168     {
6169       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
6170       otherPtr->incrRef();
6171       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
6172     }
6173   else
6174     {
6175       _content=other.shallowCpy();
6176     }
6177 }
6178
6179 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)
6180 {
6181   if(checkFieldId)
6182     {
6183       int nbFields=MEDnField(fid);
6184       if(fieldIdCFormat>=nbFields)
6185         {
6186           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
6187           throw INTERP_KERNEL::Exception(oss.str());
6188         }
6189     }
6190   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
6191   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6192   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE));
6193   INTERP_KERNEL::AutoPtr<char> dtunit(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
6194   INTERP_KERNEL::AutoPtr<char> nomcha(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6195   INTERP_KERNEL::AutoPtr<char> nomMaa(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
6196   med_bool localMesh;
6197   int nbOfStep;
6198   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
6199   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
6200   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
6201   meshName=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
6202   infos.clear(); infos.resize(ncomp);
6203   for(int j=0;j<ncomp;j++)
6204     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
6205   return nbOfStep;
6206 }
6207
6208 /*!
6209  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
6210  * 
6211  * \param [out]
6212  * \return in case of success the number of time steps available for the field with name \a fieldName.
6213  */
6214 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)
6215 {
6216   int nbFields=MEDnField(fid);
6217   bool found=false;
6218   std::vector<std::string> fns(nbFields);
6219   int nbOfStep2(-1);
6220   for(int i=0;i<nbFields && !found;i++)
6221     {
6222       std::string tmp,tmp2;
6223       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut,tmp2);
6224       fns[i]=tmp;
6225       found=(tmp==fieldName);
6226       if(found)
6227         {
6228           posCFormat=i;
6229           meshName=tmp2;
6230         }
6231     }
6232   if(!found)
6233     {
6234       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
6235       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
6236         oss << "\"" << *it << "\" ";
6237       throw INTERP_KERNEL::Exception(oss.str());
6238     }
6239   return nbOfStep2;
6240 }
6241
6242 /*!
6243  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6244  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6245  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6246  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6247  * to keep a valid instance.
6248  * 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.
6249  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
6250  * 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.
6251  *
6252  * \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.
6253  * \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.
6254  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6255  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6256  * \param [in] newLocName is the new localization name.
6257  * \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.
6258  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
6259  */
6260 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
6261 {
6262   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6263   std::string oldPflName=disc->getProfile();
6264   std::vector<std::string> vv=getPflsReallyUsedMulti();
6265   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
6266   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
6267     {
6268       disc->setProfile(newPflName);
6269       DataArrayInt *pfl=getProfile(oldPflName.c_str());
6270       pfl->setName(newPflName);
6271     }
6272   else
6273     {
6274       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
6275       throw INTERP_KERNEL::Exception(oss.str());
6276     }
6277 }
6278
6279 /*!
6280  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6281  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6282  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6283  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6284  * to keep a valid instance.
6285  * 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.
6286  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
6287  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
6288  * 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.
6289  *
6290  * \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.
6291  * \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.
6292  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6293  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6294  * \param [in] newLocName is the new localization name.
6295  * \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.
6296  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
6297  */
6298 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
6299 {
6300   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6301   std::string oldLocName=disc->getLocalization();
6302   std::vector<std::string> vv=getLocsReallyUsedMulti();
6303   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
6304   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
6305     {
6306       disc->setLocalization(newLocName);
6307       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
6308       loc.setName(newLocName);
6309     }
6310   else
6311     {
6312       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
6313       throw INTERP_KERNEL::Exception(oss.str());
6314     }
6315 }
6316
6317 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
6318 {
6319   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6320   if(!ret)
6321     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
6322   return ret;
6323 }
6324
6325 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
6326 {
6327   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6328   if(!ret)
6329     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
6330   return ret;
6331 }
6332
6333 /*!
6334  * This method alloc the arrays and load potentially huge arrays contained in this field.
6335  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
6336  * This method can be also called to refresh or reinit values from a file.
6337  * 
6338  * \throw If the fileName is not set or points to a non readable MED file.
6339  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6340  */
6341 void MEDFileAnyTypeField1TS::loadArrays()
6342 {
6343   if(getFileName().empty())
6344     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
6345   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6346   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
6347 }
6348
6349 /*!
6350  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
6351  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
6352  * this method does not throw if \a this does not come from file read.
6353  * 
6354  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
6355  */
6356 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
6357 {
6358   if(!getFileName().empty())
6359     {
6360       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6361       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
6362     }
6363 }
6364
6365 /*!
6366  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
6367  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
6368  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
6369  * 
6370  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
6371  */
6372 void MEDFileAnyTypeField1TS::unloadArrays()
6373 {
6374   contentNotNullBase()->unloadArrays();
6375 }
6376
6377 /*!
6378  * 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.
6379  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
6380  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
6381  * 
6382  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6383  */
6384 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
6385 {
6386   if(!getFileName().empty())
6387     contentNotNullBase()->unloadArrays();
6388 }
6389
6390 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6391 {
6392   int nbComp(getNumberOfComponents());
6393   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6394   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6395   for(int i=0;i<nbComp;i++)
6396     {
6397       std::string info=getInfo()[i];
6398       std::string c,u;
6399       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6400       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6401       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6402     }
6403   if(getName().empty())
6404     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6405   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6406   writeGlobals(fid,*this);
6407   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6408 }
6409
6410 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6411 {
6412   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6413 }
6414
6415 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6416 {
6417   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6418   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6419   return ret;
6420 }
6421
6422 /*!
6423  * Returns a string describing \a this field. This string is outputted 
6424  * by \c print Python command.
6425  */
6426 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6427 {
6428   std::ostringstream oss;
6429   contentNotNullBase()->simpleRepr(0,oss,-1);
6430   simpleReprGlobs(oss);
6431   return oss.str();
6432 }
6433
6434 /*!
6435  * This method returns all profiles whose name is non empty used.
6436  * \b WARNING If profile is used several times it will be reported \b only \b once.
6437  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6438  */
6439 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6440 {
6441   return contentNotNullBase()->getPflsReallyUsed2();
6442 }
6443
6444 /*!
6445  * This method returns all localizations whose name is non empty used.
6446  * \b WARNING If localization is used several times it will be reported \b only \b once.
6447  */
6448 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6449 {
6450   return contentNotNullBase()->getLocsReallyUsed2();
6451 }
6452
6453 /*!
6454  * This method returns all profiles whose name is non empty used.
6455  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6456  */
6457 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6458 {
6459   return contentNotNullBase()->getPflsReallyUsedMulti2();
6460 }
6461
6462 /*!
6463  * This method returns all localizations whose name is non empty used.
6464  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6465  */
6466 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6467 {
6468   return contentNotNullBase()->getLocsReallyUsedMulti2();
6469 }
6470
6471 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6472 {
6473   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6474 }
6475
6476 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6477 {
6478   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6479 }
6480
6481 int MEDFileAnyTypeField1TS::getDimension() const
6482 {
6483   return contentNotNullBase()->getDimension();
6484 }
6485
6486 int MEDFileAnyTypeField1TS::getIteration() const
6487 {
6488   return contentNotNullBase()->getIteration();
6489 }
6490
6491 int MEDFileAnyTypeField1TS::getOrder() const
6492 {
6493   return contentNotNullBase()->getOrder();
6494 }
6495
6496 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6497 {
6498   return contentNotNullBase()->getTime(iteration,order);
6499 }
6500
6501 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6502 {
6503   contentNotNullBase()->setTime(iteration,order,val);
6504 }
6505
6506 std::string MEDFileAnyTypeField1TS::getName() const
6507 {
6508   return contentNotNullBase()->getName();
6509 }
6510
6511 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6512 {
6513   contentNotNullBase()->setName(name);
6514 }
6515
6516 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6517 {
6518   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6519 }
6520
6521 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6522 {
6523   return contentNotNullBase()->getDtUnit();
6524 }
6525
6526 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6527 {
6528   contentNotNullBase()->setDtUnit(dtUnit);
6529 }
6530
6531 std::string MEDFileAnyTypeField1TS::getMeshName() const
6532 {
6533   return contentNotNullBase()->getMeshName();
6534 }
6535
6536 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6537 {
6538   contentNotNullBase()->setMeshName(newMeshName);
6539 }
6540
6541 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6542 {
6543   return contentNotNullBase()->changeMeshNames(modifTab);
6544 }
6545
6546 int MEDFileAnyTypeField1TS::getMeshIteration() const
6547 {
6548   return contentNotNullBase()->getMeshIteration();
6549 }
6550
6551 int MEDFileAnyTypeField1TS::getMeshOrder() const
6552 {
6553   return contentNotNullBase()->getMeshOrder();
6554 }
6555
6556 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6557 {
6558   return contentNotNullBase()->getNumberOfComponents();
6559 }
6560
6561 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6562 {
6563   return contentNotNullBase()->isDealingTS(iteration,order);
6564 }
6565
6566 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6567 {
6568   return contentNotNullBase()->getDtIt();
6569 }
6570
6571 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6572 {
6573   contentNotNullBase()->fillIteration(p);
6574 }
6575
6576 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6577 {
6578   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6579 }
6580
6581 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6582 {
6583   contentNotNullBase()->setInfo(infos);
6584 }
6585
6586 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6587 {
6588   return contentNotNullBase()->getInfo();
6589 }
6590 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6591 {
6592   return contentNotNullBase()->getInfo();
6593 }
6594
6595 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6596 {
6597   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6598 }
6599
6600 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6601 {
6602   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6603 }
6604
6605 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6606 {
6607   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6608 }
6609
6610 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6611 {
6612   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6613 }
6614
6615 void MEDFileAnyTypeField1TS::convertMedBallIntoClassic()
6616 {
6617   return contentNotNullBase()->convertMedBallIntoClassic();
6618 }
6619
6620 void MEDFileAnyTypeField1TS::makeReduction(INTERP_KERNEL::NormalizedCellType ct, TypeOfField tof, const DataArrayInt *pfl)
6621 {
6622   return contentNotNullBase()->makeReduction(ct,tof,pfl);
6623 }
6624
6625 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6626 {
6627   return contentNotNullBase()->getTypesOfFieldAvailable();
6628 }
6629
6630 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,
6631                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6632 {
6633   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6634 }
6635
6636 /*!
6637  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6638  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6639  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6640  */
6641 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6642 {
6643   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6644   if(!content)
6645     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6646   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6647   std::size_t sz(contentsSplit.size());
6648   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6649   for(std::size_t i=0;i<sz;i++)
6650     {
6651       ret[i]=shallowCpy();
6652       ret[i]->_content=contentsSplit[i];
6653     }
6654   return ret;
6655 }
6656
6657 /*!
6658  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6659  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6660  */
6661 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6662 {
6663   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6664   if(!content)
6665     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6666   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6667   std::size_t sz(contentsSplit.size());
6668   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6669   for(std::size_t i=0;i<sz;i++)
6670     {
6671       ret[i]=shallowCpy();
6672       ret[i]->_content=contentsSplit[i];
6673     }
6674   return ret;
6675 }
6676
6677 /*!
6678  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6679  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6680  */
6681 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6682 {
6683   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6684   if(!content)
6685     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6686   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6687   std::size_t sz(contentsSplit.size());
6688   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6689   for(std::size_t i=0;i<sz;i++)
6690     {
6691       ret[i]=shallowCpy();
6692       ret[i]->_content=contentsSplit[i];
6693     }
6694   return ret;
6695 }
6696
6697 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6698 {
6699   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6700   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6701     ret->_content=_content->deepCopy();
6702   ret->deepCpyGlobs(*this);
6703   return ret.retn();
6704 }
6705
6706 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6707 {
6708   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6709 }
6710
6711 //= MEDFileField1TS
6712
6713 /*!
6714  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6715  * the first field that has been read from a specified MED file.
6716  *  \param [in] fileName - the name of the MED file to read.
6717  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6718  *          is to delete this field using decrRef() as it is no more needed.
6719  *  \throw If reading the file fails.
6720  */
6721 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6722 {
6723   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6724   return New(fid,loadAll);
6725 }
6726
6727 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
6728 {
6729   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
6730   ret->contentNotNull();
6731   return ret.retn();
6732 }
6733
6734 /*!
6735  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6736  * a given field that has been read from a specified MED file.
6737  *  \param [in] fileName - the name of the MED file to read.
6738  *  \param [in] fieldName - the name of the field to read.
6739  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6740  *          is to delete this field using decrRef() as it is no more needed.
6741  *  \throw If reading the file fails.
6742  *  \throw If there is no field named \a fieldName in the file.
6743  */
6744 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6745 {
6746   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6747   return New(fid,fieldName,loadAll);
6748 }
6749
6750 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6751 {
6752   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
6753   ret->contentNotNull();
6754   return ret.retn();
6755 }
6756
6757 /*!
6758  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6759  * a given field that has been read from a specified MED file.
6760  *  \param [in] fileName - the name of the MED file to read.
6761  *  \param [in] fieldName - the name of the field to read.
6762  *  \param [in] iteration - the iteration number of a required time step.
6763  *  \param [in] order - the iteration order number of required time step.
6764  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6765  *          is to delete this field using decrRef() as it is no more needed.
6766  *  \throw If reading the file fails.
6767  *  \throw If there is no field named \a fieldName in the file.
6768  *  \throw If the required time step is missing from the file.
6769  */
6770 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6771 {
6772   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6773   return New(fid,fieldName,iteration,order,loadAll);
6774 }
6775
6776 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6777 {
6778   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
6779   ret->contentNotNull();
6780   return ret.retn();
6781 }
6782
6783 /*!
6784  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6785  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6786  *
6787  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6788  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6789  * \warning this is a shallow copy constructor
6790  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6791  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6792  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6793  *          is to delete this field using decrRef() as it is no more needed.
6794  */
6795 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6796 {
6797   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6798   ret->contentNotNull();
6799   return ret.retn();
6800 }
6801
6802 /*!
6803  * Returns a new empty instance of MEDFileField1TS.
6804  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6805  *          is to delete this field using decrRef() as it is no more needed.
6806  */
6807 MEDFileField1TS *MEDFileField1TS::New()
6808 {
6809   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6810   ret->contentNotNull();
6811   return ret.retn();
6812 }
6813
6814 /*!
6815  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6816  * following the given input policy.
6817  *
6818  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6819  *                            By default (true) the globals are deeply copied.
6820  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6821  */
6822 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6823 {
6824   MCAuto<MEDFileIntField1TS> ret;
6825   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6826   if(content)
6827     {
6828       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6829       if(!contc)
6830         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6831       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6832       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6833     }
6834   else
6835     ret=MEDFileIntField1TS::New();
6836   if(isDeepCpyGlobs)
6837     ret->deepCpyGlobs(*this);
6838   else
6839     ret->shallowCpyGlobs(*this);
6840   return ret.retn();
6841 }
6842
6843 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6844 {
6845   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6846   if(!pt)
6847     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6848   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6849   if(!ret)
6850     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
6851   return ret;
6852 }
6853
6854 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6855 {
6856   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6857   if(!pt)
6858     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6859   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6860   if(!ret)
6861     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
6862   return ret;
6863 }
6864
6865 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6866 {
6867   if(!f)
6868     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6869   if(arr.isNull())
6870     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6871   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6872   if(!arrOutC)
6873     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6874   f->setArray(arrOutC);
6875 }
6876
6877 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6878 {
6879   if(arr.isNull())
6880     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6881   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6882   if(!arrOutC)
6883     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6884   arrOutC->incrRef();
6885   return arrOutC;
6886 }
6887
6888 /*!
6889  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6890  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6891  *
6892  * \return A new object that the caller is responsible to deallocate.
6893  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6894  */
6895 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6896 {
6897   if(!mm)
6898     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6899   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6900   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6901   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6902     {
6903       if((*it0)!=ON_NODES)
6904         {
6905           std::vector<int> levs;
6906           getNonEmptyLevels(mm->getName(),levs);
6907           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6908             {
6909               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6910               if(it2!=extractDef.end())
6911                 {
6912                   MCAuto<DataArrayInt> t((*it2).second);
6913                   if(t.isNull())
6914                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6915                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6916                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6917                   ret->setFieldNoProfileSBT(fOut);
6918                 }
6919             }
6920         }
6921       else
6922         {
6923           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6924           if(it2==extractDef.end())
6925             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6926           MCAuto<DataArrayInt> t((*it2).second);
6927           if(t.isNull())
6928             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6929           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6930           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6931           DataArrayDouble *arr(f->getArray());
6932           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6933           fOut->setArray(newArr);
6934           ret->setFieldNoProfileSBT(fOut);
6935         }
6936     }
6937   return ret.retn();
6938 }
6939
6940 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6941 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6942 {
6943 }
6944 catch(INTERP_KERNEL::Exception& e)
6945 { throw e; }
6946
6947 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6948 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6949 {
6950 }
6951 catch(INTERP_KERNEL::Exception& e)
6952 { throw e; }
6953
6954 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6955 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6956 {
6957 }
6958 catch(INTERP_KERNEL::Exception& e)
6959 { throw e; }
6960
6961 /*!
6962  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6963  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6964  *
6965  * \warning this is a shallow copy constructor
6966  */
6967 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6968 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6969 {
6970 }
6971 catch(INTERP_KERNEL::Exception& e)
6972 { throw e; }
6973
6974 MEDFileField1TS::MEDFileField1TS()
6975 {
6976   _content=new MEDFileField1TSWithoutSDA;
6977 }
6978
6979 /*!
6980  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
6981  * method should be called (getFieldOnMeshAtLevel for example).
6982  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6983  *
6984  * \param [in] mesh - the mesh the field is lying on
6985  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6986  *          caller is to delete this field using decrRef() as it is no more needed. 
6987  */
6988 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6989 {
6990   MCAuto<DataArray> arrOut;
6991   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6992   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6993   return ret.retn();
6994 }
6995
6996 /*!
6997  * Returns a new MEDCouplingFieldDouble of a given type lying on
6998  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6999  * has not been constructed via file reading, an exception is thrown.
7000  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7001  *  \param [in] type - a spatial discretization of interest.
7002  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7003  *  \param [in] renumPol - specifies how to permute values of the result field according to
7004  *          the optional numbers of cells and nodes, if any. The valid values are
7005  *          - 0 - do not permute.
7006  *          - 1 - permute cells.
7007  *          - 2 - permute nodes.
7008  *          - 3 - permute cells and nodes.
7009  *
7010  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7011  *          caller is to delete this field using decrRef() as it is no more needed. 
7012  *  \throw If \a this field has not been constructed via file reading.
7013  *  \throw If the MED file is not readable.
7014  *  \throw If there is no mesh in the MED file.
7015  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7016  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7017  *  \sa getFieldOnMeshAtLevel()
7018  */
7019 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7020 {
7021   if(getFileName().empty())
7022     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7023   MCAuto<DataArray> arrOut;
7024   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7025   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7026   return ret.retn();
7027 }
7028
7029 /*!
7030  * Returns a new MEDCouplingFieldDouble of a given type lying on
7031  * the top level cells of the first mesh in MED file. If \a this field 
7032  * has not been constructed via file reading, an exception is thrown.
7033  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7034  *  \param [in] type - a spatial discretization of interest.
7035  *  \param [in] renumPol - specifies how to permute values of the result field according to
7036  *          the optional numbers of cells and nodes, if any. The valid values are
7037  *          - 0 - do not permute.
7038  *          - 1 - permute cells.
7039  *          - 2 - permute nodes.
7040  *          - 3 - permute cells and nodes.
7041  *
7042  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7043  *          caller is to delete this field using decrRef() as it is no more needed. 
7044  *  \throw If \a this field has not been constructed via file reading.
7045  *  \throw If the MED file is not readable.
7046  *  \throw If there is no mesh in the MED file.
7047  *  \throw If no field values of the given \a type.
7048  *  \throw If no field values lying on the top level support.
7049  *  \sa getFieldAtLevel()
7050  */
7051 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7052 {
7053   if(getFileName().empty())
7054     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7055   MCAuto<DataArray> arrOut;
7056   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7057   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7058   return ret.retn();
7059 }
7060
7061 /*!
7062  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
7063  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7064  *  \param [in] type - a spatial discretization of the new field.
7065  *  \param [in] mesh - the supporting mesh.
7066  *  \param [in] renumPol - specifies how to permute values of the result field according to
7067  *          the optional numbers of cells and nodes, if any. The valid values are
7068  *          - 0 - do not permute.
7069  *          - 1 - permute cells.
7070  *          - 2 - permute nodes.
7071  *          - 3 - permute cells and nodes.
7072  *
7073  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7074  *          caller is to delete this field using decrRef() as it is no more needed. 
7075  *  \throw If no field of \a this is lying on \a mesh.
7076  *  \throw If the mesh is empty.
7077  *  \throw If no field values of the given \a type are available.
7078  *  \sa getFieldAtLevel()
7079  *  \sa getFieldOnMeshAtLevel() 
7080  */
7081 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7082 {
7083   MCAuto<DataArray> arrOut;
7084   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7085   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7086   return ret.retn();
7087 }
7088
7089 /*!
7090  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7091  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7092  *  \param [in] type - a spatial discretization of interest.
7093  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7094  *  \param [in] mesh - the supporting mesh.
7095  *  \param [in] renumPol - specifies how to permute values of the result field according to
7096  *          the optional numbers of cells and nodes, if any. The valid values are
7097  *          - 0 - do not permute.
7098  *          - 1 - permute cells.
7099  *          - 2 - permute nodes.
7100  *          - 3 - permute cells and nodes.
7101  *
7102  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7103  *          caller is to delete this field using decrRef() as it is no more needed. 
7104  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7105  *  \throw If no field of \a this is lying on \a mesh.
7106  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7107  *  \sa getFieldAtLevel()
7108  *  \sa getFieldOnMeshAtLevel() 
7109  */
7110 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7111 {
7112   MCAuto<DataArray> arrOut;
7113   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7114   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7115   return ret.retn();
7116 }
7117
7118 /*!
7119  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7120  * This method is called "Old" because in MED3 norm a field has only one meshName
7121  * attached, so this method is for readers of MED2 files. If \a this field 
7122  * has not been constructed via file reading, an exception is thrown.
7123  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7124  *  \param [in] type - a spatial discretization of interest.
7125  *  \param [in] mName - a name of the supporting mesh.
7126  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7127  *  \param [in] renumPol - specifies how to permute values of the result field according to
7128  *          the optional numbers of cells and nodes, if any. The valid values are
7129  *          - 0 - do not permute.
7130  *          - 1 - permute cells.
7131  *          - 2 - permute nodes.
7132  *          - 3 - permute cells and nodes.
7133  *
7134  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
7135  *          caller is to delete this field using decrRef() as it is no more needed. 
7136  *  \throw If the MED file is not readable.
7137  *  \throw If there is no mesh named \a mName in the MED file.
7138  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7139  *  \throw If \a this field has not been constructed via file reading.
7140  *  \throw If no field of \a this is lying on the mesh named \a mName.
7141  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7142  *  \sa getFieldAtLevel()
7143  */
7144 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7145 {
7146   if(getFileName().empty())
7147     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7148   MCAuto<DataArray> arrOut;
7149   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
7150   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
7151   return ret.retn();
7152 }
7153
7154 /*!
7155  * Returns values and a profile of the field of a given type lying on a given support.
7156  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7157  *  \param [in] type - a spatial discretization of the field.
7158  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7159  *  \param [in] mesh - the supporting mesh.
7160  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7161  *          field of interest lies on. If the field lies on all entities of the given
7162  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7163  *          using decrRef() as it is no more needed.  
7164  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
7165  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7166  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7167  *  \throw If no field of \a this is lying on \a mesh.
7168  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7169  */
7170 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7171 {
7172   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7173   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
7174 }
7175
7176 /*!
7177  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
7178  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
7179  * "Sort By Type"), if not, an exception is thrown. 
7180  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7181  *  \param [in] field - the field to add to \a this.
7182  *  \throw If the name of \a field is empty.
7183  *  \throw If the data array of \a field is not set.
7184  *  \throw If the data array is already allocated but has different number of components
7185  *         than \a field.
7186  *  \throw If the underlying mesh of \a field has no name.
7187  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7188  */
7189 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
7190 {
7191   setFileName("");
7192   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
7193 }
7194
7195 /*!
7196  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
7197  * can be an aggregation of several MEDCouplingFieldDouble instances.
7198  * The mesh support of input parameter \a field is ignored here, it can be NULL.
7199  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
7200  * and \a profile.
7201  *
7202  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7203  * A new profile is added only if no equal profile is missing.
7204  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7205  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
7206  *  \param [in] mesh - the supporting mesh of \a field.
7207  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7208  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7209  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7210  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7211  *  \throw If the data array of \a field is not set.
7212  *  \throw If the data array of \a this is already allocated but has different number of
7213  *         components than \a field.
7214  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7215  *  \sa setFieldNoProfileSBT()
7216  */
7217 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7218 {
7219   setFileName("");
7220   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7221 }
7222
7223 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
7224 {
7225   return new MEDFileField1TS(*this);
7226 }
7227
7228 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
7229 {
7230   return contentNotNull()->getUndergroundDataArrayTemplate();
7231 }
7232
7233 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7234 {
7235   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
7236 }
7237
7238 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
7239                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
7240 {
7241   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7242 }
7243
7244 //= MEDFileIntField1TS
7245
7246 MEDFileIntField1TS *MEDFileIntField1TS::New()
7247 {
7248   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
7249   ret->contentNotNull();
7250   return ret.retn();
7251 }
7252
7253 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
7254 {
7255   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7256   return MEDFileIntField1TS::New(fid,loadAll);
7257 }
7258
7259 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
7260 {
7261   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
7262   ret->contentNotNull();
7263   return ret.retn();
7264 }
7265
7266 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
7267 {
7268   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7269   return MEDFileIntField1TS::New(fid,fieldName,loadAll);
7270 }
7271
7272 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
7273 {
7274   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
7275   ret->contentNotNull();
7276   return ret.retn();
7277 }
7278
7279 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
7280 {
7281   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7282   return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
7283 }
7284
7285 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
7286 {
7287   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
7288   ret->contentNotNull();
7289   return ret.retn();
7290 }
7291
7292 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
7293 {
7294   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
7295   ret->contentNotNull();
7296   return ret.retn();
7297 }
7298
7299 MEDFileIntField1TS::MEDFileIntField1TS()
7300 {
7301   _content=new MEDFileIntField1TSWithoutSDA;
7302 }
7303
7304 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
7305 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
7306 {
7307 }
7308 catch(INTERP_KERNEL::Exception& e)
7309 { throw e; }
7310
7311 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7312 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
7313 {
7314 }
7315 catch(INTERP_KERNEL::Exception& e)
7316 { throw e; }
7317
7318 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
7319 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
7320 {
7321 }
7322 catch(INTERP_KERNEL::Exception& e)
7323 { throw e; }
7324
7325 /*!
7326  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7327  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7328  *
7329  * \warning this is a shallow copy constructor
7330  */
7331 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
7332 {
7333 }
7334
7335 MEDFileIntField1TS *MEDFileIntField1TS::shallowCpy() const
7336 {
7337   return new MEDFileIntField1TS(*this);
7338 }
7339
7340 /*!
7341  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
7342  * following the given input policy.
7343  *
7344  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
7345  *                            By default (true) the globals are deeply copied.
7346  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
7347  */
7348 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
7349 {
7350   MCAuto<MEDFileField1TS> ret;
7351   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
7352   if(content)
7353     {
7354       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
7355       if(!contc)
7356         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
7357       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
7358       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
7359     }
7360   else
7361     ret=MEDFileField1TS::New();
7362   if(isDeepCpyGlobs)
7363     ret->deepCpyGlobs(*this);
7364   else
7365     ret->shallowCpyGlobs(*this);
7366   return ret.retn();
7367 }
7368
7369 /*!
7370  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
7371  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
7372  * "Sort By Type"), if not, an exception is thrown. 
7373  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7374  *  \param [in] field - the field to add to \a this.
7375  *  \throw If the name of \a field is empty.
7376  *  \throw If the data array of \a field is not set.
7377  *  \throw If the data array is already allocated but has different number of components
7378  *         than \a field.
7379  *  \throw If the underlying mesh of \a field has no name.
7380  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7381  */
7382 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
7383 {
7384   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7385   setFileName("");
7386   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
7387 }
7388
7389 /*!
7390  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
7391  * can be an aggregation of several MEDCouplingFieldDouble instances.
7392  * The mesh support of input parameter \a field is ignored here, it can be NULL.
7393  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
7394  * and \a profile.
7395  *
7396  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7397  * A new profile is added only if no equal profile is missing.
7398  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7399  *  \param [in] field - the field to add to \a this.
7400  *  \param [in] mesh - the supporting mesh of \a field.
7401  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7402  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7403  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7404  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7405  *  \throw If the data array of \a field is not set.
7406  *  \throw If the data array of \a this is already allocated but has different number of
7407  *         components than \a field.
7408  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7409  *  \sa setFieldNoProfileSBT()
7410  */
7411 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7412 {
7413   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7414   setFileName("");
7415   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7416 }
7417
7418 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
7419 {
7420   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7421   if(!pt)
7422     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
7423   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
7424   if(!ret)
7425     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !");
7426   return ret;
7427 }
7428
7429 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7430 {
7431   if(getFileName().empty())
7432     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7433   MCAuto<DataArray> arrOut;
7434   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7435   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7436   return ret2.retn();
7437 }
7438
7439 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
7440 {
7441   if(arr.isNull())
7442     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
7443   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
7444   if(!arrC)
7445     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
7446   arrC->incrRef();
7447   return arrC;
7448 }
7449
7450 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
7451 {
7452   int t1,t2;
7453   double t0(f->getTime(t1,t2));
7454   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
7455   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7456   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
7457   ret->setTime(t0,t1,t2); ret->setArray(arr2);
7458   return ret.retn();
7459 }
7460
7461 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
7462 {
7463   if(!f)
7464     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
7465   int t1,t2;
7466   double t0(f->getTime(t1,t2));
7467   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7468   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
7469   ret->setTime(t0,t1,t2);
7470   return ret;
7471 }
7472
7473 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
7474 {
7475   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
7476 }
7477
7478 /*!
7479  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
7480  * method should be called (getFieldOnMeshAtLevel for example).
7481  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
7482  *
7483  * \param [in] mesh - the mesh the field is lying on
7484  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
7485  *          caller is to delete this field using decrRef() as it is no more needed. 
7486  */
7487 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
7488 {
7489   MCAuto<DataArray> arrOut;
7490   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
7491   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7492   return ret2.retn();
7493 }
7494
7495 /*!
7496  * Returns a new MEDCouplingFieldInt of a given type lying on
7497  * the top level cells of the first mesh in MED file. If \a this field 
7498  * has not been constructed via file reading, an exception is thrown.
7499  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7500  *  \param [in] type - a spatial discretization of interest.
7501  *  \param [in] renumPol - specifies how to permute values of the result field according to
7502  *          the optional numbers of cells and nodes, if any. The valid values are
7503  *          - 0 - do not permute.
7504  *          - 1 - permute cells.
7505  *          - 2 - permute nodes.
7506  *          - 3 - permute cells and nodes.
7507  *
7508  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7509  *          caller is to delete this field using decrRef() as it is no more needed. 
7510  *  \throw If \a this field has not been constructed via file reading.
7511  *  \throw If the MED file is not readable.
7512  *  \throw If there is no mesh in the MED file.
7513  *  \throw If no field values of the given \a type.
7514  *  \throw If no field values lying on the top level support.
7515  *  \sa getFieldAtLevel()
7516  */
7517 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7518 {
7519   if(getFileName().empty())
7520     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7521   MCAuto<DataArray> arrOut;
7522   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7523   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7524   return ret2.retn();
7525 }
7526
7527 /*!
7528  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
7529  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7530  *  \param [in] type - a spatial discretization of the new field.
7531  *  \param [in] mesh - the supporting mesh.
7532  *  \param [in] renumPol - specifies how to permute values of the result field according to
7533  *          the optional numbers of cells and nodes, if any. The valid values are
7534  *          - 0 - do not permute.
7535  *          - 1 - permute cells.
7536  *          - 2 - permute nodes.
7537  *          - 3 - permute cells and nodes.
7538  *
7539  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7540  *          caller is to delete this field using decrRef() as it is no more needed. 
7541  *  \throw If no field of \a this is lying on \a mesh.
7542  *  \throw If the mesh is empty.
7543  *  \throw If no field values of the given \a type are available.
7544  *  \sa getFieldAtLevel()
7545  *  \sa getFieldOnMeshAtLevel() 
7546  */
7547 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7548 {
7549   MCAuto<DataArray> arrOut;
7550   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7551   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7552   return ret2.retn();
7553 }
7554
7555 /*!
7556  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7557  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7558  *  \param [in] type - a spatial discretization of interest.
7559  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7560  *  \param [in] mesh - the supporting mesh.
7561  *  \param [in] renumPol - specifies how to permute values of the result field according to
7562  *          the optional numbers of cells and nodes, if any. The valid values are
7563  *          - 0 - do not permute.
7564  *          - 1 - permute cells.
7565  *          - 2 - permute nodes.
7566  *          - 3 - permute cells and nodes.
7567  *
7568  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7569  *          caller is to delete this field using decrRef() as it is no more needed. 
7570  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7571  *  \throw If no field of \a this is lying on \a mesh.
7572  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7573  *  \sa getFieldAtLevel()
7574  *  \sa getFieldOnMeshAtLevel() 
7575  */
7576 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7577 {
7578   MCAuto<DataArray> arrOut;
7579   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7580   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7581   return ret2.retn();
7582 }
7583
7584 /*!
7585  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7586  * This method is called "Old" because in MED3 norm a field has only one meshName
7587  * attached, so this method is for readers of MED2 files. If \a this field 
7588  * has not been constructed via file reading, an exception is thrown.
7589  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7590  *  \param [in] type - a spatial discretization of interest.
7591  *  \param [in] mName - a name of the supporting mesh.
7592  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7593  *  \param [in] renumPol - specifies how to permute values of the result field according to
7594  *          the optional numbers of cells and nodes, if any. The valid values are
7595  *          - 0 - do not permute.
7596  *          - 1 - permute cells.
7597  *          - 2 - permute nodes.
7598  *          - 3 - permute cells and nodes.
7599  *
7600  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7601  *          caller is to delete this field using decrRef() as it is no more needed. 
7602  *  \throw If the MED file is not readable.
7603  *  \throw If there is no mesh named \a mName in the MED file.
7604  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7605  *  \throw If \a this field has not been constructed via file reading.
7606  *  \throw If no field of \a this is lying on the mesh named \a mName.
7607  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7608  *  \sa getFieldAtLevel()
7609  */
7610 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7611 {
7612   if(getFileName().empty())
7613     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7614   MCAuto<DataArray> arrOut;
7615   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7616   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7617   return ret2.retn();
7618 }
7619
7620 /*!
7621  * Returns values and a profile of the field of a given type lying on a given support.
7622  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7623  *  \param [in] type - a spatial discretization of the field.
7624  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7625  *  \param [in] mesh - the supporting mesh.
7626  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7627  *          field of interest lies on. If the field lies on all entities of the given
7628  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7629  *          using decrRef() as it is no more needed.  
7630  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7631  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7632  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7633  *  \throw If no field of \a this is lying on \a mesh.
7634  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7635  */
7636 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7637 {
7638   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7639   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7640 }
7641
7642 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7643 {
7644   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7645   if(!pt)
7646     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7647   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7648   if(!ret)
7649     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !");
7650   return ret;
7651 }
7652
7653 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7654 {
7655   return contentNotNull()->getUndergroundDataArrayTemplate();
7656 }
7657
7658 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7659
7660 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7661 {
7662 }
7663
7664 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileFieldNameScope(fieldName,meshName)
7665 {
7666 }
7667
7668 /*!
7669  * \param [in] fieldId field id in C mode
7670  */
7671 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7672 {
7673   med_field_type typcha;
7674   std::string dtunitOut,meshName;
7675   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut,meshName));
7676   setMeshName(meshName);
7677   setDtUnit(dtunitOut.c_str());
7678   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7679 }
7680
7681 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)
7682 try:MEDFileFieldNameScope(fieldName,meshName),_infos(infos)
7683 {
7684   setDtUnit(dtunit.c_str());
7685   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7686 }
7687 catch(INTERP_KERNEL::Exception& e)
7688 {
7689     throw e;
7690 }
7691
7692 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7693 {
7694   std::size_t ret(_mesh_name.capacity()+_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7695   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7696     ret+=(*it).capacity();
7697   return ret;
7698 }
7699
7700 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7701 {
7702   std::vector<const BigMemoryObject *> ret;
7703   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7704     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7705   return ret;
7706 }
7707
7708 /*!
7709  * 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
7710  * NULL.
7711  */
7712 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7713 {
7714   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7715   ret->setInfo(_infos);
7716   int sz=(int)_time_steps.size();
7717   for(const int *id=startIds;id!=endIds;id++)
7718     {
7719       if(*id>=0 && *id<sz)
7720         {
7721           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7722           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7723           if(tse)
7724             {
7725               tse->incrRef();
7726               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7727             }
7728           ret->pushBackTimeStep(tse2);
7729         }
7730       else
7731         {
7732           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7733           oss << " ! Should be in [0," << sz << ") !";
7734           throw INTERP_KERNEL::Exception(oss.str());
7735         }
7736     }
7737   if(ret->getNumberOfTS()>0)
7738     ret->synchronizeNameScope();
7739   ret->copyNameScope(*this);
7740   return ret.retn();
7741 }
7742
7743 /*!
7744  * 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
7745  * NULL.
7746  */
7747 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7748 {
7749   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7750   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7751   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7752   ret->setInfo(_infos);
7753   int sz=(int)_time_steps.size();
7754   int j=bg;
7755   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7756     {
7757       if(j>=0 && j<sz)
7758         {
7759           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7760           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7761           if(tse)
7762             {
7763               tse->incrRef();
7764               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7765             }
7766           ret->pushBackTimeStep(tse2);
7767         }
7768       else
7769         {
7770           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7771           oss << " ! Should be in [0," << sz << ") !";
7772           throw INTERP_KERNEL::Exception(oss.str());
7773         }
7774     }
7775   if(ret->getNumberOfTS()>0)
7776     ret->synchronizeNameScope();
7777   ret->copyNameScope(*this);
7778   return ret.retn();
7779 }
7780
7781 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7782 {
7783   int id=0;
7784   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7785   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7786     {
7787       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7788       if(!cur)
7789         continue;
7790       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7791       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7792         ids->pushBackSilent(id);
7793     }
7794   return buildFromTimeStepIds(ids->begin(),ids->end());
7795 }
7796
7797 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7798 {
7799   int id=0;
7800   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7801   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7802     {
7803       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7804       if(!cur)
7805         continue;
7806       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7807       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7808         ids->pushBackSilent(id);
7809     }
7810   return buildFromTimeStepIds(ids->begin(),ids->end());
7811 }
7812
7813 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
7814 {
7815   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7816     if((*it).isNotNull())
7817       if((*it)->presenceOfStructureElements())
7818         return true;
7819   return false;
7820 }
7821
7822 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
7823 {
7824   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7825     if((*it).isNotNull())
7826       if(!(*it)->onlyStructureElements())
7827         return false;
7828   return true;
7829 }
7830
7831 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
7832 {
7833   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7834   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7835     if((*it).isNotNull())
7836       {
7837         if((*it)->presenceOfStructureElements())
7838           {
7839             if(!(*it)->onlyStructureElements())
7840               {
7841                 (*it)->killStructureElements();
7842                 ret.push_back(*it);
7843               }
7844           }
7845         else
7846           {
7847             ret.push_back(*it);
7848           }
7849       }
7850   _time_steps=ret;
7851 }
7852
7853 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
7854 {
7855   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7856   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7857     if((*it).isNotNull())
7858       {
7859         if((*it)->presenceOfStructureElements())
7860           {
7861             if(!(*it)->onlyStructureElements())
7862               (*it)->keepOnlyStructureElements();
7863             ret.push_back(*it);
7864           }
7865       }
7866   _time_steps=ret;
7867 }
7868
7869 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
7870 {
7871   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7872   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7873     if((*it).isNotNull())
7874       (*it)->keepOnlyOnSE(seName);
7875 }
7876
7877 void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
7878 {
7879   std::vector< std::pair<std::string,std::string> > ps2;
7880   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7881     if((*it).isNotNull())
7882       {
7883         (*it)->getMeshSENames(ps2);
7884         break;
7885       }
7886   if(ps2.empty())
7887     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
7888   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7889     if((*it).isNotNull())
7890       {
7891         std::vector< std::pair<std::string,std::string> > ps3;
7892         (*it)->getMeshSENames(ps3);
7893         if(ps2!=ps3)
7894           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
7895       }
7896   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
7897     {
7898       std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
7899       if(it2==ps.end())
7900         ps.push_back(*it);
7901     }
7902 }
7903
7904 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7905 {
7906   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7907     {
7908       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7909       if(!cur)
7910         continue;
7911       if(cur->presenceOfMultiDiscPerGeoType())
7912         return true;
7913     }
7914   return false;
7915 }
7916
7917 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7918 {
7919   return _infos;
7920 }
7921
7922 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7923 {
7924   _infos=info;
7925 }
7926
7927 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7928 {
7929   int ret=0;
7930   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7931     {
7932       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7933       if(pt->isDealingTS(iteration,order))
7934         return ret;
7935     }
7936   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7937   std::vector< std::pair<int,int> > vp=getIterations();
7938   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7939     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7940   throw INTERP_KERNEL::Exception(oss.str());
7941 }
7942
7943 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7944 {
7945   return *_time_steps[getTimeStepPos(iteration,order)];
7946 }
7947
7948 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7949 {
7950   return *_time_steps[getTimeStepPos(iteration,order)];
7951 }
7952
7953 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7954 {
7955   bool ret(false);
7956   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
7957     {
7958       if((*it).first==getMeshName())
7959         {
7960           setMeshName((*it).second);
7961           ret=true;
7962         }
7963     }
7964   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7965     {
7966       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7967       if(cur)
7968         ret=cur->changeMeshNames(modifTab) || ret;
7969     }
7970   return ret;
7971 }
7972
7973 /*!
7974  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7975  */
7976 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7977 {
7978   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7979 }
7980
7981 /*!
7982  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7983  */
7984 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7985 {
7986   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7987 }
7988
7989 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7990                                                                        MEDFileFieldGlobsReal& glob)
7991 {
7992   bool ret=false;
7993   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7994     {
7995       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7996       if(f1ts)
7997         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7998     }
7999   return ret;
8000 }
8001
8002 void MEDFileAnyTypeFieldMultiTSWithoutSDA::accept(MEDFileFieldVisitor& visitor) const
8003 {
8004   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8005     if((*it).isNotNull())
8006       {
8007         visitor.newTimeStepEntry(*it);
8008         (*it)->accept(visitor);
8009         visitor.endTimeStepEntry(*it);
8010       }
8011 }
8012
8013 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8014 {
8015   std::string startLine(bkOffset,' ');
8016   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
8017   if(fmtsId>=0)
8018     oss << " (" << fmtsId << ")";
8019   oss << " has the following name: \"" << _name << "\"." << std::endl;
8020   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
8021   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
8022     {
8023       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
8024     }
8025   int i=0;
8026   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8027     {
8028       std::string chapter(17,'0'+i);
8029       oss << startLine << chapter << std::endl;
8030       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
8031       if(cur)
8032         cur->simpleRepr(bkOffset+2,oss,i);
8033       else
8034         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
8035       oss << startLine << chapter << std::endl;
8036     }
8037 }
8038
8039 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
8040 {
8041   std::size_t sz=_time_steps.size();
8042   std::vector< std::pair<int,int> > ret(sz);
8043   ret1.resize(sz);
8044   for(std::size_t i=0;i<sz;i++)
8045     {
8046       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
8047       if(f1ts)
8048         {
8049           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
8050         }
8051       else
8052         {
8053           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
8054           throw INTERP_KERNEL::Exception(oss.str());
8055         }
8056     }
8057   return ret;
8058 }
8059
8060 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
8061 {
8062   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
8063   if(!tse2)
8064     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
8065   checkCoherencyOfType(tse2);
8066   if(_time_steps.empty())
8067     {
8068       setName(tse2->getName());
8069       setMeshName(tse2->getMeshName());
8070       setInfo(tse2->getInfo());
8071     }
8072   checkThatComponentsMatch(tse2->getInfo());
8073   if(getDtUnit().empty() && !tse->getDtUnit().empty())
8074     setDtUnit(tse->getDtUnit());
8075   _time_steps.push_back(tse);
8076 }
8077
8078 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
8079 {
8080   std::size_t nbOfCompo=_infos.size();
8081   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8082     {
8083       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
8084       if(cur)
8085         {
8086           if((cur->getInfo()).size()!=nbOfCompo)
8087             {
8088               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
8089               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
8090               throw INTERP_KERNEL::Exception(oss.str());
8091             }
8092           cur->copyNameScope(*this);
8093         }
8094     }
8095 }
8096
8097 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8098 {
8099   _time_steps.resize(nbPdt);
8100   for(int i=0;i<nbPdt;i++)
8101     {
8102       std::vector< std::pair<int,int> > ts;
8103       med_int numdt=0,numo=0;
8104       med_float dt=0.0;
8105       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
8106       switch(fieldTyp)
8107       {
8108         case MED_FLOAT64:
8109           {
8110             _time_steps[i]=MEDFileField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
8111             break;
8112           }
8113         case MED_INT32:
8114           {
8115             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
8116             break;
8117           }
8118         default:
8119           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
8120       }
8121       if(loadAll)
8122         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
8123       else
8124         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
8125       synchronizeNameScope();
8126     }
8127 }
8128
8129 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
8130 {
8131   if(_time_steps.empty())
8132     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
8133   checkThatNbOfCompoOfTSMatchThis();
8134   std::vector<std::string> infos(getInfo());
8135   int nbComp=infos.size();
8136   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
8137   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
8138   for(int i=0;i<nbComp;i++)
8139     {
8140       std::string info=infos[i];
8141       std::string c,u;
8142       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
8143       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
8144       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
8145     }
8146   if(_name.empty())
8147     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
8148   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
8149   int nbOfTS=_time_steps.size();
8150   for(int i=0;i<nbOfTS;i++)
8151     _time_steps[i]->writeLL(fid,opts,*this);
8152 }
8153
8154 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
8155 {
8156   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8157     {
8158       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8159       if(elt)
8160         elt->loadBigArraysRecursively(fid,nasc);
8161     }
8162 }
8163
8164 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
8165 {
8166   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8167     {
8168       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8169       if(elt)
8170         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
8171     }
8172 }
8173
8174 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
8175 {
8176   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8177     {
8178       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8179       if(elt)
8180         elt->unloadArrays();
8181     }
8182 }
8183
8184 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
8185 {
8186   return _time_steps.size();
8187 }
8188
8189 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
8190 {
8191   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
8192   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8193     {
8194       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
8195       if(tmp)
8196         newTS.push_back(*it);
8197     }
8198   _time_steps=newTS;
8199 }
8200
8201 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
8202 {
8203   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
8204   int maxId=(int)_time_steps.size();
8205   int ii=0;
8206   std::set<int> idsToDel;
8207   for(const int *id=startIds;id!=endIds;id++,ii++)
8208     {
8209       if(*id>=0 && *id<maxId)
8210         {
8211           idsToDel.insert(*id);
8212         }
8213       else
8214         {
8215           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
8216           throw INTERP_KERNEL::Exception(oss.str());
8217         }
8218     }
8219   for(int iii=0;iii<maxId;iii++)
8220     if(idsToDel.find(iii)==idsToDel.end())
8221       newTS.push_back(_time_steps[iii]);
8222   _time_steps=newTS;
8223 }
8224
8225 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
8226 {
8227   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
8228   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
8229   if(nbOfEntriesToKill==0)
8230     return ;
8231   std::size_t sz=_time_steps.size();
8232   std::vector<bool> b(sz,true);
8233   int j=bg;
8234   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
8235     b[j]=false;
8236   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
8237   for(std::size_t i=0;i<sz;i++)
8238     if(b[i])
8239       newTS.push_back(_time_steps[i]);
8240   _time_steps=newTS;
8241 }
8242
8243 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
8244 {
8245   int ret=0;
8246   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
8247   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
8248     {
8249       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
8250       if(tmp)
8251         {
8252           int it2,ord;
8253           tmp->getTime(it2,ord);
8254           if(it2==iteration && order==ord)
8255             return ret;
8256           else
8257             oss << "(" << it2 << ","  << ord << "), ";
8258         }
8259     }
8260   throw INTERP_KERNEL::Exception(oss.str());
8261 }
8262
8263 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
8264 {
8265   int ret=0;
8266   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
8267   oss.precision(15);
8268   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
8269     {
8270       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
8271       if(tmp)
8272         {
8273           int it2,ord;
8274           double ti=tmp->getTime(it2,ord);
8275           if(fabs(time-ti)<eps)
8276             return ret;
8277           else
8278             oss << ti << ", ";
8279         }
8280     }
8281   throw INTERP_KERNEL::Exception(oss.str());
8282 }
8283
8284 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
8285 {
8286   int lgth=_time_steps.size();
8287   std::vector< std::pair<int,int> > ret(lgth);
8288   for(int i=0;i<lgth;i++)
8289     _time_steps[i]->fillIteration(ret[i]);
8290   return ret;
8291 }
8292
8293 /*!
8294  * 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'
8295  * This method returns two things.
8296  * - The absolute dimension of 'this' in first parameter. 
8297  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
8298  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
8299  *
8300  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
8301  * Only these 3 discretizations will be taken into account here.
8302  *
8303  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
8304  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
8305  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
8306  *
8307  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
8308  * 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'.
8309  * 
8310  * Let's consider the typical following case :
8311  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
8312  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
8313  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
8314  *   TETRA4 and SEG2
8315  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
8316  *
8317  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
8318  * 
8319  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
8320  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
8321  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
8322  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
8323  */
8324 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8325 {
8326   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
8327 }
8328
8329 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
8330 {
8331   if(pos<0 || pos>=(int)_time_steps.size())
8332     {
8333       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8334       throw INTERP_KERNEL::Exception(oss.str());
8335     }
8336   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8337   if(item==0)
8338     {
8339       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8340       oss << "\nTry to use following method eraseEmptyTS !";
8341       throw INTERP_KERNEL::Exception(oss.str());
8342     }
8343   return item;
8344 }
8345
8346 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
8347 {
8348   if(pos<0 || pos>=(int)_time_steps.size())
8349     {
8350       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8351       throw INTERP_KERNEL::Exception(oss.str());
8352     }
8353   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8354   if(item==0)
8355     {
8356       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8357       oss << "\nTry to use following method eraseEmptyTS !";
8358       throw INTERP_KERNEL::Exception(oss.str());
8359     }
8360   return item;
8361 }
8362
8363 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
8364 {
8365   std::vector<std::string> ret;
8366   std::set<std::string> ret2;
8367   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8368     {
8369       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
8370       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8371         if(ret2.find(*it2)==ret2.end())
8372           {
8373             ret.push_back(*it2);
8374             ret2.insert(*it2);
8375           }
8376     }
8377   return ret;
8378 }
8379
8380 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
8381 {
8382   std::vector<std::string> ret;
8383   std::set<std::string> ret2;
8384   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8385     {
8386       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8387       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8388         if(ret2.find(*it2)==ret2.end())
8389           {
8390             ret.push_back(*it2);
8391             ret2.insert(*it2);
8392           }
8393     }
8394   return ret;
8395 }
8396
8397 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
8398 {
8399   std::vector<std::string> ret;
8400   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8401     {
8402       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
8403       ret.insert(ret.end(),tmp.begin(),tmp.end());
8404     }
8405   return ret;
8406 }
8407
8408 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
8409 {
8410   std::vector<std::string> ret;
8411   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8412     {
8413       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
8414       ret.insert(ret.end(),tmp.begin(),tmp.end());
8415     }
8416   return ret;
8417 }
8418
8419 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8420 {
8421   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8422     (*it)->changePflsRefsNamesGen2(mapOfModif);
8423 }
8424
8425 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8426 {
8427   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8428     (*it)->changeLocsRefsNamesGen2(mapOfModif);
8429 }
8430
8431 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
8432 {
8433   int lgth=_time_steps.size();
8434   std::vector< std::vector<TypeOfField> > ret(lgth);
8435   for(int i=0;i<lgth;i++)
8436     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
8437   return ret;
8438 }
8439
8440 /*!
8441  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
8442  */
8443 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
8444 {
8445   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
8446 }
8447
8448 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
8449 {
8450   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
8451   std::size_t i=0;
8452   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8453     {
8454       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
8455         ret->_time_steps[i]=(*it)->deepCopy();
8456     }
8457   return ret.retn();
8458 }
8459
8460 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
8461 {
8462   std::size_t sz(_infos.size()),sz2(_time_steps.size());
8463   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
8464   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
8465   for(std::size_t i=0;i<sz;i++)
8466     {
8467       ret[i]=shallowCpy();
8468       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
8469     }
8470   for(std::size_t i=0;i<sz2;i++)
8471     {
8472       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
8473       if(ret1.size()!=sz)
8474         {
8475           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
8476           throw INTERP_KERNEL::Exception(oss.str());
8477         }
8478       ts[i]=ret1;
8479     }
8480   for(std::size_t i=0;i<sz;i++)
8481     for(std::size_t j=0;j<sz2;j++)
8482       ret[i]->_time_steps[j]=ts[j][i];
8483   return ret;
8484 }
8485
8486 /*!
8487  * This method splits into discretization each time steps in \a this.
8488  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
8489  */
8490 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
8491 {
8492   std::size_t sz(_time_steps.size());
8493   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8494   for(std::size_t i=0;i<sz;i++)
8495     {
8496       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8497       if(!timeStep)
8498         {
8499           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
8500           throw INTERP_KERNEL::Exception(oss.str());
8501         }
8502       items[i]=timeStep->splitDiscretizations();  
8503     }
8504   //
8505   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
8506   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
8507   std::vector< TypeOfField > types;
8508   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8509     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8510       {
8511         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
8512         if(ts.size()!=1)
8513           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
8514         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
8515         if(it2==types.end())
8516           types.push_back(ts[0]);
8517       }
8518   ret.resize(types.size()); ret2.resize(types.size());
8519   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8520     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8521       {
8522         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
8523         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
8524         ret2[pos].push_back(*it1);
8525       }
8526   for(std::size_t i=0;i<types.size();i++)
8527     {
8528       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8529       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
8530         elt->pushBackTimeStep(*it1);//also updates infos in elt
8531       ret[i]=elt;
8532       elt->MEDFileFieldNameScope::operator=(*this);
8533     }
8534   return ret;
8535 }
8536
8537 /*!
8538  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
8539  */
8540 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
8541 {
8542   std::size_t sz(_time_steps.size());
8543   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8544   std::size_t szOut(std::numeric_limits<std::size_t>::max());
8545   for(std::size_t i=0;i<sz;i++)
8546     {
8547       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8548       if(!timeStep)
8549         {
8550           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
8551           throw INTERP_KERNEL::Exception(oss.str());
8552         }
8553       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
8554       if(szOut==std::numeric_limits<std::size_t>::max())
8555         szOut=items[i].size();
8556       else
8557         if(items[i].size()!=szOut)
8558           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
8559     }
8560   if(szOut==std::numeric_limits<std::size_t>::max())
8561     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
8562   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
8563   for(std::size_t i=0;i<szOut;i++)
8564     {
8565       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8566       for(std::size_t j=0;j<sz;j++)
8567         elt->pushBackTimeStep(items[j][i]);
8568       ret[i]=elt;
8569       elt->MEDFileFieldNameScope::operator=(*this);
8570     }
8571   return ret;
8572 }
8573
8574 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
8575 {
8576   setName(field->getName());
8577   if(field->getMesh())
8578     setMeshName(field->getMesh()->getName());
8579   if(_name.empty())
8580     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
8581   if(!arr)
8582     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
8583   _infos=arr->getInfoOnComponents();
8584 }
8585
8586 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
8587 {
8588   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
8589   if(_name!=field->getName())
8590     {
8591       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
8592       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
8593       throw INTERP_KERNEL::Exception(oss.str());
8594     }
8595   if(!arr)
8596     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
8597   checkThatComponentsMatch(arr->getInfoOnComponents());
8598 }
8599
8600 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
8601 {
8602   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
8603   if(getInfo().size()!=compos.size())
8604     {
8605       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
8606       oss << " number of components of element to append (" << compos.size() << ") !";
8607       throw INTERP_KERNEL::Exception(oss.str());
8608     }
8609   if(_infos!=compos)
8610     {
8611       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
8612       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
8613       oss << " But compo in input fields are : ";
8614       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
8615       oss << " !";
8616       throw INTERP_KERNEL::Exception(oss.str());
8617     }
8618 }
8619
8620 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
8621 {
8622   std::size_t sz=_infos.size();
8623   int j=0;
8624   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
8625     {
8626       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8627       if(elt)
8628         if(elt->getInfo().size()!=sz)
8629           {
8630             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
8631             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
8632             throw INTERP_KERNEL::Exception(oss.str());
8633           }
8634     }
8635 }
8636
8637 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8638 {
8639   if(!field)
8640     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8641   if(!_time_steps.empty())
8642     checkCoherencyOfTinyInfo(field,arr);
8643   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8644   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8645   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8646   copyTinyInfoFrom(field,arr);
8647   _time_steps.push_back(obj);
8648 }
8649
8650 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8651 {
8652   if(!field)
8653     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8654   if(!_time_steps.empty())
8655     checkCoherencyOfTinyInfo(field,arr);
8656   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8657   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8658   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8659   copyTinyInfoFrom(field,arr);
8660   setMeshName(objC->getMeshName());
8661   _time_steps.push_back(obj);
8662 }
8663
8664 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8665 {
8666   int sz=(int)_time_steps.size();
8667   if(i<0 || i>=sz)
8668     {
8669       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8670       throw INTERP_KERNEL::Exception(oss.str());
8671     }
8672   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8673   if(tsPtr)
8674     {
8675       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8676         {
8677           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8678           throw INTERP_KERNEL::Exception(oss.str());
8679         }
8680     }
8681   _time_steps[i]=ts;
8682 }
8683
8684 //= MEDFileFieldMultiTSWithoutSDA
8685
8686 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(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)
8687 {
8688   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8689 }
8690
8691 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8692 {
8693 }
8694
8695 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName,meshName)
8696 {
8697 }
8698
8699 /*!
8700  * \param [in] fieldId field id in C mode
8701  */
8702 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8703 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8704 {
8705 }
8706 catch(INTERP_KERNEL::Exception& e)
8707 { throw e; }
8708
8709 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(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)
8710 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8711 {
8712 }
8713 catch(INTERP_KERNEL::Exception& e)
8714 { throw e; }
8715
8716 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8717 {
8718   return new MEDFileField1TSWithoutSDA;
8719 }
8720
8721 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8722 {
8723   if(!f1ts)
8724     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8725   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8726   if(!f1tsC)
8727     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8728 }
8729
8730 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8731 {
8732   return MEDFileField1TSWithoutSDA::TYPE_STR;
8733 }
8734
8735 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8736 {
8737   return new MEDFileFieldMultiTSWithoutSDA(*this);
8738 }
8739
8740 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8741 {
8742   return new MEDFileFieldMultiTSWithoutSDA;
8743 }
8744
8745 /*!
8746  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8747  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8748  */
8749 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
8750 {
8751   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8752   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8753   if(!myF1TSC)
8754     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8755   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8756 }
8757
8758 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8759 {
8760   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8761   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8762   int i=0;
8763   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8764     {
8765       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8766       if(eltToConv)
8767         {
8768           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8769           if(!eltToConvC)
8770             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8771           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8772           ret->setIteration(i,elt);
8773         }
8774     }
8775   return ret.retn();
8776 }
8777
8778 //= MEDFileAnyTypeFieldMultiTS
8779
8780 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8781 {
8782 }
8783
8784 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8785 try:MEDFileFieldGlobsReal(fid)
8786 {
8787   _content=BuildContentFrom(fid,loadAll,ms);
8788   loadGlobals(fid);
8789 }
8790 catch(INTERP_KERNEL::Exception& e)
8791 {
8792     throw e;
8793 }
8794
8795 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8796 {
8797   med_field_type typcha;
8798   std::vector<std::string> infos;
8799   std::string dtunit;
8800   std::string meshName;
8801   int i(-1);
8802   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit,meshName);
8803   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8804   switch(typcha)
8805   {
8806     case MED_FLOAT64:
8807       {
8808         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8809         break;
8810       }
8811     case MED_INT32:
8812       {
8813         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8814         break;
8815       }
8816     default:
8817       {
8818         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] !";
8819         throw INTERP_KERNEL::Exception(oss.str());
8820       }
8821   }
8822   ret->setMeshName(meshName);
8823   ret->setDtUnit(dtunit.c_str());
8824   return ret.retn();
8825 }
8826
8827 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8828 {
8829   med_field_type typcha;
8830   //
8831   std::vector<std::string> infos;
8832   std::string dtunit,fieldName,meshName;
8833   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit,meshName);
8834   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8835   switch(typcha)
8836   {
8837     case MED_FLOAT64:
8838       {
8839         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8840         break;
8841       }
8842     case MED_INT32:
8843       {
8844         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8845         break;
8846       }
8847     default:
8848       {
8849         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] !";
8850         throw INTERP_KERNEL::Exception(oss.str());
8851       }
8852   }
8853   ret->setMeshName(meshName);
8854   ret->setDtUnit(dtunit.c_str());
8855   return ret.retn();
8856 }
8857
8858 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8859 {
8860   if(!c)
8861     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8862   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8863     {
8864       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8865       ret->_content=c;  c->incrRef();
8866       return ret.retn();
8867     }
8868   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8869     {
8870       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8871       ret->_content=c;  c->incrRef();
8872       return ret.retn();
8873     }
8874   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8875 }
8876
8877 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8878 {
8879   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8880   std::string fileName(FileNameFromFID(fid));
8881   ret->setFileName(fileName);
8882   return ret;
8883 }
8884
8885 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8886 try:MEDFileFieldGlobsReal(fid)
8887 {
8888   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8889   loadGlobals(fid);
8890 }
8891 catch(INTERP_KERNEL::Exception& e)
8892 {
8893     throw e;
8894 }
8895
8896 //= MEDFileIntFieldMultiTSWithoutSDA
8897
8898 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(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)
8899 {
8900   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8901 }
8902
8903 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8904 {
8905 }
8906
8907 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName,meshName)
8908 {
8909 }
8910
8911 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(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)
8912 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8913 {
8914 }
8915 catch(INTERP_KERNEL::Exception& e)
8916 { throw e; }
8917
8918 /*!
8919  * \param [in] fieldId field id in C mode
8920  */
8921 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8922 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8923 {
8924 }
8925 catch(INTERP_KERNEL::Exception& e)
8926 { throw e; }
8927
8928 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8929 {
8930   return new MEDFileIntField1TSWithoutSDA;
8931 }
8932
8933 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8934 {
8935   if(!f1ts)
8936     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8937   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8938   if(!f1tsC)
8939     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8940 }
8941
8942 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8943 {
8944   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8945 }
8946
8947 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8948 {
8949   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8950 }
8951
8952 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8953 {
8954   return new MEDFileIntFieldMultiTSWithoutSDA;
8955 }
8956
8957 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8958 {
8959   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8960   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8961   int i=0;
8962   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8963     {
8964       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8965       if(eltToConv)
8966         {
8967           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8968           if(!eltToConvC)
8969             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8970           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8971           ret->setIteration(i,elt);
8972         }
8973     }
8974   return ret.retn();
8975 }
8976
8977 //= MEDFileAnyTypeFieldMultiTS
8978
8979 /*!
8980  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8981  * that has been read from a specified MED file.
8982  *  \param [in] fileName - the name of the MED file to read.
8983  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8984  *          is to delete this field using decrRef() as it is no more needed.
8985  *  \throw If reading the file fails.
8986  */
8987 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8988 {
8989   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8990   return New(fid,loadAll);
8991 }
8992
8993 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8994 {
8995   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8996   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8997   ret->loadGlobals(fid);
8998   return ret.retn();
8999 }
9000
9001 /*!
9002  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
9003  * that has been read from a specified MED file.
9004  *  \param [in] fileName - the name of the MED file to read.
9005  *  \param [in] fieldName - the name of the field to read.
9006  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
9007  *          is to delete this field using decrRef() as it is no more needed.
9008  *  \throw If reading the file fails.
9009  *  \throw If there is no field named \a fieldName in the file.
9010  */
9011 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9012 {
9013   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9014   return New(fid,fieldName,loadAll);
9015 }
9016
9017 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9018 {
9019   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
9020   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
9021   ret->loadGlobals(fid);
9022   return ret.retn();
9023 }
9024
9025 /*!
9026  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9027  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9028  *
9029  * \warning this is a shallow copy constructor
9030  */
9031 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9032 {
9033   if(!shallowCopyOfContent)
9034     {
9035       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
9036       otherPtr->incrRef();
9037       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
9038     }
9039   else
9040     {
9041       _content=other.shallowCpy();
9042     }
9043 }
9044
9045 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
9046 {
9047   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
9048   if(!ret)
9049     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
9050   return ret;
9051 }
9052
9053 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
9054 {
9055   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
9056   if(!ret)
9057     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
9058   return ret;
9059 }
9060
9061 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
9062 {
9063   return contentNotNullBase()->getPflsReallyUsed2();
9064 }
9065
9066 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
9067 {
9068   return contentNotNullBase()->getLocsReallyUsed2();
9069 }
9070
9071 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
9072 {
9073   return contentNotNullBase()->getPflsReallyUsedMulti2();
9074 }
9075
9076 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
9077 {
9078   return contentNotNullBase()->getLocsReallyUsedMulti2();
9079 }
9080
9081 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9082 {
9083   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
9084 }
9085
9086 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9087 {
9088   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
9089 }
9090
9091 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
9092 {
9093   return contentNotNullBase()->getNumberOfTS();
9094 }
9095
9096 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
9097 {
9098   contentNotNullBase()->eraseEmptyTS();
9099 }
9100
9101 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
9102 {
9103   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
9104 }
9105
9106 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
9107 {
9108   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
9109 }
9110
9111 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
9112 {
9113   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
9114   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9115   ret->_content=c;
9116   return ret.retn();
9117 }
9118
9119 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
9120 {
9121   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
9122   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9123   ret->_content=c;
9124   return ret.retn();
9125 }
9126
9127 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
9128 {
9129   return contentNotNullBase()->getIterations();
9130 }
9131
9132 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
9133 {
9134   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
9135     pushBackTimeStep(*it);
9136 }
9137
9138 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
9139 {
9140   if(!fmts)
9141     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
9142   int nbOfTS(fmts->getNumberOfTS());
9143   for(int i=0;i<nbOfTS;i++)
9144     {
9145       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
9146       pushBackTimeStep(elt);
9147     }
9148 }
9149
9150 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
9151 {
9152   if(!f1ts)
9153     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
9154   checkCoherencyOfType(f1ts);
9155   f1ts->incrRef();
9156   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
9157   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
9158   c->incrRef();
9159   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
9160   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
9161     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
9162   _content->pushBackTimeStep(cSafe);
9163   appendGlobs(*f1ts,1e-12);
9164 }
9165
9166 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
9167 {
9168   contentNotNullBase()->synchronizeNameScope();
9169 }
9170
9171 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
9172 {
9173   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
9174 }
9175
9176 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
9177 {
9178   return contentNotNullBase()->getPosGivenTime(time,eps);
9179 }
9180
9181 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
9182 {
9183   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
9184 }
9185
9186 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
9187 {
9188   return contentNotNullBase()->getTypesOfFieldAvailable();
9189 }
9190
9191 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
9192 {
9193   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
9194 }
9195
9196 std::string MEDFileAnyTypeFieldMultiTS::getName() const
9197 {
9198   return contentNotNullBase()->getName();
9199 }
9200
9201 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
9202 {
9203   contentNotNullBase()->setName(name);
9204 }
9205
9206 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
9207 {
9208   return contentNotNullBase()->getDtUnit();
9209 }
9210
9211 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
9212 {
9213   contentNotNullBase()->setDtUnit(dtUnit);
9214 }
9215
9216 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
9217 {
9218   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
9219 }
9220
9221 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
9222 {
9223   return contentNotNullBase()->getTimeSteps(ret1);
9224 }
9225
9226 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
9227 {
9228   return contentNotNullBase()->getMeshName();
9229 }
9230
9231 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
9232 {
9233   contentNotNullBase()->setMeshName(newMeshName);
9234 }
9235
9236 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9237 {
9238   return contentNotNullBase()->changeMeshNames(modifTab);
9239 }
9240
9241 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
9242 {
9243   return contentNotNullBase()->getInfo();
9244 }
9245
9246 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
9247 {
9248   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
9249 }
9250
9251 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
9252 {
9253   return contentNotNullBase()->setInfo(info);
9254 }
9255
9256 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
9257 {
9258   const std::vector<std::string> ret=getInfo();
9259   return (int)ret.size();
9260 }
9261
9262 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
9263 {
9264   writeGlobals(fid,*this);
9265   contentNotNullBase()->writeLL(fid,*this);
9266 }
9267
9268 /*!
9269  * This method alloc the arrays and load potentially huge arrays contained in this field.
9270  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9271  * This method can be also called to refresh or reinit values from a file.
9272  * 
9273  * \throw If the fileName is not set or points to a non readable MED file.
9274  */
9275 void MEDFileAnyTypeFieldMultiTS::loadArrays()
9276 {
9277   if(getFileName().empty())
9278     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
9279   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9280   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
9281 }
9282
9283 /*!
9284  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9285  * But once data loaded once, this method does nothing.
9286  * 
9287  * \throw If the fileName is not set or points to a non readable MED file.
9288  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
9289  */
9290 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
9291 {
9292   if(!getFileName().empty())
9293     {
9294       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9295       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
9296     }
9297 }
9298
9299 /*!
9300  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9301  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9302  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
9303  * 
9304  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
9305  */
9306 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
9307 {
9308   contentNotNullBase()->unloadArrays();
9309 }
9310
9311 /*!
9312  * 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.
9313  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
9314  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9315  * 
9316  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
9317  */
9318 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
9319 {
9320   if(!getFileName().empty())
9321     contentNotNullBase()->unloadArrays();
9322 }
9323
9324 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
9325 {
9326   std::ostringstream oss;
9327   contentNotNullBase()->simpleRepr(0,oss,-1);
9328   simpleReprGlobs(oss);
9329   return oss.str();
9330 }
9331
9332 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
9333 {
9334   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
9335 }
9336
9337 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
9338 {
9339   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
9340   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
9341   return ret;
9342 }
9343
9344 /*!
9345  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
9346  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
9347  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
9348  */
9349 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
9350 {
9351   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9352   if(!content)
9353     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
9354   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
9355   std::size_t sz(contentsSplit.size());
9356   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9357   for(std::size_t i=0;i<sz;i++)
9358     {
9359       ret[i]=shallowCpy();
9360       ret[i]->_content=contentsSplit[i];
9361     }
9362   return ret;
9363 }
9364
9365 /*!
9366  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
9367  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9368  */
9369 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
9370 {
9371   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9372   if(!content)
9373     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
9374   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
9375   std::size_t sz(contentsSplit.size());
9376   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9377   for(std::size_t i=0;i<sz;i++)
9378     {
9379       ret[i]=shallowCpy();
9380       ret[i]->_content=contentsSplit[i];
9381     }
9382   return ret;
9383 }
9384
9385 /*!
9386  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
9387  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9388  */
9389 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
9390 {
9391   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9392   if(!content)
9393     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
9394   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
9395   std::size_t sz(contentsSplit.size());
9396   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9397   for(std::size_t i=0;i<sz;i++)
9398     {
9399       ret[i]=shallowCpy();
9400       ret[i]->_content=contentsSplit[i];
9401     }
9402   return ret;
9403 }
9404
9405 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
9406 {
9407   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9408   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
9409     ret->_content=_content->deepCopy();
9410   ret->deepCpyGlobs(*this);
9411   return ret.retn();
9412 }
9413
9414 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
9415 {
9416   return _content;
9417 }
9418
9419 /*!
9420  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9421  *  \param [in] iteration - the iteration number of a required time step.
9422  *  \param [in] order - the iteration order number of required time step.
9423  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
9424  *          delete this field using decrRef() as it is no more needed.
9425  *  \throw If there is no required time step in \a this field.
9426  */
9427 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
9428 {
9429   int pos=getPosOfTimeStep(iteration,order);
9430   return getTimeStepAtPos(pos);
9431 }
9432
9433 /*!
9434  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9435  *  \param [in] time - the time of the time step of interest.
9436  *  \param [in] eps - a precision used to compare time values.
9437  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9438  *          delete this field using decrRef() as it is no more needed.
9439  *  \throw If there is no required time step in \a this field.
9440  */
9441 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
9442 {
9443   int pos=getPosGivenTime(time,eps);
9444   return getTimeStepAtPos(pos);
9445 }
9446
9447 /*!
9448  * 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.
9449  * The float64 value of time attached to the pair of integers are not considered here.
9450  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
9451  *
9452  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
9453  * \throw If there is a null pointer in \a vectFMTS.
9454  */
9455 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
9456 {
9457   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
9458   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9459   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9460   while(!lstFMTS.empty())
9461     {
9462       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9463       MEDFileAnyTypeFieldMultiTS *curIt(*it);
9464       if(!curIt)
9465         throw INTERP_KERNEL::Exception(msg);
9466       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
9467       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9468       elt.push_back(curIt); it=lstFMTS.erase(it);
9469       while(it!=lstFMTS.end())
9470         {
9471           curIt=*it;
9472           if(!curIt)
9473             throw INTERP_KERNEL::Exception(msg);
9474           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
9475           if(refIts==curIts)
9476             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9477           else
9478             it++;
9479         }
9480       ret.push_back(elt);
9481     }
9482   return ret;
9483 }
9484
9485 /*!
9486  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
9487  * All returned instances in a subvector can be safely loaded, rendered along time
9488  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
9489  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
9490  * 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).
9491  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
9492  * 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.
9493  *
9494  * \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().
9495  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
9496  * \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.
9497  * \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.
9498  *
9499  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
9500  * \throw If an element in \a vectFMTS change of spatial discretization along time.
9501  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
9502  * \thorw If some elements in \a vectFMTS do not have the same times steps.
9503  * \throw If mesh is null.
9504  * \throw If an element in \a vectFMTS is null.
9505  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
9506  */
9507 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
9508 {
9509   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
9510   if(!mesh)
9511     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
9512   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9513   if(vectFMTS.empty())
9514     return ret;
9515   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
9516   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
9517   if(!frstElt)
9518     throw INTERP_KERNEL::Exception(msg);
9519   std::size_t i=0;
9520   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
9521   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
9522   for(;it!=vectFMTS.end();it++,i++)
9523     {
9524       if(!(*it))
9525         throw INTERP_KERNEL::Exception(msg);
9526       TypeOfField tof0,tof1;
9527       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
9528         {
9529           if(tof1!=ON_NODES)
9530             vectFMTSNotNodes.push_back(*it);
9531           else
9532             vectFMTSNodes.push_back(*it);
9533         }
9534       else
9535         vectFMTSNotNodes.push_back(*it);
9536     }
9537   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
9538   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
9539   ret=retCell;
9540   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
9541     {
9542       i=0;
9543       bool isFetched(false);
9544       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
9545         {
9546           if((*it0).empty())
9547             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
9548           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
9549             { ret[i].push_back(*it2); isFetched=true; }
9550         }
9551       if(!isFetched)
9552         {
9553           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
9554           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
9555           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
9556         }
9557     }
9558   fsc=cmps;
9559   return ret;
9560 }
9561
9562 /*!
9563  * 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.
9564  * \param [out] cmps - same size than the returned vector.
9565  */
9566 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
9567 {
9568   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9569   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9570   while(!lstFMTS.empty())
9571     {
9572       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9573       MEDFileAnyTypeFieldMultiTS *ref(*it);
9574       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9575       elt.push_back(ref); it=lstFMTS.erase(it);
9576       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
9577       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
9578       while(it!=lstFMTS.end())
9579         {
9580           MEDFileAnyTypeFieldMultiTS *curIt(*it);
9581           if(cmp->isEqual(curIt))
9582             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9583           else
9584             it++;
9585         }
9586       ret.push_back(elt); cmps.push_back(cmp);
9587     }
9588   return ret;
9589 }
9590
9591 /*!
9592  * 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.
9593  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
9594  *
9595  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
9596  * \throw If \a f0 or \a f1 change of spatial discretization along time.
9597  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
9598  * \thorw If \a f0 and \a f1 do not have the same times steps.
9599  * \throw If mesh is null.
9600  * \throw If \a f0 or \a f1 is null.
9601  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
9602  */
9603 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
9604 {
9605   if(!mesh)
9606     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
9607   if(!f0 || !f1)
9608     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
9609   if(f0->getMeshName()!=mesh->getName())
9610     {
9611       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9612       throw INTERP_KERNEL::Exception(oss.str());
9613     }
9614   if(f1->getMeshName()!=mesh->getName())
9615     {
9616       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9617       throw INTERP_KERNEL::Exception(oss.str());
9618     }
9619   int nts=f0->getNumberOfTS();
9620   if(nts!=f1->getNumberOfTS())
9621     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
9622   if(nts==0)
9623     return nts;
9624   for(int i=0;i<nts;i++)
9625     {
9626       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
9627       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
9628       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
9629       if(tofs0.size()!=1 || tofs1.size()!=1)
9630         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
9631       if(i!=0)
9632         {
9633           if(tof0!=tofs0[0] || tof1!=tofs1[0])
9634             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
9635         }
9636       else
9637         { tof0=tofs0[0]; tof1=tofs1[0]; }
9638       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9639         {
9640           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() << ") !";
9641           throw INTERP_KERNEL::Exception(oss.str());
9642         }
9643       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9644         {
9645           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() << ") !";
9646           throw INTERP_KERNEL::Exception(oss.str());
9647         }
9648       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9649         {
9650           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() << ") !";
9651           throw INTERP_KERNEL::Exception(oss.str());
9652         }
9653     }
9654   return nts;
9655 }
9656
9657 /*!
9658  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9659  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9660  *
9661  * \return A new object that the caller is responsible to deallocate.
9662  */
9663 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9664 {
9665   if(!mm)
9666     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9667   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9668   int nbTS(getNumberOfTS());
9669   for(int i=0;i<nbTS;i++)
9670     {
9671       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9672       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9673       fmtsOut->pushBackTimeStep(f1tsOut);
9674     }
9675   return fmtsOut.retn();
9676 }
9677
9678 template<class T>
9679 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9680 {
9681   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9682   if(f1tss.empty())
9683     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9684   std::size_t sz(f1tss.size()),i(0);
9685   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9686   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9687     {
9688       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9689       if(!elt)
9690         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9691       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9692     }
9693   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9694   if(!retc)
9695     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9696   retc->aggregate(f1tsw,dts);
9697   ret->setDtUnit(f1tss[0]->getDtUnit());
9698   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9699 }
9700
9701 template<class T>
9702 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9703 {
9704   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9705   if(fmtss.empty())
9706     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9707   std::size_t sz(fmtss.size());
9708   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9709     {
9710       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9711       if(!elt)
9712         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9713     }
9714   int nbTS(fmtss[0]->getNumberOfTS());
9715   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9716     if((*it)->getNumberOfTS()!=nbTS)
9717       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9718   for(int iterTS=0;iterTS<nbTS;iterTS++)
9719     {
9720       std::size_t i(0);
9721       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9722       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9723       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9724         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9725       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9726       ret->pushBackTimeStep(f1ts);
9727       ret->setDtUnit(f1ts->getDtUnit());
9728     }
9729   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9730 }
9731
9732 /*!
9733  * \a dts and \a ftmss are expected to have same size.
9734  */
9735 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9736 {
9737   if(fmtss.empty())
9738     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9739   std::size_t sz(fmtss.size());
9740   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9741   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9742   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9743     {
9744       if(!(*it))
9745         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9746       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9747       if(elt1)
9748         {
9749           fmtss1.push_back(elt1);
9750           continue;
9751         }
9752       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9753       if(elt2)
9754         {
9755           fmtss2.push_back(elt2);
9756           continue;
9757         }
9758       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9759     }
9760   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9761     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9762   if(fmtss1.size()==sz)
9763     return AggregateHelperFMTS<double>(fmtss1,dts);
9764   if(fmtss2.size()!=sz)
9765     return AggregateHelperFMTS<int>(fmtss2,dts);
9766   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9767 }
9768
9769 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9770 {
9771   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9772 }
9773
9774 //= MEDFileFieldMultiTS
9775
9776 /*!
9777  * Returns a new empty instance of MEDFileFieldMultiTS.
9778  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9779  *          is to delete this field using decrRef() as it is no more needed.
9780  */
9781 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9782 {
9783   return new MEDFileFieldMultiTS;
9784 }
9785
9786 /*!
9787  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9788  * that has been read from a specified MED file.
9789  *  \param [in] fileName - the name of the MED file to read.
9790  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9791  *          is to delete this field using decrRef() as it is no more needed.
9792  *  \throw If reading the file fails.
9793  */
9794 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9795 {
9796   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9797   return New(fid,loadAll);
9798 }
9799
9800 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9801 {
9802   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9803   ret->contentNotNull();//to check that content type matches with \a this type.
9804   return ret.retn();
9805 }
9806
9807 /*!
9808  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9809  * that has been read from a specified MED file.
9810  *  \param [in] fileName - the name of the MED file to read.
9811  *  \param [in] fieldName - the name of the field to read.
9812  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9813  *          is to delete this field using decrRef() as it is no more needed.
9814  *  \throw If reading the file fails.
9815  *  \throw If there is no field named \a fieldName in the file.
9816  */
9817 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9818 {
9819   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9820   return New(fid,fieldName,loadAll);
9821 }
9822
9823 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9824 {
9825   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9826   ret->contentNotNull();//to check that content type matches with \a this type.
9827   return ret.retn();
9828 }
9829
9830 /*!
9831  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9832  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9833  *
9834  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9835  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9836  * \warning this is a shallow copy constructor
9837  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9838  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9839  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9840  *          is to delete this field using decrRef() as it is no more needed.
9841  */
9842 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9843 {
9844   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9845 }
9846
9847 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9848 {
9849   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9850   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9851   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
9852   ret->contentNotNull();//to check that content type matches with \a this type.
9853   return ret.retn();
9854 }
9855
9856 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9857 {
9858   return new MEDFileFieldMultiTS(*this);
9859 }
9860
9861 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9862 {
9863   if(!f1ts)
9864     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9865   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9866   if(!f1tsC)
9867     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9868 }
9869
9870 /*!
9871  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9872  * following the given input policy.
9873  *
9874  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9875  *                            By default (true) the globals are deeply copied.
9876  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9877  */
9878 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9879 {
9880   MCAuto<MEDFileIntFieldMultiTS> ret;
9881   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9882   if(content)
9883     {
9884       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9885       if(!contc)
9886         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9887       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9888       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9889     }
9890   else
9891     ret=MEDFileIntFieldMultiTS::New();
9892   if(isDeepCpyGlobs)
9893     ret->deepCpyGlobs(*this);
9894   else
9895     ret->shallowCpyGlobs(*this);
9896   return ret.retn();
9897 }
9898
9899 /*!
9900  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9901  *  \param [in] pos - a time step id.
9902  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9903  *          delete this field using decrRef() as it is no more needed.
9904  *  \throw If \a pos is not a valid time step id.
9905  */
9906 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9907 {
9908   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9909   if(!item)
9910     {
9911       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9912       throw INTERP_KERNEL::Exception(oss.str());
9913     }
9914   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9915   if(itemC)
9916     {
9917       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9918       ret->shallowCpyGlobs(*this);
9919       return ret.retn();
9920     }
9921   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9922   throw INTERP_KERNEL::Exception(oss.str());
9923 }
9924
9925 /*!
9926  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9927  * mesh entities of a given dimension of the first mesh in MED file.
9928  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9929  *  \param [in] type - a spatial discretization of interest.
9930  *  \param [in] iteration - the iteration number of a required time step.
9931  *  \param [in] order - the iteration order number of required time step.
9932  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9933  *  \param [in] renumPol - specifies how to permute values of the result field according to
9934  *          the optional numbers of cells and nodes, if any. The valid values are
9935  *          - 0 - do not permute.
9936  *          - 1 - permute cells.
9937  *          - 2 - permute nodes.
9938  *          - 3 - permute cells and nodes.
9939  *
9940  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9941  *          caller is to delete this field using decrRef() as it is no more needed. 
9942  *  \throw If the MED file is not readable.
9943  *  \throw If there is no mesh in the MED file.
9944  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9945  *  \throw If no field values of the required parameters are available.
9946  */
9947 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9948 {
9949   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9950   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9951   if(!myF1TSC)
9952     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9953   MCAuto<DataArray> arrOut;
9954   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9955   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9956   return ret.retn();
9957 }
9958
9959 /*!
9960  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9961  * the top level cells of the first mesh in MED file.
9962  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9963  *  \param [in] type - a spatial discretization of interest.
9964  *  \param [in] iteration - the iteration number of a required time step.
9965  *  \param [in] order - the iteration order number of required time step.
9966  *  \param [in] renumPol - specifies how to permute values of the result field according to
9967  *          the optional numbers of cells and nodes, if any. The valid values are
9968  *          - 0 - do not permute.
9969  *          - 1 - permute cells.
9970  *          - 2 - permute nodes.
9971  *          - 3 - permute cells and nodes.
9972  *
9973  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9974  *          caller is to delete this field using decrRef() as it is no more needed. 
9975  *  \throw If the MED file is not readable.
9976  *  \throw If there is no mesh in the MED file.
9977  *  \throw If no field values of the required parameters are available.
9978  */
9979 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9980 {
9981   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9982   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9983   if(!myF1TSC)
9984     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9985   MCAuto<DataArray> arrOut;
9986   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9987   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9988   return ret.retn();
9989 }
9990
9991 /*!
9992  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
9993  * method should be called (getFieldOnMeshAtLevel for example).
9994  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9995  *
9996  * \param [in] iteration - the iteration number of a required time step.
9997  * \param [in] order - the iteration order number of required time step.
9998  * \param [in] mesh - the mesh the field is lying on
9999  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
10000  *          caller is to delete this field using decrRef() as it is no more needed. 
10001  */
10002 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
10003 {
10004   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10005   MCAuto<DataArray> arrOut;
10006   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
10007   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
10008   return ret.retn();
10009 }
10010
10011 /*!
10012  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
10013  * a given support.
10014  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10015  *  \param [in] type - a spatial discretization of interest.
10016  *  \param [in] iteration - the iteration number of a required time step.
10017  *  \param [in] order - the iteration order number of required time step.
10018  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10019  *  \param [in] mesh - the supporting mesh.
10020  *  \param [in] renumPol - specifies how to permute values of the result field according to
10021  *          the optional numbers of cells and nodes, if any. The valid values are
10022  *          - 0 - do not permute.
10023  *          - 1 - permute cells.
10024  *          - 2 - permute nodes.
10025  *          - 3 - permute cells and nodes.
10026  *
10027  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
10028  *          caller is to delete this field using decrRef() as it is no more needed. 
10029  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10030  *  \throw If no field of \a this is lying on \a mesh.
10031  *  \throw If no field values of the required parameters are available.
10032  */
10033 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10034 {
10035   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10036   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
10037   if(!myF1TSC)
10038     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
10039   MCAuto<DataArray> arrOut;
10040   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
10041   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
10042   return ret.retn();
10043 }
10044
10045 /*!
10046  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
10047  * given support. 
10048  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10049  *  \param [in] type - a spatial discretization of the new field.
10050  *  \param [in] iteration - the iteration number of a required time step.
10051  *  \param [in] order - the iteration order number of required time step.
10052  *  \param [in] mesh - the supporting mesh.
10053  *  \param [in] renumPol - specifies how to permute values of the result field according to
10054  *          the optional numbers of cells and nodes, if any. The valid values are
10055  *          - 0 - do not permute.
10056  *          - 1 - permute cells.
10057  *          - 2 - permute nodes.
10058  *          - 3 - permute cells and nodes.
10059  *
10060  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
10061  *          caller is to delete this field using decrRef() as it is no more needed. 
10062  *  \throw If no field of \a this is lying on \a mesh.
10063  *  \throw If no field values of the required parameters are available.
10064  */
10065 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10066 {
10067   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10068   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
10069   if(!myF1TSC)
10070     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
10071   MCAuto<DataArray> arrOut;
10072   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
10073   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
10074   return ret.retn();
10075 }
10076
10077 /*!
10078  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
10079  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10080  * This method is useful for MED2 file format when field on different mesh was autorized.
10081  */
10082 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
10083 {
10084   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10085   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
10086   if(!myF1TSC)
10087     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
10088   MCAuto<DataArray> arrOut;
10089   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
10090   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
10091   return ret.retn();
10092 }
10093
10094 /*!
10095  * Returns values and a profile of the field of a given type, of a given time step,
10096  * lying on a given support.
10097  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10098  *  \param [in] type - a spatial discretization of the field.
10099  *  \param [in] iteration - the iteration number of a required time step.
10100  *  \param [in] order - the iteration order number of required time step.
10101  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10102  *  \param [in] mesh - the supporting mesh.
10103  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10104  *          field of interest lies on. If the field lies on all entities of the given
10105  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10106  *          using decrRef() as it is no more needed.  
10107  *  \param [in] glob - the global data storing profiles and localization.
10108  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
10109  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10110  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10111  *  \throw If no field of \a this is lying on \a mesh.
10112  *  \throw If no field values of the required parameters are available.
10113  */
10114 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10115 {
10116   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10117   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
10118   if(!myF1TSC)
10119     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
10120   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10121   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
10122 }
10123
10124 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
10125 {
10126   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10127   if(!pt)
10128     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
10129   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
10130   if(!ret)
10131     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
10132   return ret;
10133 }
10134
10135 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
10136 {
10137   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10138   if(!pt)
10139     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
10140   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
10141   if(!ret)
10142     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !");
10143   return ret;
10144 }
10145
10146 /*!
10147  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
10148  * the given field is checked if its elements are sorted suitable for writing to MED file
10149  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10150  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10151  *  \param [in] field - the field to add to \a this.
10152  *  \throw If the name of \a field is empty.
10153  *  \throw If the data array of \a field is not set.
10154  *  \throw If existing time steps have different name or number of components than \a field.
10155  *  \throw If the underlying mesh of \a field has no name.
10156  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10157  */
10158 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
10159 {
10160   const DataArrayDouble *arr=0;
10161   if(field)
10162     arr=field->getArray();
10163   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
10164 }
10165
10166 /*!
10167  * Adds a MEDCouplingFieldDouble to \a this as another time step.
10168  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10169  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10170  * and \a profile.
10171  *
10172  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10173  * A new profile is added only if no equal profile is missing.
10174  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10175  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
10176  *  \param [in] mesh - the supporting mesh of \a field.
10177  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10178  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10179  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10180  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10181  *  \throw If the data array of \a field is not set.
10182  *  \throw If the data array of \a this is already allocated but has different number of
10183  *         components than \a field.
10184  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10185  *  \sa setFieldNoProfileSBT()
10186  */
10187 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10188 {
10189   const DataArrayDouble *arr=0;
10190   if(field)
10191     arr=field->getArray();
10192   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
10193 }
10194
10195 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
10196 {
10197   _content=new MEDFileFieldMultiTSWithoutSDA;
10198 }
10199
10200 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10201 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10202 {
10203 }
10204 catch(INTERP_KERNEL::Exception& e)
10205 { throw e; }
10206
10207 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10208 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10209 {
10210 }
10211 catch(INTERP_KERNEL::Exception& e)
10212 { throw e; }
10213
10214 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10215 {
10216 }
10217
10218 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
10219 {
10220   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
10221 }
10222
10223 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10224 {
10225   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10226 }
10227
10228 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
10229 {
10230   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
10231 }
10232
10233 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
10234 {
10235   return MEDFileFieldMultiTS::New();
10236 }
10237
10238 //= MEDFileAnyTypeFieldMultiTSIterator
10239
10240 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
10241 {
10242   if(fmts)
10243     {
10244       fmts->incrRef();
10245       _nb_iter=fmts->getNumberOfTS();
10246     }
10247 }
10248
10249 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
10250 {
10251 }
10252
10253 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
10254 {
10255   if(_iter_id<_nb_iter)
10256     {
10257       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
10258       if(fmts)
10259         return fmts->getTimeStepAtPos(_iter_id++);
10260       else
10261         return 0;
10262     }
10263   else
10264     return 0;
10265 }
10266
10267 //= MEDFileIntFieldMultiTS
10268
10269 /*!
10270  * Returns a new empty instance of MEDFileFieldMultiTS.
10271  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10272  *          is to delete this field using decrRef() as it is no more needed.
10273  */
10274 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
10275 {
10276   return new MEDFileIntFieldMultiTS;
10277 }
10278
10279 /*!
10280  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
10281  * that has been read from a specified MED file.
10282  *  \param [in] fileName - the name of the MED file to read.
10283  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10284  *          is to delete this field using decrRef() as it is no more needed.
10285  *  \throw If reading the file fails.
10286  */
10287 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
10288 {
10289   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10290   return New(fid,loadAll);
10291 }
10292
10293 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
10294 {
10295   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
10296   ret->contentNotNull();//to check that content type matches with \a this type.
10297   return ret.retn();
10298 }
10299
10300 /*!
10301  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
10302  * that has been read from a specified MED file.
10303  *  \param [in] fileName - the name of the MED file to read.
10304  *  \param [in] fieldName - the name of the field to read.
10305  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10306  *          is to delete this field using decrRef() as it is no more needed.
10307  *  \throw If reading the file fails.
10308  *  \throw If there is no field named \a fieldName in the file.
10309  */
10310 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
10311 {
10312   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10313   return New(fid,fieldName,loadAll);
10314 }
10315
10316 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
10317 {
10318   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
10319   ret->contentNotNull();//to check that content type matches with \a this type.
10320   return ret.retn();
10321 }
10322
10323 /*!
10324  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
10325  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
10326  *
10327  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
10328  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
10329  * \warning this is a shallow copy constructor
10330  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
10331  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
10332  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10333  *          is to delete this field using decrRef() as it is no more needed.
10334  */
10335 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
10336 {
10337   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
10338 }
10339
10340 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10341 {
10342   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10343   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10344   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
10345   ret->contentNotNull();//to check that content type matches with \a this type.
10346   return ret.retn();
10347 }
10348
10349 /*!
10350  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
10351  * following the given input policy.
10352  *
10353  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
10354  *                            By default (true) the globals are deeply copied.
10355  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
10356  */
10357 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
10358 {
10359   MCAuto<MEDFileFieldMultiTS> ret;
10360   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
10361   if(content)
10362     {
10363       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
10364       if(!contc)
10365         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
10366       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
10367       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
10368     }
10369   else
10370     ret=MEDFileFieldMultiTS::New();
10371   if(isDeepCpyGlobs)
10372     ret->deepCpyGlobs(*this);
10373   else
10374     ret->shallowCpyGlobs(*this);
10375   return ret.retn();
10376 }
10377
10378 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
10379 {
10380   return new MEDFileIntFieldMultiTS(*this);
10381 }
10382
10383 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
10384 {
10385   if(!f1ts)
10386     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
10387   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
10388   if(!f1tsC)
10389     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
10390 }
10391
10392 /*!
10393  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
10394  * method should be called (getFieldOnMeshAtLevel for example).
10395  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
10396  *
10397  * \param [in] iteration - the iteration number of a required time step.
10398  * \param [in] order - the iteration order number of required time step.
10399  * \param [in] mesh - the mesh the field is lying on
10400  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
10401  *          caller is to delete this field using decrRef() as it is no more needed. 
10402  */
10403 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
10404 {
10405   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10406   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10407   if(!myF1TSC)
10408     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
10409   MCAuto<DataArray> arrOut;
10410   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
10411   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
10412   return ret2.retn();
10413 }
10414
10415 /*!
10416  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10417  * mesh entities of a given dimension of the first mesh in MED file.
10418  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10419  *  \param [in] type - a spatial discretization of interest.
10420  *  \param [in] iteration - the iteration number of a required time step.
10421  *  \param [in] order - the iteration order number of required time step.
10422  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10423  *  \param [in] renumPol - specifies how to permute values of the result field according to
10424  *          the optional numbers of cells and nodes, if any. The valid values are
10425  *          - 0 - do not permute.
10426  *          - 1 - permute cells.
10427  *          - 2 - permute nodes.
10428  *          - 3 - permute cells and nodes.
10429  *
10430  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10431  *          caller is to delete this field using decrRef() as it is no more needed. 
10432  *  \throw If the MED file is not readable.
10433  *  \throw If there is no mesh in the MED file.
10434  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10435  *  \throw If no field values of the required parameters are available.
10436  */
10437 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
10438 {
10439   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10440   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10441   if(!myF1TSC)
10442     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
10443   MCAuto<DataArray> arr;
10444   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
10445   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10446   return ret2.retn();
10447 }
10448
10449 /*!
10450  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10451  * the top level cells of the first mesh in MED file.
10452  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10453  *  \param [in] type - a spatial discretization of interest.
10454  *  \param [in] iteration - the iteration number of a required time step.
10455  *  \param [in] order - the iteration order number of required time step.
10456  *  \param [in] renumPol - specifies how to permute values of the result field according to
10457  *          the optional numbers of cells and nodes, if any. The valid values are
10458  *          - 0 - do not permute.
10459  *          - 1 - permute cells.
10460  *          - 2 - permute nodes.
10461  *          - 3 - permute cells and nodes.
10462  *
10463  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10464  *          caller is to delete this field using decrRef() as it is no more needed. 
10465  *  \throw If the MED file is not readable.
10466  *  \throw If there is no mesh in the MED file.
10467  *  \throw If no field values of the required parameters are available.
10468  */
10469 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
10470 {
10471   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10472   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10473   if(!myF1TSC)
10474     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
10475   MCAuto<DataArray> arr;
10476   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
10477   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10478   return ret2.retn();
10479 }
10480
10481 /*!
10482  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10483  * a given support.
10484  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10485  *  \param [in] type - a spatial discretization of interest.
10486  *  \param [in] iteration - the iteration number of a required time step.
10487  *  \param [in] order - the iteration order number of required time step.
10488  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10489  *  \param [in] mesh - the supporting mesh.
10490  *  \param [in] renumPol - specifies how to permute values of the result field according to
10491  *          the optional numbers of cells and nodes, if any. The valid values are
10492  *          - 0 - do not permute.
10493  *          - 1 - permute cells.
10494  *          - 2 - permute nodes.
10495  *          - 3 - permute cells and nodes.
10496  *
10497  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10498  *          caller is to delete this field using decrRef() as it is no more needed. 
10499  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10500  *  \throw If no field of \a this is lying on \a mesh.
10501  *  \throw If no field values of the required parameters are available.
10502  */
10503 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10504 {
10505   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10506   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10507   if(!myF1TSC)
10508     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10509   MCAuto<DataArray> arr;
10510   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
10511   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10512   return ret2.retn();
10513 }
10514
10515 /*!
10516  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
10517  * given support. 
10518  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10519  *  \param [in] type - a spatial discretization of the new field.
10520  *  \param [in] iteration - the iteration number of a required time step.
10521  *  \param [in] order - the iteration order number of required time step.
10522  *  \param [in] mesh - the supporting mesh.
10523  *  \param [out] arrOut - the DataArrayInt containing values of field.
10524  *  \param [in] renumPol - specifies how to permute values of the result field according to
10525  *          the optional numbers of cells and nodes, if any. The valid values are
10526  *          - 0 - do not permute.
10527  *          - 1 - permute cells.
10528  *          - 2 - permute nodes.
10529  *          - 3 - permute cells and nodes.
10530  *
10531  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10532  *          caller is to delete this field using decrRef() as it is no more needed. 
10533  *  \throw If no field of \a this is lying on \a mesh.
10534  *  \throw If no field values of the required parameters are available.
10535  */
10536 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10537 {
10538   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10539   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10540   if(!myF1TSC)
10541     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10542   MCAuto<DataArray> arr;
10543   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
10544   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10545   return ret2.retn();
10546 }
10547
10548 /*!
10549  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
10550  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10551  * This method is useful for MED2 file format when field on different mesh was autorized.
10552  */
10553 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
10554 {
10555   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10556   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10557   if(!myF1TSC)
10558     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10559   MCAuto<DataArray> arr;
10560   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
10561   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10562   return ret2.retn();
10563 }
10564
10565 /*!
10566  * Returns values and a profile of the field of a given type, of a given time step,
10567  * lying on a given support.
10568  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10569  *  \param [in] type - a spatial discretization of the field.
10570  *  \param [in] iteration - the iteration number of a required time step.
10571  *  \param [in] order - the iteration order number of required time step.
10572  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10573  *  \param [in] mesh - the supporting mesh.
10574  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10575  *          field of interest lies on. If the field lies on all entities of the given
10576  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10577  *          using decrRef() as it is no more needed.  
10578  *  \param [in] glob - the global data storing profiles and localization.
10579  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
10580  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10581  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10582  *  \throw If no field of \a this is lying on \a mesh.
10583  *  \throw If no field values of the required parameters are available.
10584  */
10585 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10586 {
10587   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10588   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
10589   if(!myF1TSC)
10590     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
10591   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10592   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
10593 }
10594
10595 /*!
10596  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
10597  *  \param [in] pos - a time step id.
10598  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
10599  *          delete this field using decrRef() as it is no more needed.
10600  *  \throw If \a pos is not a valid time step id.
10601  */
10602 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
10603 {
10604   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
10605   if(!item)
10606     {
10607       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
10608       throw INTERP_KERNEL::Exception(oss.str());
10609     }
10610   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
10611   if(itemC)
10612     {
10613       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
10614       ret->shallowCpyGlobs(*this);
10615       return ret.retn();
10616     }
10617   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
10618   throw INTERP_KERNEL::Exception(oss.str());
10619 }
10620
10621 /*!
10622  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
10623  * the given field is checked if its elements are sorted suitable for writing to MED file
10624  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10625  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10626  *  \param [in] field - the field to add to \a this.
10627  *  \throw If the name of \a field is empty.
10628  *  \throw If the data array of \a field is not set.
10629  *  \throw If existing time steps have different name or number of components than \a field.
10630  *  \throw If the underlying mesh of \a field has no name.
10631  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10632  */
10633 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
10634 {
10635   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10636   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
10637 }
10638
10639 /*!
10640  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10641  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10642  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10643  * and \a profile.
10644  *
10645  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10646  * A new profile is added only if no equal profile is missing.
10647  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10648  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10649  *  \param [in] arrOfVals - the values of the field \a field used.
10650  *  \param [in] mesh - the supporting mesh of \a field.
10651  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10652  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10653  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10654  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10655  *  \throw If the data array of \a field is not set.
10656  *  \throw If the data array of \a this is already allocated but has different number of
10657  *         components than \a field.
10658  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10659  *  \sa setFieldNoProfileSBT()
10660  */
10661 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10662 {
10663   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10664   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10665 }
10666
10667 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10668 {
10669   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10670   if(!pt)
10671     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10672   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10673   if(!ret)
10674     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is not null but it is not of type int ! Reason is maybe that the read field has not the type INT32 !");
10675   return ret;
10676 }
10677
10678 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10679 {
10680   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10681   if(!pt)
10682     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10683   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10684   if(!ret)
10685     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is not null but it is not of type int ! Reason is maybe that the read field has not the type INT32 !");
10686   return ret;
10687 }
10688
10689 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10690 {
10691   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10692 }
10693
10694 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10695 {
10696 }
10697
10698 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10699 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10700 {
10701 }
10702 catch(INTERP_KERNEL::Exception& e)
10703 { throw e; }
10704
10705 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10706 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10707 {
10708 }
10709 catch(INTERP_KERNEL::Exception& e)
10710 { throw e; }
10711
10712 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10713 {
10714   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10715 }
10716
10717 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10718 {
10719   return MEDFileIntFieldMultiTS::New();
10720 }
10721
10722 //= MEDFileFields
10723
10724 MEDFileFields *MEDFileFields::New()
10725 {
10726   return new MEDFileFields;
10727 }
10728
10729 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10730 {
10731   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10732   return New(fid,loadAll);
10733 }
10734
10735 MEDFileFields *MEDFileFields::NewAdv(const std::string& fileName, bool loadAll, const MEDFileEntities *entities)
10736 {
10737   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10738   return NewAdv(fid,loadAll,entities);
10739 }
10740
10741 MEDFileFields *MEDFileFields::NewAdv(med_idt fid, bool loadAll, const MEDFileEntities *entities)
10742 {
10743   return new MEDFileFields(fid,loadAll,0,entities);
10744 }
10745
10746 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
10747 {
10748   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10749   return NewWithDynGT(fid,se,loadAll);
10750 }
10751
10752 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
10753 {
10754   if(!se)
10755     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
10756   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
10757   return new MEDFileFields(fid,loadAll,0,entities);
10758 }
10759
10760 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10761 {
10762   return new MEDFileFields(fid,loadAll,0,0);
10763 }
10764
10765 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10766 {
10767   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10768   return new MEDFileFields(fid,loadAll,ms,0);
10769 }
10770
10771 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10772 {
10773   MEDFileUtilities::CheckFileForRead(fileName);
10774   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10775   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10776   return new MEDFileFields(fid,loadAll,0,ent);
10777 }
10778
10779 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10780 {
10781   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10782   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10783   return ret;
10784 }
10785
10786 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10787 {
10788   std::vector<const BigMemoryObject *> ret;
10789   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10790     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10791   return ret;
10792 }
10793
10794 MEDFileFields *MEDFileFields::deepCopy() const
10795 {
10796   MCAuto<MEDFileFields> ret(shallowCpy());
10797   std::size_t i(0);
10798   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10799     {
10800       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10801         ret->_fields[i]=(*it)->deepCopy();
10802     }
10803   ret->deepCpyGlobs(*this);
10804   return ret.retn();
10805 }
10806
10807 MEDFileFields *MEDFileFields::shallowCpy() const
10808 {
10809   return new MEDFileFields(*this);
10810 }
10811
10812 /*!
10813  * 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
10814  * 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.
10815  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10816  *
10817  * \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.
10818  * \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.
10819  * 
10820  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10821  */
10822 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10823 {
10824   std::set< std::pair<int,int> > s;
10825   bool firstShot=true;
10826   areThereSomeForgottenTS=false;
10827   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10828     {
10829       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10830         continue;
10831       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10832       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10833       if(firstShot)
10834         { s=s1; firstShot=false; }
10835       else
10836         {
10837           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10838           if(s!=s2)
10839             areThereSomeForgottenTS=true;
10840           s=s2;
10841         }
10842     }
10843   std::vector< std::pair<int,int> > ret;
10844   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10845   return ret;
10846 }
10847
10848 int MEDFileFields::getNumberOfFields() const
10849 {
10850   return _fields.size();
10851 }
10852
10853 std::vector<std::string> MEDFileFields::getFieldsNames() const
10854 {
10855   std::vector<std::string> ret(_fields.size());
10856   int i(0);
10857   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10858     {
10859       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10860       if(f)
10861         {
10862           ret[i]=f->getName();
10863         }
10864       else
10865         {
10866           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10867           throw INTERP_KERNEL::Exception(oss.str());
10868         }
10869     }
10870   return ret;
10871 }
10872
10873 std::vector<std::string> MEDFileFields::getMeshesNames() const
10874 {
10875   std::vector<std::string> ret;
10876   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10877     {
10878       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10879       if(cur)
10880         ret.push_back(cur->getMeshName());
10881     }
10882   return ret;
10883 }
10884
10885 std::string MEDFileFields::simpleRepr() const
10886 {
10887   std::ostringstream oss;
10888   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10889   simpleRepr(0,oss);
10890   return oss.str();
10891 }
10892
10893 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10894 {
10895   int nbOfFields(getNumberOfFields());
10896   std::string startLine(bkOffset,' ');
10897   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10898   int i=0;
10899   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10900     {
10901       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10902       if(cur)
10903         {
10904           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10905         }
10906       else
10907         {
10908           oss << startLine << "  - not defined !" << std::endl;
10909         }
10910     }
10911   i=0;
10912   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10913     {
10914       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10915       std::string chapter(17,'0'+i);
10916       oss << startLine << chapter << std::endl;
10917       if(cur)
10918         {
10919           cur->simpleRepr(bkOffset+2,oss,i);
10920         }
10921       else
10922         {
10923           oss << startLine << "  - not defined !" << std::endl;
10924         }
10925       oss << startLine << chapter << std::endl;
10926     }
10927   simpleReprGlobs(oss);
10928 }
10929
10930 MEDFileFields::MEDFileFields()
10931 {
10932 }
10933
10934 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10935 try:MEDFileFieldGlobsReal(fid)
10936 {
10937   int nbFields(MEDnField(fid));
10938   _fields.resize(nbFields);
10939   med_field_type typcha;
10940   for(int i=0;i<nbFields;i++)
10941     {
10942       std::vector<std::string> infos;
10943       std::string fieldName,dtunit,meshName;
10944       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit,meshName));
10945       switch(typcha)
10946       {
10947         case MED_FLOAT64:
10948           {
10949             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10950             break;
10951           }
10952         case MED_INT32:
10953           {
10954             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10955             break;
10956           }
10957         default:
10958           {
10959             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] !";
10960             throw INTERP_KERNEL::Exception(oss.str());
10961           }
10962       }
10963     }
10964   loadAllGlobals(fid,entities);
10965 }
10966 catch(INTERP_KERNEL::Exception& e)
10967 {
10968     throw e;
10969 }
10970
10971 void MEDFileFields::writeLL(med_idt fid) const
10972 {
10973   int i=0;
10974   writeGlobals(fid,*this);
10975   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10976     {
10977       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10978       if(!elt)
10979         {
10980           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10981           throw INTERP_KERNEL::Exception(oss.str());
10982         }
10983       elt->writeLL(fid,*this);
10984     }
10985 }
10986
10987 /*!
10988  * This method alloc the arrays and load potentially huge arrays contained in this field.
10989  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10990  * This method can be also called to refresh or reinit values from a file.
10991  * 
10992  * \throw If the fileName is not set or points to a non readable MED file.
10993  */
10994 void MEDFileFields::loadArrays()
10995 {
10996   if(getFileName().empty())
10997     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10998   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10999   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11000     {
11001       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
11002       if(elt)
11003         elt->loadBigArraysRecursively(fid,*elt);
11004     }
11005 }
11006
11007 /*!
11008  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
11009  * But once data loaded once, this method does nothing.
11010  * 
11011  * \throw If the fileName is not set or points to a non readable MED file.
11012  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
11013  */
11014 void MEDFileFields::loadArraysIfNecessary()
11015 {
11016   if(!getFileName().empty())
11017     {
11018       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
11019       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11020         {
11021           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
11022           if(elt)
11023             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
11024         }
11025     }
11026 }
11027
11028 /*!
11029  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
11030  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
11031  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
11032  * 
11033  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
11034  */
11035 void MEDFileFields::unloadArrays()
11036 {
11037   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11038     {
11039       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
11040       if(elt)
11041         elt->unloadArrays();
11042     }
11043 }
11044
11045 /*!
11046  * 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.
11047  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
11048  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
11049  * 
11050  * \sa MEDFileFields::loadArraysIfNecessary
11051  */
11052 void MEDFileFields::unloadArraysWithoutDataLoss()
11053 {
11054   if(!getFileName().empty())
11055     unloadArrays();
11056 }
11057
11058 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
11059 {
11060   std::vector<std::string> ret;
11061   std::set<std::string> ret2;
11062   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11063     {
11064       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
11065       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
11066         if(ret2.find(*it2)==ret2.end())
11067           {
11068             ret.push_back(*it2);
11069             ret2.insert(*it2);
11070           }
11071     }
11072   return ret;
11073 }
11074
11075 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
11076 {
11077   std::vector<std::string> ret;
11078   std::set<std::string> ret2;
11079   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11080     {
11081       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
11082       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
11083         if(ret2.find(*it2)==ret2.end())
11084           {
11085             ret.push_back(*it2);
11086             ret2.insert(*it2);
11087           }
11088     }
11089   return ret;
11090 }
11091
11092 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
11093 {
11094   std::vector<std::string> ret;
11095   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11096     {
11097       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
11098       ret.insert(ret.end(),tmp.begin(),tmp.end());
11099     }
11100   return ret;
11101 }
11102
11103 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
11104 {
11105   std::vector<std::string> ret;
11106   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11107     {
11108       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
11109       ret.insert(ret.end(),tmp.begin(),tmp.end());
11110     }
11111   return ret;
11112 }
11113
11114 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
11115 {
11116   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
11117     (*it)->changePflsRefsNamesGen2(mapOfModif);
11118 }
11119
11120 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
11121 {
11122   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
11123     (*it)->changeLocsRefsNamesGen2(mapOfModif);
11124 }
11125
11126 void MEDFileFields::resize(int newSize)
11127 {
11128   _fields.resize(newSize);
11129 }
11130
11131 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
11132 {
11133   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
11134     pushField(*it);
11135 }
11136
11137 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
11138 {
11139   if(!field)
11140     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
11141   _fields.push_back(field->getContent());
11142   appendGlobs(*field,1e-12);
11143 }
11144
11145 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
11146 {
11147   if(!field)
11148     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
11149   if(i>=(int)_fields.size())
11150     _fields.resize(i+1);
11151   _fields[i]=field->getContent();
11152   appendGlobs(*field,1e-12);
11153 }
11154
11155 void MEDFileFields::destroyFieldAtPos(int i)
11156 {
11157   destroyFieldsAtPos(&i,&i+1);
11158 }
11159
11160 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
11161 {
11162   std::vector<bool> b(_fields.size(),true);
11163   for(const int *i=startIds;i!=endIds;i++)
11164     {
11165       if(*i<0 || *i>=(int)_fields.size())
11166         {
11167           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
11168           throw INTERP_KERNEL::Exception(oss.str());
11169         }
11170       b[*i]=false;
11171     }
11172   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
11173   std::size_t j=0;
11174   for(std::size_t i=0;i<_fields.size();i++)
11175     if(b[i])
11176       fields[j++]=_fields[i];
11177   _fields=fields;
11178 }
11179
11180 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
11181 {
11182   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
11183   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
11184   std::vector<bool> b(_fields.size(),true);
11185   int k=bg;
11186   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
11187     {
11188       if(k<0 || k>=(int)_fields.size())
11189         {
11190           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
11191           throw INTERP_KERNEL::Exception(oss.str());
11192         }
11193       b[k]=false;
11194     }
11195   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
11196   std::size_t j(0);
11197   for(std::size_t i=0;i<_fields.size();i++)
11198     if(b[i])
11199       fields[j++]=_fields[i];
11200   _fields=fields;
11201 }
11202
11203 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
11204 {
11205   bool ret(false);
11206   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11207     {
11208       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11209       if(cur)
11210         ret=cur->changeMeshNames(modifTab) || ret;
11211     }
11212   return ret;
11213 }
11214
11215 /*!
11216  * \param [in] meshName the name of the mesh that will be renumbered.
11217  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
11218  *             This code corresponds to the distribution of types in the corresponding mesh.
11219  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
11220  * \param [in] renumO2N the old to new renumber array.
11221  * \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 
11222  *         field in \a this.
11223  */
11224 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
11225 {
11226   bool ret(false);
11227   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11228     {
11229       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
11230       if(fmts)
11231         {
11232           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
11233         }
11234     }
11235   return ret;
11236 }
11237
11238 /*!
11239  * Return an extraction of \a this using \a extractDef map to specify the extraction.
11240  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
11241  *
11242  * \return A new object that the caller is responsible to deallocate.
11243  */
11244 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
11245 {
11246   if(!mm)
11247     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
11248   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
11249   int nbFields(getNumberOfFields());
11250   for(int i=0;i<nbFields;i++)
11251     {
11252       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
11253       if(!fmts)
11254         {
11255           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
11256           throw INTERP_KERNEL::Exception(oss.str());
11257         }
11258       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
11259       fsOut->pushField(fmtsOut);
11260     }
11261   return fsOut.retn();
11262 }
11263
11264 void MEDFileFields::accept(MEDFileFieldVisitor& visitor) const
11265 {
11266   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11267     if((*it).isNotNull())
11268       {
11269         visitor.newFieldEntry(*it);
11270         (*it)->accept(visitor);
11271         visitor.endFieldEntry(*it);
11272       }
11273 }
11274
11275 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
11276 {
11277   if(i<0 || i>=(int)_fields.size())
11278     {
11279       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
11280       throw INTERP_KERNEL::Exception(oss.str());
11281     }
11282   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
11283   if(!fmts)
11284     return 0;
11285   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
11286   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
11287   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
11288   if(fmtsC)
11289     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
11290   else if(fmtsC2)
11291     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
11292   else
11293     {
11294       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
11295       throw INTERP_KERNEL::Exception(oss.str());
11296     }
11297   ret->shallowCpyGlobs(*this);
11298   return ret.retn();
11299 }
11300
11301 /*!
11302  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
11303  * This method is accessible in python using __getitem__ with a list in input.
11304  * \return a new object that the caller should deal with.
11305  */
11306 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
11307 {
11308   MCAuto<MEDFileFields> ret=shallowCpy();
11309   std::size_t sz=std::distance(startIds,endIds);
11310   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
11311   int j=0;
11312   for(const int *i=startIds;i!=endIds;i++,j++)
11313     {
11314       if(*i<0 || *i>=(int)_fields.size())
11315         {
11316           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
11317           throw INTERP_KERNEL::Exception(oss.str());
11318         }
11319       fields[j]=_fields[*i];
11320     }
11321   ret->_fields=fields;
11322   return ret.retn();
11323 }
11324
11325 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
11326 {
11327   return getFieldAtPos(getPosFromFieldName(fieldName));
11328 }
11329
11330 /*!
11331  * This method removes, if any, fields in \a this having no time steps.
11332  * 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.
11333  * 
11334  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
11335  */
11336 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
11337 {
11338   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
11339   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11340     {
11341       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
11342       if(elt)
11343         {
11344           if(elt->getNumberOfTS()>0)
11345             newFields.push_back(*it);
11346         }
11347     }
11348   if(_fields.size()==newFields.size())
11349     return false;
11350   _fields=newFields;
11351   return true;
11352 }
11353
11354 /*!
11355  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
11356  * This method can be seen as a filter applied on \a this, that returns an object containing
11357  * 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
11358  * shallow copied from \a this.
11359  * 
11360  * \param [in] meshName - the name of the mesh on w
11361  * \return a new object that the caller should deal with.
11362  */
11363 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
11364 {
11365   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11366   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11367     {
11368       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11369       if(!cur)
11370         continue;
11371       if(cur->getMeshName()==meshName)
11372         {
11373           cur->incrRef();
11374           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
11375           ret->_fields.push_back(cur2);
11376         }
11377     }
11378   ret->shallowCpyOnlyUsedGlobs(*this);
11379   return ret.retn();
11380 }
11381
11382 /*!
11383  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
11384  * Input time steps are specified using a pair of integer (iteration, order).
11385  * 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,
11386  * but for each multitimestep only the time steps in \a timeSteps are kept.
11387  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
11388  * 
11389  * The returned object points to shallow copy of elements in \a this.
11390  * 
11391  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
11392  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
11393  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
11394  */
11395 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11396 {
11397   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11398   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11399     {
11400       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11401       if(!cur)
11402         continue;
11403       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
11404       ret->_fields.push_back(elt);
11405     }
11406   ret->shallowCpyOnlyUsedGlobs(*this);
11407   return ret.retn();
11408 }
11409
11410 /*!
11411  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
11412  */
11413 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11414 {
11415   MCAuto<MEDFileFields> ret=MEDFileFields::New();
11416   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11417     {
11418       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11419       if(!cur)
11420         continue;
11421       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
11422       if(elt->getNumberOfTS()!=0)
11423         ret->_fields.push_back(elt);
11424     }
11425   ret->shallowCpyOnlyUsedGlobs(*this);
11426   return ret.retn();
11427 }
11428
11429 bool MEDFileFields::presenceOfStructureElements() const
11430 {
11431   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11432     if((*it).isNotNull())
11433       if((*it)->presenceOfStructureElements())
11434         return true;
11435   return false;
11436 }
11437
11438 void MEDFileFields::killStructureElements()
11439 {
11440   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11441   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11442     if((*it).isNotNull())
11443       {
11444         if((*it)->presenceOfStructureElements())
11445           {
11446             if(!(*it)->onlyStructureElements())
11447               {
11448                 (*it)->killStructureElements();
11449                 ret.push_back(*it);
11450               }
11451           }
11452         else
11453           {
11454             ret.push_back(*it);
11455           }
11456       }
11457   _fields=ret;
11458 }
11459
11460 void MEDFileFields::keepOnlyStructureElements()
11461 {
11462   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11463   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11464     if((*it).isNotNull())
11465       {
11466         if((*it)->presenceOfStructureElements())
11467           {
11468             if(!(*it)->onlyStructureElements())
11469               (*it)->keepOnlyStructureElements();
11470             ret.push_back(*it);
11471           }
11472       }
11473   _fields=ret;
11474 }
11475
11476 void MEDFileFields::keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName)
11477 {
11478   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11479   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11480     if((*it).isNotNull())
11481       {
11482         if((*it)->getMeshName()!=meshName)
11483           continue;
11484         std::vector< std::pair<std::string,std::string> > ps;
11485         (*it)->getMeshSENames(ps);
11486         std::pair<std::string,std::string> p(meshName,seName);
11487         if(std::find(ps.begin(),ps.end(),p)!=ps.end())
11488           (*it)->keepOnlyOnSE(seName);
11489         ret.push_back(*it);
11490       }
11491   _fields=ret;
11492 }
11493
11494 void MEDFileFields::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
11495 {
11496   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11497     if((*it).isNotNull())
11498       (*it)->getMeshSENames(ps);
11499 }
11500
11501 void MEDFileFields::blowUpSE(MEDFileMeshes *ms, const MEDFileStructureElements *ses)
11502 {
11503   MEDFileBlowStrEltUp::DealWithSE(this,ms,ses);
11504 }
11505
11506 MCAuto<MEDFileFields> MEDFileFields::partOfThisOnStructureElements() const
11507 {
11508   MCAuto<MEDFileFields> ret(deepCopy());
11509   ret->keepOnlyStructureElements();
11510   return ret;
11511 }
11512
11513 MCAuto<MEDFileFields> MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const
11514 {
11515   MCAuto<MEDFileFields> ret(deepCopy());
11516   ret->keepOnlyOnMeshSE(meshName,seName);
11517   return ret;
11518 }
11519
11520 void MEDFileFields::aggregate(const MEDFileFields& other)
11521 {
11522   int nbFieldsToAdd(other.getNumberOfFields());
11523   std::vector<std::string> fsn(getFieldsNames());
11524   for(int i=0;i<nbFieldsToAdd;i++)
11525     {
11526       MCAuto<MEDFileAnyTypeFieldMultiTS> elt(other.getFieldAtPos(i));
11527       std::string name(elt->getName());
11528       if(std::find(fsn.begin(),fsn.end(),name)!=fsn.end())
11529         {
11530           std::ostringstream oss; oss << "MEDFileFields::aggregate : name \"" << name << "\" already appears !";
11531           throw INTERP_KERNEL::Exception(oss.str());
11532         }
11533       pushField(elt);
11534     }
11535 }
11536
11537 MEDFileFieldsIterator *MEDFileFields::iterator()
11538 {
11539   return new MEDFileFieldsIterator(this);
11540 }
11541
11542 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
11543 {
11544   std::string tmp(fieldName);
11545   std::vector<std::string> poss;
11546   for(std::size_t i=0;i<_fields.size();i++)
11547     {
11548       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
11549       if(f)
11550         {
11551           std::string fname(f->getName());
11552           if(tmp==fname)
11553             return i;
11554           else
11555             poss.push_back(fname);
11556         }
11557     }
11558   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
11559   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
11560   oss << " !";
11561   throw INTERP_KERNEL::Exception(oss.str());
11562 }
11563
11564 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
11565 {
11566   if(fs)
11567     {
11568       fs->incrRef();
11569       _nb_iter=fs->getNumberOfFields();
11570     }
11571 }
11572
11573 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
11574 {
11575 }
11576
11577 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
11578 {
11579   if(_iter_id<_nb_iter)
11580     {
11581       MEDFileFields *fs(_fs);
11582       if(fs)
11583         return fs->getFieldAtPos(_iter_id++);
11584       else
11585         return 0;
11586     }
11587   else
11588     return 0;
11589 }