]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileField.cxx
Salome HOME
14f49546bfff648de020d6d6a8676aa3119e5495
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2014  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.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25 #include "MEDFileFieldOverView.hxx"
26
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "MEDCouplingFieldDiscretization.hxx"
29
30 #include "InterpKernelAutoPtr.hxx"
31 #include "CellModel.hxx"
32
33 #include <algorithm>
34 #include <iterator>
35
36 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
37 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
38 extern med_geometry_type typmainoeud[1];
39 extern med_geometry_type typmai3[34];
40
41 using namespace ParaMEDMEM;
42
43 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
44 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
45
46 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
47 {
48   return new MEDFileFieldLoc(fid,locName);
49 }
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
52 {
53   return new MEDFileFieldLoc(fid,id);
54 }
55
56 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)
57 {
58   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
59 }
60
61 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
62 {
63   med_geometry_type geotype;
64   med_geometry_type sectiongeotype;
65   int nsectionmeshcell;
66   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
67   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
69   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
70   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
71   _nb_node_per_cell=cm.getNumberOfNodes();
72   _ref_coo.resize(_dim*_nb_node_per_cell);
73   _gs_coo.resize(_dim*_nb_gauss_pt);
74   _w.resize(_nb_gauss_pt);
75   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
76 }
77
78 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
79 {
80   med_geometry_type geotype;
81   med_geometry_type sectiongeotype;
82   int nsectionmeshcell;
83   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
84   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
87   _name=locName;
88   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
89   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
90   _nb_node_per_cell=cm.getNumberOfNodes();
91   _ref_coo.resize(_dim*_nb_node_per_cell);
92   _gs_coo.resize(_dim*_nb_gauss_pt);
93   _w.resize(_nb_gauss_pt);
94   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
95 }
96
97 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
98                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
99                                      _w(w)
100 {
101   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
102   _dim=cm.getDimension();
103   _nb_node_per_cell=cm.getNumberOfNodes();
104   _nb_gauss_pt=_w.size();
105 }
106
107 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
108 {
109   return new MEDFileFieldLoc(*this);
110 }
111
112 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
113 {
114   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
115 }
116
117 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
118 {
119   return std::vector<const BigMemoryObject *>();
120 }
121
122 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
123 {
124   static const char OFF7[]="\n    ";
125   oss << "\"" << _name << "\"" << OFF7;
126   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
127   oss << "Dimension=" << _dim << OFF7;
128   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
129   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
130   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
131   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
132   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
133 }
134
135 void MEDFileFieldLoc::setName(const std::string& name)
136 {
137   _name=name;
138 }
139
140 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
141 {
142   if(_name!=other._name)
143     return false;
144   if(_dim!=other._dim)
145     return false;
146   if(_nb_gauss_pt!=other._nb_gauss_pt)
147     return false;
148   if(_nb_node_per_cell!=other._nb_node_per_cell)
149     return false;
150   if(_geo_type!=other._geo_type)
151     return false;
152   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
153     return false;
154   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
155     return false;
156   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
157     return false;
158
159   return true;
160 }
161
162 void MEDFileFieldLoc::writeLL(med_idt fid) const
163 {
164   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
165 }
166
167 std::string MEDFileFieldLoc::repr() const
168 {
169   std::ostringstream oss; oss.precision(15);
170   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
171   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
172   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
173   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
174   oss << "\n  - Ref coords are : ";
175   int sz=_ref_coo.size();
176   if(sz%_dim==0)
177     {
178       int nbOfTuples=sz/_dim;
179       for(int i=0;i<nbOfTuples;i++)
180         {
181           oss << "(";
182           for(int j=0;j<_dim;j++)
183             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
184           oss << ") ";
185         }
186     }
187   else
188     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
189   oss << "\n  - Gauss coords in reference element : ";
190   sz=_gs_coo.size();
191   if(sz%_dim==0)
192     {
193       int nbOfTuples=sz/_dim;
194       for(int i=0;i<nbOfTuples;i++)
195         {
196           oss << "(";
197           for(int j=0;j<_dim;j++)
198             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
199           oss << ") ";
200         }
201     }
202   else
203     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
204   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
205   return oss.str();
206 }
207
208 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
209 {
210   _type=field->getTypeOfField();
211   _start=start;
212   switch(_type)
213   {
214     case ON_CELLS:
215       {
216         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,offset,offset+nbOfCells,1);
217         _end=_start+nbOfCells;
218         _nval=nbOfCells;
219         break;
220       }
221     case ON_GAUSS_NE:
222       {
223         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
224         const int *arrPtr=arr->getConstPointer();
225         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
226         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
227         _nval=nbOfCells;
228         break;
229       }
230     case ON_GAUSS_PT:
231       {
232         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
233         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
234         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
235         if(!disc2)
236           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
237         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
238         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
239         const int *dai2Ptr=dai2->getConstPointer();
240         int nbi=gsLoc.getWeights().size();
241         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
242         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
243         const int *da3Ptr=da3->getConstPointer();
244         if(da3->getNumberOfTuples()!=nbOfCells)
245           {//profile : for gauss even in NoProfile !!!
246             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
247             _profile=oss.str();
248             da3->setName(_profile.c_str());
249             glob.appendProfile(da3);
250           }
251         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
252         _nval=da3->getNbOfElems();
253         da4->alloc(_nval*nbi,1);
254         int *da4Ptr=da4->getPointer();
255         for(int i=0;i<_nval;i++)
256           {
257             int ref=dai2Ptr[offset+da3Ptr[i]];
258             for(int j=0;j<nbi;j++)
259               *da4Ptr++=ref+j;
260           }
261         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
262         _localization=oss2.str();
263         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
264         _end=_start+_nval*nbi;
265         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
266         break;
267       }
268     default:
269       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
270   }
271   start=_end;
272 }
273
274 /*!
275  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
276  * \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).
277  * \param [in] multiTypePfl is the end user profile specified in high level API
278  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
279  * \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.
280  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
281  * \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.
282  */
283 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)
284 {
285   _profile.clear();
286   _type=field->getTypeOfField();
287   std::string pflName(multiTypePfl->getName());
288   std::ostringstream oss; oss << pflName;
289   if(_type!=ON_NODES)
290     {
291       if(!isPflAlone)
292         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
293     }
294   else
295     { oss << "_NODE"; }
296   if(locIds)
297     {
298       if(pflName.empty())
299         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
300       if(_type!=ON_GAUSS_PT)
301         {
302           locIds->setName(oss.str().c_str());
303           glob.appendProfile(locIds);
304           _profile=oss.str();
305         }
306     }
307   _start=start;
308   switch(_type)
309   {
310     case ON_NODES:
311       {
312         _nval=idsInPfl->getNumberOfTuples();
313         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
314         _end=_start+_nval;
315         break;
316       }
317     case ON_CELLS:
318       {
319         _nval=idsInPfl->getNumberOfTuples();
320         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
321         _end=_start+_nval;
322         break;
323       }
324     case ON_GAUSS_NE:
325       {
326         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
327         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
328         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
329         arr3->computeOffsets2();
330         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
331         int trueNval=tmp->getNumberOfTuples();
332         _nval=idsInPfl->getNumberOfTuples();
333         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
334         _end=_start+trueNval;
335         break;
336       }
337     case ON_GAUSS_PT:
338       {
339         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
340         if(!disc2)
341           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
342         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
343         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
344         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
345         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
346         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
347         //
348         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
349         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
350         //
351         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
352         int trueNval=0;
353         for(const int *pt=da4->begin();pt!=da4->end();pt++)
354           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
355         tmp->alloc(trueNval,1);
356         int *tmpPtr=tmp->getPointer();
357         for(const int *pt=da4->begin();pt!=da4->end();pt++)
358           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
359             *tmpPtr++=j;
360         //
361         _nval=da4->getNumberOfTuples();
362         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
363         _end=_start+trueNval;
364         oss << "_loc_" << _loc_id;
365         if(locIds)
366           {
367             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
368             da5->setName(oss.str().c_str());
369             glob.appendProfile(da5);
370             _profile=oss.str();
371           }
372         else
373           {
374             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
375               {
376                 da3->setName(oss.str().c_str());
377                 glob.appendProfile(da3);
378                 _profile=oss.str();
379               }
380           }
381         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
382         _localization=oss2.str();
383         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
384         break;
385       }
386     default:
387       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
388   }
389   start=_end;
390 }
391
392 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
393 {
394   _start=start;
395   _nval=arrr->getNumberOfTuples();
396   getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,_nval,1);
397   _end=_start+_nval;
398   start=_end;
399 }
400
401 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
402 {
403   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
404 }
405
406 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
407 {
408   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
409 }
410
411 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
412 {
413   return new MEDFileFieldPerMeshPerTypePerDisc(other);
414 }
415
416 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
417 {
418   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
419 }
420
421 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
422 {
423   std::vector<const BigMemoryObject *> ret(1);
424   ret[0]=(const PartDefinition*)_pd;
425   return ret;
426 }
427
428 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const
429 {
430   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
431   ret->_father=father;
432   return ret.retn();
433 }
434
435 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
436 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
437 {
438   if(pd)
439     pd->incrRef();
440 }
441 catch(INTERP_KERNEL::Exception& e)
442 {
443     throw e;
444 }
445
446 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
447 {
448 }
449
450 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)
451 {
452 }
453
454 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
455     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
456 {
457 }
458
459 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)
460 {
461   const PartDefinition *pd(_pd);
462   if(!pd)
463     {
464       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
465       int nbi,tmp1;
466       med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
467       if(_end-_start!=nbValsInFile*nbi)
468         {
469           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 !";
470           throw INTERP_KERNEL::Exception(oss.str().c_str());
471         }
472       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr);
473     }
474   else
475     {
476       if(!_profile.empty())
477         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
478       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
479       if(spd)
480         {
481           int profilesize,nbi,start,stop,step;
482           spd->getSlice(start,stop,step);
483           INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
484           int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
485           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
486           med_filter filter=MED_FILTER_INIT;
487           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
488                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
489                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
490                                    /*lastblocksize=useless because count=1*/0,&filter);
491           MEDfieldValueAdvancedRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr);
492           MEDfilterClose(&filter);
493           return ;
494         }
495       else
496         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
497     }
498 }
499
500 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
501 {
502   return _father;
503 }
504
505 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
506 {
507   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
508   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
509   std::string fieldName(nasc.getName()),meshName(getMeshName());
510   int iteration(getIteration()),order(getOrder());
511   TypeOfField type(getType());
512   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
513   int profilesize,nbi;
514   med_geometry_type mgeoti;
515   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
516   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
517   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
518   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
519   const PartDefinition *pd(_pd);
520   if(!pd)
521     {
522       _nval=zeNVal;
523     }
524   else
525     {
526       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
527       if(!spd)
528         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : Part def only implemented for split one !");
529       if(!_profile.empty())
530         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
531       int start1,stop1,step1;
532       spd->getSlice(start1,stop1,step1);
533       _nval=DataArray::GetNumberOfItemGivenBES(start1,stop1,step1,"MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively");
534     }
535   _start=start;
536   _end=start+_nval*nbi;
537   start=_end;
538   if(type==ON_CELLS && !_localization.empty())
539     {
540       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
541         setType(ON_GAUSS_PT);
542       else
543         {
544           setType(ON_GAUSS_NE);
545           _localization.clear();
546         }
547     }
548 }
549
550 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
551 {
552   std::string fieldName(nasc.getName()),meshName(getMeshName());
553   int iteration(getIteration()),order(getOrder());
554   TypeOfField type(getType());
555   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
556   med_geometry_type mgeoti;
557   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
558   if(_start>_end)
559     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
560   if(_start==_end)
561     return ;
562   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
563   if(_start<0 || _start>=arr->getNumberOfTuples())
564     {
565       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
566       throw INTERP_KERNEL::Exception(oss.str().c_str());
567     }
568   if(_end<0 || _end>arr->getNumberOfTuples())
569     {
570       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
571       throw INTERP_KERNEL::Exception(oss.str().c_str());
572     }
573   int nbOfCompo(arr->getNumberOfComponents());
574   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
575   if(arrD)
576     {
577       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
578       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
579       return ;
580     }
581   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
582   if(arrI)
583     {
584       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
585       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
586       return ;
587     }
588   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
589 }
590
591 /*!
592  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
593  */
594 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
595 {
596   int delta=_end-_start;
597   _start=newValueOfStart;
598   _end=_start+delta;
599 }
600
601 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
602 {
603   return _father->getIteration();
604 }
605
606 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
607 {
608   return _father->getOrder();
609 }
610
611 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
612 {
613   return _father->getTime();
614 }
615
616 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
617 {
618   return _father->getMeshName();
619 }
620
621 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
622 {
623   const char startLine[]="    ## ";
624   std::string startLine2(bkOffset,' ');
625   startLine2+=startLine;
626   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
627   oss << startLine2 << "Localization #" << id << "." << std::endl;
628   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
629   delete tmp;
630   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
631   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
632   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
633 }
634
635 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
636 {
637   return _type;
638 }
639
640 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
641 {
642   types.insert(_type);
643 }
644
645 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
646 {
647   _type=newType;
648 }
649
650 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
651 {
652   return _father->getGeoType();
653 }
654
655 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
656 {
657   return _father->getNumberOfComponents();
658 }
659
660 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
661 {
662   return _end-_start;
663 }
664
665 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
666 {
667   return _father->getOrCreateAndGetArray();
668 }
669
670 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
671 {
672   const MEDFileFieldPerMeshPerType *fath=_father;
673   return fath->getOrCreateAndGetArray();
674 }
675
676 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
677 {
678   return _father->getInfo();
679 }
680
681 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
682 {
683   return _profile;
684 }
685
686 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
687 {
688   _profile=newPflName;
689 }
690
691 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
692 {
693   return _localization;
694 }
695
696 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
697 {
698   _localization=newLocName;
699 }
700
701 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
702 {
703   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
704     {
705       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
706         {
707           _profile=(*it2).second;
708           return;
709         }
710     }
711 }
712
713 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
714 {
715   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
716     {
717       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
718         {
719           _localization=(*it2).second;
720           return;
721         }
722     }
723 }
724
725 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
726 {
727   if(type!=_type)
728     return ;
729   dads.push_back(std::pair<int,int>(_start,_end));
730   geoTypes.push_back(getGeoType());
731   if(_profile.empty())
732     pfls.push_back(0);
733   else
734     {
735       pfls.push_back(glob->getProfile(_profile.c_str()));
736     }
737   if(_localization.empty())
738     locs.push_back(-1);
739   else
740     {
741       locs.push_back(glob->getLocalizationId(_localization.c_str()));
742     }
743 }
744
745 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
746 {
747   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));
748   startEntryId++;
749 }
750
751 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
752 {
753   TypeOfField type=getType();
754   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
755   med_geometry_type mgeoti;
756   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
757   const DataArray *arr=getOrCreateAndGetArray();
758   if(!arr)
759     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
760   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
761   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
762   const unsigned char *locToWrite=0;
763   if(arrD)
764     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
765   else if(arrI)
766     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
767   else
768     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
769   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
770                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
771                              locToWrite);
772 }
773
774 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
775 {
776   type=_type;
777   pfl=_profile;
778   loc=_localization;
779   dad.first=_start; dad.second=_end;
780 }
781
782 /*!
783  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
784  *             This code corresponds to the distribution of types in the corresponding mesh.
785  * \param [out] ptToFill memory zone where the output will be stored.
786  * \return the size of data pushed into output param \a ptToFill
787  */
788 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
789 {
790   _loc_id=offset;
791   std::ostringstream oss;
792   std::size_t nbOfType=codeOfMesh.size()/3;
793   int found=-1;
794   for(std::size_t i=0;i<nbOfType && found==-1;i++)
795     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
796       found=(int)i;
797   if(found==-1)
798     {
799       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
800       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
801       throw INTERP_KERNEL::Exception(oss.str().c_str());
802     }
803   int *work=ptToFill;
804   if(_profile.empty())
805     {
806       if(_nval!=codeOfMesh[3*found+1])
807         {
808           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
809           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
810           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
811           throw INTERP_KERNEL::Exception(oss.str().c_str());
812         }
813       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
814         *work++=ii;
815     }
816   else
817     {
818       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
819       if(pfl->getNumberOfTuples()!=_nval)
820         {
821           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
822           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
823           oss << _nval;
824           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
825           throw INTERP_KERNEL::Exception(oss.str().c_str());
826         }
827       int offset2=codeOfMesh[3*found+2];
828       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
829         {
830           if(*pflId<codeOfMesh[3*found+1])
831             *work++=offset2+*pflId;
832         }
833     }
834   return _nval;
835 }
836
837 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
838 {
839   for(int i=_start;i<_end;i++)
840     *ptToFill++=i;
841   return _end-_start;
842 }
843
844 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
845 {
846   switch(type)
847   {
848     case ON_CELLS:
849       return -2;
850     case ON_GAUSS_NE:
851       return -1;
852     case ON_GAUSS_PT:
853       return locId;
854     default:
855       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
856   }
857 }
858
859 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
860 {
861   int id=0;
862   std::map<std::pair<std::string,TypeOfField>,int> m;
863   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
864   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
865     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
866       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
867   ret.resize(id);
868   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
869     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
870   return ret;
871 }
872
873 /*!
874  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
875  * 
876  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
877  * \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.
878  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
879  * \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)
880  * \param [in,out] glob if necessary by the method, new profiles can be added to it
881  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
882  * \param [out] result All new entries will be appended on it.
883  * \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 !)
884  */
885 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
886                                                        const DataArrayInt *explicitIdsInMesh,
887                                                        const std::vector<int>& newCode,
888                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
889                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
890 {
891   if(entriesOnSameDisc.empty())
892     return false;
893   TypeOfField type=entriesOnSameDisc[0]->getType();
894   int szEntities=0,szTuples=0;
895   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
896     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
897   int nbi=szTuples/szEntities;
898   if(szTuples%szEntities!=0)
899     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
900   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
901   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
902   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
903   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
904   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
905   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
906   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
907   int id=0;
908   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
909     {
910       int startOfEltIdOfChunk=(*it)->_start;
911       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
912       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
913       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
914       //
915       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
916       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
917       //
918       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
919       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
920     }
921   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
922   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
923   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
924   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
925   //
926   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
927   //
928   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
929   arrPart->renumberInPlace(renumTupleIds->begin());
930   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
931   bool ret=false;
932   const int *idIt=diffVals->begin();
933   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
934   int offset2=0;
935   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
936     {
937       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
938       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
939       int nbEntityElts=subIds->getNumberOfTuples();
940       bool ret2;
941       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
942           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
943                                       offset+offset2,
944                                       li,glob,ret2);
945       ret=ret || ret2;
946       result.push_back(eltToAdd);
947       offset2+=nbEntityElts*nbi;
948     }
949   ret=ret || li.empty();
950   return ret;
951 }
952
953 /*!
954  * \param [in] typeF type of field of new chunk
955  * \param [in] geoType the geometric type of the chunk
956  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
957  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
958  * \param [in] nbi number of integration points
959  * \param [in] offset The offset in the **global array of data**.
960  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
961  *                 to the new chunk to create.
962  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
963  * \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
964  *              and corresponding entry erased from \a entriesOnSameDisc.
965  * \return a newly allocated chunk
966  */
967 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
968                                                                                                   bool isPfl, int nbi, int offset,
969                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
970                                                                                                   MEDFileFieldGlobsReal& glob,
971                                                                                                   bool &notInExisting)
972 {
973   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
974   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
975   for(;it!=entriesOnSameDisc.end();it++)
976     {
977       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
978         {
979           if(!isPfl)
980             {
981               if((*it)->_profile.empty())
982                 break;
983               else
984                 if(!(*it)->_profile.empty())
985                   {
986                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
987                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
988                       break;
989                   }
990             }
991         }
992     }
993   if(it==entriesOnSameDisc.end())
994     {
995       notInExisting=true;
996       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
997       ret->_type=typeF;
998       ret->_loc_id=(int)geoType;
999       ret->_nval=nbMeshEntities;
1000       ret->_start=offset;
1001       ret->_end=ret->_start+ret->_nval*nbi;
1002       if(isPfl)
1003         {
1004           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1005           glob.appendProfile(idsOfMeshElt);
1006           ret->_profile=idsOfMeshElt->getName();
1007         }
1008       //tony treatment of localization
1009       return ret;
1010     }
1011   else
1012     {
1013       notInExisting=false;
1014       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1015       ret->_loc_id=(int)geoType;
1016       ret->setNewStart(offset);
1017       entriesOnSameDisc.erase(it);
1018       return ret;
1019     }
1020
1021 }
1022
1023 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1024 {
1025   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1026 }
1027
1028 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1029 {
1030   return new MEDFileFieldPerMeshPerType(fath,geoType);
1031 }
1032
1033 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1034 {
1035   return _field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
1036 }
1037
1038 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1039 {
1040   std::vector<const BigMemoryObject *> ret;
1041   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1042     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1043   return ret;
1044 }
1045
1046 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const
1047 {
1048   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1049   ret->_father=father;
1050   std::size_t i=0;
1051   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1052     {
1053       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1054         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
1055     }
1056   return ret.retn();
1057 }
1058
1059 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1060 {
1061   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1062   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1063     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1064 }
1065
1066 /*!
1067  * This method is the most general one. No optimization is done here.
1068  * \param [in] multiTypePfl is the end user profile specified in high level API
1069  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1070  * \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.
1071  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1072  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1073  * \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.
1074  */
1075 void MEDFileFieldPerMeshPerType::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)
1076 {
1077   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1078   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1079     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1080 }
1081
1082 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1083 {
1084   _field_pm_pt_pd.resize(1);
1085   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1086   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1087 }
1088
1089 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1090 {
1091   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1092   if(!arr || !arr->isAllocated())
1093     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1094   _field_pm_pt_pd.resize(1);
1095   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1096   _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.
1097 }
1098
1099 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1100 {
1101   TypeOfField type=field->getTypeOfField();
1102   if(type!=ON_GAUSS_PT)
1103     {
1104       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1105       int sz=_field_pm_pt_pd.size();
1106       bool found=false;
1107       for(int j=0;j<sz && !found;j++)
1108         {
1109           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1110             {
1111               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1112               found=true;
1113             }
1114         }
1115       if(!found)
1116         {
1117           _field_pm_pt_pd.resize(sz+1);
1118           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1119         }
1120       std::vector<int> ret(1,(int)sz);
1121       return ret;
1122     }
1123   else
1124     {
1125       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1126       int sz2=ret2.size();
1127       std::vector<int> ret3(sz2);
1128       int k=0;
1129       for(int i=0;i<sz2;i++)
1130         {
1131           int sz=_field_pm_pt_pd.size();
1132           int locIdToFind=ret2[i];
1133           bool found=false;
1134           for(int j=0;j<sz && !found;j++)
1135             {
1136               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1137                 {
1138                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1139                   ret3[k++]=j;
1140                   found=true;
1141                 }
1142             }
1143           if(!found)
1144             {
1145               _field_pm_pt_pd.resize(sz+1);
1146               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1147               ret3[k++]=sz;
1148             }
1149         }
1150       return ret3;
1151     }
1152 }
1153
1154 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1155 {
1156   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1157   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1158   if(!disc2)
1159     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1160   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1161   if(!da)
1162     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1163   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1164   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1165   if(retTmp->presenceOfValue(-1))
1166     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1167   std::vector<int> ret(retTmp->begin(),retTmp->end());
1168   return ret;
1169 }
1170
1171 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1172 {
1173   TypeOfField type=field->getTypeOfField();
1174   if(type!=ON_GAUSS_PT)
1175     {
1176       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1177       int sz=_field_pm_pt_pd.size();
1178       bool found=false;
1179       for(int j=0;j<sz && !found;j++)
1180         {
1181           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1182             {
1183               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1184               found=true;
1185             }
1186         }
1187       if(!found)
1188         {
1189           _field_pm_pt_pd.resize(sz+1);
1190           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1191         }
1192       std::vector<int> ret(1,0);
1193       return ret;
1194     }
1195   else
1196     {
1197       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1198       int sz2=ret2.size();
1199       std::vector<int> ret3(sz2);
1200       int k=0;
1201       for(int i=0;i<sz2;i++)
1202         {
1203           int sz=_field_pm_pt_pd.size();
1204           int locIdToFind=ret2[i];
1205           bool found=false;
1206           for(int j=0;j<sz && !found;j++)
1207             {
1208               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1209                 {
1210                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1211                   ret3[k++]=j;
1212                   found=true;
1213                 }
1214             }
1215           if(!found)
1216             {
1217               _field_pm_pt_pd.resize(sz+1);
1218               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1219               ret3[k++]=sz;
1220             }
1221         }
1222       return ret3;
1223     }
1224 }
1225
1226 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1227 {
1228   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1229   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1230   if(!disc2)
1231     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1232   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1233   if(!da)
1234     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1235   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1236   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1237   if(retTmp->presenceOfValue(-1))
1238     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1239   std::vector<int> ret(retTmp->begin(),retTmp->end());
1240   return ret;
1241 }
1242
1243 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1244 {
1245   return _father;
1246 }
1247
1248 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1249 {
1250   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1251   int curDim=(int)cm.getDimension();
1252   dim=std::max(dim,curDim);
1253 }
1254
1255 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1256 {
1257   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1258     {
1259       (*it)->fillTypesOfFieldAvailable(types);
1260     }
1261 }
1262
1263 void MEDFileFieldPerMeshPerType::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1264 {
1265   int sz=_field_pm_pt_pd.size();
1266   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1267   for(int i=0;i<sz;i++)
1268     {
1269       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1270     }
1271 }
1272
1273 int MEDFileFieldPerMeshPerType::getIteration() const
1274 {
1275   return _father->getIteration();
1276 }
1277
1278 int MEDFileFieldPerMeshPerType::getOrder() const
1279 {
1280   return _father->getOrder();
1281 }
1282
1283 double MEDFileFieldPerMeshPerType::getTime() const
1284 {
1285   return _father->getTime();
1286 }
1287
1288 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1289 {
1290   return _father->getMeshName();
1291 }
1292
1293 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1294 {
1295   const char startLine[]="  ## ";
1296   std::string startLine2(bkOffset,' ');
1297   std::string startLine3(startLine2);
1298   startLine3+=startLine;
1299   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1300     {
1301       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1302       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1303     }
1304   else
1305     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1306   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1307   int i=0;
1308   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1309     {
1310       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1311       if(cur)
1312         cur->simpleRepr(bkOffset,oss,i);
1313       else
1314         {
1315           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1316         }
1317     }
1318 }
1319
1320 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1321 {
1322   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1323     {
1324       globalSz+=(*it)->getNumberOfTuples();
1325     }
1326   nbOfEntries+=(int)_field_pm_pt_pd.size();
1327 }
1328
1329 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1330 {
1331   return _geo_type;
1332 }
1333
1334
1335 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1336 {
1337   return _father->getNumberOfComponents();
1338 }
1339
1340 bool MEDFileFieldPerMeshPerType::presenceOfMultiDiscPerGeoType() const
1341 {
1342   std::size_t nb(0);
1343   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1344     {
1345       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1346       if(fmtd)
1347         nb++;
1348     }
1349   return nb>1;
1350 }
1351
1352 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1353 {
1354   return _father->getOrCreateAndGetArray();
1355 }
1356
1357 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1358 {
1359   const MEDFileFieldPerMesh *fath=_father;
1360   return fath->getOrCreateAndGetArray();
1361 }
1362
1363 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1364 {
1365   return _father->getInfo();
1366 }
1367
1368 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1369 {
1370   std::vector<std::string> ret;
1371   std::set<std::string> ret2;
1372   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1373     {
1374       std::string tmp=(*it1)->getProfile();
1375       if(!tmp.empty())
1376         if(ret2.find(tmp)==ret2.end())
1377           {
1378             ret.push_back(tmp);
1379             ret2.insert(tmp);
1380           }
1381     }
1382   return ret;
1383 }
1384
1385 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1386 {
1387   std::vector<std::string> ret;
1388   std::set<std::string> ret2;
1389   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1390     {
1391       std::string tmp=(*it1)->getLocalization();
1392       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1393         if(ret2.find(tmp)==ret2.end())
1394           {
1395             ret.push_back(tmp);
1396             ret2.insert(tmp);
1397           }
1398     }
1399   return ret;
1400 }
1401
1402 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1403 {
1404   std::vector<std::string> ret;
1405   std::set<std::string> ret2;
1406   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1407     {
1408       std::string tmp=(*it1)->getProfile();
1409       if(!tmp.empty())
1410         ret.push_back(tmp);
1411     }
1412   return ret;
1413 }
1414
1415 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1416 {
1417   std::vector<std::string> ret;
1418   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1419     {
1420       std::string tmp=(*it1)->getLocalization();
1421       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1422         ret.push_back(tmp);
1423     }
1424   return ret;
1425 }
1426
1427 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1428 {
1429   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1430     (*it1)->changePflsRefsNamesGen(mapOfModif);
1431 }
1432
1433 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1434 {
1435   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1436     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1437 }
1438
1439 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1440 {
1441   if(_field_pm_pt_pd.empty())
1442     {
1443       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1444       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1445       throw INTERP_KERNEL::Exception(oss.str().c_str());
1446     }
1447   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1448     return _field_pm_pt_pd[locId];
1449   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1450   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1451   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1452   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1453   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1454 }
1455
1456 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1457 {
1458   if(_field_pm_pt_pd.empty())
1459     {
1460       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1461       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1462       throw INTERP_KERNEL::Exception(oss.str().c_str());
1463     }
1464   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1465     return _field_pm_pt_pd[locId];
1466   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1467   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1468   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1469   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1470   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1471 }
1472
1473 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
1474 {
1475   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1476     {
1477       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1478       if(meshDim!=(int)cm.getDimension())
1479         return ;
1480     }
1481   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1482     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1483 }
1484
1485 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1486 {
1487   int i=0;
1488   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1489     {
1490       (*it)->fillValues(i,startEntryId,entries);
1491     }
1492 }
1493
1494 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1495 {
1496   _field_pm_pt_pd=leaves;
1497   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1498     (*it)->setFather(this);
1499 }
1500
1501 /*!
1502  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1503  *  \param [out] its - list of pair (start,stop) kept
1504  *  \return bool - false if the type of field \a tof is not contained in \a this.
1505  */
1506 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1507 {
1508   bool ret=false;
1509   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1510   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1511     if((*it)->getType()==tof)
1512       {
1513         newPmPtPd.push_back(*it);
1514         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1515         (*it)->setNewStart(globalNum);
1516         globalNum=(*it)->getEnd();
1517         its.push_back(bgEnd);
1518         ret=true;
1519       }
1520   if(ret)
1521     _field_pm_pt_pd=newPmPtPd;
1522   return ret;
1523 }
1524
1525 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1526 {
1527 }
1528
1529 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1530 {
1531   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1532   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1533   med_geometry_type mgeoti;
1534   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1535   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1536   _field_pm_pt_pd.resize(nbProfiles);
1537   for(int i=0;i<nbProfiles;i++)
1538     {
1539       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1540     }
1541   if(type==ON_CELLS)
1542     {
1543       int nbProfiles2=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName);
1544       for(int i=0;i<nbProfiles2;i++)
1545         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1546     }
1547 }
1548
1549 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1550 {
1551   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1552     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1553 }
1554
1555 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1556 {
1557   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1558     (*it)->loadBigArray(fid,nasc);
1559 }
1560
1561 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1562 {
1563   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1564     {
1565       (*it)->copyOptionsFrom(*this);
1566       (*it)->writeLL(fid,nasc);
1567     }
1568 }
1569
1570 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1571 {
1572   switch(ikType)
1573   {
1574     case ON_CELLS:
1575       medfGeoType=typmai3[(int)ikGeoType];
1576       return MED_CELL;
1577     case ON_NODES:
1578       medfGeoType=MED_NONE;
1579       return MED_NODE;
1580     case ON_GAUSS_NE:
1581       medfGeoType=typmai3[(int)ikGeoType];
1582       return MED_NODE_ELEMENT;
1583     case ON_GAUSS_PT:
1584       medfGeoType=typmai3[(int)ikGeoType];
1585       return MED_CELL;
1586     default:
1587       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1588   }
1589   return MED_UNDEF_ENTITY_TYPE;
1590 }
1591
1592 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm)
1593 {
1594   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm);
1595 }
1596
1597 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1598 {
1599   return new MEDFileFieldPerMesh(fath,mesh);
1600 }
1601
1602 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1603 {
1604   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1605 }
1606
1607 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1608 {
1609   std::vector<const BigMemoryObject *> ret;
1610   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1611     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1612   return ret;
1613 }
1614
1615 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1616 {
1617   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1618   ret->_father=father;
1619   std::size_t i=0;
1620   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1621     {
1622       if((const MEDFileFieldPerMeshPerType *)*it)
1623         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1624     }
1625   return ret.retn();
1626 }
1627
1628 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1629 {
1630   std::string startLine(bkOffset,' ');
1631   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1632   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1633   int i=0;
1634   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1635     {
1636       const MEDFileFieldPerMeshPerType *cur=*it;
1637       if(cur)
1638         cur->simpleRepr(bkOffset,oss,i);
1639       else
1640         {
1641           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1642         }
1643     }
1644 }
1645
1646 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1647 {
1648   _mesh_name=mesh->getName();
1649   mesh->getTime(_mesh_iteration,_mesh_order);
1650 }
1651
1652 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1653 {
1654   int nbOfTypes=code.size()/3;
1655   int offset=0;
1656   for(int i=0;i<nbOfTypes;i++)
1657     {
1658       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1659       int nbOfCells=code[3*i+1];
1660       int pos=addNewEntryIfNecessary(type);
1661       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1662       offset+=nbOfCells;
1663     }
1664 }
1665
1666 /*!
1667  * This method is the most general one. No optimization is done here.
1668  * \param [in] multiTypePfl is the end user profile specified in high level API
1669  * \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].
1670  * \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.
1671  * \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.
1672  * \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.
1673  * \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.
1674  */
1675 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)
1676 {
1677   int nbOfTypes(code.size()/3);
1678   for(int i=0;i<nbOfTypes;i++)
1679     {
1680       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1681       int pos=addNewEntryIfNecessary(type);
1682       DataArrayInt *pfl=0;
1683       if(code[3*i+2]!=-1)
1684         pfl=idsPerType[code[3*i+2]];
1685       int nbOfTupes2=code2.size()/3;
1686       int found=0;
1687       for(;found<nbOfTupes2;found++)
1688         if(code[3*i]==code2[3*found])
1689           break;
1690       if(found==nbOfTupes2)
1691         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1692       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1693     }
1694 }
1695
1696 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1697 {
1698   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1699   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1700 }
1701
1702 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1703 {
1704   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1705   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1706 }
1707
1708 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1709 {
1710   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1711     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1712 }
1713
1714 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1715 {
1716   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1717     (*it)->loadBigArraysRecursively(fid,nasc);
1718 }
1719
1720 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1721 {
1722   int nbOfTypes=_field_pm_pt.size();
1723   for(int i=0;i<nbOfTypes;i++)
1724     {
1725       _field_pm_pt[i]->copyOptionsFrom(*this);
1726       _field_pm_pt[i]->writeLL(fid,nasc);
1727     }
1728 }
1729
1730 void MEDFileFieldPerMesh::getDimension(int& dim) const
1731 {
1732   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1733     (*it)->getDimension(dim);
1734 }
1735
1736 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1737 {
1738   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1739     (*it)->fillTypesOfFieldAvailable(types);
1740 }
1741
1742 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
1743 {
1744   int sz=_field_pm_pt.size();
1745   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1746   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1747   for(int i=0;i<sz;i++)
1748     {
1749       types[i]=_field_pm_pt[i]->getGeoType();
1750       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1751     }
1752   return ret;
1753 }
1754
1755 double MEDFileFieldPerMesh::getTime() const
1756 {
1757   int tmp1,tmp2;
1758   return _father->getTime(tmp1,tmp2);
1759 }
1760
1761 int MEDFileFieldPerMesh::getIteration() const
1762 {
1763   return _father->getIteration();
1764 }
1765
1766 int MEDFileFieldPerMesh::getOrder() const
1767 {
1768   return _father->getOrder();
1769 }
1770
1771 int MEDFileFieldPerMesh::getNumberOfComponents() const
1772 {
1773   return _father->getNumberOfComponents();
1774 }
1775
1776 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1777 {
1778   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1779     {
1780       const MEDFileFieldPerMeshPerType *fpmt(*it);
1781       if(!fpmt)
1782         continue;
1783       if(fpmt->presenceOfMultiDiscPerGeoType())
1784         return true;
1785     }
1786   return false;
1787 }
1788
1789 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1790 {
1791   if(!_father)
1792     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1793   return _father->getOrCreateAndGetArray();
1794 }
1795
1796 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1797 {
1798   if(!_father)
1799     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1800   return _father->getOrCreateAndGetArray();
1801 }
1802
1803 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1804 {
1805   return _father->getInfo();
1806 }
1807
1808 /*!
1809  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1810  * 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.
1811  * It returns 2 output vectors :
1812  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1813  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1814  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1815  */
1816 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)
1817 {
1818   int notNullPflsSz=0;
1819   int nbOfArrs=geoTypes.size();
1820   for(int i=0;i<nbOfArrs;i++)
1821     if(pfls[i])
1822       notNullPflsSz++;
1823   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1824   int nbOfDiffGeoTypes=geoTypes3.size();
1825   code.resize(3*nbOfDiffGeoTypes);
1826   notNullPfls.resize(notNullPflsSz);
1827   notNullPflsSz=0;
1828   int j=0;
1829   for(int i=0;i<nbOfDiffGeoTypes;i++)
1830     {
1831       int startZone=j;
1832       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1833       std::vector<const DataArrayInt *> notNullTmp;
1834       if(pfls[j])
1835         notNullTmp.push_back(pfls[j]);
1836       j++;
1837       for(;j<nbOfArrs;j++)
1838         if(geoTypes[j]==refType)
1839           {
1840             if(pfls[j])
1841               notNullTmp.push_back(pfls[j]);
1842           }
1843         else
1844           break;
1845       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1846       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1847       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1848       code[3*i]=(int)refType;
1849       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1850       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1851       if(notNullTmp.empty())
1852         code[3*i+2]=-1;
1853       else
1854         {
1855           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1856           code[3*i+2]=notNullPflsSz++;
1857         }
1858     }
1859 }
1860
1861 /*!
1862  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1863  */
1864 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)
1865 {
1866   int sz=dads.size();
1867   int ret=0;
1868   for(int i=0;i<sz;i++)
1869     {
1870       if(locs[i]==-1)
1871         {
1872           if(type!=ON_GAUSS_NE)
1873             ret+=dads[i].second-dads[i].first;
1874           else
1875             {
1876               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1877               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1878             }
1879         }
1880       else
1881         {
1882           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1883           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1884         }
1885     }
1886   return ret;
1887 }
1888
1889 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1890 {
1891   std::vector<std::string> ret;
1892   std::set<std::string> ret2;
1893   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1894     {
1895       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1896       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1897         if(ret2.find(*it2)==ret2.end())
1898           {
1899             ret.push_back(*it2);
1900             ret2.insert(*it2);
1901           }
1902     }
1903   return ret;
1904 }
1905
1906 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1907 {
1908   std::vector<std::string> ret;
1909   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1910     {
1911       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1912       ret.insert(ret.end(),tmp.begin(),tmp.end());
1913     }
1914   return ret;
1915 }
1916
1917 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1918 {
1919   std::vector<std::string> ret;
1920   std::set<std::string> ret2;
1921   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1922     {
1923       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1924       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1925         if(ret2.find(*it2)==ret2.end())
1926           {
1927             ret.push_back(*it2);
1928             ret2.insert(*it2);
1929           }
1930     }
1931   return ret;
1932 }
1933
1934 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1935 {
1936   std::vector<std::string> ret;
1937   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1938     {
1939       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1940       ret.insert(ret.end(),tmp.begin(),tmp.end());
1941     }
1942   return ret;
1943 }
1944
1945 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1946 {
1947   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1948     {
1949       if((*it).first==_mesh_name)
1950         {
1951           _mesh_name=(*it).second;
1952           return true;
1953         }
1954     }
1955   return false;
1956 }
1957
1958 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1959                                                       MEDFileFieldGlobsReal& glob)
1960 {
1961   if(_mesh_name!=meshName)
1962     return false;
1963   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1964   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1965   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1966   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1967   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1968   getUndergroundDataArrayExt(entries);
1969   DataArray *arr0=getOrCreateAndGetArray();//tony
1970   if(!arr0)
1971     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
1972   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
1973   if(!arr0)
1974     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
1975   int sz=0;
1976   if(!arr)
1977     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1978   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1979     {
1980       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1981         {
1982           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1983           sz+=(*it).second.second-(*it).second.first;
1984         }
1985       else
1986         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1987     }
1988   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1989   ////////////////////
1990   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1991   int *workI2=explicitIdsOldInMesh->getPointer();
1992   int sz1=0,sz2=0,sid=1;
1993   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1994   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1995   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1996     {
1997       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1998       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1999       int *workI=explicitIdsOldInArr->getPointer();
2000       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2001         {
2002           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2003           (*itL2)->setLocId(sz2);
2004           (*itL2)->_tmp_work1=(*itL2)->getStart();
2005           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2006         }
2007       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2008     }
2009   explicitIdsOldInMesh->reAlloc(sz2);
2010   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2011   ////////////////////
2012   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2013   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2014   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2015   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2016     {
2017       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2018       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2019       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2020     }
2021   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2022   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2023   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2024     {
2025       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2026       int newStart=elt->getLocId();
2027       elt->setLocId((*it)->getGeoType());
2028       elt->setNewStart(newStart);
2029       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2030       entriesKeptNew.push_back(elt);
2031       entriesKeptNew2.push_back(elt);
2032     }
2033   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2034   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2035   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2036   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2037   bool ret=false;
2038   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2039     {
2040       sid=0;
2041       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2042         {
2043           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2044           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2045           }*/
2046       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2047                                                             glob,arr2,otherEntriesNew) || ret;
2048     }
2049   if(!ret)
2050     return false;
2051   // Assign new dispatching
2052   assignNewLeaves(otherEntriesNew);
2053   arr->cpyFrom(*arr2);
2054   return true;
2055 }
2056
2057 /*!
2058  * \param [in,out] globalNum a global numbering counter for the renumbering.
2059  * \param [out] its - list of pair (start,stop) kept
2060  */
2061 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2062 {
2063   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2064   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2065     {
2066       std::vector< std::pair<int,int> > its2;
2067       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2068         {
2069           ret.push_back(*it);
2070           its.insert(its.end(),its2.begin(),its2.end());
2071         }
2072     }
2073   _field_pm_pt=ret;
2074 }
2075
2076 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2077 {
2078   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2079   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2080     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2081   //
2082   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2083   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2084   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2085   for(;it1!=types.end();it1++,it2++)
2086     {
2087       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2088       elt->setLeaves((*it1).second);
2089       *it2=elt;
2090     }
2091   _field_pm_pt=fieldPmPt;
2092 }
2093
2094 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2095 {
2096   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2097     (*it)->changePflsRefsNamesGen(mapOfModif);
2098 }
2099
2100 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2101 {
2102   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2103     (*it)->changeLocsRefsNamesGen(mapOfModif);
2104 }
2105
2106 /*!
2107  * \param [in] mesh is the whole mesh
2108  */
2109 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2110 {
2111   if(_field_pm_pt.empty())
2112     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2113   //
2114   std::vector< std::pair<int,int> > dads;
2115   std::vector<const DataArrayInt *> pfls;
2116   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2117   std::vector<int> locs,code;
2118   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2119   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2120     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2121   // Sort by types
2122   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2123   if(code.empty())
2124     {
2125       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2126       throw INTERP_KERNEL::Exception(oss.str().c_str());
2127     }
2128   //
2129   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2130   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2131   if(type!=ON_NODES)
2132     {
2133       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2134       if(!arr)
2135         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2136       else
2137         {
2138           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2139           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2140         }
2141     }
2142   else
2143     {
2144       if(code.size()!=3)
2145         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2146       int nb=code[1];
2147       if(code[2]==-1)
2148         {
2149           if(nb!=mesh->getNumberOfNodes())
2150             {
2151               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2152               oss << " nodes in mesh !";
2153               throw INTERP_KERNEL::Exception(oss.str().c_str());
2154             }
2155           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2156         }
2157       else
2158         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2159     }
2160 }
2161
2162 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2163 {
2164   if(_field_pm_pt.empty())
2165     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2166   //
2167   std::vector<std::pair<int,int> > dads;
2168   std::vector<const DataArrayInt *> pfls;
2169   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2170   std::vector<int> locs,code;
2171   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2172   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2173     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2174   // Sort by types
2175   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2176   if(code.empty())
2177     {
2178       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2179       throw INTERP_KERNEL::Exception(oss.str().c_str());
2180     }
2181   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2182   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2183   if(type!=ON_NODES)
2184     {
2185       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2186       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2187     }
2188   else
2189     {
2190       if(code.size()!=3)
2191         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2192       int nb=code[1];
2193       if(code[2]==-1)
2194         {
2195           if(nb!=mesh->getNumberOfNodes())
2196             {
2197               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2198               oss << " nodes in mesh !";
2199               throw INTERP_KERNEL::Exception(oss.str().c_str());
2200             }
2201         }
2202       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2203     }
2204   //
2205   return 0;
2206 }
2207
2208 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2209 {
2210   int globalSz=0;
2211   int nbOfEntries=0;
2212   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2213     {
2214       (*it)->getSizes(globalSz,nbOfEntries);
2215     }
2216   entries.resize(nbOfEntries);
2217   nbOfEntries=0;
2218   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2219     {
2220       (*it)->fillValues(nbOfEntries,entries);
2221     }
2222 }
2223
2224 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2225 {
2226   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2227     {
2228       if((*it)->getGeoType()==typ)
2229         return (*it)->getLeafGivenLocId(locId);
2230     }
2231   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2232   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2233   oss << "Possiblities are : ";
2234   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2235     {
2236       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2237       oss << "\"" << cm2.getRepr() << "\", ";
2238     }
2239   throw INTERP_KERNEL::Exception(oss.str().c_str());
2240 }
2241
2242 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2243 {
2244   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2245     {
2246       if((*it)->getGeoType()==typ)
2247         return (*it)->getLeafGivenLocId(locId);
2248     }
2249   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2250   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2251   oss << "Possiblities are : ";
2252   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2253     {
2254       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2255       oss << "\"" << cm2.getRepr() << "\", ";
2256     }
2257   throw INTERP_KERNEL::Exception(oss.str().c_str());
2258 }
2259
2260 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2261 {
2262   int i=0;
2263   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2264   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2265   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2266     {
2267       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2268       if(type==curType)
2269         return i;
2270       else
2271         {
2272           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2273           if(pos>pos2)
2274             it2=it+1;
2275         }
2276     }
2277   int ret=std::distance(_field_pm_pt.begin(),it2);
2278   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2279   return ret;
2280 }
2281
2282 /*!
2283  * 'dads' and 'locs' input parameters have the same number of elements
2284  * \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
2285  */
2286 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2287                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2288                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2289 {
2290   isPfl=false;
2291   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2292   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2293   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2294   const std::vector<std::string>& infos=getInfo();
2295   da->setInfoOnComponents(infos);
2296   da->setName("");
2297   if(type==ON_GAUSS_PT)
2298     {
2299       int offset=0;
2300       int nbOfArrs=dads.size();
2301       for(int i=0;i<nbOfArrs;i++)
2302         {
2303           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2304           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2305           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2306           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2307           di->alloc(nbOfElems,1);
2308           di->iota(offset);
2309           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2310           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2311           offset+=nbOfElems;
2312         }
2313     }
2314   arrOut=da;
2315   return ret.retn();
2316 }
2317
2318 /*!
2319  * 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.
2320  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2321  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2322  * The order of cells in the returned field is those imposed by the profile.
2323  * \param [in] mesh is the global mesh.
2324  */
2325 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2326                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2327                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2328                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2329 {
2330   if(da->isIdentity())
2331     {
2332       int nbOfTuples=da->getNumberOfTuples();
2333       if(nbOfTuples==mesh->getNumberOfCells())
2334         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2335     }
2336   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2337   m2->setName(mesh->getName().c_str());
2338   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2339   isPfl=true;
2340   return ret.retn();
2341 }
2342
2343 /*!
2344  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2345  */
2346 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2347                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2348                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2349 {
2350   if(da->isIdentity())
2351     {
2352       int nbOfTuples=da->getNumberOfTuples();
2353       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2354         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2355     }
2356   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2357   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2358   if(meshu)
2359     {
2360       if(meshu->getNodalConnectivity()==0)
2361         {
2362           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2363           int nb=da->getNbOfElems();
2364           const int *ptr=da->getConstPointer();
2365           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2366           meshuc->allocateCells(nb);
2367           for(int i=0;i<nb;i++)
2368             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2369           meshuc->finishInsertingCells();
2370           ret->setMesh(meshuc);
2371           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2372           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2373           disc->checkCoherencyBetween(meshuc,arrOut);
2374           return ret.retn();
2375         }
2376     }
2377   //
2378   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2379   isPfl=true;
2380   DataArrayInt *arr2=0;
2381   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2382   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2383   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2384   int nnodes=mesh2->getNumberOfNodes();
2385   if(nnodes==(int)da->getNbOfElems())
2386     {
2387       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2388       arrOut->renumberInPlace(da3->getConstPointer());
2389       mesh2->setName(mesh->getName().c_str());
2390       ret->setMesh(mesh2);
2391       return ret.retn();
2392     }
2393   else
2394     {
2395       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 !!!";
2396       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2397       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2398       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2399       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2400       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2401       throw INTERP_KERNEL::Exception(oss.str().c_str());
2402     }
2403   return 0;
2404 }
2405
2406 /*!
2407  * This method is the most light method of field retrieving.
2408  */
2409 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2410 {
2411   if(!pflIn)
2412     {
2413       pflOut=DataArrayInt::New();
2414       pflOut->alloc(nbOfElems,1);
2415       pflOut->iota(0);
2416     }
2417   else
2418     {
2419       pflOut=const_cast<DataArrayInt*>(pflIn);
2420       pflOut->incrRef();
2421     }
2422   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2423   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2424   const std::vector<std::string>& infos=getInfo();
2425   int nbOfComp=infos.size();
2426   for(int i=0;i<nbOfComp;i++)
2427     da->setInfoOnComponent(i,infos[i].c_str());
2428   safePfl->incrRef();
2429   return da.retn();
2430 }
2431
2432 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2433     _father(fath)
2434 {
2435   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2436   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2437   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2438   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2439   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2440     {
2441       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[i],meshCsit+1,meshName,pflName,locName));
2442       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2443       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],meshCsit+1,meshName,pflName,locName));
2444       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2445       if(nbProfile>0 || nbProfile2>0)
2446         {
2447           const PartDefinition *pd(0);
2448           if(mmu)
2449             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[i]),typmai2[i]);
2450           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc,pd));
2451           if(nbProfile>0)
2452             _mesh_name=name0;
2453           else
2454             _mesh_name=name1;
2455         }
2456     }
2457   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName);
2458   if(nbProfile>0)
2459     {
2460       const PartDefinition *pd(0);
2461       if(mmu)
2462         pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2463       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2464       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2465     }
2466 }
2467
2468 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2469 {
2470   copyTinyInfoFrom(mesh);
2471 }
2472
2473 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2474 {
2475   if(id>=(int)_pfls.size())
2476     _pfls.resize(id+1);
2477   _pfls[id]=DataArrayInt::New();
2478   int lgth=MEDprofileSizeByName(fid,pflName.c_str());
2479   _pfls[id]->setName(pflName);
2480   _pfls[id]->alloc(lgth,1);
2481   MEDprofileRd(fid,pflName.c_str(),_pfls[id]->getPointer());
2482   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2483 }
2484
2485 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2486 {
2487   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2488   int sz;
2489   MEDprofileInfo(fid,i+1,pflName,&sz);
2490   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2491   if(i>=(int)_pfls.size())
2492     _pfls.resize(i+1);
2493   _pfls[i]=DataArrayInt::New();
2494   _pfls[i]->alloc(sz,1);
2495   _pfls[i]->setName(pflCpp.c_str());
2496   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2497   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2498 }
2499
2500 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2501 {
2502   int nbOfPfls=_pfls.size();
2503   for(int i=0;i<nbOfPfls;i++)
2504     {
2505       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2506       cpy->applyLin(1,1,0);
2507       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2508       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2509       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2510     }
2511   //
2512   int nbOfLocs=_locs.size();
2513   for(int i=0;i<nbOfLocs;i++)
2514     _locs[i]->writeLL(fid);
2515 }
2516
2517 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2518 {
2519   std::vector<std::string> pfls=getPfls();
2520   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2521     {
2522       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2523       if(it2==pfls.end())
2524         {
2525           _pfls.push_back(*it);
2526         }
2527       else
2528         {
2529           int id=std::distance(pfls.begin(),it2);
2530           if(!(*it)->isEqual(*_pfls[id]))
2531             {
2532               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2533               throw INTERP_KERNEL::Exception(oss.str().c_str());
2534             }
2535         }
2536     }
2537   std::vector<std::string> locs=getLocs();
2538   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2539     {
2540       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2541       if(it2==locs.end())
2542         {
2543           _locs.push_back(*it);
2544         }
2545       else
2546         {
2547           int id=std::distance(locs.begin(),it2);
2548           if(!(*it)->isEqual(*_locs[id],eps))
2549             {
2550               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2551               throw INTERP_KERNEL::Exception(oss.str().c_str());
2552             }
2553         }
2554     }
2555 }
2556
2557 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2558 {
2559   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2560     getProfile((*it).c_str());
2561 }
2562
2563 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2564 {
2565   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2566     getLocalization((*it).c_str());
2567 }
2568
2569 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2570 {
2571   std::vector<std::string> profiles=real.getPflsReallyUsed();
2572   int sz=profiles.size();
2573   _pfls.resize(sz);
2574   for(int i=0;i<sz;i++)
2575     loadProfileInFile(fid,i,profiles[i].c_str());
2576   //
2577   std::vector<std::string> locs=real.getLocsReallyUsed();
2578   sz=locs.size();
2579   _locs.resize(sz);
2580   for(int i=0;i<sz;i++)
2581     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2582 }
2583
2584 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2585 {
2586   int nProfil=MEDnProfile(fid);
2587   for(int i=0;i<nProfil;i++)
2588     loadProfileInFile(fid,i);
2589   int sz=MEDnLocalization(fid);
2590   _locs.resize(sz);
2591   for(int i=0;i<sz;i++)
2592     {
2593       _locs[i]=MEDFileFieldLoc::New(fid,i);
2594     }
2595 }
2596
2597 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2598 {
2599   return new MEDFileFieldGlobs(fname);
2600 }
2601
2602 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2603 {
2604   return new MEDFileFieldGlobs;
2605 }
2606
2607 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2608 {
2609   return _file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2610 }
2611
2612 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2613 {
2614   std::vector<const BigMemoryObject *> ret;
2615   for(std::vector< MEDCouplingAutoRefCountObjectPtr< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2616     ret.push_back((const DataArrayInt *)*it);
2617   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2618     ret.push_back((const MEDFileFieldLoc *)*it);
2619   return ret;
2620 }
2621
2622 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const
2623 {
2624   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2625   std::size_t i=0;
2626   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2627     {
2628       if((const DataArrayInt *)*it)
2629         ret->_pfls[i]=(*it)->deepCpy();
2630     }
2631   i=0;
2632   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2633     {
2634       if((const MEDFileFieldLoc*)*it)
2635         ret->_locs[i]=(*it)->deepCpy();
2636     }
2637   return ret.retn();
2638 }
2639
2640 /*!
2641  * \throw if a profile in \a pfls in not in \a this.
2642  * \throw if a localization in \a locs in not in \a this.
2643  * \sa MEDFileFieldGlobs::deepCpyPart
2644  */
2645 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2646 {
2647   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2648   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2649     {
2650       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2651       if(!pfl)
2652         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2653       pfl->incrRef();
2654       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2655       ret->_pfls.push_back(pfl2);
2656     }
2657   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2658     {
2659       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2660       if(!loc)
2661         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2662       loc->incrRef();
2663       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2664       ret->_locs.push_back(loc2);
2665     }
2666   ret->setFileName(getFileName());
2667   return ret.retn();
2668 }
2669
2670 /*!
2671  * \throw if a profile in \a pfls in not in \a this.
2672  * \throw if a localization in \a locs in not in \a this.
2673  * \sa MEDFileFieldGlobs::shallowCpyPart
2674  */
2675 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2676 {
2677   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2678   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2679     {
2680       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2681       if(!pfl)
2682         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2683       ret->_pfls.push_back(pfl->deepCpy());
2684     }
2685   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2686     {
2687       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2688       if(!loc)
2689         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2690       ret->_locs.push_back(loc->deepCpy());
2691     }
2692   ret->setFileName(getFileName());
2693   return ret.retn();
2694 }
2695
2696 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2697 {
2698 }
2699
2700 MEDFileFieldGlobs::MEDFileFieldGlobs()
2701 {
2702 }
2703
2704 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2705 {
2706 }
2707
2708 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2709 {
2710   oss << "Profiles :\n";
2711   std::size_t n=_pfls.size();
2712   for(std::size_t i=0;i<n;i++)
2713     {
2714       oss << "  - #" << i << " ";
2715       const DataArrayInt *pfl=_pfls[i];
2716       if(pfl)
2717         oss << "\"" << pfl->getName() << "\"\n";
2718       else
2719         oss << "EMPTY !\n";
2720     }
2721   n=_locs.size();
2722   oss << "Localizations :\n";
2723   for(std::size_t i=0;i<n;i++)
2724     {
2725       oss << "  - #" << i << " ";
2726       const MEDFileFieldLoc *loc=_locs[i];
2727       if(loc)
2728         loc->simpleRepr(oss);
2729       else
2730         oss<< "EMPTY !\n";
2731     }
2732 }
2733
2734 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2735 {
2736   _file_name=fileName;
2737 }
2738
2739 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2740 {
2741   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2742     {
2743       DataArrayInt *elt(*it);
2744       if(elt)
2745         {
2746           std::string name(elt->getName());
2747           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2748             {
2749               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2750                 {
2751                   elt->setName((*it2).second.c_str());
2752                   return;
2753                 }
2754             }
2755         }
2756     }
2757 }
2758
2759 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2760 {
2761   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2762     {
2763       MEDFileFieldLoc *elt(*it);
2764       if(elt)
2765         {
2766           std::string name(elt->getName());
2767           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2768             {
2769               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2770                 {
2771                   elt->setName((*it2).second.c_str());
2772                   return;
2773                 }
2774             }
2775         }
2776     }
2777 }
2778
2779 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2780 {
2781   if(locId<0 || locId>=(int)_locs.size())
2782     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2783   return _locs[locId]->getNbOfGaussPtPerCell();
2784 }
2785
2786 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2787 {
2788   return getLocalizationFromId(getLocalizationId(locName));
2789 }
2790
2791 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2792 {
2793   if(locId<0 || locId>=(int)_locs.size())
2794     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2795   return *_locs[locId];
2796 }
2797
2798 namespace ParaMEDMEMImpl
2799 {
2800   class LocFinder
2801   {
2802   public:
2803     LocFinder(const std::string& loc):_loc(loc) { }
2804     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2805   private:
2806     const std::string &_loc;
2807   };
2808
2809   class PflFinder
2810   {
2811   public:
2812     PflFinder(const std::string& pfl):_pfl(pfl) { }
2813     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2814   private:
2815     const std::string& _pfl;
2816   };
2817 }
2818
2819 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2820 {
2821   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2822   if(it==_locs.end())
2823     {
2824       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2825       for(it=_locs.begin();it!=_locs.end();it++)
2826         oss << "\"" << (*it)->getName() << "\", ";
2827       throw INTERP_KERNEL::Exception(oss.str().c_str());
2828     }
2829   return std::distance(_locs.begin(),it);
2830 }
2831
2832 /*!
2833  * The returned value is never null.
2834  */
2835 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2836 {
2837   std::string pflNameCpp(pflName);
2838   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2839   if(it==_pfls.end())
2840     {
2841       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2842       for(it=_pfls.begin();it!=_pfls.end();it++)
2843         oss << "\"" << (*it)->getName() << "\", ";
2844       throw INTERP_KERNEL::Exception(oss.str().c_str());
2845     }
2846   return *it;
2847 }
2848
2849 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2850 {
2851   if(pflId<0 || pflId>=(int)_pfls.size())
2852     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2853   return _pfls[pflId];
2854 }
2855
2856 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
2857 {
2858   if(locId<0 || locId>=(int)_locs.size())
2859     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2860   return *_locs[locId];
2861 }
2862
2863 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
2864 {
2865   return getLocalizationFromId(getLocalizationId(locName));
2866 }
2867
2868 /*!
2869  * The returned value is never null.
2870  */
2871 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
2872 {
2873   std::string pflNameCpp(pflName);
2874   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2875   if(it==_pfls.end())
2876     {
2877       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2878       for(it=_pfls.begin();it!=_pfls.end();it++)
2879         oss << "\"" << (*it)->getName() << "\", ";
2880       throw INTERP_KERNEL::Exception(oss.str().c_str());
2881     }
2882   return *it;
2883 }
2884
2885 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
2886 {
2887   if(pflId<0 || pflId>=(int)_pfls.size())
2888     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2889   return _pfls[pflId];
2890 }
2891
2892 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
2893 {
2894   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2895   int i=0;
2896   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2897     {
2898       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2899         newPfls.push_back(*it);
2900     }
2901   _pfls=newPfls;
2902 }
2903
2904 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
2905 {
2906   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2907   int i=0;
2908   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2909     {
2910       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2911         newLocs.push_back(*it);
2912     }
2913   _locs=newLocs;
2914 }
2915
2916 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2917 {
2918   int sz=_pfls.size();
2919   std::vector<std::string> ret(sz);
2920   for(int i=0;i<sz;i++)
2921     ret[i]=_pfls[i]->getName();
2922   return ret;
2923 }
2924
2925 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2926 {
2927   int sz=_locs.size();
2928   std::vector<std::string> ret(sz);
2929   for(int i=0;i<sz;i++)
2930     ret[i]=_locs[i]->getName();
2931   return ret;
2932 }
2933
2934 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
2935 {
2936   std::vector<std::string> v=getPfls();
2937   std::string s(pflName);
2938   return std::find(v.begin(),v.end(),s)!=v.end();
2939 }
2940
2941 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
2942 {
2943   std::vector<std::string> v=getLocs();
2944   std::string s(locName);
2945   return std::find(v.begin(),v.end(),s)!=v.end();
2946 }
2947
2948 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2949 {
2950   std::map<int,std::vector<int> > m;
2951   int i=0;
2952   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2953     {
2954       const DataArrayInt *tmp=(*it);
2955       if(tmp)
2956         {
2957           m[tmp->getHashCode()].push_back(i);
2958         }
2959     }
2960   std::vector< std::vector<int> > ret;
2961   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2962     {
2963       if((*it2).second.size()>1)
2964         {
2965           std::vector<int> ret0;
2966           bool equalityOrNot=false;
2967           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2968             {
2969               std::vector<int>::const_iterator it4=it3; it4++;
2970               for(;it4!=(*it2).second.end();it4++)
2971                 {
2972                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2973                     {
2974                       if(!equalityOrNot)
2975                         ret0.push_back(*it3);
2976                       ret0.push_back(*it4);
2977                       equalityOrNot=true;
2978                     }
2979                 }
2980             }
2981           if(!ret0.empty())
2982             ret.push_back(ret0);
2983         }
2984     }
2985   return ret;
2986 }
2987
2988 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2989 {
2990   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2991 }
2992
2993 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
2994 {
2995   std::string name(pfl->getName());
2996   if(name.empty())
2997     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2998   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2999     if(name==(*it)->getName())
3000       {
3001         if(!pfl->isEqual(*(*it)))
3002           {
3003             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3004             throw INTERP_KERNEL::Exception(oss.str().c_str());
3005           }
3006       }
3007   pfl->incrRef();
3008   _pfls.push_back(pfl);
3009 }
3010
3011 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)
3012 {
3013   std::string name(locName);
3014   if(name.empty())
3015     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3016   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3017   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3018     if((*it)->isName(locName))
3019       {
3020         if(!(*it)->isEqual(*obj,1e-12))
3021           {
3022             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3023             throw INTERP_KERNEL::Exception(oss.str().c_str());
3024           }
3025       }
3026   _locs.push_back(obj);
3027 }
3028
3029 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3030 {
3031   std::vector<std::string> names=getPfls();
3032   return CreateNewNameNotIn("NewPfl_",names);
3033 }
3034
3035 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3036 {
3037   std::vector<std::string> names=getLocs();
3038   return CreateNewNameNotIn("NewLoc_",names);
3039 }
3040
3041 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3042 {
3043   for(std::size_t sz=0;sz<100000;sz++)
3044     {
3045       std::ostringstream tryName;
3046       tryName << prefix << sz;
3047       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3048         return tryName.str();
3049     }
3050   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3051 }
3052
3053 /*!
3054  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3055  *  \param [in] fname - the file name.
3056  */
3057 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3058 {
3059 }
3060
3061 /*!
3062  * Creates an empty MEDFileFieldGlobsReal.
3063  */
3064 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3065 {
3066 }
3067
3068 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3069 {
3070   return 0;
3071 }
3072
3073 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3074 {
3075   std::vector<const BigMemoryObject *> ret;
3076   ret.push_back((const MEDFileFieldGlobs *)_globals);
3077   return ret;
3078 }
3079
3080 /*!
3081  * Returns a string describing profiles and Gauss points held in \a this.
3082  *  \return std::string - the description string.
3083  */
3084 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3085 {
3086   const MEDFileFieldGlobs *glob=_globals;
3087   std::ostringstream oss2; oss2 << glob;
3088   std::string stars(oss2.str().length(),'*');
3089   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3090   if(glob)
3091     glob->simpleRepr(oss);
3092   else
3093     oss << "NO GLOBAL INFORMATION !\n";
3094 }
3095
3096 void MEDFileFieldGlobsReal::resetContent()
3097 {
3098   _globals=MEDFileFieldGlobs::New();
3099 }
3100
3101 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3102 {
3103 }
3104
3105 /*!
3106  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3107  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3108  */
3109 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3110 {
3111   _globals=other._globals;
3112 }
3113
3114 /*!
3115  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3116  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3117  */
3118 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3119 {
3120   const MEDFileFieldGlobs *otherg(other._globals);
3121   if(!otherg)
3122     return ;
3123   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3124 }
3125
3126 /*!
3127  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3128  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3129  */
3130 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3131 {
3132   const MEDFileFieldGlobs *otherg(other._globals);
3133   if(!otherg)
3134     return ;
3135   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3136 }
3137
3138 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3139 {
3140   _globals=other._globals;
3141   if((const MEDFileFieldGlobs *)_globals)
3142     _globals=other._globals->deepCpy();
3143 }
3144
3145 /*!
3146  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3147  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3148  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3149  *         \a this and \a other MEDFileFieldGlobsReal.
3150  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3151  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3152  */
3153 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3154 {
3155   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3156   if(thisGlobals==otherGlobals)
3157     return ;
3158   if(!thisGlobals)
3159     {
3160       _globals=other._globals;
3161       return ;
3162     }
3163   _globals->appendGlobs(*other._globals,eps);
3164 }
3165
3166 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3167 {
3168   checkGlobsPflsPartCoherency();
3169   checkGlobsLocsPartCoherency();
3170 }
3171
3172 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3173 {
3174   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3175 }
3176
3177 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3178 {
3179   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3180 }
3181
3182 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3183 {
3184   contentNotNull()->loadProfileInFile(fid,id,pflName);
3185 }
3186
3187 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3188 {
3189   contentNotNull()->loadProfileInFile(fid,id);
3190 }
3191
3192 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3193 {
3194   contentNotNull()->loadGlobals(fid,*this);
3195 }
3196
3197 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3198 {
3199   contentNotNull()->loadAllGlobals(fid);
3200 }
3201
3202 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3203 {
3204   contentNotNull()->writeGlobals(fid,opt);
3205 }
3206
3207 /*!
3208  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3209  * or getPflsReallyUsedMulti().
3210  *  \return std::vector<std::string> - a sequence of names of all profiles.
3211  */
3212 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3213 {
3214   return contentNotNull()->getPfls();
3215 }
3216
3217 /*!
3218  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3219  * or getLocsReallyUsedMulti().
3220  *  \return std::vector<std::string> - a sequence of names of all localizations.
3221  */
3222 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3223 {
3224   return contentNotNull()->getLocs();
3225 }
3226
3227 /*!
3228  * Checks if the profile with a given name exists.
3229  *  \param [in] pflName - the profile name of interest.
3230  *  \return bool - \c true if the profile named \a pflName exists.
3231  */
3232 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3233 {
3234   return contentNotNull()->existsPfl(pflName);
3235 }
3236
3237 /*!
3238  * Checks if the localization with a given name exists.
3239  *  \param [in] locName - the localization name of interest.
3240  *  \return bool - \c true if the localization named \a locName exists.
3241  */
3242 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3243 {
3244   return contentNotNull()->existsLoc(locName);
3245 }
3246
3247 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3248 {
3249   return contentNotNull()->createNewNameOfPfl();
3250 }
3251
3252 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3253 {
3254   return contentNotNull()->createNewNameOfLoc();
3255 }
3256
3257 /*!
3258  * Sets the name of a MED file.
3259  *  \param [inout] fileName - the file name.
3260  */
3261 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3262 {
3263   contentNotNull()->setFileName(fileName);
3264 }
3265
3266 /*!
3267  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3268  * in the same order.
3269  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3270  *          Each item of this sequence is a vector containing ids of equal profiles.
3271  */
3272 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3273 {
3274   return contentNotNull()->whichAreEqualProfiles();
3275 }
3276
3277 /*!
3278  * Finds equal localizations.
3279  *  \param [in] eps - a precision used to compare real values of the localizations.
3280  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3281  *          Each item of this sequence is a vector containing ids of equal localizations.
3282  */
3283 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3284 {
3285   return contentNotNull()->whichAreEqualLocs(eps);
3286 }
3287
3288 /*!
3289  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3290  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3291  *        this sequence is a pair whose 
3292  *        - the first item is a vector of profile names to replace by the second item,
3293  *        - the second item is a profile name to replace every profile name of the first item.
3294  */
3295 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3296 {
3297   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3298 }
3299
3300 /*!
3301  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3302  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3303  *        this sequence is a pair whose 
3304  *        - the first item is a vector of localization names to replace by the second item,
3305  *        - the second item is a localization name to replace every localization name of the first item.
3306  */
3307 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3308 {
3309   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3310 }
3311
3312 /*!
3313  * Replaces references to some profiles (a reference is a profile name) by references
3314  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3315  * them-selves accordingly. <br>
3316  * This method is a generalization of changePflName().
3317  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3318  *        this sequence is a pair whose 
3319  *        - the first item is a vector of profile names to replace by the second item,
3320  *        - the second item is a profile name to replace every profile of the first item.
3321  * \sa changePflsRefsNamesGen()
3322  * \sa changePflName()
3323  */
3324 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3325 {
3326   changePflsRefsNamesGen(mapOfModif);
3327   changePflsNamesInStruct(mapOfModif);
3328 }
3329
3330 /*!
3331  * Replaces references to some localizations (a reference is a localization name) by references
3332  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3333  * them-selves accordingly. <br>
3334  * This method is a generalization of changeLocName().
3335  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3336  *        this sequence is a pair whose 
3337  *        - the first item is a vector of localization names to replace by the second item,
3338  *        - the second item is a localization name to replace every localization of the first item.
3339  * \sa changeLocsRefsNamesGen()
3340  * \sa changeLocName()
3341  */
3342 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3343 {
3344   changeLocsRefsNamesGen(mapOfModif);
3345   changeLocsNamesInStruct(mapOfModif);
3346 }
3347
3348 /*!
3349  * Renames the profile having a given name and updates references to this profile.
3350  *  \param [in] oldName - the name of the profile to rename.
3351  *  \param [in] newName - a new name of the profile.
3352  * \sa changePflsNames().
3353  */
3354 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3355 {
3356   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3357   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3358   mapOfModif[0]=p;
3359   changePflsNames(mapOfModif);
3360 }
3361
3362 /*!
3363  * Renames the localization having a given name and updates references to this localization.
3364  *  \param [in] oldName - the name of the localization to rename.
3365  *  \param [in] newName - a new name of the localization.
3366  * \sa changeLocsNames().
3367  */
3368 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3369 {
3370   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3371   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3372   mapOfModif[0]=p;
3373   changeLocsNames(mapOfModif);
3374 }
3375
3376 /*!
3377  * Removes duplicated profiles. Returns a map used to update references to removed 
3378  * profiles via changePflsRefsNamesGen().
3379  * Equal profiles are found using whichAreEqualProfiles().
3380  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3381  *          a sequence describing the performed replacements of profiles. Each element of
3382  *          this sequence is a pair whose
3383  *          - the first item is a vector of profile names replaced by the second item,
3384  *          - the second item is a profile name replacing every profile of the first item.
3385  */
3386 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3387 {
3388   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3389   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3390   int i=0;
3391   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3392     {
3393       std::vector< std::string > tmp((*it).size());
3394       int j=0;
3395       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3396         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3397       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3398       ret[i]=p;
3399       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3400       killProfileIds(tmp2);
3401     }
3402   changePflsRefsNamesGen(ret);
3403   return ret;
3404 }
3405
3406 /*!
3407  * Removes duplicated localizations. Returns a map used to update references to removed 
3408  * localizations via changeLocsRefsNamesGen().
3409  * Equal localizations are found using whichAreEqualLocs().
3410  *  \param [in] eps - a precision used to compare real values of the localizations.
3411  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3412  *          a sequence describing the performed replacements of localizations. Each element of
3413  *          this sequence is a pair whose
3414  *          - the first item is a vector of localization names replaced by the second item,
3415  *          - the second item is a localization name replacing every localization of the first item.
3416  */
3417 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3418 {
3419   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3420   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3421   int i=0;
3422   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3423     {
3424       std::vector< std::string > tmp((*it).size());
3425       int j=0;
3426       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3427         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3428       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3429       ret[i]=p;
3430       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3431       killLocalizationIds(tmp2);
3432     }
3433   changeLocsRefsNamesGen(ret);
3434   return ret;
3435 }
3436
3437 /*!
3438  * Returns number of Gauss points per cell in a given localization.
3439  *  \param [in] locId - an id of the localization of interest.
3440  *  \return int - the number of the Gauss points per cell.
3441  */
3442 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3443 {
3444   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3445 }
3446
3447 /*!
3448  * Returns an id of a localization by its name.
3449  *  \param [in] loc - the localization name of interest.
3450  *  \return int - the id of the localization.
3451  *  \throw If there is no a localization named \a loc.
3452  */
3453 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3454 {
3455   return contentNotNull()->getLocalizationId(loc);
3456 }
3457
3458 /*!
3459  * Returns the name of the MED file.
3460  *  \return const std::string&  - the MED file name.
3461  */
3462 std::string MEDFileFieldGlobsReal::getFileName() const
3463 {
3464   return contentNotNull()->getFileName();
3465 }
3466
3467 /*!
3468  * Returns a localization object by its name.
3469  *  \param [in] locName - the name of the localization of interest.
3470  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3471  *  \throw If there is no a localization named \a locName.
3472  */
3473 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3474 {
3475   return contentNotNull()->getLocalization(locName);
3476 }
3477
3478 /*!
3479  * Returns a localization object by its id.
3480  *  \param [in] locId - the id of the localization of interest.
3481  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3482  *  \throw If there is no a localization with id \a locId.
3483  */
3484 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3485 {
3486   return contentNotNull()->getLocalizationFromId(locId);
3487 }
3488
3489 /*!
3490  * Returns a profile array by its name.
3491  *  \param [in] pflName - the name of the profile of interest.
3492  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3493  *  \throw If there is no a profile named \a pflName.
3494  */
3495 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3496 {
3497   return contentNotNull()->getProfile(pflName);
3498 }
3499
3500 /*!
3501  * Returns a profile array by its id.
3502  *  \param [in] pflId - the id of the profile of interest.
3503  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3504  *  \throw If there is no a profile with id \a pflId.
3505  */
3506 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3507 {
3508   return contentNotNull()->getProfileFromId(pflId);
3509 }
3510
3511 /*!
3512  * Returns a localization object, apt for modification, by its id.
3513  *  \param [in] locId - the id of the localization of interest.
3514  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3515  *          having the id \a locId.
3516  *  \throw If there is no a localization with id \a locId.
3517  */
3518 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3519 {
3520   return contentNotNull()->getLocalizationFromId(locId);
3521 }
3522
3523 /*!
3524  * Returns a localization object, apt for modification, by its name.
3525  *  \param [in] locName - the name of the localization of interest.
3526  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3527  *          having the name \a locName.
3528  *  \throw If there is no a localization named \a locName.
3529  */
3530 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3531 {
3532   return contentNotNull()->getLocalization(locName);
3533 }
3534
3535 /*!
3536  * Returns a profile array, apt for modification, by its name.
3537  *  \param [in] pflName - the name of the profile of interest.
3538  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3539  *  \throw If there is no a profile named \a pflName.
3540  */
3541 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3542 {
3543   return contentNotNull()->getProfile(pflName);
3544 }
3545
3546 /*!
3547  * Returns a profile array, apt for modification, by its id.
3548  *  \param [in] pflId - the id of the profile of interest.
3549  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3550  *  \throw If there is no a profile with id \a pflId.
3551  */
3552 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3553 {
3554   return contentNotNull()->getProfileFromId(pflId);
3555 }
3556
3557 /*!
3558  * Removes profiles given by their ids. No data is updated to track this removal.
3559  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3560  */
3561 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3562 {
3563   contentNotNull()->killProfileIds(pflIds);
3564 }
3565
3566 /*!
3567  * Removes localizations given by their ids. No data is updated to track this removal.
3568  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3569  */
3570 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3571 {
3572   contentNotNull()->killLocalizationIds(locIds);
3573 }
3574
3575 /*!
3576  * Stores a profile array.
3577  *  \param [in] pfl - the profile array to store.
3578  *  \throw If the name of \a pfl is empty.
3579  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3580  *         different ids.
3581  */
3582 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3583 {
3584   contentNotNull()->appendProfile(pfl);
3585 }
3586
3587 /*!
3588  * Adds a new localization of Gauss points.
3589  *  \param [in] locName - the name of the new localization.
3590  *  \param [in] geoType - a geometrical type of the reference cell.
3591  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3592  *         must be \c nbOfNodesPerCell * \c dimOfType.
3593  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3594  *         must be  _wg_.size() * \c dimOfType.
3595  *  \param [in] w - the weights of Gauss points.
3596  *  \throw If \a locName is empty.
3597  *  \throw If a localization with the name \a locName already exists but is
3598  *         different form the new one.
3599  */
3600 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)
3601 {
3602   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3603 }
3604
3605 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3606 {
3607   MEDFileFieldGlobs *g(_globals);
3608   if(!g)
3609     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3610   return g;
3611 }
3612
3613 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3614 {
3615   const MEDFileFieldGlobs *g(_globals);
3616   if(!g)
3617     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3618   return g;
3619 }
3620
3621 //= MEDFileFieldNameScope
3622
3623 MEDFileFieldNameScope::MEDFileFieldNameScope()
3624 {
3625 }
3626
3627 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3628 {
3629 }
3630
3631 /*!
3632  * Returns the name of \a this field.
3633  *  \return std::string - a string containing the field name.
3634  */
3635 std::string MEDFileFieldNameScope::getName() const
3636 {
3637   return _name;
3638 }
3639
3640 /*!
3641  * Sets name of \a this field
3642  *  \param [in] name - the new field name.
3643  */
3644 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3645 {
3646   _name=fieldName;
3647 }
3648
3649 std::string MEDFileFieldNameScope::getDtUnit() const
3650 {
3651   return _dt_unit;
3652 }
3653
3654 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3655 {
3656   _dt_unit=dtUnit;
3657 }
3658
3659 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3660 {
3661   _name=other._name;
3662   _dt_unit=other._dt_unit;
3663 }
3664
3665 //= MEDFileAnyTypeField1TSWithoutSDA
3666
3667 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3668 {
3669   _field_per_mesh.resize(other._field_per_mesh.size());
3670   std::size_t i=0;
3671   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3672     {
3673       if((const MEDFileFieldPerMesh *)*it)
3674         _field_per_mesh[i]=(*it)->deepCpy(this);
3675     }
3676 }
3677
3678 /*!
3679  * Prints a string describing \a this field into a stream. This string is outputted 
3680  * by \c print Python command.
3681  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3682  *  \param [in,out] oss - the out stream.
3683  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3684  *          info id printed, else, not.
3685  */
3686 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3687 {
3688   std::string startOfLine(bkOffset,' ');
3689   oss << startOfLine << "Field ";
3690   if(bkOffset==0)
3691     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3692   oss << "on one time Step ";
3693   if(f1tsId>=0)
3694     oss << "(" << f1tsId << ") ";
3695   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3696   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3697   const DataArray *arr=getUndergroundDataArray();
3698   if(arr)
3699     {
3700       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3701       if(f1tsId<0)
3702         {
3703           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3704           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3705             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3706         }
3707       if(arr->isAllocated())
3708         {
3709           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3710         }
3711       else
3712         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3713     }
3714   else
3715     {
3716       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3717     }
3718   oss << startOfLine << "----------------------" << std::endl;
3719   if(!_field_per_mesh.empty())
3720     {
3721       int i=0;
3722       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3723         {
3724           const MEDFileFieldPerMesh *cur=(*it2);
3725           if(cur)
3726             cur->simpleRepr(bkOffset,oss,i);
3727           else
3728             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3729         }
3730     }
3731   else
3732     {
3733       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3734     }
3735   oss << startOfLine << "----------------------" << std::endl;
3736 }
3737
3738 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3739 {
3740   const DataArray *arr(getUndergroundDataArray());
3741   if(!arr)
3742     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3743   int nbOfCompo=arr->getNumberOfComponents();
3744   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3745   for(int i=0;i<nbOfCompo;i++)
3746     {
3747       ret[i]=deepCpy();
3748       std::vector<int> v(1,i);
3749       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3750       ret[i]->setArray(arr2);
3751     }
3752   return ret;
3753 }
3754
3755 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order):MEDFileFieldNameScope(fieldName),_iteration(iteration),_order(order),_csit(csit),_nb_of_tuples_to_be_allocated(-2)
3756 {
3757 }
3758
3759 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3760 {
3761 }
3762
3763 /*!
3764  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3765  * empty. Returns -1 if this in on nodes.
3766  *  \return int - the dimension of \a this.
3767  */
3768 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3769 {
3770   int ret=-2;
3771   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3772     (*it)->getDimension(ret);
3773   return ret;
3774 }
3775
3776 /*!
3777  * Returns the mesh name.
3778  *  \return std::string - a string holding the mesh name.
3779  *  \throw If \c _field_per_mesh.empty()
3780  */
3781 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3782 {
3783   if(_field_per_mesh.empty())
3784     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3785   return _field_per_mesh[0]->getMeshName();
3786 }
3787
3788 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3789 {
3790   std::string oldName(getMeshName());
3791   std::vector< std::pair<std::string,std::string> > v(1);
3792   v[0].first=oldName; v[0].second=newMeshName;
3793   changeMeshNames(v);
3794 }
3795
3796 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3797 {
3798   bool ret=false;
3799   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3800     {
3801       MEDFileFieldPerMesh *cur(*it);
3802       if(cur)
3803         ret=cur->changeMeshNames(modifTab) || ret;
3804     }
3805   return ret;
3806 }
3807
3808 /*!
3809  * Returns the number of iteration of the state of underlying mesh.
3810  *  \return int - the iteration number.
3811  *  \throw If \c _field_per_mesh.empty()
3812  */
3813 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3814 {
3815   if(_field_per_mesh.empty())
3816     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3817   return _field_per_mesh[0]->getMeshIteration();
3818 }
3819
3820 /*!
3821  * Returns the order number of iteration of the state of underlying mesh.
3822  *  \return int - the order number.
3823  *  \throw If \c _field_per_mesh.empty()
3824  */
3825 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3826 {
3827   if(_field_per_mesh.empty())
3828     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3829   return _field_per_mesh[0]->getMeshOrder();
3830 }
3831
3832 /*!
3833  * Checks if \a this field is tagged by a given iteration number and a given
3834  * iteration order number.
3835  *  \param [in] iteration - the iteration number of interest.
3836  *  \param [in] order - the iteration order number of interest.
3837  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3838  *          \a this->getOrder() == \a order.
3839  */
3840 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3841 {
3842   return iteration==_iteration && order==_order;
3843 }
3844
3845 /*!
3846  * Returns number of iteration and order number of iteration when
3847  * \a this field has been calculated.
3848  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3849  *          order number.
3850  */
3851 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3852 {
3853   std::pair<int,int> p;
3854   fillIteration(p);
3855   return p;
3856 }
3857
3858 /*!
3859  * Returns number of iteration and order number of iteration when
3860  * \a this field has been calculated.
3861  *  \param [in,out] p - a pair returning the iteration number and the iteration
3862  *          order number.
3863  */
3864 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3865 {
3866   p.first=_iteration;
3867   p.second=_order;
3868 }
3869
3870 /*!
3871  * Returns all types of spatial discretization of \a this field.
3872  *  \param [in,out] types - a sequence of types of \a this field.
3873  */
3874 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
3875 {
3876   std::set<TypeOfField> types2;
3877   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3878     {
3879       (*it)->fillTypesOfFieldAvailable(types2);
3880     }
3881   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3882   std::copy(types2.begin(),types2.end(),bi);
3883 }
3884
3885 /*!
3886  * Returns all types of spatial discretization of \a this field.
3887  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3888  *          of \a this field.
3889  */
3890 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
3891 {
3892   std::vector<TypeOfField> ret;
3893   fillTypesOfFieldAvailable(ret);
3894   return ret;
3895 }
3896
3897 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3898 {
3899   std::vector<std::string> ret;
3900   std::set<std::string> ret2;
3901   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3902     {
3903       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3904       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3905         if(ret2.find(*it2)==ret2.end())
3906           {
3907             ret.push_back(*it2);
3908             ret2.insert(*it2);
3909           }
3910     }
3911   return ret;
3912 }
3913
3914 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3915 {
3916   std::vector<std::string> ret;
3917   std::set<std::string> ret2;
3918   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3919     {
3920       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3921       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3922         if(ret2.find(*it2)==ret2.end())
3923           {
3924             ret.push_back(*it2);
3925             ret2.insert(*it2);
3926           }
3927     }
3928   return ret;
3929 }
3930
3931 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3932 {
3933   std::vector<std::string> ret;
3934   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3935     {
3936       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3937       ret.insert(ret.end(),tmp.begin(),tmp.end());
3938     }
3939   return ret;
3940 }
3941
3942 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3943 {
3944   std::vector<std::string> ret;
3945   std::set<std::string> ret2;
3946   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3947     {
3948       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3949       ret.insert(ret.end(),tmp.begin(),tmp.end());
3950     }
3951   return ret;
3952 }
3953
3954 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3955 {
3956   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3957     (*it)->changePflsRefsNamesGen(mapOfModif);
3958 }
3959
3960 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3961 {
3962   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3963     (*it)->changeLocsRefsNamesGen(mapOfModif);
3964 }
3965
3966 /*!
3967  * Returns all attributes of parts of \a this field lying on a given mesh.
3968  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3969  * item of every of returned sequences refers to the _i_-th part of \a this field.
3970  * Thus all sequences returned by this method are of the same length equal to number
3971  * of different types of supporting entities.<br>
3972  * A field part can include sub-parts with several different spatial discretizations,
3973  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3974  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3975  * of a nested sequence corresponds to a type of spatial discretization.<br>
3976  * This method allows for iteration over MEDFile DataStructure without any overhead.
3977  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3978  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3979  *          not checked if \a mname == \c NULL).
3980  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3981  *          a field part is returned. 
3982  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3983  *          This sequence is of the same length as \a types. 
3984  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3985  *          discretization. A profile name can be empty.
3986  *          Length of this and of nested sequences is the same as that of \a typesF.
3987  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3988  *          discretization. A localization name can be empty.
3989  *          Length of this and of nested sequences is the same as that of \a typesF.
3990  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3991  *          of ids of tuples within the data array, per each type of spatial
3992  *          discretization within one mesh entity type. 
3993  *          Length of this and of nested sequences is the same as that of \a typesF.
3994  *  \throw If no field is lying on \a mname.
3995  */
3996 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
3997 {
3998   int meshId=0;
3999   if(!mname.empty())
4000     meshId=getMeshIdFromMeshName(mname);
4001   else
4002     if(_field_per_mesh.empty())
4003       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4004   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4005 }
4006
4007 /*!
4008  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4009  * maximal absolute dimension and values returned via the out parameter \a levs are 
4010  * dimensions relative to the maximal absolute dimension. <br>
4011  * This method is designed for MEDFileField1TS instances that have a discretization
4012  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
4013  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
4014  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
4015  * Only these 3 discretizations will be taken into account here. If \a this is
4016  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4017  * This method is useful to make the link between the dimension of the underlying mesh
4018  * and the levels of \a this, because it is possible that the highest dimension of \a this
4019  * field is not equal to the dimension of the underlying mesh.
4020  * 
4021  * Let's consider the following case:
4022  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4023  * TETRA4, HEXA8, TRI3 and SEG2.
4024  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4025  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4026  *
4027  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4028  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4029  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4030  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4031  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4032  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4033  * For example<br>
4034  * to retrieve the highest level of
4035  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4036  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4037  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4038  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4039  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4040  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4041  *          not checked if \a mname == \c NULL).
4042  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4043  *          absolute one. They are in decreasing order. This sequence is cleared before
4044  *          filling it in.
4045  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4046  *  \throw If no field is lying on \a mname.
4047  */
4048 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4049 {
4050   levs.clear();
4051   int meshId=getMeshIdFromMeshName(mname);
4052   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4053   std::vector< std::vector<TypeOfField> > typesF;
4054   std::vector< std::vector<std::string> > pfls, locs;
4055   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4056   if(types.empty())
4057     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4058   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4059   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4060     return -1;
4061   st.erase(INTERP_KERNEL::NORM_ERROR);
4062   std::set<int> ret1;
4063   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4064     {
4065       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4066       ret1.insert((int)cm.getDimension());
4067     }
4068   int ret=*std::max_element(ret1.begin(),ret1.end());
4069   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4070   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4071   return ret;
4072 }
4073
4074 /*!
4075  * \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.
4076  * \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.
4077  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4078  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4079  */
4080 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4081 {
4082   int mid=getMeshIdFromMeshName(mName);
4083   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4084 }
4085
4086 /*!
4087  * \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.
4088  * \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.
4089  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4090  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4091  */
4092 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4093 {
4094   int mid=getMeshIdFromMeshName(mName);
4095   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4096 }
4097
4098 /*!
4099  * \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.
4100  */
4101 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4102 {
4103   if(_field_per_mesh.empty())
4104     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4105   if(mName.empty())
4106     return 0;
4107   std::string mName2(mName);
4108   int ret=0;
4109   std::vector<std::string> msg;
4110   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4111     if(mName2==(*it)->getMeshName())
4112       return ret;
4113     else
4114       msg.push_back((*it)->getMeshName());
4115   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4116   oss << "Possible meshes are : ";
4117   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4118     oss << "\"" << (*it2) << "\" ";
4119   throw INTERP_KERNEL::Exception(oss.str().c_str());
4120 }
4121
4122 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4123 {
4124   if(!mesh)
4125     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4126   std::string tmp(mesh->getName());
4127   if(tmp.empty())
4128     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4129   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4130   int i=0;
4131   for(;it!=_field_per_mesh.end();it++,i++)
4132     {
4133       if((*it)->getMeshName()==tmp)
4134         return i;
4135     }
4136   int sz=_field_per_mesh.size();
4137   _field_per_mesh.resize(sz+1);
4138   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4139   return sz;
4140 }
4141
4142 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4143                                                                    MEDFileFieldGlobsReal& glob)
4144 {
4145   bool ret=false;
4146   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4147     {
4148       MEDFileFieldPerMesh *fpm(*it);
4149       if(fpm)
4150         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4151     }
4152   return ret;
4153 }
4154
4155 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4156 {
4157   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4158   std::vector< std::vector<TypeOfField> > typesF;
4159   std::vector< std::vector<std::string> > pfls,locs;
4160   std::vector< std::vector<std::pair<int,int> > > bgEnd=getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs);
4161   std::set<TypeOfField> allEnt;
4162   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4163     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4164       allEnt.insert(*it2);
4165   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4166   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4167   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4168     {
4169       std::vector< std::pair<int,int> > its;
4170       ret[i]=shallowCpy();
4171       int newLgth=ret[i]->keepOnlySpatialDiscretization(*it3,its);
4172       ret[i]->updateData(newLgth,its);
4173     }
4174   return ret;
4175 }
4176
4177 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4178 {
4179   int globalCounter=0;
4180   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4181     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4182   return globalCounter;
4183 }
4184
4185 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4186 {
4187   if(_nb_of_tuples_to_be_allocated>=0)
4188     {
4189       _nb_of_tuples_to_be_allocated=newLgth;
4190       const DataArray *oldArr(getUndergroundDataArray());
4191       if(oldArr)
4192         {
4193           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4194           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4195           setArray(newArr);
4196           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4197         }
4198       return ;
4199     }
4200   if(_nb_of_tuples_to_be_allocated==-1)
4201     return ;
4202   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4203     {
4204       const DataArray *oldArr(getUndergroundDataArray());
4205       if(!oldArr || !oldArr->isAllocated())
4206         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4207       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4208       newArr->alloc(newLgth,getNumberOfComponents());
4209       if(oldArr)
4210         newArr->copyStringInfoFrom(*oldArr);
4211       int pos=0;
4212       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4213         {
4214           if((*it).second<(*it).first)
4215             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4216           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4217           pos+=(*it).second-(*it).first;
4218         }
4219       setArray(newArr);
4220       return ;
4221     }
4222   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4223 }
4224
4225 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4226 {
4227   if(_field_per_mesh.empty())
4228     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4229   if(_field_per_mesh.size()>1)
4230     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4231   _field_per_mesh[0]->copyOptionsFrom(opts);
4232   _field_per_mesh[0]->writeLL(fid,nasc);
4233 }
4234
4235 /*!
4236  * 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.
4237  * If false is returned the memory allocation is not required.
4238  */
4239 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4240 {
4241   if(_nb_of_tuples_to_be_allocated>=0)
4242     {
4243       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4244       _nb_of_tuples_to_be_allocated=-2;
4245       return true;
4246     }
4247   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4248     return false;
4249   if(_nb_of_tuples_to_be_allocated==-1)
4250     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4251   if(_nb_of_tuples_to_be_allocated<-3)
4252     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4253   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4254 }
4255
4256 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms)
4257 {
4258   med_int numdt,numit;
4259   med_float dt;
4260   med_int nmesh;
4261   med_bool localMesh;
4262   med_int meshnumdt,meshnumit;
4263   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4264   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4265   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4266   if(_iteration!=numdt || _order!=numit)
4267     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4268   _field_per_mesh.resize(nmesh);
4269   //
4270   MEDFileMesh *mm(0);
4271   if(ms)
4272     {
4273       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4274       mm=ms->getMeshWithName(meshNameCpp);
4275     }
4276   //
4277   for(int i=0;i<nmesh;i++)
4278     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm);
4279   _nb_of_tuples_to_be_allocated=0;
4280   for(int i=0;i<nmesh;i++)
4281     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4282 }
4283
4284 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4285 {
4286   allocIfNecessaryTheArrayToReceiveDataFromFile();
4287   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4288     (*it)->loadBigArraysRecursively(fid,nasc);
4289 }
4290
4291 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4292 {
4293   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4294     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4295       (*it)->loadBigArraysRecursively(fid,nasc);
4296 }
4297
4298 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms)
4299 {
4300   loadOnlyStructureOfDataRecursively(fid,nasc,ms);
4301   loadBigArraysRecursively(fid,nasc);
4302 }
4303
4304 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4305 {
4306   DataArray *thisArr(getUndergroundDataArray());
4307   if(thisArr && thisArr->isAllocated())
4308     {
4309       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4310       thisArr->desallocate();
4311     }
4312 }
4313
4314 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4315 {
4316   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4317 }
4318
4319 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4320 {
4321   std::vector<const BigMemoryObject *> ret;
4322   if(getUndergroundDataArray())
4323     ret.push_back(getUndergroundDataArray());
4324   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4325     ret.push_back((const MEDFileFieldPerMesh *)*it);
4326   return ret;
4327 }
4328
4329 /*!
4330  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4331  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4332  * "Sort By Type"), if not, an exception is thrown. 
4333  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4334  *  \param [in] arr - the array of values.
4335  *  \param [in,out] glob - the global data where profiles and localization present in
4336  *          \a field, if any, are added.
4337  *  \throw If the name of \a field is empty.
4338  *  \throw If the data array of \a field is not set.
4339  *  \throw If \a this->_arr is already allocated but has different number of components
4340  *         than \a field.
4341  *  \throw If the underlying mesh of \a field has no name.
4342  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4343  */
4344 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4345 {
4346   const MEDCouplingMesh *mesh=field->getMesh();
4347   //
4348   TypeOfField type=field->getTypeOfField();
4349   std::vector<DataArrayInt *> dummy;
4350   int start=copyTinyInfoFrom(field,arr);
4351   int pos=addNewEntryIfNecessary(mesh);
4352   if(type!=ON_NODES)
4353     {
4354       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4355       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4356     }
4357   else
4358     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4359 }
4360
4361 /*!
4362  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4363  * of a given mesh are used as the support of the given field (a real support is not used). 
4364  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4365  * Order of underlying mesh entities of the given field specified by \a profile parameter
4366  * is not prescribed; this method permutes field values to have them sorted by element
4367  * type as required for writing to MED file. A new profile is added only if no equal
4368  * profile is missing. 
4369  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4370  *  \param [in] arrOfVals - the values of the field \a field used.
4371  *  \param [in] mesh - the supporting mesh of \a field.
4372  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4373  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4374  *  \param [in,out] glob - the global data where profiles and localization present in
4375  *          \a field, if any, are added.
4376  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4377  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4378  *  \throw If the data array of \a field is not set.
4379  *  \throw If \a this->_arr is already allocated but has different number of components
4380  *         than \a field.
4381  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4382  *  \sa setFieldNoProfileSBT()
4383  */
4384 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4385 {
4386   if(!field)
4387     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4388   if(!arrOfVals || !arrOfVals->isAllocated())
4389     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4390   TypeOfField type=field->getTypeOfField();
4391   std::vector<DataArrayInt *> idsInPflPerType;
4392   std::vector<DataArrayInt *> idsPerType;
4393   std::vector<int> code,code2;
4394   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4395   if(type!=ON_NODES)
4396     {
4397       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4398       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4399       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4400       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4401       // start of check
4402       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4403       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4404       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4405         {
4406           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4407           throw INTERP_KERNEL::Exception(oss.str().c_str());
4408         }
4409       // end of check
4410       int start=copyTinyInfoFrom(field,arrOfVals);
4411       code2=m->getDistributionOfTypes();
4412       //
4413       int pos=addNewEntryIfNecessary(m);
4414       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4415     }
4416   else
4417     {
4418       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4419         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4420       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4421       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4422       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4423       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4424         {
4425           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4426           throw INTERP_KERNEL::Exception(oss.str().c_str());
4427         }
4428       int start=copyTinyInfoFrom(field,arrOfVals);
4429       int pos=addNewEntryIfNecessary(m);
4430       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4431     }
4432 }
4433
4434 /*!
4435  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4436  */
4437 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4438 {
4439   if(_nb_of_tuples_to_be_allocated>=0)
4440     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 !");
4441   DataArray *arr(getOrCreateAndGetArray());
4442   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4443   _nb_of_tuples_to_be_allocated=-3;
4444 }
4445
4446 /*!
4447  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4448  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4449  * larger by the size of \a field. Returns an id of the first not filled
4450  * tuple of \a this->_arr.
4451  *  \param [in] field - the field to copy the info on components and the name from.
4452  *  \return int - the id of first not initialized tuple of \a this->_arr.
4453  *  \throw If the name of \a field is empty.
4454  *  \throw If the data array of \a field is not set.
4455  *  \throw If \a this->_arr is already allocated but has different number of components
4456  *         than \a field.
4457  */
4458 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4459 {
4460   if(!field)
4461     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4462   std::string name(field->getName());
4463   setName(name.c_str());
4464   setDtUnit(field->getTimeUnit());
4465   if(name.empty())
4466     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4467   if(!arr)
4468     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4469   if(!arr->isAllocated())
4470     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4471   _dt=field->getTime(_iteration,_order);
4472   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4473   if(!getOrCreateAndGetArray()->isAllocated())
4474     {
4475       allocNotFromFile(arr->getNumberOfTuples());
4476       return 0;
4477     }
4478   else
4479     {
4480       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4481       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4482       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4483       _nb_of_tuples_to_be_allocated=-3;
4484       return oldNbOfTuples;
4485     }
4486 }
4487
4488 /*!
4489  * Returns number of components in \a this field
4490  *  \return int - the number of components.
4491  */
4492 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4493 {
4494   return getOrCreateAndGetArray()->getNumberOfComponents();
4495 }
4496
4497 /*!
4498  * Change info on components in \a this.
4499  * \throw If size of \a infos is not equal to the number of components already in \a this.
4500  */
4501 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4502 {
4503   DataArray *arr=getOrCreateAndGetArray();
4504   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4505 }
4506
4507 /*!
4508  * Returns info on components of \a this field.
4509  *  \return const std::vector<std::string>& - a sequence of strings each being an
4510  *          information on _i_-th component.
4511  */
4512 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4513 {
4514   const DataArray *arr=getOrCreateAndGetArray();
4515   return arr->getInfoOnComponents();
4516 }
4517
4518 /*!
4519  * Returns a mutable info on components of \a this field.
4520  *  \return std::vector<std::string>& - a sequence of strings each being an
4521  *          information on _i_-th component.
4522  */
4523 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4524 {
4525   DataArray *arr=getOrCreateAndGetArray();
4526   return arr->getInfoOnComponents();
4527 }
4528
4529 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4530 {
4531   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4532     {
4533       const MEDFileFieldPerMesh *fpm(*it);
4534       if(!fpm)
4535         continue;
4536       if(fpm->presenceOfMultiDiscPerGeoType())
4537         return true;
4538     }
4539   return false;
4540 }
4541
4542 /*!
4543  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4544  *  \param [in] type - a spatial discretization of the new field.
4545  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4546  *  \param [in] mName - a name of the supporting mesh.
4547  *  \param [in] renumPol - specifies how to permute values of the result field according to
4548  *          the optional numbers of cells and nodes, if any. The valid values are
4549  *          - 0 - do not permute.
4550  *          - 1 - permute cells.
4551  *          - 2 - permute nodes.
4552  *          - 3 - permute cells and nodes.
4553  *
4554  *  \param [in] glob - the global data storing profiles and localization.
4555  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4556  *          caller is to delete this field using decrRef() as it is no more needed. 
4557  *  \throw If the MED file is not readable.
4558  *  \throw If there is no mesh named \a mName in the MED file.
4559  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4560  *  \throw If no field of \a this is lying on the mesh \a mName.
4561  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4562  */
4563 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4564 {
4565   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4566   if(mName.empty())
4567     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4568   else
4569     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4570   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4571 }
4572
4573 /*!
4574  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4575  *  \param [in] type - a spatial discretization of the new field.
4576  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4577  *  \param [in] renumPol - specifies how to permute values of the result field according to
4578  *          the optional numbers of cells and nodes, if any. The valid values are
4579  *          - 0 - do not permute.
4580  *          - 1 - permute cells.
4581  *          - 2 - permute nodes.
4582  *          - 3 - permute cells and nodes.
4583  *
4584  *  \param [in] glob - the global data storing profiles and localization.
4585  *  \param [in] mesh - the supporting mesh.
4586  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4587  *          caller is to delete this field using decrRef() as it is no more needed. 
4588  *  \throw If the MED file is not readable.
4589  *  \throw If no field of \a this is lying on \a mesh.
4590  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4591  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4592  */
4593 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4594 {
4595   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4596   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4597   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4598   if(meshDimRelToMax==1)
4599     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4600   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4601 }
4602
4603 /*!
4604  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4605  * given mesh. 
4606  *  \param [in] type - a spatial discretization of the new field.
4607  *  \param [in] mName - a name of the supporting mesh.
4608  *  \param [in] renumPol - specifies how to permute values of the result field according to
4609  *          the optional numbers of cells and nodes, if any. The valid values are
4610  *          - 0 - do not permute.
4611  *          - 1 - permute cells.
4612  *          - 2 - permute nodes.
4613  *          - 3 - permute cells and nodes.
4614  *
4615  *  \param [in] glob - the global data storing profiles and localization.
4616  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4617  *          caller is to delete this field using decrRef() as it is no more needed. 
4618  *  \throw If the MED file is not readable.
4619  *  \throw If there is no mesh named \a mName in the MED file.
4620  *  \throw If there are no mesh entities in the mesh.
4621  *  \throw If no field values of the given \a type are available.
4622  */
4623 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4624 {
4625   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4626   if(mName.empty())
4627     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4628   else
4629     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4630   int absDim=getDimension();
4631   int meshDimRelToMax=absDim-mm->getMeshDimension();
4632   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4633 }
4634
4635 /*!
4636  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4637  *  \param [in] type - a spatial discretization of the new field.
4638  *  \param [in] renumPol - specifies how to permute values of the result field according to
4639  *          the optional numbers of cells and nodes, if any. The valid values are
4640  *          - 0 - do not permute.
4641  *          - 1 - permute cells.
4642  *          - 2 - permute nodes.
4643  *          - 3 - permute cells and nodes.
4644  *
4645  *  \param [in] glob - the global data storing profiles and localization.
4646  *  \param [in] mesh - the supporting mesh.
4647  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4648  *         field according to \a renumPol.
4649  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4650  *         field according to \a renumPol.
4651  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4652  *          caller is to delete this field using decrRef() as it is no more needed. 
4653  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4654  *  \throw If no field of \a this is lying on \a mesh.
4655  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4656  */
4657 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4658 {
4659   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4660   int meshId=getMeshIdFromMeshName(mesh->getName());
4661   bool isPfl=false;
4662   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4663   switch(renumPol)
4664   {
4665     case 0:
4666       {
4667         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4668         return ret.retn();
4669       }
4670     case 3:
4671     case 1:
4672       {
4673         if(isPfl)
4674           throw INTERP_KERNEL::Exception(msg1);
4675         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4676         if(cellRenum)
4677           {
4678             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4679               {
4680                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4681                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4682                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4683               }
4684             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4685             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4686             std::vector<DataArray *> arrOut2(1,arrOut);
4687             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4688             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4689             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4690           }
4691         if(renumPol==1)
4692           return ret.retn();
4693       }
4694     case 2:
4695       {
4696         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4697         if(isPfl)
4698           throw INTERP_KERNEL::Exception(msg1);
4699         if(nodeRenum)
4700           {
4701             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4702               {
4703                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4704                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4705                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4706               }
4707             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4708             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4709               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4710             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4711           }
4712         return ret.retn();
4713       }
4714     default:
4715       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4716   }
4717 }
4718
4719 /*!
4720  * Returns values and a profile of the field of a given type lying on a given support.
4721  *  \param [in] type - a spatial discretization of the field.
4722  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4723  *  \param [in] mesh - the supporting mesh.
4724  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4725  *          field of interest lies on. If the field lies on all entities of the given
4726  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4727  *          using decrRef() as it is no more needed.  
4728  *  \param [in] glob - the global data storing profiles and localization.
4729  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4730  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4731  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4732  *  \throw If no field of \a this is lying on \a mesh.
4733  *  \throw If no field values of the given \a type are available.
4734  */
4735 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4736 {
4737   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4738   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4739   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4740   ret->setName(nasc.getName().c_str());
4741   return ret.retn();
4742 }
4743
4744 //= MEDFileField1TSWithoutSDA
4745
4746 /*!
4747  * Throws if a given value is not a valid (non-extended) relative dimension.
4748  *  \param [in] meshDimRelToMax - the relative dimension value.
4749  *  \throw If \a meshDimRelToMax > 0.
4750  */
4751 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4752 {
4753   if(meshDimRelToMax>0)
4754     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4755 }
4756
4757 /*!
4758  * Checks if elements of a given mesh are in the order suitable for writing 
4759  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4760  * vector describing types of elements and their number.
4761  *  \param [in] mesh - the mesh to check.
4762  *  \return std::vector<int> - a vector holding for each element type (1) item of
4763  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4764  *          These values are in full-interlace mode.
4765  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4766  */
4767 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4768 {
4769   if(!mesh)
4770     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4771   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4772   int nbOfTypes=geoTypes.size();
4773   std::vector<int> code(3*nbOfTypes);
4774   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4775   arr1->alloc(nbOfTypes,1);
4776   int *arrPtr=arr1->getPointer();
4777   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4778   for(int i=0;i<nbOfTypes;i++,it++)
4779     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4780   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4781   const int *arrPtr2=arr2->getConstPointer();
4782   int i=0;
4783   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4784     {
4785       int pos=arrPtr2[i];
4786       int nbCells=mesh->getNumberOfCellsWithType(*it);
4787       code[3*pos]=(int)(*it);
4788       code[3*pos+1]=nbCells;
4789       code[3*pos+2]=-1;//no profiles
4790     }
4791   std::vector<const DataArrayInt *> idsPerType;//no profiles
4792   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4793   if(da)
4794     {
4795       da->decrRef();
4796       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4797     }
4798   return code;
4799 }
4800
4801 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4802 {
4803   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4804 }
4805
4806 /*!
4807  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4808  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4809  * item of every of returned sequences refers to the _i_-th part of \a this field.
4810  * Thus all sequences returned by this method are of the same length equal to number
4811  * of different types of supporting entities.<br>
4812  * A field part can include sub-parts with several different spatial discretizations,
4813  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4814  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4815  * of a nested sequence corresponds to a type of spatial discretization.<br>
4816  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4817  * The overhead is due to selecting values into new instances of DataArrayDouble.
4818  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4819  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4820  *          not checked if \a mname == \c NULL).
4821  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4822  *          a field part is returned. 
4823  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4824  *          A field part can include sub-parts with several different spatial discretizations,
4825  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4826  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4827  *          This sequence is of the same length as \a types. 
4828  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4829  *          discretization. A profile name can be empty.
4830  *          Length of this and of nested sequences is the same as that of \a typesF.
4831  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4832  *          discretization. A localization name can be empty.
4833  *          Length of this and of nested sequences is the same as that of \a typesF.
4834  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4835  *          per each type of spatial discretization within one mesh entity type.
4836  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4837  *          Length of this and of nested sequences is the same as that of \a typesF.
4838  *  \throw If no field is lying on \a mname.
4839  */
4840 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
4841 {
4842   int meshId=0;
4843   if(!mname.empty())
4844     meshId=getMeshIdFromMeshName(mname);
4845   else
4846     if(_field_per_mesh.empty())
4847       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4848   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4849   int nbOfRet=ret0.size();
4850   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4851   for(int i=0;i<nbOfRet;i++)
4852     {
4853       const std::vector< std::pair<int,int> >& p=ret0[i];
4854       int nbOfRet1=p.size();
4855       ret[i].resize(nbOfRet1);
4856       for(int j=0;j<nbOfRet1;j++)
4857         {
4858           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4859           ret[i][j]=tmp;
4860         }
4861     }
4862   return ret;
4863 }
4864
4865 /*!
4866  * Returns a pointer to the underground DataArrayDouble instance. So the
4867  * caller should not decrRef() it. This method allows for a direct access to the field
4868  * values. This method is quite unusable if there is more than a nodal field or a cell
4869  * field on single geometric cell type. 
4870  *  \return DataArrayDouble * - the pointer to the field values array.
4871  */
4872 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
4873 {
4874   const DataArrayDouble *ret=_arr;
4875   if(ret)
4876     return const_cast<DataArrayDouble *>(ret);
4877   else
4878     return 0;
4879 }
4880
4881 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
4882 {
4883   return TYPE_STR;
4884 }
4885
4886 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
4887 {
4888   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4889   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4890   ret->deepCpyLeavesFrom(*this);
4891   const DataArrayDouble *arr(_arr);
4892   if(arr)
4893     {
4894       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4895       ret->setArray(arr2);
4896     }
4897   return ret.retn();
4898 }
4899
4900 /*!
4901  * Returns a pointer to the underground DataArrayDouble instance. So the
4902  * caller should not decrRef() it. This method allows for a direct access to the field
4903  * values. This method is quite unusable if there is more than a nodal field or a cell
4904  * field on single geometric cell type. 
4905  *  \return DataArrayDouble * - the pointer to the field values array.
4906  */
4907 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
4908 {
4909   return getUndergroundDataArrayDouble();
4910 }
4911
4912 /*!
4913  * Returns a pointer to the underground DataArrayDouble instance and a
4914  * sequence describing parameters of a support of each part of \a this field. The
4915  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4916  * direct access to the field values. This method is intended for the field lying on one
4917  * mesh only.
4918  *  \param [in,out] entries - the sequence describing parameters of a support of each
4919  *         part of \a this field. Each item of this sequence consists of two parts. The
4920  *         first part describes a type of mesh entity and an id of discretization of a
4921  *         current field part. The second part describes a range of values [begin,end)
4922  *         within the returned array relating to the current field part.
4923  *  \return DataArrayDouble * - the pointer to the field values array.
4924  *  \throw If the number of underlying meshes is not equal to 1.
4925  *  \throw If no field values are available.
4926  *  \sa getUndergroundDataArray()
4927  */
4928 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4929 {
4930   if(_field_per_mesh.size()!=1)
4931     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4932   if(_field_per_mesh[0]==0)
4933     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4934   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4935   return getUndergroundDataArrayDouble();
4936 }
4937
4938 /*!
4939  * Returns a pointer to the underground DataArrayDouble instance and a
4940  * sequence describing parameters of a support of each part of \a this field. The
4941  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4942  * direct access to the field values. This method is intended for the field lying on one
4943  * mesh only.
4944  *  \param [in,out] entries - the sequence describing parameters of a support of each
4945  *         part of \a this field. Each item of this sequence consists of two parts. The
4946  *         first part describes a type of mesh entity and an id of discretization of a
4947  *         current field part. The second part describes a range of values [begin,end)
4948  *         within the returned array relating to the current field part.
4949  *  \return DataArrayDouble * - the pointer to the field values array.
4950  *  \throw If the number of underlying meshes is not equal to 1.
4951  *  \throw If no field values are available.
4952  *  \sa getUndergroundDataArray()
4953  */
4954 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4955 {
4956   return getUndergroundDataArrayDoubleExt(entries);
4957 }
4958
4959 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4960 {
4961   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
4962   arr->setInfoAndChangeNbOfCompo(infos);
4963 }
4964
4965 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4966 {
4967 }
4968
4969 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
4970 {
4971   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4972   ret->deepCpyLeavesFrom(*this);
4973   return ret.retn();
4974 }
4975
4976 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
4977 {
4978   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4979   if((const DataArrayDouble *)_arr)
4980     ret->_arr=_arr->deepCpy();
4981   return ret.retn();
4982 }
4983
4984 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
4985 {
4986   if(!arr)
4987     {
4988       _nb_of_tuples_to_be_allocated=-1;
4989       _arr=0;
4990       return ;
4991     }
4992   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4993   if(!arrC)
4994     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4995   else
4996     _nb_of_tuples_to_be_allocated=-3;
4997   arrC->incrRef();
4998   _arr=arrC;
4999 }
5000
5001 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5002 {
5003   return DataArrayDouble::New();
5004 }
5005
5006 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
5007 {
5008   DataArrayDouble *ret=_arr;
5009   if(ret)
5010     return ret;
5011   _arr=DataArrayDouble::New();
5012   return _arr;
5013 }
5014
5015 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
5016 {
5017   return getOrCreateAndGetArrayDouble();
5018 }
5019
5020 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
5021 {
5022   const DataArrayDouble *ret=_arr;
5023   if(ret)
5024     return ret;
5025   DataArrayDouble *ret2=DataArrayDouble::New();
5026   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
5027   return ret2;
5028 }
5029
5030 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
5031 {
5032   return getOrCreateAndGetArrayDouble();
5033 }
5034
5035 //= MEDFileIntField1TSWithoutSDA
5036
5037 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5038 {
5039   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5040 }
5041
5042 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5043 {
5044 }
5045
5046 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5047                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5048 {
5049   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5050   arr->setInfoAndChangeNbOfCompo(infos);
5051 }
5052
5053 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5054 {
5055   return TYPE_STR;
5056 }
5057
5058 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5059 {
5060   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5061   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5062   ret->deepCpyLeavesFrom(*this);
5063   const DataArrayInt *arr(_arr);
5064   if(arr)
5065     {
5066       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
5067       ret->setArray(arr2);
5068     }
5069   return ret.retn();
5070 }
5071
5072 /*!
5073  * Returns a pointer to the underground DataArrayInt instance. So the
5074  * caller should not decrRef() it. This method allows for a direct access to the field
5075  * values. This method is quite unusable if there is more than a nodal field or a cell
5076  * field on single geometric cell type. 
5077  *  \return DataArrayInt * - the pointer to the field values array.
5078  */
5079 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5080 {
5081   return getUndergroundDataArrayInt();
5082 }
5083
5084 /*!
5085  * Returns a pointer to the underground DataArrayInt instance. So the
5086  * caller should not decrRef() it. This method allows for a direct access to the field
5087  * values. This method is quite unusable if there is more than a nodal field or a cell
5088  * field on single geometric cell type. 
5089  *  \return DataArrayInt * - the pointer to the field values array.
5090  */
5091 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5092 {
5093   const DataArrayInt *ret=_arr;
5094   if(ret)
5095     return const_cast<DataArrayInt *>(ret);
5096   else
5097     return 0;
5098 }
5099
5100 /*!
5101  * Returns a pointer to the underground DataArrayInt instance and a
5102  * sequence describing parameters of a support of each part of \a this field. The
5103  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5104  * direct access to the field values. This method is intended for the field lying on one
5105  * mesh only.
5106  *  \param [in,out] entries - the sequence describing parameters of a support of each
5107  *         part of \a this field. Each item of this sequence consists of two parts. The
5108  *         first part describes a type of mesh entity and an id of discretization of a
5109  *         current field part. The second part describes a range of values [begin,end)
5110  *         within the returned array relating to the current field part.
5111  *  \return DataArrayInt * - the pointer to the field values array.
5112  *  \throw If the number of underlying meshes is not equal to 1.
5113  *  \throw If no field values are available.
5114  *  \sa getUndergroundDataArray()
5115  */
5116 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5117 {
5118   return getUndergroundDataArrayIntExt(entries);
5119 }
5120
5121 /*!
5122  * Returns a pointer to the underground DataArrayInt instance and a
5123  * sequence describing parameters of a support of each part of \a this field. The
5124  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5125  * direct access to the field values. This method is intended for the field lying on one
5126  * mesh only.
5127  *  \param [in,out] entries - the sequence describing parameters of a support of each
5128  *         part of \a this field. Each item of this sequence consists of two parts. The
5129  *         first part describes a type of mesh entity and an id of discretization of a
5130  *         current field part. The second part describes a range of values [begin,end)
5131  *         within the returned array relating to the current field part.
5132  *  \return DataArrayInt * - the pointer to the field values array.
5133  *  \throw If the number of underlying meshes is not equal to 1.
5134  *  \throw If no field values are available.
5135  *  \sa getUndergroundDataArray()
5136  */
5137 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5138 {
5139   if(_field_per_mesh.size()!=1)
5140     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5141   if(_field_per_mesh[0]==0)
5142     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5143   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5144   return getUndergroundDataArrayInt();
5145 }
5146
5147 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5148 {
5149   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5150   ret->deepCpyLeavesFrom(*this);
5151   return ret.retn();
5152 }
5153
5154 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5155 {
5156   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5157   if((const DataArrayInt *)_arr)
5158     ret->_arr=_arr->deepCpy();
5159   return ret.retn();
5160 }
5161
5162 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5163 {
5164   if(!arr)
5165     {
5166       _nb_of_tuples_to_be_allocated=-1;
5167       _arr=0;
5168       return ;
5169     }
5170   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5171   if(!arrC)
5172     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5173   else
5174     _nb_of_tuples_to_be_allocated=-3;
5175   arrC->incrRef();
5176   _arr=arrC;
5177 }
5178
5179 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5180 {
5181   return DataArrayInt::New();
5182 }
5183
5184 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5185 {
5186   DataArrayInt *ret=_arr;
5187   if(ret)
5188     return ret;
5189   _arr=DataArrayInt::New();
5190   return _arr;
5191 }
5192
5193 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5194 {
5195   return getOrCreateAndGetArrayInt();
5196 }
5197
5198 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5199 {
5200   const DataArrayInt *ret=_arr;
5201   if(ret)
5202     return ret;
5203   DataArrayInt *ret2=DataArrayInt::New();
5204   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5205   return ret2;
5206 }
5207
5208 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5209 {
5210   return getOrCreateAndGetArrayInt();
5211 }
5212
5213 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5214 {
5215 }
5216
5217 //= MEDFileAnyTypeField1TS
5218
5219 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5220 {
5221   med_field_type typcha;
5222   //
5223   std::vector<std::string> infos;
5224   std::string dtunit,fieldName;
5225   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5226   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5227   switch(typcha)
5228   {
5229     case MED_FLOAT64:
5230       {
5231         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5232         break;
5233       }
5234     case MED_INT32:
5235       {
5236         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5237         break;
5238       }
5239     default:
5240       {
5241         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
5242         throw INTERP_KERNEL::Exception(oss.str().c_str());
5243       }
5244   }
5245   ret->setDtUnit(dtunit.c_str());
5246   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5247   //
5248   med_int numdt,numit;
5249   med_float dt;
5250   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5251   ret->setTime(numdt,numit,dt);
5252   ret->_csit=1;
5253   if(loadAll)
5254     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5255   else
5256     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5257   return ret.retn();
5258 }
5259
5260 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5261 try:MEDFileFieldGlobsReal(fileName)
5262 {
5263   MEDFileUtilities::CheckFileForRead(fileName);
5264   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5265   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5266   loadGlobals(fid);
5267 }
5268 catch(INTERP_KERNEL::Exception& e)
5269 {
5270     throw e;
5271 }
5272
5273 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5274 {
5275   med_field_type typcha;
5276   std::vector<std::string> infos;
5277   std::string dtunit;
5278   int iii=-1;
5279   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5280   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5281   switch(typcha)
5282   {
5283     case MED_FLOAT64:
5284       {
5285         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5286         break;
5287       }
5288     case MED_INT32:
5289       {
5290         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5291         break;
5292       }
5293     default:
5294       {
5295         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5296         throw INTERP_KERNEL::Exception(oss.str().c_str());
5297       }
5298   }
5299   ret->setDtUnit(dtunit.c_str());
5300   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5301   //
5302   if(nbSteps<1)
5303     {
5304       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5305       throw INTERP_KERNEL::Exception(oss.str().c_str());
5306     }
5307   //
5308   med_int numdt,numit;
5309   med_float dt;
5310   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5311   ret->setTime(numdt,numit,dt);
5312   ret->_csit=1;
5313   if(loadAll)
5314     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5315   else
5316     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5317   return ret.retn();
5318 }
5319
5320 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5321 try:MEDFileFieldGlobsReal(fileName)
5322 {
5323   MEDFileUtilities::CheckFileForRead(fileName);
5324   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5325   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5326   loadGlobals(fid);
5327 }
5328 catch(INTERP_KERNEL::Exception& e)
5329 {
5330     throw e;
5331 }
5332
5333 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5334 {
5335   if(!c)
5336     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5337   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5338     {
5339       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5340       ret->setFileName(fileName);
5341       ret->_content=c; c->incrRef();
5342       return ret.retn();
5343     }
5344   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5345     {
5346       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5347       ret->setFileName(fileName);
5348       ret->_content=c; c->incrRef();
5349       return ret.retn();
5350     }
5351   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5352 }
5353
5354 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5355 {
5356   MEDFileUtilities::CheckFileForRead(fileName);
5357   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5358   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5359   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5360   ret->loadGlobals(fid);
5361   return ret.retn();
5362 }
5363
5364 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5365 {
5366   MEDFileUtilities::CheckFileForRead(fileName);
5367   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5368   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5369   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5370   ret->loadGlobals(fid);
5371   return ret.retn();
5372 }
5373
5374 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5375 {
5376   MEDFileUtilities::CheckFileForRead(fileName);
5377   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5378   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5379   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5380   ret->loadGlobals(fid);
5381   return ret.retn();
5382 }
5383
5384 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5385 {
5386   med_field_type typcha;
5387   std::vector<std::string> infos;
5388   std::string dtunit;
5389   int iii=-1;
5390   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5391   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5392   switch(typcha)
5393   {
5394     case MED_FLOAT64:
5395       {
5396         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5397         break;
5398       }
5399     case MED_INT32:
5400       {
5401         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5402         break;
5403       }
5404     default:
5405       {
5406         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fileName,fieldName,iteration,order) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5407         throw INTERP_KERNEL::Exception(oss.str().c_str());
5408       }
5409   }
5410   ret->setDtUnit(dtunit.c_str());
5411   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5412   //
5413   bool found=false;
5414   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5415   for(int i=0;i<nbOfStep2 && !found;i++)
5416     {
5417       med_int numdt,numit;
5418       med_float dt;
5419       MEDfieldComputingStepInfo(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt);
5420       if(numdt==iteration && numit==order)
5421         {
5422           found=true;
5423           ret->_csit=i+1;
5424         }
5425       else
5426         dtits[i]=std::pair<int,int>(numdt,numit);
5427     }
5428   if(!found)
5429     {
5430       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5431       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5432         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5433       throw INTERP_KERNEL::Exception(oss.str().c_str());
5434     }
5435   if(loadAll)
5436     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5437   else
5438     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5439   return ret.retn();
5440 }
5441
5442 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5443 try:MEDFileFieldGlobsReal(fileName)
5444 {
5445   MEDFileUtilities::CheckFileForRead(fileName);
5446   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5447   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5448   loadGlobals(fid);
5449 }
5450 catch(INTERP_KERNEL::Exception& e)
5451 {
5452     throw e;
5453 }
5454
5455 /*!
5456  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5457  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5458  *
5459  * \warning this is a shallow copy constructor
5460  */
5461 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5462 {
5463   if(!shallowCopyOfContent)
5464     {
5465       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5466       otherPtr->incrRef();
5467       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5468     }
5469   else
5470     {
5471       _content=other.shallowCpy();
5472     }
5473 }
5474
5475 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, const std::string& fileName, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5476 {
5477   if(checkFieldId)
5478     {
5479       int nbFields=MEDnField(fid);
5480       if(fieldIdCFormat>=nbFields)
5481         {
5482           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5483           throw INTERP_KERNEL::Exception(oss.str().c_str());
5484         }
5485     }
5486   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5487   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5488   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5489   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5490   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5491   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5492   med_bool localMesh;
5493   int nbOfStep;
5494   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5495   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5496   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5497   infos.clear(); infos.resize(ncomp);
5498   for(int j=0;j<ncomp;j++)
5499     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5500   return nbOfStep;
5501 }
5502
5503 /*!
5504  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5505  * 
5506  * \param [out]
5507  * \return in case of success the number of time steps available for the field with name \a fieldName.
5508  */
5509 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fileName, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5510 {
5511   int nbFields=MEDnField(fid);
5512   bool found=false;
5513   std::vector<std::string> fns(nbFields);
5514   int nbOfStep2=-1;
5515   for(int i=0;i<nbFields && !found;i++)
5516     {
5517       std::string tmp;
5518       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5519       fns[i]=tmp;
5520       found=(tmp==fieldName);
5521       if(found)
5522         posCFormat=i;
5523     }
5524   if(!found)
5525     {
5526       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5527       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5528         oss << "\"" << *it << "\" ";
5529       throw INTERP_KERNEL::Exception(oss.str().c_str());
5530     }
5531   return nbOfStep2;
5532 }
5533
5534 /*!
5535  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5536  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5537  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5538  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5539  * to keep a valid instance.
5540  * 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.
5541  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5542  * 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.
5543  *
5544  * \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.
5545  * \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.
5546  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5547  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5548  * \param [in] newLocName is the new localization name.
5549  * \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.
5550  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5551  */
5552 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5553 {
5554   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5555   std::string oldPflName=disc->getProfile();
5556   std::vector<std::string> vv=getPflsReallyUsedMulti();
5557   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5558   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5559     {
5560       disc->setProfile(newPflName);
5561       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5562       pfl->setName(newPflName);
5563     }
5564   else
5565     {
5566       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5567       throw INTERP_KERNEL::Exception(oss.str().c_str());
5568     }
5569 }
5570
5571 /*!
5572  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5573  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5574  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5575  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5576  * to keep a valid instance.
5577  * 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.
5578  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5579  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5580  * 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.
5581  *
5582  * \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.
5583  * \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.
5584  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5585  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5586  * \param [in] newLocName is the new localization name.
5587  * \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.
5588  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5589  */
5590 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5591 {
5592   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5593   std::string oldLocName=disc->getLocalization();
5594   std::vector<std::string> vv=getLocsReallyUsedMulti();
5595   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5596   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5597     {
5598       disc->setLocalization(newLocName);
5599       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5600       loc.setName(newLocName);
5601     }
5602   else
5603     {
5604       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5605       throw INTERP_KERNEL::Exception(oss.str().c_str());
5606     }
5607 }
5608
5609 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5610 {
5611   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5612   if(!ret)
5613     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5614   return ret;
5615 }
5616
5617 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5618 {
5619   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5620   if(!ret)
5621     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5622   return ret;
5623 }
5624
5625 /*!
5626  * Writes \a this field into a MED file specified by its name.
5627  *  \param [in] fileName - the MED file name.
5628  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5629  * - 2 - erase; an existing file is removed.
5630  * - 1 - append; same data should not be present in an existing file.
5631  * - 0 - overwrite; same data present in an existing file is overwritten.
5632  *  \throw If the field name is not set.
5633  *  \throw If no field data is set.
5634  *  \throw If \a mode == 1 and the same data is present in an existing file.
5635  */
5636 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5637 {
5638   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5639   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5640   writeLL(fid);
5641 }
5642
5643 /*!
5644  * This method alloc the arrays and load potentially huge arrays contained in this field.
5645  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5646  * This method can be also called to refresh or reinit values from a file.
5647  * 
5648  * \throw If the fileName is not set or points to a non readable MED file.
5649  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5650  */
5651 void MEDFileAnyTypeField1TS::loadArrays()
5652 {
5653   if(getFileName().empty())
5654     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5655   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5656   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5657 }
5658
5659 /*!
5660  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5661  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5662  * this method does not throw if \a this does not come from file read.
5663  * 
5664  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5665  */
5666 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5667 {
5668   if(!getFileName().empty())
5669     {
5670       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5671       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5672     }
5673 }
5674
5675 /*!
5676  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5677  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5678  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5679  * 
5680  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5681  */
5682 void MEDFileAnyTypeField1TS::unloadArrays()
5683 {
5684   contentNotNullBase()->unloadArrays();
5685 }
5686
5687 /*!
5688  * 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.
5689  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5690  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5691  * 
5692  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5693  */
5694 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5695 {
5696   if(!getFileName().empty())
5697     contentNotNullBase()->unloadArrays();
5698 }
5699
5700 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5701 {
5702   int nbComp=getNumberOfComponents();
5703   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5704   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5705   for(int i=0;i<nbComp;i++)
5706     {
5707       std::string info=getInfo()[i];
5708       std::string c,u;
5709       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5710       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5711       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5712     }
5713   if(getName().empty())
5714     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5715   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5716   writeGlobals(fid,*this);
5717   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5718 }
5719
5720 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5721 {
5722   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5723 }
5724
5725 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5726 {
5727   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5728   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5729   return ret;
5730 }
5731
5732 /*!
5733  * Returns a string describing \a this field. This string is outputted 
5734  * by \c print Python command.
5735  */
5736 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5737 {
5738   std::ostringstream oss;
5739   contentNotNullBase()->simpleRepr(0,oss,-1);
5740   simpleReprGlobs(oss);
5741   return oss.str();
5742 }
5743
5744 /*!
5745  * This method returns all profiles whose name is non empty used.
5746  * \b WARNING If profile is used several times it will be reported \b only \b once.
5747  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5748  */
5749 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5750 {
5751   return contentNotNullBase()->getPflsReallyUsed2();
5752 }
5753
5754 /*!
5755  * This method returns all localizations whose name is non empty used.
5756  * \b WARNING If localization is used several times it will be reported \b only \b once.
5757  */
5758 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5759 {
5760   return contentNotNullBase()->getLocsReallyUsed2();
5761 }
5762
5763 /*!
5764  * This method returns all profiles whose name is non empty used.
5765  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5766  */
5767 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5768 {
5769   return contentNotNullBase()->getPflsReallyUsedMulti2();
5770 }
5771
5772 /*!
5773  * This method returns all localizations whose name is non empty used.
5774  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5775  */
5776 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5777 {
5778   return contentNotNullBase()->getLocsReallyUsedMulti2();
5779 }
5780
5781 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5782 {
5783   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5784 }
5785
5786 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5787 {
5788   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5789 }
5790
5791 int MEDFileAnyTypeField1TS::getDimension() const
5792 {
5793   return contentNotNullBase()->getDimension();
5794 }
5795
5796 int MEDFileAnyTypeField1TS::getIteration() const
5797 {
5798   return contentNotNullBase()->getIteration();
5799 }
5800
5801 int MEDFileAnyTypeField1TS::getOrder() const
5802 {
5803   return contentNotNullBase()->getOrder();
5804 }
5805
5806 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5807 {
5808   return contentNotNullBase()->getTime(iteration,order);
5809 }
5810
5811 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5812 {
5813   contentNotNullBase()->setTime(iteration,order,val);
5814 }
5815
5816 std::string MEDFileAnyTypeField1TS::getName() const
5817 {
5818   return contentNotNullBase()->getName();
5819 }
5820
5821 void MEDFileAnyTypeField1TS::setName(const std::string& name)
5822 {
5823   contentNotNullBase()->setName(name);
5824 }
5825
5826 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5827 {
5828   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5829 }
5830
5831 std::string MEDFileAnyTypeField1TS::getDtUnit() const
5832 {
5833   return contentNotNullBase()->getDtUnit();
5834 }
5835
5836 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
5837 {
5838   contentNotNullBase()->setDtUnit(dtUnit);
5839 }
5840
5841 std::string MEDFileAnyTypeField1TS::getMeshName() const
5842 {
5843   return contentNotNullBase()->getMeshName();
5844 }
5845
5846 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
5847 {
5848   contentNotNullBase()->setMeshName(newMeshName);
5849 }
5850
5851 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
5852 {
5853   return contentNotNullBase()->changeMeshNames(modifTab);
5854 }
5855
5856 int MEDFileAnyTypeField1TS::getMeshIteration() const
5857 {
5858   return contentNotNullBase()->getMeshIteration();
5859 }
5860
5861 int MEDFileAnyTypeField1TS::getMeshOrder() const
5862 {
5863   return contentNotNullBase()->getMeshOrder();
5864 }
5865
5866 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5867 {
5868   return contentNotNullBase()->getNumberOfComponents();
5869 }
5870
5871 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5872 {
5873   return contentNotNullBase()->isDealingTS(iteration,order);
5874 }
5875
5876 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5877 {
5878   return contentNotNullBase()->getDtIt();
5879 }
5880
5881 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5882 {
5883   contentNotNullBase()->fillIteration(p);
5884 }
5885
5886 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
5887 {
5888   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5889 }
5890
5891 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
5892 {
5893   contentNotNullBase()->setInfo(infos);
5894 }
5895
5896 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5897 {
5898   return contentNotNullBase()->getInfo();
5899 }
5900 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5901 {
5902   return contentNotNullBase()->getInfo();
5903 }
5904
5905 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
5906 {
5907   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
5908 }
5909
5910 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
5911 {
5912   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5913 }
5914
5915 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
5916 {
5917   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5918 }
5919
5920 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
5921 {
5922   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5923 }
5924
5925 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
5926 {
5927   return contentNotNullBase()->getTypesOfFieldAvailable();
5928 }
5929
5930 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,
5931                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
5932 {
5933   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5934 }
5935
5936 /*!
5937  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5938  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5939  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5940  */
5941 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
5942 {
5943   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5944   if(!content)
5945     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5946   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5947   std::size_t sz(contentsSplit.size());
5948   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5949   for(std::size_t i=0;i<sz;i++)
5950     {
5951       ret[i]=shallowCpy();
5952       ret[i]->_content=contentsSplit[i];
5953     }
5954   return ret;
5955 }
5956
5957 /*!
5958  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
5959  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5960  */
5961 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
5962 {
5963   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5964   if(!content)
5965     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
5966   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitDiscretizations();
5967   std::size_t sz(contentsSplit.size());
5968   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5969   for(std::size_t i=0;i<sz;i++)
5970     {
5971       ret[i]=shallowCpy();
5972       ret[i]->_content=contentsSplit[i];
5973     }
5974   return ret;
5975 }
5976
5977 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
5978 {
5979   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5980   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5981     ret->_content=_content->deepCpy();
5982   ret->deepCpyGlobs(*this);
5983   return ret.retn();
5984 }
5985
5986 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5987 {
5988   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5989 }
5990
5991 //= MEDFileField1TS
5992
5993 /*!
5994  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5995  * the first field that has been read from a specified MED file.
5996  *  \param [in] fileName - the name of the MED file to read.
5997  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5998  *          is to delete this field using decrRef() as it is no more needed.
5999  *  \throw If reading the file fails.
6000  */
6001 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6002 {
6003   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
6004   ret->contentNotNull();
6005   return ret.retn();
6006 }
6007
6008 /*!
6009  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6010  * a given field that has been read from a specified MED file.
6011  *  \param [in] fileName - the name of the MED file to read.
6012  *  \param [in] fieldName - the name of the field to read.
6013  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6014  *          is to delete this field using decrRef() as it is no more needed.
6015  *  \throw If reading the file fails.
6016  *  \throw If there is no field named \a fieldName in the file.
6017  */
6018 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6019 {
6020   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
6021   ret->contentNotNull();
6022   return ret.retn();
6023 }
6024
6025 /*!
6026  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6027  * a given field that has been read from a specified MED file.
6028  *  \param [in] fileName - the name of the MED file to read.
6029  *  \param [in] fieldName - the name of the field to read.
6030  *  \param [in] iteration - the iteration number of a required time step.
6031  *  \param [in] order - the iteration order number of required time step.
6032  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6033  *          is to delete this field using decrRef() as it is no more needed.
6034  *  \throw If reading the file fails.
6035  *  \throw If there is no field named \a fieldName in the file.
6036  *  \throw If the required time step is missing from the file.
6037  */
6038 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6039 {
6040   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6041   ret->contentNotNull();
6042   return ret.retn();
6043 }
6044
6045 /*!
6046  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6047  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6048  *
6049  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6050  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6051  * \warning this is a shallow copy constructor
6052  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6053  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6054  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6055  *          is to delete this field using decrRef() as it is no more needed.
6056  */
6057 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6058 {
6059   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6060   ret->contentNotNull();
6061   return ret.retn();
6062 }
6063
6064 /*!
6065  * Returns a new empty instance of MEDFileField1TS.
6066  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6067  *          is to delete this field using decrRef() as it is no more needed.
6068  */
6069 MEDFileField1TS *MEDFileField1TS::New()
6070 {
6071   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
6072   ret->contentNotNull();
6073   return ret.retn();
6074 }
6075
6076 /*!
6077  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6078  * following the given input policy.
6079  *
6080  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6081  *                            By default (true) the globals are deeply copied.
6082  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6083  */
6084 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6085 {
6086   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
6087   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6088   if(content)
6089     {
6090       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6091       if(!contc)
6092         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6093       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6094       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6095     }
6096   else
6097     ret=MEDFileIntField1TS::New();
6098   if(isDeepCpyGlobs)
6099     ret->deepCpyGlobs(*this);
6100   else
6101     ret->shallowCpyGlobs(*this);
6102   return ret.retn();
6103 }
6104
6105 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6106 {
6107   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6108   if(!pt)
6109     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6110   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6111   if(!ret)
6112     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 !");
6113   return ret;
6114 }
6115
6116 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6117 {
6118   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6119   if(!pt)
6120     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6121   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6122   if(!ret)
6123     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 !");
6124   return ret;
6125 }
6126
6127 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6128 {
6129   if(!f)
6130     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6131   if(!((DataArray*)arr))
6132     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6133   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6134   if(!arrOutC)
6135     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6136   f->setArray(arrOutC);
6137 }
6138
6139 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6140 {
6141   if(!((DataArray*)arr))
6142     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6143   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6144   if(!arrOutC)
6145     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6146   arrOutC->incrRef();
6147   return arrOutC;
6148 }
6149
6150 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6151 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6152 {
6153 }
6154 catch(INTERP_KERNEL::Exception& e)
6155 { throw e; }
6156
6157 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6158 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6159 {
6160 }
6161 catch(INTERP_KERNEL::Exception& e)
6162 { throw e; }
6163
6164 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6165 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6166 {
6167 }
6168 catch(INTERP_KERNEL::Exception& e)
6169 { throw e; }
6170
6171 /*!
6172  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6173  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6174  *
6175  * \warning this is a shallow copy constructor
6176  */
6177 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6178 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6179 {
6180 }
6181 catch(INTERP_KERNEL::Exception& e)
6182 { throw e; }
6183
6184 MEDFileField1TS::MEDFileField1TS()
6185 {
6186   _content=new MEDFileField1TSWithoutSDA;
6187 }
6188
6189 /*!
6190  * Returns a new MEDCouplingFieldDouble of a given type lying on
6191  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6192  * has not been constructed via file reading, an exception is thrown.
6193  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6194  *  \param [in] type - a spatial discretization of interest.
6195  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6196  *  \param [in] renumPol - specifies how to permute values of the result field according to
6197  *          the optional numbers of cells and nodes, if any. The valid values are
6198  *          - 0 - do not permute.
6199  *          - 1 - permute cells.
6200  *          - 2 - permute nodes.
6201  *          - 3 - permute cells and nodes.
6202  *
6203  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6204  *          caller is to delete this field using decrRef() as it is no more needed. 
6205  *  \throw If \a this field has not been constructed via file reading.
6206  *  \throw If the MED file is not readable.
6207  *  \throw If there is no mesh in the MED file.
6208  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6209  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6210  *  \sa getFieldOnMeshAtLevel()
6211  */
6212 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6213 {
6214   if(getFileName().empty())
6215     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6216   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6217   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6218   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6219   return ret.retn();
6220 }
6221
6222 /*!
6223  * Returns a new MEDCouplingFieldDouble of a given type lying on
6224  * the top level cells of the first mesh in MED file. If \a this field 
6225  * has not been constructed via file reading, an exception is thrown.
6226  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6227  *  \param [in] type - a spatial discretization of interest.
6228  *  \param [in] renumPol - specifies how to permute values of the result field according to
6229  *          the optional numbers of cells and nodes, if any. The valid values are
6230  *          - 0 - do not permute.
6231  *          - 1 - permute cells.
6232  *          - 2 - permute nodes.
6233  *          - 3 - permute cells and nodes.
6234  *
6235  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6236  *          caller is to delete this field using decrRef() as it is no more needed. 
6237  *  \throw If \a this field has not been constructed via file reading.
6238  *  \throw If the MED file is not readable.
6239  *  \throw If there is no mesh in the MED file.
6240  *  \throw If no field values of the given \a type.
6241  *  \throw If no field values lying on the top level support.
6242  *  \sa getFieldAtLevel()
6243  */
6244 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6245 {
6246   if(getFileName().empty())
6247     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6248   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6249   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6250   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6251   return ret.retn();
6252 }
6253
6254 /*!
6255  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6256  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6257  *  \param [in] type - a spatial discretization of the new field.
6258  *  \param [in] mesh - the supporting mesh.
6259  *  \param [in] renumPol - specifies how to permute values of the result field according to
6260  *          the optional numbers of cells and nodes, if any. The valid values are
6261  *          - 0 - do not permute.
6262  *          - 1 - permute cells.
6263  *          - 2 - permute nodes.
6264  *          - 3 - permute cells and nodes.
6265  *
6266  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6267  *          caller is to delete this field using decrRef() as it is no more needed. 
6268  *  \throw If no field of \a this is lying on \a mesh.
6269  *  \throw If the mesh is empty.
6270  *  \throw If no field values of the given \a type are available.
6271  *  \sa getFieldAtLevel()
6272  *  \sa getFieldOnMeshAtLevel() 
6273  */
6274 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6275 {
6276   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6277   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6278   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6279   return ret.retn();
6280 }
6281
6282 /*!
6283  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6284  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6285  *  \param [in] type - a spatial discretization of interest.
6286  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6287  *  \param [in] mesh - the supporting mesh.
6288  *  \param [in] renumPol - specifies how to permute values of the result field according to
6289  *          the optional numbers of cells and nodes, if any. The valid values are
6290  *          - 0 - do not permute.
6291  *          - 1 - permute cells.
6292  *          - 2 - permute nodes.
6293  *          - 3 - permute cells and nodes.
6294  *
6295  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6296  *          caller is to delete this field using decrRef() as it is no more needed. 
6297  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6298  *  \throw If no field of \a this is lying on \a mesh.
6299  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6300  *  \sa getFieldAtLevel()
6301  *  \sa getFieldOnMeshAtLevel() 
6302  */
6303 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6304 {
6305   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6306   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6307   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6308   return ret.retn();
6309 }
6310
6311 /*!
6312  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6313  * This method is called "Old" because in MED3 norm a field has only one meshName
6314  * attached, so this method is for readers of MED2 files. If \a this field 
6315  * has not been constructed via file reading, an exception is thrown.
6316  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6317  *  \param [in] type - a spatial discretization of interest.
6318  *  \param [in] mName - a name of the supporting mesh.
6319  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6320  *  \param [in] renumPol - specifies how to permute values of the result field according to
6321  *          the optional numbers of cells and nodes, if any. The valid values are
6322  *          - 0 - do not permute.
6323  *          - 1 - permute cells.
6324  *          - 2 - permute nodes.
6325  *          - 3 - permute cells and nodes.
6326  *
6327  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6328  *          caller is to delete this field using decrRef() as it is no more needed. 
6329  *  \throw If the MED file is not readable.
6330  *  \throw If there is no mesh named \a mName in the MED file.
6331  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6332  *  \throw If \a this field has not been constructed via file reading.
6333  *  \throw If no field of \a this is lying on the mesh named \a mName.
6334  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6335  *  \sa getFieldAtLevel()
6336  */
6337 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6338 {
6339   if(getFileName().empty())
6340     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6341   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6342   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6343   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6344   return ret.retn();
6345 }
6346
6347 /*!
6348  * Returns values and a profile of the field of a given type lying on a given support.
6349  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6350  *  \param [in] type - a spatial discretization of the field.
6351  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6352  *  \param [in] mesh - the supporting mesh.
6353  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6354  *          field of interest lies on. If the field lies on all entities of the given
6355  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6356  *          using decrRef() as it is no more needed.  
6357  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6358  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6359  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6360  *  \throw If no field of \a this is lying on \a mesh.
6361  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6362  */
6363 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6364 {
6365   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6366   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6367 }
6368
6369 /*!
6370  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6371  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6372  * "Sort By Type"), if not, an exception is thrown. 
6373  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6374  *  \param [in] field - the field to add to \a this.
6375  *  \throw If the name of \a field is empty.
6376  *  \throw If the data array of \a field is not set.
6377  *  \throw If the data array is already allocated but has different number of components
6378  *         than \a field.
6379  *  \throw If the underlying mesh of \a field has no name.
6380  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6381  */
6382 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6383 {
6384   setFileName("");
6385   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6386 }
6387
6388 /*!
6389  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6390  * can be an aggregation of several MEDCouplingFieldDouble instances.
6391  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6392  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6393  * and \a profile.
6394  *
6395  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6396  * A new profile is added only if no equal profile is missing.
6397  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6398  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6399  *  \param [in] mesh - the supporting mesh of \a field.
6400  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6401  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6402  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6403  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6404  *  \throw If the data array of \a field is not set.
6405  *  \throw If the data array of \a this is already allocated but has different number of
6406  *         components than \a field.
6407  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6408  *  \sa setFieldNoProfileSBT()
6409  */
6410 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6411 {
6412   setFileName("");
6413   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6414 }
6415
6416 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6417 {
6418   return new MEDFileField1TS(*this);
6419 }
6420
6421 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6422 {
6423   return contentNotNull()->getUndergroundDataArrayDouble();
6424 }
6425
6426 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6427 {
6428   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6429 }
6430
6431 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6432                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6433 {
6434   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6435 }
6436
6437 //= MEDFileIntField1TS
6438
6439 MEDFileIntField1TS *MEDFileIntField1TS::New()
6440 {
6441   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6442   ret->contentNotNull();
6443   return ret.retn();
6444 }
6445
6446 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6447 {
6448   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6449   ret->contentNotNull();
6450   return ret.retn();
6451 }
6452
6453 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6454 {
6455   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6456   ret->contentNotNull();
6457   return ret.retn();
6458 }
6459
6460 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6461 {
6462   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6463   ret->contentNotNull();
6464   return ret.retn();
6465 }
6466
6467 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6468 {
6469   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6470   ret->contentNotNull();
6471   return ret.retn();
6472 }
6473
6474 MEDFileIntField1TS::MEDFileIntField1TS()
6475 {
6476   _content=new MEDFileIntField1TSWithoutSDA;
6477 }
6478
6479 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6480 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6481 {
6482 }
6483 catch(INTERP_KERNEL::Exception& e)
6484 { throw e; }
6485
6486 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6487 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6488 {
6489 }
6490 catch(INTERP_KERNEL::Exception& e)
6491 { throw e; }
6492
6493 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6494 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6495 {
6496 }
6497 catch(INTERP_KERNEL::Exception& e)
6498 { throw e; }
6499
6500 /*!
6501  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6502  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6503  *
6504  * \warning this is a shallow copy constructor
6505  */
6506 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6507 {
6508 }
6509
6510 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6511 {
6512   return new MEDFileIntField1TS(*this);
6513 }
6514
6515 /*!
6516  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6517  * following the given input policy.
6518  *
6519  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6520  *                            By default (true) the globals are deeply copied.
6521  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6522  */
6523 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6524 {
6525   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6526   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6527   if(content)
6528     {
6529       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6530       if(!contc)
6531         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6532       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6533       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6534     }
6535   else
6536     ret=MEDFileField1TS::New();
6537   if(isDeepCpyGlobs)
6538     ret->deepCpyGlobs(*this);
6539   else
6540     ret->shallowCpyGlobs(*this);
6541   return ret.retn();
6542 }
6543
6544 /*!
6545  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6546  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6547  * "Sort By Type"), if not, an exception is thrown. 
6548  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6549  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6550  *  \param [in] arrOfVals - the values of the field \a field used.
6551  *  \throw If the name of \a field is empty.
6552  *  \throw If the data array of \a field is not set.
6553  *  \throw If the data array is already allocated but has different number of components
6554  *         than \a field.
6555  *  \throw If the underlying mesh of \a field has no name.
6556  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6557  */
6558 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6559 {
6560   setFileName("");
6561   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6562 }
6563
6564 /*!
6565  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6566  * can be an aggregation of several MEDCouplingFieldDouble instances.
6567  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6568  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6569  * and \a profile.
6570  *
6571  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6572  * A new profile is added only if no equal profile is missing.
6573  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6574  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6575  *  \param [in] arrOfVals - the values of the field \a field used.
6576  *  \param [in] mesh - the supporting mesh of \a field.
6577  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6578  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6579  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6580  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6581  *  \throw If the data array of \a field is not set.
6582  *  \throw If the data array of \a this is already allocated but has different number of
6583  *         components than \a field.
6584  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6585  *  \sa setFieldNoProfileSBT()
6586  */
6587 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6588 {
6589   setFileName("");
6590   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6591 }
6592
6593 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6594 {
6595   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6596   if(!pt)
6597     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6598   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6599   if(!ret)
6600     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 !");
6601   return ret;
6602 }
6603
6604 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6605 {
6606   if(getFileName().empty())
6607     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6608   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6609   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6610   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6611   if(!arrOutC)
6612     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6613   arrOut=arrOutC;
6614   return ret.retn();
6615 }
6616
6617 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6618 {
6619   if(!((DataArray *)arr))
6620     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6621   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6622   if(!arrC)
6623     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6624   arrC->incrRef();
6625   return arrC;
6626 }
6627
6628 /*!
6629  * Returns a new MEDCouplingFieldDouble of a given type lying on
6630  * the top level cells of the first mesh in MED file. If \a this field 
6631  * has not been constructed via file reading, an exception is thrown.
6632  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6633  *  \param [in] type - a spatial discretization of interest.
6634  *  \param [out] arrOut - the DataArrayInt containing values of field.
6635  *  \param [in] renumPol - specifies how to permute values of the result field according to
6636  *          the optional numbers of cells and nodes, if any. The valid values are
6637  *          - 0 - do not permute.
6638  *          - 1 - permute cells.
6639  *          - 2 - permute nodes.
6640  *          - 3 - permute cells and nodes.
6641  *
6642  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6643  *          caller is to delete this field using decrRef() as it is no more needed. 
6644  *  \throw If \a this field has not been constructed via file reading.
6645  *  \throw If the MED file is not readable.
6646  *  \throw If there is no mesh in the MED file.
6647  *  \throw If no field values of the given \a type.
6648  *  \throw If no field values lying on the top level support.
6649  *  \sa getFieldAtLevel()
6650  */
6651 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6652 {
6653   if(getFileName().empty())
6654     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6655   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6656   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6657   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6658   return ret.retn();
6659 }
6660
6661 /*!
6662  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6663  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6664  *  \param [in] type - a spatial discretization of the new field.
6665  *  \param [in] mesh - the supporting mesh.
6666  *  \param [out] arrOut - the DataArrayInt containing values of field.
6667  *  \param [in] renumPol - specifies how to permute values of the result field according to
6668  *          the optional numbers of cells and nodes, if any. The valid values are
6669  *          - 0 - do not permute.
6670  *          - 1 - permute cells.
6671  *          - 2 - permute nodes.
6672  *          - 3 - permute cells and nodes.
6673  *
6674  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6675  *          caller is to delete this field using decrRef() as it is no more needed. 
6676  *  \throw If no field of \a this is lying on \a mesh.
6677  *  \throw If the mesh is empty.
6678  *  \throw If no field values of the given \a type are available.
6679  *  \sa getFieldAtLevel()
6680  *  \sa getFieldOnMeshAtLevel() 
6681  */
6682 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6683 {
6684   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6685   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6686   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6687   return ret.retn();
6688 }
6689
6690 /*!
6691  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6692  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6693  *  \param [in] type - a spatial discretization of interest.
6694  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6695  *  \param [out] arrOut - the DataArrayInt containing values of field.
6696  *  \param [in] mesh - the supporting mesh.
6697  *  \param [in] renumPol - specifies how to permute values of the result field according to
6698  *          the optional numbers of cells and nodes, if any. The valid values are
6699  *          - 0 - do not permute.
6700  *          - 1 - permute cells.
6701  *          - 2 - permute nodes.
6702  *          - 3 - permute cells and nodes.
6703  *
6704  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6705  *          caller is to delete this field using decrRef() as it is no more needed. 
6706  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6707  *  \throw If no field of \a this is lying on \a mesh.
6708  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6709  *  \sa getFieldAtLevel()
6710  *  \sa getFieldOnMeshAtLevel() 
6711  */
6712 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6713 {
6714   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6715   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6716   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6717   return ret.retn();
6718 }
6719
6720 /*!
6721  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6722  * This method is called "Old" because in MED3 norm a field has only one meshName
6723  * attached, so this method is for readers of MED2 files. If \a this field 
6724  * has not been constructed via file reading, an exception is thrown.
6725  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6726  *  \param [in] type - a spatial discretization of interest.
6727  *  \param [in] mName - a name of the supporting mesh.
6728  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6729  *  \param [out] arrOut - the DataArrayInt containing values of field.
6730  *  \param [in] renumPol - specifies how to permute values of the result field according to
6731  *          the optional numbers of cells and nodes, if any. The valid values are
6732  *          - 0 - do not permute.
6733  *          - 1 - permute cells.
6734  *          - 2 - permute nodes.
6735  *          - 3 - permute cells and nodes.
6736  *
6737  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6738  *          caller is to delete this field using decrRef() as it is no more needed. 
6739  *  \throw If the MED file is not readable.
6740  *  \throw If there is no mesh named \a mName in the MED file.
6741  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6742  *  \throw If \a this field has not been constructed via file reading.
6743  *  \throw If no field of \a this is lying on the mesh named \a mName.
6744  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6745  *  \sa getFieldAtLevel()
6746  */
6747 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6748 {
6749   if(getFileName().empty())
6750     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6751   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6752   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6753   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6754   return ret.retn();
6755 }
6756
6757 /*!
6758  * Returns values and a profile of the field of a given type lying on a given support.
6759  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6760  *  \param [in] type - a spatial discretization of the field.
6761  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6762  *  \param [in] mesh - the supporting mesh.
6763  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6764  *          field of interest lies on. If the field lies on all entities of the given
6765  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6766  *          using decrRef() as it is no more needed.  
6767  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6768  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6769  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6770  *  \throw If no field of \a this is lying on \a mesh.
6771  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6772  */
6773 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6774 {
6775   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6776   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6777 }
6778
6779 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
6780 {
6781   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6782   if(!pt)
6783     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6784   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6785   if(!ret)
6786     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 !");
6787   return ret;
6788 }
6789
6790 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
6791 {
6792   return contentNotNull()->getUndergroundDataArrayInt();
6793 }
6794
6795 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6796
6797 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6798 {
6799 }
6800
6801 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
6802 {
6803 }
6804
6805 /*!
6806  * \param [in] fieldId field id in C mode
6807  */
6808 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
6809 {
6810   med_field_type typcha;
6811   std::string dtunitOut;
6812   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6813   setDtUnit(dtunitOut.c_str());
6814   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms);
6815 }
6816
6817 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
6818 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6819 {
6820   setDtUnit(dtunit.c_str());
6821   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms);
6822 }
6823 catch(INTERP_KERNEL::Exception& e)
6824 {
6825     throw e;
6826 }
6827
6828 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
6829 {
6830   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
6831   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6832     ret+=(*it).capacity();
6833   return ret;
6834 }
6835
6836 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
6837 {
6838   std::vector<const BigMemoryObject *> ret;
6839   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6840     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
6841   return ret;
6842 }
6843
6844 /*!
6845  * 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
6846  * NULL.
6847  */
6848 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
6849 {
6850   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6851   ret->setInfo(_infos);
6852   int sz=(int)_time_steps.size();
6853   for(const int *id=startIds;id!=endIds;id++)
6854     {
6855       if(*id>=0 && *id<sz)
6856         {
6857           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6858           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6859           if(tse)
6860             {
6861               tse->incrRef();
6862               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6863             }
6864           ret->pushBackTimeStep(tse2);
6865         }
6866       else
6867         {
6868           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6869           oss << " ! Should be in [0," << sz << ") !";
6870           throw INTERP_KERNEL::Exception(oss.str().c_str());
6871         }
6872     }
6873   if(ret->getNumberOfTS()>0)
6874     ret->synchronizeNameScope();
6875   ret->copyNameScope(*this);
6876   return ret.retn();
6877 }
6878
6879 /*!
6880  * 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
6881  * NULL.
6882  */
6883 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
6884 {
6885   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6886   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6887   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6888   ret->setInfo(_infos);
6889   int sz=(int)_time_steps.size();
6890   int j=bg;
6891   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6892     {
6893       if(j>=0 && j<sz)
6894         {
6895           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6896           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6897           if(tse)
6898             {
6899               tse->incrRef();
6900               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6901             }
6902           ret->pushBackTimeStep(tse2);
6903         }
6904       else
6905         {
6906           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6907           oss << " ! Should be in [0," << sz << ") !";
6908           throw INTERP_KERNEL::Exception(oss.str().c_str());
6909         }
6910     }
6911   if(ret->getNumberOfTS()>0)
6912     ret->synchronizeNameScope();
6913   ret->copyNameScope(*this);
6914   return ret.retn();
6915 }
6916
6917 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6918 {
6919   int id=0;
6920   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6921   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6922     {
6923       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6924       if(!cur)
6925         continue;
6926       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6927       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6928         ids->pushBackSilent(id);
6929     }
6930   return buildFromTimeStepIds(ids->begin(),ids->end());
6931 }
6932
6933 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6934 {
6935   int id=0;
6936   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6937   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6938     {
6939       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6940       if(!cur)
6941         continue;
6942       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6943       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6944         ids->pushBackSilent(id);
6945     }
6946   return buildFromTimeStepIds(ids->begin(),ids->end());
6947 }
6948
6949 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
6950 {
6951   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6952     {
6953       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6954       if(!cur)
6955         continue;
6956       if(cur->presenceOfMultiDiscPerGeoType())
6957         return true;
6958     }
6959   return false;
6960 }
6961
6962 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
6963 {
6964   return _infos;
6965 }
6966
6967 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
6968 {
6969   _infos=info;
6970 }
6971
6972 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
6973 {
6974   int ret=0;
6975   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6976     {
6977       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6978       if(pt->isDealingTS(iteration,order))
6979         return ret;
6980     }
6981   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6982   std::vector< std::pair<int,int> > vp=getIterations();
6983   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6984     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6985   throw INTERP_KERNEL::Exception(oss.str().c_str());
6986 }
6987
6988 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
6989 {
6990   return *_time_steps[getTimeStepPos(iteration,order)];
6991 }
6992
6993 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
6994 {
6995   return *_time_steps[getTimeStepPos(iteration,order)];
6996 }
6997
6998 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
6999 {
7000   if(_time_steps.empty())
7001     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7002   return _time_steps[0]->getMeshName();
7003 }
7004
7005 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7006 {
7007   std::string oldName(getMeshName());
7008   std::vector< std::pair<std::string,std::string> > v(1);
7009   v[0].first=oldName; v[0].second=newMeshName;
7010   changeMeshNames(v);
7011 }
7012
7013 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7014 {
7015   bool ret=false;
7016   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7017     {
7018       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7019       if(cur)
7020         ret=cur->changeMeshNames(modifTab) || ret;
7021     }
7022   return ret;
7023 }
7024
7025 /*!
7026  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7027  */
7028 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7029 {
7030   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7031 }
7032
7033 /*!
7034  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7035  */
7036 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7037 {
7038   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7039 }
7040
7041 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7042                                                                        MEDFileFieldGlobsReal& glob)
7043 {
7044   bool ret=false;
7045   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7046     {
7047       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7048       if(f1ts)
7049         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7050     }
7051   return ret;
7052 }
7053
7054 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7055 {
7056   std::string startLine(bkOffset,' ');
7057   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7058   if(fmtsId>=0)
7059     oss << " (" << fmtsId << ")";
7060   oss << " has the following name: \"" << _name << "\"." << std::endl;
7061   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7062   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7063     {
7064       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7065     }
7066   int i=0;
7067   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7068     {
7069       std::string chapter(17,'0'+i);
7070       oss << startLine << chapter << std::endl;
7071       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7072       if(cur)
7073         cur->simpleRepr(bkOffset+2,oss,i);
7074       else
7075         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7076       oss << startLine << chapter << std::endl;
7077     }
7078 }
7079
7080 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7081 {
7082   std::size_t sz=_time_steps.size();
7083   std::vector< std::pair<int,int> > ret(sz);
7084   ret1.resize(sz);
7085   for(std::size_t i=0;i<sz;i++)
7086     {
7087       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7088       if(f1ts)
7089         {
7090           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7091         }
7092       else
7093         {
7094           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7095           throw INTERP_KERNEL::Exception(oss.str().c_str());
7096         }
7097     }
7098   return ret;
7099 }
7100
7101 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7102 {
7103   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7104   if(!tse2)
7105     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7106   checkCoherencyOfType(tse2);
7107   if(_time_steps.empty())
7108     {
7109       setName(tse2->getName().c_str());
7110       setInfo(tse2->getInfo());
7111     }
7112   checkThatComponentsMatch(tse2->getInfo());
7113   _time_steps.push_back(tse);
7114 }
7115
7116 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7117 {
7118   std::size_t nbOfCompo=_infos.size();
7119   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7120     {
7121       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7122       if(cur)
7123         {
7124           if((cur->getInfo()).size()!=nbOfCompo)
7125             {
7126               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7127               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7128               throw INTERP_KERNEL::Exception(oss.str().c_str());
7129             }
7130           cur->copyNameScope(*this);
7131         }
7132     }
7133 }
7134
7135 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms)
7136 {
7137   _time_steps.resize(nbPdt);
7138   for(int i=0;i<nbPdt;i++)
7139     {
7140       std::vector< std::pair<int,int> > ts;
7141       med_int numdt=0,numo=0;
7142       med_int meshIt=0,meshOrder=0;
7143       med_float dt=0.0;
7144       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
7145       switch(fieldTyp)
7146       {
7147         case MED_FLOAT64:
7148           {
7149             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7150             break;
7151           }
7152         case MED_INT32:
7153           {
7154             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7155             break;
7156           }
7157         default:
7158           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7159       }
7160       if(loadAll)
7161         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms);
7162       else
7163         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms);
7164     }
7165 }
7166
7167 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7168 {
7169   if(_time_steps.empty())
7170     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7171   checkThatNbOfCompoOfTSMatchThis();
7172   std::vector<std::string> infos(getInfo());
7173   int nbComp=infos.size();
7174   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7175   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7176   for(int i=0;i<nbComp;i++)
7177     {
7178       std::string info=infos[i];
7179       std::string c,u;
7180       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7181       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7182       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7183     }
7184   if(_name.empty())
7185     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7186   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7187   int nbOfTS=_time_steps.size();
7188   for(int i=0;i<nbOfTS;i++)
7189     _time_steps[i]->writeLL(fid,opts,*this);
7190 }
7191
7192 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7193 {
7194   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7195     {
7196       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7197       if(elt)
7198         elt->loadBigArraysRecursively(fid,nasc);
7199     }
7200 }
7201
7202 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7203 {
7204   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7205     {
7206       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7207       if(elt)
7208         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7209     }
7210 }
7211
7212 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7213 {
7214   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7215     {
7216       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7217       if(elt)
7218         elt->unloadArrays();
7219     }
7220 }
7221
7222 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7223 {
7224   return _time_steps.size();
7225 }
7226
7227 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7228 {
7229   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7230   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7231     {
7232       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7233       if(tmp)
7234         newTS.push_back(*it);
7235     }
7236   _time_steps=newTS;
7237 }
7238
7239 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7240 {
7241   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7242   int maxId=(int)_time_steps.size();
7243   int ii=0;
7244   std::set<int> idsToDel;
7245   for(const int *id=startIds;id!=endIds;id++,ii++)
7246     {
7247       if(*id>=0 && *id<maxId)
7248         {
7249           idsToDel.insert(*id);
7250         }
7251       else
7252         {
7253           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7254           throw INTERP_KERNEL::Exception(oss.str().c_str());
7255         }
7256     }
7257   for(int iii=0;iii<maxId;iii++)
7258     if(idsToDel.find(iii)==idsToDel.end())
7259       newTS.push_back(_time_steps[iii]);
7260   _time_steps=newTS;
7261 }
7262
7263 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7264 {
7265   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7266   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7267   if(nbOfEntriesToKill==0)
7268     return ;
7269   std::size_t sz=_time_steps.size();
7270   std::vector<bool> b(sz,true);
7271   int j=bg;
7272   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7273     b[j]=false;
7274   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7275   for(std::size_t i=0;i<sz;i++)
7276     if(b[i])
7277       newTS.push_back(_time_steps[i]);
7278   _time_steps=newTS;
7279 }
7280
7281 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7282 {
7283   int ret=0;
7284   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7285   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7286     {
7287       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7288       if(tmp)
7289         {
7290           int it2,ord;
7291           tmp->getTime(it2,ord);
7292           if(it2==iteration && order==ord)
7293             return ret;
7294           else
7295             oss << "(" << it2 << ","  << ord << "), ";
7296         }
7297     }
7298   throw INTERP_KERNEL::Exception(oss.str().c_str());
7299 }
7300
7301 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7302 {
7303   int ret=0;
7304   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7305   oss.precision(15);
7306   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7307     {
7308       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7309       if(tmp)
7310         {
7311           int it2,ord;
7312           double ti=tmp->getTime(it2,ord);
7313           if(fabs(time-ti)<eps)
7314             return ret;
7315           else
7316             oss << ti << ", ";
7317         }
7318     }
7319   throw INTERP_KERNEL::Exception(oss.str().c_str());
7320 }
7321
7322 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7323 {
7324   int lgth=_time_steps.size();
7325   std::vector< std::pair<int,int> > ret(lgth);
7326   for(int i=0;i<lgth;i++)
7327     _time_steps[i]->fillIteration(ret[i]);
7328   return ret;
7329 }
7330
7331 /*!
7332  * 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'
7333  * This method returns two things.
7334  * - The absolute dimension of 'this' in first parameter. 
7335  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7336  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7337  *
7338  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7339  * Only these 3 discretizations will be taken into account here.
7340  *
7341  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7342  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7343  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7344  *
7345  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7346  * 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'.
7347  * 
7348  * Let's consider the typical following case :
7349  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7350  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7351  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7352  *   TETRA4 and SEG2
7353  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7354  *
7355  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7356  * 
7357  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7358  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7359  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7360  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7361  */
7362 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7363 {
7364   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7365 }
7366
7367 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7368 {
7369   if(pos<0 || pos>=(int)_time_steps.size())
7370     {
7371       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7372       throw INTERP_KERNEL::Exception(oss.str().c_str());
7373     }
7374   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7375   if(item==0)
7376     {
7377       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7378       oss << "\nTry to use following method eraseEmptyTS !";
7379       throw INTERP_KERNEL::Exception(oss.str().c_str());
7380     }
7381   return item;
7382 }
7383
7384 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7385 {
7386   if(pos<0 || pos>=(int)_time_steps.size())
7387     {
7388       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7389       throw INTERP_KERNEL::Exception(oss.str().c_str());
7390     }
7391   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7392   if(item==0)
7393     {
7394       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7395       oss << "\nTry to use following method eraseEmptyTS !";
7396       throw INTERP_KERNEL::Exception(oss.str().c_str());
7397     }
7398   return item;
7399 }
7400
7401 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7402 {
7403   std::vector<std::string> ret;
7404   std::set<std::string> ret2;
7405   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7406     {
7407       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7408       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7409         if(ret2.find(*it2)==ret2.end())
7410           {
7411             ret.push_back(*it2);
7412             ret2.insert(*it2);
7413           }
7414     }
7415   return ret;
7416 }
7417
7418 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7419 {
7420   std::vector<std::string> ret;
7421   std::set<std::string> ret2;
7422   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7423     {
7424       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7425       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7426         if(ret2.find(*it2)==ret2.end())
7427           {
7428             ret.push_back(*it2);
7429             ret2.insert(*it2);
7430           }
7431     }
7432   return ret;
7433 }
7434
7435 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7436 {
7437   std::vector<std::string> ret;
7438   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7439     {
7440       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7441       ret.insert(ret.end(),tmp.begin(),tmp.end());
7442     }
7443   return ret;
7444 }
7445
7446 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7447 {
7448   std::vector<std::string> ret;
7449   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7450     {
7451       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7452       ret.insert(ret.end(),tmp.begin(),tmp.end());
7453     }
7454   return ret;
7455 }
7456
7457 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7458 {
7459   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7460     (*it)->changePflsRefsNamesGen2(mapOfModif);
7461 }
7462
7463 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7464 {
7465   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7466     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7467 }
7468
7469 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7470 {
7471   int lgth=_time_steps.size();
7472   std::vector< std::vector<TypeOfField> > ret(lgth);
7473   for(int i=0;i<lgth;i++)
7474     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7475   return ret;
7476 }
7477
7478 /*!
7479  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7480  */
7481 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
7482 {
7483   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7484 }
7485
7486 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7487 {
7488   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7489   std::size_t i=0;
7490   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7491     {
7492       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7493         ret->_time_steps[i]=(*it)->deepCpy();
7494     }
7495   return ret.retn();
7496 }
7497
7498 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7499 {
7500   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7501   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7502   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7503   for(std::size_t i=0;i<sz;i++)
7504     {
7505       ret[i]=shallowCpy();
7506       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7507     }
7508   for(std::size_t i=0;i<sz2;i++)
7509     {
7510       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7511       if(ret1.size()!=sz)
7512         {
7513           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7514           throw INTERP_KERNEL::Exception(oss.str().c_str());
7515         }
7516       ts[i]=ret1;
7517     }
7518   for(std::size_t i=0;i<sz;i++)
7519     for(std::size_t j=0;j<sz2;j++)
7520       ret[i]->_time_steps[j]=ts[j][i];
7521   return ret;
7522 }
7523
7524 /*!
7525  * This method splits into discretization each time steps in \a this.
7526  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7527  */
7528 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7529 {
7530   std::size_t sz(_time_steps.size());
7531   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7532   for(std::size_t i=0;i<sz;i++)
7533     {
7534       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7535       if(!timeStep)
7536         {
7537           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7538           throw INTERP_KERNEL::Exception(oss.str().c_str());
7539         }
7540       items[i]=timeStep->splitDiscretizations();  
7541     }
7542   //
7543   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7544   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7545   std::vector< TypeOfField > types;
7546   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7547     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7548       {
7549         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7550         if(ts.size()!=1)
7551           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7552         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7553         if(it2==types.end())
7554           types.push_back(ts[0]);
7555       }
7556   ret.resize(types.size()); ret2.resize(types.size());
7557   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7558     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7559       {
7560         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7561         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7562         ret2[pos].push_back(*it1);
7563       }
7564   for(std::size_t i=0;i<types.size();i++)
7565     {
7566       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=createNew();
7567       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7568         elt->pushBackTimeStep(*it1);//also updates infos in elt
7569       ret[i]=elt;
7570       elt->MEDFileFieldNameScope::operator=(*this);
7571     }
7572   return ret;
7573 }
7574
7575 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7576 {
7577   _name=field->getName();
7578   if(_name.empty())
7579     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7580   if(!arr)
7581     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7582   _infos=arr->getInfoOnComponents();
7583 }
7584
7585 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7586 {
7587   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7588   if(_name!=field->getName())
7589     {
7590       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7591       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7592       throw INTERP_KERNEL::Exception(oss.str().c_str());
7593     }
7594   if(!arr)
7595     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7596   checkThatComponentsMatch(arr->getInfoOnComponents());
7597 }
7598
7599 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7600 {
7601   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7602   if(getInfo().size()!=compos.size())
7603     {
7604       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7605       oss << " number of components of element to append (" << compos.size() << ") !";
7606       throw INTERP_KERNEL::Exception(oss.str().c_str());
7607     }
7608   if(_infos!=compos)
7609     {
7610       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7611       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7612       oss << " But compo in input fields are : ";
7613       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7614       oss << " !";
7615       throw INTERP_KERNEL::Exception(oss.str().c_str());
7616     }
7617 }
7618
7619 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7620 {
7621   std::size_t sz=_infos.size();
7622   int j=0;
7623   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7624     {
7625       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7626       if(elt)
7627         if(elt->getInfo().size()!=sz)
7628           {
7629             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7630             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7631             throw INTERP_KERNEL::Exception(oss.str().c_str());
7632           }
7633     }
7634 }
7635
7636 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7637 {
7638   if(!field)
7639     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7640   if(!_time_steps.empty())
7641     checkCoherencyOfTinyInfo(field,arr);
7642   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7643   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7644   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7645   copyTinyInfoFrom(field,arr);
7646   _time_steps.push_back(obj);
7647 }
7648
7649 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7650 {
7651   if(!field)
7652     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7653   if(!_time_steps.empty())
7654     checkCoherencyOfTinyInfo(field,arr);
7655   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7656   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7657   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7658   copyTinyInfoFrom(field,arr);
7659   _time_steps.push_back(obj);
7660 }
7661
7662 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7663 {
7664   int sz=(int)_time_steps.size();
7665   if(i<0 || i>=sz)
7666     {
7667       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7668       throw INTERP_KERNEL::Exception(oss.str().c_str());
7669     }
7670   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7671   if(tsPtr)
7672     {
7673       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7674         {
7675           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7676           throw INTERP_KERNEL::Exception(oss.str().c_str());
7677         }
7678     }
7679   _time_steps[i]=ts;
7680 }
7681
7682 //= MEDFileFieldMultiTSWithoutSDA
7683
7684 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
7685 {
7686   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
7687 }
7688
7689 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7690 {
7691 }
7692
7693 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7694 {
7695 }
7696
7697 /*!
7698  * \param [in] fieldId field id in C mode
7699  */
7700 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
7701 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
7702 {
7703 }
7704 catch(INTERP_KERNEL::Exception& e)
7705 { throw e; }
7706
7707 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
7708 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
7709 {
7710 }
7711 catch(INTERP_KERNEL::Exception& e)
7712 { throw e; }
7713
7714 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7715 {
7716   return new MEDFileField1TSWithoutSDA;
7717 }
7718
7719 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7720 {
7721   if(!f1ts)
7722     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7723   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7724   if(!f1tsC)
7725     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7726 }
7727
7728 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7729 {
7730   return MEDFileField1TSWithoutSDA::TYPE_STR;
7731 }
7732
7733 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7734 {
7735   return new MEDFileFieldMultiTSWithoutSDA(*this);
7736 }
7737
7738 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7739 {
7740   return new MEDFileFieldMultiTSWithoutSDA;
7741 }
7742
7743 /*!
7744  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7745  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7746  */
7747 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
7748 {
7749   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7750   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7751   if(!myF1TSC)
7752     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7753   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7754 }
7755
7756 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
7757 {
7758   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7759   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7760   int i=0;
7761   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7762     {
7763       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7764       if(eltToConv)
7765         {
7766           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7767           if(!eltToConvC)
7768             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7769           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7770           ret->setIteration(i,elt);
7771         }
7772     }
7773   return ret.retn();
7774 }
7775
7776 //= MEDFileAnyTypeFieldMultiTS
7777
7778 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7779 {
7780 }
7781
7782 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7783 try:MEDFileFieldGlobsReal(fileName)
7784 {
7785   MEDFileUtilities::CheckFileForRead(fileName);
7786   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7787   _content=BuildContentFrom(fid,fileName,loadAll,ms);
7788   loadGlobals(fid);
7789 }
7790 catch(INTERP_KERNEL::Exception& e)
7791 {
7792     throw e;
7793 }
7794
7795 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7796 {
7797   med_field_type typcha;
7798   std::vector<std::string> infos;
7799   std::string dtunit;
7800   int i=-1;
7801   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7802   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7803   switch(typcha)
7804   {
7805     case MED_FLOAT64:
7806       {
7807         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7808         break;
7809       }
7810     case MED_INT32:
7811       {
7812         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7813         break;
7814       }
7815     default:
7816       {
7817         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
7818         throw INTERP_KERNEL::Exception(oss.str().c_str());
7819       }
7820   }
7821   ret->setDtUnit(dtunit.c_str());
7822   return ret.retn();
7823 }
7824
7825 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7826 {
7827   med_field_type typcha;
7828   //
7829   std::vector<std::string> infos;
7830   std::string dtunit,fieldName;
7831   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7832   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7833   switch(typcha)
7834   {
7835     case MED_FLOAT64:
7836       {
7837         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
7838         break;
7839       }
7840     case MED_INT32:
7841       {
7842         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
7843         break;
7844       }
7845     default:
7846       {
7847         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fileName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
7848         throw INTERP_KERNEL::Exception(oss.str().c_str());
7849       }
7850   }
7851   ret->setDtUnit(dtunit.c_str());
7852   return ret.retn();
7853 }
7854
7855 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
7856 {
7857   if(!c)
7858     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7859   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7860     {
7861       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7862       ret->setFileName(fileName);
7863       ret->_content=c;  c->incrRef();
7864       return ret.retn();
7865     }
7866   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7867     {
7868       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7869       ret->setFileName(fileName);
7870       ret->_content=c;  c->incrRef();
7871       return ret.retn();
7872     }
7873   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7874 }
7875
7876 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7877 try:MEDFileFieldGlobsReal(fileName)
7878 {
7879   MEDFileUtilities::CheckFileForRead(fileName);
7880   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7881   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
7882   loadGlobals(fid);
7883 }
7884 catch(INTERP_KERNEL::Exception& e)
7885 {
7886     throw e;
7887 }
7888
7889 //= MEDFileIntFieldMultiTSWithoutSDA
7890
7891 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
7892 {
7893   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
7894 }
7895
7896 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7897 {
7898 }
7899
7900 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7901 {
7902 }
7903
7904 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
7905 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
7906 {
7907 }
7908 catch(INTERP_KERNEL::Exception& e)
7909 { throw e; }
7910
7911 /*!
7912  * \param [in] fieldId field id in C mode
7913  */
7914 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
7915 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
7916 {
7917 }
7918 catch(INTERP_KERNEL::Exception& e)
7919 { throw e; }
7920
7921 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7922 {
7923   return new MEDFileIntField1TSWithoutSDA;
7924 }
7925
7926 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7927 {
7928   if(!f1ts)
7929     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7930   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7931   if(!f1tsC)
7932     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7933 }
7934
7935 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
7936 {
7937   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7938 }
7939
7940 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
7941 {
7942   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7943 }
7944
7945 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
7946 {
7947   return new MEDFileIntFieldMultiTSWithoutSDA;
7948 }
7949
7950 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
7951 {
7952   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7953   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7954   int i=0;
7955   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7956     {
7957       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7958       if(eltToConv)
7959         {
7960           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7961           if(!eltToConvC)
7962             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7963           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7964           ret->setIteration(i,elt);
7965         }
7966     }
7967   return ret.retn();
7968 }
7969
7970 //= MEDFileAnyTypeFieldMultiTS
7971
7972 /*!
7973  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7974  * that has been read from a specified MED file.
7975  *  \param [in] fileName - the name of the MED file to read.
7976  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7977  *          is to delete this field using decrRef() as it is no more needed.
7978  *  \throw If reading the file fails.
7979  */
7980 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
7981 {
7982   MEDFileUtilities::CheckFileForRead(fileName);
7983   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7984   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
7985   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7986   ret->loadGlobals(fid);
7987   return ret.retn();
7988 }
7989
7990 /*!
7991  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7992  * that has been read from a specified MED file.
7993  *  \param [in] fileName - the name of the MED file to read.
7994  *  \param [in] fieldName - the name of the field to read.
7995  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7996  *          is to delete this field using decrRef() as it is no more needed.
7997  *  \throw If reading the file fails.
7998  *  \throw If there is no field named \a fieldName in the file.
7999  */
8000 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8001 {
8002   MEDFileUtilities::CheckFileForRead(fileName);
8003   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8004   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
8005   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8006   ret->loadGlobals(fid);
8007   return ret.retn();
8008 }
8009
8010 /*!
8011  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8012  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8013  *
8014  * \warning this is a shallow copy constructor
8015  */
8016 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8017 {
8018   if(!shallowCopyOfContent)
8019     {
8020       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8021       otherPtr->incrRef();
8022       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8023     }
8024   else
8025     {
8026       _content=other.shallowCpy();
8027     }
8028 }
8029
8030 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8031 {
8032   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8033   if(!ret)
8034     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8035   return ret;
8036 }
8037
8038 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8039 {
8040   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8041   if(!ret)
8042     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8043   return ret;
8044 }
8045
8046 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8047 {
8048   return contentNotNullBase()->getPflsReallyUsed2();
8049 }
8050
8051 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8052 {
8053   return contentNotNullBase()->getLocsReallyUsed2();
8054 }
8055
8056 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8057 {
8058   return contentNotNullBase()->getPflsReallyUsedMulti2();
8059 }
8060
8061 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8062 {
8063   return contentNotNullBase()->getLocsReallyUsedMulti2();
8064 }
8065
8066 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8067 {
8068   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8069 }
8070
8071 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8072 {
8073   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8074 }
8075
8076 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8077 {
8078   return contentNotNullBase()->getNumberOfTS();
8079 }
8080
8081 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8082 {
8083   contentNotNullBase()->eraseEmptyTS();
8084 }
8085
8086 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8087 {
8088   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8089 }
8090
8091 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8092 {
8093   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8094 }
8095
8096 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8097 {
8098   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8099   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8100   ret->_content=c;
8101   return ret.retn();
8102 }
8103
8104 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8105 {
8106   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8107   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8108   ret->_content=c;
8109   return ret.retn();
8110 }
8111
8112 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8113 {
8114   return contentNotNullBase()->getIterations();
8115 }
8116
8117 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8118 {
8119   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8120     pushBackTimeStep(*it);
8121 }
8122
8123 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8124 {
8125   if(!f1ts)
8126     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8127   checkCoherencyOfType(f1ts);
8128   f1ts->incrRef();
8129   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8130   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8131   c->incrRef();
8132   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8133   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8134     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8135   _content->pushBackTimeStep(cSafe);
8136   appendGlobs(*f1ts,1e-12);
8137 }
8138
8139 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8140 {
8141   contentNotNullBase()->synchronizeNameScope();
8142 }
8143
8144 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8145 {
8146   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8147 }
8148
8149 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8150 {
8151   return contentNotNullBase()->getPosGivenTime(time,eps);
8152 }
8153
8154 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8155 {
8156   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8157 }
8158
8159 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8160 {
8161   return contentNotNullBase()->getTypesOfFieldAvailable();
8162 }
8163
8164 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
8165 {
8166   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8167 }
8168
8169 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8170 {
8171   return contentNotNullBase()->getName();
8172 }
8173
8174 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8175 {
8176   contentNotNullBase()->setName(name);
8177 }
8178
8179 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8180 {
8181   return contentNotNullBase()->getDtUnit();
8182 }
8183
8184 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8185 {
8186   contentNotNullBase()->setDtUnit(dtUnit);
8187 }
8188
8189 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8190 {
8191   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8192 }
8193
8194 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8195 {
8196   return contentNotNullBase()->getTimeSteps(ret1);
8197 }
8198
8199 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8200 {
8201   return contentNotNullBase()->getMeshName();
8202 }
8203
8204 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8205 {
8206   contentNotNullBase()->setMeshName(newMeshName);
8207 }
8208
8209 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8210 {
8211   return contentNotNullBase()->changeMeshNames(modifTab);
8212 }
8213
8214 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8215 {
8216   return contentNotNullBase()->getInfo();
8217 }
8218
8219 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8220 {
8221   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8222 }
8223
8224 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8225 {
8226   return contentNotNullBase()->setInfo(info);
8227 }
8228
8229 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8230 {
8231   const std::vector<std::string> ret=getInfo();
8232   return (int)ret.size();
8233 }
8234
8235 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8236 {
8237   writeGlobals(fid,*this);
8238   contentNotNullBase()->writeLL(fid,*this);
8239 }
8240
8241 /*!
8242  * Writes \a this field into a MED file specified by its name.
8243  *  \param [in] fileName - the MED file name.
8244  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8245  * - 2 - erase; an existing file is removed.
8246  * - 1 - append; same data should not be present in an existing file.
8247  * - 0 - overwrite; same data present in an existing file is overwritten.
8248  *  \throw If the field name is not set.
8249  *  \throw If no field data is set.
8250  *  \throw If \a mode == 1 and the same data is present in an existing file.
8251  */
8252 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8253 {
8254   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8255   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8256   writeLL(fid);
8257 }
8258
8259 /*!
8260  * This method alloc the arrays and load potentially huge arrays contained in this field.
8261  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8262  * This method can be also called to refresh or reinit values from a file.
8263  * 
8264  * \throw If the fileName is not set or points to a non readable MED file.
8265  */
8266 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8267 {
8268   if(getFileName().empty())
8269     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8270   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8271   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8272 }
8273
8274 /*!
8275  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8276  * But once data loaded once, this method does nothing.
8277  * 
8278  * \throw If the fileName is not set or points to a non readable MED file.
8279  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8280  */
8281 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8282 {
8283   if(!getFileName().empty())
8284     {
8285       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8286       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8287     }
8288 }
8289
8290 /*!
8291  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8292  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8293  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8294  * 
8295  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8296  */
8297 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8298 {
8299   contentNotNullBase()->unloadArrays();
8300 }
8301
8302 /*!
8303  * 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.
8304  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8305  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8306  * 
8307  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8308  */
8309 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8310 {
8311   if(!getFileName().empty())
8312     contentNotNullBase()->unloadArrays();
8313 }
8314
8315 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8316 {
8317   std::ostringstream oss;
8318   contentNotNullBase()->simpleRepr(0,oss,-1);
8319   simpleReprGlobs(oss);
8320   return oss.str();
8321 }
8322
8323 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8324 {
8325   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8326 }
8327
8328 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8329 {
8330   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8331   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8332   return ret;
8333 }
8334
8335 /*!
8336  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8337  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8338  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8339  */
8340 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8341 {
8342   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8343   if(!content)
8344     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8345   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8346   std::size_t sz(contentsSplit.size());
8347   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8348   for(std::size_t i=0;i<sz;i++)
8349     {
8350       ret[i]=shallowCpy();
8351       ret[i]->_content=contentsSplit[i];
8352     }
8353   return ret;
8354 }
8355
8356 /*!
8357  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8358  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8359  */
8360 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8361 {
8362   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8363   if(!content)
8364     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8365   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitDiscretizations();
8366   std::size_t sz(contentsSplit.size());
8367   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8368   for(std::size_t i=0;i<sz;i++)
8369     {
8370       ret[i]=shallowCpy();
8371       ret[i]->_content=contentsSplit[i];
8372     }
8373   return ret;
8374 }
8375
8376 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8377 {
8378   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8379   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8380     ret->_content=_content->deepCpy();
8381   ret->deepCpyGlobs(*this);
8382   return ret.retn();
8383 }
8384
8385 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8386 {
8387   return _content;
8388 }
8389
8390 /*!
8391  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8392  *  \param [in] iteration - the iteration number of a required time step.
8393  *  \param [in] order - the iteration order number of required time step.
8394  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8395  *          delete this field using decrRef() as it is no more needed.
8396  *  \throw If there is no required time step in \a this field.
8397  */
8398 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8399 {
8400   int pos=getPosOfTimeStep(iteration,order);
8401   return getTimeStepAtPos(pos);
8402 }
8403
8404 /*!
8405  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8406  *  \param [in] time - the time of the time step of interest.
8407  *  \param [in] eps - a precision used to compare time values.
8408  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8409  *          delete this field using decrRef() as it is no more needed.
8410  *  \throw If there is no required time step in \a this field.
8411  */
8412 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8413 {
8414   int pos=getPosGivenTime(time,eps);
8415   return getTimeStepAtPos(pos);
8416 }
8417
8418 /*!
8419  * 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.
8420  * The float64 value of time attached to the pair of integers are not considered here.
8421  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8422  *
8423  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8424  * \throw If there is a null pointer in \a vectFMTS.
8425  */
8426 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8427 {
8428   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8429   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8430   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8431   while(!lstFMTS.empty())
8432     {
8433       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8434       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8435       if(!curIt)
8436         throw INTERP_KERNEL::Exception(msg);
8437       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8438       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8439       elt.push_back(curIt); it=lstFMTS.erase(it);
8440       while(it!=lstFMTS.end())
8441         {
8442           curIt=*it;
8443           if(!curIt)
8444             throw INTERP_KERNEL::Exception(msg);
8445           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8446           if(refIts==curIts)
8447             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8448           else
8449             it++;
8450         }
8451       ret.push_back(elt);
8452     }
8453   return ret;
8454 }
8455
8456 /*!
8457  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8458  * All returned instances in a subvector can be safely loaded, rendered along time
8459  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8460  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8461  * 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).
8462  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8463  * 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.
8464  *
8465  * \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().
8466  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8467  * \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.
8468  * \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.
8469  *
8470  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8471  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8472  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8473  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8474  * \throw If mesh is null.
8475  * \throw If an element in \a vectFMTS is null.
8476  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8477  */
8478 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8479 {
8480   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8481   if(!mesh)
8482     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8483   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8484   if(vectFMTS.empty())
8485     return ret;
8486   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8487   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8488   if(!frstElt)
8489     throw INTERP_KERNEL::Exception(msg);
8490   std::size_t i=0;
8491   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8492   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8493   for(;it!=vectFMTS.end();it++,i++)
8494     {
8495       if(!(*it))
8496         throw INTERP_KERNEL::Exception(msg);
8497       TypeOfField tof0,tof1;
8498       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8499         {
8500           if(tof1!=ON_NODES)
8501             vectFMTSNotNodes.push_back(*it);
8502           else
8503             vectFMTSNodes.push_back(*it);
8504         }
8505       else
8506         vectFMTSNotNodes.push_back(*it);
8507     }
8508   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8509   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8510   ret=retCell;
8511   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8512     {
8513       i=0;
8514       bool isFetched(false);
8515       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8516         {
8517           if((*it0).empty())
8518             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8519           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8520             { ret[i].push_back(*it2); isFetched=true; }
8521         }
8522       if(!isFetched)
8523         {
8524           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8525           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8526           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8527         }
8528     }
8529   fsc=cmps;
8530   return ret;
8531 }
8532
8533 /*!
8534  * 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.
8535  * \param [out] cmps - same size than the returned vector.
8536  */
8537 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8538 {
8539   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8540   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8541   while(!lstFMTS.empty())
8542     {
8543       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8544       MEDFileAnyTypeFieldMultiTS *ref(*it);
8545       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8546       elt.push_back(ref); it=lstFMTS.erase(it);
8547       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8548       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8549       while(it!=lstFMTS.end())
8550         {
8551           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8552           if(cmp->isEqual(curIt))
8553             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8554           else
8555             it++;
8556         }
8557       ret.push_back(elt); cmps.push_back(cmp);
8558     }
8559   return ret;
8560 }
8561
8562 /*!
8563  * 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.
8564  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8565  *
8566  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8567  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8568  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8569  * \thorw If \a f0 and \a f1 do not have the same times steps.
8570  * \throw If mesh is null.
8571  * \throw If \a f0 or \a f1 is null.
8572  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8573  */
8574 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8575 {
8576   if(!mesh)
8577     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8578   if(!f0 || !f1)
8579     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8580   if(f0->getMeshName()!=mesh->getName())
8581     {
8582       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8583       throw INTERP_KERNEL::Exception(oss.str().c_str());
8584     }
8585   if(f1->getMeshName()!=mesh->getName())
8586     {
8587       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8588       throw INTERP_KERNEL::Exception(oss.str().c_str());
8589     }
8590   int nts=f0->getNumberOfTS();
8591   if(nts!=f1->getNumberOfTS())
8592     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8593   if(nts==0)
8594     return nts;
8595   for(int i=0;i<nts;i++)
8596     {
8597       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8598       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8599       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8600       if(tofs0.size()!=1 || tofs1.size()!=1)
8601         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8602       if(i!=0)
8603         {
8604           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8605             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8606         }
8607       else
8608         { tof0=tofs0[0]; tof1=tofs1[0]; }
8609       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8610         {
8611           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() << ") !";
8612           throw INTERP_KERNEL::Exception(oss.str().c_str());
8613         }
8614       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8615         {
8616           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() << ") !";
8617           throw INTERP_KERNEL::Exception(oss.str().c_str());
8618         }
8619       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8620         {
8621           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() << ") !";
8622           throw INTERP_KERNEL::Exception(oss.str().c_str());
8623         }
8624     }
8625   return nts;
8626 }
8627
8628 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8629 {
8630   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8631 }
8632
8633 //= MEDFileFieldMultiTS
8634
8635 /*!
8636  * Returns a new empty instance of MEDFileFieldMultiTS.
8637  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8638  *          is to delete this field using decrRef() as it is no more needed.
8639  */
8640 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8641 {
8642   return new MEDFileFieldMultiTS;
8643 }
8644
8645 /*!
8646  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8647  * that has been read from a specified MED file.
8648  *  \param [in] fileName - the name of the MED file to read.
8649  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8650  *          is to delete this field using decrRef() as it is no more needed.
8651  *  \throw If reading the file fails.
8652  */
8653 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8654 {
8655   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8656   ret->contentNotNull();//to check that content type matches with \a this type.
8657   return ret.retn();
8658 }
8659
8660 /*!
8661  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8662  * that has been read from a specified MED file.
8663  *  \param [in] fileName - the name of the MED file to read.
8664  *  \param [in] fieldName - the name of the field to read.
8665  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8666  *          is to delete this field using decrRef() as it is no more needed.
8667  *  \throw If reading the file fails.
8668  *  \throw If there is no field named \a fieldName in the file.
8669  */
8670 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8671 {
8672   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
8673   ret->contentNotNull();//to check that content type matches with \a this type.
8674   return ret.retn();
8675 }
8676
8677 /*!
8678  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8679  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8680  *
8681  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8682  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8683  * \warning this is a shallow copy constructor
8684  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8685  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8686  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8687  *          is to delete this field using decrRef() as it is no more needed.
8688  */
8689 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8690 {
8691   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8692 }
8693
8694 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8695 {
8696   return new MEDFileFieldMultiTS(*this);
8697 }
8698
8699 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8700 {
8701   if(!f1ts)
8702     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8703   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8704   if(!f1tsC)
8705     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8706 }
8707
8708 /*!
8709  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8710  * following the given input policy.
8711  *
8712  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8713  *                            By default (true) the globals are deeply copied.
8714  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8715  */
8716 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8717 {
8718   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8719   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8720   if(content)
8721     {
8722       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8723       if(!contc)
8724         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8725       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8726       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8727     }
8728   else
8729     ret=MEDFileIntFieldMultiTS::New();
8730   if(isDeepCpyGlobs)
8731     ret->deepCpyGlobs(*this);
8732   else
8733     ret->shallowCpyGlobs(*this);
8734   return ret.retn();
8735 }
8736
8737 /*!
8738  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8739  *  \param [in] pos - a time step id.
8740  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8741  *          delete this field using decrRef() as it is no more needed.
8742  *  \throw If \a pos is not a valid time step id.
8743  */
8744 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
8745 {
8746   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8747   if(!item)
8748     {
8749       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8750       throw INTERP_KERNEL::Exception(oss.str().c_str());
8751     }
8752   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8753   if(itemC)
8754     {
8755       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8756       ret->shallowCpyGlobs(*this);
8757       return ret.retn();
8758     }
8759   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8760   throw INTERP_KERNEL::Exception(oss.str().c_str());
8761 }
8762
8763 /*!
8764  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8765  * mesh entities of a given dimension of the first mesh in MED file.
8766  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8767  *  \param [in] type - a spatial discretization of interest.
8768  *  \param [in] iteration - the iteration number of a required time step.
8769  *  \param [in] order - the iteration order number of required time step.
8770  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8771  *  \param [in] renumPol - specifies how to permute values of the result field according to
8772  *          the optional numbers of cells and nodes, if any. The valid values are
8773  *          - 0 - do not permute.
8774  *          - 1 - permute cells.
8775  *          - 2 - permute nodes.
8776  *          - 3 - permute cells and nodes.
8777  *
8778  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8779  *          caller is to delete this field using decrRef() as it is no more needed. 
8780  *  \throw If the MED file is not readable.
8781  *  \throw If there is no mesh in the MED file.
8782  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8783  *  \throw If no field values of the required parameters are available.
8784  */
8785 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
8786 {
8787   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8788   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8789   if(!myF1TSC)
8790     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8791   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8792   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8793   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8794   return ret.retn();
8795 }
8796
8797 /*!
8798  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8799  * the top level cells of the first mesh in MED file.
8800  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8801  *  \param [in] type - a spatial discretization of interest.
8802  *  \param [in] iteration - the iteration number of a required time step.
8803  *  \param [in] order - the iteration order number of required time step.
8804  *  \param [in] renumPol - specifies how to permute values of the result field according to
8805  *          the optional numbers of cells and nodes, if any. The valid values are
8806  *          - 0 - do not permute.
8807  *          - 1 - permute cells.
8808  *          - 2 - permute nodes.
8809  *          - 3 - permute cells and nodes.
8810  *
8811  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8812  *          caller is to delete this field using decrRef() as it is no more needed. 
8813  *  \throw If the MED file is not readable.
8814  *  \throw If there is no mesh in the MED file.
8815  *  \throw If no field values of the required parameters are available.
8816  */
8817 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
8818 {
8819   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8820   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8821   if(!myF1TSC)
8822     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8823   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8824   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8825   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8826   return ret.retn();
8827 }
8828
8829 /*!
8830  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8831  * a given support.
8832  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8833  *  \param [in] type - a spatial discretization of interest.
8834  *  \param [in] iteration - the iteration number of a required time step.
8835  *  \param [in] order - the iteration order number of required time step.
8836  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8837  *  \param [in] mesh - the supporting mesh.
8838  *  \param [in] renumPol - specifies how to permute values of the result field according to
8839  *          the optional numbers of cells and nodes, if any. The valid values are
8840  *          - 0 - do not permute.
8841  *          - 1 - permute cells.
8842  *          - 2 - permute nodes.
8843  *          - 3 - permute cells and nodes.
8844  *
8845  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8846  *          caller is to delete this field using decrRef() as it is no more needed. 
8847  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8848  *  \throw If no field of \a this is lying on \a mesh.
8849  *  \throw If no field values of the required parameters are available.
8850  */
8851 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
8852 {
8853   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8854   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8855   if(!myF1TSC)
8856     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8857   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8858   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8859   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8860   return ret.retn();
8861 }
8862
8863 /*!
8864  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8865  * given support. 
8866  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8867  *  \param [in] type - a spatial discretization of the new field.
8868  *  \param [in] iteration - the iteration number of a required time step.
8869  *  \param [in] order - the iteration order number of required time step.
8870  *  \param [in] mesh - the supporting mesh.
8871  *  \param [in] renumPol - specifies how to permute values of the result field according to
8872  *          the optional numbers of cells and nodes, if any. The valid values are
8873  *          - 0 - do not permute.
8874  *          - 1 - permute cells.
8875  *          - 2 - permute nodes.
8876  *          - 3 - permute cells and nodes.
8877  *
8878  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8879  *          caller is to delete this field using decrRef() as it is no more needed. 
8880  *  \throw If no field of \a this is lying on \a mesh.
8881  *  \throw If no field values of the required parameters are available.
8882  */
8883 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
8884 {
8885   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8886   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8887   if(!myF1TSC)
8888     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8889   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8890   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8891   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8892   return ret.retn();
8893 }
8894
8895 /*!
8896  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8897  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8898  * This method is useful for MED2 file format when field on different mesh was autorized.
8899  */
8900 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
8901 {
8902   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8903   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8904   if(!myF1TSC)
8905     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8906   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8907   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8908   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8909   return ret.retn();
8910 }
8911
8912 /*!
8913  * Returns values and a profile of the field of a given type, of a given time step,
8914  * lying on a given support.
8915  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8916  *  \param [in] type - a spatial discretization of the field.
8917  *  \param [in] iteration - the iteration number of a required time step.
8918  *  \param [in] order - the iteration order number of required time step.
8919  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8920  *  \param [in] mesh - the supporting mesh.
8921  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8922  *          field of interest lies on. If the field lies on all entities of the given
8923  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8924  *          using decrRef() as it is no more needed.  
8925  *  \param [in] glob - the global data storing profiles and localization.
8926  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8927  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8928  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8929  *  \throw If no field of \a this is lying on \a mesh.
8930  *  \throw If no field values of the required parameters are available.
8931  */
8932 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
8933 {
8934   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8935   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8936   if(!myF1TSC)
8937     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8938   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8939   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8940 }
8941
8942 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
8943 {
8944   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8945   if(!pt)
8946     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8947   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8948   if(!ret)
8949     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 !");
8950   return ret;
8951 }
8952
8953 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
8954 {
8955   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8956   if(!pt)
8957     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8958   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8959   if(!ret)
8960     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 !");
8961   return ret;
8962 }
8963
8964 /*!
8965  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8966  * the given field is checked if its elements are sorted suitable for writing to MED file
8967  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8968  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8969  *  \param [in] field - the field to add to \a this.
8970  *  \throw If the name of \a field is empty.
8971  *  \throw If the data array of \a field is not set.
8972  *  \throw If existing time steps have different name or number of components than \a field.
8973  *  \throw If the underlying mesh of \a field has no name.
8974  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8975  */
8976 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
8977 {
8978   const DataArrayDouble *arr=0;
8979   if(field)
8980     arr=field->getArray();
8981   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8982 }
8983
8984 /*!
8985  * Adds a MEDCouplingFieldDouble to \a this as another time step.
8986  * The mesh support of input parameter \a field is ignored here, it can be NULL.
8987  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
8988  * and \a profile.
8989  *
8990  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
8991  * A new profile is added only if no equal profile is missing.
8992  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8993  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
8994  *  \param [in] mesh - the supporting mesh of \a field.
8995  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
8996  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8997  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8998  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8999  *  \throw If the data array of \a field is not set.
9000  *  \throw If the data array of \a this is already allocated but has different number of
9001  *         components than \a field.
9002  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9003  *  \sa setFieldNoProfileSBT()
9004  */
9005 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9006 {
9007   const DataArrayDouble *arr=0;
9008   if(field)
9009     arr=field->getArray();
9010   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9011 }
9012
9013 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9014 {
9015   _content=new MEDFileFieldMultiTSWithoutSDA;
9016 }
9017
9018 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9019 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9020 {
9021 }
9022 catch(INTERP_KERNEL::Exception& e)
9023 { throw e; }
9024
9025 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
9026 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
9027 {
9028 }
9029 catch(INTERP_KERNEL::Exception& e)
9030 { throw e; }
9031
9032 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9033 {
9034 }
9035
9036 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
9037 {
9038   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9039 }
9040
9041 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9042 {
9043   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9044 }
9045
9046 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9047 {
9048   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9049 }
9050
9051 //= MEDFileAnyTypeFieldMultiTSIterator
9052
9053 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9054 {
9055   if(fmts)
9056     {
9057       fmts->incrRef();
9058       _nb_iter=fmts->getNumberOfTS();
9059     }
9060 }
9061
9062 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9063 {
9064 }
9065
9066 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9067 {
9068   if(_iter_id<_nb_iter)
9069     {
9070       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9071       if(fmts)
9072         return fmts->getTimeStepAtPos(_iter_id++);
9073       else
9074         return 0;
9075     }
9076   else
9077     return 0;
9078 }
9079
9080 //= MEDFileIntFieldMultiTS
9081
9082 /*!
9083  * Returns a new empty instance of MEDFileFieldMultiTS.
9084  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9085  *          is to delete this field using decrRef() as it is no more needed.
9086  */
9087 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9088 {
9089   return new MEDFileIntFieldMultiTS;
9090 }
9091
9092 /*!
9093  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9094  * that has been read from a specified MED file.
9095  *  \param [in] fileName - the name of the MED file to read.
9096  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9097  *          is to delete this field using decrRef() as it is no more needed.
9098  *  \throw If reading the file fails.
9099  */
9100 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9101 {
9102   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9103   ret->contentNotNull();//to check that content type matches with \a this type.
9104   return ret.retn();
9105 }
9106
9107 /*!
9108  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9109  * that has been read from a specified MED file.
9110  *  \param [in] fileName - the name of the MED file to read.
9111  *  \param [in] fieldName - the name of the field to read.
9112  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9113  *          is to delete this field using decrRef() as it is no more needed.
9114  *  \throw If reading the file fails.
9115  *  \throw If there is no field named \a fieldName in the file.
9116  */
9117 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9118 {
9119   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9120   ret->contentNotNull();//to check that content type matches with \a this type.
9121   return ret.retn();
9122 }
9123
9124 /*!
9125  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9126  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9127  *
9128  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9129  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9130  * \warning this is a shallow copy constructor
9131  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9132  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9133  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9134  *          is to delete this field using decrRef() as it is no more needed.
9135  */
9136 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9137 {
9138   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9139 }
9140
9141 /*!
9142  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9143  * following the given input policy.
9144  *
9145  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9146  *                            By default (true) the globals are deeply copied.
9147  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9148  */
9149 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9150 {
9151   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9152   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9153   if(content)
9154     {
9155       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9156       if(!contc)
9157         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9158       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9159       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9160     }
9161   else
9162     ret=MEDFileFieldMultiTS::New();
9163   if(isDeepCpyGlobs)
9164     ret->deepCpyGlobs(*this);
9165   else
9166     ret->shallowCpyGlobs(*this);
9167   return ret.retn();
9168 }
9169
9170 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9171 {
9172   return new MEDFileIntFieldMultiTS(*this);
9173 }
9174
9175 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9176 {
9177   if(!f1ts)
9178     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9179   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9180   if(!f1tsC)
9181     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9182 }
9183
9184 /*!
9185  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9186  * mesh entities of a given dimension of the first mesh in MED file.
9187  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9188  *  \param [in] type - a spatial discretization of interest.
9189  *  \param [in] iteration - the iteration number of a required time step.
9190  *  \param [in] order - the iteration order number of required time step.
9191  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9192  *  \param [out] arrOut - the DataArrayInt containing values of field.
9193  *  \param [in] renumPol - specifies how to permute values of the result field according to
9194  *          the optional numbers of cells and nodes, if any. The valid values are
9195  *          - 0 - do not permute.
9196  *          - 1 - permute cells.
9197  *          - 2 - permute nodes.
9198  *          - 3 - permute cells and nodes.
9199  *
9200  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9201  *          caller is to delete this field using decrRef() as it is no more needed. 
9202  *  \throw If the MED file is not readable.
9203  *  \throw If there is no mesh in the MED file.
9204  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9205  *  \throw If no field values of the required parameters are available.
9206  */
9207 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9208 {
9209   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9210   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9211   if(!myF1TSC)
9212     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9213   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9214   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9215   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9216   return ret.retn();
9217 }
9218
9219 /*!
9220  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9221  * the top level cells of the first mesh in MED file.
9222  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9223  *  \param [in] type - a spatial discretization of interest.
9224  *  \param [in] iteration - the iteration number of a required time step.
9225  *  \param [in] order - the iteration order number of required time step.
9226  *  \param [out] arrOut - the DataArrayInt containing values of field.
9227  *  \param [in] renumPol - specifies how to permute values of the result field according to
9228  *          the optional numbers of cells and nodes, if any. The valid values are
9229  *          - 0 - do not permute.
9230  *          - 1 - permute cells.
9231  *          - 2 - permute nodes.
9232  *          - 3 - permute cells and nodes.
9233  *
9234  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9235  *          caller is to delete this field using decrRef() as it is no more needed. 
9236  *  \throw If the MED file is not readable.
9237  *  \throw If there is no mesh in the MED file.
9238  *  \throw If no field values of the required parameters are available.
9239  */
9240 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9241 {
9242   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9243   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9244   if(!myF1TSC)
9245     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9246   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9247   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9248   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9249   return ret.retn();
9250 }
9251
9252 /*!
9253  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9254  * a given support.
9255  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9256  *  \param [in] type - a spatial discretization of interest.
9257  *  \param [in] iteration - the iteration number of a required time step.
9258  *  \param [in] order - the iteration order number of required time step.
9259  *  \param [out] arrOut - the DataArrayInt containing values of field.
9260  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9261  *  \param [in] mesh - the supporting mesh.
9262  *  \param [in] renumPol - specifies how to permute values of the result field according to
9263  *          the optional numbers of cells and nodes, if any. The valid values are
9264  *          - 0 - do not permute.
9265  *          - 1 - permute cells.
9266  *          - 2 - permute nodes.
9267  *          - 3 - permute cells and nodes.
9268  *
9269  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9270  *          caller is to delete this field using decrRef() as it is no more needed. 
9271  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9272  *  \throw If no field of \a this is lying on \a mesh.
9273  *  \throw If no field values of the required parameters are available.
9274  */
9275 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9276 {
9277   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9278   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9279   if(!myF1TSC)
9280     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9281   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9282   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9283   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9284   return ret.retn();
9285 }
9286
9287 /*!
9288  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9289  * given support. 
9290  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9291  *  \param [in] type - a spatial discretization of the new field.
9292  *  \param [in] iteration - the iteration number of a required time step.
9293  *  \param [in] order - the iteration order number of required time step.
9294  *  \param [in] mesh - the supporting mesh.
9295  *  \param [out] arrOut - the DataArrayInt containing values of field.
9296  *  \param [in] renumPol - specifies how to permute values of the result field according to
9297  *          the optional numbers of cells and nodes, if any. The valid values are
9298  *          - 0 - do not permute.
9299  *          - 1 - permute cells.
9300  *          - 2 - permute nodes.
9301  *          - 3 - permute cells and nodes.
9302  *
9303  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9304  *          caller is to delete this field using decrRef() as it is no more needed. 
9305  *  \throw If no field of \a this is lying on \a mesh.
9306  *  \throw If no field values of the required parameters are available.
9307  */
9308 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9309 {
9310   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9311   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9312   if(!myF1TSC)
9313     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9314   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9315   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9316   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9317   return ret.retn();
9318 }
9319
9320 /*!
9321  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9322  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9323  * This method is useful for MED2 file format when field on different mesh was autorized.
9324  */
9325 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9326 {
9327   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9328   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9329   if(!myF1TSC)
9330     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9331   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9332   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9333   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9334   return ret.retn();
9335 }
9336
9337 /*!
9338  * Returns values and a profile of the field of a given type, of a given time step,
9339  * lying on a given support.
9340  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9341  *  \param [in] type - a spatial discretization of the field.
9342  *  \param [in] iteration - the iteration number of a required time step.
9343  *  \param [in] order - the iteration order number of required time step.
9344  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9345  *  \param [in] mesh - the supporting mesh.
9346  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9347  *          field of interest lies on. If the field lies on all entities of the given
9348  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9349  *          using decrRef() as it is no more needed.  
9350  *  \param [in] glob - the global data storing profiles and localization.
9351  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9352  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9353  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9354  *  \throw If no field of \a this is lying on \a mesh.
9355  *  \throw If no field values of the required parameters are available.
9356  */
9357 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9358 {
9359   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9360   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9361   if(!myF1TSC)
9362     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9363   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9364   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9365 }
9366
9367 /*!
9368  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9369  *  \param [in] pos - a time step id.
9370  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9371  *          delete this field using decrRef() as it is no more needed.
9372  *  \throw If \a pos is not a valid time step id.
9373  */
9374 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9375 {
9376   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9377   if(!item)
9378     {
9379       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9380       throw INTERP_KERNEL::Exception(oss.str().c_str());
9381     }
9382   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9383   if(itemC)
9384     {
9385       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9386       ret->shallowCpyGlobs(*this);
9387       return ret.retn();
9388     }
9389   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9390   throw INTERP_KERNEL::Exception(oss.str().c_str());
9391 }
9392
9393 /*!
9394  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9395  * the given field is checked if its elements are sorted suitable for writing to MED file
9396  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9397  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9398  *  \param [in] field - the field to add to \a this.
9399  *  \throw If the name of \a field is empty.
9400  *  \throw If the data array of \a field is not set.
9401  *  \throw If existing time steps have different name or number of components than \a field.
9402  *  \throw If the underlying mesh of \a field has no name.
9403  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9404  */
9405 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9406 {
9407   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9408 }
9409
9410 /*!
9411  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9412  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9413  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9414  * and \a profile.
9415  *
9416  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9417  * A new profile is added only if no equal profile is missing.
9418  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9419  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9420  *  \param [in] arrOfVals - the values of the field \a field used.
9421  *  \param [in] mesh - the supporting mesh of \a field.
9422  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9423  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9424  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9425  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9426  *  \throw If the data array of \a field is not set.
9427  *  \throw If the data array of \a this is already allocated but has different number of
9428  *         components than \a field.
9429  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9430  *  \sa setFieldNoProfileSBT()
9431  */
9432 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9433 {
9434   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9435 }
9436
9437 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9438 {
9439   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9440   if(!pt)
9441     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9442   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9443   if(!ret)
9444     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 !");
9445   return ret;
9446 }
9447
9448 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9449 {
9450   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9451   if(!pt)
9452     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9453   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9454   if(!ret)
9455     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 !");
9456   return ret;
9457 }
9458
9459 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9460 {
9461   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9462 }
9463
9464 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9465 {
9466 }
9467
9468 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9469 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9470 {
9471 }
9472 catch(INTERP_KERNEL::Exception& e)
9473 { throw e; }
9474
9475 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
9476 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
9477 {
9478 }
9479 catch(INTERP_KERNEL::Exception& e)
9480 { throw e; }
9481
9482 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9483 {
9484   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9485 }
9486
9487 //= MEDFileFields
9488
9489 MEDFileFields *MEDFileFields::New()
9490 {
9491   return new MEDFileFields;
9492 }
9493
9494 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9495 {
9496   return new MEDFileFields(fileName,loadAll,0);
9497 }
9498
9499 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9500 {
9501   return new MEDFileFields(fileName,loadAll,ms);
9502 }
9503
9504 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9505 {
9506   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9507   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9508   return ret;
9509 }
9510
9511 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9512 {
9513   std::vector<const BigMemoryObject *> ret;
9514   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9515     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9516   return ret;
9517 }
9518
9519 MEDFileFields *MEDFileFields::deepCpy() const
9520 {
9521   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9522   std::size_t i=0;
9523   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9524     {
9525       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9526         ret->_fields[i]=(*it)->deepCpy();
9527     }
9528   ret->deepCpyGlobs(*this);
9529   return ret.retn();
9530 }
9531
9532 MEDFileFields *MEDFileFields::shallowCpy() const
9533 {
9534   return new MEDFileFields(*this);
9535 }
9536
9537 /*!
9538  * 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
9539  * 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.
9540  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9541  *
9542  * \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.
9543  * \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.
9544  * 
9545  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9546  */
9547 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9548 {
9549   std::set< std::pair<int,int> > s;
9550   bool firstShot=true;
9551   areThereSomeForgottenTS=false;
9552   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9553     {
9554       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9555         continue;
9556       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9557       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9558       if(firstShot)
9559         { s=s1; firstShot=false; }
9560       else
9561         {
9562           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9563           if(s!=s2)
9564             areThereSomeForgottenTS=true;
9565           s=s2;
9566         }
9567     }
9568   std::vector< std::pair<int,int> > ret;
9569   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9570   return ret;
9571 }
9572
9573 int MEDFileFields::getNumberOfFields() const
9574 {
9575   return _fields.size();
9576 }
9577
9578 std::vector<std::string> MEDFileFields::getFieldsNames() const
9579 {
9580   std::vector<std::string> ret(_fields.size());
9581   int i=0;
9582   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9583     {
9584       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9585       if(f)
9586         {
9587           ret[i]=f->getName();
9588         }
9589       else
9590         {
9591           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9592           throw INTERP_KERNEL::Exception(oss.str().c_str());
9593         }
9594     }
9595   return ret;
9596 }
9597
9598 std::vector<std::string> MEDFileFields::getMeshesNames() const
9599 {
9600   std::vector<std::string> ret;
9601   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9602     {
9603       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9604       if(cur)
9605         ret.push_back(cur->getMeshName());
9606     }
9607   return ret;
9608 }
9609
9610 std::string MEDFileFields::simpleRepr() const
9611 {
9612   std::ostringstream oss;
9613   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9614   simpleRepr(0,oss);
9615   return oss.str();
9616 }
9617
9618 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9619 {
9620   int nbOfFields=getNumberOfFields();
9621   std::string startLine(bkOffset,' ');
9622   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9623   int i=0;
9624   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9625     {
9626       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9627       if(cur)
9628         {
9629           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9630         }
9631       else
9632         {
9633           oss << startLine << "  - not defined !" << std::endl;
9634         }
9635     }
9636   i=0;
9637   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9638     {
9639       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9640       std::string chapter(17,'0'+i);
9641       oss << startLine << chapter << std::endl;
9642       if(cur)
9643         {
9644           cur->simpleRepr(bkOffset+2,oss,i);
9645         }
9646       else
9647         {
9648           oss << startLine << "  - not defined !" << std::endl;
9649         }
9650       oss << startLine << chapter << std::endl;
9651     }
9652   simpleReprGlobs(oss);
9653 }
9654
9655 MEDFileFields::MEDFileFields()
9656 {
9657 }
9658
9659 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9660 try:MEDFileFieldGlobsReal(fileName)
9661 {
9662   MEDFileUtilities::CheckFileForRead(fileName);
9663   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
9664   int nbFields(MEDnField(fid));
9665   _fields.resize(nbFields);
9666   med_field_type typcha;
9667   for(int i=0;i<nbFields;i++)
9668     {
9669       std::vector<std::string> infos;
9670       std::string fieldName,dtunit;
9671       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
9672       switch(typcha)
9673       {
9674         case MED_FLOAT64:
9675           {
9676             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9677             break;
9678           }
9679         case MED_INT32:
9680           {
9681             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9682             break;
9683           }
9684         default:
9685           {
9686             std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << fileName << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
9687             throw INTERP_KERNEL::Exception(oss.str().c_str());
9688           }
9689       }
9690     }
9691   loadAllGlobals(fid);
9692 }
9693 catch(INTERP_KERNEL::Exception& e)
9694 {
9695     throw e;
9696 }
9697
9698 void MEDFileFields::writeLL(med_idt fid) const
9699 {
9700   int i=0;
9701   writeGlobals(fid,*this);
9702   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9703     {
9704       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9705       if(!elt)
9706         {
9707           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9708           throw INTERP_KERNEL::Exception(oss.str().c_str());
9709         }
9710       elt->writeLL(fid,*this);
9711     }
9712 }
9713
9714 void MEDFileFields::write(const std::string& fileName, int mode) const
9715 {
9716   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9717   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
9718   writeLL(fid);
9719 }
9720
9721 /*!
9722  * This method alloc the arrays and load potentially huge arrays contained in this field.
9723  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9724  * This method can be also called to refresh or reinit values from a file.
9725  * 
9726  * \throw If the fileName is not set or points to a non readable MED file.
9727  */
9728 void MEDFileFields::loadArrays()
9729 {
9730   if(getFileName().empty())
9731     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9732   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9733   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9734     {
9735       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9736       if(elt)
9737         elt->loadBigArraysRecursively(fid,*elt);
9738     }
9739 }
9740
9741 /*!
9742  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9743  * But once data loaded once, this method does nothing.
9744  * 
9745  * \throw If the fileName is not set or points to a non readable MED file.
9746  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9747  */
9748 void MEDFileFields::loadArraysIfNecessary()
9749 {
9750   if(!getFileName().empty())
9751     {
9752       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9753       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9754         {
9755           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9756           if(elt)
9757             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9758         }
9759     }
9760 }
9761
9762 /*!
9763  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9764  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9765  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9766  * 
9767  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9768  */
9769 void MEDFileFields::unloadArrays()
9770 {
9771   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9772     {
9773       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9774       if(elt)
9775         elt->unloadArrays();
9776     }
9777 }
9778
9779 /*!
9780  * 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.
9781  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9782  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9783  * 
9784  * \sa MEDFileFields::loadArraysIfNecessary
9785  */
9786 void MEDFileFields::unloadArraysWithoutDataLoss()
9787 {
9788   if(!getFileName().empty())
9789     unloadArrays();
9790 }
9791
9792 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9793 {
9794   std::vector<std::string> ret;
9795   std::set<std::string> ret2;
9796   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9797     {
9798       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9799       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9800         if(ret2.find(*it2)==ret2.end())
9801           {
9802             ret.push_back(*it2);
9803             ret2.insert(*it2);
9804           }
9805     }
9806   return ret;
9807 }
9808
9809 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9810 {
9811   std::vector<std::string> ret;
9812   std::set<std::string> ret2;
9813   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9814     {
9815       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9816       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9817         if(ret2.find(*it2)==ret2.end())
9818           {
9819             ret.push_back(*it2);
9820             ret2.insert(*it2);
9821           }
9822     }
9823   return ret;
9824 }
9825
9826 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9827 {
9828   std::vector<std::string> ret;
9829   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9830     {
9831       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
9832       ret.insert(ret.end(),tmp.begin(),tmp.end());
9833     }
9834   return ret;
9835 }
9836
9837 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9838 {
9839   std::vector<std::string> ret;
9840   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9841     {
9842       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9843       ret.insert(ret.end(),tmp.begin(),tmp.end());
9844     }
9845   return ret;
9846 }
9847
9848 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9849 {
9850   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9851     (*it)->changePflsRefsNamesGen2(mapOfModif);
9852 }
9853
9854 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9855 {
9856   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9857     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9858 }
9859
9860 void MEDFileFields::resize(int newSize)
9861 {
9862   _fields.resize(newSize);
9863 }
9864
9865 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
9866 {
9867   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9868     pushField(*it);
9869 }
9870
9871 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
9872 {
9873   if(!field)
9874     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9875   _fields.push_back(field->getContent());
9876   appendGlobs(*field,1e-12);
9877 }
9878
9879 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
9880 {
9881   if(!field)
9882     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9883   if(i>=(int)_fields.size())
9884     _fields.resize(i+1);
9885   _fields[i]=field->getContent();
9886   appendGlobs(*field,1e-12);
9887 }
9888
9889 void MEDFileFields::destroyFieldAtPos(int i)
9890 {
9891   destroyFieldsAtPos(&i,&i+1);
9892 }
9893
9894 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
9895 {
9896   std::vector<bool> b(_fields.size(),true);
9897   for(const int *i=startIds;i!=endIds;i++)
9898     {
9899       if(*i<0 || *i>=(int)_fields.size())
9900         {
9901           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9902           throw INTERP_KERNEL::Exception(oss.str().c_str());
9903         }
9904       b[*i]=false;
9905     }
9906   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9907   std::size_t j=0;
9908   for(std::size_t i=0;i<_fields.size();i++)
9909     if(b[i])
9910       fields[j++]=_fields[i];
9911   _fields=fields;
9912 }
9913
9914 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
9915 {
9916   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9917   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9918   std::vector<bool> b(_fields.size(),true);
9919   int k=bg;
9920   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9921     {
9922       if(k<0 || k>=(int)_fields.size())
9923         {
9924           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9925           throw INTERP_KERNEL::Exception(oss.str().c_str());
9926         }
9927       b[k]=false;
9928     }
9929   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9930   std::size_t j=0;
9931   for(std::size_t i=0;i<_fields.size();i++)
9932     if(b[i])
9933       fields[j++]=_fields[i];
9934   _fields=fields;
9935 }
9936
9937 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9938 {
9939   bool ret=false;
9940   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9941     {
9942       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9943       if(cur)
9944         ret=cur->changeMeshNames(modifTab) || ret;
9945     }
9946   return ret;
9947 }
9948
9949 /*!
9950  * \param [in] meshName the name of the mesh that will be renumbered.
9951  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9952  *             This code corresponds to the distribution of types in the corresponding mesh.
9953  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9954  * \param [in] renumO2N the old to new renumber array.
9955  * \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 
9956  *         field in \a this.
9957  */
9958 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
9959 {
9960   bool ret=false;
9961   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9962     {
9963       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9964       if(fmts)
9965         {
9966           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9967         }
9968     }
9969   return ret;
9970 }
9971
9972 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
9973 {
9974   if(i<0 || i>=(int)_fields.size())
9975     {
9976       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9977       throw INTERP_KERNEL::Exception(oss.str().c_str());
9978     }
9979   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9980   if(!fmts)
9981     return 0;
9982   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9983   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9984   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9985   if(fmtsC)
9986     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9987   else if(fmtsC2)
9988     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9989   else
9990     {
9991       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9992       throw INTERP_KERNEL::Exception(oss.str().c_str());
9993     }
9994   ret->shallowCpyGlobs(*this);
9995   return ret.retn();
9996 }
9997
9998 /*!
9999  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10000  * This method is accessible in python using __getitem__ with a list in input.
10001  * \return a new object that the caller should deal with.
10002  */
10003 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10004 {
10005   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
10006   std::size_t sz=std::distance(startIds,endIds);
10007   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10008   int j=0;
10009   for(const int *i=startIds;i!=endIds;i++,j++)
10010     {
10011       if(*i<0 || *i>=(int)_fields.size())
10012         {
10013           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10014           throw INTERP_KERNEL::Exception(oss.str().c_str());
10015         }
10016       fields[j]=_fields[*i];
10017     }
10018   ret->_fields=fields;
10019   return ret.retn();
10020 }
10021
10022 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10023 {
10024   return getFieldAtPos(getPosFromFieldName(fieldName));
10025 }
10026
10027 /*!
10028  * This method removes, if any, fields in \a this having no time steps.
10029  * 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.
10030  * 
10031  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10032  */
10033 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10034 {
10035   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10036   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10037     {
10038       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10039       if(elt)
10040         {
10041           if(elt->getNumberOfTS()>0)
10042             newFields.push_back(*it);
10043         }
10044     }
10045   if(_fields.size()==newFields.size())
10046     return false;
10047   _fields=newFields;
10048   return true;
10049 }
10050
10051 /*!
10052  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10053  * This method can be seen as a filter applied on \a this, that returns an object containing
10054  * 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
10055  * shallow copied from \a this.
10056  * 
10057  * \param [in] meshName - the name of the mesh on w
10058  * \return a new object that the caller should deal with.
10059  */
10060 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10061 {
10062   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10063   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10064     {
10065       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10066       if(!cur)
10067         continue;
10068       if(cur->getMeshName()==meshName)
10069         {
10070           cur->incrRef();
10071           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10072           ret->_fields.push_back(cur2);
10073         }
10074     }
10075   ret->shallowCpyOnlyUsedGlobs(*this);
10076   return ret.retn();
10077 }
10078
10079 /*!
10080  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10081  * Input time steps are specified using a pair of integer (iteration, order).
10082  * 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,
10083  * but for each multitimestep only the time steps in \a timeSteps are kept.
10084  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10085  * 
10086  * The returned object points to shallow copy of elements in \a this.
10087  * 
10088  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10089  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10090  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10091  */
10092 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10093 {
10094   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10095   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10096     {
10097       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10098       if(!cur)
10099         continue;
10100       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10101       ret->_fields.push_back(elt);
10102     }
10103   ret->shallowCpyOnlyUsedGlobs(*this);
10104   return ret.retn();
10105 }
10106
10107 /*!
10108  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10109  */
10110 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10111 {
10112   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10113   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10114     {
10115       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10116       if(!cur)
10117         continue;
10118       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10119       if(elt->getNumberOfTS()!=0)
10120         ret->_fields.push_back(elt);
10121     }
10122   ret->shallowCpyOnlyUsedGlobs(*this);
10123   return ret.retn();
10124 }
10125
10126 MEDFileFieldsIterator *MEDFileFields::iterator()
10127 {
10128   return new MEDFileFieldsIterator(this);
10129 }
10130
10131 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10132 {
10133   std::string tmp(fieldName);
10134   std::vector<std::string> poss;
10135   for(std::size_t i=0;i<_fields.size();i++)
10136     {
10137       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10138       if(f)
10139         {
10140           std::string fname(f->getName());
10141           if(tmp==fname)
10142             return i;
10143           else
10144             poss.push_back(fname);
10145         }
10146     }
10147   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10148   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10149   oss << " !";
10150   throw INTERP_KERNEL::Exception(oss.str().c_str());
10151 }
10152
10153 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10154 {
10155   if(fs)
10156     {
10157       fs->incrRef();
10158       _nb_iter=fs->getNumberOfFields();
10159     }
10160 }
10161
10162 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10163 {
10164 }
10165
10166 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10167 {
10168   if(_iter_id<_nb_iter)
10169     {
10170       MEDFileFields *fs(_fs);
10171       if(fs)
10172         return fs->getFieldAtPos(_iter_id++);
10173       else
10174         return 0;
10175     }
10176   else
10177     return 0;
10178 }