Salome HOME
Pickelization of MEDFileUMesh objects.
[modules/med.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25 #include "MEDFileFieldOverView.hxx"
26
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "MEDCouplingFieldDiscretization.hxx"
29
30 #include "InterpKernelAutoPtr.hxx"
31 #include "CellModel.hxx"
32
33 #include <algorithm>
34 #include <iterator>
35
36 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
37 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
38 extern med_geometry_type typmainoeud[1];
39 extern med_geometry_type typmai3[34];
40
41 using namespace ParaMEDMEM;
42
43 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
44 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
45
46 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
47 {
48   return new MEDFileFieldLoc(fid,locName);
49 }
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
52 {
53   return new MEDFileFieldLoc(fid,id);
54 }
55
56 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
57 {
58   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
59 }
60
61 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
62 {
63   med_geometry_type geotype;
64   med_geometry_type sectiongeotype;
65   int nsectionmeshcell;
66   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
67   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
69   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
70   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
71   _nb_node_per_cell=cm.getNumberOfNodes();
72   _ref_coo.resize(_dim*_nb_node_per_cell);
73   _gs_coo.resize(_dim*_nb_gauss_pt);
74   _w.resize(_nb_gauss_pt);
75   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
76 }
77
78 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
79 {
80   med_geometry_type geotype;
81   med_geometry_type sectiongeotype;
82   int nsectionmeshcell;
83   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
84   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
87   _name=locName;
88   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
89   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
90   _nb_node_per_cell=cm.getNumberOfNodes();
91   _ref_coo.resize(_dim*_nb_node_per_cell);
92   _gs_coo.resize(_dim*_nb_gauss_pt);
93   _w.resize(_nb_gauss_pt);
94   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
95 }
96
97 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
98                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
99                                      _w(w)
100 {
101   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
102   _dim=cm.getDimension();
103   _nb_node_per_cell=cm.getNumberOfNodes();
104   _nb_gauss_pt=_w.size();
105 }
106
107 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
108 {
109   return new MEDFileFieldLoc(*this);
110 }
111
112 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
113 {
114   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
115 }
116
117 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
118 {
119   return std::vector<const BigMemoryObject *>();
120 }
121
122 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
123 {
124   static const char OFF7[]="\n    ";
125   oss << "\"" << _name << "\"" << OFF7;
126   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
127   oss << "Dimension=" << _dim << OFF7;
128   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
129   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
130   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
131   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
132   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
133 }
134
135 void MEDFileFieldLoc::setName(const std::string& name)
136 {
137   _name=name;
138 }
139
140 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
141 {
142   if(_name!=other._name)
143     return false;
144   if(_dim!=other._dim)
145     return false;
146   if(_nb_gauss_pt!=other._nb_gauss_pt)
147     return false;
148   if(_nb_node_per_cell!=other._nb_node_per_cell)
149     return false;
150   if(_geo_type!=other._geo_type)
151     return false;
152   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
153     return false;
154   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
155     return false;
156   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
157     return false;
158
159   return true;
160 }
161
162 void MEDFileFieldLoc::writeLL(med_idt fid) const
163 {
164   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
165 }
166
167 std::string MEDFileFieldLoc::repr() const
168 {
169   std::ostringstream oss; oss.precision(15);
170   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
171   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
172   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
173   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
174   oss << "\n  - Ref coords are : ";
175   int sz=_ref_coo.size();
176   if(sz%_dim==0)
177     {
178       int nbOfTuples=sz/_dim;
179       for(int i=0;i<nbOfTuples;i++)
180         {
181           oss << "(";
182           for(int j=0;j<_dim;j++)
183             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
184           oss << ") ";
185         }
186     }
187   else
188     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
189   oss << "\n  - Gauss coords in reference element : ";
190   sz=_gs_coo.size();
191   if(sz%_dim==0)
192     {
193       int nbOfTuples=sz/_dim;
194       for(int i=0;i<nbOfTuples;i++)
195         {
196           oss << "(";
197           for(int j=0;j<_dim;j++)
198             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
199           oss << ") ";
200         }
201     }
202   else
203     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
204   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
205   return oss.str();
206 }
207
208 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
209 {
210   _type=field->getTypeOfField();
211   _start=start;
212   switch(_type)
213   {
214     case ON_CELLS:
215       {
216         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,offset,offset+nbOfCells,1);
217         _end=_start+nbOfCells;
218         _nval=nbOfCells;
219         break;
220       }
221     case ON_GAUSS_NE:
222       {
223         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
224         const int *arrPtr=arr->getConstPointer();
225         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
226         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
227         _nval=nbOfCells;
228         break;
229       }
230     case ON_GAUSS_PT:
231       {
232         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
233         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
234         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
235         if(!disc2)
236           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
237         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
238         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
239         const int *dai2Ptr=dai2->getConstPointer();
240         int nbi=gsLoc.getWeights().size();
241         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
242         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
243         const int *da3Ptr=da3->getConstPointer();
244         if(da3->getNumberOfTuples()!=nbOfCells)
245           {//profile : for gauss even in NoProfile !!!
246             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
247             _profile=oss.str();
248             da3->setName(_profile.c_str());
249             glob.appendProfile(da3);
250           }
251         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
252         _nval=da3->getNbOfElems();
253         da4->alloc(_nval*nbi,1);
254         int *da4Ptr=da4->getPointer();
255         for(int i=0;i<_nval;i++)
256           {
257             int ref=dai2Ptr[offset+da3Ptr[i]];
258             for(int j=0;j<nbi;j++)
259               *da4Ptr++=ref+j;
260           }
261         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
262         _localization=oss2.str();
263         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
264         _end=_start+_nval*nbi;
265         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
266         break;
267       }
268     default:
269       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
270   }
271   start=_end;
272 }
273
274 /*!
275  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
276  * \param [in] pflName input containing name of profile if any. 0 if no profile (except for GAUSS_PT where a no profile can hide a profile when splitted by loc_id).
277  * \param [in] multiTypePfl is the end user profile specified in high level API
278  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
279  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
280  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
281  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
282  */
283 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
284 {
285   _profile.clear();
286   _type=field->getTypeOfField();
287   std::string pflName(multiTypePfl->getName());
288   std::ostringstream oss; oss << pflName;
289   if(_type!=ON_NODES)
290     {
291       if(!isPflAlone)
292         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
293     }
294   else
295     { oss << "_NODE"; }
296   if(locIds)
297     {
298       if(pflName.empty())
299         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
300       if(_type!=ON_GAUSS_PT)
301         {
302           locIds->setName(oss.str().c_str());
303           glob.appendProfile(locIds);
304           _profile=oss.str();
305         }
306     }
307   _start=start;
308   switch(_type)
309   {
310     case ON_NODES:
311       {
312         _nval=idsInPfl->getNumberOfTuples();
313         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
314         _end=_start+_nval;
315         break;
316       }
317     case ON_CELLS:
318       {
319         _nval=idsInPfl->getNumberOfTuples();
320         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
321         _end=_start+_nval;
322         break;
323       }
324     case ON_GAUSS_NE:
325       {
326         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
327         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
328         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
329         arr3->computeOffsets2();
330         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
331         int trueNval=tmp->getNumberOfTuples();
332         _nval=idsInPfl->getNumberOfTuples();
333         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
334         _end=_start+trueNval;
335         break;
336       }
337     case ON_GAUSS_PT:
338       {
339         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
340         if(!disc2)
341           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
342         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
343         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
344         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
345         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
346         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
347         //
348         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
349         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
350         //
351         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
352         int trueNval=0;
353         for(const int *pt=da4->begin();pt!=da4->end();pt++)
354           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
355         tmp->alloc(trueNval,1);
356         int *tmpPtr=tmp->getPointer();
357         for(const int *pt=da4->begin();pt!=da4->end();pt++)
358           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
359             *tmpPtr++=j;
360         //
361         _nval=da4->getNumberOfTuples();
362         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
363         _end=_start+trueNval;
364         oss << "_loc_" << _loc_id;
365         if(locIds)
366           {
367             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
368             da5->setName(oss.str().c_str());
369             glob.appendProfile(da5);
370             _profile=oss.str();
371           }
372         else
373           {
374             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
375               {
376                 da3->setName(oss.str().c_str());
377                 glob.appendProfile(da3);
378                 _profile=oss.str();
379               }
380           }
381         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
382         _localization=oss2.str();
383         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
384         break;
385       }
386     default:
387       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
388   }
389   start=_end;
390 }
391
392 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
393 {
394   _start=start;
395   _nval=arrr->getNumberOfTuples();
396   getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,_nval,1);
397   _end=_start+_nval;
398   start=_end;
399 }
400
401 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
402 {
403   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
404 }
405
406 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
407 {
408   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
409 }
410
411 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
412 {
413   return new MEDFileFieldPerMeshPerTypePerDisc(other);
414 }
415
416 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
417 {
418   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
419 }
420
421 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
422 {
423   std::vector<const BigMemoryObject *> ret(1);
424   ret[0]=(const PartDefinition*)_pd;
425   return ret;
426 }
427
428 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const
429 {
430   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
431   ret->_father=father;
432   return ret.retn();
433 }
434
435 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
436 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
437 {
438   if(pd)
439     pd->incrRef();
440 }
441 catch(INTERP_KERNEL::Exception& e)
442 {
443     throw e;
444 }
445
446 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
447 {
448 }
449
450 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_profile_it(other._profile_it),_pd(other._pd),_tmp_work1(other._tmp_work1)
451 {
452 }
453
454 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
455     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
456 {
457 }
458
459 void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const std::string& fieldName, int nbOfCompo, int iteration, int order, med_entity_type menti, med_geometry_type mgeoti, unsigned char *startFeedingPtr)
460 {
461   const PartDefinition *pd(_pd);
462   if(!pd)
463     {
464       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
465       int nbi,tmp1;
466       med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
467       if(_end-_start!=nbValsInFile*nbi)
468         {
469           std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
470           throw INTERP_KERNEL::Exception(oss.str().c_str());
471         }
472       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr);
473     }
474   else
475     {
476       if(!_profile.empty())
477         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
478       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
479       int profilesize,nbi;
480       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
481       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
482       if(spd)
483         {
484           int start,stop,step;
485           spd->getSlice(start,stop,step);
486           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
487           med_filter filter=MED_FILTER_INIT;
488           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
489                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
490                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
491                                    /*lastblocksize=useless because count=1*/0,&filter);
492           MEDfieldValueAdvancedRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr);
493           MEDfilterClose(&filter);
494           return ;
495         }
496       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
497       if(dpd)
498         {
499           dpd->checkCoherency();
500           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> myIds(dpd->toDAI());
501           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
502           myIds->applyLin(1,-a);
503           int nbOfEltsToLoad(b-a+1);
504           med_filter filter=MED_FILTER_INIT;
505           {//TODO : manage int32 !
506             MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(DataArrayDouble::New());
507             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
508             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
509                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
510                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
511                                      /*lastblocksize=useless because count=1*/0,&filter);
512             MEDfieldValueAdvancedRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer()));
513             MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> feeder(DataArrayDouble::New());
514             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
515             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
516           }
517           MEDfilterClose(&filter);
518         }
519       else
520         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
521     }
522 }
523
524 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
525 {
526   return _father;
527 }
528
529 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
530 {
531   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
532   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
533   std::string fieldName(nasc.getName()),meshName(getMeshName());
534   int iteration(getIteration()),order(getOrder());
535   TypeOfField type(getType());
536   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
537   int profilesize,nbi;
538   med_geometry_type mgeoti;
539   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
540   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
541   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
542   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
543   const PartDefinition *pd(_pd);
544   if(!pd)
545     {
546       _nval=zeNVal;
547     }
548   else
549     {
550       if(!_profile.empty())
551         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
552       _nval=pd->getNumberOfElems();
553     }
554   _start=start;
555   _end=start+_nval*nbi;
556   start=_end;
557   if(type==ON_CELLS && !_localization.empty())
558     {
559       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
560         setType(ON_GAUSS_PT);
561       else
562         {
563           setType(ON_GAUSS_NE);
564           _localization.clear();
565         }
566     }
567 }
568
569 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
570 {
571   std::string fieldName(nasc.getName()),meshName(getMeshName());
572   int iteration(getIteration()),order(getOrder());
573   TypeOfField type(getType());
574   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
575   med_geometry_type mgeoti;
576   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
577   if(_start>_end)
578     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
579   if(_start==_end)
580     return ;
581   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
582   if(_start<0 || _start>=arr->getNumberOfTuples())
583     {
584       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
585       throw INTERP_KERNEL::Exception(oss.str().c_str());
586     }
587   if(_end<0 || _end>arr->getNumberOfTuples())
588     {
589       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
590       throw INTERP_KERNEL::Exception(oss.str().c_str());
591     }
592   int nbOfCompo(arr->getNumberOfComponents());
593   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
594   if(arrD)
595     {
596       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
597       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
598       return ;
599     }
600   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
601   if(arrI)
602     {
603       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
604       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
605       return ;
606     }
607   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
608 }
609
610 /*!
611  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
612  */
613 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
614 {
615   int delta=_end-_start;
616   _start=newValueOfStart;
617   _end=_start+delta;
618 }
619
620 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
621 {
622   return _father->getIteration();
623 }
624
625 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
626 {
627   return _father->getOrder();
628 }
629
630 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
631 {
632   return _father->getTime();
633 }
634
635 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
636 {
637   return _father->getMeshName();
638 }
639
640 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
641 {
642   const char startLine[]="    ## ";
643   std::string startLine2(bkOffset,' ');
644   startLine2+=startLine;
645   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
646   oss << startLine2 << "Localization #" << id << "." << std::endl;
647   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
648   delete tmp;
649   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
650   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
651   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
652 }
653
654 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
655 {
656   return _type;
657 }
658
659 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
660 {
661   types.insert(_type);
662 }
663
664 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
665 {
666   _type=newType;
667 }
668
669 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
670 {
671   return _father->getGeoType();
672 }
673
674 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
675 {
676   return _father->getNumberOfComponents();
677 }
678
679 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
680 {
681   return _end-_start;
682 }
683
684 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
685 {
686   return _father->getOrCreateAndGetArray();
687 }
688
689 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
690 {
691   const MEDFileFieldPerMeshPerType *fath=_father;
692   return fath->getOrCreateAndGetArray();
693 }
694
695 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
696 {
697   return _father->getInfo();
698 }
699
700 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
701 {
702   return _profile;
703 }
704
705 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
706 {
707   _profile=newPflName;
708 }
709
710 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
711 {
712   return _localization;
713 }
714
715 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
716 {
717   _localization=newLocName;
718 }
719
720 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
721 {
722   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
723     {
724       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
725         {
726           _profile=(*it2).second;
727           return;
728         }
729     }
730 }
731
732 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
733 {
734   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
735     {
736       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
737         {
738           _localization=(*it2).second;
739           return;
740         }
741     }
742 }
743
744 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
745 {
746   if(type!=_type)
747     return ;
748   dads.push_back(std::pair<int,int>(_start,_end));
749   geoTypes.push_back(getGeoType());
750   if(_profile.empty())
751     pfls.push_back(0);
752   else
753     {
754       pfls.push_back(glob->getProfile(_profile.c_str()));
755     }
756   if(_localization.empty())
757     locs.push_back(-1);
758   else
759     {
760       locs.push_back(glob->getLocalizationId(_localization.c_str()));
761     }
762 }
763
764 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
765 {
766   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));
767   startEntryId++;
768 }
769
770 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
771 {
772   TypeOfField type=getType();
773   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
774   med_geometry_type mgeoti;
775   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
776   const DataArray *arr=getOrCreateAndGetArray();
777   if(!arr)
778     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
779   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
780   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
781   const unsigned char *locToWrite=0;
782   if(arrD)
783     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
784   else if(arrI)
785     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
786   else
787     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
788   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
789                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
790                              locToWrite);
791 }
792
793 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
794 {
795   type=_type;
796   pfl=_profile;
797   loc=_localization;
798   dad.first=_start; dad.second=_end;
799 }
800
801 /*!
802  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
803  *             This code corresponds to the distribution of types in the corresponding mesh.
804  * \param [out] ptToFill memory zone where the output will be stored.
805  * \return the size of data pushed into output param \a ptToFill
806  */
807 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
808 {
809   _loc_id=offset;
810   std::ostringstream oss;
811   std::size_t nbOfType=codeOfMesh.size()/3;
812   int found=-1;
813   for(std::size_t i=0;i<nbOfType && found==-1;i++)
814     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
815       found=(int)i;
816   if(found==-1)
817     {
818       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
819       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
820       throw INTERP_KERNEL::Exception(oss.str().c_str());
821     }
822   int *work=ptToFill;
823   if(_profile.empty())
824     {
825       if(_nval!=codeOfMesh[3*found+1])
826         {
827           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
828           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
829           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
830           throw INTERP_KERNEL::Exception(oss.str().c_str());
831         }
832       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
833         *work++=ii;
834     }
835   else
836     {
837       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
838       if(pfl->getNumberOfTuples()!=_nval)
839         {
840           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
841           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
842           oss << _nval;
843           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
844           throw INTERP_KERNEL::Exception(oss.str().c_str());
845         }
846       int offset2=codeOfMesh[3*found+2];
847       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
848         {
849           if(*pflId<codeOfMesh[3*found+1])
850             *work++=offset2+*pflId;
851         }
852     }
853   return _nval;
854 }
855
856 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
857 {
858   for(int i=_start;i<_end;i++)
859     *ptToFill++=i;
860   return _end-_start;
861 }
862
863 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
864 {
865   switch(type)
866   {
867     case ON_CELLS:
868       return -2;
869     case ON_GAUSS_NE:
870       return -1;
871     case ON_GAUSS_PT:
872       return locId;
873     default:
874       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
875   }
876 }
877
878 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
879 {
880   int id=0;
881   std::map<std::pair<std::string,TypeOfField>,int> m;
882   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
883   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
884     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
885       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
886   ret.resize(id);
887   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
888     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
889   return ret;
890 }
891
892 /*!
893  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
894  * 
895  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
896  * \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.
897  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
898  * \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)
899  * \param [in,out] glob if necessary by the method, new profiles can be added to it
900  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
901  * \param [out] result All new entries will be appended on it.
902  * \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 !)
903  */
904 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
905                                                        const DataArrayInt *explicitIdsInMesh,
906                                                        const std::vector<int>& newCode,
907                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
908                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
909 {
910   if(entriesOnSameDisc.empty())
911     return false;
912   TypeOfField type=entriesOnSameDisc[0]->getType();
913   int szEntities=0,szTuples=0;
914   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
915     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
916   int nbi=szTuples/szEntities;
917   if(szTuples%szEntities!=0)
918     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
919   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
920   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
921   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
922   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
923   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
924   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
925   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
926   int id=0;
927   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
928     {
929       int startOfEltIdOfChunk=(*it)->_start;
930       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
931       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
932       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
933       //
934       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
935       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
936       //
937       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
938       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
939     }
940   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
941   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
942   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
943   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
944   //
945   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
946   //
947   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
948   arrPart->renumberInPlace(renumTupleIds->begin());
949   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
950   bool ret=false;
951   const int *idIt=diffVals->begin();
952   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
953   int offset2=0;
954   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
955     {
956       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
957       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
958       int nbEntityElts=subIds->getNumberOfTuples();
959       bool ret2;
960       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
961           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
962                                       offset+offset2,
963                                       li,glob,ret2);
964       ret=ret || ret2;
965       result.push_back(eltToAdd);
966       offset2+=nbEntityElts*nbi;
967     }
968   ret=ret || li.empty();
969   return ret;
970 }
971
972 /*!
973  * \param [in] typeF type of field of new chunk
974  * \param [in] geoType the geometric type of the chunk
975  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
976  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
977  * \param [in] nbi number of integration points
978  * \param [in] offset The offset in the **global array of data**.
979  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
980  *                 to the new chunk to create.
981  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
982  * \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
983  *              and corresponding entry erased from \a entriesOnSameDisc.
984  * \return a newly allocated chunk
985  */
986 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
987                                                                                                   bool isPfl, int nbi, int offset,
988                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
989                                                                                                   MEDFileFieldGlobsReal& glob,
990                                                                                                   bool &notInExisting)
991 {
992   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
993   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
994   for(;it!=entriesOnSameDisc.end();it++)
995     {
996       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
997         {
998           if(!isPfl)
999             {
1000               if((*it)->_profile.empty())
1001                 break;
1002               else
1003                 if(!(*it)->_profile.empty())
1004                   {
1005                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1006                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1007                       break;
1008                   }
1009             }
1010         }
1011     }
1012   if(it==entriesOnSameDisc.end())
1013     {
1014       notInExisting=true;
1015       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1016       ret->_type=typeF;
1017       ret->_loc_id=(int)geoType;
1018       ret->_nval=nbMeshEntities;
1019       ret->_start=offset;
1020       ret->_end=ret->_start+ret->_nval*nbi;
1021       if(isPfl)
1022         {
1023           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1024           glob.appendProfile(idsOfMeshElt);
1025           ret->_profile=idsOfMeshElt->getName();
1026         }
1027       //tony treatment of localization
1028       return ret;
1029     }
1030   else
1031     {
1032       notInExisting=false;
1033       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1034       ret->_loc_id=(int)geoType;
1035       ret->setNewStart(offset);
1036       entriesOnSameDisc.erase(it);
1037       return ret;
1038     }
1039
1040 }
1041
1042 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1043 {
1044   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1045 }
1046
1047 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1048 {
1049   return new MEDFileFieldPerMeshPerType(fath,geoType);
1050 }
1051
1052 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1053 {
1054   return _field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
1055 }
1056
1057 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1058 {
1059   std::vector<const BigMemoryObject *> ret;
1060   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1061     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1062   return ret;
1063 }
1064
1065 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const
1066 {
1067   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1068   ret->_father=father;
1069   std::size_t i=0;
1070   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1071     {
1072       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1073         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
1074     }
1075   return ret.retn();
1076 }
1077
1078 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1079 {
1080   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1081   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1082     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1083 }
1084
1085 /*!
1086  * This method is the most general one. No optimization is done here.
1087  * \param [in] multiTypePfl is the end user profile specified in high level API
1088  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1089  * \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.
1090  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1091  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1092  * \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.
1093  */
1094 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)
1095 {
1096   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1097   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1098     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1099 }
1100
1101 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1102 {
1103   _field_pm_pt_pd.resize(1);
1104   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1105   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1106 }
1107
1108 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1109 {
1110   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1111   if(!arr || !arr->isAllocated())
1112     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1113   _field_pm_pt_pd.resize(1);
1114   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1115   _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.
1116 }
1117
1118 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1119 {
1120   TypeOfField type=field->getTypeOfField();
1121   if(type!=ON_GAUSS_PT)
1122     {
1123       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1124       int sz=_field_pm_pt_pd.size();
1125       bool found=false;
1126       for(int j=0;j<sz && !found;j++)
1127         {
1128           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1129             {
1130               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1131               found=true;
1132             }
1133         }
1134       if(!found)
1135         {
1136           _field_pm_pt_pd.resize(sz+1);
1137           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1138         }
1139       std::vector<int> ret(1,(int)sz);
1140       return ret;
1141     }
1142   else
1143     {
1144       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1145       int sz2=ret2.size();
1146       std::vector<int> ret3(sz2);
1147       int k=0;
1148       for(int i=0;i<sz2;i++)
1149         {
1150           int sz=_field_pm_pt_pd.size();
1151           int locIdToFind=ret2[i];
1152           bool found=false;
1153           for(int j=0;j<sz && !found;j++)
1154             {
1155               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1156                 {
1157                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1158                   ret3[k++]=j;
1159                   found=true;
1160                 }
1161             }
1162           if(!found)
1163             {
1164               _field_pm_pt_pd.resize(sz+1);
1165               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1166               ret3[k++]=sz;
1167             }
1168         }
1169       return ret3;
1170     }
1171 }
1172
1173 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1174 {
1175   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1176   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1177   if(!disc2)
1178     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1179   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1180   if(!da)
1181     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1182   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1183   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1184   if(retTmp->presenceOfValue(-1))
1185     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1186   std::vector<int> ret(retTmp->begin(),retTmp->end());
1187   return ret;
1188 }
1189
1190 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1191 {
1192   TypeOfField type=field->getTypeOfField();
1193   if(type!=ON_GAUSS_PT)
1194     {
1195       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1196       int sz=_field_pm_pt_pd.size();
1197       bool found=false;
1198       for(int j=0;j<sz && !found;j++)
1199         {
1200           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1201             {
1202               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1203               found=true;
1204             }
1205         }
1206       if(!found)
1207         {
1208           _field_pm_pt_pd.resize(sz+1);
1209           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1210         }
1211       std::vector<int> ret(1,0);
1212       return ret;
1213     }
1214   else
1215     {
1216       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1217       int sz2=ret2.size();
1218       std::vector<int> ret3(sz2);
1219       int k=0;
1220       for(int i=0;i<sz2;i++)
1221         {
1222           int sz=_field_pm_pt_pd.size();
1223           int locIdToFind=ret2[i];
1224           bool found=false;
1225           for(int j=0;j<sz && !found;j++)
1226             {
1227               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1228                 {
1229                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1230                   ret3[k++]=j;
1231                   found=true;
1232                 }
1233             }
1234           if(!found)
1235             {
1236               _field_pm_pt_pd.resize(sz+1);
1237               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1238               ret3[k++]=sz;
1239             }
1240         }
1241       return ret3;
1242     }
1243 }
1244
1245 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1246 {
1247   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1248   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1249   if(!disc2)
1250     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1251   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1252   if(!da)
1253     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1254   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1255   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1256   if(retTmp->presenceOfValue(-1))
1257     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1258   std::vector<int> ret(retTmp->begin(),retTmp->end());
1259   return ret;
1260 }
1261
1262 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1263 {
1264   return _father;
1265 }
1266
1267 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1268 {
1269   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1270   int curDim=(int)cm.getDimension();
1271   dim=std::max(dim,curDim);
1272 }
1273
1274 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) 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       (*it)->fillTypesOfFieldAvailable(types);
1279     }
1280 }
1281
1282 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
1283 {
1284   int sz=_field_pm_pt_pd.size();
1285   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1286   for(int i=0;i<sz;i++)
1287     {
1288       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1289     }
1290 }
1291
1292 int MEDFileFieldPerMeshPerType::getIteration() const
1293 {
1294   return _father->getIteration();
1295 }
1296
1297 int MEDFileFieldPerMeshPerType::getOrder() const
1298 {
1299   return _father->getOrder();
1300 }
1301
1302 double MEDFileFieldPerMeshPerType::getTime() const
1303 {
1304   return _father->getTime();
1305 }
1306
1307 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1308 {
1309   return _father->getMeshName();
1310 }
1311
1312 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1313 {
1314   const char startLine[]="  ## ";
1315   std::string startLine2(bkOffset,' ');
1316   std::string startLine3(startLine2);
1317   startLine3+=startLine;
1318   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1319     {
1320       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1321       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1322     }
1323   else
1324     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1325   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1326   int i=0;
1327   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1328     {
1329       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1330       if(cur)
1331         cur->simpleRepr(bkOffset,oss,i);
1332       else
1333         {
1334           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1335         }
1336     }
1337 }
1338
1339 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1340 {
1341   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1342     {
1343       globalSz+=(*it)->getNumberOfTuples();
1344     }
1345   nbOfEntries+=(int)_field_pm_pt_pd.size();
1346 }
1347
1348 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1349 {
1350   return _geo_type;
1351 }
1352
1353
1354 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1355 {
1356   return _father->getNumberOfComponents();
1357 }
1358
1359 bool MEDFileFieldPerMeshPerType::presenceOfMultiDiscPerGeoType() const
1360 {
1361   std::size_t nb(0);
1362   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1363     {
1364       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1365       if(fmtd)
1366         nb++;
1367     }
1368   return nb>1;
1369 }
1370
1371 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1372 {
1373   return _father->getOrCreateAndGetArray();
1374 }
1375
1376 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1377 {
1378   const MEDFileFieldPerMesh *fath=_father;
1379   return fath->getOrCreateAndGetArray();
1380 }
1381
1382 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1383 {
1384   return _father->getInfo();
1385 }
1386
1387 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1388 {
1389   std::vector<std::string> ret;
1390   std::set<std::string> ret2;
1391   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1392     {
1393       std::string tmp=(*it1)->getProfile();
1394       if(!tmp.empty())
1395         if(ret2.find(tmp)==ret2.end())
1396           {
1397             ret.push_back(tmp);
1398             ret2.insert(tmp);
1399           }
1400     }
1401   return ret;
1402 }
1403
1404 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1405 {
1406   std::vector<std::string> ret;
1407   std::set<std::string> ret2;
1408   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1409     {
1410       std::string tmp=(*it1)->getLocalization();
1411       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1412         if(ret2.find(tmp)==ret2.end())
1413           {
1414             ret.push_back(tmp);
1415             ret2.insert(tmp);
1416           }
1417     }
1418   return ret;
1419 }
1420
1421 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1422 {
1423   std::vector<std::string> ret;
1424   std::set<std::string> ret2;
1425   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1426     {
1427       std::string tmp=(*it1)->getProfile();
1428       if(!tmp.empty())
1429         ret.push_back(tmp);
1430     }
1431   return ret;
1432 }
1433
1434 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1435 {
1436   std::vector<std::string> ret;
1437   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1438     {
1439       std::string tmp=(*it1)->getLocalization();
1440       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1441         ret.push_back(tmp);
1442     }
1443   return ret;
1444 }
1445
1446 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1447 {
1448   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1449     (*it1)->changePflsRefsNamesGen(mapOfModif);
1450 }
1451
1452 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1453 {
1454   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1455     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1456 }
1457
1458 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1459 {
1460   if(_field_pm_pt_pd.empty())
1461     {
1462       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1463       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1464       throw INTERP_KERNEL::Exception(oss.str().c_str());
1465     }
1466   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1467     return _field_pm_pt_pd[locId];
1468   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1469   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1470   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1471   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1472   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1473 }
1474
1475 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1476 {
1477   if(_field_pm_pt_pd.empty())
1478     {
1479       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1480       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1481       throw INTERP_KERNEL::Exception(oss.str().c_str());
1482     }
1483   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1484     return _field_pm_pt_pd[locId];
1485   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1486   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1487   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1488   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1489   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1490 }
1491
1492 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
1493 {
1494   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1495     {
1496       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1497       if(meshDim!=(int)cm.getDimension())
1498         return ;
1499     }
1500   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1501     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1502 }
1503
1504 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1505 {
1506   int i=0;
1507   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1508     {
1509       (*it)->fillValues(i,startEntryId,entries);
1510     }
1511 }
1512
1513 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1514 {
1515   _field_pm_pt_pd=leaves;
1516   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1517     (*it)->setFather(this);
1518 }
1519
1520 /*!
1521  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1522  *  \param [out] its - list of pair (start,stop) kept
1523  *  \return bool - false if the type of field \a tof is not contained in \a this.
1524  */
1525 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1526 {
1527   bool ret(false);
1528   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1529   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1530     if((*it)->getType()==tof)
1531       {
1532         newPmPtPd.push_back(*it);
1533         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1534         (*it)->setNewStart(globalNum);
1535         globalNum=(*it)->getEnd();
1536         its.push_back(bgEnd);
1537         ret=true;
1538       }
1539   if(ret)
1540     _field_pm_pt_pd=newPmPtPd;
1541   return ret;
1542 }
1543
1544 /*!
1545  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1546  *  \param [out] its - list of pair (start,stop) kept
1547  *  \return bool - false if the type of field \a tof is not contained in \a this.
1548  */
1549 bool MEDFileFieldPerMeshPerType::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1550 {
1551   if(_field_pm_pt_pd.size()<=idOfDisc)
1552     return false;
1553   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1554   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1555   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1556   elt->setNewStart(globalNum);
1557   globalNum=elt->getEnd();
1558   its.push_back(bgEnd);
1559   _field_pm_pt_pd=newPmPtPd;
1560   return true;
1561 }
1562
1563 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1564 {
1565 }
1566
1567 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1568 {
1569   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1570   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1571   med_geometry_type mgeoti;
1572   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1573   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1574   _field_pm_pt_pd.resize(nbProfiles);
1575   for(int i=0;i<nbProfiles;i++)
1576     {
1577       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1578     }
1579   if(type==ON_CELLS)
1580     {
1581       int nbProfiles2=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName);
1582       for(int i=0;i<nbProfiles2;i++)
1583         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1584     }
1585 }
1586
1587 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1588 {
1589   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1590     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1591 }
1592
1593 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1594 {
1595   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1596     (*it)->loadBigArray(fid,nasc);
1597 }
1598
1599 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1600 {
1601   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1602     {
1603       (*it)->copyOptionsFrom(*this);
1604       (*it)->writeLL(fid,nasc);
1605     }
1606 }
1607
1608 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1609 {
1610   switch(ikType)
1611   {
1612     case ON_CELLS:
1613       medfGeoType=typmai3[(int)ikGeoType];
1614       return MED_CELL;
1615     case ON_NODES:
1616       medfGeoType=MED_NONE;
1617       return MED_NODE;
1618     case ON_GAUSS_NE:
1619       medfGeoType=typmai3[(int)ikGeoType];
1620       return MED_NODE_ELEMENT;
1621     case ON_GAUSS_PT:
1622       medfGeoType=typmai3[(int)ikGeoType];
1623       return MED_CELL;
1624     default:
1625       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1626   }
1627   return MED_UNDEF_ENTITY_TYPE;
1628 }
1629
1630 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm)
1631 {
1632   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm);
1633 }
1634
1635 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1636 {
1637   return new MEDFileFieldPerMesh(fath,mesh);
1638 }
1639
1640 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1641 {
1642   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1643 }
1644
1645 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1646 {
1647   std::vector<const BigMemoryObject *> ret;
1648   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1649     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1650   return ret;
1651 }
1652
1653 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1654 {
1655   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1656   ret->_father=father;
1657   std::size_t i=0;
1658   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1659     {
1660       if((const MEDFileFieldPerMeshPerType *)*it)
1661         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1662     }
1663   return ret.retn();
1664 }
1665
1666 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1667 {
1668   std::string startLine(bkOffset,' ');
1669   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1670   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1671   int i=0;
1672   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1673     {
1674       const MEDFileFieldPerMeshPerType *cur=*it;
1675       if(cur)
1676         cur->simpleRepr(bkOffset,oss,i);
1677       else
1678         {
1679           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1680         }
1681     }
1682 }
1683
1684 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1685 {
1686   _mesh_name=mesh->getName();
1687   mesh->getTime(_mesh_iteration,_mesh_order);
1688 }
1689
1690 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1691 {
1692   int nbOfTypes=code.size()/3;
1693   int offset=0;
1694   for(int i=0;i<nbOfTypes;i++)
1695     {
1696       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1697       int nbOfCells=code[3*i+1];
1698       int pos=addNewEntryIfNecessary(type);
1699       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1700       offset+=nbOfCells;
1701     }
1702 }
1703
1704 /*!
1705  * This method is the most general one. No optimization is done here.
1706  * \param [in] multiTypePfl is the end user profile specified in high level API
1707  * \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].
1708  * \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.
1709  * \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.
1710  * \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.
1711  * \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.
1712  */
1713 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)
1714 {
1715   int nbOfTypes(code.size()/3);
1716   for(int i=0;i<nbOfTypes;i++)
1717     {
1718       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1719       int pos=addNewEntryIfNecessary(type);
1720       DataArrayInt *pfl=0;
1721       if(code[3*i+2]!=-1)
1722         pfl=idsPerType[code[3*i+2]];
1723       int nbOfTupes2=code2.size()/3;
1724       int found=0;
1725       for(;found<nbOfTupes2;found++)
1726         if(code[3*i]==code2[3*found])
1727           break;
1728       if(found==nbOfTupes2)
1729         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1730       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1731     }
1732 }
1733
1734 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1735 {
1736   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1737   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1738 }
1739
1740 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1741 {
1742   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1743   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1744 }
1745
1746 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1747 {
1748   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1749     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1750 }
1751
1752 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1753 {
1754   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1755     (*it)->loadBigArraysRecursively(fid,nasc);
1756 }
1757
1758 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1759 {
1760   int nbOfTypes=_field_pm_pt.size();
1761   for(int i=0;i<nbOfTypes;i++)
1762     {
1763       _field_pm_pt[i]->copyOptionsFrom(*this);
1764       _field_pm_pt[i]->writeLL(fid,nasc);
1765     }
1766 }
1767
1768 void MEDFileFieldPerMesh::getDimension(int& dim) const
1769 {
1770   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1771     (*it)->getDimension(dim);
1772 }
1773
1774 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1775 {
1776   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1777     (*it)->fillTypesOfFieldAvailable(types);
1778 }
1779
1780 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
1781 {
1782   int sz=_field_pm_pt.size();
1783   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1784   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1785   for(int i=0;i<sz;i++)
1786     {
1787       types[i]=_field_pm_pt[i]->getGeoType();
1788       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1789     }
1790   return ret;
1791 }
1792
1793 double MEDFileFieldPerMesh::getTime() const
1794 {
1795   int tmp1,tmp2;
1796   return _father->getTime(tmp1,tmp2);
1797 }
1798
1799 int MEDFileFieldPerMesh::getIteration() const
1800 {
1801   return _father->getIteration();
1802 }
1803
1804 int MEDFileFieldPerMesh::getOrder() const
1805 {
1806   return _father->getOrder();
1807 }
1808
1809 int MEDFileFieldPerMesh::getNumberOfComponents() const
1810 {
1811   return _father->getNumberOfComponents();
1812 }
1813
1814 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1815 {
1816   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1817     {
1818       const MEDFileFieldPerMeshPerType *fpmt(*it);
1819       if(!fpmt)
1820         continue;
1821       if(fpmt->presenceOfMultiDiscPerGeoType())
1822         return true;
1823     }
1824   return false;
1825 }
1826
1827 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1828 {
1829   if(!_father)
1830     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1831   return _father->getOrCreateAndGetArray();
1832 }
1833
1834 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1835 {
1836   if(!_father)
1837     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1838   return _father->getOrCreateAndGetArray();
1839 }
1840
1841 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1842 {
1843   return _father->getInfo();
1844 }
1845
1846 /*!
1847  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1848  * 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.
1849  * It returns 2 output vectors :
1850  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1851  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1852  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1853  */
1854 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)
1855 {
1856   int notNullPflsSz=0;
1857   int nbOfArrs=geoTypes.size();
1858   for(int i=0;i<nbOfArrs;i++)
1859     if(pfls[i])
1860       notNullPflsSz++;
1861   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1862   int nbOfDiffGeoTypes=geoTypes3.size();
1863   code.resize(3*nbOfDiffGeoTypes);
1864   notNullPfls.resize(notNullPflsSz);
1865   notNullPflsSz=0;
1866   int j=0;
1867   for(int i=0;i<nbOfDiffGeoTypes;i++)
1868     {
1869       int startZone=j;
1870       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1871       std::vector<const DataArrayInt *> notNullTmp;
1872       if(pfls[j])
1873         notNullTmp.push_back(pfls[j]);
1874       j++;
1875       for(;j<nbOfArrs;j++)
1876         if(geoTypes[j]==refType)
1877           {
1878             if(pfls[j])
1879               notNullTmp.push_back(pfls[j]);
1880           }
1881         else
1882           break;
1883       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1884       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1885       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1886       code[3*i]=(int)refType;
1887       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1888       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1889       if(notNullTmp.empty())
1890         code[3*i+2]=-1;
1891       else
1892         {
1893           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1894           code[3*i+2]=notNullPflsSz++;
1895         }
1896     }
1897 }
1898
1899 /*!
1900  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1901  */
1902 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)
1903 {
1904   int sz=dads.size();
1905   int ret=0;
1906   for(int i=0;i<sz;i++)
1907     {
1908       if(locs[i]==-1)
1909         {
1910           if(type!=ON_GAUSS_NE)
1911             ret+=dads[i].second-dads[i].first;
1912           else
1913             {
1914               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1915               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1916             }
1917         }
1918       else
1919         {
1920           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1921           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1922         }
1923     }
1924   return ret;
1925 }
1926
1927 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1928 {
1929   std::vector<std::string> ret;
1930   std::set<std::string> ret2;
1931   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1932     {
1933       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1934       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1935         if(ret2.find(*it2)==ret2.end())
1936           {
1937             ret.push_back(*it2);
1938             ret2.insert(*it2);
1939           }
1940     }
1941   return ret;
1942 }
1943
1944 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1945 {
1946   std::vector<std::string> ret;
1947   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1948     {
1949       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1950       ret.insert(ret.end(),tmp.begin(),tmp.end());
1951     }
1952   return ret;
1953 }
1954
1955 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1956 {
1957   std::vector<std::string> ret;
1958   std::set<std::string> ret2;
1959   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1960     {
1961       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1962       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1963         if(ret2.find(*it2)==ret2.end())
1964           {
1965             ret.push_back(*it2);
1966             ret2.insert(*it2);
1967           }
1968     }
1969   return ret;
1970 }
1971
1972 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1973 {
1974   std::vector<std::string> ret;
1975   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1976     {
1977       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1978       ret.insert(ret.end(),tmp.begin(),tmp.end());
1979     }
1980   return ret;
1981 }
1982
1983 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1984 {
1985   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1986     {
1987       if((*it).first==_mesh_name)
1988         {
1989           _mesh_name=(*it).second;
1990           return true;
1991         }
1992     }
1993   return false;
1994 }
1995
1996 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1997                                                       MEDFileFieldGlobsReal& glob)
1998 {
1999   if(_mesh_name!=meshName)
2000     return false;
2001   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2002   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2003   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2004   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2005   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2006   getUndergroundDataArrayExt(entries);
2007   DataArray *arr0=getOrCreateAndGetArray();//tony
2008   if(!arr0)
2009     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2010   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
2011   if(!arr0)
2012     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2013   int sz=0;
2014   if(!arr)
2015     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2016   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2017     {
2018       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2019         {
2020           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2021           sz+=(*it).second.second-(*it).second.first;
2022         }
2023       else
2024         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2025     }
2026   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2027   ////////////////////
2028   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2029   int *workI2=explicitIdsOldInMesh->getPointer();
2030   int sz1=0,sz2=0,sid=1;
2031   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2032   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2033   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2034     {
2035       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2036       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2037       int *workI=explicitIdsOldInArr->getPointer();
2038       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2039         {
2040           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2041           (*itL2)->setLocId(sz2);
2042           (*itL2)->_tmp_work1=(*itL2)->getStart();
2043           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2044         }
2045       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2046     }
2047   explicitIdsOldInMesh->reAlloc(sz2);
2048   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2049   ////////////////////
2050   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2051   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2052   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2053   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2054     {
2055       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2056       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2057       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2058     }
2059   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2060   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2061   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2062     {
2063       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2064       int newStart=elt->getLocId();
2065       elt->setLocId((*it)->getGeoType());
2066       elt->setNewStart(newStart);
2067       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2068       entriesKeptNew.push_back(elt);
2069       entriesKeptNew2.push_back(elt);
2070     }
2071   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2072   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2073   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2074   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2075   bool ret=false;
2076   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2077     {
2078       sid=0;
2079       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2080         {
2081           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2082           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2083           }*/
2084       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2085                                                             glob,arr2,otherEntriesNew) || ret;
2086     }
2087   if(!ret)
2088     return false;
2089   // Assign new dispatching
2090   assignNewLeaves(otherEntriesNew);
2091   arr->cpyFrom(*arr2);
2092   return true;
2093 }
2094
2095 /*!
2096  * \param [in,out] globalNum a global numbering counter for the renumbering.
2097  * \param [out] its - list of pair (start,stop) kept
2098  */
2099 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2100 {
2101   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2102   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2103     {
2104       std::vector< std::pair<int,int> > its2;
2105       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2106         {
2107           ret.push_back(*it);
2108           its.insert(its.end(),its2.begin(),its2.end());
2109         }
2110     }
2111   _field_pm_pt=ret;
2112 }
2113
2114 /*!
2115  * \param [in,out] globalNum a global numbering counter for the renumbering.
2116  * \param [out] its - list of pair (start,stop) kept
2117  */
2118 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2119 {
2120   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2121   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2122     {
2123       std::vector< std::pair<int,int> > its2;
2124       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2125         {
2126           ret.push_back(*it);
2127           its.insert(its.end(),its2.begin(),its2.end());
2128         }
2129     }
2130   _field_pm_pt=ret;
2131 }
2132
2133 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2134 {
2135   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2136   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2137     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2138   //
2139   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2140   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2141   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2142   for(;it1!=types.end();it1++,it2++)
2143     {
2144       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2145       elt->setLeaves((*it1).second);
2146       *it2=elt;
2147     }
2148   _field_pm_pt=fieldPmPt;
2149 }
2150
2151 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2152 {
2153   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2154     (*it)->changePflsRefsNamesGen(mapOfModif);
2155 }
2156
2157 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2158 {
2159   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2160     (*it)->changeLocsRefsNamesGen(mapOfModif);
2161 }
2162
2163 /*!
2164  * \param [in] mesh is the whole mesh
2165  */
2166 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2167 {
2168   if(_field_pm_pt.empty())
2169     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2170   //
2171   std::vector< std::pair<int,int> > dads;
2172   std::vector<const DataArrayInt *> pfls;
2173   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2174   std::vector<int> locs,code;
2175   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2176   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2177     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2178   // Sort by types
2179   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2180   if(code.empty())
2181     {
2182       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2183       throw INTERP_KERNEL::Exception(oss.str().c_str());
2184     }
2185   //
2186   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2187   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2188   if(type!=ON_NODES)
2189     {
2190       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2191       if(!arr)
2192         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2193       else
2194         {
2195           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2196           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2197         }
2198     }
2199   else
2200     {
2201       if(code.size()!=3)
2202         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2203       int nb=code[1];
2204       if(code[2]==-1)
2205         {
2206           if(nb!=mesh->getNumberOfNodes())
2207             {
2208               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2209               oss << " nodes in mesh !";
2210               throw INTERP_KERNEL::Exception(oss.str().c_str());
2211             }
2212           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2213         }
2214       else
2215         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2216     }
2217 }
2218
2219 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2220 {
2221   if(_field_pm_pt.empty())
2222     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2223   //
2224   std::vector<std::pair<int,int> > dads;
2225   std::vector<const DataArrayInt *> pfls;
2226   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2227   std::vector<int> locs,code;
2228   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2229   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2230     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2231   // Sort by types
2232   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2233   if(code.empty())
2234     {
2235       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2236       throw INTERP_KERNEL::Exception(oss.str().c_str());
2237     }
2238   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2239   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2240   if(type!=ON_NODES)
2241     {
2242       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2243       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2244     }
2245   else
2246     {
2247       if(code.size()!=3)
2248         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2249       int nb=code[1];
2250       if(code[2]==-1)
2251         {
2252           if(nb!=mesh->getNumberOfNodes())
2253             {
2254               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2255               oss << " nodes in mesh !";
2256               throw INTERP_KERNEL::Exception(oss.str().c_str());
2257             }
2258         }
2259       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2260     }
2261   //
2262   return 0;
2263 }
2264
2265 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2266 {
2267   int globalSz=0;
2268   int nbOfEntries=0;
2269   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2270     {
2271       (*it)->getSizes(globalSz,nbOfEntries);
2272     }
2273   entries.resize(nbOfEntries);
2274   nbOfEntries=0;
2275   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2276     {
2277       (*it)->fillValues(nbOfEntries,entries);
2278     }
2279 }
2280
2281 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2282 {
2283   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2284     {
2285       if((*it)->getGeoType()==typ)
2286         return (*it)->getLeafGivenLocId(locId);
2287     }
2288   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2289   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2290   oss << "Possiblities are : ";
2291   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2292     {
2293       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2294       oss << "\"" << cm2.getRepr() << "\", ";
2295     }
2296   throw INTERP_KERNEL::Exception(oss.str().c_str());
2297 }
2298
2299 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2300 {
2301   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2302     {
2303       if((*it)->getGeoType()==typ)
2304         return (*it)->getLeafGivenLocId(locId);
2305     }
2306   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2307   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2308   oss << "Possiblities are : ";
2309   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2310     {
2311       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2312       oss << "\"" << cm2.getRepr() << "\", ";
2313     }
2314   throw INTERP_KERNEL::Exception(oss.str().c_str());
2315 }
2316
2317 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2318 {
2319   int i=0;
2320   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2321   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2322   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2323     {
2324       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2325       if(type==curType)
2326         return i;
2327       else
2328         {
2329           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2330           if(pos>pos2)
2331             it2=it+1;
2332         }
2333     }
2334   int ret=std::distance(_field_pm_pt.begin(),it2);
2335   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2336   return ret;
2337 }
2338
2339 /*!
2340  * 'dads' and 'locs' input parameters have the same number of elements
2341  * \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
2342  */
2343 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2344                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2345                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2346 {
2347   isPfl=false;
2348   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2349   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2350   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2351   const std::vector<std::string>& infos=getInfo();
2352   da->setInfoOnComponents(infos);
2353   da->setName("");
2354   if(type==ON_GAUSS_PT)
2355     {
2356       int offset=0;
2357       int nbOfArrs=dads.size();
2358       for(int i=0;i<nbOfArrs;i++)
2359         {
2360           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2361           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2362           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2363           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2364           di->alloc(nbOfElems,1);
2365           di->iota(offset);
2366           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2367           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2368           offset+=nbOfElems;
2369         }
2370     }
2371   arrOut=da;
2372   return ret.retn();
2373 }
2374
2375 /*!
2376  * 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.
2377  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2378  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2379  * The order of cells in the returned field is those imposed by the profile.
2380  * \param [in] mesh is the global mesh.
2381  */
2382 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2383                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2384                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2385                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2386 {
2387   if(da->isIdentity())
2388     {
2389       int nbOfTuples=da->getNumberOfTuples();
2390       if(nbOfTuples==mesh->getNumberOfCells())
2391         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2392     }
2393   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2394   m2->setName(mesh->getName().c_str());
2395   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2396   isPfl=true;
2397   return ret.retn();
2398 }
2399
2400 /*!
2401  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2402  */
2403 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2404                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2405                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2406 {
2407   if(da->isIdentity())
2408     {
2409       int nbOfTuples=da->getNumberOfTuples();
2410       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2411         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2412     }
2413   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2414   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2415   if(meshu)
2416     {
2417       if(meshu->getNodalConnectivity()==0)
2418         {
2419           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2420           int nb=da->getNbOfElems();
2421           const int *ptr=da->getConstPointer();
2422           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2423           meshuc->allocateCells(nb);
2424           for(int i=0;i<nb;i++)
2425             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2426           meshuc->finishInsertingCells();
2427           ret->setMesh(meshuc);
2428           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2429           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2430           disc->checkCoherencyBetween(meshuc,arrOut);
2431           return ret.retn();
2432         }
2433     }
2434   //
2435   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2436   isPfl=true;
2437   DataArrayInt *arr2=0;
2438   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2439   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2440   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2441   int nnodes=mesh2->getNumberOfNodes();
2442   if(nnodes==(int)da->getNbOfElems())
2443     {
2444       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2445       arrOut->renumberInPlace(da3->getConstPointer());
2446       mesh2->setName(mesh->getName().c_str());
2447       ret->setMesh(mesh2);
2448       return ret.retn();
2449     }
2450   else
2451     {
2452       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 !!!";
2453       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2454       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2455       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2456       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2457       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2458       throw INTERP_KERNEL::Exception(oss.str().c_str());
2459     }
2460   return 0;
2461 }
2462
2463 /*!
2464  * This method is the most light method of field retrieving.
2465  */
2466 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2467 {
2468   if(!pflIn)
2469     {
2470       pflOut=DataArrayInt::New();
2471       pflOut->alloc(nbOfElems,1);
2472       pflOut->iota(0);
2473     }
2474   else
2475     {
2476       pflOut=const_cast<DataArrayInt*>(pflIn);
2477       pflOut->incrRef();
2478     }
2479   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2480   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2481   const std::vector<std::string>& infos=getInfo();
2482   int nbOfComp=infos.size();
2483   for(int i=0;i<nbOfComp;i++)
2484     da->setInfoOnComponent(i,infos[i].c_str());
2485   safePfl->incrRef();
2486   return da.retn();
2487 }
2488
2489 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2490     _father(fath)
2491 {
2492   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2493   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2494   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2495   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2496   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2497     {
2498       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[i],meshCsit+1,meshName,pflName,locName));
2499       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2500       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],meshCsit+1,meshName,pflName,locName));
2501       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2502       if(nbProfile>0 || nbProfile2>0)
2503         {
2504           const PartDefinition *pd(0);
2505           if(mmu)
2506             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[i]),typmai2[i]);
2507           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc,pd));
2508           if(nbProfile>0)
2509             _mesh_name=name0;
2510           else
2511             _mesh_name=name1;
2512         }
2513     }
2514   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName);
2515   if(nbProfile>0)
2516     {
2517       const PartDefinition *pd(0);
2518       if(mmu)
2519         pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2520       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2521       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2522     }
2523 }
2524
2525 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2526 {
2527   copyTinyInfoFrom(mesh);
2528 }
2529
2530 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2531 {
2532   if(id>=(int)_pfls.size())
2533     _pfls.resize(id+1);
2534   _pfls[id]=DataArrayInt::New();
2535   int lgth=MEDprofileSizeByName(fid,pflName.c_str());
2536   _pfls[id]->setName(pflName);
2537   _pfls[id]->alloc(lgth,1);
2538   MEDprofileRd(fid,pflName.c_str(),_pfls[id]->getPointer());
2539   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2540 }
2541
2542 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2543 {
2544   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2545   int sz;
2546   MEDprofileInfo(fid,i+1,pflName,&sz);
2547   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2548   if(i>=(int)_pfls.size())
2549     _pfls.resize(i+1);
2550   _pfls[i]=DataArrayInt::New();
2551   _pfls[i]->alloc(sz,1);
2552   _pfls[i]->setName(pflCpp.c_str());
2553   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2554   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2555 }
2556
2557 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2558 {
2559   int nbOfPfls=_pfls.size();
2560   for(int i=0;i<nbOfPfls;i++)
2561     {
2562       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2563       cpy->applyLin(1,1,0);
2564       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2565       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2566       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2567     }
2568   //
2569   int nbOfLocs=_locs.size();
2570   for(int i=0;i<nbOfLocs;i++)
2571     _locs[i]->writeLL(fid);
2572 }
2573
2574 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2575 {
2576   std::vector<std::string> pfls=getPfls();
2577   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2578     {
2579       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2580       if(it2==pfls.end())
2581         {
2582           _pfls.push_back(*it);
2583         }
2584       else
2585         {
2586           int id=std::distance(pfls.begin(),it2);
2587           if(!(*it)->isEqual(*_pfls[id]))
2588             {
2589               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2590               throw INTERP_KERNEL::Exception(oss.str().c_str());
2591             }
2592         }
2593     }
2594   std::vector<std::string> locs=getLocs();
2595   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2596     {
2597       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2598       if(it2==locs.end())
2599         {
2600           _locs.push_back(*it);
2601         }
2602       else
2603         {
2604           int id=std::distance(locs.begin(),it2);
2605           if(!(*it)->isEqual(*_locs[id],eps))
2606             {
2607               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2608               throw INTERP_KERNEL::Exception(oss.str().c_str());
2609             }
2610         }
2611     }
2612 }
2613
2614 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2615 {
2616   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2617     getProfile((*it).c_str());
2618 }
2619
2620 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2621 {
2622   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2623     getLocalization((*it).c_str());
2624 }
2625
2626 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2627 {
2628   std::vector<std::string> profiles=real.getPflsReallyUsed();
2629   int sz=profiles.size();
2630   _pfls.resize(sz);
2631   for(int i=0;i<sz;i++)
2632     loadProfileInFile(fid,i,profiles[i].c_str());
2633   //
2634   std::vector<std::string> locs=real.getLocsReallyUsed();
2635   sz=locs.size();
2636   _locs.resize(sz);
2637   for(int i=0;i<sz;i++)
2638     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2639 }
2640
2641 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2642 {
2643   int nProfil=MEDnProfile(fid);
2644   for(int i=0;i<nProfil;i++)
2645     loadProfileInFile(fid,i);
2646   int sz=MEDnLocalization(fid);
2647   _locs.resize(sz);
2648   for(int i=0;i<sz;i++)
2649     {
2650       _locs[i]=MEDFileFieldLoc::New(fid,i);
2651     }
2652 }
2653
2654 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2655 {
2656   return new MEDFileFieldGlobs(fname);
2657 }
2658
2659 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2660 {
2661   return new MEDFileFieldGlobs;
2662 }
2663
2664 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2665 {
2666   return _file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2667 }
2668
2669 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2670 {
2671   std::vector<const BigMemoryObject *> ret;
2672   for(std::vector< MEDCouplingAutoRefCountObjectPtr< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2673     ret.push_back((const DataArrayInt *)*it);
2674   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2675     ret.push_back((const MEDFileFieldLoc *)*it);
2676   return ret;
2677 }
2678
2679 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const
2680 {
2681   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2682   std::size_t i=0;
2683   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2684     {
2685       if((const DataArrayInt *)*it)
2686         ret->_pfls[i]=(*it)->deepCpy();
2687     }
2688   i=0;
2689   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2690     {
2691       if((const MEDFileFieldLoc*)*it)
2692         ret->_locs[i]=(*it)->deepCpy();
2693     }
2694   return ret.retn();
2695 }
2696
2697 /*!
2698  * \throw if a profile in \a pfls in not in \a this.
2699  * \throw if a localization in \a locs in not in \a this.
2700  * \sa MEDFileFieldGlobs::deepCpyPart
2701  */
2702 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2703 {
2704   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2705   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2706     {
2707       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2708       if(!pfl)
2709         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2710       pfl->incrRef();
2711       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2712       ret->_pfls.push_back(pfl2);
2713     }
2714   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2715     {
2716       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2717       if(!loc)
2718         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2719       loc->incrRef();
2720       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2721       ret->_locs.push_back(loc2);
2722     }
2723   ret->setFileName(getFileName());
2724   return ret.retn();
2725 }
2726
2727 /*!
2728  * \throw if a profile in \a pfls in not in \a this.
2729  * \throw if a localization in \a locs in not in \a this.
2730  * \sa MEDFileFieldGlobs::shallowCpyPart
2731  */
2732 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2733 {
2734   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2735   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2736     {
2737       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2738       if(!pfl)
2739         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2740       ret->_pfls.push_back(pfl->deepCpy());
2741     }
2742   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2743     {
2744       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2745       if(!loc)
2746         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2747       ret->_locs.push_back(loc->deepCpy());
2748     }
2749   ret->setFileName(getFileName());
2750   return ret.retn();
2751 }
2752
2753 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2754 {
2755 }
2756
2757 MEDFileFieldGlobs::MEDFileFieldGlobs()
2758 {
2759 }
2760
2761 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2762 {
2763 }
2764
2765 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2766 {
2767   oss << "Profiles :\n";
2768   std::size_t n=_pfls.size();
2769   for(std::size_t i=0;i<n;i++)
2770     {
2771       oss << "  - #" << i << " ";
2772       const DataArrayInt *pfl=_pfls[i];
2773       if(pfl)
2774         oss << "\"" << pfl->getName() << "\"\n";
2775       else
2776         oss << "EMPTY !\n";
2777     }
2778   n=_locs.size();
2779   oss << "Localizations :\n";
2780   for(std::size_t i=0;i<n;i++)
2781     {
2782       oss << "  - #" << i << " ";
2783       const MEDFileFieldLoc *loc=_locs[i];
2784       if(loc)
2785         loc->simpleRepr(oss);
2786       else
2787         oss<< "EMPTY !\n";
2788     }
2789 }
2790
2791 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2792 {
2793   _file_name=fileName;
2794 }
2795
2796 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2797 {
2798   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2799     {
2800       DataArrayInt *elt(*it);
2801       if(elt)
2802         {
2803           std::string name(elt->getName());
2804           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2805             {
2806               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2807                 {
2808                   elt->setName((*it2).second.c_str());
2809                   return;
2810                 }
2811             }
2812         }
2813     }
2814 }
2815
2816 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2817 {
2818   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2819     {
2820       MEDFileFieldLoc *elt(*it);
2821       if(elt)
2822         {
2823           std::string name(elt->getName());
2824           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2825             {
2826               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2827                 {
2828                   elt->setName((*it2).second.c_str());
2829                   return;
2830                 }
2831             }
2832         }
2833     }
2834 }
2835
2836 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2837 {
2838   if(locId<0 || locId>=(int)_locs.size())
2839     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2840   return _locs[locId]->getNbOfGaussPtPerCell();
2841 }
2842
2843 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2844 {
2845   return getLocalizationFromId(getLocalizationId(locName));
2846 }
2847
2848 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2849 {
2850   if(locId<0 || locId>=(int)_locs.size())
2851     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2852   return *_locs[locId];
2853 }
2854
2855 namespace ParaMEDMEMImpl
2856 {
2857   class LocFinder
2858   {
2859   public:
2860     LocFinder(const std::string& loc):_loc(loc) { }
2861     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2862   private:
2863     const std::string &_loc;
2864   };
2865
2866   class PflFinder
2867   {
2868   public:
2869     PflFinder(const std::string& pfl):_pfl(pfl) { }
2870     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2871   private:
2872     const std::string& _pfl;
2873   };
2874 }
2875
2876 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2877 {
2878   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2879   if(it==_locs.end())
2880     {
2881       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2882       for(it=_locs.begin();it!=_locs.end();it++)
2883         oss << "\"" << (*it)->getName() << "\", ";
2884       throw INTERP_KERNEL::Exception(oss.str().c_str());
2885     }
2886   return std::distance(_locs.begin(),it);
2887 }
2888
2889 /*!
2890  * The returned value is never null.
2891  */
2892 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2893 {
2894   std::string pflNameCpp(pflName);
2895   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2896   if(it==_pfls.end())
2897     {
2898       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2899       for(it=_pfls.begin();it!=_pfls.end();it++)
2900         oss << "\"" << (*it)->getName() << "\", ";
2901       throw INTERP_KERNEL::Exception(oss.str().c_str());
2902     }
2903   return *it;
2904 }
2905
2906 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2907 {
2908   if(pflId<0 || pflId>=(int)_pfls.size())
2909     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2910   return _pfls[pflId];
2911 }
2912
2913 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
2914 {
2915   if(locId<0 || locId>=(int)_locs.size())
2916     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2917   return *_locs[locId];
2918 }
2919
2920 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
2921 {
2922   return getLocalizationFromId(getLocalizationId(locName));
2923 }
2924
2925 /*!
2926  * The returned value is never null.
2927  */
2928 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
2929 {
2930   std::string pflNameCpp(pflName);
2931   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2932   if(it==_pfls.end())
2933     {
2934       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2935       for(it=_pfls.begin();it!=_pfls.end();it++)
2936         oss << "\"" << (*it)->getName() << "\", ";
2937       throw INTERP_KERNEL::Exception(oss.str().c_str());
2938     }
2939   return *it;
2940 }
2941
2942 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
2943 {
2944   if(pflId<0 || pflId>=(int)_pfls.size())
2945     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2946   return _pfls[pflId];
2947 }
2948
2949 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
2950 {
2951   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2952   int i=0;
2953   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2954     {
2955       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2956         newPfls.push_back(*it);
2957     }
2958   _pfls=newPfls;
2959 }
2960
2961 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
2962 {
2963   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2964   int i=0;
2965   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2966     {
2967       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2968         newLocs.push_back(*it);
2969     }
2970   _locs=newLocs;
2971 }
2972
2973 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2974 {
2975   int sz=_pfls.size();
2976   std::vector<std::string> ret(sz);
2977   for(int i=0;i<sz;i++)
2978     ret[i]=_pfls[i]->getName();
2979   return ret;
2980 }
2981
2982 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2983 {
2984   int sz=_locs.size();
2985   std::vector<std::string> ret(sz);
2986   for(int i=0;i<sz;i++)
2987     ret[i]=_locs[i]->getName();
2988   return ret;
2989 }
2990
2991 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
2992 {
2993   std::vector<std::string> v=getPfls();
2994   std::string s(pflName);
2995   return std::find(v.begin(),v.end(),s)!=v.end();
2996 }
2997
2998 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
2999 {
3000   std::vector<std::string> v=getLocs();
3001   std::string s(locName);
3002   return std::find(v.begin(),v.end(),s)!=v.end();
3003 }
3004
3005 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3006 {
3007   std::map<int,std::vector<int> > m;
3008   int i=0;
3009   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3010     {
3011       const DataArrayInt *tmp=(*it);
3012       if(tmp)
3013         {
3014           m[tmp->getHashCode()].push_back(i);
3015         }
3016     }
3017   std::vector< std::vector<int> > ret;
3018   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3019     {
3020       if((*it2).second.size()>1)
3021         {
3022           std::vector<int> ret0;
3023           bool equalityOrNot=false;
3024           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3025             {
3026               std::vector<int>::const_iterator it4=it3; it4++;
3027               for(;it4!=(*it2).second.end();it4++)
3028                 {
3029                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3030                     {
3031                       if(!equalityOrNot)
3032                         ret0.push_back(*it3);
3033                       ret0.push_back(*it4);
3034                       equalityOrNot=true;
3035                     }
3036                 }
3037             }
3038           if(!ret0.empty())
3039             ret.push_back(ret0);
3040         }
3041     }
3042   return ret;
3043 }
3044
3045 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3046 {
3047   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3048 }
3049
3050 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3051 {
3052   std::string name(pfl->getName());
3053   if(name.empty())
3054     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3055   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3056     if(name==(*it)->getName())
3057       {
3058         if(!pfl->isEqual(*(*it)))
3059           {
3060             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3061             throw INTERP_KERNEL::Exception(oss.str().c_str());
3062           }
3063       }
3064   pfl->incrRef();
3065   _pfls.push_back(pfl);
3066 }
3067
3068 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)
3069 {
3070   std::string name(locName);
3071   if(name.empty())
3072     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3073   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3074   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3075     if((*it)->isName(locName))
3076       {
3077         if(!(*it)->isEqual(*obj,1e-12))
3078           {
3079             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3080             throw INTERP_KERNEL::Exception(oss.str().c_str());
3081           }
3082       }
3083   _locs.push_back(obj);
3084 }
3085
3086 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3087 {
3088   std::vector<std::string> names=getPfls();
3089   return CreateNewNameNotIn("NewPfl_",names);
3090 }
3091
3092 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3093 {
3094   std::vector<std::string> names=getLocs();
3095   return CreateNewNameNotIn("NewLoc_",names);
3096 }
3097
3098 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3099 {
3100   for(std::size_t sz=0;sz<100000;sz++)
3101     {
3102       std::ostringstream tryName;
3103       tryName << prefix << sz;
3104       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3105         return tryName.str();
3106     }
3107   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3108 }
3109
3110 /*!
3111  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3112  *  \param [in] fname - the file name.
3113  */
3114 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3115 {
3116 }
3117
3118 /*!
3119  * Creates an empty MEDFileFieldGlobsReal.
3120  */
3121 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3122 {
3123 }
3124
3125 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3126 {
3127   return 0;
3128 }
3129
3130 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3131 {
3132   std::vector<const BigMemoryObject *> ret;
3133   ret.push_back((const MEDFileFieldGlobs *)_globals);
3134   return ret;
3135 }
3136
3137 /*!
3138  * Returns a string describing profiles and Gauss points held in \a this.
3139  *  \return std::string - the description string.
3140  */
3141 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3142 {
3143   const MEDFileFieldGlobs *glob=_globals;
3144   std::ostringstream oss2; oss2 << glob;
3145   std::string stars(oss2.str().length(),'*');
3146   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3147   if(glob)
3148     glob->simpleRepr(oss);
3149   else
3150     oss << "NO GLOBAL INFORMATION !\n";
3151 }
3152
3153 void MEDFileFieldGlobsReal::resetContent()
3154 {
3155   _globals=MEDFileFieldGlobs::New();
3156 }
3157
3158 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3159 {
3160 }
3161
3162 /*!
3163  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3164  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3165  */
3166 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3167 {
3168   _globals=other._globals;
3169 }
3170
3171 /*!
3172  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3173  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3174  */
3175 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3176 {
3177   const MEDFileFieldGlobs *otherg(other._globals);
3178   if(!otherg)
3179     return ;
3180   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3181 }
3182
3183 /*!
3184  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3185  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3186  */
3187 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3188 {
3189   const MEDFileFieldGlobs *otherg(other._globals);
3190   if(!otherg)
3191     return ;
3192   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3193 }
3194
3195 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3196 {
3197   _globals=other._globals;
3198   if((const MEDFileFieldGlobs *)_globals)
3199     _globals=other._globals->deepCpy();
3200 }
3201
3202 /*!
3203  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3204  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3205  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3206  *         \a this and \a other MEDFileFieldGlobsReal.
3207  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3208  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3209  */
3210 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3211 {
3212   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3213   if(thisGlobals==otherGlobals)
3214     return ;
3215   if(!thisGlobals)
3216     {
3217       _globals=other._globals;
3218       return ;
3219     }
3220   _globals->appendGlobs(*other._globals,eps);
3221 }
3222
3223 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3224 {
3225   checkGlobsPflsPartCoherency();
3226   checkGlobsLocsPartCoherency();
3227 }
3228
3229 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3230 {
3231   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3232 }
3233
3234 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3235 {
3236   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3237 }
3238
3239 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3240 {
3241   contentNotNull()->loadProfileInFile(fid,id,pflName);
3242 }
3243
3244 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3245 {
3246   contentNotNull()->loadProfileInFile(fid,id);
3247 }
3248
3249 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3250 {
3251   contentNotNull()->loadGlobals(fid,*this);
3252 }
3253
3254 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3255 {
3256   contentNotNull()->loadAllGlobals(fid);
3257 }
3258
3259 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3260 {
3261   contentNotNull()->writeGlobals(fid,opt);
3262 }
3263
3264 /*!
3265  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3266  * or getPflsReallyUsedMulti().
3267  *  \return std::vector<std::string> - a sequence of names of all profiles.
3268  */
3269 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3270 {
3271   return contentNotNull()->getPfls();
3272 }
3273
3274 /*!
3275  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3276  * or getLocsReallyUsedMulti().
3277  *  \return std::vector<std::string> - a sequence of names of all localizations.
3278  */
3279 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3280 {
3281   return contentNotNull()->getLocs();
3282 }
3283
3284 /*!
3285  * Checks if the profile with a given name exists.
3286  *  \param [in] pflName - the profile name of interest.
3287  *  \return bool - \c true if the profile named \a pflName exists.
3288  */
3289 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3290 {
3291   return contentNotNull()->existsPfl(pflName);
3292 }
3293
3294 /*!
3295  * Checks if the localization with a given name exists.
3296  *  \param [in] locName - the localization name of interest.
3297  *  \return bool - \c true if the localization named \a locName exists.
3298  */
3299 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3300 {
3301   return contentNotNull()->existsLoc(locName);
3302 }
3303
3304 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3305 {
3306   return contentNotNull()->createNewNameOfPfl();
3307 }
3308
3309 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3310 {
3311   return contentNotNull()->createNewNameOfLoc();
3312 }
3313
3314 /*!
3315  * Sets the name of a MED file.
3316  *  \param [inout] fileName - the file name.
3317  */
3318 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3319 {
3320   contentNotNull()->setFileName(fileName);
3321 }
3322
3323 /*!
3324  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3325  * in the same order.
3326  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3327  *          Each item of this sequence is a vector containing ids of equal profiles.
3328  */
3329 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3330 {
3331   return contentNotNull()->whichAreEqualProfiles();
3332 }
3333
3334 /*!
3335  * Finds equal localizations.
3336  *  \param [in] eps - a precision used to compare real values of the localizations.
3337  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3338  *          Each item of this sequence is a vector containing ids of equal localizations.
3339  */
3340 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3341 {
3342   return contentNotNull()->whichAreEqualLocs(eps);
3343 }
3344
3345 /*!
3346  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3347  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3348  *        this sequence is a pair whose 
3349  *        - the first item is a vector of profile names to replace by the second item,
3350  *        - the second item is a profile name to replace every profile name of the first item.
3351  */
3352 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3353 {
3354   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3355 }
3356
3357 /*!
3358  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3359  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3360  *        this sequence is a pair whose 
3361  *        - the first item is a vector of localization names to replace by the second item,
3362  *        - the second item is a localization name to replace every localization name of the first item.
3363  */
3364 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3365 {
3366   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3367 }
3368
3369 /*!
3370  * Replaces references to some profiles (a reference is a profile name) by references
3371  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3372  * them-selves accordingly. <br>
3373  * This method is a generalization of changePflName().
3374  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3375  *        this sequence is a pair whose 
3376  *        - the first item is a vector of profile names to replace by the second item,
3377  *        - the second item is a profile name to replace every profile of the first item.
3378  * \sa changePflsRefsNamesGen()
3379  * \sa changePflName()
3380  */
3381 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3382 {
3383   changePflsRefsNamesGen(mapOfModif);
3384   changePflsNamesInStruct(mapOfModif);
3385 }
3386
3387 /*!
3388  * Replaces references to some localizations (a reference is a localization name) by references
3389  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3390  * them-selves accordingly. <br>
3391  * This method is a generalization of changeLocName().
3392  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3393  *        this sequence is a pair whose 
3394  *        - the first item is a vector of localization names to replace by the second item,
3395  *        - the second item is a localization name to replace every localization of the first item.
3396  * \sa changeLocsRefsNamesGen()
3397  * \sa changeLocName()
3398  */
3399 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3400 {
3401   changeLocsRefsNamesGen(mapOfModif);
3402   changeLocsNamesInStruct(mapOfModif);
3403 }
3404
3405 /*!
3406  * Renames the profile having a given name and updates references to this profile.
3407  *  \param [in] oldName - the name of the profile to rename.
3408  *  \param [in] newName - a new name of the profile.
3409  * \sa changePflsNames().
3410  */
3411 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3412 {
3413   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3414   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3415   mapOfModif[0]=p;
3416   changePflsNames(mapOfModif);
3417 }
3418
3419 /*!
3420  * Renames the localization having a given name and updates references to this localization.
3421  *  \param [in] oldName - the name of the localization to rename.
3422  *  \param [in] newName - a new name of the localization.
3423  * \sa changeLocsNames().
3424  */
3425 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3426 {
3427   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3428   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3429   mapOfModif[0]=p;
3430   changeLocsNames(mapOfModif);
3431 }
3432
3433 /*!
3434  * Removes duplicated profiles. Returns a map used to update references to removed 
3435  * profiles via changePflsRefsNamesGen().
3436  * Equal profiles are found using whichAreEqualProfiles().
3437  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3438  *          a sequence describing the performed replacements of profiles. Each element of
3439  *          this sequence is a pair whose
3440  *          - the first item is a vector of profile names replaced by the second item,
3441  *          - the second item is a profile name replacing every profile of the first item.
3442  */
3443 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3444 {
3445   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3446   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3447   int i=0;
3448   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3449     {
3450       std::vector< std::string > tmp((*it).size());
3451       int j=0;
3452       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3453         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3454       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3455       ret[i]=p;
3456       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3457       killProfileIds(tmp2);
3458     }
3459   changePflsRefsNamesGen(ret);
3460   return ret;
3461 }
3462
3463 /*!
3464  * Removes duplicated localizations. Returns a map used to update references to removed 
3465  * localizations via changeLocsRefsNamesGen().
3466  * Equal localizations are found using whichAreEqualLocs().
3467  *  \param [in] eps - a precision used to compare real values of the localizations.
3468  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3469  *          a sequence describing the performed replacements of localizations. Each element of
3470  *          this sequence is a pair whose
3471  *          - the first item is a vector of localization names replaced by the second item,
3472  *          - the second item is a localization name replacing every localization of the first item.
3473  */
3474 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3475 {
3476   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3477   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3478   int i=0;
3479   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3480     {
3481       std::vector< std::string > tmp((*it).size());
3482       int j=0;
3483       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3484         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3485       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3486       ret[i]=p;
3487       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3488       killLocalizationIds(tmp2);
3489     }
3490   changeLocsRefsNamesGen(ret);
3491   return ret;
3492 }
3493
3494 /*!
3495  * Returns number of Gauss points per cell in a given localization.
3496  *  \param [in] locId - an id of the localization of interest.
3497  *  \return int - the number of the Gauss points per cell.
3498  */
3499 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3500 {
3501   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3502 }
3503
3504 /*!
3505  * Returns an id of a localization by its name.
3506  *  \param [in] loc - the localization name of interest.
3507  *  \return int - the id of the localization.
3508  *  \throw If there is no a localization named \a loc.
3509  */
3510 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3511 {
3512   return contentNotNull()->getLocalizationId(loc);
3513 }
3514
3515 /*!
3516  * Returns the name of the MED file.
3517  *  \return const std::string&  - the MED file name.
3518  */
3519 std::string MEDFileFieldGlobsReal::getFileName() const
3520 {
3521   return contentNotNull()->getFileName();
3522 }
3523
3524 /*!
3525  * Returns a localization object by its name.
3526  *  \param [in] locName - the name of the localization of interest.
3527  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3528  *  \throw If there is no a localization named \a locName.
3529  */
3530 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3531 {
3532   return contentNotNull()->getLocalization(locName);
3533 }
3534
3535 /*!
3536  * Returns a localization object by its id.
3537  *  \param [in] locId - the id of the localization of interest.
3538  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3539  *  \throw If there is no a localization with id \a locId.
3540  */
3541 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3542 {
3543   return contentNotNull()->getLocalizationFromId(locId);
3544 }
3545
3546 /*!
3547  * Returns a profile array by its name.
3548  *  \param [in] pflName - the name of the profile of interest.
3549  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3550  *  \throw If there is no a profile named \a pflName.
3551  */
3552 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3553 {
3554   return contentNotNull()->getProfile(pflName);
3555 }
3556
3557 /*!
3558  * Returns a profile array by its id.
3559  *  \param [in] pflId - the id of the profile of interest.
3560  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3561  *  \throw If there is no a profile with id \a pflId.
3562  */
3563 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3564 {
3565   return contentNotNull()->getProfileFromId(pflId);
3566 }
3567
3568 /*!
3569  * Returns a localization object, apt for modification, by its id.
3570  *  \param [in] locId - the id of the localization of interest.
3571  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3572  *          having the id \a locId.
3573  *  \throw If there is no a localization with id \a locId.
3574  */
3575 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3576 {
3577   return contentNotNull()->getLocalizationFromId(locId);
3578 }
3579
3580 /*!
3581  * Returns a localization object, apt for modification, by its name.
3582  *  \param [in] locName - the name of the localization of interest.
3583  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3584  *          having the name \a locName.
3585  *  \throw If there is no a localization named \a locName.
3586  */
3587 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3588 {
3589   return contentNotNull()->getLocalization(locName);
3590 }
3591
3592 /*!
3593  * Returns a profile array, apt for modification, by its name.
3594  *  \param [in] pflName - the name of the profile of interest.
3595  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3596  *  \throw If there is no a profile named \a pflName.
3597  */
3598 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3599 {
3600   return contentNotNull()->getProfile(pflName);
3601 }
3602
3603 /*!
3604  * Returns a profile array, apt for modification, by its id.
3605  *  \param [in] pflId - the id of the profile of interest.
3606  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3607  *  \throw If there is no a profile with id \a pflId.
3608  */
3609 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3610 {
3611   return contentNotNull()->getProfileFromId(pflId);
3612 }
3613
3614 /*!
3615  * Removes profiles given by their ids. No data is updated to track this removal.
3616  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3617  */
3618 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3619 {
3620   contentNotNull()->killProfileIds(pflIds);
3621 }
3622
3623 /*!
3624  * Removes localizations given by their ids. No data is updated to track this removal.
3625  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3626  */
3627 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3628 {
3629   contentNotNull()->killLocalizationIds(locIds);
3630 }
3631
3632 /*!
3633  * Stores a profile array.
3634  *  \param [in] pfl - the profile array to store.
3635  *  \throw If the name of \a pfl is empty.
3636  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3637  *         different ids.
3638  */
3639 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3640 {
3641   contentNotNull()->appendProfile(pfl);
3642 }
3643
3644 /*!
3645  * Adds a new localization of Gauss points.
3646  *  \param [in] locName - the name of the new localization.
3647  *  \param [in] geoType - a geometrical type of the reference cell.
3648  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3649  *         must be \c nbOfNodesPerCell * \c dimOfType.
3650  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3651  *         must be  _wg_.size() * \c dimOfType.
3652  *  \param [in] w - the weights of Gauss points.
3653  *  \throw If \a locName is empty.
3654  *  \throw If a localization with the name \a locName already exists but is
3655  *         different form the new one.
3656  */
3657 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)
3658 {
3659   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3660 }
3661
3662 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3663 {
3664   MEDFileFieldGlobs *g(_globals);
3665   if(!g)
3666     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3667   return g;
3668 }
3669
3670 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3671 {
3672   const MEDFileFieldGlobs *g(_globals);
3673   if(!g)
3674     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3675   return g;
3676 }
3677
3678 //= MEDFileFieldNameScope
3679
3680 MEDFileFieldNameScope::MEDFileFieldNameScope()
3681 {
3682 }
3683
3684 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3685 {
3686 }
3687
3688 /*!
3689  * Returns the name of \a this field.
3690  *  \return std::string - a string containing the field name.
3691  */
3692 std::string MEDFileFieldNameScope::getName() const
3693 {
3694   return _name;
3695 }
3696
3697 /*!
3698  * Sets name of \a this field
3699  *  \param [in] name - the new field name.
3700  */
3701 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3702 {
3703   _name=fieldName;
3704 }
3705
3706 std::string MEDFileFieldNameScope::getDtUnit() const
3707 {
3708   return _dt_unit;
3709 }
3710
3711 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3712 {
3713   _dt_unit=dtUnit;
3714 }
3715
3716 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3717 {
3718   _name=other._name;
3719   _dt_unit=other._dt_unit;
3720 }
3721
3722 //= MEDFileAnyTypeField1TSWithoutSDA
3723
3724 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3725 {
3726   _field_per_mesh.resize(other._field_per_mesh.size());
3727   std::size_t i=0;
3728   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3729     {
3730       if((const MEDFileFieldPerMesh *)*it)
3731         _field_per_mesh[i]=(*it)->deepCpy(this);
3732     }
3733 }
3734
3735 /*!
3736  * Prints a string describing \a this field into a stream. This string is outputted 
3737  * by \c print Python command.
3738  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3739  *  \param [in,out] oss - the out stream.
3740  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3741  *          info id printed, else, not.
3742  */
3743 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3744 {
3745   std::string startOfLine(bkOffset,' ');
3746   oss << startOfLine << "Field ";
3747   if(bkOffset==0)
3748     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3749   oss << "on one time Step ";
3750   if(f1tsId>=0)
3751     oss << "(" << f1tsId << ") ";
3752   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3753   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3754   const DataArray *arr=getUndergroundDataArray();
3755   if(arr)
3756     {
3757       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3758       if(f1tsId<0)
3759         {
3760           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3761           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3762             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3763         }
3764       if(arr->isAllocated())
3765         {
3766           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3767         }
3768       else
3769         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3770     }
3771   else
3772     {
3773       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3774     }
3775   oss << startOfLine << "----------------------" << std::endl;
3776   if(!_field_per_mesh.empty())
3777     {
3778       int i=0;
3779       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3780         {
3781           const MEDFileFieldPerMesh *cur=(*it2);
3782           if(cur)
3783             cur->simpleRepr(bkOffset,oss,i);
3784           else
3785             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3786         }
3787     }
3788   else
3789     {
3790       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3791     }
3792   oss << startOfLine << "----------------------" << std::endl;
3793 }
3794
3795 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3796 {
3797   const DataArray *arr(getUndergroundDataArray());
3798   if(!arr)
3799     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3800   int nbOfCompo=arr->getNumberOfComponents();
3801   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3802   for(int i=0;i<nbOfCompo;i++)
3803     {
3804       ret[i]=deepCpy();
3805       std::vector<int> v(1,i);
3806       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3807       ret[i]->setArray(arr2);
3808     }
3809   return ret;
3810 }
3811
3812 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)
3813 {
3814 }
3815
3816 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3817 {
3818 }
3819
3820 /*!
3821  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3822  * empty. Returns -1 if this in on nodes.
3823  *  \return int - the dimension of \a this.
3824  */
3825 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3826 {
3827   int ret=-2;
3828   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3829     (*it)->getDimension(ret);
3830   return ret;
3831 }
3832
3833 /*!
3834  * Returns the mesh name.
3835  *  \return std::string - a string holding the mesh name.
3836  *  \throw If \c _field_per_mesh.empty()
3837  */
3838 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3839 {
3840   if(_field_per_mesh.empty())
3841     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3842   return _field_per_mesh[0]->getMeshName();
3843 }
3844
3845 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3846 {
3847   std::string oldName(getMeshName());
3848   std::vector< std::pair<std::string,std::string> > v(1);
3849   v[0].first=oldName; v[0].second=newMeshName;
3850   changeMeshNames(v);
3851 }
3852
3853 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3854 {
3855   bool ret=false;
3856   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3857     {
3858       MEDFileFieldPerMesh *cur(*it);
3859       if(cur)
3860         ret=cur->changeMeshNames(modifTab) || ret;
3861     }
3862   return ret;
3863 }
3864
3865 /*!
3866  * Returns the number of iteration of the state of underlying mesh.
3867  *  \return int - the iteration number.
3868  *  \throw If \c _field_per_mesh.empty()
3869  */
3870 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3871 {
3872   if(_field_per_mesh.empty())
3873     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3874   return _field_per_mesh[0]->getMeshIteration();
3875 }
3876
3877 /*!
3878  * Returns the order number of iteration of the state of underlying mesh.
3879  *  \return int - the order number.
3880  *  \throw If \c _field_per_mesh.empty()
3881  */
3882 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3883 {
3884   if(_field_per_mesh.empty())
3885     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3886   return _field_per_mesh[0]->getMeshOrder();
3887 }
3888
3889 /*!
3890  * Checks if \a this field is tagged by a given iteration number and a given
3891  * iteration order number.
3892  *  \param [in] iteration - the iteration number of interest.
3893  *  \param [in] order - the iteration order number of interest.
3894  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3895  *          \a this->getOrder() == \a order.
3896  */
3897 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3898 {
3899   return iteration==_iteration && order==_order;
3900 }
3901
3902 /*!
3903  * Returns number of iteration and order number of iteration when
3904  * \a this field has been calculated.
3905  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3906  *          order number.
3907  */
3908 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3909 {
3910   std::pair<int,int> p;
3911   fillIteration(p);
3912   return p;
3913 }
3914
3915 /*!
3916  * Returns number of iteration and order number of iteration when
3917  * \a this field has been calculated.
3918  *  \param [in,out] p - a pair returning the iteration number and the iteration
3919  *          order number.
3920  */
3921 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3922 {
3923   p.first=_iteration;
3924   p.second=_order;
3925 }
3926
3927 /*!
3928  * Returns all types of spatial discretization of \a this field.
3929  *  \param [in,out] types - a sequence of types of \a this field.
3930  */
3931 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
3932 {
3933   std::set<TypeOfField> types2;
3934   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3935     {
3936       (*it)->fillTypesOfFieldAvailable(types2);
3937     }
3938   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3939   std::copy(types2.begin(),types2.end(),bi);
3940 }
3941
3942 /*!
3943  * Returns all types of spatial discretization of \a this field.
3944  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3945  *          of \a this field.
3946  */
3947 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
3948 {
3949   std::vector<TypeOfField> ret;
3950   fillTypesOfFieldAvailable(ret);
3951   return ret;
3952 }
3953
3954 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3955 {
3956   std::vector<std::string> ret;
3957   std::set<std::string> ret2;
3958   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3959     {
3960       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3961       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3962         if(ret2.find(*it2)==ret2.end())
3963           {
3964             ret.push_back(*it2);
3965             ret2.insert(*it2);
3966           }
3967     }
3968   return ret;
3969 }
3970
3971 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3972 {
3973   std::vector<std::string> ret;
3974   std::set<std::string> ret2;
3975   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3976     {
3977       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3978       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3979         if(ret2.find(*it2)==ret2.end())
3980           {
3981             ret.push_back(*it2);
3982             ret2.insert(*it2);
3983           }
3984     }
3985   return ret;
3986 }
3987
3988 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3989 {
3990   std::vector<std::string> ret;
3991   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3992     {
3993       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3994       ret.insert(ret.end(),tmp.begin(),tmp.end());
3995     }
3996   return ret;
3997 }
3998
3999 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4000 {
4001   std::vector<std::string> ret;
4002   std::set<std::string> ret2;
4003   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4004     {
4005       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4006       ret.insert(ret.end(),tmp.begin(),tmp.end());
4007     }
4008   return ret;
4009 }
4010
4011 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4012 {
4013   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4014     (*it)->changePflsRefsNamesGen(mapOfModif);
4015 }
4016
4017 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4018 {
4019   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4020     (*it)->changeLocsRefsNamesGen(mapOfModif);
4021 }
4022
4023 /*!
4024  * Returns all attributes of parts of \a this field lying on a given mesh.
4025  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4026  * item of every of returned sequences refers to the _i_-th part of \a this field.
4027  * Thus all sequences returned by this method are of the same length equal to number
4028  * of different types of supporting entities.<br>
4029  * A field part can include sub-parts with several different spatial discretizations,
4030  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4031  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4032  * of a nested sequence corresponds to a type of spatial discretization.<br>
4033  * This method allows for iteration over MEDFile DataStructure without any overhead.
4034  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4035  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4036  *          not checked if \a mname == \c NULL).
4037  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4038  *          a field part is returned. 
4039  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4040  *          This sequence is of the same length as \a types. 
4041  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4042  *          discretization. A profile name can be empty.
4043  *          Length of this and of nested sequences is the same as that of \a typesF.
4044  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4045  *          discretization. A localization name can be empty.
4046  *          Length of this and of nested sequences is the same as that of \a typesF.
4047  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4048  *          of ids of tuples within the data array, per each type of spatial
4049  *          discretization within one mesh entity type. 
4050  *          Length of this and of nested sequences is the same as that of \a typesF.
4051  *  \throw If no field is lying on \a mname.
4052  */
4053 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
4054 {
4055   int meshId=0;
4056   if(!mname.empty())
4057     meshId=getMeshIdFromMeshName(mname);
4058   else
4059     if(_field_per_mesh.empty())
4060       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4061   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4062 }
4063
4064 /*!
4065  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4066  * maximal absolute dimension and values returned via the out parameter \a levs are 
4067  * dimensions relative to the maximal absolute dimension. <br>
4068  * This method is designed for MEDFileField1TS instances that have a discretization
4069  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
4070  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
4071  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
4072  * Only these 3 discretizations will be taken into account here. If \a this is
4073  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4074  * This method is useful to make the link between the dimension of the underlying mesh
4075  * and the levels of \a this, because it is possible that the highest dimension of \a this
4076  * field is not equal to the dimension of the underlying mesh.
4077  * 
4078  * Let's consider the following case:
4079  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4080  * TETRA4, HEXA8, TRI3 and SEG2.
4081  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4082  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4083  *
4084  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4085  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4086  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4087  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4088  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4089  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4090  * For example<br>
4091  * to retrieve the highest level of
4092  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4093  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4094  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4095  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4096  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4097  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4098  *          not checked if \a mname == \c NULL).
4099  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4100  *          absolute one. They are in decreasing order. This sequence is cleared before
4101  *          filling it in.
4102  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4103  *  \throw If no field is lying on \a mname.
4104  */
4105 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4106 {
4107   levs.clear();
4108   int meshId=getMeshIdFromMeshName(mname);
4109   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4110   std::vector< std::vector<TypeOfField> > typesF;
4111   std::vector< std::vector<std::string> > pfls, locs;
4112   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4113   if(types.empty())
4114     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4115   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4116   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4117     return -1;
4118   st.erase(INTERP_KERNEL::NORM_ERROR);
4119   std::set<int> ret1;
4120   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4121     {
4122       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4123       ret1.insert((int)cm.getDimension());
4124     }
4125   int ret=*std::max_element(ret1.begin(),ret1.end());
4126   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4127   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4128   return ret;
4129 }
4130
4131 /*!
4132  * \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.
4133  * \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.
4134  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4135  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4136  */
4137 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4138 {
4139   int mid=getMeshIdFromMeshName(mName);
4140   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4141 }
4142
4143 /*!
4144  * \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.
4145  * \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.
4146  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4147  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4148  */
4149 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4150 {
4151   int mid=getMeshIdFromMeshName(mName);
4152   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4153 }
4154
4155 /*!
4156  * \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.
4157  */
4158 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4159 {
4160   if(_field_per_mesh.empty())
4161     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4162   if(mName.empty())
4163     return 0;
4164   std::string mName2(mName);
4165   int ret=0;
4166   std::vector<std::string> msg;
4167   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4168     if(mName2==(*it)->getMeshName())
4169       return ret;
4170     else
4171       msg.push_back((*it)->getMeshName());
4172   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4173   oss << "Possible meshes are : ";
4174   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4175     oss << "\"" << (*it2) << "\" ";
4176   throw INTERP_KERNEL::Exception(oss.str().c_str());
4177 }
4178
4179 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4180 {
4181   if(!mesh)
4182     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4183   std::string tmp(mesh->getName());
4184   if(tmp.empty())
4185     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4186   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4187   int i=0;
4188   for(;it!=_field_per_mesh.end();it++,i++)
4189     {
4190       if((*it)->getMeshName()==tmp)
4191         return i;
4192     }
4193   int sz=_field_per_mesh.size();
4194   _field_per_mesh.resize(sz+1);
4195   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4196   return sz;
4197 }
4198
4199 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4200                                                                    MEDFileFieldGlobsReal& glob)
4201 {
4202   bool ret=false;
4203   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4204     {
4205       MEDFileFieldPerMesh *fpm(*it);
4206       if(fpm)
4207         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4208     }
4209   return ret;
4210 }
4211
4212 /*!
4213  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4214  * splitting that leads to single spatial discretization of this.
4215  *
4216  * \sa splitMultiDiscrPerGeoTypes
4217  */
4218 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4219 {
4220   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4221   std::vector< std::vector<TypeOfField> > typesF;
4222   std::vector< std::vector<std::string> > pfls,locs;
4223   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4224   std::set<TypeOfField> allEnt;
4225   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4226     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4227       allEnt.insert(*it2);
4228   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4229   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4230   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4231     {
4232       std::vector< std::pair<int,int> > its;
4233       ret[i]=shallowCpy();
4234       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4235       ret[i]->updateData(newLgth,its);
4236     }
4237   return ret;
4238 }
4239
4240 /*!
4241  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4242  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4243  *
4244  * \sa splitDiscretizations
4245  */
4246 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4247 {
4248   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4249   std::vector< std::vector<TypeOfField> > typesF;
4250   std::vector< std::vector<std::string> > pfls,locs;
4251   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4252   std::set<TypeOfField> allEnt;
4253   std::size_t nbOfMDPGT(0),ii(0);
4254   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4255     {
4256       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4257       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4258         allEnt.insert(*it2);
4259     }
4260         if(allEnt.size()!=1)
4261           throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4262         if(nbOfMDPGT==0)
4263           throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4264   if(nbOfMDPGT==1)
4265     {
4266       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4267       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4268       return ret0;
4269     }
4270   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4271   for(std::size_t i=0;i<nbOfMDPGT;i++)
4272     {
4273       std::vector< std::pair<int,int> > its;
4274       ret[i]=shallowCpy();
4275       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4276       ret[i]->updateData(newLgth,its);
4277     }
4278   return ret;
4279 }
4280
4281 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4282 {
4283   int globalCounter(0);
4284   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4285     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4286   return globalCounter;
4287 }
4288
4289 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4290 {
4291   int globalCounter(0);
4292   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4293     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4294   return globalCounter;
4295 }
4296
4297 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4298 {
4299   if(_nb_of_tuples_to_be_allocated>=0)
4300     {
4301       _nb_of_tuples_to_be_allocated=newLgth;
4302       const DataArray *oldArr(getUndergroundDataArray());
4303       if(oldArr)
4304         {
4305           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4306           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4307           setArray(newArr);
4308           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4309         }
4310       return ;
4311     }
4312   if(_nb_of_tuples_to_be_allocated==-1)
4313     return ;
4314   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4315     {
4316       const DataArray *oldArr(getUndergroundDataArray());
4317       if(!oldArr || !oldArr->isAllocated())
4318         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4319       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4320       newArr->alloc(newLgth,getNumberOfComponents());
4321       if(oldArr)
4322         newArr->copyStringInfoFrom(*oldArr);
4323       int pos=0;
4324       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4325         {
4326           if((*it).second<(*it).first)
4327             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4328           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4329           pos+=(*it).second-(*it).first;
4330         }
4331       setArray(newArr);
4332       return ;
4333     }
4334   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4335 }
4336
4337 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4338 {
4339   if(_field_per_mesh.empty())
4340     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4341   if(_field_per_mesh.size()>1)
4342     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4343   _field_per_mesh[0]->copyOptionsFrom(opts);
4344   _field_per_mesh[0]->writeLL(fid,nasc);
4345 }
4346
4347 /*!
4348  * 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.
4349  * If false is returned the memory allocation is not required.
4350  */
4351 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4352 {
4353   if(_nb_of_tuples_to_be_allocated>=0)
4354     {
4355       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4356       _nb_of_tuples_to_be_allocated=-2;
4357       return true;
4358     }
4359   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4360     return false;
4361   if(_nb_of_tuples_to_be_allocated==-1)
4362     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4363   if(_nb_of_tuples_to_be_allocated<-3)
4364     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4365   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4366 }
4367
4368 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms)
4369 {
4370   med_int numdt,numit;
4371   med_float dt;
4372   med_int nmesh;
4373   med_bool localMesh;
4374   med_int meshnumdt,meshnumit;
4375   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4376   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4377   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4378   if(_iteration!=numdt || _order!=numit)
4379     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4380   _field_per_mesh.resize(nmesh);
4381   //
4382   MEDFileMesh *mm(0);
4383   if(ms)
4384     {
4385       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4386       mm=ms->getMeshWithName(meshNameCpp);
4387     }
4388   //
4389   for(int i=0;i<nmesh;i++)
4390     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm);
4391   _nb_of_tuples_to_be_allocated=0;
4392   for(int i=0;i<nmesh;i++)
4393     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4394 }
4395
4396 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4397 {
4398   allocIfNecessaryTheArrayToReceiveDataFromFile();
4399   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4400     (*it)->loadBigArraysRecursively(fid,nasc);
4401 }
4402
4403 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4404 {
4405   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4406     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4407       (*it)->loadBigArraysRecursively(fid,nasc);
4408 }
4409
4410 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms)
4411 {
4412   loadOnlyStructureOfDataRecursively(fid,nasc,ms);
4413   loadBigArraysRecursively(fid,nasc);
4414 }
4415
4416 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4417 {
4418   DataArray *thisArr(getUndergroundDataArray());
4419   if(thisArr && thisArr->isAllocated())
4420     {
4421       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4422       thisArr->desallocate();
4423     }
4424 }
4425
4426 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4427 {
4428   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4429 }
4430
4431 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4432 {
4433   std::vector<const BigMemoryObject *> ret;
4434   if(getUndergroundDataArray())
4435     ret.push_back(getUndergroundDataArray());
4436   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4437     ret.push_back((const MEDFileFieldPerMesh *)*it);
4438   return ret;
4439 }
4440
4441 /*!
4442  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4443  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4444  * "Sort By Type"), if not, an exception is thrown. 
4445  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4446  *  \param [in] arr - the array of values.
4447  *  \param [in,out] glob - the global data where profiles and localization present in
4448  *          \a field, if any, are added.
4449  *  \throw If the name of \a field is empty.
4450  *  \throw If the data array of \a field is not set.
4451  *  \throw If \a this->_arr is already allocated but has different number of components
4452  *         than \a field.
4453  *  \throw If the underlying mesh of \a field has no name.
4454  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4455  */
4456 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4457 {
4458   const MEDCouplingMesh *mesh=field->getMesh();
4459   //
4460   TypeOfField type=field->getTypeOfField();
4461   std::vector<DataArrayInt *> dummy;
4462   int start=copyTinyInfoFrom(field,arr);
4463   int pos=addNewEntryIfNecessary(mesh);
4464   if(type!=ON_NODES)
4465     {
4466       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4467       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4468     }
4469   else
4470     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4471 }
4472
4473 /*!
4474  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4475  * of a given mesh are used as the support of the given field (a real support is not used). 
4476  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4477  * Order of underlying mesh entities of the given field specified by \a profile parameter
4478  * is not prescribed; this method permutes field values to have them sorted by element
4479  * type as required for writing to MED file. A new profile is added only if no equal
4480  * profile is missing. 
4481  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4482  *  \param [in] arrOfVals - the values of the field \a field used.
4483  *  \param [in] mesh - the supporting mesh of \a field.
4484  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4485  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4486  *  \param [in,out] glob - the global data where profiles and localization present in
4487  *          \a field, if any, are added.
4488  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4489  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4490  *  \throw If the data array of \a field is not set.
4491  *  \throw If \a this->_arr is already allocated but has different number of components
4492  *         than \a field.
4493  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4494  *  \sa setFieldNoProfileSBT()
4495  */
4496 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4497 {
4498   if(!field)
4499     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4500   if(!arrOfVals || !arrOfVals->isAllocated())
4501     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4502   TypeOfField type=field->getTypeOfField();
4503   std::vector<DataArrayInt *> idsInPflPerType;
4504   std::vector<DataArrayInt *> idsPerType;
4505   std::vector<int> code,code2;
4506   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4507   if(type!=ON_NODES)
4508     {
4509       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4510       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4511       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4512       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4513       // start of check
4514       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4515       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4516       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4517         {
4518           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4519           throw INTERP_KERNEL::Exception(oss.str().c_str());
4520         }
4521       // end of check
4522       int start=copyTinyInfoFrom(field,arrOfVals);
4523       code2=m->getDistributionOfTypes();
4524       //
4525       int pos=addNewEntryIfNecessary(m);
4526       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4527     }
4528   else
4529     {
4530       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4531         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4532       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4533       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4534       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4535       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4536         {
4537           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4538           throw INTERP_KERNEL::Exception(oss.str().c_str());
4539         }
4540       int start=copyTinyInfoFrom(field,arrOfVals);
4541       int pos=addNewEntryIfNecessary(m);
4542       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4543     }
4544 }
4545
4546 /*!
4547  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4548  */
4549 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4550 {
4551   if(_nb_of_tuples_to_be_allocated>=0)
4552     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 !");
4553   DataArray *arr(getOrCreateAndGetArray());
4554   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4555   _nb_of_tuples_to_be_allocated=-3;
4556 }
4557
4558 /*!
4559  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4560  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4561  * larger by the size of \a field. Returns an id of the first not filled
4562  * tuple of \a this->_arr.
4563  *  \param [in] field - the field to copy the info on components and the name from.
4564  *  \return int - the id of first not initialized tuple of \a this->_arr.
4565  *  \throw If the name of \a field is empty.
4566  *  \throw If the data array of \a field is not set.
4567  *  \throw If \a this->_arr is already allocated but has different number of components
4568  *         than \a field.
4569  */
4570 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4571 {
4572   if(!field)
4573     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4574   std::string name(field->getName());
4575   setName(name.c_str());
4576   setDtUnit(field->getTimeUnit());
4577   if(name.empty())
4578     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4579   if(!arr)
4580     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4581   if(!arr->isAllocated())
4582     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4583   _dt=field->getTime(_iteration,_order);
4584   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4585   if(!getOrCreateAndGetArray()->isAllocated())
4586     {
4587       allocNotFromFile(arr->getNumberOfTuples());
4588       return 0;
4589     }
4590   else
4591     {
4592       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4593       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4594       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4595       _nb_of_tuples_to_be_allocated=-3;
4596       return oldNbOfTuples;
4597     }
4598 }
4599
4600 /*!
4601  * Returns number of components in \a this field
4602  *  \return int - the number of components.
4603  */
4604 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4605 {
4606   return getOrCreateAndGetArray()->getNumberOfComponents();
4607 }
4608
4609 /*!
4610  * Change info on components in \a this.
4611  * \throw If size of \a infos is not equal to the number of components already in \a this.
4612  */
4613 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4614 {
4615   DataArray *arr=getOrCreateAndGetArray();
4616   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4617 }
4618
4619 /*!
4620  * Returns info on components of \a this field.
4621  *  \return const std::vector<std::string>& - a sequence of strings each being an
4622  *          information on _i_-th component.
4623  */
4624 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4625 {
4626   const DataArray *arr=getOrCreateAndGetArray();
4627   return arr->getInfoOnComponents();
4628 }
4629
4630 /*!
4631  * Returns a mutable info on components of \a this field.
4632  *  \return std::vector<std::string>& - a sequence of strings each being an
4633  *          information on _i_-th component.
4634  */
4635 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4636 {
4637   DataArray *arr=getOrCreateAndGetArray();
4638   return arr->getInfoOnComponents();
4639 }
4640
4641 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4642 {
4643   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4644     {
4645       const MEDFileFieldPerMesh *fpm(*it);
4646       if(!fpm)
4647         continue;
4648       if(fpm->presenceOfMultiDiscPerGeoType())
4649         return true;
4650     }
4651   return false;
4652 }
4653
4654 /*!
4655  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4656  *  \param [in] type - a spatial discretization of the new field.
4657  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4658  *  \param [in] mName - a name of the supporting mesh.
4659  *  \param [in] renumPol - specifies how to permute values of the result field according to
4660  *          the optional numbers of cells and nodes, if any. The valid values are
4661  *          - 0 - do not permute.
4662  *          - 1 - permute cells.
4663  *          - 2 - permute nodes.
4664  *          - 3 - permute cells and nodes.
4665  *
4666  *  \param [in] glob - the global data storing profiles and localization.
4667  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4668  *          caller is to delete this field using decrRef() as it is no more needed. 
4669  *  \throw If the MED file is not readable.
4670  *  \throw If there is no mesh named \a mName in the MED file.
4671  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4672  *  \throw If no field of \a this is lying on the mesh \a mName.
4673  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4674  */
4675 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4676 {
4677   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4678   if(mName.empty())
4679     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4680   else
4681     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4682   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4683 }
4684
4685 /*!
4686  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4687  *  \param [in] type - a spatial discretization of the new field.
4688  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4689  *  \param [in] renumPol - specifies how to permute values of the result field according to
4690  *          the optional numbers of cells and nodes, if any. The valid values are
4691  *          - 0 - do not permute.
4692  *          - 1 - permute cells.
4693  *          - 2 - permute nodes.
4694  *          - 3 - permute cells and nodes.
4695  *
4696  *  \param [in] glob - the global data storing profiles and localization.
4697  *  \param [in] mesh - the supporting mesh.
4698  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4699  *          caller is to delete this field using decrRef() as it is no more needed. 
4700  *  \throw If the MED file is not readable.
4701  *  \throw If no field of \a this is lying on \a mesh.
4702  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4703  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4704  */
4705 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4706 {
4707   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4708   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4709   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4710   if(meshDimRelToMax==1)
4711     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4712   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4713 }
4714
4715 /*!
4716  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4717  * given mesh. 
4718  *  \param [in] type - a spatial discretization of the new field.
4719  *  \param [in] mName - a name of the supporting mesh.
4720  *  \param [in] renumPol - specifies how to permute values of the result field according to
4721  *          the optional numbers of cells and nodes, if any. The valid values are
4722  *          - 0 - do not permute.
4723  *          - 1 - permute cells.
4724  *          - 2 - permute nodes.
4725  *          - 3 - permute cells and nodes.
4726  *
4727  *  \param [in] glob - the global data storing profiles and localization.
4728  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4729  *          caller is to delete this field using decrRef() as it is no more needed. 
4730  *  \throw If the MED file is not readable.
4731  *  \throw If there is no mesh named \a mName in the MED file.
4732  *  \throw If there are no mesh entities in the mesh.
4733  *  \throw If no field values of the given \a type are available.
4734  */
4735 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4736 {
4737   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4738   if(mName.empty())
4739     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4740   else
4741     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4742   int absDim=getDimension();
4743   int meshDimRelToMax=absDim-mm->getMeshDimension();
4744   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4745 }
4746
4747 /*!
4748  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4749  *  \param [in] type - a spatial discretization of the new field.
4750  *  \param [in] renumPol - specifies how to permute values of the result field according to
4751  *          the optional numbers of cells and nodes, if any. The valid values are
4752  *          - 0 - do not permute.
4753  *          - 1 - permute cells.
4754  *          - 2 - permute nodes.
4755  *          - 3 - permute cells and nodes.
4756  *
4757  *  \param [in] glob - the global data storing profiles and localization.
4758  *  \param [in] mesh - the supporting mesh.
4759  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4760  *         field according to \a renumPol.
4761  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4762  *         field according to \a renumPol.
4763  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4764  *          caller is to delete this field using decrRef() as it is no more needed. 
4765  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4766  *  \throw If no field of \a this is lying on \a mesh.
4767  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4768  */
4769 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
4770 {
4771   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4772   int meshId=getMeshIdFromMeshName(mesh->getName());
4773   bool isPfl=false;
4774   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4775   switch(renumPol)
4776   {
4777     case 0:
4778       {
4779         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4780         return ret.retn();
4781       }
4782     case 3:
4783     case 1:
4784       {
4785         if(isPfl)
4786           throw INTERP_KERNEL::Exception(msg1);
4787         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4788         if(cellRenum)
4789           {
4790             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4791               {
4792                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4793                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4794                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4795               }
4796             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4797             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4798             std::vector<DataArray *> arrOut2(1,arrOut);
4799             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4800             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4801             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4802           }
4803         if(renumPol==1)
4804           return ret.retn();
4805       }
4806     case 2:
4807       {
4808         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4809         if(isPfl)
4810           throw INTERP_KERNEL::Exception(msg1);
4811         if(nodeRenum)
4812           {
4813             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4814               {
4815                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4816                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4817                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4818               }
4819             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4820             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4821               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4822             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4823           }
4824         return ret.retn();
4825       }
4826     default:
4827       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4828   }
4829 }
4830
4831 /*!
4832  * Returns values and a profile of the field of a given type lying on a given support.
4833  *  \param [in] type - a spatial discretization of the field.
4834  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4835  *  \param [in] mesh - the supporting mesh.
4836  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4837  *          field of interest lies on. If the field lies on all entities of the given
4838  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4839  *          using decrRef() as it is no more needed.  
4840  *  \param [in] glob - the global data storing profiles and localization.
4841  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4842  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4843  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4844  *  \throw If no field of \a this is lying on \a mesh.
4845  *  \throw If no field values of the given \a type are available.
4846  */
4847 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4848 {
4849   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4850   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4851   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4852   ret->setName(nasc.getName().c_str());
4853   return ret.retn();
4854 }
4855
4856 //= MEDFileField1TSWithoutSDA
4857
4858 /*!
4859  * Throws if a given value is not a valid (non-extended) relative dimension.
4860  *  \param [in] meshDimRelToMax - the relative dimension value.
4861  *  \throw If \a meshDimRelToMax > 0.
4862  */
4863 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4864 {
4865   if(meshDimRelToMax>0)
4866     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4867 }
4868
4869 /*!
4870  * Checks if elements of a given mesh are in the order suitable for writing 
4871  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4872  * vector describing types of elements and their number.
4873  *  \param [in] mesh - the mesh to check.
4874  *  \return std::vector<int> - a vector holding for each element type (1) item of
4875  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4876  *          These values are in full-interlace mode.
4877  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4878  */
4879 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4880 {
4881   if(!mesh)
4882     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4883   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4884   int nbOfTypes=geoTypes.size();
4885   std::vector<int> code(3*nbOfTypes);
4886   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4887   arr1->alloc(nbOfTypes,1);
4888   int *arrPtr=arr1->getPointer();
4889   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4890   for(int i=0;i<nbOfTypes;i++,it++)
4891     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4892   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4893   const int *arrPtr2=arr2->getConstPointer();
4894   int i=0;
4895   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4896     {
4897       int pos=arrPtr2[i];
4898       int nbCells=mesh->getNumberOfCellsWithType(*it);
4899       code[3*pos]=(int)(*it);
4900       code[3*pos+1]=nbCells;
4901       code[3*pos+2]=-1;//no profiles
4902     }
4903   std::vector<const DataArrayInt *> idsPerType;//no profiles
4904   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4905   if(da)
4906     {
4907       da->decrRef();
4908       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4909     }
4910   return code;
4911 }
4912
4913 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4914 {
4915   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4916 }
4917
4918 /*!
4919  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4920  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4921  * item of every of returned sequences refers to the _i_-th part of \a this field.
4922  * Thus all sequences returned by this method are of the same length equal to number
4923  * of different types of supporting entities.<br>
4924  * A field part can include sub-parts with several different spatial discretizations,
4925  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4926  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4927  * of a nested sequence corresponds to a type of spatial discretization.<br>
4928  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4929  * The overhead is due to selecting values into new instances of DataArrayDouble.
4930  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4931  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4932  *          not checked if \a mname == \c NULL).
4933  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4934  *          a field part is returned. 
4935  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4936  *          A field part can include sub-parts with several different spatial discretizations,
4937  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4938  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4939  *          This sequence is of the same length as \a types. 
4940  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4941  *          discretization. A profile name can be empty.
4942  *          Length of this and of nested sequences is the same as that of \a typesF.
4943  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4944  *          discretization. A localization name can be empty.
4945  *          Length of this and of nested sequences is the same as that of \a typesF.
4946  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4947  *          per each type of spatial discretization within one mesh entity type.
4948  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4949  *          Length of this and of nested sequences is the same as that of \a typesF.
4950  *  \throw If no field is lying on \a mname.
4951  */
4952 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
4953 {
4954   int meshId=0;
4955   if(!mname.empty())
4956     meshId=getMeshIdFromMeshName(mname);
4957   else
4958     if(_field_per_mesh.empty())
4959       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4960   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4961   int nbOfRet=ret0.size();
4962   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4963   for(int i=0;i<nbOfRet;i++)
4964     {
4965       const std::vector< std::pair<int,int> >& p=ret0[i];
4966       int nbOfRet1=p.size();
4967       ret[i].resize(nbOfRet1);
4968       for(int j=0;j<nbOfRet1;j++)
4969         {
4970           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4971           ret[i][j]=tmp;
4972         }
4973     }
4974   return ret;
4975 }
4976
4977 /*!
4978  * Returns a pointer to the underground DataArrayDouble instance. So the
4979  * caller should not decrRef() it. This method allows for a direct access to the field
4980  * values. This method is quite unusable if there is more than a nodal field or a cell
4981  * field on single geometric cell type. 
4982  *  \return DataArrayDouble * - the pointer to the field values array.
4983  */
4984 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
4985 {
4986   const DataArrayDouble *ret=_arr;
4987   if(ret)
4988     return const_cast<DataArrayDouble *>(ret);
4989   else
4990     return 0;
4991 }
4992
4993 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
4994 {
4995   return TYPE_STR;
4996 }
4997
4998 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
4999 {
5000   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5001   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5002   ret->deepCpyLeavesFrom(*this);
5003   const DataArrayDouble *arr(_arr);
5004   if(arr)
5005     {
5006       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
5007       ret->setArray(arr2);
5008     }
5009   return ret.retn();
5010 }
5011
5012 /*!
5013  * Returns a pointer to the underground DataArrayDouble instance. So the
5014  * caller should not decrRef() it. This method allows for a direct access to the field
5015  * values. This method is quite unusable if there is more than a nodal field or a cell
5016  * field on single geometric cell type. 
5017  *  \return DataArrayDouble * - the pointer to the field values array.
5018  */
5019 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
5020 {
5021   return getUndergroundDataArrayDouble();
5022 }
5023
5024 /*!
5025  * Returns a pointer to the underground DataArrayDouble instance and a
5026  * sequence describing parameters of a support of each part of \a this field. The
5027  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5028  * direct access to the field values. This method is intended for the field lying on one
5029  * mesh only.
5030  *  \param [in,out] entries - the sequence describing parameters of a support of each
5031  *         part of \a this field. Each item of this sequence consists of two parts. The
5032  *         first part describes a type of mesh entity and an id of discretization of a
5033  *         current field part. The second part describes a range of values [begin,end)
5034  *         within the returned array relating to the current field part.
5035  *  \return DataArrayDouble * - the pointer to the field values array.
5036  *  \throw If the number of underlying meshes is not equal to 1.
5037  *  \throw If no field values are available.
5038  *  \sa getUndergroundDataArray()
5039  */
5040 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5041 {
5042   if(_field_per_mesh.size()!=1)
5043     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5044   if(_field_per_mesh[0]==0)
5045     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5046   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5047   return getUndergroundDataArrayDouble();
5048 }
5049
5050 /*!
5051  * Returns a pointer to the underground DataArrayDouble instance and a
5052  * sequence describing parameters of a support of each part of \a this field. The
5053  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5054  * direct access to the field values. This method is intended for the field lying on one
5055  * mesh only.
5056  *  \param [in,out] entries - the sequence describing parameters of a support of each
5057  *         part of \a this field. Each item of this sequence consists of two parts. The
5058  *         first part describes a type of mesh entity and an id of discretization of a
5059  *         current field part. The second part describes a range of values [begin,end)
5060  *         within the returned array relating to the current field part.
5061  *  \return DataArrayDouble * - the pointer to the field values array.
5062  *  \throw If the number of underlying meshes is not equal to 1.
5063  *  \throw If no field values are available.
5064  *  \sa getUndergroundDataArray()
5065  */
5066 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5067 {
5068   return getUndergroundDataArrayDoubleExt(entries);
5069 }
5070
5071 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5072 {
5073   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
5074   arr->setInfoAndChangeNbOfCompo(infos);
5075 }
5076
5077 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5078 {
5079 }
5080
5081 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5082 {
5083   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5084   ret->deepCpyLeavesFrom(*this);
5085   return ret.retn();
5086 }
5087
5088 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
5089 {
5090   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5091   if((const DataArrayDouble *)_arr)
5092     ret->_arr=_arr->deepCpy();
5093   return ret.retn();
5094 }
5095
5096 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
5097 {
5098   if(!arr)
5099     {
5100       _nb_of_tuples_to_be_allocated=-1;
5101       _arr=0;
5102       return ;
5103     }
5104   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
5105   if(!arrC)
5106     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
5107   else
5108     _nb_of_tuples_to_be_allocated=-3;
5109   arrC->incrRef();
5110   _arr=arrC;
5111 }
5112
5113 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5114 {
5115   return DataArrayDouble::New();
5116 }
5117
5118 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
5119 {
5120   DataArrayDouble *ret=_arr;
5121   if(ret)
5122     return ret;
5123   _arr=DataArrayDouble::New();
5124   return _arr;
5125 }
5126
5127 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
5128 {
5129   return getOrCreateAndGetArrayDouble();
5130 }
5131
5132 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
5133 {
5134   const DataArrayDouble *ret=_arr;
5135   if(ret)
5136     return ret;
5137   DataArrayDouble *ret2=DataArrayDouble::New();
5138   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
5139   return ret2;
5140 }
5141
5142 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
5143 {
5144   return getOrCreateAndGetArrayDouble();
5145 }
5146
5147 //= MEDFileIntField1TSWithoutSDA
5148
5149 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5150 {
5151   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5152 }
5153
5154 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5155 {
5156 }
5157
5158 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5159                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5160 {
5161   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5162   arr->setInfoAndChangeNbOfCompo(infos);
5163 }
5164
5165 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5166 {
5167   return TYPE_STR;
5168 }
5169
5170 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5171 {
5172   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5173   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5174   ret->deepCpyLeavesFrom(*this);
5175   const DataArrayInt *arr(_arr);
5176   if(arr)
5177     {
5178       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
5179       ret->setArray(arr2);
5180     }
5181   return ret.retn();
5182 }
5183
5184 /*!
5185  * Returns a pointer to the underground DataArrayInt instance. So the
5186  * caller should not decrRef() it. This method allows for a direct access to the field
5187  * values. This method is quite unusable if there is more than a nodal field or a cell
5188  * field on single geometric cell type. 
5189  *  \return DataArrayInt * - the pointer to the field values array.
5190  */
5191 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5192 {
5193   return getUndergroundDataArrayInt();
5194 }
5195
5196 /*!
5197  * Returns a pointer to the underground DataArrayInt instance. So the
5198  * caller should not decrRef() it. This method allows for a direct access to the field
5199  * values. This method is quite unusable if there is more than a nodal field or a cell
5200  * field on single geometric cell type. 
5201  *  \return DataArrayInt * - the pointer to the field values array.
5202  */
5203 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5204 {
5205   const DataArrayInt *ret=_arr;
5206   if(ret)
5207     return const_cast<DataArrayInt *>(ret);
5208   else
5209     return 0;
5210 }
5211
5212 /*!
5213  * Returns a pointer to the underground DataArrayInt instance and a
5214  * sequence describing parameters of a support of each part of \a this field. The
5215  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5216  * direct access to the field values. This method is intended for the field lying on one
5217  * mesh only.
5218  *  \param [in,out] entries - the sequence describing parameters of a support of each
5219  *         part of \a this field. Each item of this sequence consists of two parts. The
5220  *         first part describes a type of mesh entity and an id of discretization of a
5221  *         current field part. The second part describes a range of values [begin,end)
5222  *         within the returned array relating to the current field part.
5223  *  \return DataArrayInt * - the pointer to the field values array.
5224  *  \throw If the number of underlying meshes is not equal to 1.
5225  *  \throw If no field values are available.
5226  *  \sa getUndergroundDataArray()
5227  */
5228 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5229 {
5230   return getUndergroundDataArrayIntExt(entries);
5231 }
5232
5233 /*!
5234  * Returns a pointer to the underground DataArrayInt instance and a
5235  * sequence describing parameters of a support of each part of \a this field. The
5236  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5237  * direct access to the field values. This method is intended for the field lying on one
5238  * mesh only.
5239  *  \param [in,out] entries - the sequence describing parameters of a support of each
5240  *         part of \a this field. Each item of this sequence consists of two parts. The
5241  *         first part describes a type of mesh entity and an id of discretization of a
5242  *         current field part. The second part describes a range of values [begin,end)
5243  *         within the returned array relating to the current field part.
5244  *  \return DataArrayInt * - the pointer to the field values array.
5245  *  \throw If the number of underlying meshes is not equal to 1.
5246  *  \throw If no field values are available.
5247  *  \sa getUndergroundDataArray()
5248  */
5249 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5250 {
5251   if(_field_per_mesh.size()!=1)
5252     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5253   if(_field_per_mesh[0]==0)
5254     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5255   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5256   return getUndergroundDataArrayInt();
5257 }
5258
5259 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5260 {
5261   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5262   ret->deepCpyLeavesFrom(*this);
5263   return ret.retn();
5264 }
5265
5266 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5267 {
5268   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5269   if((const DataArrayInt *)_arr)
5270     ret->_arr=_arr->deepCpy();
5271   return ret.retn();
5272 }
5273
5274 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5275 {
5276   if(!arr)
5277     {
5278       _nb_of_tuples_to_be_allocated=-1;
5279       _arr=0;
5280       return ;
5281     }
5282   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5283   if(!arrC)
5284     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5285   else
5286     _nb_of_tuples_to_be_allocated=-3;
5287   arrC->incrRef();
5288   _arr=arrC;
5289 }
5290
5291 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5292 {
5293   return DataArrayInt::New();
5294 }
5295
5296 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5297 {
5298   DataArrayInt *ret=_arr;
5299   if(ret)
5300     return ret;
5301   _arr=DataArrayInt::New();
5302   return _arr;
5303 }
5304
5305 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5306 {
5307   return getOrCreateAndGetArrayInt();
5308 }
5309
5310 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5311 {
5312   const DataArrayInt *ret=_arr;
5313   if(ret)
5314     return ret;
5315   DataArrayInt *ret2=DataArrayInt::New();
5316   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5317   return ret2;
5318 }
5319
5320 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5321 {
5322   return getOrCreateAndGetArrayInt();
5323 }
5324
5325 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5326 {
5327 }
5328
5329 //= MEDFileAnyTypeField1TS
5330
5331 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5332 {
5333   med_field_type typcha;
5334   //
5335   std::vector<std::string> infos;
5336   std::string dtunit,fieldName;
5337   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5338   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5339   switch(typcha)
5340   {
5341     case MED_FLOAT64:
5342       {
5343         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5344         break;
5345       }
5346     case MED_INT32:
5347       {
5348         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5349         break;
5350       }
5351     default:
5352       {
5353         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] !";
5354         throw INTERP_KERNEL::Exception(oss.str().c_str());
5355       }
5356   }
5357   ret->setDtUnit(dtunit.c_str());
5358   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5359   //
5360   med_int numdt,numit;
5361   med_float dt;
5362   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5363   ret->setTime(numdt,numit,dt);
5364   ret->_csit=1;
5365   if(loadAll)
5366     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5367   else
5368     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5369   return ret.retn();
5370 }
5371
5372 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5373 try:MEDFileFieldGlobsReal(fileName)
5374 {
5375   MEDFileUtilities::CheckFileForRead(fileName);
5376   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5377   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5378   loadGlobals(fid);
5379 }
5380 catch(INTERP_KERNEL::Exception& e)
5381 {
5382     throw e;
5383 }
5384
5385 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5386 {
5387   med_field_type typcha;
5388   std::vector<std::string> infos;
5389   std::string dtunit;
5390   int iii=-1;
5391   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5392   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5393   switch(typcha)
5394   {
5395     case MED_FLOAT64:
5396       {
5397         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5398         break;
5399       }
5400     case MED_INT32:
5401       {
5402         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5403         break;
5404       }
5405     default:
5406       {
5407         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] !";
5408         throw INTERP_KERNEL::Exception(oss.str().c_str());
5409       }
5410   }
5411   ret->setDtUnit(dtunit.c_str());
5412   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5413   //
5414   if(nbSteps<1)
5415     {
5416       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5417       throw INTERP_KERNEL::Exception(oss.str().c_str());
5418     }
5419   //
5420   med_int numdt,numit;
5421   med_float dt;
5422   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5423   ret->setTime(numdt,numit,dt);
5424   ret->_csit=1;
5425   if(loadAll)
5426     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5427   else
5428     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5429   return ret.retn();
5430 }
5431
5432 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5433 try:MEDFileFieldGlobsReal(fileName)
5434 {
5435   MEDFileUtilities::CheckFileForRead(fileName);
5436   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5437   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5438   loadGlobals(fid);
5439 }
5440 catch(INTERP_KERNEL::Exception& e)
5441 {
5442     throw e;
5443 }
5444
5445 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5446 {
5447   if(!c)
5448     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5449   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5450     {
5451       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5452       ret->setFileName(fileName);
5453       ret->_content=c; c->incrRef();
5454       return ret.retn();
5455     }
5456   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5457     {
5458       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5459       ret->setFileName(fileName);
5460       ret->_content=c; c->incrRef();
5461       return ret.retn();
5462     }
5463   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5464 }
5465
5466 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5467 {
5468   MEDFileUtilities::CheckFileForRead(fileName);
5469   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5470   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5471   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5472   ret->loadGlobals(fid);
5473   return ret.retn();
5474 }
5475
5476 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5477 {
5478   MEDFileUtilities::CheckFileForRead(fileName);
5479   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5480   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5481   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5482   ret->loadGlobals(fid);
5483   return ret.retn();
5484 }
5485
5486 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5487 {
5488   MEDFileUtilities::CheckFileForRead(fileName);
5489   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5490   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5491   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5492   ret->loadGlobals(fid);
5493   return ret.retn();
5494 }
5495
5496 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5497 {
5498   med_field_type typcha;
5499   std::vector<std::string> infos;
5500   std::string dtunit;
5501   int iii=-1;
5502   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5503   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5504   switch(typcha)
5505   {
5506     case MED_FLOAT64:
5507       {
5508         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5509         break;
5510       }
5511     case MED_INT32:
5512       {
5513         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5514         break;
5515       }
5516     default:
5517       {
5518         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] !";
5519         throw INTERP_KERNEL::Exception(oss.str().c_str());
5520       }
5521   }
5522   ret->setDtUnit(dtunit.c_str());
5523   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5524   //
5525   bool found=false;
5526   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5527   for(int i=0;i<nbOfStep2 && !found;i++)
5528     {
5529       med_int numdt,numit;
5530       med_float dt;
5531       MEDfieldComputingStepInfo(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt);
5532       if(numdt==iteration && numit==order)
5533         {
5534           found=true;
5535           ret->_csit=i+1;
5536         }
5537       else
5538         dtits[i]=std::pair<int,int>(numdt,numit);
5539     }
5540   if(!found)
5541     {
5542       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5543       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5544         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5545       throw INTERP_KERNEL::Exception(oss.str().c_str());
5546     }
5547   if(loadAll)
5548     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5549   else
5550     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms);
5551   return ret.retn();
5552 }
5553
5554 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5555 try:MEDFileFieldGlobsReal(fileName)
5556 {
5557   MEDFileUtilities::CheckFileForRead(fileName);
5558   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5559   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5560   loadGlobals(fid);
5561 }
5562 catch(INTERP_KERNEL::Exception& e)
5563 {
5564     throw e;
5565 }
5566
5567 /*!
5568  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5569  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5570  *
5571  * \warning this is a shallow copy constructor
5572  */
5573 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5574 {
5575   if(!shallowCopyOfContent)
5576     {
5577       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5578       otherPtr->incrRef();
5579       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5580     }
5581   else
5582     {
5583       _content=other.shallowCpy();
5584     }
5585 }
5586
5587 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)
5588 {
5589   if(checkFieldId)
5590     {
5591       int nbFields=MEDnField(fid);
5592       if(fieldIdCFormat>=nbFields)
5593         {
5594           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5595           throw INTERP_KERNEL::Exception(oss.str().c_str());
5596         }
5597     }
5598   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5599   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5600   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5601   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5602   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5603   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5604   med_bool localMesh;
5605   int nbOfStep;
5606   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5607   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5608   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5609   infos.clear(); infos.resize(ncomp);
5610   for(int j=0;j<ncomp;j++)
5611     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5612   return nbOfStep;
5613 }
5614
5615 /*!
5616  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5617  * 
5618  * \param [out]
5619  * \return in case of success the number of time steps available for the field with name \a fieldName.
5620  */
5621 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)
5622 {
5623   int nbFields=MEDnField(fid);
5624   bool found=false;
5625   std::vector<std::string> fns(nbFields);
5626   int nbOfStep2=-1;
5627   for(int i=0;i<nbFields && !found;i++)
5628     {
5629       std::string tmp;
5630       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5631       fns[i]=tmp;
5632       found=(tmp==fieldName);
5633       if(found)
5634         posCFormat=i;
5635     }
5636   if(!found)
5637     {
5638       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5639       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5640         oss << "\"" << *it << "\" ";
5641       throw INTERP_KERNEL::Exception(oss.str().c_str());
5642     }
5643   return nbOfStep2;
5644 }
5645
5646 /*!
5647  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5648  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5649  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5650  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5651  * to keep a valid instance.
5652  * 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.
5653  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5654  * 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.
5655  *
5656  * \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.
5657  * \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.
5658  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5659  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5660  * \param [in] newLocName is the new localization name.
5661  * \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.
5662  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5663  */
5664 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5665 {
5666   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5667   std::string oldPflName=disc->getProfile();
5668   std::vector<std::string> vv=getPflsReallyUsedMulti();
5669   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5670   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5671     {
5672       disc->setProfile(newPflName);
5673       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5674       pfl->setName(newPflName);
5675     }
5676   else
5677     {
5678       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5679       throw INTERP_KERNEL::Exception(oss.str().c_str());
5680     }
5681 }
5682
5683 /*!
5684  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5685  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5686  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5687  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5688  * to keep a valid instance.
5689  * 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.
5690  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5691  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5692  * 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.
5693  *
5694  * \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.
5695  * \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.
5696  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5697  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5698  * \param [in] newLocName is the new localization name.
5699  * \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.
5700  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5701  */
5702 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5703 {
5704   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5705   std::string oldLocName=disc->getLocalization();
5706   std::vector<std::string> vv=getLocsReallyUsedMulti();
5707   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5708   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5709     {
5710       disc->setLocalization(newLocName);
5711       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5712       loc.setName(newLocName);
5713     }
5714   else
5715     {
5716       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5717       throw INTERP_KERNEL::Exception(oss.str().c_str());
5718     }
5719 }
5720
5721 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5722 {
5723   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5724   if(!ret)
5725     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5726   return ret;
5727 }
5728
5729 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5730 {
5731   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5732   if(!ret)
5733     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5734   return ret;
5735 }
5736
5737 /*!
5738  * Writes \a this field into a MED file specified by its name.
5739  *  \param [in] fileName - the MED file name.
5740  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5741  * - 2 - erase; an existing file is removed.
5742  * - 1 - append; same data should not be present in an existing file.
5743  * - 0 - overwrite; same data present in an existing file is overwritten.
5744  *  \throw If the field name is not set.
5745  *  \throw If no field data is set.
5746  *  \throw If \a mode == 1 and the same data is present in an existing file.
5747  */
5748 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5749 {
5750   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5751   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5752   writeLL(fid);
5753 }
5754
5755 /*!
5756  * This method alloc the arrays and load potentially huge arrays contained in this field.
5757  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5758  * This method can be also called to refresh or reinit values from a file.
5759  * 
5760  * \throw If the fileName is not set or points to a non readable MED file.
5761  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5762  */
5763 void MEDFileAnyTypeField1TS::loadArrays()
5764 {
5765   if(getFileName().empty())
5766     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5767   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5768   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5769 }
5770
5771 /*!
5772  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5773  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5774  * this method does not throw if \a this does not come from file read.
5775  * 
5776  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5777  */
5778 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5779 {
5780   if(!getFileName().empty())
5781     {
5782       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5783       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5784     }
5785 }
5786
5787 /*!
5788  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5789  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5790  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5791  * 
5792  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5793  */
5794 void MEDFileAnyTypeField1TS::unloadArrays()
5795 {
5796   contentNotNullBase()->unloadArrays();
5797 }
5798
5799 /*!
5800  * 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.
5801  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5802  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5803  * 
5804  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5805  */
5806 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5807 {
5808   if(!getFileName().empty())
5809     contentNotNullBase()->unloadArrays();
5810 }
5811
5812 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5813 {
5814   int nbComp=getNumberOfComponents();
5815   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5816   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5817   for(int i=0;i<nbComp;i++)
5818     {
5819       std::string info=getInfo()[i];
5820       std::string c,u;
5821       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5822       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5823       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5824     }
5825   if(getName().empty())
5826     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5827   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5828   writeGlobals(fid,*this);
5829   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5830 }
5831
5832 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5833 {
5834   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5835 }
5836
5837 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5838 {
5839   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5840   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5841   return ret;
5842 }
5843
5844 /*!
5845  * Returns a string describing \a this field. This string is outputted 
5846  * by \c print Python command.
5847  */
5848 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5849 {
5850   std::ostringstream oss;
5851   contentNotNullBase()->simpleRepr(0,oss,-1);
5852   simpleReprGlobs(oss);
5853   return oss.str();
5854 }
5855
5856 /*!
5857  * This method returns all profiles whose name is non empty used.
5858  * \b WARNING If profile is used several times it will be reported \b only \b once.
5859  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5860  */
5861 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5862 {
5863   return contentNotNullBase()->getPflsReallyUsed2();
5864 }
5865
5866 /*!
5867  * This method returns all localizations whose name is non empty used.
5868  * \b WARNING If localization is used several times it will be reported \b only \b once.
5869  */
5870 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5871 {
5872   return contentNotNullBase()->getLocsReallyUsed2();
5873 }
5874
5875 /*!
5876  * This method returns all profiles whose name is non empty used.
5877  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5878  */
5879 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5880 {
5881   return contentNotNullBase()->getPflsReallyUsedMulti2();
5882 }
5883
5884 /*!
5885  * This method returns all localizations whose name is non empty used.
5886  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5887  */
5888 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5889 {
5890   return contentNotNullBase()->getLocsReallyUsedMulti2();
5891 }
5892
5893 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5894 {
5895   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5896 }
5897
5898 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5899 {
5900   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5901 }
5902
5903 int MEDFileAnyTypeField1TS::getDimension() const
5904 {
5905   return contentNotNullBase()->getDimension();
5906 }
5907
5908 int MEDFileAnyTypeField1TS::getIteration() const
5909 {
5910   return contentNotNullBase()->getIteration();
5911 }
5912
5913 int MEDFileAnyTypeField1TS::getOrder() const
5914 {
5915   return contentNotNullBase()->getOrder();
5916 }
5917
5918 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5919 {
5920   return contentNotNullBase()->getTime(iteration,order);
5921 }
5922
5923 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5924 {
5925   contentNotNullBase()->setTime(iteration,order,val);
5926 }
5927
5928 std::string MEDFileAnyTypeField1TS::getName() const
5929 {
5930   return contentNotNullBase()->getName();
5931 }
5932
5933 void MEDFileAnyTypeField1TS::setName(const std::string& name)
5934 {
5935   contentNotNullBase()->setName(name);
5936 }
5937
5938 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5939 {
5940   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5941 }
5942
5943 std::string MEDFileAnyTypeField1TS::getDtUnit() const
5944 {
5945   return contentNotNullBase()->getDtUnit();
5946 }
5947
5948 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
5949 {
5950   contentNotNullBase()->setDtUnit(dtUnit);
5951 }
5952
5953 std::string MEDFileAnyTypeField1TS::getMeshName() const
5954 {
5955   return contentNotNullBase()->getMeshName();
5956 }
5957
5958 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
5959 {
5960   contentNotNullBase()->setMeshName(newMeshName);
5961 }
5962
5963 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
5964 {
5965   return contentNotNullBase()->changeMeshNames(modifTab);
5966 }
5967
5968 int MEDFileAnyTypeField1TS::getMeshIteration() const
5969 {
5970   return contentNotNullBase()->getMeshIteration();
5971 }
5972
5973 int MEDFileAnyTypeField1TS::getMeshOrder() const
5974 {
5975   return contentNotNullBase()->getMeshOrder();
5976 }
5977
5978 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5979 {
5980   return contentNotNullBase()->getNumberOfComponents();
5981 }
5982
5983 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5984 {
5985   return contentNotNullBase()->isDealingTS(iteration,order);
5986 }
5987
5988 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5989 {
5990   return contentNotNullBase()->getDtIt();
5991 }
5992
5993 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5994 {
5995   contentNotNullBase()->fillIteration(p);
5996 }
5997
5998 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
5999 {
6000   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6001 }
6002
6003 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6004 {
6005   contentNotNullBase()->setInfo(infos);
6006 }
6007
6008 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6009 {
6010   return contentNotNullBase()->getInfo();
6011 }
6012 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6013 {
6014   return contentNotNullBase()->getInfo();
6015 }
6016
6017 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6018 {
6019   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6020 }
6021
6022 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6023 {
6024   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6025 }
6026
6027 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6028 {
6029   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6030 }
6031
6032 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6033 {
6034   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6035 }
6036
6037 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6038 {
6039   return contentNotNullBase()->getTypesOfFieldAvailable();
6040 }
6041
6042 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,
6043                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6044 {
6045   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6046 }
6047
6048 /*!
6049  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6050  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6051  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6052  */
6053 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6054 {
6055   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6056   if(!content)
6057     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6058   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6059   std::size_t sz(contentsSplit.size());
6060   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6061   for(std::size_t i=0;i<sz;i++)
6062     {
6063       ret[i]=shallowCpy();
6064       ret[i]->_content=contentsSplit[i];
6065     }
6066   return ret;
6067 }
6068
6069 /*!
6070  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6071  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6072  */
6073 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6074 {
6075   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6076   if(!content)
6077     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6078   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6079   std::size_t sz(contentsSplit.size());
6080   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6081   for(std::size_t i=0;i<sz;i++)
6082     {
6083       ret[i]=shallowCpy();
6084       ret[i]->_content=contentsSplit[i];
6085     }
6086   return ret;
6087 }
6088
6089 /*!
6090  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6091  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6092  */
6093 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6094 {
6095   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6096   if(!content)
6097     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6098   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6099   std::size_t sz(contentsSplit.size());
6100   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6101   for(std::size_t i=0;i<sz;i++)
6102     {
6103       ret[i]=shallowCpy();
6104       ret[i]->_content=contentsSplit[i];
6105     }
6106   return ret;
6107 }
6108
6109 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
6110 {
6111   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
6112   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6113     ret->_content=_content->deepCpy();
6114   ret->deepCpyGlobs(*this);
6115   return ret.retn();
6116 }
6117
6118 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6119 {
6120   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6121 }
6122
6123 //= MEDFileField1TS
6124
6125 /*!
6126  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6127  * the first field that has been read from a specified MED file.
6128  *  \param [in] fileName - the name of the MED file to read.
6129  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6130  *          is to delete this field using decrRef() as it is no more needed.
6131  *  \throw If reading the file fails.
6132  */
6133 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6134 {
6135   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
6136   ret->contentNotNull();
6137   return ret.retn();
6138 }
6139
6140 /*!
6141  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6142  * a given field that has been read from a specified MED file.
6143  *  \param [in] fileName - the name of the MED file to read.
6144  *  \param [in] fieldName - the name of the field to read.
6145  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6146  *          is to delete this field using decrRef() as it is no more needed.
6147  *  \throw If reading the file fails.
6148  *  \throw If there is no field named \a fieldName in the file.
6149  */
6150 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6151 {
6152   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
6153   ret->contentNotNull();
6154   return ret.retn();
6155 }
6156
6157 /*!
6158  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6159  * a given field that has been read from a specified MED file.
6160  *  \param [in] fileName - the name of the MED file to read.
6161  *  \param [in] fieldName - the name of the field to read.
6162  *  \param [in] iteration - the iteration number of a required time step.
6163  *  \param [in] order - the iteration order number of required time step.
6164  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6165  *          is to delete this field using decrRef() as it is no more needed.
6166  *  \throw If reading the file fails.
6167  *  \throw If there is no field named \a fieldName in the file.
6168  *  \throw If the required time step is missing from the file.
6169  */
6170 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6171 {
6172   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6173   ret->contentNotNull();
6174   return ret.retn();
6175 }
6176
6177 /*!
6178  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6179  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6180  *
6181  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6182  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6183  * \warning this is a shallow copy constructor
6184  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6185  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6186  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6187  *          is to delete this field using decrRef() as it is no more needed.
6188  */
6189 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6190 {
6191   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6192   ret->contentNotNull();
6193   return ret.retn();
6194 }
6195
6196 /*!
6197  * Returns a new empty instance of MEDFileField1TS.
6198  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6199  *          is to delete this field using decrRef() as it is no more needed.
6200  */
6201 MEDFileField1TS *MEDFileField1TS::New()
6202 {
6203   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
6204   ret->contentNotNull();
6205   return ret.retn();
6206 }
6207
6208 /*!
6209  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6210  * following the given input policy.
6211  *
6212  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6213  *                            By default (true) the globals are deeply copied.
6214  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6215  */
6216 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6217 {
6218   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
6219   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6220   if(content)
6221     {
6222       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6223       if(!contc)
6224         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6225       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6226       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6227     }
6228   else
6229     ret=MEDFileIntField1TS::New();
6230   if(isDeepCpyGlobs)
6231     ret->deepCpyGlobs(*this);
6232   else
6233     ret->shallowCpyGlobs(*this);
6234   return ret.retn();
6235 }
6236
6237 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6238 {
6239   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6240   if(!pt)
6241     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6242   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6243   if(!ret)
6244     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 !");
6245   return ret;
6246 }
6247
6248 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6249 {
6250   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6251   if(!pt)
6252     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6253   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6254   if(!ret)
6255     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 !");
6256   return ret;
6257 }
6258
6259 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6260 {
6261   if(!f)
6262     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6263   if(!((DataArray*)arr))
6264     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6265   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6266   if(!arrOutC)
6267     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6268   f->setArray(arrOutC);
6269 }
6270
6271 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6272 {
6273   if(!((DataArray*)arr))
6274     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6275   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6276   if(!arrOutC)
6277     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6278   arrOutC->incrRef();
6279   return arrOutC;
6280 }
6281
6282 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6283 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6284 {
6285 }
6286 catch(INTERP_KERNEL::Exception& e)
6287 { throw e; }
6288
6289 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6290 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6291 {
6292 }
6293 catch(INTERP_KERNEL::Exception& e)
6294 { throw e; }
6295
6296 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6297 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6298 {
6299 }
6300 catch(INTERP_KERNEL::Exception& e)
6301 { throw e; }
6302
6303 /*!
6304  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6305  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6306  *
6307  * \warning this is a shallow copy constructor
6308  */
6309 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6310 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6311 {
6312 }
6313 catch(INTERP_KERNEL::Exception& e)
6314 { throw e; }
6315
6316 MEDFileField1TS::MEDFileField1TS()
6317 {
6318   _content=new MEDFileField1TSWithoutSDA;
6319 }
6320
6321 /*!
6322  * Returns a new MEDCouplingFieldDouble of a given type lying on
6323  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6324  * has not been constructed via file reading, an exception is thrown.
6325  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6326  *  \param [in] type - a spatial discretization of interest.
6327  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6328  *  \param [in] renumPol - specifies how to permute values of the result field according to
6329  *          the optional numbers of cells and nodes, if any. The valid values are
6330  *          - 0 - do not permute.
6331  *          - 1 - permute cells.
6332  *          - 2 - permute nodes.
6333  *          - 3 - permute cells and nodes.
6334  *
6335  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6336  *          caller is to delete this field using decrRef() as it is no more needed. 
6337  *  \throw If \a this field has not been constructed via file reading.
6338  *  \throw If the MED file is not readable.
6339  *  \throw If there is no mesh in the MED file.
6340  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6341  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6342  *  \sa getFieldOnMeshAtLevel()
6343  */
6344 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6345 {
6346   if(getFileName().empty())
6347     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6348   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6349   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6350   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6351   return ret.retn();
6352 }
6353
6354 /*!
6355  * Returns a new MEDCouplingFieldDouble of a given type lying on
6356  * the top level cells of the first mesh in MED file. If \a this field 
6357  * has not been constructed via file reading, an exception is thrown.
6358  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6359  *  \param [in] type - a spatial discretization of interest.
6360  *  \param [in] renumPol - specifies how to permute values of the result field according to
6361  *          the optional numbers of cells and nodes, if any. The valid values are
6362  *          - 0 - do not permute.
6363  *          - 1 - permute cells.
6364  *          - 2 - permute nodes.
6365  *          - 3 - permute cells and nodes.
6366  *
6367  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6368  *          caller is to delete this field using decrRef() as it is no more needed. 
6369  *  \throw If \a this field has not been constructed via file reading.
6370  *  \throw If the MED file is not readable.
6371  *  \throw If there is no mesh in the MED file.
6372  *  \throw If no field values of the given \a type.
6373  *  \throw If no field values lying on the top level support.
6374  *  \sa getFieldAtLevel()
6375  */
6376 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6377 {
6378   if(getFileName().empty())
6379     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6380   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6381   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6382   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6383   return ret.retn();
6384 }
6385
6386 /*!
6387  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6388  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6389  *  \param [in] type - a spatial discretization of the new field.
6390  *  \param [in] mesh - the supporting mesh.
6391  *  \param [in] renumPol - specifies how to permute values of the result field according to
6392  *          the optional numbers of cells and nodes, if any. The valid values are
6393  *          - 0 - do not permute.
6394  *          - 1 - permute cells.
6395  *          - 2 - permute nodes.
6396  *          - 3 - permute cells and nodes.
6397  *
6398  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6399  *          caller is to delete this field using decrRef() as it is no more needed. 
6400  *  \throw If no field of \a this is lying on \a mesh.
6401  *  \throw If the mesh is empty.
6402  *  \throw If no field values of the given \a type are available.
6403  *  \sa getFieldAtLevel()
6404  *  \sa getFieldOnMeshAtLevel() 
6405  */
6406 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6407 {
6408   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6409   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6410   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6411   return ret.retn();
6412 }
6413
6414 /*!
6415  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6416  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6417  *  \param [in] type - a spatial discretization of interest.
6418  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6419  *  \param [in] mesh - the supporting mesh.
6420  *  \param [in] renumPol - specifies how to permute values of the result field according to
6421  *          the optional numbers of cells and nodes, if any. The valid values are
6422  *          - 0 - do not permute.
6423  *          - 1 - permute cells.
6424  *          - 2 - permute nodes.
6425  *          - 3 - permute cells and nodes.
6426  *
6427  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6428  *          caller is to delete this field using decrRef() as it is no more needed. 
6429  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6430  *  \throw If no field of \a this is lying on \a mesh.
6431  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6432  *  \sa getFieldAtLevel()
6433  *  \sa getFieldOnMeshAtLevel() 
6434  */
6435 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6436 {
6437   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6438   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6439   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6440   return ret.retn();
6441 }
6442
6443 /*!
6444  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6445  * This method is called "Old" because in MED3 norm a field has only one meshName
6446  * attached, so this method is for readers of MED2 files. If \a this field 
6447  * has not been constructed via file reading, an exception is thrown.
6448  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6449  *  \param [in] type - a spatial discretization of interest.
6450  *  \param [in] mName - a name of the supporting mesh.
6451  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6452  *  \param [in] renumPol - specifies how to permute values of the result field according to
6453  *          the optional numbers of cells and nodes, if any. The valid values are
6454  *          - 0 - do not permute.
6455  *          - 1 - permute cells.
6456  *          - 2 - permute nodes.
6457  *          - 3 - permute cells and nodes.
6458  *
6459  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6460  *          caller is to delete this field using decrRef() as it is no more needed. 
6461  *  \throw If the MED file is not readable.
6462  *  \throw If there is no mesh named \a mName in the MED file.
6463  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6464  *  \throw If \a this field has not been constructed via file reading.
6465  *  \throw If no field of \a this is lying on the mesh named \a mName.
6466  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6467  *  \sa getFieldAtLevel()
6468  */
6469 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6470 {
6471   if(getFileName().empty())
6472     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6473   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6474   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6475   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6476   return ret.retn();
6477 }
6478
6479 /*!
6480  * Returns values and a profile of the field of a given type lying on a given support.
6481  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6482  *  \param [in] type - a spatial discretization of the field.
6483  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6484  *  \param [in] mesh - the supporting mesh.
6485  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6486  *          field of interest lies on. If the field lies on all entities of the given
6487  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6488  *          using decrRef() as it is no more needed.  
6489  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6490  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6491  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6492  *  \throw If no field of \a this is lying on \a mesh.
6493  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6494  */
6495 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6496 {
6497   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6498   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6499 }
6500
6501 /*!
6502  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6503  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6504  * "Sort By Type"), if not, an exception is thrown. 
6505  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6506  *  \param [in] field - the field to add to \a this.
6507  *  \throw If the name of \a field is empty.
6508  *  \throw If the data array of \a field is not set.
6509  *  \throw If the data array is already allocated but has different number of components
6510  *         than \a field.
6511  *  \throw If the underlying mesh of \a field has no name.
6512  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6513  */
6514 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6515 {
6516   setFileName("");
6517   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6518 }
6519
6520 /*!
6521  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6522  * can be an aggregation of several MEDCouplingFieldDouble instances.
6523  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6524  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6525  * and \a profile.
6526  *
6527  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6528  * A new profile is added only if no equal profile is missing.
6529  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6530  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6531  *  \param [in] mesh - the supporting mesh of \a field.
6532  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6533  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6534  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6535  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6536  *  \throw If the data array of \a field is not set.
6537  *  \throw If the data array of \a this is already allocated but has different number of
6538  *         components than \a field.
6539  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6540  *  \sa setFieldNoProfileSBT()
6541  */
6542 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6543 {
6544   setFileName("");
6545   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6546 }
6547
6548 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6549 {
6550   return new MEDFileField1TS(*this);
6551 }
6552
6553 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6554 {
6555   return contentNotNull()->getUndergroundDataArrayDouble();
6556 }
6557
6558 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6559 {
6560   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6561 }
6562
6563 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6564                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6565 {
6566   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6567 }
6568
6569 //= MEDFileIntField1TS
6570
6571 MEDFileIntField1TS *MEDFileIntField1TS::New()
6572 {
6573   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6574   ret->contentNotNull();
6575   return ret.retn();
6576 }
6577
6578 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6579 {
6580   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6581   ret->contentNotNull();
6582   return ret.retn();
6583 }
6584
6585 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6586 {
6587   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6588   ret->contentNotNull();
6589   return ret.retn();
6590 }
6591
6592 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6593 {
6594   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6595   ret->contentNotNull();
6596   return ret.retn();
6597 }
6598
6599 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6600 {
6601   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6602   ret->contentNotNull();
6603   return ret.retn();
6604 }
6605
6606 MEDFileIntField1TS::MEDFileIntField1TS()
6607 {
6608   _content=new MEDFileIntField1TSWithoutSDA;
6609 }
6610
6611 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6612 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6613 {
6614 }
6615 catch(INTERP_KERNEL::Exception& e)
6616 { throw e; }
6617
6618 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6619 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6620 {
6621 }
6622 catch(INTERP_KERNEL::Exception& e)
6623 { throw e; }
6624
6625 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6626 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6627 {
6628 }
6629 catch(INTERP_KERNEL::Exception& e)
6630 { throw e; }
6631
6632 /*!
6633  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6634  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6635  *
6636  * \warning this is a shallow copy constructor
6637  */
6638 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6639 {
6640 }
6641
6642 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6643 {
6644   return new MEDFileIntField1TS(*this);
6645 }
6646
6647 /*!
6648  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6649  * following the given input policy.
6650  *
6651  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6652  *                            By default (true) the globals are deeply copied.
6653  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6654  */
6655 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6656 {
6657   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6658   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6659   if(content)
6660     {
6661       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6662       if(!contc)
6663         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6664       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6665       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6666     }
6667   else
6668     ret=MEDFileField1TS::New();
6669   if(isDeepCpyGlobs)
6670     ret->deepCpyGlobs(*this);
6671   else
6672     ret->shallowCpyGlobs(*this);
6673   return ret.retn();
6674 }
6675
6676 /*!
6677  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6678  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6679  * "Sort By Type"), if not, an exception is thrown. 
6680  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6681  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6682  *  \param [in] arrOfVals - the values of the field \a field used.
6683  *  \throw If the name of \a field is empty.
6684  *  \throw If the data array of \a field is not set.
6685  *  \throw If the data array is already allocated but has different number of components
6686  *         than \a field.
6687  *  \throw If the underlying mesh of \a field has no name.
6688  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6689  */
6690 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6691 {
6692   setFileName("");
6693   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6694 }
6695
6696 /*!
6697  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6698  * can be an aggregation of several MEDCouplingFieldDouble instances.
6699  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6700  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6701  * and \a profile.
6702  *
6703  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6704  * A new profile is added only if no equal profile is missing.
6705  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6706  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6707  *  \param [in] arrOfVals - the values of the field \a field used.
6708  *  \param [in] mesh - the supporting mesh of \a field.
6709  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6710  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6711  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6712  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6713  *  \throw If the data array of \a field is not set.
6714  *  \throw If the data array of \a this is already allocated but has different number of
6715  *         components than \a field.
6716  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6717  *  \sa setFieldNoProfileSBT()
6718  */
6719 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6720 {
6721   setFileName("");
6722   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6723 }
6724
6725 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6726 {
6727   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6728   if(!pt)
6729     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6730   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6731   if(!ret)
6732     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 !");
6733   return ret;
6734 }
6735
6736 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6737 {
6738   if(getFileName().empty())
6739     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6740   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6741   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6742   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6743   if(!arrOutC)
6744     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6745   arrOut=arrOutC;
6746   arrOut->incrRef();  // arrOut2 dies at the end of the func
6747   return ret.retn();
6748 }
6749
6750 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6751 {
6752   if(!((DataArray *)arr))
6753     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6754   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6755   if(!arrC)
6756     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6757   arrC->incrRef();
6758   return arrC;
6759 }
6760
6761 /*!
6762  * Returns a new MEDCouplingFieldDouble of a given type lying on
6763  * the top level cells of the first mesh in MED file. If \a this field 
6764  * has not been constructed via file reading, an exception is thrown.
6765  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6766  *  \param [in] type - a spatial discretization of interest.
6767  *  \param [out] arrOut - the DataArrayInt containing values of field.
6768  *  \param [in] renumPol - specifies how to permute values of the result field according to
6769  *          the optional numbers of cells and nodes, if any. The valid values are
6770  *          - 0 - do not permute.
6771  *          - 1 - permute cells.
6772  *          - 2 - permute nodes.
6773  *          - 3 - permute cells and nodes.
6774  *
6775  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6776  *          caller is to delete this field using decrRef() as it is no more needed. 
6777  *  \throw If \a this field has not been constructed via file reading.
6778  *  \throw If the MED file is not readable.
6779  *  \throw If there is no mesh in the MED file.
6780  *  \throw If no field values of the given \a type.
6781  *  \throw If no field values lying on the top level support.
6782  *  \sa getFieldAtLevel()
6783  */
6784 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6785 {
6786   if(getFileName().empty())
6787     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6788   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6789   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6790   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6791   return ret.retn();
6792 }
6793
6794 /*!
6795  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6796  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6797  *  \param [in] type - a spatial discretization of the new field.
6798  *  \param [in] mesh - the supporting mesh.
6799  *  \param [out] arrOut - the DataArrayInt containing values of field.
6800  *  \param [in] renumPol - specifies how to permute values of the result field according to
6801  *          the optional numbers of cells and nodes, if any. The valid values are
6802  *          - 0 - do not permute.
6803  *          - 1 - permute cells.
6804  *          - 2 - permute nodes.
6805  *          - 3 - permute cells and nodes.
6806  *
6807  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6808  *          caller is to delete this field using decrRef() as it is no more needed. 
6809  *  \throw If no field of \a this is lying on \a mesh.
6810  *  \throw If the mesh is empty.
6811  *  \throw If no field values of the given \a type are available.
6812  *  \sa getFieldAtLevel()
6813  *  \sa getFieldOnMeshAtLevel() 
6814  */
6815 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6816 {
6817   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6818   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6819   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6820   return ret.retn();
6821 }
6822
6823 /*!
6824  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6825  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6826  *  \param [in] type - a spatial discretization of interest.
6827  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6828  *  \param [out] arrOut - the DataArrayInt containing values of field.
6829  *  \param [in] mesh - the supporting mesh.
6830  *  \param [in] renumPol - specifies how to permute values of the result field according to
6831  *          the optional numbers of cells and nodes, if any. The valid values are
6832  *          - 0 - do not permute.
6833  *          - 1 - permute cells.
6834  *          - 2 - permute nodes.
6835  *          - 3 - permute cells and nodes.
6836  *
6837  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6838  *          caller is to delete this field using decrRef() as it is no more needed. 
6839  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6840  *  \throw If no field of \a this is lying on \a mesh.
6841  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6842  *  \sa getFieldAtLevel()
6843  *  \sa getFieldOnMeshAtLevel() 
6844  */
6845 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6846 {
6847   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6848   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6849   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6850   return ret.retn();
6851 }
6852
6853 /*!
6854  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6855  * This method is called "Old" because in MED3 norm a field has only one meshName
6856  * attached, so this method is for readers of MED2 files. If \a this field 
6857  * has not been constructed via file reading, an exception is thrown.
6858  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6859  *  \param [in] type - a spatial discretization of interest.
6860  *  \param [in] mName - a name of the supporting mesh.
6861  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6862  *  \param [out] arrOut - the DataArrayInt containing values of field.
6863  *  \param [in] renumPol - specifies how to permute values of the result field according to
6864  *          the optional numbers of cells and nodes, if any. The valid values are
6865  *          - 0 - do not permute.
6866  *          - 1 - permute cells.
6867  *          - 2 - permute nodes.
6868  *          - 3 - permute cells and nodes.
6869  *
6870  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6871  *          caller is to delete this field using decrRef() as it is no more needed. 
6872  *  \throw If the MED file is not readable.
6873  *  \throw If there is no mesh named \a mName in the MED file.
6874  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6875  *  \throw If \a this field has not been constructed via file reading.
6876  *  \throw If no field of \a this is lying on the mesh named \a mName.
6877  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6878  *  \sa getFieldAtLevel()
6879  */
6880 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6881 {
6882   if(getFileName().empty())
6883     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6884   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6885   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6886   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6887   return ret.retn();
6888 }
6889
6890 /*!
6891  * Returns values and a profile of the field of a given type lying on a given support.
6892  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6893  *  \param [in] type - a spatial discretization of the field.
6894  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6895  *  \param [in] mesh - the supporting mesh.
6896  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6897  *          field of interest lies on. If the field lies on all entities of the given
6898  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6899  *          using decrRef() as it is no more needed.  
6900  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6901  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6902  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6903  *  \throw If no field of \a this is lying on \a mesh.
6904  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6905  */
6906 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6907 {
6908   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6909   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6910 }
6911
6912 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
6913 {
6914   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6915   if(!pt)
6916     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6917   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6918   if(!ret)
6919     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 !");
6920   return ret;
6921 }
6922
6923 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
6924 {
6925   return contentNotNull()->getUndergroundDataArrayInt();
6926 }
6927
6928 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6929
6930 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6931 {
6932 }
6933
6934 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
6935 {
6936 }
6937
6938 /*!
6939  * \param [in] fieldId field id in C mode
6940  */
6941 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
6942 {
6943   med_field_type typcha;
6944   std::string dtunitOut;
6945   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6946   setDtUnit(dtunitOut.c_str());
6947   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms);
6948 }
6949
6950 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
6951 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6952 {
6953   setDtUnit(dtunit.c_str());
6954   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms);
6955 }
6956 catch(INTERP_KERNEL::Exception& e)
6957 {
6958     throw e;
6959 }
6960
6961 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
6962 {
6963   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
6964   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6965     ret+=(*it).capacity();
6966   return ret;
6967 }
6968
6969 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
6970 {
6971   std::vector<const BigMemoryObject *> ret;
6972   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6973     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
6974   return ret;
6975 }
6976
6977 /*!
6978  * 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
6979  * NULL.
6980  */
6981 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
6982 {
6983   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6984   ret->setInfo(_infos);
6985   int sz=(int)_time_steps.size();
6986   for(const int *id=startIds;id!=endIds;id++)
6987     {
6988       if(*id>=0 && *id<sz)
6989         {
6990           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6991           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6992           if(tse)
6993             {
6994               tse->incrRef();
6995               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6996             }
6997           ret->pushBackTimeStep(tse2);
6998         }
6999       else
7000         {
7001           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7002           oss << " ! Should be in [0," << sz << ") !";
7003           throw INTERP_KERNEL::Exception(oss.str().c_str());
7004         }
7005     }
7006   if(ret->getNumberOfTS()>0)
7007     ret->synchronizeNameScope();
7008   ret->copyNameScope(*this);
7009   return ret.retn();
7010 }
7011
7012 /*!
7013  * 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
7014  * NULL.
7015  */
7016 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7017 {
7018   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7019   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7020   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7021   ret->setInfo(_infos);
7022   int sz=(int)_time_steps.size();
7023   int j=bg;
7024   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7025     {
7026       if(j>=0 && j<sz)
7027         {
7028           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7029           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7030           if(tse)
7031             {
7032               tse->incrRef();
7033               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7034             }
7035           ret->pushBackTimeStep(tse2);
7036         }
7037       else
7038         {
7039           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7040           oss << " ! Should be in [0," << sz << ") !";
7041           throw INTERP_KERNEL::Exception(oss.str().c_str());
7042         }
7043     }
7044   if(ret->getNumberOfTS()>0)
7045     ret->synchronizeNameScope();
7046   ret->copyNameScope(*this);
7047   return ret.retn();
7048 }
7049
7050 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7051 {
7052   int id=0;
7053   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7054   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7055     {
7056       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7057       if(!cur)
7058         continue;
7059       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7060       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7061         ids->pushBackSilent(id);
7062     }
7063   return buildFromTimeStepIds(ids->begin(),ids->end());
7064 }
7065
7066 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7067 {
7068   int id=0;
7069   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7070   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7071     {
7072       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7073       if(!cur)
7074         continue;
7075       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7076       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7077         ids->pushBackSilent(id);
7078     }
7079   return buildFromTimeStepIds(ids->begin(),ids->end());
7080 }
7081
7082 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7083 {
7084   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7085     {
7086       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7087       if(!cur)
7088         continue;
7089       if(cur->presenceOfMultiDiscPerGeoType())
7090         return true;
7091     }
7092   return false;
7093 }
7094
7095 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7096 {
7097   return _infos;
7098 }
7099
7100 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7101 {
7102   _infos=info;
7103 }
7104
7105 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7106 {
7107   int ret=0;
7108   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7109     {
7110       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7111       if(pt->isDealingTS(iteration,order))
7112         return ret;
7113     }
7114   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7115   std::vector< std::pair<int,int> > vp=getIterations();
7116   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7117     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7118   throw INTERP_KERNEL::Exception(oss.str().c_str());
7119 }
7120
7121 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7122 {
7123   return *_time_steps[getTimeStepPos(iteration,order)];
7124 }
7125
7126 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7127 {
7128   return *_time_steps[getTimeStepPos(iteration,order)];
7129 }
7130
7131 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7132 {
7133   if(_time_steps.empty())
7134     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7135   return _time_steps[0]->getMeshName();
7136 }
7137
7138 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7139 {
7140   std::string oldName(getMeshName());
7141   std::vector< std::pair<std::string,std::string> > v(1);
7142   v[0].first=oldName; v[0].second=newMeshName;
7143   changeMeshNames(v);
7144 }
7145
7146 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7147 {
7148   bool ret=false;
7149   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7150     {
7151       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7152       if(cur)
7153         ret=cur->changeMeshNames(modifTab) || ret;
7154     }
7155   return ret;
7156 }
7157
7158 /*!
7159  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7160  */
7161 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7162 {
7163   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7164 }
7165
7166 /*!
7167  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7168  */
7169 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7170 {
7171   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7172 }
7173
7174 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7175                                                                        MEDFileFieldGlobsReal& glob)
7176 {
7177   bool ret=false;
7178   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7179     {
7180       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7181       if(f1ts)
7182         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7183     }
7184   return ret;
7185 }
7186
7187 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7188 {
7189   std::string startLine(bkOffset,' ');
7190   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7191   if(fmtsId>=0)
7192     oss << " (" << fmtsId << ")";
7193   oss << " has the following name: \"" << _name << "\"." << std::endl;
7194   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7195   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7196     {
7197       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7198     }
7199   int i=0;
7200   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7201     {
7202       std::string chapter(17,'0'+i);
7203       oss << startLine << chapter << std::endl;
7204       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7205       if(cur)
7206         cur->simpleRepr(bkOffset+2,oss,i);
7207       else
7208         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7209       oss << startLine << chapter << std::endl;
7210     }
7211 }
7212
7213 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7214 {
7215   std::size_t sz=_time_steps.size();
7216   std::vector< std::pair<int,int> > ret(sz);
7217   ret1.resize(sz);
7218   for(std::size_t i=0;i<sz;i++)
7219     {
7220       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7221       if(f1ts)
7222         {
7223           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7224         }
7225       else
7226         {
7227           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7228           throw INTERP_KERNEL::Exception(oss.str().c_str());
7229         }
7230     }
7231   return ret;
7232 }
7233
7234 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7235 {
7236   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7237   if(!tse2)
7238     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7239   checkCoherencyOfType(tse2);
7240   if(_time_steps.empty())
7241     {
7242       setName(tse2->getName().c_str());
7243       setInfo(tse2->getInfo());
7244     }
7245   checkThatComponentsMatch(tse2->getInfo());
7246   _time_steps.push_back(tse);
7247 }
7248
7249 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7250 {
7251   std::size_t nbOfCompo=_infos.size();
7252   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7253     {
7254       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7255       if(cur)
7256         {
7257           if((cur->getInfo()).size()!=nbOfCompo)
7258             {
7259               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7260               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7261               throw INTERP_KERNEL::Exception(oss.str().c_str());
7262             }
7263           cur->copyNameScope(*this);
7264         }
7265     }
7266 }
7267
7268 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms)
7269 {
7270   _time_steps.resize(nbPdt);
7271   for(int i=0;i<nbPdt;i++)
7272     {
7273       std::vector< std::pair<int,int> > ts;
7274       med_int numdt=0,numo=0;
7275       med_int meshIt=0,meshOrder=0;
7276       med_float dt=0.0;
7277       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
7278       switch(fieldTyp)
7279       {
7280         case MED_FLOAT64:
7281           {
7282             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7283             break;
7284           }
7285         case MED_INT32:
7286           {
7287             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7288             break;
7289           }
7290         default:
7291           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7292       }
7293       if(loadAll)
7294         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms);
7295       else
7296         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms);
7297     }
7298 }
7299
7300 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7301 {
7302   if(_time_steps.empty())
7303     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7304   checkThatNbOfCompoOfTSMatchThis();
7305   std::vector<std::string> infos(getInfo());
7306   int nbComp=infos.size();
7307   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7308   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7309   for(int i=0;i<nbComp;i++)
7310     {
7311       std::string info=infos[i];
7312       std::string c,u;
7313       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7314       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7315       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7316     }
7317   if(_name.empty())
7318     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7319   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7320   int nbOfTS=_time_steps.size();
7321   for(int i=0;i<nbOfTS;i++)
7322     _time_steps[i]->writeLL(fid,opts,*this);
7323 }
7324
7325 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7326 {
7327   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7328     {
7329       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7330       if(elt)
7331         elt->loadBigArraysRecursively(fid,nasc);
7332     }
7333 }
7334
7335 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7336 {
7337   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7338     {
7339       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7340       if(elt)
7341         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7342     }
7343 }
7344
7345 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7346 {
7347   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7348     {
7349       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7350       if(elt)
7351         elt->unloadArrays();
7352     }
7353 }
7354
7355 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7356 {
7357   return _time_steps.size();
7358 }
7359
7360 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7361 {
7362   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7363   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7364     {
7365       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7366       if(tmp)
7367         newTS.push_back(*it);
7368     }
7369   _time_steps=newTS;
7370 }
7371
7372 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7373 {
7374   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7375   int maxId=(int)_time_steps.size();
7376   int ii=0;
7377   std::set<int> idsToDel;
7378   for(const int *id=startIds;id!=endIds;id++,ii++)
7379     {
7380       if(*id>=0 && *id<maxId)
7381         {
7382           idsToDel.insert(*id);
7383         }
7384       else
7385         {
7386           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7387           throw INTERP_KERNEL::Exception(oss.str().c_str());
7388         }
7389     }
7390   for(int iii=0;iii<maxId;iii++)
7391     if(idsToDel.find(iii)==idsToDel.end())
7392       newTS.push_back(_time_steps[iii]);
7393   _time_steps=newTS;
7394 }
7395
7396 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7397 {
7398   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7399   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7400   if(nbOfEntriesToKill==0)
7401     return ;
7402   std::size_t sz=_time_steps.size();
7403   std::vector<bool> b(sz,true);
7404   int j=bg;
7405   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7406     b[j]=false;
7407   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7408   for(std::size_t i=0;i<sz;i++)
7409     if(b[i])
7410       newTS.push_back(_time_steps[i]);
7411   _time_steps=newTS;
7412 }
7413
7414 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7415 {
7416   int ret=0;
7417   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7418   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7419     {
7420       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7421       if(tmp)
7422         {
7423           int it2,ord;
7424           tmp->getTime(it2,ord);
7425           if(it2==iteration && order==ord)
7426             return ret;
7427           else
7428             oss << "(" << it2 << ","  << ord << "), ";
7429         }
7430     }
7431   throw INTERP_KERNEL::Exception(oss.str().c_str());
7432 }
7433
7434 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7435 {
7436   int ret=0;
7437   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7438   oss.precision(15);
7439   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7440     {
7441       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7442       if(tmp)
7443         {
7444           int it2,ord;
7445           double ti=tmp->getTime(it2,ord);
7446           if(fabs(time-ti)<eps)
7447             return ret;
7448           else
7449             oss << ti << ", ";
7450         }
7451     }
7452   throw INTERP_KERNEL::Exception(oss.str().c_str());
7453 }
7454
7455 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7456 {
7457   int lgth=_time_steps.size();
7458   std::vector< std::pair<int,int> > ret(lgth);
7459   for(int i=0;i<lgth;i++)
7460     _time_steps[i]->fillIteration(ret[i]);
7461   return ret;
7462 }
7463
7464 /*!
7465  * 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'
7466  * This method returns two things.
7467  * - The absolute dimension of 'this' in first parameter. 
7468  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7469  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7470  *
7471  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7472  * Only these 3 discretizations will be taken into account here.
7473  *
7474  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7475  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7476  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7477  *
7478  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7479  * 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'.
7480  * 
7481  * Let's consider the typical following case :
7482  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7483  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7484  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7485  *   TETRA4 and SEG2
7486  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7487  *
7488  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7489  * 
7490  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7491  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7492  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7493  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7494  */
7495 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7496 {
7497   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7498 }
7499
7500 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7501 {
7502   if(pos<0 || pos>=(int)_time_steps.size())
7503     {
7504       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7505       throw INTERP_KERNEL::Exception(oss.str().c_str());
7506     }
7507   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7508   if(item==0)
7509     {
7510       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7511       oss << "\nTry to use following method eraseEmptyTS !";
7512       throw INTERP_KERNEL::Exception(oss.str().c_str());
7513     }
7514   return item;
7515 }
7516
7517 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7518 {
7519   if(pos<0 || pos>=(int)_time_steps.size())
7520     {
7521       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7522       throw INTERP_KERNEL::Exception(oss.str().c_str());
7523     }
7524   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7525   if(item==0)
7526     {
7527       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7528       oss << "\nTry to use following method eraseEmptyTS !";
7529       throw INTERP_KERNEL::Exception(oss.str().c_str());
7530     }
7531   return item;
7532 }
7533
7534 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7535 {
7536   std::vector<std::string> ret;
7537   std::set<std::string> ret2;
7538   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7539     {
7540       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7541       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7542         if(ret2.find(*it2)==ret2.end())
7543           {
7544             ret.push_back(*it2);
7545             ret2.insert(*it2);
7546           }
7547     }
7548   return ret;
7549 }
7550
7551 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7552 {
7553   std::vector<std::string> ret;
7554   std::set<std::string> ret2;
7555   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7556     {
7557       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7558       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7559         if(ret2.find(*it2)==ret2.end())
7560           {
7561             ret.push_back(*it2);
7562             ret2.insert(*it2);
7563           }
7564     }
7565   return ret;
7566 }
7567
7568 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7569 {
7570   std::vector<std::string> ret;
7571   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7572     {
7573       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7574       ret.insert(ret.end(),tmp.begin(),tmp.end());
7575     }
7576   return ret;
7577 }
7578
7579 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7580 {
7581   std::vector<std::string> ret;
7582   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7583     {
7584       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7585       ret.insert(ret.end(),tmp.begin(),tmp.end());
7586     }
7587   return ret;
7588 }
7589
7590 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7591 {
7592   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7593     (*it)->changePflsRefsNamesGen2(mapOfModif);
7594 }
7595
7596 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7597 {
7598   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7599     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7600 }
7601
7602 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7603 {
7604   int lgth=_time_steps.size();
7605   std::vector< std::vector<TypeOfField> > ret(lgth);
7606   for(int i=0;i<lgth;i++)
7607     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7608   return ret;
7609 }
7610
7611 /*!
7612  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7613  */
7614 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
7615 {
7616   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7617 }
7618
7619 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7620 {
7621   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7622   std::size_t i=0;
7623   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7624     {
7625       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7626         ret->_time_steps[i]=(*it)->deepCpy();
7627     }
7628   return ret.retn();
7629 }
7630
7631 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7632 {
7633   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7634   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7635   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7636   for(std::size_t i=0;i<sz;i++)
7637     {
7638       ret[i]=shallowCpy();
7639       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7640     }
7641   for(std::size_t i=0;i<sz2;i++)
7642     {
7643       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7644       if(ret1.size()!=sz)
7645         {
7646           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7647           throw INTERP_KERNEL::Exception(oss.str().c_str());
7648         }
7649       ts[i]=ret1;
7650     }
7651   for(std::size_t i=0;i<sz;i++)
7652     for(std::size_t j=0;j<sz2;j++)
7653       ret[i]->_time_steps[j]=ts[j][i];
7654   return ret;
7655 }
7656
7657 /*!
7658  * This method splits into discretization each time steps in \a this.
7659  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7660  */
7661 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7662 {
7663   std::size_t sz(_time_steps.size());
7664   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7665   for(std::size_t i=0;i<sz;i++)
7666     {
7667       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7668       if(!timeStep)
7669         {
7670           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7671           throw INTERP_KERNEL::Exception(oss.str().c_str());
7672         }
7673       items[i]=timeStep->splitDiscretizations();  
7674     }
7675   //
7676   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7677   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7678   std::vector< TypeOfField > types;
7679   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7680     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7681       {
7682         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7683         if(ts.size()!=1)
7684           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7685         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7686         if(it2==types.end())
7687           types.push_back(ts[0]);
7688       }
7689   ret.resize(types.size()); ret2.resize(types.size());
7690   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7691     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7692       {
7693         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7694         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7695         ret2[pos].push_back(*it1);
7696       }
7697   for(std::size_t i=0;i<types.size();i++)
7698     {
7699       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7700       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7701         elt->pushBackTimeStep(*it1);//also updates infos in elt
7702       ret[i]=elt;
7703       elt->MEDFileFieldNameScope::operator=(*this);
7704     }
7705   return ret;
7706 }
7707
7708 /*!
7709  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7710  */
7711 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7712 {
7713   std::size_t sz(_time_steps.size());
7714   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7715   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7716   for(std::size_t i=0;i<sz;i++)
7717     {
7718       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7719       if(!timeStep)
7720         {
7721           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7722           throw INTERP_KERNEL::Exception(oss.str().c_str());
7723         }
7724       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7725       if(szOut==std::numeric_limits<std::size_t>::max())
7726         szOut=items[i].size();
7727       else
7728         if(items[i].size()!=szOut)
7729           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7730     }
7731   if(szOut==std::numeric_limits<std::size_t>::max())
7732     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7733   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7734   for(std::size_t i=0;i<szOut;i++)
7735     {
7736       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7737       for(std::size_t j=0;j<sz;j++)
7738         elt->pushBackTimeStep(items[j][i]);
7739       ret[i]=elt;
7740       elt->MEDFileFieldNameScope::operator=(*this);
7741     }
7742   return ret;
7743 }
7744
7745 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7746 {
7747   _name=field->getName();
7748   if(_name.empty())
7749     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7750   if(!arr)
7751     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7752   _infos=arr->getInfoOnComponents();
7753 }
7754
7755 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7756 {
7757   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7758   if(_name!=field->getName())
7759     {
7760       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7761       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7762       throw INTERP_KERNEL::Exception(oss.str().c_str());
7763     }
7764   if(!arr)
7765     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7766   checkThatComponentsMatch(arr->getInfoOnComponents());
7767 }
7768
7769 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7770 {
7771   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7772   if(getInfo().size()!=compos.size())
7773     {
7774       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7775       oss << " number of components of element to append (" << compos.size() << ") !";
7776       throw INTERP_KERNEL::Exception(oss.str().c_str());
7777     }
7778   if(_infos!=compos)
7779     {
7780       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7781       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7782       oss << " But compo in input fields are : ";
7783       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7784       oss << " !";
7785       throw INTERP_KERNEL::Exception(oss.str().c_str());
7786     }
7787 }
7788
7789 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7790 {
7791   std::size_t sz=_infos.size();
7792   int j=0;
7793   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7794     {
7795       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7796       if(elt)
7797         if(elt->getInfo().size()!=sz)
7798           {
7799             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7800             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7801             throw INTERP_KERNEL::Exception(oss.str().c_str());
7802           }
7803     }
7804 }
7805
7806 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7807 {
7808   if(!field)
7809     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7810   if(!_time_steps.empty())
7811     checkCoherencyOfTinyInfo(field,arr);
7812   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7813   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7814   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7815   copyTinyInfoFrom(field,arr);
7816   _time_steps.push_back(obj);
7817 }
7818
7819 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7820 {
7821   if(!field)
7822     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7823   if(!_time_steps.empty())
7824     checkCoherencyOfTinyInfo(field,arr);
7825   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7826   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7827   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7828   copyTinyInfoFrom(field,arr);
7829   _time_steps.push_back(obj);
7830 }
7831
7832 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7833 {
7834   int sz=(int)_time_steps.size();
7835   if(i<0 || i>=sz)
7836     {
7837       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7838       throw INTERP_KERNEL::Exception(oss.str().c_str());
7839     }
7840   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7841   if(tsPtr)
7842     {
7843       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7844         {
7845           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7846           throw INTERP_KERNEL::Exception(oss.str().c_str());
7847         }
7848     }
7849   _time_steps[i]=ts;
7850 }
7851
7852 //= MEDFileFieldMultiTSWithoutSDA
7853
7854 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
7855 {
7856   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
7857 }
7858
7859 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7860 {
7861 }
7862
7863 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7864 {
7865 }
7866
7867 /*!
7868  * \param [in] fieldId field id in C mode
7869  */
7870 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
7871 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
7872 {
7873 }
7874 catch(INTERP_KERNEL::Exception& e)
7875 { throw e; }
7876
7877 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
7878 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
7879 {
7880 }
7881 catch(INTERP_KERNEL::Exception& e)
7882 { throw e; }
7883
7884 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7885 {
7886   return new MEDFileField1TSWithoutSDA;
7887 }
7888
7889 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7890 {
7891   if(!f1ts)
7892     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7893   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7894   if(!f1tsC)
7895     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7896 }
7897
7898 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7899 {
7900   return MEDFileField1TSWithoutSDA::TYPE_STR;
7901 }
7902
7903 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7904 {
7905   return new MEDFileFieldMultiTSWithoutSDA(*this);
7906 }
7907
7908 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7909 {
7910   return new MEDFileFieldMultiTSWithoutSDA;
7911 }
7912
7913 /*!
7914  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7915  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7916  */
7917 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
7918 {
7919   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7920   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7921   if(!myF1TSC)
7922     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7923   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7924 }
7925
7926 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
7927 {
7928   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7929   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7930   int i=0;
7931   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7932     {
7933       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7934       if(eltToConv)
7935         {
7936           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7937           if(!eltToConvC)
7938             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7939           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7940           ret->setIteration(i,elt);
7941         }
7942     }
7943   return ret.retn();
7944 }
7945
7946 //= MEDFileAnyTypeFieldMultiTS
7947
7948 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7949 {
7950 }
7951
7952 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7953 try:MEDFileFieldGlobsReal(fileName)
7954 {
7955   MEDFileUtilities::CheckFileForRead(fileName);
7956   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7957   _content=BuildContentFrom(fid,fileName,loadAll,ms);
7958   loadGlobals(fid);
7959 }
7960 catch(INTERP_KERNEL::Exception& e)
7961 {
7962     throw e;
7963 }
7964
7965 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7966 {
7967   med_field_type typcha;
7968   std::vector<std::string> infos;
7969   std::string dtunit;
7970   int i=-1;
7971   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7972   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7973   switch(typcha)
7974   {
7975     case MED_FLOAT64:
7976       {
7977         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7978         break;
7979       }
7980     case MED_INT32:
7981       {
7982         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7983         break;
7984       }
7985     default:
7986       {
7987         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] !";
7988         throw INTERP_KERNEL::Exception(oss.str().c_str());
7989       }
7990   }
7991   ret->setDtUnit(dtunit.c_str());
7992   return ret.retn();
7993 }
7994
7995 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7996 {
7997   med_field_type typcha;
7998   //
7999   std::vector<std::string> infos;
8000   std::string dtunit,fieldName;
8001   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8002   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8003   switch(typcha)
8004   {
8005     case MED_FLOAT64:
8006       {
8007         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
8008         break;
8009       }
8010     case MED_INT32:
8011       {
8012         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
8013         break;
8014       }
8015     default:
8016       {
8017         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] !";
8018         throw INTERP_KERNEL::Exception(oss.str().c_str());
8019       }
8020   }
8021   ret->setDtUnit(dtunit.c_str());
8022   return ret.retn();
8023 }
8024
8025 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8026 {
8027   if(!c)
8028     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8029   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8030     {
8031       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8032       ret->setFileName(fileName);
8033       ret->_content=c;  c->incrRef();
8034       return ret.retn();
8035     }
8036   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8037     {
8038       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8039       ret->setFileName(fileName);
8040       ret->_content=c;  c->incrRef();
8041       return ret.retn();
8042     }
8043   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8044 }
8045
8046 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
8047 try:MEDFileFieldGlobsReal(fileName)
8048 {
8049   MEDFileUtilities::CheckFileForRead(fileName);
8050   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8051   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
8052   loadGlobals(fid);
8053 }
8054 catch(INTERP_KERNEL::Exception& e)
8055 {
8056     throw e;
8057 }
8058
8059 //= MEDFileIntFieldMultiTSWithoutSDA
8060
8061 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
8062 {
8063   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
8064 }
8065
8066 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8067 {
8068 }
8069
8070 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8071 {
8072 }
8073
8074 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms)
8075 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
8076 {
8077 }
8078 catch(INTERP_KERNEL::Exception& e)
8079 { throw e; }
8080
8081 /*!
8082  * \param [in] fieldId field id in C mode
8083  */
8084 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
8085 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
8086 {
8087 }
8088 catch(INTERP_KERNEL::Exception& e)
8089 { throw e; }
8090
8091 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8092 {
8093   return new MEDFileIntField1TSWithoutSDA;
8094 }
8095
8096 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8097 {
8098   if(!f1ts)
8099     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8100   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8101   if(!f1tsC)
8102     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8103 }
8104
8105 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8106 {
8107   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8108 }
8109
8110 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8111 {
8112   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8113 }
8114
8115 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8116 {
8117   return new MEDFileIntFieldMultiTSWithoutSDA;
8118 }
8119
8120 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8121 {
8122   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8123   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8124   int i=0;
8125   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8126     {
8127       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8128       if(eltToConv)
8129         {
8130           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8131           if(!eltToConvC)
8132             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8133           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8134           ret->setIteration(i,elt);
8135         }
8136     }
8137   return ret.retn();
8138 }
8139
8140 //= MEDFileAnyTypeFieldMultiTS
8141
8142 /*!
8143  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8144  * that has been read from a specified MED file.
8145  *  \param [in] fileName - the name of the MED file to read.
8146  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8147  *          is to delete this field using decrRef() as it is no more needed.
8148  *  \throw If reading the file fails.
8149  */
8150 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8151 {
8152   MEDFileUtilities::CheckFileForRead(fileName);
8153   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8154   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8155   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8156   ret->loadGlobals(fid);
8157   return ret.retn();
8158 }
8159
8160 /*!
8161  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8162  * that has been read from a specified MED file.
8163  *  \param [in] fileName - the name of the MED file to read.
8164  *  \param [in] fieldName - the name of the field to read.
8165  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8166  *          is to delete this field using decrRef() as it is no more needed.
8167  *  \throw If reading the file fails.
8168  *  \throw If there is no field named \a fieldName in the file.
8169  */
8170 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8171 {
8172   MEDFileUtilities::CheckFileForRead(fileName);
8173   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8174   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
8175   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8176   ret->loadGlobals(fid);
8177   return ret.retn();
8178 }
8179
8180 /*!
8181  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8182  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8183  *
8184  * \warning this is a shallow copy constructor
8185  */
8186 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8187 {
8188   if(!shallowCopyOfContent)
8189     {
8190       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8191       otherPtr->incrRef();
8192       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8193     }
8194   else
8195     {
8196       _content=other.shallowCpy();
8197     }
8198 }
8199
8200 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8201 {
8202   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8203   if(!ret)
8204     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8205   return ret;
8206 }
8207
8208 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8209 {
8210   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8211   if(!ret)
8212     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8213   return ret;
8214 }
8215
8216 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8217 {
8218   return contentNotNullBase()->getPflsReallyUsed2();
8219 }
8220
8221 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8222 {
8223   return contentNotNullBase()->getLocsReallyUsed2();
8224 }
8225
8226 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8227 {
8228   return contentNotNullBase()->getPflsReallyUsedMulti2();
8229 }
8230
8231 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8232 {
8233   return contentNotNullBase()->getLocsReallyUsedMulti2();
8234 }
8235
8236 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8237 {
8238   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8239 }
8240
8241 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8242 {
8243   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8244 }
8245
8246 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8247 {
8248   return contentNotNullBase()->getNumberOfTS();
8249 }
8250
8251 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8252 {
8253   contentNotNullBase()->eraseEmptyTS();
8254 }
8255
8256 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8257 {
8258   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8259 }
8260
8261 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8262 {
8263   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8264 }
8265
8266 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8267 {
8268   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8269   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8270   ret->_content=c;
8271   return ret.retn();
8272 }
8273
8274 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8275 {
8276   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8277   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8278   ret->_content=c;
8279   return ret.retn();
8280 }
8281
8282 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8283 {
8284   return contentNotNullBase()->getIterations();
8285 }
8286
8287 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8288 {
8289   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8290     pushBackTimeStep(*it);
8291 }
8292
8293 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8294 {
8295   if(!f1ts)
8296     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8297   checkCoherencyOfType(f1ts);
8298   f1ts->incrRef();
8299   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8300   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8301   c->incrRef();
8302   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8303   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8304     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8305   _content->pushBackTimeStep(cSafe);
8306   appendGlobs(*f1ts,1e-12);
8307 }
8308
8309 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8310 {
8311   contentNotNullBase()->synchronizeNameScope();
8312 }
8313
8314 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8315 {
8316   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8317 }
8318
8319 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8320 {
8321   return contentNotNullBase()->getPosGivenTime(time,eps);
8322 }
8323
8324 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8325 {
8326   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8327 }
8328
8329 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8330 {
8331   return contentNotNullBase()->getTypesOfFieldAvailable();
8332 }
8333
8334 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
8335 {
8336   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8337 }
8338
8339 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8340 {
8341   return contentNotNullBase()->getName();
8342 }
8343
8344 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8345 {
8346   contentNotNullBase()->setName(name);
8347 }
8348
8349 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8350 {
8351   return contentNotNullBase()->getDtUnit();
8352 }
8353
8354 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8355 {
8356   contentNotNullBase()->setDtUnit(dtUnit);
8357 }
8358
8359 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8360 {
8361   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8362 }
8363
8364 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8365 {
8366   return contentNotNullBase()->getTimeSteps(ret1);
8367 }
8368
8369 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8370 {
8371   return contentNotNullBase()->getMeshName();
8372 }
8373
8374 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8375 {
8376   contentNotNullBase()->setMeshName(newMeshName);
8377 }
8378
8379 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8380 {
8381   return contentNotNullBase()->changeMeshNames(modifTab);
8382 }
8383
8384 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8385 {
8386   return contentNotNullBase()->getInfo();
8387 }
8388
8389 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8390 {
8391   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8392 }
8393
8394 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8395 {
8396   return contentNotNullBase()->setInfo(info);
8397 }
8398
8399 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8400 {
8401   const std::vector<std::string> ret=getInfo();
8402   return (int)ret.size();
8403 }
8404
8405 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8406 {
8407   writeGlobals(fid,*this);
8408   contentNotNullBase()->writeLL(fid,*this);
8409 }
8410
8411 /*!
8412  * Writes \a this field into a MED file specified by its name.
8413  *  \param [in] fileName - the MED file name.
8414  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8415  * - 2 - erase; an existing file is removed.
8416  * - 1 - append; same data should not be present in an existing file.
8417  * - 0 - overwrite; same data present in an existing file is overwritten.
8418  *  \throw If the field name is not set.
8419  *  \throw If no field data is set.
8420  *  \throw If \a mode == 1 and the same data is present in an existing file.
8421  */
8422 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8423 {
8424   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8425   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8426   writeLL(fid);
8427 }
8428
8429 /*!
8430  * This method alloc the arrays and load potentially huge arrays contained in this field.
8431  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8432  * This method can be also called to refresh or reinit values from a file.
8433  * 
8434  * \throw If the fileName is not set or points to a non readable MED file.
8435  */
8436 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8437 {
8438   if(getFileName().empty())
8439     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8440   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8441   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8442 }
8443
8444 /*!
8445  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8446  * But once data loaded once, this method does nothing.
8447  * 
8448  * \throw If the fileName is not set or points to a non readable MED file.
8449  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8450  */
8451 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8452 {
8453   if(!getFileName().empty())
8454     {
8455       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8456       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8457     }
8458 }
8459
8460 /*!
8461  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8462  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8463  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8464  * 
8465  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8466  */
8467 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8468 {
8469   contentNotNullBase()->unloadArrays();
8470 }
8471
8472 /*!
8473  * 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.
8474  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8475  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8476  * 
8477  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8478  */
8479 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8480 {
8481   if(!getFileName().empty())
8482     contentNotNullBase()->unloadArrays();
8483 }
8484
8485 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8486 {
8487   std::ostringstream oss;
8488   contentNotNullBase()->simpleRepr(0,oss,-1);
8489   simpleReprGlobs(oss);
8490   return oss.str();
8491 }
8492
8493 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8494 {
8495   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8496 }
8497
8498 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8499 {
8500   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8501   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8502   return ret;
8503 }
8504
8505 /*!
8506  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8507  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8508  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8509  */
8510 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8511 {
8512   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8513   if(!content)
8514     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8515   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8516   std::size_t sz(contentsSplit.size());
8517   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8518   for(std::size_t i=0;i<sz;i++)
8519     {
8520       ret[i]=shallowCpy();
8521       ret[i]->_content=contentsSplit[i];
8522     }
8523   return ret;
8524 }
8525
8526 /*!
8527  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8528  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8529  */
8530 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8531 {
8532   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8533   if(!content)
8534     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8535   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8536   std::size_t sz(contentsSplit.size());
8537   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8538   for(std::size_t i=0;i<sz;i++)
8539     {
8540       ret[i]=shallowCpy();
8541       ret[i]->_content=contentsSplit[i];
8542     }
8543   return ret;
8544 }
8545
8546 /*!
8547  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8548  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8549  */
8550 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8551 {
8552   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8553   if(!content)
8554     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8555   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8556   std::size_t sz(contentsSplit.size());
8557   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8558   for(std::size_t i=0;i<sz;i++)
8559     {
8560       ret[i]=shallowCpy();
8561       ret[i]->_content=contentsSplit[i];
8562     }
8563   return ret;
8564 }
8565
8566 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8567 {
8568   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8569   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8570     ret->_content=_content->deepCpy();
8571   ret->deepCpyGlobs(*this);
8572   return ret.retn();
8573 }
8574
8575 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8576 {
8577   return _content;
8578 }
8579
8580 /*!
8581  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8582  *  \param [in] iteration - the iteration number of a required time step.
8583  *  \param [in] order - the iteration order number of required time step.
8584  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8585  *          delete this field using decrRef() as it is no more needed.
8586  *  \throw If there is no required time step in \a this field.
8587  */
8588 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8589 {
8590   int pos=getPosOfTimeStep(iteration,order);
8591   return getTimeStepAtPos(pos);
8592 }
8593
8594 /*!
8595  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8596  *  \param [in] time - the time of the time step of interest.
8597  *  \param [in] eps - a precision used to compare time values.
8598  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8599  *          delete this field using decrRef() as it is no more needed.
8600  *  \throw If there is no required time step in \a this field.
8601  */
8602 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8603 {
8604   int pos=getPosGivenTime(time,eps);
8605   return getTimeStepAtPos(pos);
8606 }
8607
8608 /*!
8609  * 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.
8610  * The float64 value of time attached to the pair of integers are not considered here.
8611  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8612  *
8613  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8614  * \throw If there is a null pointer in \a vectFMTS.
8615  */
8616 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8617 {
8618   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8619   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8620   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8621   while(!lstFMTS.empty())
8622     {
8623       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8624       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8625       if(!curIt)
8626         throw INTERP_KERNEL::Exception(msg);
8627       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8628       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8629       elt.push_back(curIt); it=lstFMTS.erase(it);
8630       while(it!=lstFMTS.end())
8631         {
8632           curIt=*it;
8633           if(!curIt)
8634             throw INTERP_KERNEL::Exception(msg);
8635           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8636           if(refIts==curIts)
8637             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8638           else
8639             it++;
8640         }
8641       ret.push_back(elt);
8642     }
8643   return ret;
8644 }
8645
8646 /*!
8647  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8648  * All returned instances in a subvector can be safely loaded, rendered along time
8649  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8650  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8651  * 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).
8652  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8653  * 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.
8654  *
8655  * \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().
8656  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8657  * \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.
8658  * \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.
8659  *
8660  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8661  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8662  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8663  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8664  * \throw If mesh is null.
8665  * \throw If an element in \a vectFMTS is null.
8666  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8667  */
8668 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8669 {
8670   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8671   if(!mesh)
8672     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8673   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8674   if(vectFMTS.empty())
8675     return ret;
8676   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8677   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8678   if(!frstElt)
8679     throw INTERP_KERNEL::Exception(msg);
8680   std::size_t i=0;
8681   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8682   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8683   for(;it!=vectFMTS.end();it++,i++)
8684     {
8685       if(!(*it))
8686         throw INTERP_KERNEL::Exception(msg);
8687       TypeOfField tof0,tof1;
8688       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8689         {
8690           if(tof1!=ON_NODES)
8691             vectFMTSNotNodes.push_back(*it);
8692           else
8693             vectFMTSNodes.push_back(*it);
8694         }
8695       else
8696         vectFMTSNotNodes.push_back(*it);
8697     }
8698   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8699   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8700   ret=retCell;
8701   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8702     {
8703       i=0;
8704       bool isFetched(false);
8705       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8706         {
8707           if((*it0).empty())
8708             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8709           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8710             { ret[i].push_back(*it2); isFetched=true; }
8711         }
8712       if(!isFetched)
8713         {
8714           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8715           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8716           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8717         }
8718     }
8719   fsc=cmps;
8720   return ret;
8721 }
8722
8723 /*!
8724  * 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.
8725  * \param [out] cmps - same size than the returned vector.
8726  */
8727 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8728 {
8729   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8730   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8731   while(!lstFMTS.empty())
8732     {
8733       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8734       MEDFileAnyTypeFieldMultiTS *ref(*it);
8735       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8736       elt.push_back(ref); it=lstFMTS.erase(it);
8737       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8738       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8739       while(it!=lstFMTS.end())
8740         {
8741           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8742           if(cmp->isEqual(curIt))
8743             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8744           else
8745             it++;
8746         }
8747       ret.push_back(elt); cmps.push_back(cmp);
8748     }
8749   return ret;
8750 }
8751
8752 /*!
8753  * 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.
8754  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8755  *
8756  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8757  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8758  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8759  * \thorw If \a f0 and \a f1 do not have the same times steps.
8760  * \throw If mesh is null.
8761  * \throw If \a f0 or \a f1 is null.
8762  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8763  */
8764 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8765 {
8766   if(!mesh)
8767     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8768   if(!f0 || !f1)
8769     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8770   if(f0->getMeshName()!=mesh->getName())
8771     {
8772       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8773       throw INTERP_KERNEL::Exception(oss.str().c_str());
8774     }
8775   if(f1->getMeshName()!=mesh->getName())
8776     {
8777       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8778       throw INTERP_KERNEL::Exception(oss.str().c_str());
8779     }
8780   int nts=f0->getNumberOfTS();
8781   if(nts!=f1->getNumberOfTS())
8782     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8783   if(nts==0)
8784     return nts;
8785   for(int i=0;i<nts;i++)
8786     {
8787       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8788       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8789       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8790       if(tofs0.size()!=1 || tofs1.size()!=1)
8791         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8792       if(i!=0)
8793         {
8794           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8795             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8796         }
8797       else
8798         { tof0=tofs0[0]; tof1=tofs1[0]; }
8799       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8800         {
8801           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() << ") !";
8802           throw INTERP_KERNEL::Exception(oss.str().c_str());
8803         }
8804       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8805         {
8806           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() << ") !";
8807           throw INTERP_KERNEL::Exception(oss.str().c_str());
8808         }
8809       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8810         {
8811           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() << ") !";
8812           throw INTERP_KERNEL::Exception(oss.str().c_str());
8813         }
8814     }
8815   return nts;
8816 }
8817
8818 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8819 {
8820   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8821 }
8822
8823 //= MEDFileFieldMultiTS
8824
8825 /*!
8826  * Returns a new empty instance of MEDFileFieldMultiTS.
8827  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8828  *          is to delete this field using decrRef() as it is no more needed.
8829  */
8830 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8831 {
8832   return new MEDFileFieldMultiTS;
8833 }
8834
8835 /*!
8836  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8837  * that has been read from a specified MED file.
8838  *  \param [in] fileName - the name of the MED file to read.
8839  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8840  *          is to delete this field using decrRef() as it is no more needed.
8841  *  \throw If reading the file fails.
8842  */
8843 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8844 {
8845   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8846   ret->contentNotNull();//to check that content type matches with \a this type.
8847   return ret.retn();
8848 }
8849
8850 /*!
8851  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8852  * that has been read from a specified MED file.
8853  *  \param [in] fileName - the name of the MED file to read.
8854  *  \param [in] fieldName - the name of the field to read.
8855  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8856  *          is to delete this field using decrRef() as it is no more needed.
8857  *  \throw If reading the file fails.
8858  *  \throw If there is no field named \a fieldName in the file.
8859  */
8860 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8861 {
8862   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
8863   ret->contentNotNull();//to check that content type matches with \a this type.
8864   return ret.retn();
8865 }
8866
8867 /*!
8868  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8869  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8870  *
8871  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8872  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8873  * \warning this is a shallow copy constructor
8874  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8875  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8876  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8877  *          is to delete this field using decrRef() as it is no more needed.
8878  */
8879 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8880 {
8881   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8882 }
8883
8884 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8885 {
8886   return new MEDFileFieldMultiTS(*this);
8887 }
8888
8889 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8890 {
8891   if(!f1ts)
8892     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8893   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8894   if(!f1tsC)
8895     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8896 }
8897
8898 /*!
8899  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8900  * following the given input policy.
8901  *
8902  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8903  *                            By default (true) the globals are deeply copied.
8904  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8905  */
8906 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8907 {
8908   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8909   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8910   if(content)
8911     {
8912       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8913       if(!contc)
8914         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8915       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8916       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8917     }
8918   else
8919     ret=MEDFileIntFieldMultiTS::New();
8920   if(isDeepCpyGlobs)
8921     ret->deepCpyGlobs(*this);
8922   else
8923     ret->shallowCpyGlobs(*this);
8924   return ret.retn();
8925 }
8926
8927 /*!
8928  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8929  *  \param [in] pos - a time step id.
8930  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8931  *          delete this field using decrRef() as it is no more needed.
8932  *  \throw If \a pos is not a valid time step id.
8933  */
8934 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
8935 {
8936   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8937   if(!item)
8938     {
8939       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8940       throw INTERP_KERNEL::Exception(oss.str().c_str());
8941     }
8942   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8943   if(itemC)
8944     {
8945       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8946       ret->shallowCpyGlobs(*this);
8947       return ret.retn();
8948     }
8949   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8950   throw INTERP_KERNEL::Exception(oss.str().c_str());
8951 }
8952
8953 /*!
8954  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8955  * mesh entities of a given dimension of the first mesh in MED file.
8956  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8957  *  \param [in] type - a spatial discretization of interest.
8958  *  \param [in] iteration - the iteration number of a required time step.
8959  *  \param [in] order - the iteration order number of required time step.
8960  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8961  *  \param [in] renumPol - specifies how to permute values of the result field according to
8962  *          the optional numbers of cells and nodes, if any. The valid values are
8963  *          - 0 - do not permute.
8964  *          - 1 - permute cells.
8965  *          - 2 - permute nodes.
8966  *          - 3 - permute cells and nodes.
8967  *
8968  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8969  *          caller is to delete this field using decrRef() as it is no more needed. 
8970  *  \throw If the MED file is not readable.
8971  *  \throw If there is no mesh in the MED file.
8972  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8973  *  \throw If no field values of the required parameters are available.
8974  */
8975 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
8976 {
8977   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8978   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8979   if(!myF1TSC)
8980     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8981   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8982   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8983   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8984   return ret.retn();
8985 }
8986
8987 /*!
8988  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8989  * the top level cells of the first mesh in MED file.
8990  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8991  *  \param [in] type - a spatial discretization of interest.
8992  *  \param [in] iteration - the iteration number of a required time step.
8993  *  \param [in] order - the iteration order number of required time step.
8994  *  \param [in] renumPol - specifies how to permute values of the result field according to
8995  *          the optional numbers of cells and nodes, if any. The valid values are
8996  *          - 0 - do not permute.
8997  *          - 1 - permute cells.
8998  *          - 2 - permute nodes.
8999  *          - 3 - permute cells and nodes.
9000  *
9001  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9002  *          caller is to delete this field using decrRef() as it is no more needed. 
9003  *  \throw If the MED file is not readable.
9004  *  \throw If there is no mesh in the MED file.
9005  *  \throw If no field values of the required parameters are available.
9006  */
9007 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9008 {
9009   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9010   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9011   if(!myF1TSC)
9012     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9013   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9014   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9015   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9016   return ret.retn();
9017 }
9018
9019 /*!
9020  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9021  * a given support.
9022  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9023  *  \param [in] type - a spatial discretization of interest.
9024  *  \param [in] iteration - the iteration number of a required time step.
9025  *  \param [in] order - the iteration order number of required time step.
9026  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9027  *  \param [in] mesh - the supporting mesh.
9028  *  \param [in] renumPol - specifies how to permute values of the result field according to
9029  *          the optional numbers of cells and nodes, if any. The valid values are
9030  *          - 0 - do not permute.
9031  *          - 1 - permute cells.
9032  *          - 2 - permute nodes.
9033  *          - 3 - permute cells and nodes.
9034  *
9035  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9036  *          caller is to delete this field using decrRef() as it is no more needed. 
9037  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9038  *  \throw If no field of \a this is lying on \a mesh.
9039  *  \throw If no field values of the required parameters are available.
9040  */
9041 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9042 {
9043   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9044   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9045   if(!myF1TSC)
9046     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9047   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9048   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9049   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9050   return ret.retn();
9051 }
9052
9053 /*!
9054  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9055  * given support. 
9056  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9057  *  \param [in] type - a spatial discretization of the new field.
9058  *  \param [in] iteration - the iteration number of a required time step.
9059  *  \param [in] order - the iteration order number of required time step.
9060  *  \param [in] mesh - the supporting mesh.
9061  *  \param [in] renumPol - specifies how to permute values of the result field according to
9062  *          the optional numbers of cells and nodes, if any. The valid values are
9063  *          - 0 - do not permute.
9064  *          - 1 - permute cells.
9065  *          - 2 - permute nodes.
9066  *          - 3 - permute cells and nodes.
9067  *
9068  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9069  *          caller is to delete this field using decrRef() as it is no more needed. 
9070  *  \throw If no field of \a this is lying on \a mesh.
9071  *  \throw If no field values of the required parameters are available.
9072  */
9073 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9074 {
9075   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9076   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9077   if(!myF1TSC)
9078     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9079   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9080   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9081   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9082   return ret.retn();
9083 }
9084
9085 /*!
9086  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9087  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9088  * This method is useful for MED2 file format when field on different mesh was autorized.
9089  */
9090 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9091 {
9092   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9093   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9094   if(!myF1TSC)
9095     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9096   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9097   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9098   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9099   return ret.retn();
9100 }
9101
9102 /*!
9103  * Returns values and a profile of the field of a given type, of a given time step,
9104  * lying on a given support.
9105  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9106  *  \param [in] type - a spatial discretization of the field.
9107  *  \param [in] iteration - the iteration number of a required time step.
9108  *  \param [in] order - the iteration order number of required time step.
9109  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9110  *  \param [in] mesh - the supporting mesh.
9111  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9112  *          field of interest lies on. If the field lies on all entities of the given
9113  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9114  *          using decrRef() as it is no more needed.  
9115  *  \param [in] glob - the global data storing profiles and localization.
9116  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9117  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9118  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9119  *  \throw If no field of \a this is lying on \a mesh.
9120  *  \throw If no field values of the required parameters are available.
9121  */
9122 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9123 {
9124   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9125   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9126   if(!myF1TSC)
9127     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9128   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9129   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9130 }
9131
9132 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9133 {
9134   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9135   if(!pt)
9136     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9137   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9138   if(!ret)
9139     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 !");
9140   return ret;
9141 }
9142
9143 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9144 {
9145   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9146   if(!pt)
9147     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9148   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9149   if(!ret)
9150     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 !");
9151   return ret;
9152 }
9153
9154 /*!
9155  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9156  * the given field is checked if its elements are sorted suitable for writing to MED file
9157  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9158  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9159  *  \param [in] field - the field to add to \a this.
9160  *  \throw If the name of \a field is empty.
9161  *  \throw If the data array of \a field is not set.
9162  *  \throw If existing time steps have different name or number of components than \a field.
9163  *  \throw If the underlying mesh of \a field has no name.
9164  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9165  */
9166 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9167 {
9168   const DataArrayDouble *arr=0;
9169   if(field)
9170     arr=field->getArray();
9171   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9172 }
9173
9174 /*!
9175  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9176  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9177  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9178  * and \a profile.
9179  *
9180  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9181  * A new profile is added only if no equal profile is missing.
9182  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9183  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9184  *  \param [in] mesh - the supporting mesh of \a field.
9185  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9186  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9187  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9188  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9189  *  \throw If the data array of \a field is not set.
9190  *  \throw If the data array of \a this is already allocated but has different number of
9191  *         components than \a field.
9192  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9193  *  \sa setFieldNoProfileSBT()
9194  */
9195 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9196 {
9197   const DataArrayDouble *arr=0;
9198   if(field)
9199     arr=field->getArray();
9200   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9201 }
9202
9203 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9204 {
9205   _content=new MEDFileFieldMultiTSWithoutSDA;
9206 }
9207
9208 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9209 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9210 {
9211 }
9212 catch(INTERP_KERNEL::Exception& e)
9213 { throw e; }
9214
9215 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
9216 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
9217 {
9218 }
9219 catch(INTERP_KERNEL::Exception& e)
9220 { throw e; }
9221
9222 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9223 {
9224 }
9225
9226 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
9227 {
9228   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9229 }
9230
9231 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9232 {
9233   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9234 }
9235
9236 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9237 {
9238   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9239 }
9240
9241 //= MEDFileAnyTypeFieldMultiTSIterator
9242
9243 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9244 {
9245   if(fmts)
9246     {
9247       fmts->incrRef();
9248       _nb_iter=fmts->getNumberOfTS();
9249     }
9250 }
9251
9252 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9253 {
9254 }
9255
9256 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9257 {
9258   if(_iter_id<_nb_iter)
9259     {
9260       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9261       if(fmts)
9262         return fmts->getTimeStepAtPos(_iter_id++);
9263       else
9264         return 0;
9265     }
9266   else
9267     return 0;
9268 }
9269
9270 //= MEDFileIntFieldMultiTS
9271
9272 /*!
9273  * Returns a new empty instance of MEDFileFieldMultiTS.
9274  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9275  *          is to delete this field using decrRef() as it is no more needed.
9276  */
9277 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9278 {
9279   return new MEDFileIntFieldMultiTS;
9280 }
9281
9282 /*!
9283  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9284  * that has been read from a specified MED file.
9285  *  \param [in] fileName - the name of the MED file to read.
9286  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9287  *          is to delete this field using decrRef() as it is no more needed.
9288  *  \throw If reading the file fails.
9289  */
9290 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9291 {
9292   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9293   ret->contentNotNull();//to check that content type matches with \a this type.
9294   return ret.retn();
9295 }
9296
9297 /*!
9298  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9299  * that has been read from a specified MED file.
9300  *  \param [in] fileName - the name of the MED file to read.
9301  *  \param [in] fieldName - the name of the field to read.
9302  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9303  *          is to delete this field using decrRef() as it is no more needed.
9304  *  \throw If reading the file fails.
9305  *  \throw If there is no field named \a fieldName in the file.
9306  */
9307 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9308 {
9309   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9310   ret->contentNotNull();//to check that content type matches with \a this type.
9311   return ret.retn();
9312 }
9313
9314 /*!
9315  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9316  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9317  *
9318  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9319  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9320  * \warning this is a shallow copy constructor
9321  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9322  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9323  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9324  *          is to delete this field using decrRef() as it is no more needed.
9325  */
9326 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9327 {
9328   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9329 }
9330
9331 /*!
9332  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9333  * following the given input policy.
9334  *
9335  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9336  *                            By default (true) the globals are deeply copied.
9337  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9338  */
9339 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9340 {
9341   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9342   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9343   if(content)
9344     {
9345       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9346       if(!contc)
9347         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9348       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9349       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9350     }
9351   else
9352     ret=MEDFileFieldMultiTS::New();
9353   if(isDeepCpyGlobs)
9354     ret->deepCpyGlobs(*this);
9355   else
9356     ret->shallowCpyGlobs(*this);
9357   return ret.retn();
9358 }
9359
9360 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9361 {
9362   return new MEDFileIntFieldMultiTS(*this);
9363 }
9364
9365 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9366 {
9367   if(!f1ts)
9368     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9369   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9370   if(!f1tsC)
9371     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9372 }
9373
9374 /*!
9375  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9376  * mesh entities of a given dimension of the first mesh in MED file.
9377  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9378  *  \param [in] type - a spatial discretization of interest.
9379  *  \param [in] iteration - the iteration number of a required time step.
9380  *  \param [in] order - the iteration order number of required time step.
9381  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9382  *  \param [out] arrOut - the DataArrayInt containing values of field.
9383  *  \param [in] renumPol - specifies how to permute values of the result field according to
9384  *          the optional numbers of cells and nodes, if any. The valid values are
9385  *          - 0 - do not permute.
9386  *          - 1 - permute cells.
9387  *          - 2 - permute nodes.
9388  *          - 3 - permute cells and nodes.
9389  *
9390  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9391  *          caller is to delete this field using decrRef() as it is no more needed. 
9392  *  \throw If the MED file is not readable.
9393  *  \throw If there is no mesh in the MED file.
9394  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9395  *  \throw If no field values of the required parameters are available.
9396  */
9397 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9398 {
9399   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9400   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9401   if(!myF1TSC)
9402     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9403   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9404   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9405   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9406   return ret.retn();
9407 }
9408
9409 /*!
9410  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9411  * the top level cells of the first mesh in MED file.
9412  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9413  *  \param [in] type - a spatial discretization of interest.
9414  *  \param [in] iteration - the iteration number of a required time step.
9415  *  \param [in] order - the iteration order number of required time step.
9416  *  \param [out] arrOut - the DataArrayInt containing values of field.
9417  *  \param [in] renumPol - specifies how to permute values of the result field according to
9418  *          the optional numbers of cells and nodes, if any. The valid values are
9419  *          - 0 - do not permute.
9420  *          - 1 - permute cells.
9421  *          - 2 - permute nodes.
9422  *          - 3 - permute cells and nodes.
9423  *
9424  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9425  *          caller is to delete this field using decrRef() as it is no more needed. 
9426  *  \throw If the MED file is not readable.
9427  *  \throw If there is no mesh in the MED file.
9428  *  \throw If no field values of the required parameters are available.
9429  */
9430 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9431 {
9432   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9433   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9434   if(!myF1TSC)
9435     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9436   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9437   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9438   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9439   return ret.retn();
9440 }
9441
9442 /*!
9443  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9444  * a given support.
9445  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9446  *  \param [in] type - a spatial discretization of interest.
9447  *  \param [in] iteration - the iteration number of a required time step.
9448  *  \param [in] order - the iteration order number of required time step.
9449  *  \param [out] arrOut - the DataArrayInt containing values of field.
9450  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9451  *  \param [in] mesh - the supporting mesh.
9452  *  \param [in] renumPol - specifies how to permute values of the result field according to
9453  *          the optional numbers of cells and nodes, if any. The valid values are
9454  *          - 0 - do not permute.
9455  *          - 1 - permute cells.
9456  *          - 2 - permute nodes.
9457  *          - 3 - permute cells and nodes.
9458  *
9459  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9460  *          caller is to delete this field using decrRef() as it is no more needed. 
9461  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9462  *  \throw If no field of \a this is lying on \a mesh.
9463  *  \throw If no field values of the required parameters are available.
9464  */
9465 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9466 {
9467   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9468   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9469   if(!myF1TSC)
9470     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9471   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9472   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9473   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9474   return ret.retn();
9475 }
9476
9477 /*!
9478  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9479  * given support. 
9480  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9481  *  \param [in] type - a spatial discretization of the new field.
9482  *  \param [in] iteration - the iteration number of a required time step.
9483  *  \param [in] order - the iteration order number of required time step.
9484  *  \param [in] mesh - the supporting mesh.
9485  *  \param [out] arrOut - the DataArrayInt containing values of field.
9486  *  \param [in] renumPol - specifies how to permute values of the result field according to
9487  *          the optional numbers of cells and nodes, if any. The valid values are
9488  *          - 0 - do not permute.
9489  *          - 1 - permute cells.
9490  *          - 2 - permute nodes.
9491  *          - 3 - permute cells and nodes.
9492  *
9493  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9494  *          caller is to delete this field using decrRef() as it is no more needed. 
9495  *  \throw If no field of \a this is lying on \a mesh.
9496  *  \throw If no field values of the required parameters are available.
9497  */
9498 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9499 {
9500   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9501   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9502   if(!myF1TSC)
9503     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9504   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9505   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9506   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9507   return ret.retn();
9508 }
9509
9510 /*!
9511  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9512  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9513  * This method is useful for MED2 file format when field on different mesh was autorized.
9514  */
9515 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9516 {
9517   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9518   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9519   if(!myF1TSC)
9520     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9521   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9522   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9523   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9524   return ret.retn();
9525 }
9526
9527 /*!
9528  * Returns values and a profile of the field of a given type, of a given time step,
9529  * lying on a given support.
9530  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9531  *  \param [in] type - a spatial discretization of the field.
9532  *  \param [in] iteration - the iteration number of a required time step.
9533  *  \param [in] order - the iteration order number of required time step.
9534  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9535  *  \param [in] mesh - the supporting mesh.
9536  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9537  *          field of interest lies on. If the field lies on all entities of the given
9538  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9539  *          using decrRef() as it is no more needed.  
9540  *  \param [in] glob - the global data storing profiles and localization.
9541  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9542  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9543  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9544  *  \throw If no field of \a this is lying on \a mesh.
9545  *  \throw If no field values of the required parameters are available.
9546  */
9547 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9548 {
9549   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9550   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9551   if(!myF1TSC)
9552     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9553   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9554   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9555 }
9556
9557 /*!
9558  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9559  *  \param [in] pos - a time step id.
9560  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9561  *          delete this field using decrRef() as it is no more needed.
9562  *  \throw If \a pos is not a valid time step id.
9563  */
9564 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9565 {
9566   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9567   if(!item)
9568     {
9569       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9570       throw INTERP_KERNEL::Exception(oss.str().c_str());
9571     }
9572   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9573   if(itemC)
9574     {
9575       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9576       ret->shallowCpyGlobs(*this);
9577       return ret.retn();
9578     }
9579   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9580   throw INTERP_KERNEL::Exception(oss.str().c_str());
9581 }
9582
9583 /*!
9584  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9585  * the given field is checked if its elements are sorted suitable for writing to MED file
9586  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9587  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9588  *  \param [in] field - the field to add to \a this.
9589  *  \throw If the name of \a field is empty.
9590  *  \throw If the data array of \a field is not set.
9591  *  \throw If existing time steps have different name or number of components than \a field.
9592  *  \throw If the underlying mesh of \a field has no name.
9593  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9594  */
9595 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9596 {
9597   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9598 }
9599
9600 /*!
9601  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9602  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9603  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9604  * and \a profile.
9605  *
9606  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9607  * A new profile is added only if no equal profile is missing.
9608  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9609  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9610  *  \param [in] arrOfVals - the values of the field \a field used.
9611  *  \param [in] mesh - the supporting mesh of \a field.
9612  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9613  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9614  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9615  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9616  *  \throw If the data array of \a field is not set.
9617  *  \throw If the data array of \a this is already allocated but has different number of
9618  *         components than \a field.
9619  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9620  *  \sa setFieldNoProfileSBT()
9621  */
9622 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9623 {
9624   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9625 }
9626
9627 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9628 {
9629   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9630   if(!pt)
9631     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9632   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9633   if(!ret)
9634     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 !");
9635   return ret;
9636 }
9637
9638 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9639 {
9640   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9641   if(!pt)
9642     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9643   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9644   if(!ret)
9645     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 !");
9646   return ret;
9647 }
9648
9649 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9650 {
9651   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9652 }
9653
9654 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9655 {
9656 }
9657
9658 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9659 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9660 {
9661 }
9662 catch(INTERP_KERNEL::Exception& e)
9663 { throw e; }
9664
9665 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
9666 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
9667 {
9668 }
9669 catch(INTERP_KERNEL::Exception& e)
9670 { throw e; }
9671
9672 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9673 {
9674   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9675 }
9676
9677 //= MEDFileFields
9678
9679 MEDFileFields *MEDFileFields::New()
9680 {
9681   return new MEDFileFields;
9682 }
9683
9684 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9685 {
9686   return new MEDFileFields(fileName,loadAll,0);
9687 }
9688
9689 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9690 {
9691   return new MEDFileFields(fileName,loadAll,ms);
9692 }
9693
9694 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9695 {
9696   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9697   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9698   return ret;
9699 }
9700
9701 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9702 {
9703   std::vector<const BigMemoryObject *> ret;
9704   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9705     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9706   return ret;
9707 }
9708
9709 MEDFileFields *MEDFileFields::deepCpy() const
9710 {
9711   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9712   std::size_t i=0;
9713   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9714     {
9715       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9716         ret->_fields[i]=(*it)->deepCpy();
9717     }
9718   ret->deepCpyGlobs(*this);
9719   return ret.retn();
9720 }
9721
9722 MEDFileFields *MEDFileFields::shallowCpy() const
9723 {
9724   return new MEDFileFields(*this);
9725 }
9726
9727 /*!
9728  * 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
9729  * 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.
9730  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9731  *
9732  * \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.
9733  * \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.
9734  * 
9735  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9736  */
9737 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9738 {
9739   std::set< std::pair<int,int> > s;
9740   bool firstShot=true;
9741   areThereSomeForgottenTS=false;
9742   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9743     {
9744       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9745         continue;
9746       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9747       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9748       if(firstShot)
9749         { s=s1; firstShot=false; }
9750       else
9751         {
9752           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9753           if(s!=s2)
9754             areThereSomeForgottenTS=true;
9755           s=s2;
9756         }
9757     }
9758   std::vector< std::pair<int,int> > ret;
9759   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9760   return ret;
9761 }
9762
9763 int MEDFileFields::getNumberOfFields() const
9764 {
9765   return _fields.size();
9766 }
9767
9768 std::vector<std::string> MEDFileFields::getFieldsNames() const
9769 {
9770   std::vector<std::string> ret(_fields.size());
9771   int i=0;
9772   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9773     {
9774       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9775       if(f)
9776         {
9777           ret[i]=f->getName();
9778         }
9779       else
9780         {
9781           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9782           throw INTERP_KERNEL::Exception(oss.str().c_str());
9783         }
9784     }
9785   return ret;
9786 }
9787
9788 std::vector<std::string> MEDFileFields::getMeshesNames() const
9789 {
9790   std::vector<std::string> ret;
9791   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9792     {
9793       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9794       if(cur)
9795         ret.push_back(cur->getMeshName());
9796     }
9797   return ret;
9798 }
9799
9800 std::string MEDFileFields::simpleRepr() const
9801 {
9802   std::ostringstream oss;
9803   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9804   simpleRepr(0,oss);
9805   return oss.str();
9806 }
9807
9808 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9809 {
9810   int nbOfFields=getNumberOfFields();
9811   std::string startLine(bkOffset,' ');
9812   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9813   int i=0;
9814   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9815     {
9816       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9817       if(cur)
9818         {
9819           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9820         }
9821       else
9822         {
9823           oss << startLine << "  - not defined !" << std::endl;
9824         }
9825     }
9826   i=0;
9827   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9828     {
9829       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9830       std::string chapter(17,'0'+i);
9831       oss << startLine << chapter << std::endl;
9832       if(cur)
9833         {
9834           cur->simpleRepr(bkOffset+2,oss,i);
9835         }
9836       else
9837         {
9838           oss << startLine << "  - not defined !" << std::endl;
9839         }
9840       oss << startLine << chapter << std::endl;
9841     }
9842   simpleReprGlobs(oss);
9843 }
9844
9845 MEDFileFields::MEDFileFields()
9846 {
9847 }
9848
9849 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9850 try:MEDFileFieldGlobsReal(fileName)
9851 {
9852   MEDFileUtilities::CheckFileForRead(fileName);
9853   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
9854   int nbFields(MEDnField(fid));
9855   _fields.resize(nbFields);
9856   med_field_type typcha;
9857   for(int i=0;i<nbFields;i++)
9858     {
9859       std::vector<std::string> infos;
9860       std::string fieldName,dtunit;
9861       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
9862       switch(typcha)
9863       {
9864         case MED_FLOAT64:
9865           {
9866             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9867             break;
9868           }
9869         case MED_INT32:
9870           {
9871             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9872             break;
9873           }
9874         default:
9875           {
9876             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] !";
9877             throw INTERP_KERNEL::Exception(oss.str().c_str());
9878           }
9879       }
9880     }
9881   loadAllGlobals(fid);
9882 }
9883 catch(INTERP_KERNEL::Exception& e)
9884 {
9885     throw e;
9886 }
9887
9888 void MEDFileFields::writeLL(med_idt fid) const
9889 {
9890   int i=0;
9891   writeGlobals(fid,*this);
9892   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9893     {
9894       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9895       if(!elt)
9896         {
9897           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9898           throw INTERP_KERNEL::Exception(oss.str().c_str());
9899         }
9900       elt->writeLL(fid,*this);
9901     }
9902 }
9903
9904 void MEDFileFields::write(const std::string& fileName, int mode) const
9905 {
9906   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9907   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
9908   writeLL(fid);
9909 }
9910
9911 /*!
9912  * This method alloc the arrays and load potentially huge arrays contained in this field.
9913  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9914  * This method can be also called to refresh or reinit values from a file.
9915  * 
9916  * \throw If the fileName is not set or points to a non readable MED file.
9917  */
9918 void MEDFileFields::loadArrays()
9919 {
9920   if(getFileName().empty())
9921     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9922   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9923   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9924     {
9925       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9926       if(elt)
9927         elt->loadBigArraysRecursively(fid,*elt);
9928     }
9929 }
9930
9931 /*!
9932  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9933  * But once data loaded once, this method does nothing.
9934  * 
9935  * \throw If the fileName is not set or points to a non readable MED file.
9936  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9937  */
9938 void MEDFileFields::loadArraysIfNecessary()
9939 {
9940   if(!getFileName().empty())
9941     {
9942       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9943       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9944         {
9945           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9946           if(elt)
9947             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9948         }
9949     }
9950 }
9951
9952 /*!
9953  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9954  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9955  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9956  * 
9957  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9958  */
9959 void MEDFileFields::unloadArrays()
9960 {
9961   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9962     {
9963       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9964       if(elt)
9965         elt->unloadArrays();
9966     }
9967 }
9968
9969 /*!
9970  * 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.
9971  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9972  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9973  * 
9974  * \sa MEDFileFields::loadArraysIfNecessary
9975  */
9976 void MEDFileFields::unloadArraysWithoutDataLoss()
9977 {
9978   if(!getFileName().empty())
9979     unloadArrays();
9980 }
9981
9982 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9983 {
9984   std::vector<std::string> ret;
9985   std::set<std::string> ret2;
9986   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9987     {
9988       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9989       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9990         if(ret2.find(*it2)==ret2.end())
9991           {
9992             ret.push_back(*it2);
9993             ret2.insert(*it2);
9994           }
9995     }
9996   return ret;
9997 }
9998
9999 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10000 {
10001   std::vector<std::string> ret;
10002   std::set<std::string> ret2;
10003   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10004     {
10005       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10006       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10007         if(ret2.find(*it2)==ret2.end())
10008           {
10009             ret.push_back(*it2);
10010             ret2.insert(*it2);
10011           }
10012     }
10013   return ret;
10014 }
10015
10016 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10017 {
10018   std::vector<std::string> ret;
10019   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10020     {
10021       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10022       ret.insert(ret.end(),tmp.begin(),tmp.end());
10023     }
10024   return ret;
10025 }
10026
10027 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10028 {
10029   std::vector<std::string> ret;
10030   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10031     {
10032       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10033       ret.insert(ret.end(),tmp.begin(),tmp.end());
10034     }
10035   return ret;
10036 }
10037
10038 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10039 {
10040   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10041     (*it)->changePflsRefsNamesGen2(mapOfModif);
10042 }
10043
10044 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10045 {
10046   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10047     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10048 }
10049
10050 void MEDFileFields::resize(int newSize)
10051 {
10052   _fields.resize(newSize);
10053 }
10054
10055 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10056 {
10057   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10058     pushField(*it);
10059 }
10060
10061 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10062 {
10063   if(!field)
10064     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10065   _fields.push_back(field->getContent());
10066   appendGlobs(*field,1e-12);
10067 }
10068
10069 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10070 {
10071   if(!field)
10072     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10073   if(i>=(int)_fields.size())
10074     _fields.resize(i+1);
10075   _fields[i]=field->getContent();
10076   appendGlobs(*field,1e-12);
10077 }
10078
10079 void MEDFileFields::destroyFieldAtPos(int i)
10080 {
10081   destroyFieldsAtPos(&i,&i+1);
10082 }
10083
10084 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10085 {
10086   std::vector<bool> b(_fields.size(),true);
10087   for(const int *i=startIds;i!=endIds;i++)
10088     {
10089       if(*i<0 || *i>=(int)_fields.size())
10090         {
10091           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10092           throw INTERP_KERNEL::Exception(oss.str().c_str());
10093         }
10094       b[*i]=false;
10095     }
10096   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10097   std::size_t j=0;
10098   for(std::size_t i=0;i<_fields.size();i++)
10099     if(b[i])
10100       fields[j++]=_fields[i];
10101   _fields=fields;
10102 }
10103
10104 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10105 {
10106   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10107   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10108   std::vector<bool> b(_fields.size(),true);
10109   int k=bg;
10110   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10111     {
10112       if(k<0 || k>=(int)_fields.size())
10113         {
10114           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10115           throw INTERP_KERNEL::Exception(oss.str().c_str());
10116         }
10117       b[k]=false;
10118     }
10119   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10120   std::size_t j=0;
10121   for(std::size_t i=0;i<_fields.size();i++)
10122     if(b[i])
10123       fields[j++]=_fields[i];
10124   _fields=fields;
10125 }
10126
10127 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10128 {
10129   bool ret=false;
10130   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10131     {
10132       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10133       if(cur)
10134         ret=cur->changeMeshNames(modifTab) || ret;
10135     }
10136   return ret;
10137 }
10138
10139 /*!
10140  * \param [in] meshName the name of the mesh that will be renumbered.
10141  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10142  *             This code corresponds to the distribution of types in the corresponding mesh.
10143  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10144  * \param [in] renumO2N the old to new renumber array.
10145  * \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 
10146  *         field in \a this.
10147  */
10148 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10149 {
10150   bool ret=false;
10151   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10152     {
10153       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10154       if(fmts)
10155         {
10156           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10157         }
10158     }
10159   return ret;
10160 }
10161
10162 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10163 {
10164   if(i<0 || i>=(int)_fields.size())
10165     {
10166       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10167       throw INTERP_KERNEL::Exception(oss.str().c_str());
10168     }
10169   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10170   if(!fmts)
10171     return 0;
10172   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
10173   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10174   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10175   if(fmtsC)
10176     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10177   else if(fmtsC2)
10178     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10179   else
10180     {
10181       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10182       throw INTERP_KERNEL::Exception(oss.str().c_str());
10183     }
10184   ret->shallowCpyGlobs(*this);
10185   return ret.retn();
10186 }
10187
10188 /*!
10189  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10190  * This method is accessible in python using __getitem__ with a list in input.
10191  * \return a new object that the caller should deal with.
10192  */
10193 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10194 {
10195   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
10196   std::size_t sz=std::distance(startIds,endIds);
10197   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10198   int j=0;
10199   for(const int *i=startIds;i!=endIds;i++,j++)
10200     {
10201       if(*i<0 || *i>=(int)_fields.size())
10202         {
10203           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10204           throw INTERP_KERNEL::Exception(oss.str().c_str());
10205         }
10206       fields[j]=_fields[*i];
10207     }
10208   ret->_fields=fields;
10209   return ret.retn();
10210 }
10211
10212 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10213 {
10214   return getFieldAtPos(getPosFromFieldName(fieldName));
10215 }
10216
10217 /*!
10218  * This method removes, if any, fields in \a this having no time steps.
10219  * 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.
10220  * 
10221  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10222  */
10223 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10224 {
10225   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10226   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10227     {
10228       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10229       if(elt)
10230         {
10231           if(elt->getNumberOfTS()>0)
10232             newFields.push_back(*it);
10233         }
10234     }
10235   if(_fields.size()==newFields.size())
10236     return false;
10237   _fields=newFields;
10238   return true;
10239 }
10240
10241 /*!
10242  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10243  * This method can be seen as a filter applied on \a this, that returns an object containing
10244  * 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
10245  * shallow copied from \a this.
10246  * 
10247  * \param [in] meshName - the name of the mesh on w
10248  * \return a new object that the caller should deal with.
10249  */
10250 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10251 {
10252   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10253   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10254     {
10255       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10256       if(!cur)
10257         continue;
10258       if(cur->getMeshName()==meshName)
10259         {
10260           cur->incrRef();
10261           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10262           ret->_fields.push_back(cur2);
10263         }
10264     }
10265   ret->shallowCpyOnlyUsedGlobs(*this);
10266   return ret.retn();
10267 }
10268
10269 /*!
10270  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10271  * Input time steps are specified using a pair of integer (iteration, order).
10272  * 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,
10273  * but for each multitimestep only the time steps in \a timeSteps are kept.
10274  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10275  * 
10276  * The returned object points to shallow copy of elements in \a this.
10277  * 
10278  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10279  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10280  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10281  */
10282 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10283 {
10284   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10285   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10286     {
10287       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10288       if(!cur)
10289         continue;
10290       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10291       ret->_fields.push_back(elt);
10292     }
10293   ret->shallowCpyOnlyUsedGlobs(*this);
10294   return ret.retn();
10295 }
10296
10297 /*!
10298  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10299  */
10300 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10301 {
10302   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10303   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10304     {
10305       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10306       if(!cur)
10307         continue;
10308       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10309       if(elt->getNumberOfTS()!=0)
10310         ret->_fields.push_back(elt);
10311     }
10312   ret->shallowCpyOnlyUsedGlobs(*this);
10313   return ret.retn();
10314 }
10315
10316 MEDFileFieldsIterator *MEDFileFields::iterator()
10317 {
10318   return new MEDFileFieldsIterator(this);
10319 }
10320
10321 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10322 {
10323   std::string tmp(fieldName);
10324   std::vector<std::string> poss;
10325   for(std::size_t i=0;i<_fields.size();i++)
10326     {
10327       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10328       if(f)
10329         {
10330           std::string fname(f->getName());
10331           if(tmp==fname)
10332             return i;
10333           else
10334             poss.push_back(fname);
10335         }
10336     }
10337   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10338   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10339   oss << " !";
10340   throw INTERP_KERNEL::Exception(oss.str().c_str());
10341 }
10342
10343 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10344 {
10345   if(fs)
10346     {
10347       fs->incrRef();
10348       _nb_iter=fs->getNumberOfFields();
10349     }
10350 }
10351
10352 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10353 {
10354 }
10355
10356 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10357 {
10358   if(_iter_id<_nb_iter)
10359     {
10360       MEDFileFields *fs(_fs);
10361       if(fs)
10362         return fs->getFieldAtPos(_iter_id++);
10363       else
10364         return 0;
10365     }
10366   else
10367     return 0;
10368 }