Salome HOME
Little refactoring of progeny mechanism to avoid if.
[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)
402 {
403   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt);
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()+5*sizeof(int);
419 }
420
421 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
422 {
423   return std::vector<const BigMemoryObject *>();
424 }
425
426 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const
427 {
428   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
429   ret->_father=father;
430   return ret.retn();
431 }
432
433 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt)
434 try:_type(atype),_father(fath),_profile_it(profileIt)
435 {
436 }
437 catch(INTERP_KERNEL::Exception& e)
438 {
439     throw e;
440 }
441
442 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
443 {
444 }
445
446 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),_tmp_work1(other._tmp_work1)
447 {
448 }
449
450 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
451     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
452 {
453 }
454
455 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
456 {
457   return _father;
458 }
459
460 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
461 {
462   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
463   INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
464   std::string fieldName=nasc.getName();
465   std::string meshName=getMeshName();
466   int iteration=getIteration();
467   int order=getOrder();
468   TypeOfField type=getType();
469   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
470   int profilesize,nbi;
471   med_geometry_type mgeoti;
472   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
473   _nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it,MED_COMPACT_PFLMODE,
474       pflname,&profilesize,locname,&nbi);
475   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
476   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
477   _start=start;
478   _end=start+_nval*nbi;
479   start=_end;
480   if(type==ON_CELLS && !_localization.empty())
481     {
482       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
483         setType(ON_GAUSS_PT);
484       else
485         {
486           setType(ON_GAUSS_NE);
487           _localization.clear();
488         }
489     }
490 }
491
492 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
493 {
494   std::string fieldName=nasc.getName();
495   std::string meshName=getMeshName();
496   int iteration=getIteration();
497   int order=getOrder();
498   TypeOfField type=getType();
499   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
500   med_geometry_type mgeoti;
501   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
502   if(_start>_end)
503     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
504   if(_start==_end)
505     return ;
506   DataArray *arr=getOrCreateAndGetArray();//arr is not null due to the spec of getOrCreateAndGetArray
507   if(_start<0 || _start>=arr->getNumberOfTuples())
508     {
509       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
510       throw INTERP_KERNEL::Exception(oss.str().c_str());
511     }
512   if(_end<0 || _end>arr->getNumberOfTuples())
513     {
514       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
515       throw INTERP_KERNEL::Exception(oss.str().c_str());
516     }
517   med_int tmp1,nbi;
518   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
519   med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
520   int nbOfCompo=arr->getNumberOfComponents();
521   if(_end-_start!=nbValsInFile*nbi)
522     {
523       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
524       throw INTERP_KERNEL::Exception(oss.str().c_str());
525     }
526   DataArrayDouble *arrD=dynamic_cast<DataArrayDouble *>(arr);
527   if(arrD)
528     {
529       double *startFeeding=arrD->getPointer()+_start*nbOfCompo;
530       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
531                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
532       return ;
533     }
534   DataArrayInt *arrI=dynamic_cast<DataArrayInt *>(arr);
535   if(arrI)
536     {
537       int *startFeeding=arrI->getPointer()+_start*nbOfCompo;
538       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
539                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
540       return ;
541     }
542   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
543 }
544
545 /*!
546  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
547  */
548 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
549 {
550   int delta=_end-_start;
551   _start=newValueOfStart;
552   _end=_start+delta;
553 }
554
555 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
556 {
557   return _father->getIteration();
558 }
559
560 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
561 {
562   return _father->getOrder();
563 }
564
565 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
566 {
567   return _father->getTime();
568 }
569
570 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
571 {
572   return _father->getMeshName();
573 }
574
575 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
576 {
577   const char startLine[]="    ## ";
578   std::string startLine2(bkOffset,' ');
579   startLine2+=startLine;
580   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
581   oss << startLine2 << "Localization #" << id << "." << std::endl;
582   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
583   delete tmp;
584   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
585   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
586   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
587 }
588
589 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
590 {
591   return _type;
592 }
593
594 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
595 {
596   types.insert(_type);
597 }
598
599 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
600 {
601   _type=newType;
602 }
603
604 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
605 {
606   return _father->getGeoType();
607 }
608
609 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
610 {
611   return _father->getNumberOfComponents();
612 }
613
614 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
615 {
616   return _end-_start;
617 }
618
619 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
620 {
621   return _father->getOrCreateAndGetArray();
622 }
623
624 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
625 {
626   const MEDFileFieldPerMeshPerType *fath=_father;
627   return fath->getOrCreateAndGetArray();
628 }
629
630 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
631 {
632   return _father->getInfo();
633 }
634
635 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
636 {
637   return _profile;
638 }
639
640 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
641 {
642   _profile=newPflName;
643 }
644
645 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
646 {
647   return _localization;
648 }
649
650 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
651 {
652   _localization=newLocName;
653 }
654
655 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
656 {
657   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
658     {
659       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
660         {
661           _profile=(*it2).second;
662           return;
663         }
664     }
665 }
666
667 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
668 {
669   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
670     {
671       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
672         {
673           _localization=(*it2).second;
674           return;
675         }
676     }
677 }
678
679 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
680 {
681   if(type!=_type)
682     return ;
683   dads.push_back(std::pair<int,int>(_start,_end));
684   geoTypes.push_back(getGeoType());
685   if(_profile.empty())
686     pfls.push_back(0);
687   else
688     {
689       pfls.push_back(glob->getProfile(_profile.c_str()));
690     }
691   if(_localization.empty())
692     locs.push_back(-1);
693   else
694     {
695       locs.push_back(glob->getLocalizationId(_localization.c_str()));
696     }
697 }
698
699 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
700 {
701   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));
702   startEntryId++;
703 }
704
705 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
706 {
707   TypeOfField type=getType();
708   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
709   med_geometry_type mgeoti;
710   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
711   const DataArray *arr=getOrCreateAndGetArray();
712   if(!arr)
713     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
714   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
715   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
716   const unsigned char *locToWrite=0;
717   if(arrD)
718     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
719   else if(arrI)
720     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
721   else
722     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
723   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
724                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
725                              locToWrite);
726 }
727
728 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
729 {
730   type=_type;
731   pfl=_profile;
732   loc=_localization;
733   dad.first=_start; dad.second=_end;
734 }
735
736 /*!
737  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
738  *             This code corresponds to the distribution of types in the corresponding mesh.
739  * \param [out] ptToFill memory zone where the output will be stored.
740  * \return the size of data pushed into output param \a ptToFill
741  */
742 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
743 {
744   _loc_id=offset;
745   std::ostringstream oss;
746   std::size_t nbOfType=codeOfMesh.size()/3;
747   int found=-1;
748   for(std::size_t i=0;i<nbOfType && found==-1;i++)
749     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
750       found=(int)i;
751   if(found==-1)
752     {
753       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
754       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
755       throw INTERP_KERNEL::Exception(oss.str().c_str());
756     }
757   int *work=ptToFill;
758   if(_profile.empty())
759     {
760       if(_nval!=codeOfMesh[3*found+1])
761         {
762           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
763           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
764           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
765           throw INTERP_KERNEL::Exception(oss.str().c_str());
766         }
767       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
768         *work++=ii;
769     }
770   else
771     {
772       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
773       if(pfl->getNumberOfTuples()!=_nval)
774         {
775           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
776           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
777           oss << _nval;
778           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
779           throw INTERP_KERNEL::Exception(oss.str().c_str());
780         }
781       int offset2=codeOfMesh[3*found+2];
782       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
783         {
784           if(*pflId<codeOfMesh[3*found+1])
785             *work++=offset2+*pflId;
786         }
787     }
788   return _nval;
789 }
790
791 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
792 {
793   for(int i=_start;i<_end;i++)
794     *ptToFill++=i;
795   return _end-_start;
796 }
797
798 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
799 {
800   switch(type)
801   {
802     case ON_CELLS:
803       return -2;
804     case ON_GAUSS_NE:
805       return -1;
806     case ON_GAUSS_PT:
807       return locId;
808     default:
809       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
810   }
811 }
812
813 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
814 {
815   int id=0;
816   std::map<std::pair<std::string,TypeOfField>,int> m;
817   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
818   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
819     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
820       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
821   ret.resize(id);
822   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
823     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
824   return ret;
825 }
826
827 /*!
828  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
829  * 
830  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
831  * \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.
832  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
833  * \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)
834  * \param [in,out] glob if necessary by the method, new profiles can be added to it
835  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
836  * \param [out] result All new entries will be appended on it.
837  * \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 !)
838  */
839 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
840                                                        const DataArrayInt *explicitIdsInMesh,
841                                                        const std::vector<int>& newCode,
842                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
843                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
844 {
845   if(entriesOnSameDisc.empty())
846     return false;
847   TypeOfField type=entriesOnSameDisc[0]->getType();
848   int szEntities=0,szTuples=0;
849   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
850     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
851   int nbi=szTuples/szEntities;
852   if(szTuples%szEntities!=0)
853     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
854   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
855   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
856   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
857   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
858   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
859   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
860   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
861   int id=0;
862   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
863     {
864       int startOfEltIdOfChunk=(*it)->_start;
865       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
866       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
867       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
868       //
869       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
870       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
871       //
872       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
873       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
874     }
875   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
876   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
877   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
878   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
879   //
880   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
881   //
882   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
883   arrPart->renumberInPlace(renumTupleIds->begin());
884   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
885   bool ret=false;
886   const int *idIt=diffVals->begin();
887   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
888   int offset2=0;
889   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
890     {
891       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
892       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
893       int nbEntityElts=subIds->getNumberOfTuples();
894       bool ret2;
895       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
896           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
897                                       offset+offset2,
898                                       li,glob,ret2);
899       ret=ret || ret2;
900       result.push_back(eltToAdd);
901       offset2+=nbEntityElts*nbi;
902     }
903   ret=ret || li.empty();
904   return ret;
905 }
906
907 /*!
908  * \param [in] typeF type of field of new chunk
909  * \param [in] geoType the geometric type of the chunk
910  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
911  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
912  * \param [in] nbi number of integration points
913  * \param [in] offset The offset in the **global array of data**.
914  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
915  *                 to the new chunk to create.
916  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
917  * \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
918  *              and corresponding entry erased from \a entriesOnSameDisc.
919  * \return a newly allocated chunk
920  */
921 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
922                                                                                                   bool isPfl, int nbi, int offset,
923                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
924                                                                                                   MEDFileFieldGlobsReal& glob,
925                                                                                                   bool &notInExisting)
926 {
927   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
928   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
929   for(;it!=entriesOnSameDisc.end();it++)
930     {
931       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
932         {
933           if(!isPfl)
934             {
935               if((*it)->_profile.empty())
936                 break;
937               else
938                 if(!(*it)->_profile.empty())
939                   {
940                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
941                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
942                       break;
943                   }
944             }
945         }
946     }
947   if(it==entriesOnSameDisc.end())
948     {
949       notInExisting=true;
950       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
951       ret->_type=typeF;
952       ret->_loc_id=(int)geoType;
953       ret->_nval=nbMeshEntities;
954       ret->_start=offset;
955       ret->_end=ret->_start+ret->_nval*nbi;
956       if(isPfl)
957         {
958           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
959           glob.appendProfile(idsOfMeshElt);
960           ret->_profile=idsOfMeshElt->getName();
961         }
962       //tony treatment of localization
963       return ret;
964     }
965   else
966     {
967       notInExisting=false;
968       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
969       ret->_loc_id=(int)geoType;
970       ret->setNewStart(offset);
971       entriesOnSameDisc.erase(it);
972       return ret;
973     }
974
975 }
976
977 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc)
978 {
979   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc);
980 }
981
982 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
983 {
984   return new MEDFileFieldPerMeshPerType(fath,geoType);
985 }
986
987 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
988 {
989   return _field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
990 }
991
992 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
993 {
994   std::vector<const BigMemoryObject *> ret;
995   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
996     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
997   return ret;
998 }
999
1000 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const
1001 {
1002   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1003   ret->_father=father;
1004   std::size_t i=0;
1005   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1006     {
1007       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1008         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
1009     }
1010   return ret.retn();
1011 }
1012
1013 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1014 {
1015   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1016   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1017     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1018 }
1019
1020 /*!
1021  * This method is the most general one. No optimization is done here.
1022  * \param [in] multiTypePfl is the end user profile specified in high level API
1023  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1024  * \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.
1025  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1026  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1027  * \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.
1028  */
1029 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)
1030 {
1031   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1032   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1033     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1034 }
1035
1036 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1037 {
1038   _field_pm_pt_pd.resize(1);
1039   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1040   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1041 }
1042
1043 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1044 {
1045   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1046   if(!arr || !arr->isAllocated())
1047     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1048   _field_pm_pt_pd.resize(1);
1049   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1050   _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.
1051 }
1052
1053 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1054 {
1055   TypeOfField type=field->getTypeOfField();
1056   if(type!=ON_GAUSS_PT)
1057     {
1058       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1059       int sz=_field_pm_pt_pd.size();
1060       bool found=false;
1061       for(int j=0;j<sz && !found;j++)
1062         {
1063           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1064             {
1065               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1066               found=true;
1067             }
1068         }
1069       if(!found)
1070         {
1071           _field_pm_pt_pd.resize(sz+1);
1072           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1073         }
1074       std::vector<int> ret(1,(int)sz);
1075       return ret;
1076     }
1077   else
1078     {
1079       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1080       int sz2=ret2.size();
1081       std::vector<int> ret3(sz2);
1082       int k=0;
1083       for(int i=0;i<sz2;i++)
1084         {
1085           int sz=_field_pm_pt_pd.size();
1086           int locIdToFind=ret2[i];
1087           bool found=false;
1088           for(int j=0;j<sz && !found;j++)
1089             {
1090               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1091                 {
1092                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1093                   ret3[k++]=j;
1094                   found=true;
1095                 }
1096             }
1097           if(!found)
1098             {
1099               _field_pm_pt_pd.resize(sz+1);
1100               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1101               ret3[k++]=sz;
1102             }
1103         }
1104       return ret3;
1105     }
1106 }
1107
1108 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1109 {
1110   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1111   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1112   if(!disc2)
1113     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1114   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1115   if(!da)
1116     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1117   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1118   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1119   if(retTmp->presenceOfValue(-1))
1120     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1121   std::vector<int> ret(retTmp->begin(),retTmp->end());
1122   return ret;
1123 }
1124
1125 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1126 {
1127   TypeOfField type=field->getTypeOfField();
1128   if(type!=ON_GAUSS_PT)
1129     {
1130       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1131       int sz=_field_pm_pt_pd.size();
1132       bool found=false;
1133       for(int j=0;j<sz && !found;j++)
1134         {
1135           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1136             {
1137               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1138               found=true;
1139             }
1140         }
1141       if(!found)
1142         {
1143           _field_pm_pt_pd.resize(sz+1);
1144           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1145         }
1146       std::vector<int> ret(1,0);
1147       return ret;
1148     }
1149   else
1150     {
1151       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1152       int sz2=ret2.size();
1153       std::vector<int> ret3(sz2);
1154       int k=0;
1155       for(int i=0;i<sz2;i++)
1156         {
1157           int sz=_field_pm_pt_pd.size();
1158           int locIdToFind=ret2[i];
1159           bool found=false;
1160           for(int j=0;j<sz && !found;j++)
1161             {
1162               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1163                 {
1164                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1165                   ret3[k++]=j;
1166                   found=true;
1167                 }
1168             }
1169           if(!found)
1170             {
1171               _field_pm_pt_pd.resize(sz+1);
1172               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1173               ret3[k++]=sz;
1174             }
1175         }
1176       return ret3;
1177     }
1178 }
1179
1180 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1181 {
1182   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1183   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1184   if(!disc2)
1185     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1186   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1187   if(!da)
1188     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1189   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1190   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1191   if(retTmp->presenceOfValue(-1))
1192     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1193   std::vector<int> ret(retTmp->begin(),retTmp->end());
1194   return ret;
1195 }
1196
1197 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1198 {
1199   return _father;
1200 }
1201
1202 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1203 {
1204   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1205   int curDim=(int)cm.getDimension();
1206   dim=std::max(dim,curDim);
1207 }
1208
1209 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1210 {
1211   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1212     {
1213       (*it)->fillTypesOfFieldAvailable(types);
1214     }
1215 }
1216
1217 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
1218 {
1219   int sz=_field_pm_pt_pd.size();
1220   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1221   for(int i=0;i<sz;i++)
1222     {
1223       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1224     }
1225 }
1226
1227 int MEDFileFieldPerMeshPerType::getIteration() const
1228 {
1229   return _father->getIteration();
1230 }
1231
1232 int MEDFileFieldPerMeshPerType::getOrder() const
1233 {
1234   return _father->getOrder();
1235 }
1236
1237 double MEDFileFieldPerMeshPerType::getTime() const
1238 {
1239   return _father->getTime();
1240 }
1241
1242 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1243 {
1244   return _father->getMeshName();
1245 }
1246
1247 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1248 {
1249   const char startLine[]="  ## ";
1250   std::string startLine2(bkOffset,' ');
1251   std::string startLine3(startLine2);
1252   startLine3+=startLine;
1253   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1254     {
1255       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1256       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1257     }
1258   else
1259     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1260   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1261   int i=0;
1262   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1263     {
1264       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1265       if(cur)
1266         cur->simpleRepr(bkOffset,oss,i);
1267       else
1268         {
1269           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1270         }
1271     }
1272 }
1273
1274 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1275 {
1276   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1277     {
1278       globalSz+=(*it)->getNumberOfTuples();
1279     }
1280   nbOfEntries+=(int)_field_pm_pt_pd.size();
1281 }
1282
1283 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1284 {
1285   return _geo_type;
1286 }
1287
1288
1289 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1290 {
1291   return _father->getNumberOfComponents();
1292 }
1293
1294 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1295 {
1296   return _father->getOrCreateAndGetArray();
1297 }
1298
1299 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1300 {
1301   const MEDFileFieldPerMesh *fath=_father;
1302   return fath->getOrCreateAndGetArray();
1303 }
1304
1305 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1306 {
1307   return _father->getInfo();
1308 }
1309
1310 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1311 {
1312   std::vector<std::string> ret;
1313   std::set<std::string> ret2;
1314   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1315     {
1316       std::string tmp=(*it1)->getProfile();
1317       if(!tmp.empty())
1318         if(ret2.find(tmp)==ret2.end())
1319           {
1320             ret.push_back(tmp);
1321             ret2.insert(tmp);
1322           }
1323     }
1324   return ret;
1325 }
1326
1327 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1328 {
1329   std::vector<std::string> ret;
1330   std::set<std::string> ret2;
1331   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1332     {
1333       std::string tmp=(*it1)->getLocalization();
1334       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1335         if(ret2.find(tmp)==ret2.end())
1336           {
1337             ret.push_back(tmp);
1338             ret2.insert(tmp);
1339           }
1340     }
1341   return ret;
1342 }
1343
1344 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1345 {
1346   std::vector<std::string> ret;
1347   std::set<std::string> ret2;
1348   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1349     {
1350       std::string tmp=(*it1)->getProfile();
1351       if(!tmp.empty())
1352         ret.push_back(tmp);
1353     }
1354   return ret;
1355 }
1356
1357 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1358 {
1359   std::vector<std::string> ret;
1360   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1361     {
1362       std::string tmp=(*it1)->getLocalization();
1363       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1364         ret.push_back(tmp);
1365     }
1366   return ret;
1367 }
1368
1369 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1370 {
1371   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1372     (*it1)->changePflsRefsNamesGen(mapOfModif);
1373 }
1374
1375 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1376 {
1377   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1378     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1379 }
1380
1381 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1382 {
1383   if(_field_pm_pt_pd.empty())
1384     {
1385       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1386       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1387       throw INTERP_KERNEL::Exception(oss.str().c_str());
1388     }
1389   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1390     return _field_pm_pt_pd[locId];
1391   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1392   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1393   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1394   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1395   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1396 }
1397
1398 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1399 {
1400   if(_field_pm_pt_pd.empty())
1401     {
1402       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1403       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1404       throw INTERP_KERNEL::Exception(oss.str().c_str());
1405     }
1406   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1407     return _field_pm_pt_pd[locId];
1408   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1409   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1410   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1411   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1412   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1413 }
1414
1415 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
1416 {
1417   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1418     {
1419       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1420       if(meshDim!=(int)cm.getDimension())
1421         return ;
1422     }
1423   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1424     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1425 }
1426
1427 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1428 {
1429   int i=0;
1430   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1431     {
1432       (*it)->fillValues(i,startEntryId,entries);
1433     }
1434 }
1435
1436 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1437 {
1438   _field_pm_pt_pd=leaves;
1439   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1440     (*it)->setFather(this);
1441 }
1442
1443 /*!
1444  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1445  *  \param [out] its - list of pair (start,stop) kept
1446  *  \return bool - false if the type of field \a tof is not contained in \a this.
1447  */
1448 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1449 {
1450   bool ret=false;
1451   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1452   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1453     if((*it)->getType()==tof)
1454       {
1455         newPmPtPd.push_back(*it);
1456         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1457         (*it)->setNewStart(globalNum);
1458         globalNum=(*it)->getEnd();
1459         its.push_back(bgEnd);
1460         ret=true;
1461       }
1462   if(ret)
1463     _field_pm_pt_pd=newPmPtPd;
1464   return ret;
1465 }
1466
1467 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1468 {
1469 }
1470
1471 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc):_father(fath),_geo_type(geoType)
1472 {
1473   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1474   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1475   med_geometry_type mgeoti;
1476   med_entity_type menti;
1477   menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1478   int nbProfiles=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1479   _field_pm_pt_pd.resize(nbProfiles);
1480   for(int i=0;i<nbProfiles;i++)
1481     {
1482       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1483     }
1484   if(type==ON_CELLS)
1485     {
1486       int nbProfiles2=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName);
1487       for(int i=0;i<nbProfiles2;i++)
1488         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i+1));
1489     }
1490 }
1491
1492 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1493 {
1494   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1495     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1496 }
1497
1498 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1499 {
1500   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1501     (*it)->loadBigArray(fid,nasc);
1502 }
1503
1504 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1505 {
1506   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1507     {
1508       (*it)->copyOptionsFrom(*this);
1509       (*it)->writeLL(fid,nasc);
1510     }
1511 }
1512
1513 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1514 {
1515   switch(ikType)
1516   {
1517     case ON_CELLS:
1518       medfGeoType=typmai3[(int)ikGeoType];
1519       return MED_CELL;
1520     case ON_NODES:
1521       medfGeoType=MED_NONE;
1522       return MED_NODE;
1523     case ON_GAUSS_NE:
1524       medfGeoType=typmai3[(int)ikGeoType];
1525       return MED_NODE_ELEMENT;
1526     case ON_GAUSS_PT:
1527       medfGeoType=typmai3[(int)ikGeoType];
1528       return MED_CELL;
1529     default:
1530       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1531   }
1532   return MED_UNDEF_ENTITY_TYPE;
1533 }
1534
1535 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc)
1536 {
1537   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc);
1538 }
1539
1540 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1541 {
1542   return new MEDFileFieldPerMesh(fath,mesh);
1543 }
1544
1545 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1546 {
1547   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1548 }
1549
1550 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1551 {
1552   std::vector<const BigMemoryObject *> ret;
1553   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1554     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1555   return ret;
1556 }
1557
1558 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1559 {
1560   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1561   ret->_father=father;
1562   std::size_t i=0;
1563   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1564     {
1565       if((const MEDFileFieldPerMeshPerType *)*it)
1566         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1567     }
1568   return ret.retn();
1569 }
1570
1571 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1572 {
1573   std::string startLine(bkOffset,' ');
1574   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1575   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1576   int i=0;
1577   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1578     {
1579       const MEDFileFieldPerMeshPerType *cur=*it;
1580       if(cur)
1581         cur->simpleRepr(bkOffset,oss,i);
1582       else
1583         {
1584           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1585         }
1586     }
1587 }
1588
1589 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1590 {
1591   _mesh_name=mesh->getName();
1592   mesh->getTime(_mesh_iteration,_mesh_order);
1593 }
1594
1595 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1596 {
1597   int nbOfTypes=code.size()/3;
1598   int offset=0;
1599   for(int i=0;i<nbOfTypes;i++)
1600     {
1601       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1602       int nbOfCells=code[3*i+1];
1603       int pos=addNewEntryIfNecessary(type);
1604       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1605       offset+=nbOfCells;
1606     }
1607 }
1608
1609 /*!
1610  * This method is the most general one. No optimization is done here.
1611  * \param [in] multiTypePfl is the end user profile specified in high level API
1612  * \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].
1613  * \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.
1614  * \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.
1615  * \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.
1616  * \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.
1617  */
1618 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)
1619 {
1620   int nbOfTypes(code.size()/3);
1621   for(int i=0;i<nbOfTypes;i++)
1622     {
1623       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1624       int pos=addNewEntryIfNecessary(type);
1625       DataArrayInt *pfl=0;
1626       if(code[3*i+2]!=-1)
1627         pfl=idsPerType[code[3*i+2]];
1628       int nbOfTupes2=code2.size()/3;
1629       int found=0;
1630       for(;found<nbOfTupes2;found++)
1631         if(code[3*i]==code2[3*found])
1632           break;
1633       if(found==nbOfTupes2)
1634         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1635       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1636     }
1637 }
1638
1639 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1640 {
1641   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1642   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1643 }
1644
1645 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1646 {
1647   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1648   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1649 }
1650
1651 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1652 {
1653   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1654     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1655 }
1656
1657 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1658 {
1659   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1660     (*it)->loadBigArraysRecursively(fid,nasc);
1661 }
1662
1663 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1664 {
1665   int nbOfTypes=_field_pm_pt.size();
1666   for(int i=0;i<nbOfTypes;i++)
1667     {
1668       _field_pm_pt[i]->copyOptionsFrom(*this);
1669       _field_pm_pt[i]->writeLL(fid,nasc);
1670     }
1671 }
1672
1673 void MEDFileFieldPerMesh::getDimension(int& dim) const
1674 {
1675   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1676     (*it)->getDimension(dim);
1677 }
1678
1679 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1680 {
1681   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1682     (*it)->fillTypesOfFieldAvailable(types);
1683 }
1684
1685 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
1686 {
1687   int sz=_field_pm_pt.size();
1688   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1689   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1690   for(int i=0;i<sz;i++)
1691     {
1692       types[i]=_field_pm_pt[i]->getGeoType();
1693       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1694     }
1695   return ret;
1696 }
1697
1698 double MEDFileFieldPerMesh::getTime() const
1699 {
1700   int tmp1,tmp2;
1701   return _father->getTime(tmp1,tmp2);
1702 }
1703
1704 int MEDFileFieldPerMesh::getIteration() const
1705 {
1706   return _father->getIteration();
1707 }
1708
1709 int MEDFileFieldPerMesh::getOrder() const
1710 {
1711   return _father->getOrder();
1712 }
1713
1714 int MEDFileFieldPerMesh::getNumberOfComponents() const
1715 {
1716   return _father->getNumberOfComponents();
1717 }
1718
1719 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1720 {
1721   if(!_father)
1722     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1723   return _father->getOrCreateAndGetArray();
1724 }
1725
1726 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1727 {
1728   if(!_father)
1729     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1730   return _father->getOrCreateAndGetArray();
1731 }
1732
1733 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1734 {
1735   return _father->getInfo();
1736 }
1737
1738 /*!
1739  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1740  * 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.
1741  * It returns 2 output vectors :
1742  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1743  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1744  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1745  */
1746 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)
1747 {
1748   int notNullPflsSz=0;
1749   int nbOfArrs=geoTypes.size();
1750   for(int i=0;i<nbOfArrs;i++)
1751     if(pfls[i])
1752       notNullPflsSz++;
1753   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1754   int nbOfDiffGeoTypes=geoTypes3.size();
1755   code.resize(3*nbOfDiffGeoTypes);
1756   notNullPfls.resize(notNullPflsSz);
1757   notNullPflsSz=0;
1758   int j=0;
1759   for(int i=0;i<nbOfDiffGeoTypes;i++)
1760     {
1761       int startZone=j;
1762       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1763       std::vector<const DataArrayInt *> notNullTmp;
1764       if(pfls[j])
1765         notNullTmp.push_back(pfls[j]);
1766       j++;
1767       for(;j<nbOfArrs;j++)
1768         if(geoTypes[j]==refType)
1769           {
1770             if(pfls[j])
1771               notNullTmp.push_back(pfls[j]);
1772           }
1773         else
1774           break;
1775       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1776       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1777       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1778       code[3*i]=(int)refType;
1779       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1780       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1781       if(notNullTmp.empty())
1782         code[3*i+2]=-1;
1783       else
1784         {
1785           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1786           code[3*i+2]=notNullPflsSz++;
1787         }
1788     }
1789 }
1790
1791 /*!
1792  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1793  */
1794 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)
1795 {
1796   int sz=dads.size();
1797   int ret=0;
1798   for(int i=0;i<sz;i++)
1799     {
1800       if(locs[i]==-1)
1801         {
1802           if(type!=ON_GAUSS_NE)
1803             ret+=dads[i].second-dads[i].first;
1804           else
1805             {
1806               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1807               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1808             }
1809         }
1810       else
1811         {
1812           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1813           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1814         }
1815     }
1816   return ret;
1817 }
1818
1819 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1820 {
1821   std::vector<std::string> ret;
1822   std::set<std::string> ret2;
1823   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1824     {
1825       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1826       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1827         if(ret2.find(*it2)==ret2.end())
1828           {
1829             ret.push_back(*it2);
1830             ret2.insert(*it2);
1831           }
1832     }
1833   return ret;
1834 }
1835
1836 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1837 {
1838   std::vector<std::string> ret;
1839   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1840     {
1841       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1842       ret.insert(ret.end(),tmp.begin(),tmp.end());
1843     }
1844   return ret;
1845 }
1846
1847 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1848 {
1849   std::vector<std::string> ret;
1850   std::set<std::string> ret2;
1851   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1852     {
1853       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1854       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1855         if(ret2.find(*it2)==ret2.end())
1856           {
1857             ret.push_back(*it2);
1858             ret2.insert(*it2);
1859           }
1860     }
1861   return ret;
1862 }
1863
1864 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1865 {
1866   std::vector<std::string> ret;
1867   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1868     {
1869       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1870       ret.insert(ret.end(),tmp.begin(),tmp.end());
1871     }
1872   return ret;
1873 }
1874
1875 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1876 {
1877   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1878     {
1879       if((*it).first==_mesh_name)
1880         {
1881           _mesh_name=(*it).second;
1882           return true;
1883         }
1884     }
1885   return false;
1886 }
1887
1888 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1889                                                       MEDFileFieldGlobsReal& glob)
1890 {
1891   if(_mesh_name!=meshName)
1892     return false;
1893   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1894   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1895   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1896   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1897   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1898   getUndergroundDataArrayExt(entries);
1899   DataArray *arr0=getOrCreateAndGetArray();//tony
1900   if(!arr0)
1901     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
1902   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
1903   if(!arr0)
1904     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
1905   int sz=0;
1906   if(!arr)
1907     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1908   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1909     {
1910       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1911         {
1912           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1913           sz+=(*it).second.second-(*it).second.first;
1914         }
1915       else
1916         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1917     }
1918   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1919   ////////////////////
1920   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1921   int *workI2=explicitIdsOldInMesh->getPointer();
1922   int sz1=0,sz2=0,sid=1;
1923   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1924   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1925   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1926     {
1927       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1928       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1929       int *workI=explicitIdsOldInArr->getPointer();
1930       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1931         {
1932           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1933           (*itL2)->setLocId(sz2);
1934           (*itL2)->_tmp_work1=(*itL2)->getStart();
1935           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1936         }
1937       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1938     }
1939   explicitIdsOldInMesh->reAlloc(sz2);
1940   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1941   ////////////////////
1942   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1943   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1944   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1945   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1946     {
1947       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1948       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1949       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1950     }
1951   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1952   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1953   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1954     {
1955       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1956       int newStart=elt->getLocId();
1957       elt->setLocId((*it)->getGeoType());
1958       elt->setNewStart(newStart);
1959       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1960       entriesKeptNew.push_back(elt);
1961       entriesKeptNew2.push_back(elt);
1962     }
1963   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1964   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1965   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1966   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1967   bool ret=false;
1968   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1969     {
1970       sid=0;
1971       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1972         {
1973           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1974           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1975           }*/
1976       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1977                                                             glob,arr2,otherEntriesNew) || ret;
1978     }
1979   if(!ret)
1980     return false;
1981   // Assign new dispatching
1982   assignNewLeaves(otherEntriesNew);
1983   arr->cpyFrom(*arr2);
1984   return true;
1985 }
1986
1987 /*!
1988  * \param [in,out] globalNum a global numbering counter for the renumbering.
1989  * \param [out] its - list of pair (start,stop) kept
1990  */
1991 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1992 {
1993   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
1994   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1995     {
1996       std::vector< std::pair<int,int> > its2;
1997       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
1998         {
1999           ret.push_back(*it);
2000           its.insert(its.end(),its2.begin(),its2.end());
2001         }
2002     }
2003   _field_pm_pt=ret;
2004 }
2005
2006 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2007 {
2008   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2009   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2010     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2011   //
2012   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2013   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2014   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2015   for(;it1!=types.end();it1++,it2++)
2016     {
2017       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2018       elt->setLeaves((*it1).second);
2019       *it2=elt;
2020     }
2021   _field_pm_pt=fieldPmPt;
2022 }
2023
2024 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2025 {
2026   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2027     (*it)->changePflsRefsNamesGen(mapOfModif);
2028 }
2029
2030 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2031 {
2032   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2033     (*it)->changeLocsRefsNamesGen(mapOfModif);
2034 }
2035
2036 /*!
2037  * \param [in] mesh is the whole mesh
2038  */
2039 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2040 {
2041   if(_field_pm_pt.empty())
2042     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2043   //
2044   std::vector< std::pair<int,int> > dads;
2045   std::vector<const DataArrayInt *> pfls;
2046   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2047   std::vector<int> locs,code;
2048   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2049   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2050     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2051   // Sort by types
2052   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2053   if(code.empty())
2054     {
2055       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2056       throw INTERP_KERNEL::Exception(oss.str().c_str());
2057     }
2058   //
2059   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2060   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2061   if(type!=ON_NODES)
2062     {
2063       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2064       if(!arr)
2065         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2066       else
2067         {
2068           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2069           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2070         }
2071     }
2072   else
2073     {
2074       if(code.size()!=3)
2075         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2076       int nb=code[1];
2077       if(code[2]==-1)
2078         {
2079           if(nb!=mesh->getNumberOfNodes())
2080             {
2081               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2082               oss << " nodes in mesh !";
2083               throw INTERP_KERNEL::Exception(oss.str().c_str());
2084             }
2085           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2086         }
2087       else
2088         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2089     }
2090 }
2091
2092 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2093 {
2094   if(_field_pm_pt.empty())
2095     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2096   //
2097   std::vector<std::pair<int,int> > dads;
2098   std::vector<const DataArrayInt *> pfls;
2099   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2100   std::vector<int> locs,code;
2101   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2102   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2103     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2104   // Sort by types
2105   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2106   if(code.empty())
2107     {
2108       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2109       throw INTERP_KERNEL::Exception(oss.str().c_str());
2110     }
2111   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2112   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2113   if(type!=ON_NODES)
2114     {
2115       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2116       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2117     }
2118   else
2119     {
2120       if(code.size()!=3)
2121         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2122       int nb=code[1];
2123       if(code[2]==-1)
2124         {
2125           if(nb!=mesh->getNumberOfNodes())
2126             {
2127               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2128               oss << " nodes in mesh !";
2129               throw INTERP_KERNEL::Exception(oss.str().c_str());
2130             }
2131         }
2132       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2133     }
2134   //
2135   return 0;
2136 }
2137
2138 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2139 {
2140   int globalSz=0;
2141   int nbOfEntries=0;
2142   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2143     {
2144       (*it)->getSizes(globalSz,nbOfEntries);
2145     }
2146   entries.resize(nbOfEntries);
2147   nbOfEntries=0;
2148   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2149     {
2150       (*it)->fillValues(nbOfEntries,entries);
2151     }
2152 }
2153
2154 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2155 {
2156   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2157     {
2158       if((*it)->getGeoType()==typ)
2159         return (*it)->getLeafGivenLocId(locId);
2160     }
2161   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2162   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2163   oss << "Possiblities are : ";
2164   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2165     {
2166       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2167       oss << "\"" << cm2.getRepr() << "\", ";
2168     }
2169   throw INTERP_KERNEL::Exception(oss.str().c_str());
2170 }
2171
2172 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2173 {
2174   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2175     {
2176       if((*it)->getGeoType()==typ)
2177         return (*it)->getLeafGivenLocId(locId);
2178     }
2179   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2180   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2181   oss << "Possiblities are : ";
2182   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2183     {
2184       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2185       oss << "\"" << cm2.getRepr() << "\", ";
2186     }
2187   throw INTERP_KERNEL::Exception(oss.str().c_str());
2188 }
2189
2190 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2191 {
2192   int i=0;
2193   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2194   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2195   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2196     {
2197       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2198       if(type==curType)
2199         return i;
2200       else
2201         {
2202           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2203           if(pos>pos2)
2204             it2=it+1;
2205         }
2206     }
2207   int ret=std::distance(_field_pm_pt.begin(),it2);
2208   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2209   return ret;
2210 }
2211
2212 /*!
2213  * 'dads' and 'locs' input parameters have the same number of elements
2214  * \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
2215  */
2216 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2217                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2218                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2219 {
2220   isPfl=false;
2221   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2222   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2223   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2224   const std::vector<std::string>& infos=getInfo();
2225   da->setInfoOnComponents(infos);
2226   da->setName("");
2227   if(type==ON_GAUSS_PT)
2228     {
2229       int offset=0;
2230       int nbOfArrs=dads.size();
2231       for(int i=0;i<nbOfArrs;i++)
2232         {
2233           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2234           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2235           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2236           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2237           di->alloc(nbOfElems,1);
2238           di->iota(offset);
2239           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2240           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2241           offset+=nbOfElems;
2242         }
2243     }
2244   arrOut=da;
2245   return ret.retn();
2246 }
2247
2248 /*!
2249  * 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.
2250  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2251  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2252  * The order of cells in the returned field is those imposed by the profile.
2253  * \param [in] mesh is the global mesh.
2254  */
2255 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2256                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2257                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2258                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2259 {
2260   if(da->isIdentity())
2261     {
2262       int nbOfTuples=da->getNumberOfTuples();
2263       if(nbOfTuples==mesh->getNumberOfCells())
2264         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2265     }
2266   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2267   m2->setName(mesh->getName().c_str());
2268   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2269   isPfl=true;
2270   return ret.retn();
2271 }
2272
2273 /*!
2274  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2275  */
2276 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2277                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2278                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2279 {
2280   if(da->isIdentity())
2281     {
2282       int nbOfTuples=da->getNumberOfTuples();
2283       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2284         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2285     }
2286   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2287   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2288   if(meshu)
2289     {
2290       if(meshu->getNodalConnectivity()==0)
2291         {
2292           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2293           int nb=da->getNbOfElems();
2294           const int *ptr=da->getConstPointer();
2295           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2296           meshuc->allocateCells(nb);
2297           for(int i=0;i<nb;i++)
2298             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2299           meshuc->finishInsertingCells();
2300           ret->setMesh(meshuc);
2301           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2302           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2303           disc->checkCoherencyBetween(meshuc,arrOut);
2304           return ret.retn();
2305         }
2306     }
2307   //
2308   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2309   isPfl=true;
2310   DataArrayInt *arr2=0;
2311   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2312   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2313   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2314   int nnodes=mesh2->getNumberOfNodes();
2315   if(nnodes==(int)da->getNbOfElems())
2316     {
2317       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2318       arrOut->renumberInPlace(da3->getConstPointer());
2319       mesh2->setName(mesh->getName().c_str());
2320       ret->setMesh(mesh2);
2321       return ret.retn();
2322     }
2323   else
2324     {
2325       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 !!!";
2326       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2327       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2328       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2329       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2330       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2331       throw INTERP_KERNEL::Exception(oss.str().c_str());
2332     }
2333   return 0;
2334 }
2335
2336 /*!
2337  * This method is the most light method of field retrieving.
2338  */
2339 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2340 {
2341   if(!pflIn)
2342     {
2343       pflOut=DataArrayInt::New();
2344       pflOut->alloc(nbOfElems,1);
2345       pflOut->iota(0);
2346     }
2347   else
2348     {
2349       pflOut=const_cast<DataArrayInt*>(pflIn);
2350       pflOut->incrRef();
2351     }
2352   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2353   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2354   const std::vector<std::string>& infos=getInfo();
2355   int nbOfComp=infos.size();
2356   for(int i=0;i<nbOfComp;i++)
2357     da->setInfoOnComponent(i,infos[i].c_str());
2358   safePfl->incrRef();
2359   return da.retn();
2360 }
2361
2362 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2363     _mesh_csit(meshCsit),_father(fath)
2364 {
2365   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2366   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2367   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2368   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2369     {
2370       int nbProfile =MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[i],_mesh_csit,meshName,pflName,locName);
2371       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2372       int nbProfile2=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2373       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2374       if(nbProfile>0 || nbProfile2>0)
2375         {
2376           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc));
2377           if(nbProfile>0)
2378             _mesh_name=name0;
2379           else
2380             _mesh_name=name1;
2381         }
2382     }
2383   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2384   if(nbProfile>0)
2385     {
2386       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc));
2387       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2388     }
2389 }
2390
2391 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2392 {
2393   copyTinyInfoFrom(mesh);
2394 }
2395
2396 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2397 {
2398   if(id>=(int)_pfls.size())
2399     _pfls.resize(id+1);
2400   _pfls[id]=DataArrayInt::New();
2401   int lgth=MEDprofileSizeByName(fid,pflName.c_str());
2402   _pfls[id]->setName(pflName);
2403   _pfls[id]->alloc(lgth,1);
2404   MEDprofileRd(fid,pflName.c_str(),_pfls[id]->getPointer());
2405   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2406 }
2407
2408 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2409 {
2410   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2411   int sz;
2412   MEDprofileInfo(fid,i+1,pflName,&sz);
2413   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2414   if(i>=(int)_pfls.size())
2415     _pfls.resize(i+1);
2416   _pfls[i]=DataArrayInt::New();
2417   _pfls[i]->alloc(sz,1);
2418   _pfls[i]->setName(pflCpp.c_str());
2419   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2420   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2421 }
2422
2423 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2424 {
2425   int nbOfPfls=_pfls.size();
2426   for(int i=0;i<nbOfPfls;i++)
2427     {
2428       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2429       cpy->applyLin(1,1,0);
2430       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2431       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2432       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2433     }
2434   //
2435   int nbOfLocs=_locs.size();
2436   for(int i=0;i<nbOfLocs;i++)
2437     _locs[i]->writeLL(fid);
2438 }
2439
2440 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2441 {
2442   std::vector<std::string> pfls=getPfls();
2443   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2444     {
2445       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2446       if(it2==pfls.end())
2447         {
2448           _pfls.push_back(*it);
2449         }
2450       else
2451         {
2452           int id=std::distance(pfls.begin(),it2);
2453           if(!(*it)->isEqual(*_pfls[id]))
2454             {
2455               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2456               throw INTERP_KERNEL::Exception(oss.str().c_str());
2457             }
2458         }
2459     }
2460   std::vector<std::string> locs=getLocs();
2461   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2462     {
2463       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2464       if(it2==locs.end())
2465         {
2466           _locs.push_back(*it);
2467         }
2468       else
2469         {
2470           int id=std::distance(locs.begin(),it2);
2471           if(!(*it)->isEqual(*_locs[id],eps))
2472             {
2473               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2474               throw INTERP_KERNEL::Exception(oss.str().c_str());
2475             }
2476         }
2477     }
2478 }
2479
2480 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2481 {
2482   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2483     getProfile((*it).c_str());
2484 }
2485
2486 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2487 {
2488   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2489     getLocalization((*it).c_str());
2490 }
2491
2492 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2493 {
2494   std::vector<std::string> profiles=real.getPflsReallyUsed();
2495   int sz=profiles.size();
2496   _pfls.resize(sz);
2497   for(int i=0;i<sz;i++)
2498     loadProfileInFile(fid,i,profiles[i].c_str());
2499   //
2500   std::vector<std::string> locs=real.getLocsReallyUsed();
2501   sz=locs.size();
2502   _locs.resize(sz);
2503   for(int i=0;i<sz;i++)
2504     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2505 }
2506
2507 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2508 {
2509   int nProfil=MEDnProfile(fid);
2510   for(int i=0;i<nProfil;i++)
2511     loadProfileInFile(fid,i);
2512   int sz=MEDnLocalization(fid);
2513   _locs.resize(sz);
2514   for(int i=0;i<sz;i++)
2515     {
2516       _locs[i]=MEDFileFieldLoc::New(fid,i);
2517     }
2518 }
2519
2520 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2521 {
2522   return new MEDFileFieldGlobs(fname);
2523 }
2524
2525 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2526 {
2527   return new MEDFileFieldGlobs;
2528 }
2529
2530 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2531 {
2532   return _file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2533 }
2534
2535 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2536 {
2537   std::vector<const BigMemoryObject *> ret;
2538   for(std::vector< MEDCouplingAutoRefCountObjectPtr< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2539     ret.push_back((const DataArrayInt *)*it);
2540   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2541     ret.push_back((const MEDFileFieldLoc *)*it);
2542   return ret;
2543 }
2544
2545 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const
2546 {
2547   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2548   std::size_t i=0;
2549   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2550     {
2551       if((const DataArrayInt *)*it)
2552         ret->_pfls[i]=(*it)->deepCpy();
2553     }
2554   i=0;
2555   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2556     {
2557       if((const MEDFileFieldLoc*)*it)
2558         ret->_locs[i]=(*it)->deepCpy();
2559     }
2560   return ret.retn();
2561 }
2562
2563 /*!
2564  * \throw if a profile in \a pfls in not in \a this.
2565  * \throw if a localization in \a locs in not in \a this.
2566  * \sa MEDFileFieldGlobs::deepCpyPart
2567  */
2568 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2569 {
2570   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2571   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2572     {
2573       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2574       if(!pfl)
2575         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2576       pfl->incrRef();
2577       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2578       ret->_pfls.push_back(pfl2);
2579     }
2580   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2581     {
2582       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2583       if(!loc)
2584         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2585       loc->incrRef();
2586       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2587       ret->_locs.push_back(loc2);
2588     }
2589   ret->setFileName(getFileName());
2590   return ret.retn();
2591 }
2592
2593 /*!
2594  * \throw if a profile in \a pfls in not in \a this.
2595  * \throw if a localization in \a locs in not in \a this.
2596  * \sa MEDFileFieldGlobs::shallowCpyPart
2597  */
2598 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2599 {
2600   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2601   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2602     {
2603       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2604       if(!pfl)
2605         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2606       ret->_pfls.push_back(pfl->deepCpy());
2607     }
2608   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2609     {
2610       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2611       if(!loc)
2612         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2613       ret->_locs.push_back(loc->deepCpy());
2614     }
2615   ret->setFileName(getFileName());
2616   return ret.retn();
2617 }
2618
2619 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2620 {
2621 }
2622
2623 MEDFileFieldGlobs::MEDFileFieldGlobs()
2624 {
2625 }
2626
2627 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2628 {
2629 }
2630
2631 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2632 {
2633   oss << "Profiles :\n";
2634   std::size_t n=_pfls.size();
2635   for(std::size_t i=0;i<n;i++)
2636     {
2637       oss << "  - #" << i << " ";
2638       const DataArrayInt *pfl=_pfls[i];
2639       if(pfl)
2640         oss << "\"" << pfl->getName() << "\"\n";
2641       else
2642         oss << "EMPTY !\n";
2643     }
2644   n=_locs.size();
2645   oss << "Localizations :\n";
2646   for(std::size_t i=0;i<n;i++)
2647     {
2648       oss << "  - #" << i << " ";
2649       const MEDFileFieldLoc *loc=_locs[i];
2650       if(loc)
2651         loc->simpleRepr(oss);
2652       else
2653         oss<< "EMPTY !\n";
2654     }
2655 }
2656
2657 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2658 {
2659   _file_name=fileName;
2660 }
2661
2662 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2663 {
2664   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2665     {
2666       DataArrayInt *elt(*it);
2667       if(elt)
2668         {
2669           std::string name(elt->getName());
2670           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2671             {
2672               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2673                 {
2674                   elt->setName((*it2).second.c_str());
2675                   return;
2676                 }
2677             }
2678         }
2679     }
2680 }
2681
2682 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2683 {
2684   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2685     {
2686       MEDFileFieldLoc *elt(*it);
2687       if(elt)
2688         {
2689           std::string name(elt->getName());
2690           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2691             {
2692               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2693                 {
2694                   elt->setName((*it2).second.c_str());
2695                   return;
2696                 }
2697             }
2698         }
2699     }
2700 }
2701
2702 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2703 {
2704   if(locId<0 || locId>=(int)_locs.size())
2705     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2706   return _locs[locId]->getNbOfGaussPtPerCell();
2707 }
2708
2709 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2710 {
2711   return getLocalizationFromId(getLocalizationId(locName));
2712 }
2713
2714 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2715 {
2716   if(locId<0 || locId>=(int)_locs.size())
2717     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2718   return *_locs[locId];
2719 }
2720
2721 namespace ParaMEDMEMImpl
2722 {
2723   class LocFinder
2724   {
2725   public:
2726     LocFinder(const std::string& loc):_loc(loc) { }
2727     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2728   private:
2729     const std::string &_loc;
2730   };
2731
2732   class PflFinder
2733   {
2734   public:
2735     PflFinder(const std::string& pfl):_pfl(pfl) { }
2736     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2737   private:
2738     const std::string& _pfl;
2739   };
2740 }
2741
2742 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2743 {
2744   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2745   if(it==_locs.end())
2746     {
2747       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2748       for(it=_locs.begin();it!=_locs.end();it++)
2749         oss << "\"" << (*it)->getName() << "\", ";
2750       throw INTERP_KERNEL::Exception(oss.str().c_str());
2751     }
2752   return std::distance(_locs.begin(),it);
2753 }
2754
2755 /*!
2756  * The returned value is never null.
2757  */
2758 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2759 {
2760   std::string pflNameCpp(pflName);
2761   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2762   if(it==_pfls.end())
2763     {
2764       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2765       for(it=_pfls.begin();it!=_pfls.end();it++)
2766         oss << "\"" << (*it)->getName() << "\", ";
2767       throw INTERP_KERNEL::Exception(oss.str().c_str());
2768     }
2769   return *it;
2770 }
2771
2772 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2773 {
2774   if(pflId<0 || pflId>=(int)_pfls.size())
2775     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2776   return _pfls[pflId];
2777 }
2778
2779 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
2780 {
2781   if(locId<0 || locId>=(int)_locs.size())
2782     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2783   return *_locs[locId];
2784 }
2785
2786 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
2787 {
2788   return getLocalizationFromId(getLocalizationId(locName));
2789 }
2790
2791 /*!
2792  * The returned value is never null.
2793  */
2794 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
2795 {
2796   std::string pflNameCpp(pflName);
2797   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2798   if(it==_pfls.end())
2799     {
2800       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2801       for(it=_pfls.begin();it!=_pfls.end();it++)
2802         oss << "\"" << (*it)->getName() << "\", ";
2803       throw INTERP_KERNEL::Exception(oss.str().c_str());
2804     }
2805   return *it;
2806 }
2807
2808 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
2809 {
2810   if(pflId<0 || pflId>=(int)_pfls.size())
2811     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2812   return _pfls[pflId];
2813 }
2814
2815 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
2816 {
2817   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2818   int i=0;
2819   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2820     {
2821       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2822         newPfls.push_back(*it);
2823     }
2824   _pfls=newPfls;
2825 }
2826
2827 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
2828 {
2829   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2830   int i=0;
2831   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2832     {
2833       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2834         newLocs.push_back(*it);
2835     }
2836   _locs=newLocs;
2837 }
2838
2839 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2840 {
2841   int sz=_pfls.size();
2842   std::vector<std::string> ret(sz);
2843   for(int i=0;i<sz;i++)
2844     ret[i]=_pfls[i]->getName();
2845   return ret;
2846 }
2847
2848 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2849 {
2850   int sz=_locs.size();
2851   std::vector<std::string> ret(sz);
2852   for(int i=0;i<sz;i++)
2853     ret[i]=_locs[i]->getName();
2854   return ret;
2855 }
2856
2857 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
2858 {
2859   std::vector<std::string> v=getPfls();
2860   std::string s(pflName);
2861   return std::find(v.begin(),v.end(),s)!=v.end();
2862 }
2863
2864 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
2865 {
2866   std::vector<std::string> v=getLocs();
2867   std::string s(locName);
2868   return std::find(v.begin(),v.end(),s)!=v.end();
2869 }
2870
2871 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2872 {
2873   std::map<int,std::vector<int> > m;
2874   int i=0;
2875   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2876     {
2877       const DataArrayInt *tmp=(*it);
2878       if(tmp)
2879         {
2880           m[tmp->getHashCode()].push_back(i);
2881         }
2882     }
2883   std::vector< std::vector<int> > ret;
2884   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2885     {
2886       if((*it2).second.size()>1)
2887         {
2888           std::vector<int> ret0;
2889           bool equalityOrNot=false;
2890           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2891             {
2892               std::vector<int>::const_iterator it4=it3; it4++;
2893               for(;it4!=(*it2).second.end();it4++)
2894                 {
2895                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2896                     {
2897                       if(!equalityOrNot)
2898                         ret0.push_back(*it3);
2899                       ret0.push_back(*it4);
2900                       equalityOrNot=true;
2901                     }
2902                 }
2903             }
2904           if(!ret0.empty())
2905             ret.push_back(ret0);
2906         }
2907     }
2908   return ret;
2909 }
2910
2911 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2912 {
2913   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2914 }
2915
2916 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
2917 {
2918   std::string name(pfl->getName());
2919   if(name.empty())
2920     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2921   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2922     if(name==(*it)->getName())
2923       {
2924         if(!pfl->isEqual(*(*it)))
2925           {
2926             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2927             throw INTERP_KERNEL::Exception(oss.str().c_str());
2928           }
2929       }
2930   pfl->incrRef();
2931   _pfls.push_back(pfl);
2932 }
2933
2934 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)
2935 {
2936   std::string name(locName);
2937   if(name.empty())
2938     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2939   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2940   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2941     if((*it)->isName(locName))
2942       {
2943         if(!(*it)->isEqual(*obj,1e-12))
2944           {
2945             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2946             throw INTERP_KERNEL::Exception(oss.str().c_str());
2947           }
2948       }
2949   _locs.push_back(obj);
2950 }
2951
2952 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
2953 {
2954   std::vector<std::string> names=getPfls();
2955   return CreateNewNameNotIn("NewPfl_",names);
2956 }
2957
2958 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
2959 {
2960   std::vector<std::string> names=getLocs();
2961   return CreateNewNameNotIn("NewLoc_",names);
2962 }
2963
2964 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
2965 {
2966   for(std::size_t sz=0;sz<100000;sz++)
2967     {
2968       std::ostringstream tryName;
2969       tryName << prefix << sz;
2970       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2971         return tryName.str();
2972     }
2973   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2974 }
2975
2976 /*!
2977  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
2978  *  \param [in] fname - the file name.
2979  */
2980 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
2981 {
2982 }
2983
2984 /*!
2985  * Creates an empty MEDFileFieldGlobsReal.
2986  */
2987 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
2988 {
2989 }
2990
2991 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
2992 {
2993   return 0;
2994 }
2995
2996 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
2997 {
2998   std::vector<const BigMemoryObject *> ret;
2999   ret.push_back((const MEDFileFieldGlobs *)_globals);
3000   return ret;
3001 }
3002
3003 /*!
3004  * Returns a string describing profiles and Gauss points held in \a this.
3005  *  \return std::string - the description string.
3006  */
3007 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3008 {
3009   const MEDFileFieldGlobs *glob=_globals;
3010   std::ostringstream oss2; oss2 << glob;
3011   std::string stars(oss2.str().length(),'*');
3012   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3013   if(glob)
3014     glob->simpleRepr(oss);
3015   else
3016     oss << "NO GLOBAL INFORMATION !\n";
3017 }
3018
3019 void MEDFileFieldGlobsReal::resetContent()
3020 {
3021   _globals=MEDFileFieldGlobs::New();
3022 }
3023
3024 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3025 {
3026 }
3027
3028 /*!
3029  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3030  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3031  */
3032 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3033 {
3034   _globals=other._globals;
3035 }
3036
3037 /*!
3038  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3039  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3040  */
3041 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3042 {
3043   const MEDFileFieldGlobs *otherg(other._globals);
3044   if(!otherg)
3045     return ;
3046   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3047 }
3048
3049 /*!
3050  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3051  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3052  */
3053 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3054 {
3055   const MEDFileFieldGlobs *otherg(other._globals);
3056   if(!otherg)
3057     return ;
3058   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3059 }
3060
3061 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3062 {
3063   _globals=other._globals;
3064   if((const MEDFileFieldGlobs *)_globals)
3065     _globals=other._globals->deepCpy();
3066 }
3067
3068 /*!
3069  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3070  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3071  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3072  *         \a this and \a other MEDFileFieldGlobsReal.
3073  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3074  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3075  */
3076 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3077 {
3078   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3079   if(thisGlobals==otherGlobals)
3080     return ;
3081   if(!thisGlobals)
3082     {
3083       _globals=other._globals;
3084       return ;
3085     }
3086   _globals->appendGlobs(*other._globals,eps);
3087 }
3088
3089 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3090 {
3091   checkGlobsPflsPartCoherency();
3092   checkGlobsLocsPartCoherency();
3093 }
3094
3095 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3096 {
3097   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3098 }
3099
3100 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3101 {
3102   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3103 }
3104
3105 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3106 {
3107   contentNotNull()->loadProfileInFile(fid,id,pflName);
3108 }
3109
3110 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3111 {
3112   contentNotNull()->loadProfileInFile(fid,id);
3113 }
3114
3115 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3116 {
3117   contentNotNull()->loadGlobals(fid,*this);
3118 }
3119
3120 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3121 {
3122   contentNotNull()->loadAllGlobals(fid);
3123 }
3124
3125 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3126 {
3127   contentNotNull()->writeGlobals(fid,opt);
3128 }
3129
3130 /*!
3131  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3132  * or getPflsReallyUsedMulti().
3133  *  \return std::vector<std::string> - a sequence of names of all profiles.
3134  */
3135 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3136 {
3137   return contentNotNull()->getPfls();
3138 }
3139
3140 /*!
3141  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3142  * or getLocsReallyUsedMulti().
3143  *  \return std::vector<std::string> - a sequence of names of all localizations.
3144  */
3145 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3146 {
3147   return contentNotNull()->getLocs();
3148 }
3149
3150 /*!
3151  * Checks if the profile with a given name exists.
3152  *  \param [in] pflName - the profile name of interest.
3153  *  \return bool - \c true if the profile named \a pflName exists.
3154  */
3155 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3156 {
3157   return contentNotNull()->existsPfl(pflName);
3158 }
3159
3160 /*!
3161  * Checks if the localization with a given name exists.
3162  *  \param [in] locName - the localization name of interest.
3163  *  \return bool - \c true if the localization named \a locName exists.
3164  */
3165 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3166 {
3167   return contentNotNull()->existsLoc(locName);
3168 }
3169
3170 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3171 {
3172   return contentNotNull()->createNewNameOfPfl();
3173 }
3174
3175 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3176 {
3177   return contentNotNull()->createNewNameOfLoc();
3178 }
3179
3180 /*!
3181  * Sets the name of a MED file.
3182  *  \param [inout] fileName - the file name.
3183  */
3184 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3185 {
3186   contentNotNull()->setFileName(fileName);
3187 }
3188
3189 /*!
3190  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3191  * in the same order.
3192  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3193  *          Each item of this sequence is a vector containing ids of equal profiles.
3194  */
3195 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3196 {
3197   return contentNotNull()->whichAreEqualProfiles();
3198 }
3199
3200 /*!
3201  * Finds equal localizations.
3202  *  \param [in] eps - a precision used to compare real values of the localizations.
3203  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3204  *          Each item of this sequence is a vector containing ids of equal localizations.
3205  */
3206 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3207 {
3208   return contentNotNull()->whichAreEqualLocs(eps);
3209 }
3210
3211 /*!
3212  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3213  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3214  *        this sequence is a pair whose 
3215  *        - the first item is a vector of profile names to replace by the second item,
3216  *        - the second item is a profile name to replace every profile name of the first item.
3217  */
3218 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3219 {
3220   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3221 }
3222
3223 /*!
3224  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3225  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3226  *        this sequence is a pair whose 
3227  *        - the first item is a vector of localization names to replace by the second item,
3228  *        - the second item is a localization name to replace every localization name of the first item.
3229  */
3230 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3231 {
3232   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3233 }
3234
3235 /*!
3236  * Replaces references to some profiles (a reference is a profile name) by references
3237  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3238  * them-selves accordingly. <br>
3239  * This method is a generalization of changePflName().
3240  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3241  *        this sequence is a pair whose 
3242  *        - the first item is a vector of profile names to replace by the second item,
3243  *        - the second item is a profile name to replace every profile of the first item.
3244  * \sa changePflsRefsNamesGen()
3245  * \sa changePflName()
3246  */
3247 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3248 {
3249   changePflsRefsNamesGen(mapOfModif);
3250   changePflsNamesInStruct(mapOfModif);
3251 }
3252
3253 /*!
3254  * Replaces references to some localizations (a reference is a localization name) by references
3255  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3256  * them-selves accordingly. <br>
3257  * This method is a generalization of changeLocName().
3258  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3259  *        this sequence is a pair whose 
3260  *        - the first item is a vector of localization names to replace by the second item,
3261  *        - the second item is a localization name to replace every localization of the first item.
3262  * \sa changeLocsRefsNamesGen()
3263  * \sa changeLocName()
3264  */
3265 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3266 {
3267   changeLocsRefsNamesGen(mapOfModif);
3268   changeLocsNamesInStruct(mapOfModif);
3269 }
3270
3271 /*!
3272  * Renames the profile having a given name and updates references to this profile.
3273  *  \param [in] oldName - the name of the profile to rename.
3274  *  \param [in] newName - a new name of the profile.
3275  * \sa changePflsNames().
3276  */
3277 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3278 {
3279   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3280   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3281   mapOfModif[0]=p;
3282   changePflsNames(mapOfModif);
3283 }
3284
3285 /*!
3286  * Renames the localization having a given name and updates references to this localization.
3287  *  \param [in] oldName - the name of the localization to rename.
3288  *  \param [in] newName - a new name of the localization.
3289  * \sa changeLocsNames().
3290  */
3291 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3292 {
3293   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3294   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3295   mapOfModif[0]=p;
3296   changeLocsNames(mapOfModif);
3297 }
3298
3299 /*!
3300  * Removes duplicated profiles. Returns a map used to update references to removed 
3301  * profiles via changePflsRefsNamesGen().
3302  * Equal profiles are found using whichAreEqualProfiles().
3303  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3304  *          a sequence describing the performed replacements of profiles. Each element of
3305  *          this sequence is a pair whose
3306  *          - the first item is a vector of profile names replaced by the second item,
3307  *          - the second item is a profile name replacing every profile of the first item.
3308  */
3309 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3310 {
3311   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3312   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3313   int i=0;
3314   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3315     {
3316       std::vector< std::string > tmp((*it).size());
3317       int j=0;
3318       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3319         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3320       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3321       ret[i]=p;
3322       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3323       killProfileIds(tmp2);
3324     }
3325   changePflsRefsNamesGen(ret);
3326   return ret;
3327 }
3328
3329 /*!
3330  * Removes duplicated localizations. Returns a map used to update references to removed 
3331  * localizations via changeLocsRefsNamesGen().
3332  * Equal localizations are found using whichAreEqualLocs().
3333  *  \param [in] eps - a precision used to compare real values of the localizations.
3334  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3335  *          a sequence describing the performed replacements of localizations. Each element of
3336  *          this sequence is a pair whose
3337  *          - the first item is a vector of localization names replaced by the second item,
3338  *          - the second item is a localization name replacing every localization of the first item.
3339  */
3340 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3341 {
3342   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3343   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3344   int i=0;
3345   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3346     {
3347       std::vector< std::string > tmp((*it).size());
3348       int j=0;
3349       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3350         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3351       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3352       ret[i]=p;
3353       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3354       killLocalizationIds(tmp2);
3355     }
3356   changeLocsRefsNamesGen(ret);
3357   return ret;
3358 }
3359
3360 /*!
3361  * Returns number of Gauss points per cell in a given localization.
3362  *  \param [in] locId - an id of the localization of interest.
3363  *  \return int - the number of the Gauss points per cell.
3364  */
3365 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3366 {
3367   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3368 }
3369
3370 /*!
3371  * Returns an id of a localization by its name.
3372  *  \param [in] loc - the localization name of interest.
3373  *  \return int - the id of the localization.
3374  *  \throw If there is no a localization named \a loc.
3375  */
3376 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3377 {
3378   return contentNotNull()->getLocalizationId(loc);
3379 }
3380
3381 /*!
3382  * Returns the name of the MED file.
3383  *  \return const std::string&  - the MED file name.
3384  */
3385 std::string MEDFileFieldGlobsReal::getFileName() const
3386 {
3387   return contentNotNull()->getFileName();
3388 }
3389
3390 /*!
3391  * Returns a localization object by its name.
3392  *  \param [in] locName - the name of the localization of interest.
3393  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3394  *  \throw If there is no a localization named \a locName.
3395  */
3396 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3397 {
3398   return contentNotNull()->getLocalization(locName);
3399 }
3400
3401 /*!
3402  * Returns a localization object by its id.
3403  *  \param [in] locId - the id of the localization of interest.
3404  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3405  *  \throw If there is no a localization with id \a locId.
3406  */
3407 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3408 {
3409   return contentNotNull()->getLocalizationFromId(locId);
3410 }
3411
3412 /*!
3413  * Returns a profile array by its name.
3414  *  \param [in] pflName - the name of the profile of interest.
3415  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3416  *  \throw If there is no a profile named \a pflName.
3417  */
3418 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3419 {
3420   return contentNotNull()->getProfile(pflName);
3421 }
3422
3423 /*!
3424  * Returns a profile array by its id.
3425  *  \param [in] pflId - the id of the profile of interest.
3426  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3427  *  \throw If there is no a profile with id \a pflId.
3428  */
3429 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3430 {
3431   return contentNotNull()->getProfileFromId(pflId);
3432 }
3433
3434 /*!
3435  * Returns a localization object, apt for modification, by its id.
3436  *  \param [in] locId - the id of the localization of interest.
3437  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3438  *          having the id \a locId.
3439  *  \throw If there is no a localization with id \a locId.
3440  */
3441 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3442 {
3443   return contentNotNull()->getLocalizationFromId(locId);
3444 }
3445
3446 /*!
3447  * Returns a localization object, apt for modification, by its name.
3448  *  \param [in] locName - the name of the localization of interest.
3449  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3450  *          having the name \a locName.
3451  *  \throw If there is no a localization named \a locName.
3452  */
3453 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3454 {
3455   return contentNotNull()->getLocalization(locName);
3456 }
3457
3458 /*!
3459  * Returns a profile array, apt for modification, by its name.
3460  *  \param [in] pflName - the name of the profile of interest.
3461  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3462  *  \throw If there is no a profile named \a pflName.
3463  */
3464 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3465 {
3466   return contentNotNull()->getProfile(pflName);
3467 }
3468
3469 /*!
3470  * Returns a profile array, apt for modification, by its id.
3471  *  \param [in] pflId - the id of the profile of interest.
3472  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3473  *  \throw If there is no a profile with id \a pflId.
3474  */
3475 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3476 {
3477   return contentNotNull()->getProfileFromId(pflId);
3478 }
3479
3480 /*!
3481  * Removes profiles given by their ids. No data is updated to track this removal.
3482  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3483  */
3484 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3485 {
3486   contentNotNull()->killProfileIds(pflIds);
3487 }
3488
3489 /*!
3490  * Removes localizations given by their ids. No data is updated to track this removal.
3491  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3492  */
3493 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3494 {
3495   contentNotNull()->killLocalizationIds(locIds);
3496 }
3497
3498 /*!
3499  * Stores a profile array.
3500  *  \param [in] pfl - the profile array to store.
3501  *  \throw If the name of \a pfl is empty.
3502  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3503  *         different ids.
3504  */
3505 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3506 {
3507   contentNotNull()->appendProfile(pfl);
3508 }
3509
3510 /*!
3511  * Adds a new localization of Gauss points.
3512  *  \param [in] locName - the name of the new localization.
3513  *  \param [in] geoType - a geometrical type of the reference cell.
3514  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3515  *         must be \c nbOfNodesPerCell * \c dimOfType.
3516  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3517  *         must be  _wg_.size() * \c dimOfType.
3518  *  \param [in] w - the weights of Gauss points.
3519  *  \throw If \a locName is empty.
3520  *  \throw If a localization with the name \a locName already exists but is
3521  *         different form the new one.
3522  */
3523 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)
3524 {
3525   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3526 }
3527
3528 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3529 {
3530   MEDFileFieldGlobs *g(_globals);
3531   if(!g)
3532     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3533   return g;
3534 }
3535
3536 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3537 {
3538   const MEDFileFieldGlobs *g(_globals);
3539   if(!g)
3540     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3541   return g;
3542 }
3543
3544 //= MEDFileFieldNameScope
3545
3546 MEDFileFieldNameScope::MEDFileFieldNameScope()
3547 {
3548 }
3549
3550 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3551 {
3552 }
3553
3554 /*!
3555  * Returns the name of \a this field.
3556  *  \return std::string - a string containing the field name.
3557  */
3558 std::string MEDFileFieldNameScope::getName() const
3559 {
3560   return _name;
3561 }
3562
3563 /*!
3564  * Sets name of \a this field
3565  *  \param [in] name - the new field name.
3566  */
3567 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3568 {
3569   _name=fieldName;
3570 }
3571
3572 std::string MEDFileFieldNameScope::getDtUnit() const
3573 {
3574   return _dt_unit;
3575 }
3576
3577 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3578 {
3579   _dt_unit=dtUnit;
3580 }
3581
3582 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3583 {
3584   _name=other._name;
3585   _dt_unit=other._dt_unit;
3586 }
3587
3588 //= MEDFileAnyTypeField1TSWithoutSDA
3589
3590 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3591 {
3592   _field_per_mesh.resize(other._field_per_mesh.size());
3593   std::size_t i=0;
3594   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3595     {
3596       if((const MEDFileFieldPerMesh *)*it)
3597         _field_per_mesh[i]=(*it)->deepCpy(this);
3598     }
3599 }
3600
3601 /*!
3602  * Prints a string describing \a this field into a stream. This string is outputted 
3603  * by \c print Python command.
3604  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3605  *  \param [in,out] oss - the out stream.
3606  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3607  *          info id printed, else, not.
3608  */
3609 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3610 {
3611   std::string startOfLine(bkOffset,' ');
3612   oss << startOfLine << "Field ";
3613   if(bkOffset==0)
3614     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3615   oss << "on one time Step ";
3616   if(f1tsId>=0)
3617     oss << "(" << f1tsId << ") ";
3618   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3619   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3620   const DataArray *arr=getUndergroundDataArray();
3621   if(arr)
3622     {
3623       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3624       if(f1tsId<0)
3625         {
3626           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3627           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3628             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3629         }
3630       if(arr->isAllocated())
3631         {
3632           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3633         }
3634       else
3635         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3636     }
3637   else
3638     {
3639       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3640     }
3641   oss << startOfLine << "----------------------" << std::endl;
3642   if(!_field_per_mesh.empty())
3643     {
3644       int i=0;
3645       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3646         {
3647           const MEDFileFieldPerMesh *cur=(*it2);
3648           if(cur)
3649             cur->simpleRepr(bkOffset,oss,i);
3650           else
3651             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3652         }
3653     }
3654   else
3655     {
3656       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3657     }
3658   oss << startOfLine << "----------------------" << std::endl;
3659 }
3660
3661 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3662 {
3663   const DataArray *arr(getUndergroundDataArray());
3664   if(!arr)
3665     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3666   int nbOfCompo=arr->getNumberOfComponents();
3667   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3668   for(int i=0;i<nbOfCompo;i++)
3669     {
3670       ret[i]=deepCpy();
3671       std::vector<int> v(1,i);
3672       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3673       ret[i]->setArray(arr2);
3674     }
3675   return ret;
3676 }
3677
3678 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)
3679 {
3680 }
3681
3682 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3683 {
3684 }
3685
3686 /*!
3687  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3688  * empty. Returns -1 if this in on nodes.
3689  *  \return int - the dimension of \a this.
3690  */
3691 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3692 {
3693   int ret=-2;
3694   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3695     (*it)->getDimension(ret);
3696   return ret;
3697 }
3698
3699 /*!
3700  * Returns the mesh name.
3701  *  \return std::string - a string holding the mesh name.
3702  *  \throw If \c _field_per_mesh.empty()
3703  */
3704 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3705 {
3706   if(_field_per_mesh.empty())
3707     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3708   return _field_per_mesh[0]->getMeshName();
3709 }
3710
3711 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3712 {
3713   std::string oldName(getMeshName());
3714   std::vector< std::pair<std::string,std::string> > v(1);
3715   v[0].first=oldName; v[0].second=newMeshName;
3716   changeMeshNames(v);
3717 }
3718
3719 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3720 {
3721   bool ret=false;
3722   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3723     {
3724       MEDFileFieldPerMesh *cur(*it);
3725       if(cur)
3726         ret=cur->changeMeshNames(modifTab) || ret;
3727     }
3728   return ret;
3729 }
3730
3731 /*!
3732  * Returns the number of iteration of the state of underlying mesh.
3733  *  \return int - the iteration number.
3734  *  \throw If \c _field_per_mesh.empty()
3735  */
3736 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3737 {
3738   if(_field_per_mesh.empty())
3739     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3740   return _field_per_mesh[0]->getMeshIteration();
3741 }
3742
3743 /*!
3744  * Returns the order number of iteration of the state of underlying mesh.
3745  *  \return int - the order number.
3746  *  \throw If \c _field_per_mesh.empty()
3747  */
3748 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3749 {
3750   if(_field_per_mesh.empty())
3751     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3752   return _field_per_mesh[0]->getMeshOrder();
3753 }
3754
3755 /*!
3756  * Checks if \a this field is tagged by a given iteration number and a given
3757  * iteration order number.
3758  *  \param [in] iteration - the iteration number of interest.
3759  *  \param [in] order - the iteration order number of interest.
3760  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3761  *          \a this->getOrder() == \a order.
3762  */
3763 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3764 {
3765   return iteration==_iteration && order==_order;
3766 }
3767
3768 /*!
3769  * Returns number of iteration and order number of iteration when
3770  * \a this field has been calculated.
3771  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3772  *          order number.
3773  */
3774 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3775 {
3776   std::pair<int,int> p;
3777   fillIteration(p);
3778   return p;
3779 }
3780
3781 /*!
3782  * Returns number of iteration and order number of iteration when
3783  * \a this field has been calculated.
3784  *  \param [in,out] p - a pair returning the iteration number and the iteration
3785  *          order number.
3786  */
3787 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3788 {
3789   p.first=_iteration;
3790   p.second=_order;
3791 }
3792
3793 /*!
3794  * Returns all types of spatial discretization of \a this field.
3795  *  \param [in,out] types - a sequence of types of \a this field.
3796  */
3797 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
3798 {
3799   std::set<TypeOfField> types2;
3800   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3801     {
3802       (*it)->fillTypesOfFieldAvailable(types2);
3803     }
3804   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3805   std::copy(types2.begin(),types2.end(),bi);
3806 }
3807
3808 /*!
3809  * Returns all types of spatial discretization of \a this field.
3810  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3811  *          of \a this field.
3812  */
3813 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
3814 {
3815   std::vector<TypeOfField> ret;
3816   fillTypesOfFieldAvailable(ret);
3817   return ret;
3818 }
3819
3820 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3821 {
3822   std::vector<std::string> ret;
3823   std::set<std::string> ret2;
3824   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3825     {
3826       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3827       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3828         if(ret2.find(*it2)==ret2.end())
3829           {
3830             ret.push_back(*it2);
3831             ret2.insert(*it2);
3832           }
3833     }
3834   return ret;
3835 }
3836
3837 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3838 {
3839   std::vector<std::string> ret;
3840   std::set<std::string> ret2;
3841   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3842     {
3843       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3844       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3845         if(ret2.find(*it2)==ret2.end())
3846           {
3847             ret.push_back(*it2);
3848             ret2.insert(*it2);
3849           }
3850     }
3851   return ret;
3852 }
3853
3854 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3855 {
3856   std::vector<std::string> ret;
3857   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3858     {
3859       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3860       ret.insert(ret.end(),tmp.begin(),tmp.end());
3861     }
3862   return ret;
3863 }
3864
3865 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3866 {
3867   std::vector<std::string> ret;
3868   std::set<std::string> ret2;
3869   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3870     {
3871       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3872       ret.insert(ret.end(),tmp.begin(),tmp.end());
3873     }
3874   return ret;
3875 }
3876
3877 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3878 {
3879   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3880     (*it)->changePflsRefsNamesGen(mapOfModif);
3881 }
3882
3883 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3884 {
3885   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3886     (*it)->changeLocsRefsNamesGen(mapOfModif);
3887 }
3888
3889 /*!
3890  * Returns all attributes of parts of \a this field lying on a given mesh.
3891  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3892  * item of every of returned sequences refers to the _i_-th part of \a this field.
3893  * Thus all sequences returned by this method are of the same length equal to number
3894  * of different types of supporting entities.<br>
3895  * A field part can include sub-parts with several different spatial discretizations,
3896  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3897  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3898  * of a nested sequence corresponds to a type of spatial discretization.<br>
3899  * This method allows for iteration over MEDFile DataStructure without any overhead.
3900  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3901  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3902  *          not checked if \a mname == \c NULL).
3903  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3904  *          a field part is returned. 
3905  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3906  *          This sequence is of the same length as \a types. 
3907  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3908  *          discretization. A profile name can be empty.
3909  *          Length of this and of nested sequences is the same as that of \a typesF.
3910  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3911  *          discretization. A localization name can be empty.
3912  *          Length of this and of nested sequences is the same as that of \a typesF.
3913  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3914  *          of ids of tuples within the data array, per each type of spatial
3915  *          discretization within one mesh entity type. 
3916  *          Length of this and of nested sequences is the same as that of \a typesF.
3917  *  \throw If no field is lying on \a mname.
3918  */
3919 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
3920 {
3921   int meshId=0;
3922   if(!mname.empty())
3923     meshId=getMeshIdFromMeshName(mname);
3924   else
3925     if(_field_per_mesh.empty())
3926       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3927   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3928 }
3929
3930 /*!
3931  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3932  * maximal absolute dimension and values returned via the out parameter \a levs are 
3933  * dimensions relative to the maximal absolute dimension. <br>
3934  * This method is designed for MEDFileField1TS instances that have a discretization
3935  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3936  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3937  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3938  * Only these 3 discretizations will be taken into account here. If \a this is
3939  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3940  * This method is useful to make the link between the dimension of the underlying mesh
3941  * and the levels of \a this, because it is possible that the highest dimension of \a this
3942  * field is not equal to the dimension of the underlying mesh.
3943  * 
3944  * Let's consider the following case:
3945  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3946  * TETRA4, HEXA8, TRI3 and SEG2.
3947  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
3948  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
3949  *
3950  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
3951  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
3952  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
3953  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
3954  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
3955  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
3956  * For example<br>
3957  * to retrieve the highest level of
3958  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
3959  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
3960  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
3961  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
3962  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3963  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3964  *          not checked if \a mname == \c NULL).
3965  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
3966  *          absolute one. They are in decreasing order. This sequence is cleared before
3967  *          filling it in.
3968  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
3969  *  \throw If no field is lying on \a mname.
3970  */
3971 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
3972 {
3973   levs.clear();
3974   int meshId=getMeshIdFromMeshName(mname);
3975   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3976   std::vector< std::vector<TypeOfField> > typesF;
3977   std::vector< std::vector<std::string> > pfls, locs;
3978   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3979   if(types.empty())
3980     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3981   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3982   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3983     return -1;
3984   st.erase(INTERP_KERNEL::NORM_ERROR);
3985   std::set<int> ret1;
3986   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3987     {
3988       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
3989       ret1.insert((int)cm.getDimension());
3990     }
3991   int ret=*std::max_element(ret1.begin(),ret1.end());
3992   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
3993   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
3994   return ret;
3995 }
3996
3997 /*!
3998  * \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.
3999  * \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.
4000  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4001  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4002  */
4003 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4004 {
4005   int mid=getMeshIdFromMeshName(mName);
4006   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4007 }
4008
4009 /*!
4010  * \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.
4011  * \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.
4012  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4013  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4014  */
4015 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4016 {
4017   int mid=getMeshIdFromMeshName(mName);
4018   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4019 }
4020
4021 /*!
4022  * \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.
4023  */
4024 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4025 {
4026   if(_field_per_mesh.empty())
4027     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4028   if(mName.empty())
4029     return 0;
4030   std::string mName2(mName);
4031   int ret=0;
4032   std::vector<std::string> msg;
4033   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4034     if(mName2==(*it)->getMeshName())
4035       return ret;
4036     else
4037       msg.push_back((*it)->getMeshName());
4038   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4039   oss << "Possible meshes are : ";
4040   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4041     oss << "\"" << (*it2) << "\" ";
4042   throw INTERP_KERNEL::Exception(oss.str().c_str());
4043 }
4044
4045 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4046 {
4047   if(!mesh)
4048     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4049   std::string tmp(mesh->getName());
4050   if(tmp.empty())
4051     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4052   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4053   int i=0;
4054   for(;it!=_field_per_mesh.end();it++,i++)
4055     {
4056       if((*it)->getMeshName()==tmp)
4057         return i;
4058     }
4059   int sz=_field_per_mesh.size();
4060   _field_per_mesh.resize(sz+1);
4061   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4062   return sz;
4063 }
4064
4065 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4066                                                                    MEDFileFieldGlobsReal& glob)
4067 {
4068   bool ret=false;
4069   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4070     {
4071       MEDFileFieldPerMesh *fpm(*it);
4072       if(fpm)
4073         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4074     }
4075   return ret;
4076 }
4077
4078 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4079 {
4080   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4081   std::vector< std::vector<TypeOfField> > typesF;
4082   std::vector< std::vector<std::string> > pfls,locs;
4083   std::vector< std::vector<std::pair<int,int> > > bgEnd=getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs);
4084   std::set<TypeOfField> allEnt;
4085   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4086     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4087       allEnt.insert(*it2);
4088   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4089   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4090   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4091     {
4092       std::vector< std::pair<int,int> > its;
4093       ret[i]=shallowCpy();
4094       int newLgth=ret[i]->keepOnlySpatialDiscretization(*it3,its);
4095       ret[i]->updateData(newLgth,its);
4096     }
4097   return ret;
4098 }
4099
4100 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4101 {
4102   int globalCounter=0;
4103   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4104     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4105   return globalCounter;
4106 }
4107
4108 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4109 {
4110   if(_nb_of_tuples_to_be_allocated>=0)
4111     {
4112       _nb_of_tuples_to_be_allocated=newLgth;
4113       const DataArray *oldArr(getUndergroundDataArray());
4114       if(oldArr)
4115         {
4116           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4117           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4118           setArray(newArr);
4119           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4120         }
4121       return ;
4122     }
4123   if(_nb_of_tuples_to_be_allocated==-1)
4124     return ;
4125   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4126     {
4127       const DataArray *oldArr(getUndergroundDataArray());
4128       if(!oldArr || !oldArr->isAllocated())
4129         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4130       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4131       newArr->alloc(newLgth,getNumberOfComponents());
4132       if(oldArr)
4133         newArr->copyStringInfoFrom(*oldArr);
4134       int pos=0;
4135       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4136         {
4137           if((*it).second<(*it).first)
4138             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4139           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4140           pos+=(*it).second-(*it).first;
4141         }
4142       setArray(newArr);
4143       return ;
4144     }
4145   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4146 }
4147
4148 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4149 {
4150   if(_field_per_mesh.empty())
4151     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4152   if(_field_per_mesh.size()>1)
4153     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4154   _field_per_mesh[0]->copyOptionsFrom(opts);
4155   _field_per_mesh[0]->writeLL(fid,nasc);
4156 }
4157
4158 /*!
4159  * 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.
4160  * If false is returned the memory allocation is not required.
4161  */
4162 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4163 {
4164   if(_nb_of_tuples_to_be_allocated>=0)
4165     {
4166       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4167       _nb_of_tuples_to_be_allocated=-2;
4168       return true;
4169     }
4170   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4171     return false;
4172   if(_nb_of_tuples_to_be_allocated==-1)
4173     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4174   if(_nb_of_tuples_to_be_allocated<-3)
4175     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4176   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4177 }
4178
4179 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4180 {
4181   med_int numdt,numit;
4182   med_float dt;
4183   med_int nmesh;
4184   med_bool localMesh;
4185   med_int meshnumdt,meshnumit;
4186   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4187   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4188   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4189   if(_iteration!=numdt || _order!=numit)
4190     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4191   _field_per_mesh.resize(nmesh);
4192   for(int i=0;i<nmesh;i++)
4193     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit,nasc);//tony
4194   _nb_of_tuples_to_be_allocated=0;
4195   for(int i=0;i<nmesh;i++)
4196     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4197 }
4198
4199 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4200 {
4201   allocIfNecessaryTheArrayToReceiveDataFromFile();
4202   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4203     (*it)->loadBigArraysRecursively(fid,nasc);
4204 }
4205
4206 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4207 {
4208   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4209     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4210       (*it)->loadBigArraysRecursively(fid,nasc);
4211 }
4212
4213 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4214 {
4215   loadOnlyStructureOfDataRecursively(fid,nasc);
4216   loadBigArraysRecursively(fid,nasc);
4217 }
4218
4219 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4220 {
4221   DataArray *thisArr(getUndergroundDataArray());
4222   if(thisArr && thisArr->isAllocated())
4223     {
4224       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4225       thisArr->desallocate();
4226     }
4227 }
4228
4229 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4230 {
4231   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4232 }
4233
4234 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4235 {
4236   std::vector<const BigMemoryObject *> ret;
4237   if(getUndergroundDataArray())
4238     ret.push_back(getUndergroundDataArray());
4239   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4240     ret.push_back((const MEDFileFieldPerMesh *)*it);
4241   return ret;
4242 }
4243
4244 /*!
4245  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4246  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4247  * "Sort By Type"), if not, an exception is thrown. 
4248  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4249  *  \param [in] arr - the array of values.
4250  *  \param [in,out] glob - the global data where profiles and localization present in
4251  *          \a field, if any, are added.
4252  *  \throw If the name of \a field is empty.
4253  *  \throw If the data array of \a field is not set.
4254  *  \throw If \a this->_arr is already allocated but has different number of components
4255  *         than \a field.
4256  *  \throw If the underlying mesh of \a field has no name.
4257  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4258  */
4259 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4260 {
4261   const MEDCouplingMesh *mesh=field->getMesh();
4262   //
4263   TypeOfField type=field->getTypeOfField();
4264   std::vector<DataArrayInt *> dummy;
4265   int start=copyTinyInfoFrom(field,arr);
4266   int pos=addNewEntryIfNecessary(mesh);
4267   if(type!=ON_NODES)
4268     {
4269       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4270       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4271     }
4272   else
4273     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4274 }
4275
4276 /*!
4277  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4278  * of a given mesh are used as the support of the given field (a real support is not used). 
4279  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4280  * Order of underlying mesh entities of the given field specified by \a profile parameter
4281  * is not prescribed; this method permutes field values to have them sorted by element
4282  * type as required for writing to MED file. A new profile is added only if no equal
4283  * profile is missing. 
4284  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4285  *  \param [in] arrOfVals - the values of the field \a field used.
4286  *  \param [in] mesh - the supporting mesh of \a field.
4287  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4288  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4289  *  \param [in,out] glob - the global data where profiles and localization present in
4290  *          \a field, if any, are added.
4291  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4292  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4293  *  \throw If the data array of \a field is not set.
4294  *  \throw If \a this->_arr is already allocated but has different number of components
4295  *         than \a field.
4296  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4297  *  \sa setFieldNoProfileSBT()
4298  */
4299 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4300 {
4301   if(!field)
4302     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4303   if(!arrOfVals || !arrOfVals->isAllocated())
4304     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4305   TypeOfField type=field->getTypeOfField();
4306   std::vector<DataArrayInt *> idsInPflPerType;
4307   std::vector<DataArrayInt *> idsPerType;
4308   std::vector<int> code,code2;
4309   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4310   if(type!=ON_NODES)
4311     {
4312       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4313       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4314       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4315       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4316       // start of check
4317       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4318       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4319       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4320         {
4321           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4322           throw INTERP_KERNEL::Exception(oss.str().c_str());
4323         }
4324       // end of check
4325       int start=copyTinyInfoFrom(field,arrOfVals);
4326       code2=m->getDistributionOfTypes();
4327       //
4328       int pos=addNewEntryIfNecessary(m);
4329       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4330     }
4331   else
4332     {
4333       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4334         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4335       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4336       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4337       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4338       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4339         {
4340           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4341           throw INTERP_KERNEL::Exception(oss.str().c_str());
4342         }
4343       int start=copyTinyInfoFrom(field,arrOfVals);
4344       int pos=addNewEntryIfNecessary(m);
4345       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4346     }
4347 }
4348
4349 /*!
4350  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4351  */
4352 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4353 {
4354   if(_nb_of_tuples_to_be_allocated>=0)
4355     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 !");
4356   DataArray *arr(getOrCreateAndGetArray());
4357   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4358   _nb_of_tuples_to_be_allocated=-3;
4359 }
4360
4361 /*!
4362  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4363  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4364  * larger by the size of \a field. Returns an id of the first not filled
4365  * tuple of \a this->_arr.
4366  *  \param [in] field - the field to copy the info on components and the name from.
4367  *  \return int - the id of first not initialized tuple of \a this->_arr.
4368  *  \throw If the name of \a field is empty.
4369  *  \throw If the data array of \a field is not set.
4370  *  \throw If \a this->_arr is already allocated but has different number of components
4371  *         than \a field.
4372  */
4373 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4374 {
4375   if(!field)
4376     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4377   std::string name(field->getName());
4378   setName(name.c_str());
4379   setDtUnit(field->getTimeUnit());
4380   if(name.empty())
4381     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4382   if(!arr)
4383     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4384   if(!arr->isAllocated())
4385     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4386   _dt=field->getTime(_iteration,_order);
4387   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4388   if(!getOrCreateAndGetArray()->isAllocated())
4389     {
4390       allocNotFromFile(arr->getNumberOfTuples());
4391       return 0;
4392     }
4393   else
4394     {
4395       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4396       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4397       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4398       _nb_of_tuples_to_be_allocated=-3;
4399       return oldNbOfTuples;
4400     }
4401 }
4402
4403 /*!
4404  * Returns number of components in \a this field
4405  *  \return int - the number of components.
4406  */
4407 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4408 {
4409   return getOrCreateAndGetArray()->getNumberOfComponents();
4410 }
4411
4412 /*!
4413  * Change info on components in \a this.
4414  * \throw If size of \a infos is not equal to the number of components already in \a this.
4415  */
4416 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4417 {
4418   DataArray *arr=getOrCreateAndGetArray();
4419   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4420 }
4421
4422 /*!
4423  * Returns info on components of \a this field.
4424  *  \return const std::vector<std::string>& - a sequence of strings each being an
4425  *          information on _i_-th component.
4426  */
4427 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4428 {
4429   const DataArray *arr=getOrCreateAndGetArray();
4430   return arr->getInfoOnComponents();
4431 }
4432
4433 /*!
4434  * Returns a mutable info on components of \a this field.
4435  *  \return std::vector<std::string>& - a sequence of strings each being an
4436  *          information on _i_-th component.
4437  */
4438 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4439 {
4440   DataArray *arr=getOrCreateAndGetArray();
4441   return arr->getInfoOnComponents();
4442 }
4443
4444 /*!
4445  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4446  *  \param [in] type - a spatial discretization of the new field.
4447  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4448  *  \param [in] mName - a name of the supporting mesh.
4449  *  \param [in] renumPol - specifies how to permute values of the result field according to
4450  *          the optional numbers of cells and nodes, if any. The valid values are
4451  *          - 0 - do not permute.
4452  *          - 1 - permute cells.
4453  *          - 2 - permute nodes.
4454  *          - 3 - permute cells and nodes.
4455  *
4456  *  \param [in] glob - the global data storing profiles and localization.
4457  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4458  *          caller is to delete this field using decrRef() as it is no more needed. 
4459  *  \throw If the MED file is not readable.
4460  *  \throw If there is no mesh named \a mName in the MED file.
4461  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4462  *  \throw If no field of \a this is lying on the mesh \a mName.
4463  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4464  */
4465 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4466 {
4467   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4468   if(mName.empty())
4469     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4470   else
4471     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4472   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4473 }
4474
4475 /*!
4476  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4477  *  \param [in] type - a spatial discretization of the new field.
4478  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4479  *  \param [in] renumPol - specifies how to permute values of the result field according to
4480  *          the optional numbers of cells and nodes, if any. The valid values are
4481  *          - 0 - do not permute.
4482  *          - 1 - permute cells.
4483  *          - 2 - permute nodes.
4484  *          - 3 - permute cells and nodes.
4485  *
4486  *  \param [in] glob - the global data storing profiles and localization.
4487  *  \param [in] mesh - the supporting mesh.
4488  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4489  *          caller is to delete this field using decrRef() as it is no more needed. 
4490  *  \throw If the MED file is not readable.
4491  *  \throw If no field of \a this is lying on \a mesh.
4492  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4493  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4494  */
4495 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4496 {
4497   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4498   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4499   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4500   if(meshDimRelToMax==1)
4501     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4502   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4503 }
4504
4505 /*!
4506  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4507  * given mesh. 
4508  *  \param [in] type - a spatial discretization of the new field.
4509  *  \param [in] mName - a name of the supporting mesh.
4510  *  \param [in] renumPol - specifies how to permute values of the result field according to
4511  *          the optional numbers of cells and nodes, if any. The valid values are
4512  *          - 0 - do not permute.
4513  *          - 1 - permute cells.
4514  *          - 2 - permute nodes.
4515  *          - 3 - permute cells and nodes.
4516  *
4517  *  \param [in] glob - the global data storing profiles and localization.
4518  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4519  *          caller is to delete this field using decrRef() as it is no more needed. 
4520  *  \throw If the MED file is not readable.
4521  *  \throw If there is no mesh named \a mName in the MED file.
4522  *  \throw If there are no mesh entities in the mesh.
4523  *  \throw If no field values of the given \a type are available.
4524  */
4525 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4526 {
4527   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4528   if(mName.empty())
4529     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4530   else
4531     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4532   int absDim=getDimension();
4533   int meshDimRelToMax=absDim-mm->getMeshDimension();
4534   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4535 }
4536
4537 /*!
4538  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4539  *  \param [in] type - a spatial discretization of the new field.
4540  *  \param [in] renumPol - specifies how to permute values of the result field according to
4541  *          the optional numbers of cells and nodes, if any. The valid values are
4542  *          - 0 - do not permute.
4543  *          - 1 - permute cells.
4544  *          - 2 - permute nodes.
4545  *          - 3 - permute cells and nodes.
4546  *
4547  *  \param [in] glob - the global data storing profiles and localization.
4548  *  \param [in] mesh - the supporting mesh.
4549  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4550  *         field according to \a renumPol.
4551  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4552  *         field according to \a renumPol.
4553  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4554  *          caller is to delete this field using decrRef() as it is no more needed. 
4555  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4556  *  \throw If no field of \a this is lying on \a mesh.
4557  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4558  */
4559 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
4560 {
4561   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4562   int meshId=getMeshIdFromMeshName(mesh->getName());
4563   bool isPfl=false;
4564   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4565   switch(renumPol)
4566   {
4567     case 0:
4568       {
4569         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4570         return ret.retn();
4571       }
4572     case 3:
4573     case 1:
4574       {
4575         if(isPfl)
4576           throw INTERP_KERNEL::Exception(msg1);
4577         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4578         if(cellRenum)
4579           {
4580             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4581               {
4582                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4583                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4584                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4585               }
4586             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4587             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4588             std::vector<DataArray *> arrOut2(1,arrOut);
4589             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4590             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4591             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4592           }
4593         if(renumPol==1)
4594           return ret.retn();
4595       }
4596     case 2:
4597       {
4598         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4599         if(isPfl)
4600           throw INTERP_KERNEL::Exception(msg1);
4601         if(nodeRenum)
4602           {
4603             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4604               {
4605                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4606                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4607                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4608               }
4609             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4610             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4611               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4612             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4613           }
4614         return ret.retn();
4615       }
4616     default:
4617       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4618   }
4619 }
4620
4621 /*!
4622  * Returns values and a profile of the field of a given type lying on a given support.
4623  *  \param [in] type - a spatial discretization of the field.
4624  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4625  *  \param [in] mesh - the supporting mesh.
4626  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4627  *          field of interest lies on. If the field lies on all entities of the given
4628  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4629  *          using decrRef() as it is no more needed.  
4630  *  \param [in] glob - the global data storing profiles and localization.
4631  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4632  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4633  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4634  *  \throw If no field of \a this is lying on \a mesh.
4635  *  \throw If no field values of the given \a type are available.
4636  */
4637 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4638 {
4639   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4640   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4641   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4642   ret->setName(nasc.getName().c_str());
4643   return ret.retn();
4644 }
4645
4646 //= MEDFileField1TSWithoutSDA
4647
4648 /*!
4649  * Throws if a given value is not a valid (non-extended) relative dimension.
4650  *  \param [in] meshDimRelToMax - the relative dimension value.
4651  *  \throw If \a meshDimRelToMax > 0.
4652  */
4653 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4654 {
4655   if(meshDimRelToMax>0)
4656     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4657 }
4658
4659 /*!
4660  * Checks if elements of a given mesh are in the order suitable for writing 
4661  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4662  * vector describing types of elements and their number.
4663  *  \param [in] mesh - the mesh to check.
4664  *  \return std::vector<int> - a vector holding for each element type (1) item of
4665  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4666  *          These values are in full-interlace mode.
4667  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4668  */
4669 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4670 {
4671   if(!mesh)
4672     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4673   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4674   int nbOfTypes=geoTypes.size();
4675   std::vector<int> code(3*nbOfTypes);
4676   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4677   arr1->alloc(nbOfTypes,1);
4678   int *arrPtr=arr1->getPointer();
4679   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4680   for(int i=0;i<nbOfTypes;i++,it++)
4681     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4682   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4683   const int *arrPtr2=arr2->getConstPointer();
4684   int i=0;
4685   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4686     {
4687       int pos=arrPtr2[i];
4688       int nbCells=mesh->getNumberOfCellsWithType(*it);
4689       code[3*pos]=(int)(*it);
4690       code[3*pos+1]=nbCells;
4691       code[3*pos+2]=-1;//no profiles
4692     }
4693   std::vector<const DataArrayInt *> idsPerType;//no profiles
4694   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4695   if(da)
4696     {
4697       da->decrRef();
4698       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4699     }
4700   return code;
4701 }
4702
4703 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4704 {
4705   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4706 }
4707
4708 /*!
4709  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4710  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4711  * item of every of returned sequences refers to the _i_-th part of \a this field.
4712  * Thus all sequences returned by this method are of the same length equal to number
4713  * of different types of supporting entities.<br>
4714  * A field part can include sub-parts with several different spatial discretizations,
4715  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4716  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4717  * of a nested sequence corresponds to a type of spatial discretization.<br>
4718  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4719  * The overhead is due to selecting values into new instances of DataArrayDouble.
4720  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4721  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4722  *          not checked if \a mname == \c NULL).
4723  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4724  *          a field part is returned. 
4725  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4726  *          A field part can include sub-parts with several different spatial discretizations,
4727  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4728  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4729  *          This sequence is of the same length as \a types. 
4730  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4731  *          discretization. A profile name can be empty.
4732  *          Length of this and of nested sequences is the same as that of \a typesF.
4733  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4734  *          discretization. A localization name can be empty.
4735  *          Length of this and of nested sequences is the same as that of \a typesF.
4736  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4737  *          per each type of spatial discretization within one mesh entity type.
4738  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4739  *          Length of this and of nested sequences is the same as that of \a typesF.
4740  *  \throw If no field is lying on \a mname.
4741  */
4742 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
4743 {
4744   int meshId=0;
4745   if(!mname.empty())
4746     meshId=getMeshIdFromMeshName(mname);
4747   else
4748     if(_field_per_mesh.empty())
4749       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4750   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4751   int nbOfRet=ret0.size();
4752   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4753   for(int i=0;i<nbOfRet;i++)
4754     {
4755       const std::vector< std::pair<int,int> >& p=ret0[i];
4756       int nbOfRet1=p.size();
4757       ret[i].resize(nbOfRet1);
4758       for(int j=0;j<nbOfRet1;j++)
4759         {
4760           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4761           ret[i][j]=tmp;
4762         }
4763     }
4764   return ret;
4765 }
4766
4767 /*!
4768  * Returns a pointer to the underground DataArrayDouble instance. So the
4769  * caller should not decrRef() it. This method allows for a direct access to the field
4770  * values. This method is quite unusable if there is more than a nodal field or a cell
4771  * field on single geometric cell type. 
4772  *  \return DataArrayDouble * - the pointer to the field values array.
4773  */
4774 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
4775 {
4776   const DataArrayDouble *ret=_arr;
4777   if(ret)
4778     return const_cast<DataArrayDouble *>(ret);
4779   else
4780     return 0;
4781 }
4782
4783 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
4784 {
4785   return TYPE_STR;
4786 }
4787
4788 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
4789 {
4790   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4791   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4792   ret->deepCpyLeavesFrom(*this);
4793   const DataArrayDouble *arr(_arr);
4794   if(arr)
4795     {
4796       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4797       ret->setArray(arr2);
4798     }
4799   return ret.retn();
4800 }
4801
4802 /*!
4803  * Returns a pointer to the underground DataArrayDouble instance. So the
4804  * caller should not decrRef() it. This method allows for a direct access to the field
4805  * values. This method is quite unusable if there is more than a nodal field or a cell
4806  * field on single geometric cell type. 
4807  *  \return DataArrayDouble * - the pointer to the field values array.
4808  */
4809 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
4810 {
4811   return getUndergroundDataArrayDouble();
4812 }
4813
4814 /*!
4815  * Returns a pointer to the underground DataArrayDouble instance and a
4816  * sequence describing parameters of a support of each part of \a this field. The
4817  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4818  * direct access to the field values. This method is intended for the field lying on one
4819  * mesh only.
4820  *  \param [in,out] entries - the sequence describing parameters of a support of each
4821  *         part of \a this field. Each item of this sequence consists of two parts. The
4822  *         first part describes a type of mesh entity and an id of discretization of a
4823  *         current field part. The second part describes a range of values [begin,end)
4824  *         within the returned array relating to the current field part.
4825  *  \return DataArrayDouble * - the pointer to the field values array.
4826  *  \throw If the number of underlying meshes is not equal to 1.
4827  *  \throw If no field values are available.
4828  *  \sa getUndergroundDataArray()
4829  */
4830 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4831 {
4832   if(_field_per_mesh.size()!=1)
4833     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4834   if(_field_per_mesh[0]==0)
4835     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4836   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4837   return getUndergroundDataArrayDouble();
4838 }
4839
4840 /*!
4841  * Returns a pointer to the underground DataArrayDouble instance and a
4842  * sequence describing parameters of a support of each part of \a this field. The
4843  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4844  * direct access to the field values. This method is intended for the field lying on one
4845  * mesh only.
4846  *  \param [in,out] entries - the sequence describing parameters of a support of each
4847  *         part of \a this field. Each item of this sequence consists of two parts. The
4848  *         first part describes a type of mesh entity and an id of discretization of a
4849  *         current field part. The second part describes a range of values [begin,end)
4850  *         within the returned array relating to the current field part.
4851  *  \return DataArrayDouble * - the pointer to the field values array.
4852  *  \throw If the number of underlying meshes is not equal to 1.
4853  *  \throw If no field values are available.
4854  *  \sa getUndergroundDataArray()
4855  */
4856 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4857 {
4858   return getUndergroundDataArrayDoubleExt(entries);
4859 }
4860
4861 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
4862                                                      const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4863 {
4864   DataArrayDouble *arr=getOrCreateAndGetArrayDouble();
4865   arr->setInfoAndChangeNbOfCompo(infos);
4866 }
4867
4868 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4869 {
4870 }
4871
4872 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
4873 {
4874   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4875   ret->deepCpyLeavesFrom(*this);
4876   return ret.retn();
4877 }
4878
4879 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
4880 {
4881   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4882   if((const DataArrayDouble *)_arr)
4883     ret->_arr=_arr->deepCpy();
4884   return ret.retn();
4885 }
4886
4887 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
4888 {
4889   if(!arr)
4890     {
4891       _nb_of_tuples_to_be_allocated=-1;
4892       _arr=0;
4893       return ;
4894     }
4895   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4896   if(!arrC)
4897     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4898   else
4899     _nb_of_tuples_to_be_allocated=-3;
4900   arrC->incrRef();
4901   _arr=arrC;
4902 }
4903
4904 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4905 {
4906   return DataArrayDouble::New();
4907 }
4908
4909 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4910 {
4911   DataArrayDouble *ret=_arr;
4912   if(ret)
4913     return ret;
4914   _arr=DataArrayDouble::New();
4915   return _arr;
4916 }
4917
4918 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4919 {
4920   return getOrCreateAndGetArrayDouble();
4921 }
4922
4923 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4924 {
4925   const DataArrayDouble *ret=_arr;
4926   if(ret)
4927     return ret;
4928   DataArrayDouble *ret2=DataArrayDouble::New();
4929   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4930   return ret2;
4931 }
4932
4933 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4934 {
4935   return getOrCreateAndGetArrayDouble();
4936 }
4937
4938 //= MEDFileIntField1TSWithoutSDA
4939
4940 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order,
4941                                                                 const std::vector<std::string>& infos)
4942 {
4943   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4944 }
4945
4946 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4947 {
4948 }
4949
4950 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
4951                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4952 {
4953   DataArrayInt *arr=getOrCreateAndGetArrayInt();
4954   arr->setInfoAndChangeNbOfCompo(infos);
4955 }
4956
4957 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
4958 {
4959   return TYPE_STR;
4960 }
4961
4962 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
4963 {
4964   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
4965   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4966   ret->deepCpyLeavesFrom(*this);
4967   const DataArrayInt *arr(_arr);
4968   if(arr)
4969     {
4970       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
4971       ret->setArray(arr2);
4972     }
4973   return ret.retn();
4974 }
4975
4976 /*!
4977  * Returns a pointer to the underground DataArrayInt instance. So the
4978  * caller should not decrRef() it. This method allows for a direct access to the field
4979  * values. This method is quite unusable if there is more than a nodal field or a cell
4980  * field on single geometric cell type. 
4981  *  \return DataArrayInt * - the pointer to the field values array.
4982  */
4983 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
4984 {
4985   return getUndergroundDataArrayInt();
4986 }
4987
4988 /*!
4989  * Returns a pointer to the underground DataArrayInt instance. So the
4990  * caller should not decrRef() it. This method allows for a direct access to the field
4991  * values. This method is quite unusable if there is more than a nodal field or a cell
4992  * field on single geometric cell type. 
4993  *  \return DataArrayInt * - the pointer to the field values array.
4994  */
4995 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
4996 {
4997   const DataArrayInt *ret=_arr;
4998   if(ret)
4999     return const_cast<DataArrayInt *>(ret);
5000   else
5001     return 0;
5002 }
5003
5004 /*!
5005  * Returns a pointer to the underground DataArrayInt instance and a
5006  * sequence describing parameters of a support of each part of \a this field. The
5007  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5008  * direct access to the field values. This method is intended for the field lying on one
5009  * mesh only.
5010  *  \param [in,out] entries - the sequence describing parameters of a support of each
5011  *         part of \a this field. Each item of this sequence consists of two parts. The
5012  *         first part describes a type of mesh entity and an id of discretization of a
5013  *         current field part. The second part describes a range of values [begin,end)
5014  *         within the returned array relating to the current field part.
5015  *  \return DataArrayInt * - the pointer to the field values array.
5016  *  \throw If the number of underlying meshes is not equal to 1.
5017  *  \throw If no field values are available.
5018  *  \sa getUndergroundDataArray()
5019  */
5020 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5021 {
5022   return getUndergroundDataArrayIntExt(entries);
5023 }
5024
5025 /*!
5026  * Returns a pointer to the underground DataArrayInt instance and a
5027  * sequence describing parameters of a support of each part of \a this field. The
5028  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5029  * direct access to the field values. This method is intended for the field lying on one
5030  * mesh only.
5031  *  \param [in,out] entries - the sequence describing parameters of a support of each
5032  *         part of \a this field. Each item of this sequence consists of two parts. The
5033  *         first part describes a type of mesh entity and an id of discretization of a
5034  *         current field part. The second part describes a range of values [begin,end)
5035  *         within the returned array relating to the current field part.
5036  *  \return DataArrayInt * - the pointer to the field values array.
5037  *  \throw If the number of underlying meshes is not equal to 1.
5038  *  \throw If no field values are available.
5039  *  \sa getUndergroundDataArray()
5040  */
5041 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5042 {
5043   if(_field_per_mesh.size()!=1)
5044     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5045   if(_field_per_mesh[0]==0)
5046     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5047   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5048   return getUndergroundDataArrayInt();
5049 }
5050
5051 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5052 {
5053   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5054   ret->deepCpyLeavesFrom(*this);
5055   return ret.retn();
5056 }
5057
5058 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5059 {
5060   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5061   if((const DataArrayInt *)_arr)
5062     ret->_arr=_arr->deepCpy();
5063   return ret.retn();
5064 }
5065
5066 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5067 {
5068   if(!arr)
5069     {
5070       _nb_of_tuples_to_be_allocated=-1;
5071       _arr=0;
5072       return ;
5073     }
5074   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5075   if(!arrC)
5076     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5077   else
5078     _nb_of_tuples_to_be_allocated=-3;
5079   arrC->incrRef();
5080   _arr=arrC;
5081 }
5082
5083 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5084 {
5085   return DataArrayInt::New();
5086 }
5087
5088 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5089 {
5090   DataArrayInt *ret=_arr;
5091   if(ret)
5092     return ret;
5093   _arr=DataArrayInt::New();
5094   return _arr;
5095 }
5096
5097 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5098 {
5099   return getOrCreateAndGetArrayInt();
5100 }
5101
5102 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5103 {
5104   const DataArrayInt *ret=_arr;
5105   if(ret)
5106     return ret;
5107   DataArrayInt *ret2=DataArrayInt::New();
5108   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5109   return ret2;
5110 }
5111
5112 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5113 {
5114   return getOrCreateAndGetArrayInt();
5115 }
5116
5117 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5118 {
5119 }
5120
5121 //= MEDFileAnyTypeField1TS
5122
5123 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll)
5124 {
5125   med_field_type typcha;
5126   //
5127   std::vector<std::string> infos;
5128   std::string dtunit,fieldName;
5129   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5130   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5131   switch(typcha)
5132   {
5133     case MED_FLOAT64:
5134       {
5135         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5136         break;
5137       }
5138     case MED_INT32:
5139       {
5140         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5141         break;
5142       }
5143     default:
5144       {
5145         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] !";
5146         throw INTERP_KERNEL::Exception(oss.str().c_str());
5147       }
5148   }
5149   ret->setDtUnit(dtunit.c_str());
5150   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5151   //
5152   med_int numdt,numit;
5153   med_float dt;
5154   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5155   ret->setTime(numdt,numit,dt);
5156   ret->_csit=1;
5157   if(loadAll)
5158     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5159   else
5160     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5161   return ret.retn();
5162 }
5163
5164 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll)
5165 try:MEDFileFieldGlobsReal(fileName)
5166 {
5167   MEDFileUtilities::CheckFileForRead(fileName);
5168   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5169   _content=BuildContentFrom(fid,fileName,loadAll);
5170   loadGlobals(fid);
5171 }
5172 catch(INTERP_KERNEL::Exception& e)
5173 {
5174     throw e;
5175 }
5176
5177 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll)
5178 {
5179   med_field_type typcha;
5180   std::vector<std::string> infos;
5181   std::string dtunit;
5182   int iii=-1;
5183   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5184   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5185   switch(typcha)
5186   {
5187     case MED_FLOAT64:
5188       {
5189         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5190         break;
5191       }
5192     case MED_INT32:
5193       {
5194         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5195         break;
5196       }
5197     default:
5198       {
5199         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] !";
5200         throw INTERP_KERNEL::Exception(oss.str().c_str());
5201       }
5202   }
5203   ret->setDtUnit(dtunit.c_str());
5204   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5205   //
5206   if(nbSteps<1)
5207     {
5208       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5209       throw INTERP_KERNEL::Exception(oss.str().c_str());
5210     }
5211   //
5212   med_int numdt,numit;
5213   med_float dt;
5214   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5215   ret->setTime(numdt,numit,dt);
5216   ret->_csit=1;
5217   if(loadAll)
5218     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5219   else
5220     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5221   return ret.retn();
5222 }
5223
5224 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll)
5225 try:MEDFileFieldGlobsReal(fileName)
5226 {
5227   MEDFileUtilities::CheckFileForRead(fileName);
5228   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5229   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
5230   loadGlobals(fid);
5231 }
5232 catch(INTERP_KERNEL::Exception& e)
5233 {
5234     throw e;
5235 }
5236
5237 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5238 {
5239   if(!c)
5240     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5241   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5242     {
5243       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5244       ret->setFileName(fileName);
5245       ret->_content=c; c->incrRef();
5246       return ret.retn();
5247     }
5248   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5249     {
5250       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5251       ret->setFileName(fileName);
5252       ret->_content=c; c->incrRef();
5253       return ret.retn();
5254     }
5255   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5256 }
5257
5258 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5259 {
5260   MEDFileUtilities::CheckFileForRead(fileName);
5261   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5262   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
5263   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5264   ret->loadGlobals(fid);
5265   return ret.retn();
5266 }
5267
5268 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5269 {
5270   MEDFileUtilities::CheckFileForRead(fileName);
5271   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5272   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
5273   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5274   ret->loadGlobals(fid);
5275   return ret.retn();
5276 }
5277
5278 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5279 {
5280   MEDFileUtilities::CheckFileForRead(fileName);
5281   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5282   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll);
5283   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5284   ret->loadGlobals(fid);
5285   return ret.retn();
5286 }
5287
5288 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5289 {
5290   med_field_type typcha;
5291   std::vector<std::string> infos;
5292   std::string dtunit;
5293   int iii=-1;
5294   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5295   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5296   switch(typcha)
5297   {
5298     case MED_FLOAT64:
5299       {
5300         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5301         break;
5302       }
5303     case MED_INT32:
5304       {
5305         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5306         break;
5307       }
5308     default:
5309       {
5310         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] !";
5311         throw INTERP_KERNEL::Exception(oss.str().c_str());
5312       }
5313   }
5314   ret->setDtUnit(dtunit.c_str());
5315   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5316   //
5317   bool found=false;
5318   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5319   for(int i=0;i<nbOfStep2 && !found;i++)
5320     {
5321       med_int numdt,numit;
5322       med_float dt;
5323       MEDfieldComputingStepInfo(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt);
5324       if(numdt==iteration && numit==order)
5325         {
5326           found=true;
5327           ret->_csit=i+1;
5328         }
5329       else
5330         dtits[i]=std::pair<int,int>(numdt,numit);
5331     }
5332   if(!found)
5333     {
5334       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5335       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5336         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5337       throw INTERP_KERNEL::Exception(oss.str().c_str());
5338     }
5339   if(loadAll)
5340     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5341   else
5342     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5343   return ret.retn();
5344 }
5345
5346 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5347 try:MEDFileFieldGlobsReal(fileName)
5348 {
5349   MEDFileUtilities::CheckFileForRead(fileName);
5350   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5351   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll);
5352   loadGlobals(fid);
5353 }
5354 catch(INTERP_KERNEL::Exception& e)
5355 {
5356     throw e;
5357 }
5358
5359 /*!
5360  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5361  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5362  *
5363  * \warning this is a shallow copy constructor
5364  */
5365 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5366 {
5367   if(!shallowCopyOfContent)
5368     {
5369       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5370       otherPtr->incrRef();
5371       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5372     }
5373   else
5374     {
5375       _content=other.shallowCpy();
5376     }
5377 }
5378
5379 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)
5380 {
5381   if(checkFieldId)
5382     {
5383       int nbFields=MEDnField(fid);
5384       if(fieldIdCFormat>=nbFields)
5385         {
5386           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5387           throw INTERP_KERNEL::Exception(oss.str().c_str());
5388         }
5389     }
5390   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5391   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5392   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5393   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5394   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5395   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5396   med_bool localMesh;
5397   int nbOfStep;
5398   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5399   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5400   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5401   infos.clear(); infos.resize(ncomp);
5402   for(int j=0;j<ncomp;j++)
5403     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5404   return nbOfStep;
5405 }
5406
5407 /*!
5408  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5409  * 
5410  * \param [out]
5411  * \return in case of success the number of time steps available for the field with name \a fieldName.
5412  */
5413 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)
5414 {
5415   int nbFields=MEDnField(fid);
5416   bool found=false;
5417   std::vector<std::string> fns(nbFields);
5418   int nbOfStep2=-1;
5419   for(int i=0;i<nbFields && !found;i++)
5420     {
5421       std::string tmp;
5422       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5423       fns[i]=tmp;
5424       found=(tmp==fieldName);
5425       if(found)
5426         posCFormat=i;
5427     }
5428   if(!found)
5429     {
5430       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5431       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5432         oss << "\"" << *it << "\" ";
5433       throw INTERP_KERNEL::Exception(oss.str().c_str());
5434     }
5435   return nbOfStep2;
5436 }
5437
5438 /*!
5439  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5440  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5441  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5442  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5443  * to keep a valid instance.
5444  * 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.
5445  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5446  * 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.
5447  *
5448  * \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.
5449  * \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.
5450  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5451  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5452  * \param [in] newLocName is the new localization name.
5453  * \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.
5454  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5455  */
5456 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5457 {
5458   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5459   std::string oldPflName=disc->getProfile();
5460   std::vector<std::string> vv=getPflsReallyUsedMulti();
5461   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5462   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5463     {
5464       disc->setProfile(newPflName);
5465       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5466       pfl->setName(newPflName);
5467     }
5468   else
5469     {
5470       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5471       throw INTERP_KERNEL::Exception(oss.str().c_str());
5472     }
5473 }
5474
5475 /*!
5476  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5477  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5478  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5479  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5480  * to keep a valid instance.
5481  * 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.
5482  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5483  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5484  * 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.
5485  *
5486  * \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.
5487  * \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.
5488  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5489  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5490  * \param [in] newLocName is the new localization name.
5491  * \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.
5492  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5493  */
5494 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5495 {
5496   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5497   std::string oldLocName=disc->getLocalization();
5498   std::vector<std::string> vv=getLocsReallyUsedMulti();
5499   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5500   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5501     {
5502       disc->setLocalization(newLocName);
5503       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5504       loc.setName(newLocName);
5505     }
5506   else
5507     {
5508       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5509       throw INTERP_KERNEL::Exception(oss.str().c_str());
5510     }
5511 }
5512
5513 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5514 {
5515   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5516   if(!ret)
5517     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5518   return ret;
5519 }
5520
5521 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5522 {
5523   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5524   if(!ret)
5525     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5526   return ret;
5527 }
5528
5529 /*!
5530  * Writes \a this field into a MED file specified by its name.
5531  *  \param [in] fileName - the MED file name.
5532  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5533  * - 2 - erase; an existing file is removed.
5534  * - 1 - append; same data should not be present in an existing file.
5535  * - 0 - overwrite; same data present in an existing file is overwritten.
5536  *  \throw If the field name is not set.
5537  *  \throw If no field data is set.
5538  *  \throw If \a mode == 1 and the same data is present in an existing file.
5539  */
5540 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5541 {
5542   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5543   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5544   writeLL(fid);
5545 }
5546
5547 /*!
5548  * This method alloc the arrays and load potentially huge arrays contained in this field.
5549  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5550  * This method can be also called to refresh or reinit values from a file.
5551  * 
5552  * \throw If the fileName is not set or points to a non readable MED file.
5553  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5554  */
5555 void MEDFileAnyTypeField1TS::loadArrays()
5556 {
5557   if(getFileName().empty())
5558     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5559   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5560   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5561 }
5562
5563 /*!
5564  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5565  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5566  * this method does not throw if \a this does not come from file read.
5567  * 
5568  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5569  */
5570 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5571 {
5572   if(!getFileName().empty())
5573     {
5574       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5575       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5576     }
5577 }
5578
5579 /*!
5580  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5581  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5582  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5583  * 
5584  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5585  */
5586 void MEDFileAnyTypeField1TS::unloadArrays()
5587 {
5588   contentNotNullBase()->unloadArrays();
5589 }
5590
5591 /*!
5592  * 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.
5593  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5594  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5595  * 
5596  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5597  */
5598 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5599 {
5600   if(!getFileName().empty())
5601     contentNotNullBase()->unloadArrays();
5602 }
5603
5604 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5605 {
5606   int nbComp=getNumberOfComponents();
5607   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5608   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5609   for(int i=0;i<nbComp;i++)
5610     {
5611       std::string info=getInfo()[i];
5612       std::string c,u;
5613       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5614       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5615       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5616     }
5617   if(getName().empty())
5618     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5619   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5620   writeGlobals(fid,*this);
5621   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5622 }
5623
5624 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5625 {
5626   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5627 }
5628
5629 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5630 {
5631   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5632   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5633   return ret;
5634 }
5635
5636 /*!
5637  * Returns a string describing \a this field. This string is outputted 
5638  * by \c print Python command.
5639  */
5640 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5641 {
5642   std::ostringstream oss;
5643   contentNotNullBase()->simpleRepr(0,oss,-1);
5644   simpleReprGlobs(oss);
5645   return oss.str();
5646 }
5647
5648 /*!
5649  * This method returns all profiles whose name is non empty used.
5650  * \b WARNING If profile is used several times it will be reported \b only \b once.
5651  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5652  */
5653 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5654 {
5655   return contentNotNullBase()->getPflsReallyUsed2();
5656 }
5657
5658 /*!
5659  * This method returns all localizations whose name is non empty used.
5660  * \b WARNING If localization is used several times it will be reported \b only \b once.
5661  */
5662 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5663 {
5664   return contentNotNullBase()->getLocsReallyUsed2();
5665 }
5666
5667 /*!
5668  * This method returns all profiles whose name is non empty used.
5669  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5670  */
5671 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5672 {
5673   return contentNotNullBase()->getPflsReallyUsedMulti2();
5674 }
5675
5676 /*!
5677  * This method returns all localizations whose name is non empty used.
5678  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5679  */
5680 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5681 {
5682   return contentNotNullBase()->getLocsReallyUsedMulti2();
5683 }
5684
5685 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5686 {
5687   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5688 }
5689
5690 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5691 {
5692   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5693 }
5694
5695 int MEDFileAnyTypeField1TS::getDimension() const
5696 {
5697   return contentNotNullBase()->getDimension();
5698 }
5699
5700 int MEDFileAnyTypeField1TS::getIteration() const
5701 {
5702   return contentNotNullBase()->getIteration();
5703 }
5704
5705 int MEDFileAnyTypeField1TS::getOrder() const
5706 {
5707   return contentNotNullBase()->getOrder();
5708 }
5709
5710 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5711 {
5712   return contentNotNullBase()->getTime(iteration,order);
5713 }
5714
5715 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5716 {
5717   contentNotNullBase()->setTime(iteration,order,val);
5718 }
5719
5720 std::string MEDFileAnyTypeField1TS::getName() const
5721 {
5722   return contentNotNullBase()->getName();
5723 }
5724
5725 void MEDFileAnyTypeField1TS::setName(const std::string& name)
5726 {
5727   contentNotNullBase()->setName(name);
5728 }
5729
5730 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5731 {
5732   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5733 }
5734
5735 std::string MEDFileAnyTypeField1TS::getDtUnit() const
5736 {
5737   return contentNotNullBase()->getDtUnit();
5738 }
5739
5740 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
5741 {
5742   contentNotNullBase()->setDtUnit(dtUnit);
5743 }
5744
5745 std::string MEDFileAnyTypeField1TS::getMeshName() const
5746 {
5747   return contentNotNullBase()->getMeshName();
5748 }
5749
5750 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
5751 {
5752   contentNotNullBase()->setMeshName(newMeshName);
5753 }
5754
5755 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
5756 {
5757   return contentNotNullBase()->changeMeshNames(modifTab);
5758 }
5759
5760 int MEDFileAnyTypeField1TS::getMeshIteration() const
5761 {
5762   return contentNotNullBase()->getMeshIteration();
5763 }
5764
5765 int MEDFileAnyTypeField1TS::getMeshOrder() const
5766 {
5767   return contentNotNullBase()->getMeshOrder();
5768 }
5769
5770 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5771 {
5772   return contentNotNullBase()->getNumberOfComponents();
5773 }
5774
5775 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5776 {
5777   return contentNotNullBase()->isDealingTS(iteration,order);
5778 }
5779
5780 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5781 {
5782   return contentNotNullBase()->getDtIt();
5783 }
5784
5785 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5786 {
5787   contentNotNullBase()->fillIteration(p);
5788 }
5789
5790 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
5791 {
5792   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5793 }
5794
5795 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
5796 {
5797   contentNotNullBase()->setInfo(infos);
5798 }
5799
5800 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5801 {
5802   return contentNotNullBase()->getInfo();
5803 }
5804 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5805 {
5806   return contentNotNullBase()->getInfo();
5807 }
5808
5809 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
5810 {
5811   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5812 }
5813
5814 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
5815 {
5816   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5817 }
5818
5819 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
5820 {
5821   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5822 }
5823
5824 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
5825 {
5826   return contentNotNullBase()->getTypesOfFieldAvailable();
5827 }
5828
5829 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,
5830                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
5831 {
5832   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5833 }
5834
5835 /*!
5836  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5837  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5838  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5839  */
5840 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
5841 {
5842   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5843   if(!content)
5844     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5845   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5846   std::size_t sz(contentsSplit.size());
5847   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5848   for(std::size_t i=0;i<sz;i++)
5849     {
5850       ret[i]=shallowCpy();
5851       ret[i]->_content=contentsSplit[i];
5852     }
5853   return ret;
5854 }
5855
5856 /*!
5857  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
5858  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5859  */
5860 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
5861 {
5862   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5863   if(!content)
5864     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
5865   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitDiscretizations();
5866   std::size_t sz(contentsSplit.size());
5867   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5868   for(std::size_t i=0;i<sz;i++)
5869     {
5870       ret[i]=shallowCpy();
5871       ret[i]->_content=contentsSplit[i];
5872     }
5873   return ret;
5874 }
5875
5876 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
5877 {
5878   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5879   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5880     ret->_content=_content->deepCpy();
5881   ret->deepCpyGlobs(*this);
5882   return ret.retn();
5883 }
5884
5885 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5886 {
5887   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5888 }
5889
5890 //= MEDFileField1TS
5891
5892 /*!
5893  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5894  * the first field that has been read from a specified MED file.
5895  *  \param [in] fileName - the name of the MED file to read.
5896  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5897  *          is to delete this field using decrRef() as it is no more needed.
5898  *  \throw If reading the file fails.
5899  */
5900 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
5901 {
5902   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,loadAll);
5903   ret->contentNotNull();
5904   return ret.retn();
5905 }
5906
5907 /*!
5908  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5909  * a given field that has been read from a specified MED file.
5910  *  \param [in] fileName - the name of the MED file to read.
5911  *  \param [in] fieldName - the name of the field to read.
5912  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5913  *          is to delete this field using decrRef() as it is no more needed.
5914  *  \throw If reading the file fails.
5915  *  \throw If there is no field named \a fieldName in the file.
5916  */
5917 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5918 {
5919   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,loadAll);
5920   ret->contentNotNull();
5921   return ret.retn();
5922 }
5923
5924 /*!
5925  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5926  * a given field that has been read from a specified MED file.
5927  *  \param [in] fileName - the name of the MED file to read.
5928  *  \param [in] fieldName - the name of the field to read.
5929  *  \param [in] iteration - the iteration number of a required time step.
5930  *  \param [in] order - the iteration order number of required time step.
5931  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5932  *          is to delete this field using decrRef() as it is no more needed.
5933  *  \throw If reading the file fails.
5934  *  \throw If there is no field named \a fieldName in the file.
5935  *  \throw If the required time step is missing from the file.
5936  */
5937 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5938 {
5939   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll);
5940   ret->contentNotNull();
5941   return ret.retn();
5942 }
5943
5944 /*!
5945  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5946  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5947  *
5948  * Returns a new instance of MEDFileField1TS holding either a shallow copy
5949  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
5950  * \warning this is a shallow copy constructor
5951  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
5952  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
5953  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5954  *          is to delete this field using decrRef() as it is no more needed.
5955  */
5956 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5957 {
5958   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
5959   ret->contentNotNull();
5960   return ret.retn();
5961 }
5962
5963 /*!
5964  * Returns a new empty instance of MEDFileField1TS.
5965  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5966  *          is to delete this field using decrRef() as it is no more needed.
5967  */
5968 MEDFileField1TS *MEDFileField1TS::New()
5969 {
5970   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
5971   ret->contentNotNull();
5972   return ret.retn();
5973 }
5974
5975 /*!
5976  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
5977  * following the given input policy.
5978  *
5979  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
5980  *                            By default (true) the globals are deeply copied.
5981  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
5982  */
5983 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
5984 {
5985   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
5986   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5987   if(content)
5988     {
5989       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
5990       if(!contc)
5991         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
5992       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
5993       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
5994     }
5995   else
5996     ret=MEDFileIntField1TS::New();
5997   if(isDeepCpyGlobs)
5998     ret->deepCpyGlobs(*this);
5999   else
6000     ret->shallowCpyGlobs(*this);
6001   return ret.retn();
6002 }
6003
6004 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6005 {
6006   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6007   if(!pt)
6008     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6009   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6010   if(!ret)
6011     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 !");
6012   return ret;
6013 }
6014
6015 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6016 {
6017   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6018   if(!pt)
6019     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6020   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6021   if(!ret)
6022     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 !");
6023   return ret;
6024 }
6025
6026 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6027 {
6028   if(!f)
6029     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6030   if(!((DataArray*)arr))
6031     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6032   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6033   if(!arrOutC)
6034     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6035   f->setArray(arrOutC);
6036 }
6037
6038 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6039 {
6040   if(!((DataArray*)arr))
6041     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6042   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6043   if(!arrOutC)
6044     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6045   arrOutC->incrRef();
6046   return arrOutC;
6047 }
6048
6049 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll)
6050 try:MEDFileAnyTypeField1TS(fileName,loadAll)
6051 {
6052 }
6053 catch(INTERP_KERNEL::Exception& e)
6054 { throw e; }
6055
6056 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll)
6057 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
6058 {
6059 }
6060 catch(INTERP_KERNEL::Exception& e)
6061 { throw e; }
6062
6063 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6064 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
6065 {
6066 }
6067 catch(INTERP_KERNEL::Exception& e)
6068 { throw e; }
6069
6070 /*!
6071  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6072  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6073  *
6074  * \warning this is a shallow copy constructor
6075  */
6076 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6077 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6078 {
6079 }
6080 catch(INTERP_KERNEL::Exception& e)
6081 { throw e; }
6082
6083 MEDFileField1TS::MEDFileField1TS()
6084 {
6085   _content=new MEDFileField1TSWithoutSDA;
6086 }
6087
6088 /*!
6089  * Returns a new MEDCouplingFieldDouble of a given type lying on
6090  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6091  * has not been constructed via file reading, an exception is thrown.
6092  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6093  *  \param [in] type - a spatial discretization of interest.
6094  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6095  *  \param [in] renumPol - specifies how to permute values of the result field according to
6096  *          the optional numbers of cells and nodes, if any. The valid values are
6097  *          - 0 - do not permute.
6098  *          - 1 - permute cells.
6099  *          - 2 - permute nodes.
6100  *          - 3 - permute cells and nodes.
6101  *
6102  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6103  *          caller is to delete this field using decrRef() as it is no more needed. 
6104  *  \throw If \a this field has not been constructed via file reading.
6105  *  \throw If the MED file is not readable.
6106  *  \throw If there is no mesh in the MED file.
6107  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6108  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6109  *  \sa getFieldOnMeshAtLevel()
6110  */
6111 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6112 {
6113   if(getFileName().empty())
6114     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6115   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6116   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6117   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6118   return ret.retn();
6119 }
6120
6121 /*!
6122  * Returns a new MEDCouplingFieldDouble of a given type lying on
6123  * the top level cells of the first mesh in MED file. If \a this field 
6124  * has not been constructed via file reading, an exception is thrown.
6125  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6126  *  \param [in] type - a spatial discretization of interest.
6127  *  \param [in] renumPol - specifies how to permute values of the result field according to
6128  *          the optional numbers of cells and nodes, if any. The valid values are
6129  *          - 0 - do not permute.
6130  *          - 1 - permute cells.
6131  *          - 2 - permute nodes.
6132  *          - 3 - permute cells and nodes.
6133  *
6134  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6135  *          caller is to delete this field using decrRef() as it is no more needed. 
6136  *  \throw If \a this field has not been constructed via file reading.
6137  *  \throw If the MED file is not readable.
6138  *  \throw If there is no mesh in the MED file.
6139  *  \throw If no field values of the given \a type.
6140  *  \throw If no field values lying on the top level support.
6141  *  \sa getFieldAtLevel()
6142  */
6143 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6144 {
6145   if(getFileName().empty())
6146     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6147   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6148   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6149   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6150   return ret.retn();
6151 }
6152
6153 /*!
6154  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6155  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6156  *  \param [in] type - a spatial discretization of the new field.
6157  *  \param [in] mesh - the supporting mesh.
6158  *  \param [in] renumPol - specifies how to permute values of the result field according to
6159  *          the optional numbers of cells and nodes, if any. The valid values are
6160  *          - 0 - do not permute.
6161  *          - 1 - permute cells.
6162  *          - 2 - permute nodes.
6163  *          - 3 - permute cells and nodes.
6164  *
6165  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6166  *          caller is to delete this field using decrRef() as it is no more needed. 
6167  *  \throw If no field of \a this is lying on \a mesh.
6168  *  \throw If the mesh is empty.
6169  *  \throw If no field values of the given \a type are available.
6170  *  \sa getFieldAtLevel()
6171  *  \sa getFieldOnMeshAtLevel() 
6172  */
6173 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6174 {
6175   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6176   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6177   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6178   return ret.retn();
6179 }
6180
6181 /*!
6182  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6183  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6184  *  \param [in] type - a spatial discretization of interest.
6185  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6186  *  \param [in] mesh - the supporting mesh.
6187  *  \param [in] renumPol - specifies how to permute values of the result field according to
6188  *          the optional numbers of cells and nodes, if any. The valid values are
6189  *          - 0 - do not permute.
6190  *          - 1 - permute cells.
6191  *          - 2 - permute nodes.
6192  *          - 3 - permute cells and nodes.
6193  *
6194  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6195  *          caller is to delete this field using decrRef() as it is no more needed. 
6196  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6197  *  \throw If no field of \a this is lying on \a mesh.
6198  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6199  *  \sa getFieldAtLevel()
6200  *  \sa getFieldOnMeshAtLevel() 
6201  */
6202 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6203 {
6204   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6205   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6206   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6207   return ret.retn();
6208 }
6209
6210 /*!
6211  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6212  * This method is called "Old" because in MED3 norm a field has only one meshName
6213  * attached, so this method is for readers of MED2 files. If \a this field 
6214  * has not been constructed via file reading, an exception is thrown.
6215  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6216  *  \param [in] type - a spatial discretization of interest.
6217  *  \param [in] mName - a name of the supporting mesh.
6218  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6219  *  \param [in] renumPol - specifies how to permute values of the result field according to
6220  *          the optional numbers of cells and nodes, if any. The valid values are
6221  *          - 0 - do not permute.
6222  *          - 1 - permute cells.
6223  *          - 2 - permute nodes.
6224  *          - 3 - permute cells and nodes.
6225  *
6226  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6227  *          caller is to delete this field using decrRef() as it is no more needed. 
6228  *  \throw If the MED file is not readable.
6229  *  \throw If there is no mesh named \a mName in the MED file.
6230  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6231  *  \throw If \a this field has not been constructed via file reading.
6232  *  \throw If no field of \a this is lying on the mesh named \a mName.
6233  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6234  *  \sa getFieldAtLevel()
6235  */
6236 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6237 {
6238   if(getFileName().empty())
6239     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6240   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6241   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6242   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6243   return ret.retn();
6244 }
6245
6246 /*!
6247  * Returns values and a profile of the field of a given type lying on a given support.
6248  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6249  *  \param [in] type - a spatial discretization of the field.
6250  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6251  *  \param [in] mesh - the supporting mesh.
6252  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6253  *          field of interest lies on. If the field lies on all entities of the given
6254  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6255  *          using decrRef() as it is no more needed.  
6256  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6257  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6258  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6259  *  \throw If no field of \a this is lying on \a mesh.
6260  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6261  */
6262 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6263 {
6264   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6265   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6266 }
6267
6268 /*!
6269  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6270  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6271  * "Sort By Type"), if not, an exception is thrown. 
6272  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6273  *  \param [in] field - the field to add to \a this.
6274  *  \throw If the name of \a field is empty.
6275  *  \throw If the data array of \a field is not set.
6276  *  \throw If the data array is already allocated but has different number of components
6277  *         than \a field.
6278  *  \throw If the underlying mesh of \a field has no name.
6279  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6280  */
6281 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6282 {
6283   setFileName("");
6284   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6285 }
6286
6287 /*!
6288  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6289  * can be an aggregation of several MEDCouplingFieldDouble instances.
6290  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6291  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6292  * and \a profile.
6293  *
6294  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6295  * A new profile is added only if no equal profile is missing.
6296  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6297  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6298  *  \param [in] mesh - the supporting mesh of \a field.
6299  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6300  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6301  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6302  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6303  *  \throw If the data array of \a field is not set.
6304  *  \throw If the data array of \a this is already allocated but has different number of
6305  *         components than \a field.
6306  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6307  *  \sa setFieldNoProfileSBT()
6308  */
6309 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6310 {
6311   setFileName("");
6312   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6313 }
6314
6315 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6316 {
6317   return new MEDFileField1TS(*this);
6318 }
6319
6320 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6321 {
6322   return contentNotNull()->getUndergroundDataArrayDouble();
6323 }
6324
6325 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6326 {
6327   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6328 }
6329
6330 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6331                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6332 {
6333   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6334 }
6335
6336 //= MEDFileIntField1TS
6337
6338 MEDFileIntField1TS *MEDFileIntField1TS::New()
6339 {
6340   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6341   ret->contentNotNull();
6342   return ret.retn();
6343 }
6344
6345 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6346 {
6347   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,loadAll);
6348   ret->contentNotNull();
6349   return ret.retn();
6350 }
6351
6352 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6353 {
6354   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,loadAll);
6355   ret->contentNotNull();
6356   return ret.retn();
6357 }
6358
6359 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6360 {
6361   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll);
6362   ret->contentNotNull();
6363   return ret.retn();
6364 }
6365
6366 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6367 {
6368   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6369   ret->contentNotNull();
6370   return ret.retn();
6371 }
6372
6373 MEDFileIntField1TS::MEDFileIntField1TS()
6374 {
6375   _content=new MEDFileIntField1TSWithoutSDA;
6376 }
6377
6378 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll)
6379 try:MEDFileAnyTypeField1TS(fileName,loadAll)
6380 {
6381 }
6382 catch(INTERP_KERNEL::Exception& e)
6383 { throw e; }
6384
6385 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll)
6386 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
6387 {
6388 }
6389 catch(INTERP_KERNEL::Exception& e)
6390 { throw e; }
6391
6392 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6393 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
6394 {
6395 }
6396 catch(INTERP_KERNEL::Exception& e)
6397 { throw e; }
6398
6399 /*!
6400  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6401  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6402  *
6403  * \warning this is a shallow copy constructor
6404  */
6405 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6406 {
6407 }
6408
6409 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6410 {
6411   return new MEDFileIntField1TS(*this);
6412 }
6413
6414 /*!
6415  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6416  * following the given input policy.
6417  *
6418  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6419  *                            By default (true) the globals are deeply copied.
6420  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6421  */
6422 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6423 {
6424   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6425   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6426   if(content)
6427     {
6428       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6429       if(!contc)
6430         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6431       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6432       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6433     }
6434   else
6435     ret=MEDFileField1TS::New();
6436   if(isDeepCpyGlobs)
6437     ret->deepCpyGlobs(*this);
6438   else
6439     ret->shallowCpyGlobs(*this);
6440   return ret.retn();
6441 }
6442
6443 /*!
6444  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6445  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6446  * "Sort By Type"), if not, an exception is thrown. 
6447  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6448  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6449  *  \param [in] arrOfVals - the values of the field \a field used.
6450  *  \throw If the name of \a field is empty.
6451  *  \throw If the data array of \a field is not set.
6452  *  \throw If the data array is already allocated but has different number of components
6453  *         than \a field.
6454  *  \throw If the underlying mesh of \a field has no name.
6455  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6456  */
6457 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6458 {
6459   setFileName("");
6460   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6461 }
6462
6463 /*!
6464  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6465  * can be an aggregation of several MEDCouplingFieldDouble instances.
6466  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6467  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6468  * and \a profile.
6469  *
6470  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6471  * A new profile is added only if no equal profile is missing.
6472  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6473  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6474  *  \param [in] arrOfVals - the values of the field \a field used.
6475  *  \param [in] mesh - the supporting mesh of \a field.
6476  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6477  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6478  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6479  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6480  *  \throw If the data array of \a field is not set.
6481  *  \throw If the data array of \a this is already allocated but has different number of
6482  *         components than \a field.
6483  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6484  *  \sa setFieldNoProfileSBT()
6485  */
6486 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6487 {
6488   setFileName("");
6489   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6490 }
6491
6492 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6493 {
6494   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6495   if(!pt)
6496     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6497   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6498   if(!ret)
6499     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 !");
6500   return ret;
6501 }
6502
6503 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6504 {
6505   if(getFileName().empty())
6506     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6507   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6508   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6509   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6510   if(!arrOutC)
6511     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6512   arrOut=arrOutC;
6513   return ret.retn();
6514 }
6515
6516 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6517 {
6518   if(!((DataArray *)arr))
6519     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6520   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6521   if(!arrC)
6522     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6523   arrC->incrRef();
6524   return arrC;
6525 }
6526
6527 /*!
6528  * Returns a new MEDCouplingFieldDouble of a given type lying on
6529  * the top level cells of the first mesh in MED file. If \a this field 
6530  * has not been constructed via file reading, an exception is thrown.
6531  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6532  *  \param [in] type - a spatial discretization of interest.
6533  *  \param [out] arrOut - the DataArrayInt containing values of field.
6534  *  \param [in] renumPol - specifies how to permute values of the result field according to
6535  *          the optional numbers of cells and nodes, if any. The valid values are
6536  *          - 0 - do not permute.
6537  *          - 1 - permute cells.
6538  *          - 2 - permute nodes.
6539  *          - 3 - permute cells and nodes.
6540  *
6541  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6542  *          caller is to delete this field using decrRef() as it is no more needed. 
6543  *  \throw If \a this field has not been constructed via file reading.
6544  *  \throw If the MED file is not readable.
6545  *  \throw If there is no mesh in the MED file.
6546  *  \throw If no field values of the given \a type.
6547  *  \throw If no field values lying on the top level support.
6548  *  \sa getFieldAtLevel()
6549  */
6550 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6551 {
6552   if(getFileName().empty())
6553     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6554   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6555   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6556   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6557   return ret.retn();
6558 }
6559
6560 /*!
6561  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6562  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6563  *  \param [in] type - a spatial discretization of the new field.
6564  *  \param [in] mesh - the supporting mesh.
6565  *  \param [out] arrOut - the DataArrayInt containing values of field.
6566  *  \param [in] renumPol - specifies how to permute values of the result field according to
6567  *          the optional numbers of cells and nodes, if any. The valid values are
6568  *          - 0 - do not permute.
6569  *          - 1 - permute cells.
6570  *          - 2 - permute nodes.
6571  *          - 3 - permute cells and nodes.
6572  *
6573  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6574  *          caller is to delete this field using decrRef() as it is no more needed. 
6575  *  \throw If no field of \a this is lying on \a mesh.
6576  *  \throw If the mesh is empty.
6577  *  \throw If no field values of the given \a type are available.
6578  *  \sa getFieldAtLevel()
6579  *  \sa getFieldOnMeshAtLevel() 
6580  */
6581 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6582 {
6583   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6584   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6585   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6586   return ret.retn();
6587 }
6588
6589 /*!
6590  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6591  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6592  *  \param [in] type - a spatial discretization of interest.
6593  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6594  *  \param [out] arrOut - the DataArrayInt containing values of field.
6595  *  \param [in] mesh - the supporting mesh.
6596  *  \param [in] renumPol - specifies how to permute values of the result field according to
6597  *          the optional numbers of cells and nodes, if any. The valid values are
6598  *          - 0 - do not permute.
6599  *          - 1 - permute cells.
6600  *          - 2 - permute nodes.
6601  *          - 3 - permute cells and nodes.
6602  *
6603  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6604  *          caller is to delete this field using decrRef() as it is no more needed. 
6605  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6606  *  \throw If no field of \a this is lying on \a mesh.
6607  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6608  *  \sa getFieldAtLevel()
6609  *  \sa getFieldOnMeshAtLevel() 
6610  */
6611 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6612 {
6613   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6614   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6615   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6616   return ret.retn();
6617 }
6618
6619 /*!
6620  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6621  * This method is called "Old" because in MED3 norm a field has only one meshName
6622  * attached, so this method is for readers of MED2 files. If \a this field 
6623  * has not been constructed via file reading, an exception is thrown.
6624  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6625  *  \param [in] type - a spatial discretization of interest.
6626  *  \param [in] mName - a name of the supporting mesh.
6627  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6628  *  \param [out] arrOut - the DataArrayInt containing values of field.
6629  *  \param [in] renumPol - specifies how to permute values of the result field according to
6630  *          the optional numbers of cells and nodes, if any. The valid values are
6631  *          - 0 - do not permute.
6632  *          - 1 - permute cells.
6633  *          - 2 - permute nodes.
6634  *          - 3 - permute cells and nodes.
6635  *
6636  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6637  *          caller is to delete this field using decrRef() as it is no more needed. 
6638  *  \throw If the MED file is not readable.
6639  *  \throw If there is no mesh named \a mName in the MED file.
6640  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6641  *  \throw If \a this field has not been constructed via file reading.
6642  *  \throw If no field of \a this is lying on the mesh named \a mName.
6643  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6644  *  \sa getFieldAtLevel()
6645  */
6646 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6647 {
6648   if(getFileName().empty())
6649     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6650   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6651   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6652   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6653   return ret.retn();
6654 }
6655
6656 /*!
6657  * Returns values and a profile of the field of a given type lying on a given support.
6658  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6659  *  \param [in] type - a spatial discretization of the field.
6660  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6661  *  \param [in] mesh - the supporting mesh.
6662  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6663  *          field of interest lies on. If the field lies on all entities of the given
6664  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6665  *          using decrRef() as it is no more needed.  
6666  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6667  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6668  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6669  *  \throw If no field of \a this is lying on \a mesh.
6670  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6671  */
6672 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6673 {
6674   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6675   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6676 }
6677
6678 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
6679 {
6680   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6681   if(!pt)
6682     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6683   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6684   if(!ret)
6685     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 !");
6686   return ret;
6687 }
6688
6689 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
6690 {
6691   return contentNotNull()->getUndergroundDataArrayInt();
6692 }
6693
6694 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6695
6696 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6697 {
6698 }
6699
6700 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
6701 {
6702 }
6703
6704 /*!
6705  * \param [in] fieldId field id in C mode
6706  */
6707 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll)
6708 {
6709   med_field_type typcha;
6710   std::string dtunitOut;
6711   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6712   setDtUnit(dtunitOut.c_str());
6713   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll);
6714 }
6715
6716 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)
6717 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6718 {
6719   setDtUnit(dtunit.c_str());
6720   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll);
6721 }
6722 catch(INTERP_KERNEL::Exception& e)
6723 {
6724     throw e;
6725 }
6726
6727 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
6728 {
6729   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
6730   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6731     ret+=(*it).capacity();
6732   return ret;
6733 }
6734
6735 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
6736 {
6737   std::vector<const BigMemoryObject *> ret;
6738   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6739     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
6740   return ret;
6741 }
6742
6743 /*!
6744  * 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
6745  * NULL.
6746  */
6747 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
6748 {
6749   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6750   ret->setInfo(_infos);
6751   int sz=(int)_time_steps.size();
6752   for(const int *id=startIds;id!=endIds;id++)
6753     {
6754       if(*id>=0 && *id<sz)
6755         {
6756           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6757           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6758           if(tse)
6759             {
6760               tse->incrRef();
6761               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6762             }
6763           ret->pushBackTimeStep(tse2);
6764         }
6765       else
6766         {
6767           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6768           oss << " ! Should be in [0," << sz << ") !";
6769           throw INTERP_KERNEL::Exception(oss.str().c_str());
6770         }
6771     }
6772   if(ret->getNumberOfTS()>0)
6773     ret->synchronizeNameScope();
6774   ret->copyNameScope(*this);
6775   return ret.retn();
6776 }
6777
6778 /*!
6779  * 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
6780  * NULL.
6781  */
6782 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
6783 {
6784   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6785   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6786   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6787   ret->setInfo(_infos);
6788   int sz=(int)_time_steps.size();
6789   int j=bg;
6790   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6791     {
6792       if(j>=0 && j<sz)
6793         {
6794           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6795           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6796           if(tse)
6797             {
6798               tse->incrRef();
6799               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6800             }
6801           ret->pushBackTimeStep(tse2);
6802         }
6803       else
6804         {
6805           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6806           oss << " ! Should be in [0," << sz << ") !";
6807           throw INTERP_KERNEL::Exception(oss.str().c_str());
6808         }
6809     }
6810   if(ret->getNumberOfTS()>0)
6811     ret->synchronizeNameScope();
6812   ret->copyNameScope(*this);
6813   return ret.retn();
6814 }
6815
6816 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6817 {
6818   int id=0;
6819   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6820   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6821     {
6822       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6823       if(!cur)
6824         continue;
6825       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6826       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6827         ids->pushBackSilent(id);
6828     }
6829   return buildFromTimeStepIds(ids->begin(),ids->end());
6830 }
6831
6832 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6833 {
6834   int id=0;
6835   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6836   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6837     {
6838       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6839       if(!cur)
6840         continue;
6841       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6842       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6843         ids->pushBackSilent(id);
6844     }
6845   return buildFromTimeStepIds(ids->begin(),ids->end());
6846 }
6847
6848 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
6849 {
6850   return _infos;
6851 }
6852
6853 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
6854 {
6855   _infos=info;
6856 }
6857
6858 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
6859 {
6860   int ret=0;
6861   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6862     {
6863       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6864       if(pt->isDealingTS(iteration,order))
6865         return ret;
6866     }
6867   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6868   std::vector< std::pair<int,int> > vp=getIterations();
6869   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6870     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6871   throw INTERP_KERNEL::Exception(oss.str().c_str());
6872 }
6873
6874 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
6875 {
6876   return *_time_steps[getTimeStepPos(iteration,order)];
6877 }
6878
6879 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
6880 {
6881   return *_time_steps[getTimeStepPos(iteration,order)];
6882 }
6883
6884 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
6885 {
6886   if(_time_steps.empty())
6887     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6888   return _time_steps[0]->getMeshName();
6889 }
6890
6891 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
6892 {
6893   std::string oldName(getMeshName());
6894   std::vector< std::pair<std::string,std::string> > v(1);
6895   v[0].first=oldName; v[0].second=newMeshName;
6896   changeMeshNames(v);
6897 }
6898
6899 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6900 {
6901   bool ret=false;
6902   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6903     {
6904       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6905       if(cur)
6906         ret=cur->changeMeshNames(modifTab) || ret;
6907     }
6908   return ret;
6909 }
6910
6911 /*!
6912  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6913  */
6914 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
6915 {
6916   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6917 }
6918
6919 /*!
6920  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6921  */
6922 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6923 {
6924   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6925 }
6926
6927 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6928                                                                        MEDFileFieldGlobsReal& glob)
6929 {
6930   bool ret=false;
6931   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6932     {
6933       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6934       if(f1ts)
6935         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6936     }
6937   return ret;
6938 }
6939
6940 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6941 {
6942   std::string startLine(bkOffset,' ');
6943   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
6944   if(fmtsId>=0)
6945     oss << " (" << fmtsId << ")";
6946   oss << " has the following name: \"" << _name << "\"." << std::endl;
6947   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
6948   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6949     {
6950       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
6951     }
6952   int i=0;
6953   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
6954     {
6955       std::string chapter(17,'0'+i);
6956       oss << startLine << chapter << std::endl;
6957       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6958       if(cur)
6959         cur->simpleRepr(bkOffset+2,oss,i);
6960       else
6961         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
6962       oss << startLine << chapter << std::endl;
6963     }
6964 }
6965
6966 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
6967 {
6968   std::size_t sz=_time_steps.size();
6969   std::vector< std::pair<int,int> > ret(sz);
6970   ret1.resize(sz);
6971   for(std::size_t i=0;i<sz;i++)
6972     {
6973       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
6974       if(f1ts)
6975         {
6976           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
6977         }
6978       else
6979         {
6980           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
6981           throw INTERP_KERNEL::Exception(oss.str().c_str());
6982         }
6983     }
6984   return ret;
6985 }
6986
6987 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
6988 {
6989   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
6990   if(!tse2)
6991     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
6992   checkCoherencyOfType(tse2);
6993   if(_time_steps.empty())
6994     {
6995       setName(tse2->getName().c_str());
6996       setInfo(tse2->getInfo());
6997     }
6998   checkThatComponentsMatch(tse2->getInfo());
6999   _time_steps.push_back(tse);
7000 }
7001
7002 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7003 {
7004   std::size_t nbOfCompo=_infos.size();
7005   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7006     {
7007       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7008       if(cur)
7009         {
7010           if((cur->getInfo()).size()!=nbOfCompo)
7011             {
7012               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7013               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7014               throw INTERP_KERNEL::Exception(oss.str().c_str());
7015             }
7016           cur->copyNameScope(*this);
7017         }
7018     }
7019 }
7020
7021 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll)
7022 {
7023   _time_steps.resize(nbPdt);
7024   for(int i=0;i<nbPdt;i++)
7025     {
7026       std::vector< std::pair<int,int> > ts;
7027       med_int numdt=0,numo=0;
7028       med_int meshIt=0,meshOrder=0;
7029       med_float dt=0.0;
7030       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
7031       switch(fieldTyp)
7032       {
7033         case MED_FLOAT64:
7034           {
7035             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7036             break;
7037           }
7038         case MED_INT32:
7039           {
7040             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7041             break;
7042           }
7043         default:
7044           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7045       }
7046       if(loadAll)
7047         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this);
7048       else
7049         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this);
7050     }
7051 }
7052
7053 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7054 {
7055   if(_time_steps.empty())
7056     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7057   checkThatNbOfCompoOfTSMatchThis();
7058   std::vector<std::string> infos(getInfo());
7059   int nbComp=infos.size();
7060   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7061   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7062   for(int i=0;i<nbComp;i++)
7063     {
7064       std::string info=infos[i];
7065       std::string c,u;
7066       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7067       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7068       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7069     }
7070   if(_name.empty())
7071     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7072   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7073   int nbOfTS=_time_steps.size();
7074   for(int i=0;i<nbOfTS;i++)
7075     _time_steps[i]->writeLL(fid,opts,*this);
7076 }
7077
7078 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7079 {
7080   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7081     {
7082       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7083       if(elt)
7084         elt->loadBigArraysRecursively(fid,nasc);
7085     }
7086 }
7087
7088 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7089 {
7090   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7091     {
7092       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7093       if(elt)
7094         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7095     }
7096 }
7097
7098 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7099 {
7100   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7101     {
7102       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7103       if(elt)
7104         elt->unloadArrays();
7105     }
7106 }
7107
7108 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7109 {
7110   return _time_steps.size();
7111 }
7112
7113 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7114 {
7115   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7116   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7117     {
7118       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7119       if(tmp)
7120         newTS.push_back(*it);
7121     }
7122   _time_steps=newTS;
7123 }
7124
7125 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7126 {
7127   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7128   int maxId=(int)_time_steps.size();
7129   int ii=0;
7130   std::set<int> idsToDel;
7131   for(const int *id=startIds;id!=endIds;id++,ii++)
7132     {
7133       if(*id>=0 && *id<maxId)
7134         {
7135           idsToDel.insert(*id);
7136         }
7137       else
7138         {
7139           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7140           throw INTERP_KERNEL::Exception(oss.str().c_str());
7141         }
7142     }
7143   for(int iii=0;iii<maxId;iii++)
7144     if(idsToDel.find(iii)==idsToDel.end())
7145       newTS.push_back(_time_steps[iii]);
7146   _time_steps=newTS;
7147 }
7148
7149 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7150 {
7151   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7152   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7153   if(nbOfEntriesToKill==0)
7154     return ;
7155   std::size_t sz=_time_steps.size();
7156   std::vector<bool> b(sz,true);
7157   int j=bg;
7158   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7159     b[j]=false;
7160   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7161   for(std::size_t i=0;i<sz;i++)
7162     if(b[i])
7163       newTS.push_back(_time_steps[i]);
7164   _time_steps=newTS;
7165 }
7166
7167 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7168 {
7169   int ret=0;
7170   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7171   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7172     {
7173       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7174       if(tmp)
7175         {
7176           int it2,ord;
7177           tmp->getTime(it2,ord);
7178           if(it2==iteration && order==ord)
7179             return ret;
7180           else
7181             oss << "(" << it2 << ","  << ord << "), ";
7182         }
7183     }
7184   throw INTERP_KERNEL::Exception(oss.str().c_str());
7185 }
7186
7187 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7188 {
7189   int ret=0;
7190   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7191   oss.precision(15);
7192   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7193     {
7194       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7195       if(tmp)
7196         {
7197           int it2,ord;
7198           double ti=tmp->getTime(it2,ord);
7199           if(fabs(time-ti)<eps)
7200             return ret;
7201           else
7202             oss << ti << ", ";
7203         }
7204     }
7205   throw INTERP_KERNEL::Exception(oss.str().c_str());
7206 }
7207
7208 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7209 {
7210   int lgth=_time_steps.size();
7211   std::vector< std::pair<int,int> > ret(lgth);
7212   for(int i=0;i<lgth;i++)
7213     _time_steps[i]->fillIteration(ret[i]);
7214   return ret;
7215 }
7216
7217 /*!
7218  * 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'
7219  * This method returns two things.
7220  * - The absolute dimension of 'this' in first parameter. 
7221  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7222  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7223  *
7224  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7225  * Only these 3 discretizations will be taken into account here.
7226  *
7227  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7228  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7229  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7230  *
7231  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7232  * 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'.
7233  * 
7234  * Let's consider the typical following case :
7235  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7236  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7237  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7238  *   TETRA4 and SEG2
7239  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7240  *
7241  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7242  * 
7243  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7244  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7245  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7246  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7247  */
7248 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7249 {
7250   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7251 }
7252
7253 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7254 {
7255   if(pos<0 || pos>=(int)_time_steps.size())
7256     {
7257       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7258       throw INTERP_KERNEL::Exception(oss.str().c_str());
7259     }
7260   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7261   if(item==0)
7262     {
7263       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7264       oss << "\nTry to use following method eraseEmptyTS !";
7265       throw INTERP_KERNEL::Exception(oss.str().c_str());
7266     }
7267   return item;
7268 }
7269
7270 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7271 {
7272   if(pos<0 || pos>=(int)_time_steps.size())
7273     {
7274       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7275       throw INTERP_KERNEL::Exception(oss.str().c_str());
7276     }
7277   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7278   if(item==0)
7279     {
7280       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7281       oss << "\nTry to use following method eraseEmptyTS !";
7282       throw INTERP_KERNEL::Exception(oss.str().c_str());
7283     }
7284   return item;
7285 }
7286
7287 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7288 {
7289   std::vector<std::string> ret;
7290   std::set<std::string> ret2;
7291   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7292     {
7293       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7294       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7295         if(ret2.find(*it2)==ret2.end())
7296           {
7297             ret.push_back(*it2);
7298             ret2.insert(*it2);
7299           }
7300     }
7301   return ret;
7302 }
7303
7304 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7305 {
7306   std::vector<std::string> ret;
7307   std::set<std::string> ret2;
7308   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7309     {
7310       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7311       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7312         if(ret2.find(*it2)==ret2.end())
7313           {
7314             ret.push_back(*it2);
7315             ret2.insert(*it2);
7316           }
7317     }
7318   return ret;
7319 }
7320
7321 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7322 {
7323   std::vector<std::string> ret;
7324   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7325     {
7326       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7327       ret.insert(ret.end(),tmp.begin(),tmp.end());
7328     }
7329   return ret;
7330 }
7331
7332 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7333 {
7334   std::vector<std::string> ret;
7335   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7336     {
7337       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7338       ret.insert(ret.end(),tmp.begin(),tmp.end());
7339     }
7340   return ret;
7341 }
7342
7343 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7344 {
7345   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7346     (*it)->changePflsRefsNamesGen2(mapOfModif);
7347 }
7348
7349 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7350 {
7351   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7352     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7353 }
7354
7355 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7356 {
7357   int lgth=_time_steps.size();
7358   std::vector< std::vector<TypeOfField> > ret(lgth);
7359   for(int i=0;i<lgth;i++)
7360     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7361   return ret;
7362 }
7363
7364 /*!
7365  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7366  */
7367 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
7368 {
7369   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7370 }
7371
7372 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7373 {
7374   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7375   std::size_t i=0;
7376   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7377     {
7378       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7379         ret->_time_steps[i]=(*it)->deepCpy();
7380     }
7381   return ret.retn();
7382 }
7383
7384 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7385 {
7386   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7387   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7388   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7389   for(std::size_t i=0;i<sz;i++)
7390     {
7391       ret[i]=shallowCpy();
7392       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7393     }
7394   for(std::size_t i=0;i<sz2;i++)
7395     {
7396       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7397       if(ret1.size()!=sz)
7398         {
7399           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7400           throw INTERP_KERNEL::Exception(oss.str().c_str());
7401         }
7402       ts[i]=ret1;
7403     }
7404   for(std::size_t i=0;i<sz;i++)
7405     for(std::size_t j=0;j<sz2;j++)
7406       ret[i]->_time_steps[j]=ts[j][i];
7407   return ret;
7408 }
7409
7410 /*!
7411  * This method splits into discretization each time steps in \a this.
7412  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7413  */
7414 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7415 {
7416   std::size_t sz(_time_steps.size());
7417   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7418   for(std::size_t i=0;i<sz;i++)
7419     {
7420       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7421       if(!timeStep)
7422         {
7423           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7424           throw INTERP_KERNEL::Exception(oss.str().c_str());
7425         }
7426       items[i]=timeStep->splitDiscretizations();  
7427     }
7428   //
7429   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7430   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7431   std::vector< TypeOfField > types;
7432   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7433     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7434       {
7435         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7436         if(ts.size()!=1)
7437           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7438         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7439         if(it2==types.end())
7440           types.push_back(ts[0]);
7441       }
7442   ret.resize(types.size()); ret2.resize(types.size());
7443   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7444     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7445       {
7446         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7447         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7448         ret2[pos].push_back(*it1);
7449       }
7450   for(std::size_t i=0;i<types.size();i++)
7451     {
7452       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=createNew();
7453       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7454         elt->pushBackTimeStep(*it1);//also updates infos in elt
7455       ret[i]=elt;
7456       elt->MEDFileFieldNameScope::operator=(*this);
7457     }
7458   return ret;
7459 }
7460
7461 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7462 {
7463   _name=field->getName();
7464   if(_name.empty())
7465     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7466   if(!arr)
7467     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7468   _infos=arr->getInfoOnComponents();
7469 }
7470
7471 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7472 {
7473   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7474   if(_name!=field->getName())
7475     {
7476       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7477       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7478       throw INTERP_KERNEL::Exception(oss.str().c_str());
7479     }
7480   if(!arr)
7481     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7482   checkThatComponentsMatch(arr->getInfoOnComponents());
7483 }
7484
7485 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7486 {
7487   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7488   if(getInfo().size()!=compos.size())
7489     {
7490       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7491       oss << " number of components of element to append (" << compos.size() << ") !";
7492       throw INTERP_KERNEL::Exception(oss.str().c_str());
7493     }
7494   if(_infos!=compos)
7495     {
7496       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7497       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7498       oss << " But compo in input fields are : ";
7499       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7500       oss << " !";
7501       throw INTERP_KERNEL::Exception(oss.str().c_str());
7502     }
7503 }
7504
7505 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7506 {
7507   std::size_t sz=_infos.size();
7508   int j=0;
7509   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7510     {
7511       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7512       if(elt)
7513         if(elt->getInfo().size()!=sz)
7514           {
7515             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7516             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7517             throw INTERP_KERNEL::Exception(oss.str().c_str());
7518           }
7519     }
7520 }
7521
7522 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7523 {
7524   if(!field)
7525     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7526   if(!_time_steps.empty())
7527     checkCoherencyOfTinyInfo(field,arr);
7528   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7529   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7530   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7531   copyTinyInfoFrom(field,arr);
7532   _time_steps.push_back(obj);
7533 }
7534
7535 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7536 {
7537   if(!field)
7538     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7539   if(!_time_steps.empty())
7540     checkCoherencyOfTinyInfo(field,arr);
7541   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7542   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7543   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7544   copyTinyInfoFrom(field,arr);
7545   _time_steps.push_back(obj);
7546 }
7547
7548 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7549 {
7550   int sz=(int)_time_steps.size();
7551   if(i<0 || i>=sz)
7552     {
7553       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7554       throw INTERP_KERNEL::Exception(oss.str().c_str());
7555     }
7556   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7557   if(tsPtr)
7558     {
7559       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7560         {
7561           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7562           throw INTERP_KERNEL::Exception(oss.str().c_str());
7563         }
7564     }
7565   _time_steps[i]=ts;
7566 }
7567
7568 //= MEDFileFieldMultiTSWithoutSDA
7569
7570 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)
7571 {
7572   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7573 }
7574
7575 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7576 {
7577 }
7578
7579 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7580 {
7581 }
7582
7583 /*!
7584  * \param [in] fieldId field id in C mode
7585  */
7586 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll)
7587 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7588 {
7589 }
7590 catch(INTERP_KERNEL::Exception& e)
7591 { throw e; }
7592
7593 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)
7594 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7595 {
7596 }
7597 catch(INTERP_KERNEL::Exception& e)
7598 { throw e; }
7599
7600 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7601 {
7602   return new MEDFileField1TSWithoutSDA;
7603 }
7604
7605 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7606 {
7607   if(!f1ts)
7608     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7609   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7610   if(!f1tsC)
7611     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7612 }
7613
7614 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7615 {
7616   return MEDFileField1TSWithoutSDA::TYPE_STR;
7617 }
7618
7619 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7620 {
7621   return new MEDFileFieldMultiTSWithoutSDA(*this);
7622 }
7623
7624 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7625 {
7626   return new MEDFileFieldMultiTSWithoutSDA;
7627 }
7628
7629 /*!
7630  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7631  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7632  */
7633 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
7634 {
7635   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7636   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7637   if(!myF1TSC)
7638     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7639   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7640 }
7641
7642 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
7643 {
7644   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7645   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7646   int i=0;
7647   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7648     {
7649       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7650       if(eltToConv)
7651         {
7652           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7653           if(!eltToConvC)
7654             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7655           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7656           ret->setIteration(i,elt);
7657         }
7658     }
7659   return ret.retn();
7660 }
7661
7662 //= MEDFileAnyTypeFieldMultiTS
7663
7664 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7665 {
7666 }
7667
7668 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll)
7669 try:MEDFileFieldGlobsReal(fileName)
7670 {
7671   MEDFileUtilities::CheckFileForRead(fileName);
7672   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7673   _content=BuildContentFrom(fid,fileName,loadAll);
7674   loadGlobals(fid);
7675 }
7676 catch(INTERP_KERNEL::Exception& e)
7677 {
7678     throw e;
7679 }
7680
7681 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll)
7682 {
7683   med_field_type typcha;
7684   std::vector<std::string> infos;
7685   std::string dtunit;
7686   int i=-1;
7687   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7688   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7689   switch(typcha)
7690   {
7691     case MED_FLOAT64:
7692       {
7693         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll);
7694         break;
7695       }
7696     case MED_INT32:
7697       {
7698         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll);
7699         break;
7700       }
7701     default:
7702       {
7703         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] !";
7704         throw INTERP_KERNEL::Exception(oss.str().c_str());
7705       }
7706   }
7707   ret->setDtUnit(dtunit.c_str());
7708   return ret.retn();
7709 }
7710
7711 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll)
7712 {
7713   med_field_type typcha;
7714   //
7715   std::vector<std::string> infos;
7716   std::string dtunit,fieldName;
7717   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7718   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7719   switch(typcha)
7720   {
7721     case MED_FLOAT64:
7722       {
7723         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll);
7724         break;
7725       }
7726     case MED_INT32:
7727       {
7728         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll);
7729         break;
7730       }
7731     default:
7732       {
7733         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] !";
7734         throw INTERP_KERNEL::Exception(oss.str().c_str());
7735       }
7736   }
7737   ret->setDtUnit(dtunit.c_str());
7738   return ret.retn();
7739 }
7740
7741 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
7742 {
7743   if(!c)
7744     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7745   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7746     {
7747       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7748       ret->setFileName(fileName);
7749       ret->_content=c;  c->incrRef();
7750       return ret.retn();
7751     }
7752   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7753     {
7754       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7755       ret->setFileName(fileName);
7756       ret->_content=c;  c->incrRef();
7757       return ret.retn();
7758     }
7759   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7760 }
7761
7762 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll)
7763 try:MEDFileFieldGlobsReal(fileName)
7764 {
7765   MEDFileUtilities::CheckFileForRead(fileName);
7766   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7767   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
7768   loadGlobals(fid);
7769 }
7770 catch(INTERP_KERNEL::Exception& e)
7771 {
7772     throw e;
7773 }
7774
7775 //= MEDFileIntFieldMultiTSWithoutSDA
7776
7777 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)
7778 {
7779   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7780 }
7781
7782 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7783 {
7784 }
7785
7786 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7787 {
7788 }
7789
7790 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)
7791 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7792 {
7793 }
7794 catch(INTERP_KERNEL::Exception& e)
7795 { throw e; }
7796
7797 /*!
7798  * \param [in] fieldId field id in C mode
7799  */
7800 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll)
7801 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7802 {
7803 }
7804 catch(INTERP_KERNEL::Exception& e)
7805 { throw e; }
7806
7807 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7808 {
7809   return new MEDFileIntField1TSWithoutSDA;
7810 }
7811
7812 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7813 {
7814   if(!f1ts)
7815     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7816   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7817   if(!f1tsC)
7818     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7819 }
7820
7821 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
7822 {
7823   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7824 }
7825
7826 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
7827 {
7828   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7829 }
7830
7831 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
7832 {
7833   return new MEDFileIntFieldMultiTSWithoutSDA;
7834 }
7835
7836 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
7837 {
7838   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7839   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7840   int i=0;
7841   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7842     {
7843       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7844       if(eltToConv)
7845         {
7846           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7847           if(!eltToConvC)
7848             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7849           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7850           ret->setIteration(i,elt);
7851         }
7852     }
7853   return ret.retn();
7854 }
7855
7856 //= MEDFileAnyTypeFieldMultiTS
7857
7858 /*!
7859  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7860  * that has been read from a specified MED file.
7861  *  \param [in] fileName - the name of the MED file to read.
7862  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7863  *          is to delete this field using decrRef() as it is no more needed.
7864  *  \throw If reading the file fails.
7865  */
7866 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
7867 {
7868   MEDFileUtilities::CheckFileForRead(fileName);
7869   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7870   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
7871   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7872   ret->loadGlobals(fid);
7873   return ret.retn();
7874 }
7875
7876 /*!
7877  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7878  * that has been read from a specified MED file.
7879  *  \param [in] fileName - the name of the MED file to read.
7880  *  \param [in] fieldName - the name of the field to read.
7881  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7882  *          is to delete this field using decrRef() as it is no more needed.
7883  *  \throw If reading the file fails.
7884  *  \throw If there is no field named \a fieldName in the file.
7885  */
7886 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
7887 {
7888   MEDFileUtilities::CheckFileForRead(fileName);
7889   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7890   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
7891   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7892   ret->loadGlobals(fid);
7893   return ret.retn();
7894 }
7895
7896 /*!
7897  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7898  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7899  *
7900  * \warning this is a shallow copy constructor
7901  */
7902 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7903 {
7904   if(!shallowCopyOfContent)
7905     {
7906       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7907       otherPtr->incrRef();
7908       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7909     }
7910   else
7911     {
7912       _content=other.shallowCpy();
7913     }
7914 }
7915
7916 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
7917 {
7918   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7919   if(!ret)
7920     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7921   return ret;
7922 }
7923
7924 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
7925 {
7926   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7927   if(!ret)
7928     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7929   return ret;
7930 }
7931
7932 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7933 {
7934   return contentNotNullBase()->getPflsReallyUsed2();
7935 }
7936
7937 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7938 {
7939   return contentNotNullBase()->getLocsReallyUsed2();
7940 }
7941
7942 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
7943 {
7944   return contentNotNullBase()->getPflsReallyUsedMulti2();
7945 }
7946
7947 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
7948 {
7949   return contentNotNullBase()->getLocsReallyUsedMulti2();
7950 }
7951
7952 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7953 {
7954   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
7955 }
7956
7957 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7958 {
7959   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
7960 }
7961
7962 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
7963 {
7964   return contentNotNullBase()->getNumberOfTS();
7965 }
7966
7967 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
7968 {
7969   contentNotNullBase()->eraseEmptyTS();
7970 }
7971
7972 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
7973 {
7974   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
7975 }
7976
7977 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
7978 {
7979   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
7980 }
7981
7982 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
7983 {
7984   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
7985   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7986   ret->_content=c;
7987   return ret.retn();
7988 }
7989
7990 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
7991 {
7992   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
7993   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
7994   ret->_content=c;
7995   return ret.retn();
7996 }
7997
7998 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
7999 {
8000   return contentNotNullBase()->getIterations();
8001 }
8002
8003 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8004 {
8005   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8006     pushBackTimeStep(*it);
8007 }
8008
8009 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8010 {
8011   if(!f1ts)
8012     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8013   checkCoherencyOfType(f1ts);
8014   f1ts->incrRef();
8015   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8016   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8017   c->incrRef();
8018   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8019   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8020     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8021   _content->pushBackTimeStep(cSafe);
8022   appendGlobs(*f1ts,1e-12);
8023 }
8024
8025 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8026 {
8027   contentNotNullBase()->synchronizeNameScope();
8028 }
8029
8030 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8031 {
8032   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8033 }
8034
8035 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8036 {
8037   return contentNotNullBase()->getPosGivenTime(time,eps);
8038 }
8039
8040 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8041 {
8042   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8043 }
8044
8045 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8046 {
8047   return contentNotNullBase()->getTypesOfFieldAvailable();
8048 }
8049
8050 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
8051 {
8052   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8053 }
8054
8055 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8056 {
8057   return contentNotNullBase()->getName();
8058 }
8059
8060 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8061 {
8062   contentNotNullBase()->setName(name);
8063 }
8064
8065 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8066 {
8067   return contentNotNullBase()->getDtUnit();
8068 }
8069
8070 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8071 {
8072   contentNotNullBase()->setDtUnit(dtUnit);
8073 }
8074
8075 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8076 {
8077   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8078 }
8079
8080 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8081 {
8082   return contentNotNullBase()->getTimeSteps(ret1);
8083 }
8084
8085 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8086 {
8087   return contentNotNullBase()->getMeshName();
8088 }
8089
8090 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8091 {
8092   contentNotNullBase()->setMeshName(newMeshName);
8093 }
8094
8095 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8096 {
8097   return contentNotNullBase()->changeMeshNames(modifTab);
8098 }
8099
8100 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8101 {
8102   return contentNotNullBase()->getInfo();
8103 }
8104
8105 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8106 {
8107   return contentNotNullBase()->setInfo(info);
8108 }
8109
8110 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8111 {
8112   const std::vector<std::string> ret=getInfo();
8113   return (int)ret.size();
8114 }
8115
8116 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8117 {
8118   writeGlobals(fid,*this);
8119   contentNotNullBase()->writeLL(fid,*this);
8120 }
8121
8122 /*!
8123  * Writes \a this field into a MED file specified by its name.
8124  *  \param [in] fileName - the MED file name.
8125  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8126  * - 2 - erase; an existing file is removed.
8127  * - 1 - append; same data should not be present in an existing file.
8128  * - 0 - overwrite; same data present in an existing file is overwritten.
8129  *  \throw If the field name is not set.
8130  *  \throw If no field data is set.
8131  *  \throw If \a mode == 1 and the same data is present in an existing file.
8132  */
8133 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8134 {
8135   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8136   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8137   writeLL(fid);
8138 }
8139
8140 /*!
8141  * This method alloc the arrays and load potentially huge arrays contained in this field.
8142  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8143  * This method can be also called to refresh or reinit values from a file.
8144  * 
8145  * \throw If the fileName is not set or points to a non readable MED file.
8146  */
8147 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8148 {
8149   if(getFileName().empty())
8150     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8151   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8152   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8153 }
8154
8155 /*!
8156  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8157  * But once data loaded once, this method does nothing.
8158  * 
8159  * \throw If the fileName is not set or points to a non readable MED file.
8160  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8161  */
8162 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8163 {
8164   if(!getFileName().empty())
8165     {
8166       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8167       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8168     }
8169 }
8170
8171 /*!
8172  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8173  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8174  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8175  * 
8176  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8177  */
8178 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8179 {
8180   contentNotNullBase()->unloadArrays();
8181 }
8182
8183 /*!
8184  * 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.
8185  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8186  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8187  * 
8188  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8189  */
8190 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8191 {
8192   if(!getFileName().empty())
8193     contentNotNullBase()->unloadArrays();
8194 }
8195
8196 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8197 {
8198   std::ostringstream oss;
8199   contentNotNullBase()->simpleRepr(0,oss,-1);
8200   simpleReprGlobs(oss);
8201   return oss.str();
8202 }
8203
8204 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8205 {
8206   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8207 }
8208
8209 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8210 {
8211   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8212   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8213   return ret;
8214 }
8215
8216 /*!
8217  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8218  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8219  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8220  */
8221 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8222 {
8223   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8224   if(!content)
8225     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8226   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8227   std::size_t sz(contentsSplit.size());
8228   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8229   for(std::size_t i=0;i<sz;i++)
8230     {
8231       ret[i]=shallowCpy();
8232       ret[i]->_content=contentsSplit[i];
8233     }
8234   return ret;
8235 }
8236
8237 /*!
8238  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8239  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8240  */
8241 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8242 {
8243   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8244   if(!content)
8245     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8246   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitDiscretizations();
8247   std::size_t sz(contentsSplit.size());
8248   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8249   for(std::size_t i=0;i<sz;i++)
8250     {
8251       ret[i]=shallowCpy();
8252       ret[i]->_content=contentsSplit[i];
8253     }
8254   return ret;
8255 }
8256
8257 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8258 {
8259   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8260   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8261     ret->_content=_content->deepCpy();
8262   ret->deepCpyGlobs(*this);
8263   return ret.retn();
8264 }
8265
8266 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8267 {
8268   return _content;
8269 }
8270
8271 /*!
8272  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8273  *  \param [in] iteration - the iteration number of a required time step.
8274  *  \param [in] order - the iteration order number of required time step.
8275  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8276  *          delete this field using decrRef() as it is no more needed.
8277  *  \throw If there is no required time step in \a this field.
8278  */
8279 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8280 {
8281   int pos=getPosOfTimeStep(iteration,order);
8282   return getTimeStepAtPos(pos);
8283 }
8284
8285 /*!
8286  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8287  *  \param [in] time - the time of the time step of interest.
8288  *  \param [in] eps - a precision used to compare time values.
8289  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8290  *          delete this field using decrRef() as it is no more needed.
8291  *  \throw If there is no required time step in \a this field.
8292  */
8293 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8294 {
8295   int pos=getPosGivenTime(time,eps);
8296   return getTimeStepAtPos(pos);
8297 }
8298
8299 /*!
8300  * 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.
8301  * The float64 value of time attached to the pair of integers are not considered here.
8302  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8303  *
8304  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8305  * \throw If there is a null pointer in \a vectFMTS.
8306  */
8307 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8308 {
8309   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8310   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8311   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8312   while(!lstFMTS.empty())
8313     {
8314       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8315       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8316       if(!curIt)
8317         throw INTERP_KERNEL::Exception(msg);
8318       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8319       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8320       elt.push_back(curIt); it=lstFMTS.erase(it);
8321       while(it!=lstFMTS.end())
8322         {
8323           curIt=*it;
8324           if(!curIt)
8325             throw INTERP_KERNEL::Exception(msg);
8326           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8327           if(refIts==curIts)
8328             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8329           else
8330             it++;
8331         }
8332       ret.push_back(elt);
8333     }
8334   return ret;
8335 }
8336
8337 /*!
8338  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8339  * All returned instances in a subvector can be safely loaded, rendered along time
8340  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8341  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8342  * 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).
8343  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8344  * 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.
8345  *
8346  * \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().
8347  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8348  * \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.
8349  * \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.
8350  *
8351  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8352  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8353  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8354  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8355  * \throw If mesh is null.
8356  * \throw If an element in \a vectFMTS is null.
8357  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8358  */
8359 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8360 {
8361   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8362   if(!mesh)
8363     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8364   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8365   if(vectFMTS.empty())
8366     return ret;
8367   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8368   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8369   if(!frstElt)
8370     throw INTERP_KERNEL::Exception(msg);
8371   std::size_t i=0;
8372   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8373   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8374   for(;it!=vectFMTS.end();it++,i++)
8375     {
8376       if(!(*it))
8377         throw INTERP_KERNEL::Exception(msg);
8378       TypeOfField tof0,tof1;
8379       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8380         {
8381           if(tof1!=ON_NODES)
8382             vectFMTSNotNodes.push_back(*it);
8383           else
8384             vectFMTSNodes.push_back(*it);
8385         }
8386       else
8387         vectFMTSNotNodes.push_back(*it);
8388     }
8389   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8390   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8391   ret=retCell;
8392   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8393     {
8394       i=0;
8395       bool isFetched(false);
8396       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8397         {
8398           if((*it0).empty())
8399             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8400           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8401             { ret[i].push_back(*it2); isFetched=true; }
8402         }
8403       if(!isFetched)
8404         {
8405           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8406           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8407           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8408         }
8409     }
8410   fsc=cmps;
8411   return ret;
8412 }
8413
8414 /*!
8415  * 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.
8416  * \param [out] cmps - same size than the returned vector.
8417  */
8418 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8419 {
8420   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8421   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8422   while(!lstFMTS.empty())
8423     {
8424       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8425       MEDFileAnyTypeFieldMultiTS *ref(*it);
8426       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8427       elt.push_back(ref); it=lstFMTS.erase(it);
8428       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8429       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8430       while(it!=lstFMTS.end())
8431         {
8432           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8433           if(cmp->isEqual(curIt))
8434             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8435           else
8436             it++;
8437         }
8438       ret.push_back(elt); cmps.push_back(cmp);
8439     }
8440   return ret;
8441 }
8442
8443 /*!
8444  * 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.
8445  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8446  *
8447  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8448  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8449  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8450  * \thorw If \a f0 and \a f1 do not have the same times steps.
8451  * \throw If mesh is null.
8452  * \throw If \a f0 or \a f1 is null.
8453  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8454  */
8455 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8456 {
8457   if(!mesh)
8458     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8459   if(!f0 || !f1)
8460     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8461   if(f0->getMeshName()!=mesh->getName())
8462     {
8463       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8464       throw INTERP_KERNEL::Exception(oss.str().c_str());
8465     }
8466   if(f1->getMeshName()!=mesh->getName())
8467     {
8468       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8469       throw INTERP_KERNEL::Exception(oss.str().c_str());
8470     }
8471   int nts=f0->getNumberOfTS();
8472   if(nts!=f1->getNumberOfTS())
8473     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8474   if(nts==0)
8475     return nts;
8476   for(int i=0;i<nts;i++)
8477     {
8478       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8479       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8480       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8481       if(tofs0.size()!=1 || tofs1.size()!=1)
8482         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8483       if(i!=0)
8484         {
8485           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8486             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8487         }
8488       else
8489         { tof0=tofs0[0]; tof1=tofs1[0]; }
8490       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8491         {
8492           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() << ") !";
8493           throw INTERP_KERNEL::Exception(oss.str().c_str());
8494         }
8495       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8496         {
8497           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() << ") !";
8498           throw INTERP_KERNEL::Exception(oss.str().c_str());
8499         }
8500       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8501         {
8502           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() << ") !";
8503           throw INTERP_KERNEL::Exception(oss.str().c_str());
8504         }
8505     }
8506   return nts;
8507 }
8508
8509 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8510 {
8511   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8512 }
8513
8514 //= MEDFileFieldMultiTS
8515
8516 /*!
8517  * Returns a new empty instance of MEDFileFieldMultiTS.
8518  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8519  *          is to delete this field using decrRef() as it is no more needed.
8520  */
8521 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8522 {
8523   return new MEDFileFieldMultiTS;
8524 }
8525
8526 /*!
8527  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8528  * that has been read from a specified MED file.
8529  *  \param [in] fileName - the name of the MED file to read.
8530  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8531  *          is to delete this field using decrRef() as it is no more needed.
8532  *  \throw If reading the file fails.
8533  */
8534 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8535 {
8536   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll);
8537   ret->contentNotNull();//to check that content type matches with \a this type.
8538   return ret.retn();
8539 }
8540
8541 /*!
8542  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8543  * that has been read from a specified MED file.
8544  *  \param [in] fileName - the name of the MED file to read.
8545  *  \param [in] fieldName - the name of the field to read.
8546  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8547  *          is to delete this field using decrRef() as it is no more needed.
8548  *  \throw If reading the file fails.
8549  *  \throw If there is no field named \a fieldName in the file.
8550  */
8551 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8552 {
8553   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll);
8554   ret->contentNotNull();//to check that content type matches with \a this type.
8555   return ret.retn();
8556 }
8557
8558 /*!
8559  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8560  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8561  *
8562  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8563  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8564  * \warning this is a shallow copy constructor
8565  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8566  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8567  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8568  *          is to delete this field using decrRef() as it is no more needed.
8569  */
8570 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8571 {
8572   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8573 }
8574
8575 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8576 {
8577   return new MEDFileFieldMultiTS(*this);
8578 }
8579
8580 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8581 {
8582   if(!f1ts)
8583     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8584   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8585   if(!f1tsC)
8586     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8587 }
8588
8589 /*!
8590  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8591  * following the given input policy.
8592  *
8593  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8594  *                            By default (true) the globals are deeply copied.
8595  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8596  */
8597 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8598 {
8599   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8600   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8601   if(content)
8602     {
8603       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8604       if(!contc)
8605         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8606       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8607       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8608     }
8609   else
8610     ret=MEDFileIntFieldMultiTS::New();
8611   if(isDeepCpyGlobs)
8612     ret->deepCpyGlobs(*this);
8613   else
8614     ret->shallowCpyGlobs(*this);
8615   return ret.retn();
8616 }
8617
8618 /*!
8619  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8620  *  \param [in] pos - a time step id.
8621  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8622  *          delete this field using decrRef() as it is no more needed.
8623  *  \throw If \a pos is not a valid time step id.
8624  */
8625 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
8626 {
8627   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8628   if(!item)
8629     {
8630       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8631       throw INTERP_KERNEL::Exception(oss.str().c_str());
8632     }
8633   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8634   if(itemC)
8635     {
8636       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8637       ret->shallowCpyGlobs(*this);
8638       return ret.retn();
8639     }
8640   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8641   throw INTERP_KERNEL::Exception(oss.str().c_str());
8642 }
8643
8644 /*!
8645  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8646  * mesh entities of a given dimension of the first mesh in MED file.
8647  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8648  *  \param [in] type - a spatial discretization of interest.
8649  *  \param [in] iteration - the iteration number of a required time step.
8650  *  \param [in] order - the iteration order number of required time step.
8651  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8652  *  \param [in] renumPol - specifies how to permute values of the result field according to
8653  *          the optional numbers of cells and nodes, if any. The valid values are
8654  *          - 0 - do not permute.
8655  *          - 1 - permute cells.
8656  *          - 2 - permute nodes.
8657  *          - 3 - permute cells and nodes.
8658  *
8659  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8660  *          caller is to delete this field using decrRef() as it is no more needed. 
8661  *  \throw If the MED file is not readable.
8662  *  \throw If there is no mesh in the MED file.
8663  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8664  *  \throw If no field values of the required parameters are available.
8665  */
8666 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
8667 {
8668   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8669   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8670   if(!myF1TSC)
8671     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8672   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8673   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8674   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8675   return ret.retn();
8676 }
8677
8678 /*!
8679  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8680  * the top level cells of the first mesh in MED file.
8681  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8682  *  \param [in] type - a spatial discretization of interest.
8683  *  \param [in] iteration - the iteration number of a required time step.
8684  *  \param [in] order - the iteration order number of required time step.
8685  *  \param [in] renumPol - specifies how to permute values of the result field according to
8686  *          the optional numbers of cells and nodes, if any. The valid values are
8687  *          - 0 - do not permute.
8688  *          - 1 - permute cells.
8689  *          - 2 - permute nodes.
8690  *          - 3 - permute cells and nodes.
8691  *
8692  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8693  *          caller is to delete this field using decrRef() as it is no more needed. 
8694  *  \throw If the MED file is not readable.
8695  *  \throw If there is no mesh in the MED file.
8696  *  \throw If no field values of the required parameters are available.
8697  */
8698 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
8699 {
8700   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8701   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8702   if(!myF1TSC)
8703     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8704   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8705   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8706   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8707   return ret.retn();
8708 }
8709
8710 /*!
8711  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8712  * a given support.
8713  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8714  *  \param [in] type - a spatial discretization of interest.
8715  *  \param [in] iteration - the iteration number of a required time step.
8716  *  \param [in] order - the iteration order number of required time step.
8717  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8718  *  \param [in] mesh - the supporting mesh.
8719  *  \param [in] renumPol - specifies how to permute values of the result field according to
8720  *          the optional numbers of cells and nodes, if any. The valid values are
8721  *          - 0 - do not permute.
8722  *          - 1 - permute cells.
8723  *          - 2 - permute nodes.
8724  *          - 3 - permute cells and nodes.
8725  *
8726  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8727  *          caller is to delete this field using decrRef() as it is no more needed. 
8728  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8729  *  \throw If no field of \a this is lying on \a mesh.
8730  *  \throw If no field values of the required parameters are available.
8731  */
8732 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
8733 {
8734   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8735   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8736   if(!myF1TSC)
8737     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8738   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8739   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8740   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8741   return ret.retn();
8742 }
8743
8744 /*!
8745  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8746  * given support. 
8747  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8748  *  \param [in] type - a spatial discretization of the new field.
8749  *  \param [in] iteration - the iteration number of a required time step.
8750  *  \param [in] order - the iteration order number of required time step.
8751  *  \param [in] mesh - the supporting mesh.
8752  *  \param [in] renumPol - specifies how to permute values of the result field according to
8753  *          the optional numbers of cells and nodes, if any. The valid values are
8754  *          - 0 - do not permute.
8755  *          - 1 - permute cells.
8756  *          - 2 - permute nodes.
8757  *          - 3 - permute cells and nodes.
8758  *
8759  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8760  *          caller is to delete this field using decrRef() as it is no more needed. 
8761  *  \throw If no field of \a this is lying on \a mesh.
8762  *  \throw If no field values of the required parameters are available.
8763  */
8764 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
8765 {
8766   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8767   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8768   if(!myF1TSC)
8769     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8770   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8771   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8772   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8773   return ret.retn();
8774 }
8775
8776 /*!
8777  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8778  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8779  * This method is useful for MED2 file format when field on different mesh was autorized.
8780  */
8781 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
8782 {
8783   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8784   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8785   if(!myF1TSC)
8786     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8787   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8788   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8789   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8790   return ret.retn();
8791 }
8792
8793 /*!
8794  * Returns values and a profile of the field of a given type, of a given time step,
8795  * lying on a given support.
8796  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8797  *  \param [in] type - a spatial discretization of the field.
8798  *  \param [in] iteration - the iteration number of a required time step.
8799  *  \param [in] order - the iteration order number of required time step.
8800  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8801  *  \param [in] mesh - the supporting mesh.
8802  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8803  *          field of interest lies on. If the field lies on all entities of the given
8804  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8805  *          using decrRef() as it is no more needed.  
8806  *  \param [in] glob - the global data storing profiles and localization.
8807  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8808  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8809  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8810  *  \throw If no field of \a this is lying on \a mesh.
8811  *  \throw If no field values of the required parameters are available.
8812  */
8813 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
8814 {
8815   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8816   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8817   if(!myF1TSC)
8818     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8819   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8820   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8821 }
8822
8823 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
8824 {
8825   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8826   if(!pt)
8827     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8828   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8829   if(!ret)
8830     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 !");
8831   return ret;
8832 }
8833
8834 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
8835 {
8836   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8837   if(!pt)
8838     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8839   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8840   if(!ret)
8841     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 !");
8842   return ret;
8843 }
8844
8845 /*!
8846  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8847  * the given field is checked if its elements are sorted suitable for writing to MED file
8848  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8849  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8850  *  \param [in] field - the field to add to \a this.
8851  *  \throw If the name of \a field is empty.
8852  *  \throw If the data array of \a field is not set.
8853  *  \throw If existing time steps have different name or number of components than \a field.
8854  *  \throw If the underlying mesh of \a field has no name.
8855  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8856  */
8857 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
8858 {
8859   const DataArrayDouble *arr=0;
8860   if(field)
8861     arr=field->getArray();
8862   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8863 }
8864
8865 /*!
8866  * Adds a MEDCouplingFieldDouble to \a this as another time step.
8867  * The mesh support of input parameter \a field is ignored here, it can be NULL.
8868  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
8869  * and \a profile.
8870  *
8871  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
8872  * A new profile is added only if no equal profile is missing.
8873  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8874  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
8875  *  \param [in] mesh - the supporting mesh of \a field.
8876  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
8877  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8878  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8879  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8880  *  \throw If the data array of \a field is not set.
8881  *  \throw If the data array of \a this is already allocated but has different number of
8882  *         components than \a field.
8883  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8884  *  \sa setFieldNoProfileSBT()
8885  */
8886 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
8887 {
8888   const DataArrayDouble *arr=0;
8889   if(field)
8890     arr=field->getArray();
8891   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8892 }
8893
8894 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8895 {
8896   _content=new MEDFileFieldMultiTSWithoutSDA;
8897 }
8898
8899 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll)
8900 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
8901 {
8902 }
8903 catch(INTERP_KERNEL::Exception& e)
8904 { throw e; }
8905
8906 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll)
8907 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
8908 {
8909 }
8910 catch(INTERP_KERNEL::Exception& e)
8911 { throw e; }
8912
8913 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8914 {
8915 }
8916
8917 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
8918 {
8919   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8920 }
8921
8922 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
8923 {
8924   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8925 }
8926
8927 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
8928 {
8929   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8930 }
8931
8932 //= MEDFileAnyTypeFieldMultiTSIterator
8933
8934 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8935 {
8936   if(fmts)
8937     {
8938       fmts->incrRef();
8939       _nb_iter=fmts->getNumberOfTS();
8940     }
8941 }
8942
8943 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
8944 {
8945 }
8946
8947 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
8948 {
8949   if(_iter_id<_nb_iter)
8950     {
8951       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
8952       if(fmts)
8953         return fmts->getTimeStepAtPos(_iter_id++);
8954       else
8955         return 0;
8956     }
8957   else
8958     return 0;
8959 }
8960
8961 //= MEDFileIntFieldMultiTS
8962
8963 /*!
8964  * Returns a new empty instance of MEDFileFieldMultiTS.
8965  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8966  *          is to delete this field using decrRef() as it is no more needed.
8967  */
8968 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
8969 {
8970   return new MEDFileIntFieldMultiTS;
8971 }
8972
8973 /*!
8974  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
8975  * that has been read from a specified MED file.
8976  *  \param [in] fileName - the name of the MED file to read.
8977  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8978  *          is to delete this field using decrRef() as it is no more needed.
8979  *  \throw If reading the file fails.
8980  */
8981 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
8982 {
8983   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll);
8984   ret->contentNotNull();//to check that content type matches with \a this type.
8985   return ret.retn();
8986 }
8987
8988 /*!
8989  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
8990  * that has been read from a specified MED file.
8991  *  \param [in] fileName - the name of the MED file to read.
8992  *  \param [in] fieldName - the name of the field to read.
8993  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8994  *          is to delete this field using decrRef() as it is no more needed.
8995  *  \throw If reading the file fails.
8996  *  \throw If there is no field named \a fieldName in the file.
8997  */
8998 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8999 {
9000   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll);
9001   ret->contentNotNull();//to check that content type matches with \a this type.
9002   return ret.retn();
9003 }
9004
9005 /*!
9006  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9007  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9008  *
9009  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9010  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9011  * \warning this is a shallow copy constructor
9012  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9013  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9014  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9015  *          is to delete this field using decrRef() as it is no more needed.
9016  */
9017 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9018 {
9019   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9020 }
9021
9022 /*!
9023  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9024  * following the given input policy.
9025  *
9026  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9027  *                            By default (true) the globals are deeply copied.
9028  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9029  */
9030 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9031 {
9032   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9033   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9034   if(content)
9035     {
9036       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9037       if(!contc)
9038         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9039       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9040       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9041     }
9042   else
9043     ret=MEDFileFieldMultiTS::New();
9044   if(isDeepCpyGlobs)
9045     ret->deepCpyGlobs(*this);
9046   else
9047     ret->shallowCpyGlobs(*this);
9048   return ret.retn();
9049 }
9050
9051 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9052 {
9053   return new MEDFileIntFieldMultiTS(*this);
9054 }
9055
9056 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9057 {
9058   if(!f1ts)
9059     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9060   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9061   if(!f1tsC)
9062     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9063 }
9064
9065 /*!
9066  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9067  * mesh entities of a given dimension of the first mesh in MED file.
9068  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9069  *  \param [in] type - a spatial discretization of interest.
9070  *  \param [in] iteration - the iteration number of a required time step.
9071  *  \param [in] order - the iteration order number of required time step.
9072  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9073  *  \param [out] arrOut - the DataArrayInt containing values of field.
9074  *  \param [in] renumPol - specifies how to permute values of the result field according to
9075  *          the optional numbers of cells and nodes, if any. The valid values are
9076  *          - 0 - do not permute.
9077  *          - 1 - permute cells.
9078  *          - 2 - permute nodes.
9079  *          - 3 - permute cells and nodes.
9080  *
9081  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9082  *          caller is to delete this field using decrRef() as it is no more needed. 
9083  *  \throw If the MED file is not readable.
9084  *  \throw If there is no mesh in the MED file.
9085  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9086  *  \throw If no field values of the required parameters are available.
9087  */
9088 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9089 {
9090   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9091   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9092   if(!myF1TSC)
9093     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9094   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9095   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9096   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9097   return ret.retn();
9098 }
9099
9100 /*!
9101  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9102  * the top level cells of the first mesh in MED file.
9103  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9104  *  \param [in] type - a spatial discretization of interest.
9105  *  \param [in] iteration - the iteration number of a required time step.
9106  *  \param [in] order - the iteration order number of required time step.
9107  *  \param [out] arrOut - the DataArrayInt containing values of field.
9108  *  \param [in] renumPol - specifies how to permute values of the result field according to
9109  *          the optional numbers of cells and nodes, if any. The valid values are
9110  *          - 0 - do not permute.
9111  *          - 1 - permute cells.
9112  *          - 2 - permute nodes.
9113  *          - 3 - permute cells and nodes.
9114  *
9115  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9116  *          caller is to delete this field using decrRef() as it is no more needed. 
9117  *  \throw If the MED file is not readable.
9118  *  \throw If there is no mesh in the MED file.
9119  *  \throw If no field values of the required parameters are available.
9120  */
9121 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9122 {
9123   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9124   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9125   if(!myF1TSC)
9126     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9127   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9128   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9129   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9130   return ret.retn();
9131 }
9132
9133 /*!
9134  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9135  * a given support.
9136  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9137  *  \param [in] type - a spatial discretization of interest.
9138  *  \param [in] iteration - the iteration number of a required time step.
9139  *  \param [in] order - the iteration order number of required time step.
9140  *  \param [out] arrOut - the DataArrayInt containing values of field.
9141  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9142  *  \param [in] mesh - the supporting mesh.
9143  *  \param [in] renumPol - specifies how to permute values of the result field according to
9144  *          the optional numbers of cells and nodes, if any. The valid values are
9145  *          - 0 - do not permute.
9146  *          - 1 - permute cells.
9147  *          - 2 - permute nodes.
9148  *          - 3 - permute cells and nodes.
9149  *
9150  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9151  *          caller is to delete this field using decrRef() as it is no more needed. 
9152  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9153  *  \throw If no field of \a this is lying on \a mesh.
9154  *  \throw If no field values of the required parameters are available.
9155  */
9156 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9157 {
9158   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9159   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9160   if(!myF1TSC)
9161     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9162   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9163   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9164   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9165   return ret.retn();
9166 }
9167
9168 /*!
9169  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9170  * given support. 
9171  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9172  *  \param [in] type - a spatial discretization of the new field.
9173  *  \param [in] iteration - the iteration number of a required time step.
9174  *  \param [in] order - the iteration order number of required time step.
9175  *  \param [in] mesh - the supporting mesh.
9176  *  \param [out] arrOut - the DataArrayInt containing values of field.
9177  *  \param [in] renumPol - specifies how to permute values of the result field according to
9178  *          the optional numbers of cells and nodes, if any. The valid values are
9179  *          - 0 - do not permute.
9180  *          - 1 - permute cells.
9181  *          - 2 - permute nodes.
9182  *          - 3 - permute cells and nodes.
9183  *
9184  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9185  *          caller is to delete this field using decrRef() as it is no more needed. 
9186  *  \throw If no field of \a this is lying on \a mesh.
9187  *  \throw If no field values of the required parameters are available.
9188  */
9189 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9190 {
9191   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9192   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9193   if(!myF1TSC)
9194     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9195   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9196   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9197   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9198   return ret.retn();
9199 }
9200
9201 /*!
9202  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9203  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9204  * This method is useful for MED2 file format when field on different mesh was autorized.
9205  */
9206 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9207 {
9208   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9209   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9210   if(!myF1TSC)
9211     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9212   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9213   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9214   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9215   return ret.retn();
9216 }
9217
9218 /*!
9219  * Returns values and a profile of the field of a given type, of a given time step,
9220  * lying on a given support.
9221  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9222  *  \param [in] type - a spatial discretization of the field.
9223  *  \param [in] iteration - the iteration number of a required time step.
9224  *  \param [in] order - the iteration order number of required time step.
9225  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9226  *  \param [in] mesh - the supporting mesh.
9227  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9228  *          field of interest lies on. If the field lies on all entities of the given
9229  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9230  *          using decrRef() as it is no more needed.  
9231  *  \param [in] glob - the global data storing profiles and localization.
9232  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9233  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9234  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9235  *  \throw If no field of \a this is lying on \a mesh.
9236  *  \throw If no field values of the required parameters are available.
9237  */
9238 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9239 {
9240   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9241   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9242   if(!myF1TSC)
9243     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9244   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9245   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9246 }
9247
9248 /*!
9249  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9250  *  \param [in] pos - a time step id.
9251  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9252  *          delete this field using decrRef() as it is no more needed.
9253  *  \throw If \a pos is not a valid time step id.
9254  */
9255 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9256 {
9257   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9258   if(!item)
9259     {
9260       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9261       throw INTERP_KERNEL::Exception(oss.str().c_str());
9262     }
9263   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9264   if(itemC)
9265     {
9266       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9267       ret->shallowCpyGlobs(*this);
9268       return ret.retn();
9269     }
9270   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9271   throw INTERP_KERNEL::Exception(oss.str().c_str());
9272 }
9273
9274 /*!
9275  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9276  * the given field is checked if its elements are sorted suitable for writing to MED file
9277  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9278  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9279  *  \param [in] field - the field to add to \a this.
9280  *  \throw If the name of \a field is empty.
9281  *  \throw If the data array of \a field is not set.
9282  *  \throw If existing time steps have different name or number of components than \a field.
9283  *  \throw If the underlying mesh of \a field has no name.
9284  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9285  */
9286 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9287 {
9288   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9289 }
9290
9291 /*!
9292  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9293  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9294  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9295  * and \a profile.
9296  *
9297  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9298  * A new profile is added only if no equal profile is missing.
9299  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9300  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9301  *  \param [in] arrOfVals - the values of the field \a field used.
9302  *  \param [in] mesh - the supporting mesh of \a field.
9303  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9304  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9305  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9306  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9307  *  \throw If the data array of \a field is not set.
9308  *  \throw If the data array of \a this is already allocated but has different number of
9309  *         components than \a field.
9310  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9311  *  \sa setFieldNoProfileSBT()
9312  */
9313 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9314 {
9315   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9316 }
9317
9318 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9319 {
9320   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9321   if(!pt)
9322     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9323   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9324   if(!ret)
9325     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 !");
9326   return ret;
9327 }
9328
9329 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9330 {
9331   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9332   if(!pt)
9333     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9334   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9335   if(!ret)
9336     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 !");
9337   return ret;
9338 }
9339
9340 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9341 {
9342   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9343 }
9344
9345 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9346 {
9347 }
9348
9349 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll)
9350 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
9351 {
9352 }
9353 catch(INTERP_KERNEL::Exception& e)
9354 { throw e; }
9355
9356 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll)
9357 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
9358 {
9359 }
9360 catch(INTERP_KERNEL::Exception& e)
9361 { throw e; }
9362
9363 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9364 {
9365   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9366 }
9367
9368 //= MEDFileFields
9369
9370 MEDFileFields *MEDFileFields::New()
9371 {
9372   return new MEDFileFields;
9373 }
9374
9375 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9376 {
9377   return new MEDFileFields(fileName,loadAll);
9378 }
9379
9380 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9381 {
9382   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9383   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9384   return ret;
9385 }
9386
9387 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9388 {
9389   std::vector<const BigMemoryObject *> ret;
9390   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9391     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9392   return ret;
9393 }
9394
9395 MEDFileFields *MEDFileFields::deepCpy() const
9396 {
9397   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9398   std::size_t i=0;
9399   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9400     {
9401       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9402         ret->_fields[i]=(*it)->deepCpy();
9403     }
9404   ret->deepCpyGlobs(*this);
9405   return ret.retn();
9406 }
9407
9408 MEDFileFields *MEDFileFields::shallowCpy() const
9409 {
9410   return new MEDFileFields(*this);
9411 }
9412
9413 /*!
9414  * 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
9415  * 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.
9416  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9417  *
9418  * \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.
9419  * \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.
9420  * 
9421  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9422  */
9423 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9424 {
9425   std::set< std::pair<int,int> > s;
9426   bool firstShot=true;
9427   areThereSomeForgottenTS=false;
9428   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9429     {
9430       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9431         continue;
9432       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9433       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9434       if(firstShot)
9435         { s=s1; firstShot=false; }
9436       else
9437         {
9438           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9439           if(s!=s2)
9440             areThereSomeForgottenTS=true;
9441           s=s2;
9442         }
9443     }
9444   std::vector< std::pair<int,int> > ret;
9445   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9446   return ret;
9447 }
9448
9449 int MEDFileFields::getNumberOfFields() const
9450 {
9451   return _fields.size();
9452 }
9453
9454 std::vector<std::string> MEDFileFields::getFieldsNames() const
9455 {
9456   std::vector<std::string> ret(_fields.size());
9457   int i=0;
9458   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9459     {
9460       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9461       if(f)
9462         {
9463           ret[i]=f->getName();
9464         }
9465       else
9466         {
9467           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9468           throw INTERP_KERNEL::Exception(oss.str().c_str());
9469         }
9470     }
9471   return ret;
9472 }
9473
9474 std::vector<std::string> MEDFileFields::getMeshesNames() const
9475 {
9476   std::vector<std::string> ret;
9477   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9478     {
9479       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9480       if(cur)
9481         ret.push_back(cur->getMeshName());
9482     }
9483   return ret;
9484 }
9485
9486 std::string MEDFileFields::simpleRepr() const
9487 {
9488   std::ostringstream oss;
9489   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9490   simpleRepr(0,oss);
9491   return oss.str();
9492 }
9493
9494 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9495 {
9496   int nbOfFields=getNumberOfFields();
9497   std::string startLine(bkOffset,' ');
9498   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9499   int i=0;
9500   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9501     {
9502       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9503       if(cur)
9504         {
9505           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9506         }
9507       else
9508         {
9509           oss << startLine << "  - not defined !" << std::endl;
9510         }
9511     }
9512   i=0;
9513   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9514     {
9515       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9516       std::string chapter(17,'0'+i);
9517       oss << startLine << chapter << std::endl;
9518       if(cur)
9519         {
9520           cur->simpleRepr(bkOffset+2,oss,i);
9521         }
9522       else
9523         {
9524           oss << startLine << "  - not defined !" << std::endl;
9525         }
9526       oss << startLine << chapter << std::endl;
9527     }
9528   simpleReprGlobs(oss);
9529 }
9530
9531 MEDFileFields::MEDFileFields()
9532 {
9533 }
9534
9535 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll)
9536 try:MEDFileFieldGlobsReal(fileName)
9537 {
9538   MEDFileUtilities::CheckFileForRead(fileName);
9539   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
9540   int nbFields=MEDnField(fid);
9541   _fields.resize(nbFields);
9542   med_field_type typcha;
9543   for(int i=0;i<nbFields;i++)
9544     {
9545       std::vector<std::string> infos;
9546       std::string fieldName,dtunit;
9547       int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit);
9548       switch(typcha)
9549       {
9550         case MED_FLOAT64:
9551           {
9552             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9553             break;
9554           }
9555         case MED_INT32:
9556           {
9557             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9558             break;
9559           }
9560         default:
9561           {
9562             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] !";
9563             throw INTERP_KERNEL::Exception(oss.str().c_str());
9564           }
9565       }
9566     }
9567   loadAllGlobals(fid);
9568 }
9569 catch(INTERP_KERNEL::Exception& e)
9570 {
9571     throw e;
9572 }
9573
9574 void MEDFileFields::writeLL(med_idt fid) const
9575 {
9576   int i=0;
9577   writeGlobals(fid,*this);
9578   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9579     {
9580       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9581       if(!elt)
9582         {
9583           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9584           throw INTERP_KERNEL::Exception(oss.str().c_str());
9585         }
9586       elt->writeLL(fid,*this);
9587     }
9588 }
9589
9590 void MEDFileFields::write(const std::string& fileName, int mode) const
9591 {
9592   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9593   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
9594   writeLL(fid);
9595 }
9596
9597 /*!
9598  * This method alloc the arrays and load potentially huge arrays contained in this field.
9599  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9600  * This method can be also called to refresh or reinit values from a file.
9601  * 
9602  * \throw If the fileName is not set or points to a non readable MED file.
9603  */
9604 void MEDFileFields::loadArrays()
9605 {
9606   if(getFileName().empty())
9607     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9608   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9609   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9610     {
9611       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9612       if(elt)
9613         elt->loadBigArraysRecursively(fid,*elt);
9614     }
9615 }
9616
9617 /*!
9618  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9619  * But once data loaded once, this method does nothing.
9620  * 
9621  * \throw If the fileName is not set or points to a non readable MED file.
9622  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9623  */
9624 void MEDFileFields::loadArraysIfNecessary()
9625 {
9626   if(!getFileName().empty())
9627     {
9628       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9629       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9630         {
9631           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9632           if(elt)
9633             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9634         }
9635     }
9636 }
9637
9638 /*!
9639  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9640  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9641  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9642  * 
9643  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9644  */
9645 void MEDFileFields::unloadArrays()
9646 {
9647   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9648     {
9649       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9650       if(elt)
9651         elt->unloadArrays();
9652     }
9653 }
9654
9655 /*!
9656  * 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.
9657  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9658  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9659  * 
9660  * \sa MEDFileFields::loadArraysIfNecessary
9661  */
9662 void MEDFileFields::unloadArraysWithoutDataLoss()
9663 {
9664   if(!getFileName().empty())
9665     unloadArrays();
9666 }
9667
9668 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9669 {
9670   std::vector<std::string> ret;
9671   std::set<std::string> ret2;
9672   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9673     {
9674       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9675       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9676         if(ret2.find(*it2)==ret2.end())
9677           {
9678             ret.push_back(*it2);
9679             ret2.insert(*it2);
9680           }
9681     }
9682   return ret;
9683 }
9684
9685 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9686 {
9687   std::vector<std::string> ret;
9688   std::set<std::string> ret2;
9689   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9690     {
9691       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9692       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9693         if(ret2.find(*it2)==ret2.end())
9694           {
9695             ret.push_back(*it2);
9696             ret2.insert(*it2);
9697           }
9698     }
9699   return ret;
9700 }
9701
9702 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9703 {
9704   std::vector<std::string> ret;
9705   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9706     {
9707       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
9708       ret.insert(ret.end(),tmp.begin(),tmp.end());
9709     }
9710   return ret;
9711 }
9712
9713 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9714 {
9715   std::vector<std::string> ret;
9716   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9717     {
9718       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9719       ret.insert(ret.end(),tmp.begin(),tmp.end());
9720     }
9721   return ret;
9722 }
9723
9724 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9725 {
9726   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9727     (*it)->changePflsRefsNamesGen2(mapOfModif);
9728 }
9729
9730 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9731 {
9732   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9733     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9734 }
9735
9736 void MEDFileFields::resize(int newSize)
9737 {
9738   _fields.resize(newSize);
9739 }
9740
9741 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
9742 {
9743   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9744     pushField(*it);
9745 }
9746
9747 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
9748 {
9749   if(!field)
9750     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9751   _fields.push_back(field->getContent());
9752   appendGlobs(*field,1e-12);
9753 }
9754
9755 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
9756 {
9757   if(!field)
9758     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9759   if(i>=(int)_fields.size())
9760     _fields.resize(i+1);
9761   _fields[i]=field->getContent();
9762   appendGlobs(*field,1e-12);
9763 }
9764
9765 void MEDFileFields::destroyFieldAtPos(int i)
9766 {
9767   destroyFieldsAtPos(&i,&i+1);
9768 }
9769
9770 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
9771 {
9772   std::vector<bool> b(_fields.size(),true);
9773   for(const int *i=startIds;i!=endIds;i++)
9774     {
9775       if(*i<0 || *i>=(int)_fields.size())
9776         {
9777           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9778           throw INTERP_KERNEL::Exception(oss.str().c_str());
9779         }
9780       b[*i]=false;
9781     }
9782   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9783   std::size_t j=0;
9784   for(std::size_t i=0;i<_fields.size();i++)
9785     if(b[i])
9786       fields[j++]=_fields[i];
9787   _fields=fields;
9788 }
9789
9790 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
9791 {
9792   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9793   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9794   std::vector<bool> b(_fields.size(),true);
9795   int k=bg;
9796   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9797     {
9798       if(k<0 || k>=(int)_fields.size())
9799         {
9800           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9801           throw INTERP_KERNEL::Exception(oss.str().c_str());
9802         }
9803       b[k]=false;
9804     }
9805   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9806   std::size_t j=0;
9807   for(std::size_t i=0;i<_fields.size();i++)
9808     if(b[i])
9809       fields[j++]=_fields[i];
9810   _fields=fields;
9811 }
9812
9813 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9814 {
9815   bool ret=false;
9816   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9817     {
9818       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9819       if(cur)
9820         ret=cur->changeMeshNames(modifTab) || ret;
9821     }
9822   return ret;
9823 }
9824
9825 /*!
9826  * \param [in] meshName the name of the mesh that will be renumbered.
9827  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9828  *             This code corresponds to the distribution of types in the corresponding mesh.
9829  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9830  * \param [in] renumO2N the old to new renumber array.
9831  * \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 
9832  *         field in \a this.
9833  */
9834 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
9835 {
9836   bool ret=false;
9837   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9838     {
9839       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9840       if(fmts)
9841         {
9842           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9843         }
9844     }
9845   return ret;
9846 }
9847
9848 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
9849 {
9850   if(i<0 || i>=(int)_fields.size())
9851     {
9852       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9853       throw INTERP_KERNEL::Exception(oss.str().c_str());
9854     }
9855   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9856   if(!fmts)
9857     return 0;
9858   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9859   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9860   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9861   if(fmtsC)
9862     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9863   else if(fmtsC2)
9864     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9865   else
9866     {
9867       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9868       throw INTERP_KERNEL::Exception(oss.str().c_str());
9869     }
9870   ret->shallowCpyGlobs(*this);
9871   return ret.retn();
9872 }
9873
9874 /*!
9875  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9876  * This method is accessible in python using __getitem__ with a list in input.
9877  * \return a new object that the caller should deal with.
9878  */
9879 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
9880 {
9881   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9882   std::size_t sz=std::distance(startIds,endIds);
9883   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9884   int j=0;
9885   for(const int *i=startIds;i!=endIds;i++,j++)
9886     {
9887       if(*i<0 || *i>=(int)_fields.size())
9888         {
9889           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9890           throw INTERP_KERNEL::Exception(oss.str().c_str());
9891         }
9892       fields[j]=_fields[*i];
9893     }
9894   ret->_fields=fields;
9895   return ret.retn();
9896 }
9897
9898 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
9899 {
9900   return getFieldAtPos(getPosFromFieldName(fieldName));
9901 }
9902
9903 /*!
9904  * This method removes, if any, fields in \a this having no time steps.
9905  * 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.
9906  * 
9907  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
9908  */
9909 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
9910 {
9911   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
9912   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9913     {
9914       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9915       if(elt)
9916         {
9917           if(elt->getNumberOfTS()>0)
9918             newFields.push_back(*it);
9919         }
9920     }
9921   if(_fields.size()==newFields.size())
9922     return false;
9923   _fields=newFields;
9924   return true;
9925 }
9926
9927 /*!
9928  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9929  * This method can be seen as a filter applied on \a this, that returns an object containing
9930  * 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
9931  * shallow copied from \a this.
9932  * 
9933  * \param [in] meshName - the name of the mesh on w
9934  * \return a new object that the caller should deal with.
9935  */
9936 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
9937 {
9938   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9939   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9940     {
9941       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9942       if(!cur)
9943         continue;
9944       if(cur->getMeshName()==meshName)
9945         {
9946           cur->incrRef();
9947           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9948           ret->_fields.push_back(cur2);
9949         }
9950     }
9951   ret->shallowCpyOnlyUsedGlobs(*this);
9952   return ret.retn();
9953 }
9954
9955 /*!
9956  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9957  * Input time steps are specified using a pair of integer (iteration, order).
9958  * 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,
9959  * but for each multitimestep only the time steps in \a timeSteps are kept.
9960  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9961  * 
9962  * The returned object points to shallow copy of elements in \a this.
9963  * 
9964  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9965  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9966  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9967  */
9968 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
9969 {
9970   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9971   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9972     {
9973       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9974       if(!cur)
9975         continue;
9976       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
9977       ret->_fields.push_back(elt);
9978     }
9979   ret->shallowCpyOnlyUsedGlobs(*this);
9980   return ret.retn();
9981 }
9982
9983 /*!
9984  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
9985  */
9986 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
9987 {
9988   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9989   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9990     {
9991       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9992       if(!cur)
9993         continue;
9994       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
9995       if(elt->getNumberOfTS()!=0)
9996         ret->_fields.push_back(elt);
9997     }
9998   ret->shallowCpyOnlyUsedGlobs(*this);
9999   return ret.retn();
10000 }
10001
10002 MEDFileFieldsIterator *MEDFileFields::iterator()
10003 {
10004   return new MEDFileFieldsIterator(this);
10005 }
10006
10007 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10008 {
10009   std::string tmp(fieldName);
10010   std::vector<std::string> poss;
10011   for(std::size_t i=0;i<_fields.size();i++)
10012     {
10013       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10014       if(f)
10015         {
10016           std::string fname(f->getName());
10017           if(tmp==fname)
10018             return i;
10019           else
10020             poss.push_back(fname);
10021         }
10022     }
10023   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10024   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10025   oss << " !";
10026   throw INTERP_KERNEL::Exception(oss.str().c_str());
10027 }
10028
10029 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10030 {
10031   if(fs)
10032     {
10033       fs->incrRef();
10034       _nb_iter=fs->getNumberOfFields();
10035     }
10036 }
10037
10038 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10039 {
10040 }
10041
10042 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10043 {
10044   if(_iter_id<_nb_iter)
10045     {
10046       MEDFileFields *fs(_fs);
10047       if(fs)
10048         return fs->getFieldAtPos(_iter_id++);
10049       else
10050         return 0;
10051     }
10052   else
10053     return 0;
10054 }