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