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