Salome HOME
Copyrights update 2015.
[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   return ret.retn();
6747 }
6748
6749 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6750 {
6751   if(!((DataArray *)arr))
6752     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6753   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6754   if(!arrC)
6755     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6756   arrC->incrRef();
6757   return arrC;
6758 }
6759
6760 /*!
6761  * Returns a new MEDCouplingFieldDouble of a given type lying on
6762  * the top level cells of the first mesh in MED file. If \a this field 
6763  * has not been constructed via file reading, an exception is thrown.
6764  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6765  *  \param [in] type - a spatial discretization of interest.
6766  *  \param [out] arrOut - the DataArrayInt containing values of field.
6767  *  \param [in] renumPol - specifies how to permute values of the result field according to
6768  *          the optional numbers of cells and nodes, if any. The valid values are
6769  *          - 0 - do not permute.
6770  *          - 1 - permute cells.
6771  *          - 2 - permute nodes.
6772  *          - 3 - permute cells and nodes.
6773  *
6774  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6775  *          caller is to delete this field using decrRef() as it is no more needed. 
6776  *  \throw If \a this field has not been constructed via file reading.
6777  *  \throw If the MED file is not readable.
6778  *  \throw If there is no mesh in the MED file.
6779  *  \throw If no field values of the given \a type.
6780  *  \throw If no field values lying on the top level support.
6781  *  \sa getFieldAtLevel()
6782  */
6783 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6784 {
6785   if(getFileName().empty())
6786     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6787   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6788   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6789   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6790   return ret.retn();
6791 }
6792
6793 /*!
6794  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6795  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6796  *  \param [in] type - a spatial discretization of the new field.
6797  *  \param [in] mesh - the supporting mesh.
6798  *  \param [out] arrOut - the DataArrayInt containing values of field.
6799  *  \param [in] renumPol - specifies how to permute values of the result field according to
6800  *          the optional numbers of cells and nodes, if any. The valid values are
6801  *          - 0 - do not permute.
6802  *          - 1 - permute cells.
6803  *          - 2 - permute nodes.
6804  *          - 3 - permute cells and nodes.
6805  *
6806  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6807  *          caller is to delete this field using decrRef() as it is no more needed. 
6808  *  \throw If no field of \a this is lying on \a mesh.
6809  *  \throw If the mesh is empty.
6810  *  \throw If no field values of the given \a type are available.
6811  *  \sa getFieldAtLevel()
6812  *  \sa getFieldOnMeshAtLevel() 
6813  */
6814 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6815 {
6816   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6817   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6818   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6819   return ret.retn();
6820 }
6821
6822 /*!
6823  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6824  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6825  *  \param [in] type - a spatial discretization of interest.
6826  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6827  *  \param [out] arrOut - the DataArrayInt containing values of field.
6828  *  \param [in] mesh - the supporting mesh.
6829  *  \param [in] renumPol - specifies how to permute values of the result field according to
6830  *          the optional numbers of cells and nodes, if any. The valid values are
6831  *          - 0 - do not permute.
6832  *          - 1 - permute cells.
6833  *          - 2 - permute nodes.
6834  *          - 3 - permute cells and nodes.
6835  *
6836  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6837  *          caller is to delete this field using decrRef() as it is no more needed. 
6838  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6839  *  \throw If no field of \a this is lying on \a mesh.
6840  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6841  *  \sa getFieldAtLevel()
6842  *  \sa getFieldOnMeshAtLevel() 
6843  */
6844 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6845 {
6846   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6847   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6848   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6849   return ret.retn();
6850 }
6851
6852 /*!
6853  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6854  * This method is called "Old" because in MED3 norm a field has only one meshName
6855  * attached, so this method is for readers of MED2 files. If \a this field 
6856  * has not been constructed via file reading, an exception is thrown.
6857  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6858  *  \param [in] type - a spatial discretization of interest.
6859  *  \param [in] mName - a name of the supporting mesh.
6860  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6861  *  \param [out] arrOut - the DataArrayInt containing values of field.
6862  *  \param [in] renumPol - specifies how to permute values of the result field according to
6863  *          the optional numbers of cells and nodes, if any. The valid values are
6864  *          - 0 - do not permute.
6865  *          - 1 - permute cells.
6866  *          - 2 - permute nodes.
6867  *          - 3 - permute cells and nodes.
6868  *
6869  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6870  *          caller is to delete this field using decrRef() as it is no more needed. 
6871  *  \throw If the MED file is not readable.
6872  *  \throw If there is no mesh named \a mName in the MED file.
6873  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6874  *  \throw If \a this field has not been constructed via file reading.
6875  *  \throw If no field of \a this is lying on the mesh named \a mName.
6876  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6877  *  \sa getFieldAtLevel()
6878  */
6879 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6880 {
6881   if(getFileName().empty())
6882     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6883   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6884   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6885   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6886   return ret.retn();
6887 }
6888
6889 /*!
6890  * Returns values and a profile of the field of a given type lying on a given support.
6891  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6892  *  \param [in] type - a spatial discretization of the field.
6893  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6894  *  \param [in] mesh - the supporting mesh.
6895  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6896  *          field of interest lies on. If the field lies on all entities of the given
6897  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6898  *          using decrRef() as it is no more needed.  
6899  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6900  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6901  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6902  *  \throw If no field of \a this is lying on \a mesh.
6903  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6904  */
6905 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6906 {
6907   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6908   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6909 }
6910
6911 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
6912 {
6913   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6914   if(!pt)
6915     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6916   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6917   if(!ret)
6918     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 !");
6919   return ret;
6920 }
6921
6922 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
6923 {
6924   return contentNotNull()->getUndergroundDataArrayInt();
6925 }
6926
6927 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6928
6929 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6930 {
6931 }
6932
6933 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
6934 {
6935 }
6936
6937 /*!
6938  * \param [in] fieldId field id in C mode
6939  */
6940 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
6941 {
6942   med_field_type typcha;
6943   std::string dtunitOut;
6944   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6945   setDtUnit(dtunitOut.c_str());
6946   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms);
6947 }
6948
6949 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)
6950 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6951 {
6952   setDtUnit(dtunit.c_str());
6953   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms);
6954 }
6955 catch(INTERP_KERNEL::Exception& e)
6956 {
6957     throw e;
6958 }
6959
6960 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
6961 {
6962   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
6963   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6964     ret+=(*it).capacity();
6965   return ret;
6966 }
6967
6968 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
6969 {
6970   std::vector<const BigMemoryObject *> ret;
6971   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6972     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
6973   return ret;
6974 }
6975
6976 /*!
6977  * 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
6978  * NULL.
6979  */
6980 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
6981 {
6982   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6983   ret->setInfo(_infos);
6984   int sz=(int)_time_steps.size();
6985   for(const int *id=startIds;id!=endIds;id++)
6986     {
6987       if(*id>=0 && *id<sz)
6988         {
6989           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6990           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6991           if(tse)
6992             {
6993               tse->incrRef();
6994               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6995             }
6996           ret->pushBackTimeStep(tse2);
6997         }
6998       else
6999         {
7000           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7001           oss << " ! Should be in [0," << sz << ") !";
7002           throw INTERP_KERNEL::Exception(oss.str().c_str());
7003         }
7004     }
7005   if(ret->getNumberOfTS()>0)
7006     ret->synchronizeNameScope();
7007   ret->copyNameScope(*this);
7008   return ret.retn();
7009 }
7010
7011 /*!
7012  * 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
7013  * NULL.
7014  */
7015 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7016 {
7017   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7018   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7019   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7020   ret->setInfo(_infos);
7021   int sz=(int)_time_steps.size();
7022   int j=bg;
7023   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7024     {
7025       if(j>=0 && j<sz)
7026         {
7027           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7028           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7029           if(tse)
7030             {
7031               tse->incrRef();
7032               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7033             }
7034           ret->pushBackTimeStep(tse2);
7035         }
7036       else
7037         {
7038           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7039           oss << " ! Should be in [0," << sz << ") !";
7040           throw INTERP_KERNEL::Exception(oss.str().c_str());
7041         }
7042     }
7043   if(ret->getNumberOfTS()>0)
7044     ret->synchronizeNameScope();
7045   ret->copyNameScope(*this);
7046   return ret.retn();
7047 }
7048
7049 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7050 {
7051   int id=0;
7052   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7053   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7054     {
7055       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7056       if(!cur)
7057         continue;
7058       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7059       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7060         ids->pushBackSilent(id);
7061     }
7062   return buildFromTimeStepIds(ids->begin(),ids->end());
7063 }
7064
7065 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7066 {
7067   int id=0;
7068   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7069   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7070     {
7071       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7072       if(!cur)
7073         continue;
7074       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7075       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7076         ids->pushBackSilent(id);
7077     }
7078   return buildFromTimeStepIds(ids->begin(),ids->end());
7079 }
7080
7081 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7082 {
7083   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7084     {
7085       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7086       if(!cur)
7087         continue;
7088       if(cur->presenceOfMultiDiscPerGeoType())
7089         return true;
7090     }
7091   return false;
7092 }
7093
7094 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7095 {
7096   return _infos;
7097 }
7098
7099 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7100 {
7101   _infos=info;
7102 }
7103
7104 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7105 {
7106   int ret=0;
7107   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7108     {
7109       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7110       if(pt->isDealingTS(iteration,order))
7111         return ret;
7112     }
7113   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7114   std::vector< std::pair<int,int> > vp=getIterations();
7115   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7116     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7117   throw INTERP_KERNEL::Exception(oss.str().c_str());
7118 }
7119
7120 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7121 {
7122   return *_time_steps[getTimeStepPos(iteration,order)];
7123 }
7124
7125 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7126 {
7127   return *_time_steps[getTimeStepPos(iteration,order)];
7128 }
7129
7130 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7131 {
7132   if(_time_steps.empty())
7133     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7134   return _time_steps[0]->getMeshName();
7135 }
7136
7137 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7138 {
7139   std::string oldName(getMeshName());
7140   std::vector< std::pair<std::string,std::string> > v(1);
7141   v[0].first=oldName; v[0].second=newMeshName;
7142   changeMeshNames(v);
7143 }
7144
7145 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7146 {
7147   bool ret=false;
7148   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7149     {
7150       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7151       if(cur)
7152         ret=cur->changeMeshNames(modifTab) || ret;
7153     }
7154   return ret;
7155 }
7156
7157 /*!
7158  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7159  */
7160 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7161 {
7162   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7163 }
7164
7165 /*!
7166  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7167  */
7168 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7169 {
7170   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7171 }
7172
7173 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7174                                                                        MEDFileFieldGlobsReal& glob)
7175 {
7176   bool ret=false;
7177   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7178     {
7179       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7180       if(f1ts)
7181         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7182     }
7183   return ret;
7184 }
7185
7186 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7187 {
7188   std::string startLine(bkOffset,' ');
7189   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7190   if(fmtsId>=0)
7191     oss << " (" << fmtsId << ")";
7192   oss << " has the following name: \"" << _name << "\"." << std::endl;
7193   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7194   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7195     {
7196       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7197     }
7198   int i=0;
7199   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7200     {
7201       std::string chapter(17,'0'+i);
7202       oss << startLine << chapter << std::endl;
7203       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7204       if(cur)
7205         cur->simpleRepr(bkOffset+2,oss,i);
7206       else
7207         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7208       oss << startLine << chapter << std::endl;
7209     }
7210 }
7211
7212 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7213 {
7214   std::size_t sz=_time_steps.size();
7215   std::vector< std::pair<int,int> > ret(sz);
7216   ret1.resize(sz);
7217   for(std::size_t i=0;i<sz;i++)
7218     {
7219       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7220       if(f1ts)
7221         {
7222           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7223         }
7224       else
7225         {
7226           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7227           throw INTERP_KERNEL::Exception(oss.str().c_str());
7228         }
7229     }
7230   return ret;
7231 }
7232
7233 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7234 {
7235   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7236   if(!tse2)
7237     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7238   checkCoherencyOfType(tse2);
7239   if(_time_steps.empty())
7240     {
7241       setName(tse2->getName().c_str());
7242       setInfo(tse2->getInfo());
7243     }
7244   checkThatComponentsMatch(tse2->getInfo());
7245   _time_steps.push_back(tse);
7246 }
7247
7248 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7249 {
7250   std::size_t nbOfCompo=_infos.size();
7251   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7252     {
7253       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7254       if(cur)
7255         {
7256           if((cur->getInfo()).size()!=nbOfCompo)
7257             {
7258               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7259               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7260               throw INTERP_KERNEL::Exception(oss.str().c_str());
7261             }
7262           cur->copyNameScope(*this);
7263         }
7264     }
7265 }
7266
7267 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms)
7268 {
7269   _time_steps.resize(nbPdt);
7270   for(int i=0;i<nbPdt;i++)
7271     {
7272       std::vector< std::pair<int,int> > ts;
7273       med_int numdt=0,numo=0;
7274       med_int meshIt=0,meshOrder=0;
7275       med_float dt=0.0;
7276       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
7277       switch(fieldTyp)
7278       {
7279         case MED_FLOAT64:
7280           {
7281             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7282             break;
7283           }
7284         case MED_INT32:
7285           {
7286             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7287             break;
7288           }
7289         default:
7290           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7291       }
7292       if(loadAll)
7293         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms);
7294       else
7295         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms);
7296     }
7297 }
7298
7299 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7300 {
7301   if(_time_steps.empty())
7302     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7303   checkThatNbOfCompoOfTSMatchThis();
7304   std::vector<std::string> infos(getInfo());
7305   int nbComp=infos.size();
7306   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7307   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7308   for(int i=0;i<nbComp;i++)
7309     {
7310       std::string info=infos[i];
7311       std::string c,u;
7312       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7313       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7314       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7315     }
7316   if(_name.empty())
7317     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7318   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7319   int nbOfTS=_time_steps.size();
7320   for(int i=0;i<nbOfTS;i++)
7321     _time_steps[i]->writeLL(fid,opts,*this);
7322 }
7323
7324 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7325 {
7326   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7327     {
7328       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7329       if(elt)
7330         elt->loadBigArraysRecursively(fid,nasc);
7331     }
7332 }
7333
7334 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7335 {
7336   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7337     {
7338       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7339       if(elt)
7340         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7341     }
7342 }
7343
7344 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7345 {
7346   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7347     {
7348       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7349       if(elt)
7350         elt->unloadArrays();
7351     }
7352 }
7353
7354 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7355 {
7356   return _time_steps.size();
7357 }
7358
7359 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7360 {
7361   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7362   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7363     {
7364       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7365       if(tmp)
7366         newTS.push_back(*it);
7367     }
7368   _time_steps=newTS;
7369 }
7370
7371 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7372 {
7373   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7374   int maxId=(int)_time_steps.size();
7375   int ii=0;
7376   std::set<int> idsToDel;
7377   for(const int *id=startIds;id!=endIds;id++,ii++)
7378     {
7379       if(*id>=0 && *id<maxId)
7380         {
7381           idsToDel.insert(*id);
7382         }
7383       else
7384         {
7385           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7386           throw INTERP_KERNEL::Exception(oss.str().c_str());
7387         }
7388     }
7389   for(int iii=0;iii<maxId;iii++)
7390     if(idsToDel.find(iii)==idsToDel.end())
7391       newTS.push_back(_time_steps[iii]);
7392   _time_steps=newTS;
7393 }
7394
7395 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7396 {
7397   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7398   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7399   if(nbOfEntriesToKill==0)
7400     return ;
7401   std::size_t sz=_time_steps.size();
7402   std::vector<bool> b(sz,true);
7403   int j=bg;
7404   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7405     b[j]=false;
7406   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7407   for(std::size_t i=0;i<sz;i++)
7408     if(b[i])
7409       newTS.push_back(_time_steps[i]);
7410   _time_steps=newTS;
7411 }
7412
7413 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7414 {
7415   int ret=0;
7416   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7417   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7418     {
7419       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7420       if(tmp)
7421         {
7422           int it2,ord;
7423           tmp->getTime(it2,ord);
7424           if(it2==iteration && order==ord)
7425             return ret;
7426           else
7427             oss << "(" << it2 << ","  << ord << "), ";
7428         }
7429     }
7430   throw INTERP_KERNEL::Exception(oss.str().c_str());
7431 }
7432
7433 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7434 {
7435   int ret=0;
7436   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7437   oss.precision(15);
7438   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7439     {
7440       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7441       if(tmp)
7442         {
7443           int it2,ord;
7444           double ti=tmp->getTime(it2,ord);
7445           if(fabs(time-ti)<eps)
7446             return ret;
7447           else
7448             oss << ti << ", ";
7449         }
7450     }
7451   throw INTERP_KERNEL::Exception(oss.str().c_str());
7452 }
7453
7454 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7455 {
7456   int lgth=_time_steps.size();
7457   std::vector< std::pair<int,int> > ret(lgth);
7458   for(int i=0;i<lgth;i++)
7459     _time_steps[i]->fillIteration(ret[i]);
7460   return ret;
7461 }
7462
7463 /*!
7464  * 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'
7465  * This method returns two things.
7466  * - The absolute dimension of 'this' in first parameter. 
7467  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7468  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7469  *
7470  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7471  * Only these 3 discretizations will be taken into account here.
7472  *
7473  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7474  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7475  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7476  *
7477  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7478  * 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'.
7479  * 
7480  * Let's consider the typical following case :
7481  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7482  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7483  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7484  *   TETRA4 and SEG2
7485  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7486  *
7487  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7488  * 
7489  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7490  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7491  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7492  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7493  */
7494 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7495 {
7496   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7497 }
7498
7499 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7500 {
7501   if(pos<0 || pos>=(int)_time_steps.size())
7502     {
7503       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7504       throw INTERP_KERNEL::Exception(oss.str().c_str());
7505     }
7506   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7507   if(item==0)
7508     {
7509       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7510       oss << "\nTry to use following method eraseEmptyTS !";
7511       throw INTERP_KERNEL::Exception(oss.str().c_str());
7512     }
7513   return item;
7514 }
7515
7516 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7517 {
7518   if(pos<0 || pos>=(int)_time_steps.size())
7519     {
7520       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7521       throw INTERP_KERNEL::Exception(oss.str().c_str());
7522     }
7523   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7524   if(item==0)
7525     {
7526       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7527       oss << "\nTry to use following method eraseEmptyTS !";
7528       throw INTERP_KERNEL::Exception(oss.str().c_str());
7529     }
7530   return item;
7531 }
7532
7533 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7534 {
7535   std::vector<std::string> ret;
7536   std::set<std::string> ret2;
7537   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7538     {
7539       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7540       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7541         if(ret2.find(*it2)==ret2.end())
7542           {
7543             ret.push_back(*it2);
7544             ret2.insert(*it2);
7545           }
7546     }
7547   return ret;
7548 }
7549
7550 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7551 {
7552   std::vector<std::string> ret;
7553   std::set<std::string> ret2;
7554   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7555     {
7556       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7557       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7558         if(ret2.find(*it2)==ret2.end())
7559           {
7560             ret.push_back(*it2);
7561             ret2.insert(*it2);
7562           }
7563     }
7564   return ret;
7565 }
7566
7567 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7568 {
7569   std::vector<std::string> ret;
7570   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7571     {
7572       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7573       ret.insert(ret.end(),tmp.begin(),tmp.end());
7574     }
7575   return ret;
7576 }
7577
7578 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7579 {
7580   std::vector<std::string> ret;
7581   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7582     {
7583       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7584       ret.insert(ret.end(),tmp.begin(),tmp.end());
7585     }
7586   return ret;
7587 }
7588
7589 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7590 {
7591   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7592     (*it)->changePflsRefsNamesGen2(mapOfModif);
7593 }
7594
7595 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7596 {
7597   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7598     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7599 }
7600
7601 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7602 {
7603   int lgth=_time_steps.size();
7604   std::vector< std::vector<TypeOfField> > ret(lgth);
7605   for(int i=0;i<lgth;i++)
7606     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7607   return ret;
7608 }
7609
7610 /*!
7611  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7612  */
7613 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
7614 {
7615   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7616 }
7617
7618 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7619 {
7620   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7621   std::size_t i=0;
7622   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7623     {
7624       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7625         ret->_time_steps[i]=(*it)->deepCpy();
7626     }
7627   return ret.retn();
7628 }
7629
7630 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7631 {
7632   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7633   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7634   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7635   for(std::size_t i=0;i<sz;i++)
7636     {
7637       ret[i]=shallowCpy();
7638       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7639     }
7640   for(std::size_t i=0;i<sz2;i++)
7641     {
7642       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7643       if(ret1.size()!=sz)
7644         {
7645           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7646           throw INTERP_KERNEL::Exception(oss.str().c_str());
7647         }
7648       ts[i]=ret1;
7649     }
7650   for(std::size_t i=0;i<sz;i++)
7651     for(std::size_t j=0;j<sz2;j++)
7652       ret[i]->_time_steps[j]=ts[j][i];
7653   return ret;
7654 }
7655
7656 /*!
7657  * This method splits into discretization each time steps in \a this.
7658  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7659  */
7660 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7661 {
7662   std::size_t sz(_time_steps.size());
7663   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7664   for(std::size_t i=0;i<sz;i++)
7665     {
7666       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7667       if(!timeStep)
7668         {
7669           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7670           throw INTERP_KERNEL::Exception(oss.str().c_str());
7671         }
7672       items[i]=timeStep->splitDiscretizations();  
7673     }
7674   //
7675   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7676   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7677   std::vector< TypeOfField > types;
7678   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7679     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7680       {
7681         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7682         if(ts.size()!=1)
7683           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7684         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7685         if(it2==types.end())
7686           types.push_back(ts[0]);
7687       }
7688   ret.resize(types.size()); ret2.resize(types.size());
7689   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7690     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7691       {
7692         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7693         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7694         ret2[pos].push_back(*it1);
7695       }
7696   for(std::size_t i=0;i<types.size();i++)
7697     {
7698       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7699       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7700         elt->pushBackTimeStep(*it1);//also updates infos in elt
7701       ret[i]=elt;
7702       elt->MEDFileFieldNameScope::operator=(*this);
7703     }
7704   return ret;
7705 }
7706
7707 /*!
7708  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7709  */
7710 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7711 {
7712   std::size_t sz(_time_steps.size());
7713   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7714   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7715   for(std::size_t i=0;i<sz;i++)
7716     {
7717       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7718       if(!timeStep)
7719         {
7720           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7721           throw INTERP_KERNEL::Exception(oss.str().c_str());
7722         }
7723       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7724       if(szOut==std::numeric_limits<std::size_t>::max())
7725         szOut=items[i].size();
7726       else
7727         if(items[i].size()!=szOut)
7728           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7729     }
7730   if(szOut==std::numeric_limits<std::size_t>::max())
7731     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7732   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7733   for(std::size_t i=0;i<szOut;i++)
7734     {
7735       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7736       for(std::size_t j=0;j<sz;j++)
7737         elt->pushBackTimeStep(items[j][i]);
7738       ret[i]=elt;
7739       elt->MEDFileFieldNameScope::operator=(*this);
7740     }
7741   return ret;
7742 }
7743
7744 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7745 {
7746   _name=field->getName();
7747   if(_name.empty())
7748     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7749   if(!arr)
7750     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7751   _infos=arr->getInfoOnComponents();
7752 }
7753
7754 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7755 {
7756   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7757   if(_name!=field->getName())
7758     {
7759       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7760       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7761       throw INTERP_KERNEL::Exception(oss.str().c_str());
7762     }
7763   if(!arr)
7764     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7765   checkThatComponentsMatch(arr->getInfoOnComponents());
7766 }
7767
7768 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7769 {
7770   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7771   if(getInfo().size()!=compos.size())
7772     {
7773       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7774       oss << " number of components of element to append (" << compos.size() << ") !";
7775       throw INTERP_KERNEL::Exception(oss.str().c_str());
7776     }
7777   if(_infos!=compos)
7778     {
7779       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7780       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7781       oss << " But compo in input fields are : ";
7782       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7783       oss << " !";
7784       throw INTERP_KERNEL::Exception(oss.str().c_str());
7785     }
7786 }
7787
7788 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7789 {
7790   std::size_t sz=_infos.size();
7791   int j=0;
7792   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7793     {
7794       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7795       if(elt)
7796         if(elt->getInfo().size()!=sz)
7797           {
7798             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7799             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7800             throw INTERP_KERNEL::Exception(oss.str().c_str());
7801           }
7802     }
7803 }
7804
7805 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7806 {
7807   if(!field)
7808     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7809   if(!_time_steps.empty())
7810     checkCoherencyOfTinyInfo(field,arr);
7811   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7812   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7813   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7814   copyTinyInfoFrom(field,arr);
7815   _time_steps.push_back(obj);
7816 }
7817
7818 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7819 {
7820   if(!field)
7821     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7822   if(!_time_steps.empty())
7823     checkCoherencyOfTinyInfo(field,arr);
7824   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7825   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7826   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7827   copyTinyInfoFrom(field,arr);
7828   _time_steps.push_back(obj);
7829 }
7830
7831 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7832 {
7833   int sz=(int)_time_steps.size();
7834   if(i<0 || i>=sz)
7835     {
7836       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7837       throw INTERP_KERNEL::Exception(oss.str().c_str());
7838     }
7839   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7840   if(tsPtr)
7841     {
7842       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7843         {
7844           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7845           throw INTERP_KERNEL::Exception(oss.str().c_str());
7846         }
7847     }
7848   _time_steps[i]=ts;
7849 }
7850
7851 //= MEDFileFieldMultiTSWithoutSDA
7852
7853 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)
7854 {
7855   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
7856 }
7857
7858 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7859 {
7860 }
7861
7862 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7863 {
7864 }
7865
7866 /*!
7867  * \param [in] fieldId field id in C mode
7868  */
7869 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
7870 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
7871 {
7872 }
7873 catch(INTERP_KERNEL::Exception& e)
7874 { throw e; }
7875
7876 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)
7877 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
7878 {
7879 }
7880 catch(INTERP_KERNEL::Exception& e)
7881 { throw e; }
7882
7883 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7884 {
7885   return new MEDFileField1TSWithoutSDA;
7886 }
7887
7888 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7889 {
7890   if(!f1ts)
7891     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7892   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7893   if(!f1tsC)
7894     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7895 }
7896
7897 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7898 {
7899   return MEDFileField1TSWithoutSDA::TYPE_STR;
7900 }
7901
7902 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7903 {
7904   return new MEDFileFieldMultiTSWithoutSDA(*this);
7905 }
7906
7907 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7908 {
7909   return new MEDFileFieldMultiTSWithoutSDA;
7910 }
7911
7912 /*!
7913  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7914  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7915  */
7916 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
7917 {
7918   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7919   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7920   if(!myF1TSC)
7921     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7922   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7923 }
7924
7925 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
7926 {
7927   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7928   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7929   int i=0;
7930   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7931     {
7932       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7933       if(eltToConv)
7934         {
7935           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7936           if(!eltToConvC)
7937             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7938           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7939           ret->setIteration(i,elt);
7940         }
7941     }
7942   return ret.retn();
7943 }
7944
7945 //= MEDFileAnyTypeFieldMultiTS
7946
7947 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7948 {
7949 }
7950
7951 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7952 try:MEDFileFieldGlobsReal(fileName)
7953 {
7954   MEDFileUtilities::CheckFileForRead(fileName);
7955   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7956   _content=BuildContentFrom(fid,fileName,loadAll,ms);
7957   loadGlobals(fid);
7958 }
7959 catch(INTERP_KERNEL::Exception& e)
7960 {
7961     throw e;
7962 }
7963
7964 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7965 {
7966   med_field_type typcha;
7967   std::vector<std::string> infos;
7968   std::string dtunit;
7969   int i=-1;
7970   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7971   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7972   switch(typcha)
7973   {
7974     case MED_FLOAT64:
7975       {
7976         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7977         break;
7978       }
7979     case MED_INT32:
7980       {
7981         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms);
7982         break;
7983       }
7984     default:
7985       {
7986         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] !";
7987         throw INTERP_KERNEL::Exception(oss.str().c_str());
7988       }
7989   }
7990   ret->setDtUnit(dtunit.c_str());
7991   return ret.retn();
7992 }
7993
7994 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
7995 {
7996   med_field_type typcha;
7997   //
7998   std::vector<std::string> infos;
7999   std::string dtunit,fieldName;
8000   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8001   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8002   switch(typcha)
8003   {
8004     case MED_FLOAT64:
8005       {
8006         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
8007         break;
8008       }
8009     case MED_INT32:
8010       {
8011         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms);
8012         break;
8013       }
8014     default:
8015       {
8016         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] !";
8017         throw INTERP_KERNEL::Exception(oss.str().c_str());
8018       }
8019   }
8020   ret->setDtUnit(dtunit.c_str());
8021   return ret.retn();
8022 }
8023
8024 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8025 {
8026   if(!c)
8027     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8028   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8029     {
8030       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8031       ret->setFileName(fileName);
8032       ret->_content=c;  c->incrRef();
8033       return ret.retn();
8034     }
8035   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8036     {
8037       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8038       ret->setFileName(fileName);
8039       ret->_content=c;  c->incrRef();
8040       return ret.retn();
8041     }
8042   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8043 }
8044
8045 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
8046 try:MEDFileFieldGlobsReal(fileName)
8047 {
8048   MEDFileUtilities::CheckFileForRead(fileName);
8049   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8050   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
8051   loadGlobals(fid);
8052 }
8053 catch(INTERP_KERNEL::Exception& e)
8054 {
8055     throw e;
8056 }
8057
8058 //= MEDFileIntFieldMultiTSWithoutSDA
8059
8060 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)
8061 {
8062   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms);
8063 }
8064
8065 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8066 {
8067 }
8068
8069 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8070 {
8071 }
8072
8073 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)
8074 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms)
8075 {
8076 }
8077 catch(INTERP_KERNEL::Exception& e)
8078 { throw e; }
8079
8080 /*!
8081  * \param [in] fieldId field id in C mode
8082  */
8083 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms)
8084 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms)
8085 {
8086 }
8087 catch(INTERP_KERNEL::Exception& e)
8088 { throw e; }
8089
8090 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8091 {
8092   return new MEDFileIntField1TSWithoutSDA;
8093 }
8094
8095 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8096 {
8097   if(!f1ts)
8098     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8099   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8100   if(!f1tsC)
8101     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8102 }
8103
8104 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8105 {
8106   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8107 }
8108
8109 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8110 {
8111   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8112 }
8113
8114 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8115 {
8116   return new MEDFileIntFieldMultiTSWithoutSDA;
8117 }
8118
8119 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8120 {
8121   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8122   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8123   int i=0;
8124   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8125     {
8126       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8127       if(eltToConv)
8128         {
8129           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8130           if(!eltToConvC)
8131             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8132           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8133           ret->setIteration(i,elt);
8134         }
8135     }
8136   return ret.retn();
8137 }
8138
8139 //= MEDFileAnyTypeFieldMultiTS
8140
8141 /*!
8142  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8143  * that has been read from a specified MED file.
8144  *  \param [in] fileName - the name of the MED file to read.
8145  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8146  *          is to delete this field using decrRef() as it is no more needed.
8147  *  \throw If reading the file fails.
8148  */
8149 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8150 {
8151   MEDFileUtilities::CheckFileForRead(fileName);
8152   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8153   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8154   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8155   ret->loadGlobals(fid);
8156   return ret.retn();
8157 }
8158
8159 /*!
8160  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8161  * that has been read from a specified MED file.
8162  *  \param [in] fileName - the name of the MED file to read.
8163  *  \param [in] fieldName - the name of the field to read.
8164  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8165  *          is to delete this field using decrRef() as it is no more needed.
8166  *  \throw If reading the file fails.
8167  *  \throw If there is no field named \a fieldName in the file.
8168  */
8169 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8170 {
8171   MEDFileUtilities::CheckFileForRead(fileName);
8172   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8173   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
8174   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8175   ret->loadGlobals(fid);
8176   return ret.retn();
8177 }
8178
8179 /*!
8180  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8181  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8182  *
8183  * \warning this is a shallow copy constructor
8184  */
8185 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8186 {
8187   if(!shallowCopyOfContent)
8188     {
8189       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8190       otherPtr->incrRef();
8191       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8192     }
8193   else
8194     {
8195       _content=other.shallowCpy();
8196     }
8197 }
8198
8199 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8200 {
8201   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8202   if(!ret)
8203     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8204   return ret;
8205 }
8206
8207 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8208 {
8209   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8210   if(!ret)
8211     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8212   return ret;
8213 }
8214
8215 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8216 {
8217   return contentNotNullBase()->getPflsReallyUsed2();
8218 }
8219
8220 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8221 {
8222   return contentNotNullBase()->getLocsReallyUsed2();
8223 }
8224
8225 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8226 {
8227   return contentNotNullBase()->getPflsReallyUsedMulti2();
8228 }
8229
8230 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8231 {
8232   return contentNotNullBase()->getLocsReallyUsedMulti2();
8233 }
8234
8235 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8236 {
8237   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8238 }
8239
8240 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8241 {
8242   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8243 }
8244
8245 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8246 {
8247   return contentNotNullBase()->getNumberOfTS();
8248 }
8249
8250 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8251 {
8252   contentNotNullBase()->eraseEmptyTS();
8253 }
8254
8255 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8256 {
8257   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8258 }
8259
8260 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8261 {
8262   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8263 }
8264
8265 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8266 {
8267   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8268   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8269   ret->_content=c;
8270   return ret.retn();
8271 }
8272
8273 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8274 {
8275   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8276   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8277   ret->_content=c;
8278   return ret.retn();
8279 }
8280
8281 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8282 {
8283   return contentNotNullBase()->getIterations();
8284 }
8285
8286 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8287 {
8288   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8289     pushBackTimeStep(*it);
8290 }
8291
8292 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8293 {
8294   if(!f1ts)
8295     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8296   checkCoherencyOfType(f1ts);
8297   f1ts->incrRef();
8298   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8299   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8300   c->incrRef();
8301   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8302   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8303     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8304   _content->pushBackTimeStep(cSafe);
8305   appendGlobs(*f1ts,1e-12);
8306 }
8307
8308 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8309 {
8310   contentNotNullBase()->synchronizeNameScope();
8311 }
8312
8313 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8314 {
8315   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8316 }
8317
8318 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8319 {
8320   return contentNotNullBase()->getPosGivenTime(time,eps);
8321 }
8322
8323 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8324 {
8325   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8326 }
8327
8328 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8329 {
8330   return contentNotNullBase()->getTypesOfFieldAvailable();
8331 }
8332
8333 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
8334 {
8335   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8336 }
8337
8338 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8339 {
8340   return contentNotNullBase()->getName();
8341 }
8342
8343 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8344 {
8345   contentNotNullBase()->setName(name);
8346 }
8347
8348 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8349 {
8350   return contentNotNullBase()->getDtUnit();
8351 }
8352
8353 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8354 {
8355   contentNotNullBase()->setDtUnit(dtUnit);
8356 }
8357
8358 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8359 {
8360   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8361 }
8362
8363 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8364 {
8365   return contentNotNullBase()->getTimeSteps(ret1);
8366 }
8367
8368 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8369 {
8370   return contentNotNullBase()->getMeshName();
8371 }
8372
8373 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8374 {
8375   contentNotNullBase()->setMeshName(newMeshName);
8376 }
8377
8378 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8379 {
8380   return contentNotNullBase()->changeMeshNames(modifTab);
8381 }
8382
8383 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8384 {
8385   return contentNotNullBase()->getInfo();
8386 }
8387
8388 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8389 {
8390   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8391 }
8392
8393 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8394 {
8395   return contentNotNullBase()->setInfo(info);
8396 }
8397
8398 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8399 {
8400   const std::vector<std::string> ret=getInfo();
8401   return (int)ret.size();
8402 }
8403
8404 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8405 {
8406   writeGlobals(fid,*this);
8407   contentNotNullBase()->writeLL(fid,*this);
8408 }
8409
8410 /*!
8411  * Writes \a this field into a MED file specified by its name.
8412  *  \param [in] fileName - the MED file name.
8413  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8414  * - 2 - erase; an existing file is removed.
8415  * - 1 - append; same data should not be present in an existing file.
8416  * - 0 - overwrite; same data present in an existing file is overwritten.
8417  *  \throw If the field name is not set.
8418  *  \throw If no field data is set.
8419  *  \throw If \a mode == 1 and the same data is present in an existing file.
8420  */
8421 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8422 {
8423   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8424   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8425   writeLL(fid);
8426 }
8427
8428 /*!
8429  * This method alloc the arrays and load potentially huge arrays contained in this field.
8430  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8431  * This method can be also called to refresh or reinit values from a file.
8432  * 
8433  * \throw If the fileName is not set or points to a non readable MED file.
8434  */
8435 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8436 {
8437   if(getFileName().empty())
8438     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8439   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8440   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8441 }
8442
8443 /*!
8444  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8445  * But once data loaded once, this method does nothing.
8446  * 
8447  * \throw If the fileName is not set or points to a non readable MED file.
8448  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8449  */
8450 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8451 {
8452   if(!getFileName().empty())
8453     {
8454       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8455       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8456     }
8457 }
8458
8459 /*!
8460  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8461  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8462  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8463  * 
8464  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8465  */
8466 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8467 {
8468   contentNotNullBase()->unloadArrays();
8469 }
8470
8471 /*!
8472  * 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.
8473  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8474  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8475  * 
8476  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8477  */
8478 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8479 {
8480   if(!getFileName().empty())
8481     contentNotNullBase()->unloadArrays();
8482 }
8483
8484 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8485 {
8486   std::ostringstream oss;
8487   contentNotNullBase()->simpleRepr(0,oss,-1);
8488   simpleReprGlobs(oss);
8489   return oss.str();
8490 }
8491
8492 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8493 {
8494   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8495 }
8496
8497 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8498 {
8499   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8500   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8501   return ret;
8502 }
8503
8504 /*!
8505  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8506  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8507  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8508  */
8509 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8510 {
8511   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8512   if(!content)
8513     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8514   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8515   std::size_t sz(contentsSplit.size());
8516   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8517   for(std::size_t i=0;i<sz;i++)
8518     {
8519       ret[i]=shallowCpy();
8520       ret[i]->_content=contentsSplit[i];
8521     }
8522   return ret;
8523 }
8524
8525 /*!
8526  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8527  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8528  */
8529 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8530 {
8531   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8532   if(!content)
8533     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8534   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8535   std::size_t sz(contentsSplit.size());
8536   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8537   for(std::size_t i=0;i<sz;i++)
8538     {
8539       ret[i]=shallowCpy();
8540       ret[i]->_content=contentsSplit[i];
8541     }
8542   return ret;
8543 }
8544
8545 /*!
8546  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8547  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8548  */
8549 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8550 {
8551   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8552   if(!content)
8553     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8554   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8555   std::size_t sz(contentsSplit.size());
8556   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8557   for(std::size_t i=0;i<sz;i++)
8558     {
8559       ret[i]=shallowCpy();
8560       ret[i]->_content=contentsSplit[i];
8561     }
8562   return ret;
8563 }
8564
8565 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8566 {
8567   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8568   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8569     ret->_content=_content->deepCpy();
8570   ret->deepCpyGlobs(*this);
8571   return ret.retn();
8572 }
8573
8574 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8575 {
8576   return _content;
8577 }
8578
8579 /*!
8580  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8581  *  \param [in] iteration - the iteration number of a required time step.
8582  *  \param [in] order - the iteration order number of required time step.
8583  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8584  *          delete this field using decrRef() as it is no more needed.
8585  *  \throw If there is no required time step in \a this field.
8586  */
8587 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8588 {
8589   int pos=getPosOfTimeStep(iteration,order);
8590   return getTimeStepAtPos(pos);
8591 }
8592
8593 /*!
8594  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8595  *  \param [in] time - the time of the time step of interest.
8596  *  \param [in] eps - a precision used to compare time values.
8597  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8598  *          delete this field using decrRef() as it is no more needed.
8599  *  \throw If there is no required time step in \a this field.
8600  */
8601 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8602 {
8603   int pos=getPosGivenTime(time,eps);
8604   return getTimeStepAtPos(pos);
8605 }
8606
8607 /*!
8608  * 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.
8609  * The float64 value of time attached to the pair of integers are not considered here.
8610  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8611  *
8612  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8613  * \throw If there is a null pointer in \a vectFMTS.
8614  */
8615 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8616 {
8617   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8618   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8619   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8620   while(!lstFMTS.empty())
8621     {
8622       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8623       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8624       if(!curIt)
8625         throw INTERP_KERNEL::Exception(msg);
8626       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8627       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8628       elt.push_back(curIt); it=lstFMTS.erase(it);
8629       while(it!=lstFMTS.end())
8630         {
8631           curIt=*it;
8632           if(!curIt)
8633             throw INTERP_KERNEL::Exception(msg);
8634           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8635           if(refIts==curIts)
8636             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8637           else
8638             it++;
8639         }
8640       ret.push_back(elt);
8641     }
8642   return ret;
8643 }
8644
8645 /*!
8646  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8647  * All returned instances in a subvector can be safely loaded, rendered along time
8648  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8649  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8650  * 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).
8651  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8652  * 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.
8653  *
8654  * \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().
8655  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8656  * \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.
8657  * \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.
8658  *
8659  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8660  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8661  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8662  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8663  * \throw If mesh is null.
8664  * \throw If an element in \a vectFMTS is null.
8665  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8666  */
8667 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8668 {
8669   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8670   if(!mesh)
8671     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8672   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8673   if(vectFMTS.empty())
8674     return ret;
8675   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8676   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8677   if(!frstElt)
8678     throw INTERP_KERNEL::Exception(msg);
8679   std::size_t i=0;
8680   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8681   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8682   for(;it!=vectFMTS.end();it++,i++)
8683     {
8684       if(!(*it))
8685         throw INTERP_KERNEL::Exception(msg);
8686       TypeOfField tof0,tof1;
8687       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8688         {
8689           if(tof1!=ON_NODES)
8690             vectFMTSNotNodes.push_back(*it);
8691           else
8692             vectFMTSNodes.push_back(*it);
8693         }
8694       else
8695         vectFMTSNotNodes.push_back(*it);
8696     }
8697   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8698   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8699   ret=retCell;
8700   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8701     {
8702       i=0;
8703       bool isFetched(false);
8704       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8705         {
8706           if((*it0).empty())
8707             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8708           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8709             { ret[i].push_back(*it2); isFetched=true; }
8710         }
8711       if(!isFetched)
8712         {
8713           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8714           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8715           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8716         }
8717     }
8718   fsc=cmps;
8719   return ret;
8720 }
8721
8722 /*!
8723  * 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.
8724  * \param [out] cmps - same size than the returned vector.
8725  */
8726 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8727 {
8728   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8729   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8730   while(!lstFMTS.empty())
8731     {
8732       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8733       MEDFileAnyTypeFieldMultiTS *ref(*it);
8734       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8735       elt.push_back(ref); it=lstFMTS.erase(it);
8736       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8737       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8738       while(it!=lstFMTS.end())
8739         {
8740           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8741           if(cmp->isEqual(curIt))
8742             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8743           else
8744             it++;
8745         }
8746       ret.push_back(elt); cmps.push_back(cmp);
8747     }
8748   return ret;
8749 }
8750
8751 /*!
8752  * 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.
8753  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8754  *
8755  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8756  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8757  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8758  * \thorw If \a f0 and \a f1 do not have the same times steps.
8759  * \throw If mesh is null.
8760  * \throw If \a f0 or \a f1 is null.
8761  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8762  */
8763 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8764 {
8765   if(!mesh)
8766     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8767   if(!f0 || !f1)
8768     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8769   if(f0->getMeshName()!=mesh->getName())
8770     {
8771       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8772       throw INTERP_KERNEL::Exception(oss.str().c_str());
8773     }
8774   if(f1->getMeshName()!=mesh->getName())
8775     {
8776       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8777       throw INTERP_KERNEL::Exception(oss.str().c_str());
8778     }
8779   int nts=f0->getNumberOfTS();
8780   if(nts!=f1->getNumberOfTS())
8781     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8782   if(nts==0)
8783     return nts;
8784   for(int i=0;i<nts;i++)
8785     {
8786       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8787       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8788       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8789       if(tofs0.size()!=1 || tofs1.size()!=1)
8790         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8791       if(i!=0)
8792         {
8793           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8794             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8795         }
8796       else
8797         { tof0=tofs0[0]; tof1=tofs1[0]; }
8798       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8799         {
8800           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() << ") !";
8801           throw INTERP_KERNEL::Exception(oss.str().c_str());
8802         }
8803       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8804         {
8805           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() << ") !";
8806           throw INTERP_KERNEL::Exception(oss.str().c_str());
8807         }
8808       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8809         {
8810           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() << ") !";
8811           throw INTERP_KERNEL::Exception(oss.str().c_str());
8812         }
8813     }
8814   return nts;
8815 }
8816
8817 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8818 {
8819   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8820 }
8821
8822 //= MEDFileFieldMultiTS
8823
8824 /*!
8825  * Returns a new empty instance of MEDFileFieldMultiTS.
8826  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8827  *          is to delete this field using decrRef() as it is no more needed.
8828  */
8829 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8830 {
8831   return new MEDFileFieldMultiTS;
8832 }
8833
8834 /*!
8835  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8836  * that has been read from a specified MED file.
8837  *  \param [in] fileName - the name of the MED file to read.
8838  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8839  *          is to delete this field using decrRef() as it is no more needed.
8840  *  \throw If reading the file fails.
8841  */
8842 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8843 {
8844   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8845   ret->contentNotNull();//to check that content type matches with \a this type.
8846   return ret.retn();
8847 }
8848
8849 /*!
8850  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8851  * that has been read from a specified MED file.
8852  *  \param [in] fileName - the name of the MED file to read.
8853  *  \param [in] fieldName - the name of the field to read.
8854  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8855  *          is to delete this field using decrRef() as it is no more needed.
8856  *  \throw If reading the file fails.
8857  *  \throw If there is no field named \a fieldName in the file.
8858  */
8859 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8860 {
8861   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
8862   ret->contentNotNull();//to check that content type matches with \a this type.
8863   return ret.retn();
8864 }
8865
8866 /*!
8867  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8868  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8869  *
8870  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8871  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8872  * \warning this is a shallow copy constructor
8873  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8874  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8875  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8876  *          is to delete this field using decrRef() as it is no more needed.
8877  */
8878 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8879 {
8880   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8881 }
8882
8883 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8884 {
8885   return new MEDFileFieldMultiTS(*this);
8886 }
8887
8888 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8889 {
8890   if(!f1ts)
8891     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8892   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8893   if(!f1tsC)
8894     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8895 }
8896
8897 /*!
8898  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8899  * following the given input policy.
8900  *
8901  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8902  *                            By default (true) the globals are deeply copied.
8903  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8904  */
8905 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8906 {
8907   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8908   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8909   if(content)
8910     {
8911       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8912       if(!contc)
8913         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8914       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8915       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8916     }
8917   else
8918     ret=MEDFileIntFieldMultiTS::New();
8919   if(isDeepCpyGlobs)
8920     ret->deepCpyGlobs(*this);
8921   else
8922     ret->shallowCpyGlobs(*this);
8923   return ret.retn();
8924 }
8925
8926 /*!
8927  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8928  *  \param [in] pos - a time step id.
8929  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8930  *          delete this field using decrRef() as it is no more needed.
8931  *  \throw If \a pos is not a valid time step id.
8932  */
8933 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
8934 {
8935   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8936   if(!item)
8937     {
8938       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8939       throw INTERP_KERNEL::Exception(oss.str().c_str());
8940     }
8941   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8942   if(itemC)
8943     {
8944       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8945       ret->shallowCpyGlobs(*this);
8946       return ret.retn();
8947     }
8948   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8949   throw INTERP_KERNEL::Exception(oss.str().c_str());
8950 }
8951
8952 /*!
8953  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8954  * mesh entities of a given dimension of the first mesh in MED file.
8955  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8956  *  \param [in] type - a spatial discretization of interest.
8957  *  \param [in] iteration - the iteration number of a required time step.
8958  *  \param [in] order - the iteration order number of required time step.
8959  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8960  *  \param [in] renumPol - specifies how to permute values of the result field according to
8961  *          the optional numbers of cells and nodes, if any. The valid values are
8962  *          - 0 - do not permute.
8963  *          - 1 - permute cells.
8964  *          - 2 - permute nodes.
8965  *          - 3 - permute cells and nodes.
8966  *
8967  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8968  *          caller is to delete this field using decrRef() as it is no more needed. 
8969  *  \throw If the MED file is not readable.
8970  *  \throw If there is no mesh in the MED file.
8971  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8972  *  \throw If no field values of the required parameters are available.
8973  */
8974 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
8975 {
8976   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8977   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8978   if(!myF1TSC)
8979     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8980   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8981   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8982   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8983   return ret.retn();
8984 }
8985
8986 /*!
8987  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8988  * the top level cells of the first mesh in MED file.
8989  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8990  *  \param [in] type - a spatial discretization of interest.
8991  *  \param [in] iteration - the iteration number of a required time step.
8992  *  \param [in] order - the iteration order number of required time step.
8993  *  \param [in] renumPol - specifies how to permute values of the result field according to
8994  *          the optional numbers of cells and nodes, if any. The valid values are
8995  *          - 0 - do not permute.
8996  *          - 1 - permute cells.
8997  *          - 2 - permute nodes.
8998  *          - 3 - permute cells and nodes.
8999  *
9000  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9001  *          caller is to delete this field using decrRef() as it is no more needed. 
9002  *  \throw If the MED file is not readable.
9003  *  \throw If there is no mesh in the MED file.
9004  *  \throw If no field values of the required parameters are available.
9005  */
9006 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9007 {
9008   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9009   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9010   if(!myF1TSC)
9011     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9012   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9013   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9014   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9015   return ret.retn();
9016 }
9017
9018 /*!
9019  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9020  * a given support.
9021  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9022  *  \param [in] type - a spatial discretization of interest.
9023  *  \param [in] iteration - the iteration number of a required time step.
9024  *  \param [in] order - the iteration order number of required time step.
9025  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9026  *  \param [in] mesh - the supporting mesh.
9027  *  \param [in] renumPol - specifies how to permute values of the result field according to
9028  *          the optional numbers of cells and nodes, if any. The valid values are
9029  *          - 0 - do not permute.
9030  *          - 1 - permute cells.
9031  *          - 2 - permute nodes.
9032  *          - 3 - permute cells and nodes.
9033  *
9034  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9035  *          caller is to delete this field using decrRef() as it is no more needed. 
9036  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9037  *  \throw If no field of \a this is lying on \a mesh.
9038  *  \throw If no field values of the required parameters are available.
9039  */
9040 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9041 {
9042   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9043   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9044   if(!myF1TSC)
9045     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9046   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9047   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9048   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9049   return ret.retn();
9050 }
9051
9052 /*!
9053  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9054  * given support. 
9055  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9056  *  \param [in] type - a spatial discretization of the new field.
9057  *  \param [in] iteration - the iteration number of a required time step.
9058  *  \param [in] order - the iteration order number of required time step.
9059  *  \param [in] mesh - the supporting mesh.
9060  *  \param [in] renumPol - specifies how to permute values of the result field according to
9061  *          the optional numbers of cells and nodes, if any. The valid values are
9062  *          - 0 - do not permute.
9063  *          - 1 - permute cells.
9064  *          - 2 - permute nodes.
9065  *          - 3 - permute cells and nodes.
9066  *
9067  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9068  *          caller is to delete this field using decrRef() as it is no more needed. 
9069  *  \throw If no field of \a this is lying on \a mesh.
9070  *  \throw If no field values of the required parameters are available.
9071  */
9072 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9073 {
9074   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9075   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9076   if(!myF1TSC)
9077     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9078   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9079   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9080   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9081   return ret.retn();
9082 }
9083
9084 /*!
9085  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9086  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9087  * This method is useful for MED2 file format when field on different mesh was autorized.
9088  */
9089 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9090 {
9091   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9092   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9093   if(!myF1TSC)
9094     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9095   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9096   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9097   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9098   return ret.retn();
9099 }
9100
9101 /*!
9102  * Returns values and a profile of the field of a given type, of a given time step,
9103  * lying on a given support.
9104  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9105  *  \param [in] type - a spatial discretization of the field.
9106  *  \param [in] iteration - the iteration number of a required time step.
9107  *  \param [in] order - the iteration order number of required time step.
9108  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9109  *  \param [in] mesh - the supporting mesh.
9110  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9111  *          field of interest lies on. If the field lies on all entities of the given
9112  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9113  *          using decrRef() as it is no more needed.  
9114  *  \param [in] glob - the global data storing profiles and localization.
9115  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9116  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9117  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9118  *  \throw If no field of \a this is lying on \a mesh.
9119  *  \throw If no field values of the required parameters are available.
9120  */
9121 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9122 {
9123   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9124   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9125   if(!myF1TSC)
9126     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9127   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9128   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9129 }
9130
9131 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9132 {
9133   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9134   if(!pt)
9135     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9136   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9137   if(!ret)
9138     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 !");
9139   return ret;
9140 }
9141
9142 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9143 {
9144   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9145   if(!pt)
9146     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9147   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9148   if(!ret)
9149     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 !");
9150   return ret;
9151 }
9152
9153 /*!
9154  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9155  * the given field is checked if its elements are sorted suitable for writing to MED file
9156  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9157  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9158  *  \param [in] field - the field to add to \a this.
9159  *  \throw If the name of \a field is empty.
9160  *  \throw If the data array of \a field is not set.
9161  *  \throw If existing time steps have different name or number of components than \a field.
9162  *  \throw If the underlying mesh of \a field has no name.
9163  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9164  */
9165 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9166 {
9167   const DataArrayDouble *arr=0;
9168   if(field)
9169     arr=field->getArray();
9170   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9171 }
9172
9173 /*!
9174  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9175  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9176  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9177  * and \a profile.
9178  *
9179  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9180  * A new profile is added only if no equal profile is missing.
9181  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9182  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9183  *  \param [in] mesh - the supporting mesh of \a field.
9184  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9185  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9186  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9187  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9188  *  \throw If the data array of \a field is not set.
9189  *  \throw If the data array of \a this is already allocated but has different number of
9190  *         components than \a field.
9191  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9192  *  \sa setFieldNoProfileSBT()
9193  */
9194 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9195 {
9196   const DataArrayDouble *arr=0;
9197   if(field)
9198     arr=field->getArray();
9199   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9200 }
9201
9202 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9203 {
9204   _content=new MEDFileFieldMultiTSWithoutSDA;
9205 }
9206
9207 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9208 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9209 {
9210 }
9211 catch(INTERP_KERNEL::Exception& e)
9212 { throw e; }
9213
9214 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
9215 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
9216 {
9217 }
9218 catch(INTERP_KERNEL::Exception& e)
9219 { throw e; }
9220
9221 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9222 {
9223 }
9224
9225 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
9226 {
9227   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9228 }
9229
9230 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9231 {
9232   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9233 }
9234
9235 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9236 {
9237   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9238 }
9239
9240 //= MEDFileAnyTypeFieldMultiTSIterator
9241
9242 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9243 {
9244   if(fmts)
9245     {
9246       fmts->incrRef();
9247       _nb_iter=fmts->getNumberOfTS();
9248     }
9249 }
9250
9251 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9252 {
9253 }
9254
9255 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9256 {
9257   if(_iter_id<_nb_iter)
9258     {
9259       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9260       if(fmts)
9261         return fmts->getTimeStepAtPos(_iter_id++);
9262       else
9263         return 0;
9264     }
9265   else
9266     return 0;
9267 }
9268
9269 //= MEDFileIntFieldMultiTS
9270
9271 /*!
9272  * Returns a new empty instance of MEDFileFieldMultiTS.
9273  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9274  *          is to delete this field using decrRef() as it is no more needed.
9275  */
9276 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9277 {
9278   return new MEDFileIntFieldMultiTS;
9279 }
9280
9281 /*!
9282  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9283  * that has been read from a specified MED file.
9284  *  \param [in] fileName - the name of the MED file to read.
9285  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9286  *          is to delete this field using decrRef() as it is no more needed.
9287  *  \throw If reading the file fails.
9288  */
9289 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9290 {
9291   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9292   ret->contentNotNull();//to check that content type matches with \a this type.
9293   return ret.retn();
9294 }
9295
9296 /*!
9297  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9298  * that has been read from a specified MED file.
9299  *  \param [in] fileName - the name of the MED file to read.
9300  *  \param [in] fieldName - the name of the field to read.
9301  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9302  *          is to delete this field using decrRef() as it is no more needed.
9303  *  \throw If reading the file fails.
9304  *  \throw If there is no field named \a fieldName in the file.
9305  */
9306 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9307 {
9308   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9309   ret->contentNotNull();//to check that content type matches with \a this type.
9310   return ret.retn();
9311 }
9312
9313 /*!
9314  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9315  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9316  *
9317  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9318  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9319  * \warning this is a shallow copy constructor
9320  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9321  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9322  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9323  *          is to delete this field using decrRef() as it is no more needed.
9324  */
9325 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9326 {
9327   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9328 }
9329
9330 /*!
9331  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9332  * following the given input policy.
9333  *
9334  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9335  *                            By default (true) the globals are deeply copied.
9336  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9337  */
9338 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9339 {
9340   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9341   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9342   if(content)
9343     {
9344       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9345       if(!contc)
9346         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9347       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9348       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9349     }
9350   else
9351     ret=MEDFileFieldMultiTS::New();
9352   if(isDeepCpyGlobs)
9353     ret->deepCpyGlobs(*this);
9354   else
9355     ret->shallowCpyGlobs(*this);
9356   return ret.retn();
9357 }
9358
9359 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9360 {
9361   return new MEDFileIntFieldMultiTS(*this);
9362 }
9363
9364 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9365 {
9366   if(!f1ts)
9367     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9368   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9369   if(!f1tsC)
9370     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9371 }
9372
9373 /*!
9374  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9375  * mesh entities of a given dimension of the first mesh in MED file.
9376  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9377  *  \param [in] type - a spatial discretization of interest.
9378  *  \param [in] iteration - the iteration number of a required time step.
9379  *  \param [in] order - the iteration order number of required time step.
9380  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9381  *  \param [out] arrOut - the DataArrayInt containing values of field.
9382  *  \param [in] renumPol - specifies how to permute values of the result field according to
9383  *          the optional numbers of cells and nodes, if any. The valid values are
9384  *          - 0 - do not permute.
9385  *          - 1 - permute cells.
9386  *          - 2 - permute nodes.
9387  *          - 3 - permute cells and nodes.
9388  *
9389  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9390  *          caller is to delete this field using decrRef() as it is no more needed. 
9391  *  \throw If the MED file is not readable.
9392  *  \throw If there is no mesh in the MED file.
9393  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9394  *  \throw If no field values of the required parameters are available.
9395  */
9396 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9397 {
9398   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9399   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9400   if(!myF1TSC)
9401     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9402   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9403   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9404   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9405   return ret.retn();
9406 }
9407
9408 /*!
9409  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9410  * the top level cells of the first mesh in MED file.
9411  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9412  *  \param [in] type - a spatial discretization of interest.
9413  *  \param [in] iteration - the iteration number of a required time step.
9414  *  \param [in] order - the iteration order number of required time step.
9415  *  \param [out] arrOut - the DataArrayInt containing values of field.
9416  *  \param [in] renumPol - specifies how to permute values of the result field according to
9417  *          the optional numbers of cells and nodes, if any. The valid values are
9418  *          - 0 - do not permute.
9419  *          - 1 - permute cells.
9420  *          - 2 - permute nodes.
9421  *          - 3 - permute cells and nodes.
9422  *
9423  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9424  *          caller is to delete this field using decrRef() as it is no more needed. 
9425  *  \throw If the MED file is not readable.
9426  *  \throw If there is no mesh in the MED file.
9427  *  \throw If no field values of the required parameters are available.
9428  */
9429 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9430 {
9431   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9432   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9433   if(!myF1TSC)
9434     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9435   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9436   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9437   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9438   return ret.retn();
9439 }
9440
9441 /*!
9442  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9443  * a given support.
9444  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9445  *  \param [in] type - a spatial discretization of interest.
9446  *  \param [in] iteration - the iteration number of a required time step.
9447  *  \param [in] order - the iteration order number of required time step.
9448  *  \param [out] arrOut - the DataArrayInt containing values of field.
9449  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9450  *  \param [in] mesh - the supporting mesh.
9451  *  \param [in] renumPol - specifies how to permute values of the result field according to
9452  *          the optional numbers of cells and nodes, if any. The valid values are
9453  *          - 0 - do not permute.
9454  *          - 1 - permute cells.
9455  *          - 2 - permute nodes.
9456  *          - 3 - permute cells and nodes.
9457  *
9458  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9459  *          caller is to delete this field using decrRef() as it is no more needed. 
9460  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9461  *  \throw If no field of \a this is lying on \a mesh.
9462  *  \throw If no field values of the required parameters are available.
9463  */
9464 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9465 {
9466   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9467   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9468   if(!myF1TSC)
9469     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9470   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9471   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9472   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9473   return ret.retn();
9474 }
9475
9476 /*!
9477  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9478  * given support. 
9479  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9480  *  \param [in] type - a spatial discretization of the new field.
9481  *  \param [in] iteration - the iteration number of a required time step.
9482  *  \param [in] order - the iteration order number of required time step.
9483  *  \param [in] mesh - the supporting mesh.
9484  *  \param [out] arrOut - the DataArrayInt containing values of field.
9485  *  \param [in] renumPol - specifies how to permute values of the result field according to
9486  *          the optional numbers of cells and nodes, if any. The valid values are
9487  *          - 0 - do not permute.
9488  *          - 1 - permute cells.
9489  *          - 2 - permute nodes.
9490  *          - 3 - permute cells and nodes.
9491  *
9492  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9493  *          caller is to delete this field using decrRef() as it is no more needed. 
9494  *  \throw If no field of \a this is lying on \a mesh.
9495  *  \throw If no field values of the required parameters are available.
9496  */
9497 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9498 {
9499   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9500   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9501   if(!myF1TSC)
9502     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9503   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9504   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9505   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9506   return ret.retn();
9507 }
9508
9509 /*!
9510  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9511  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9512  * This method is useful for MED2 file format when field on different mesh was autorized.
9513  */
9514 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9515 {
9516   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9517   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9518   if(!myF1TSC)
9519     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9520   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9521   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9522   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9523   return ret.retn();
9524 }
9525
9526 /*!
9527  * Returns values and a profile of the field of a given type, of a given time step,
9528  * lying on a given support.
9529  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9530  *  \param [in] type - a spatial discretization of the field.
9531  *  \param [in] iteration - the iteration number of a required time step.
9532  *  \param [in] order - the iteration order number of required time step.
9533  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9534  *  \param [in] mesh - the supporting mesh.
9535  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9536  *          field of interest lies on. If the field lies on all entities of the given
9537  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9538  *          using decrRef() as it is no more needed.  
9539  *  \param [in] glob - the global data storing profiles and localization.
9540  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9541  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9542  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9543  *  \throw If no field of \a this is lying on \a mesh.
9544  *  \throw If no field values of the required parameters are available.
9545  */
9546 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9547 {
9548   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9549   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9550   if(!myF1TSC)
9551     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9552   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9553   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9554 }
9555
9556 /*!
9557  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9558  *  \param [in] pos - a time step id.
9559  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9560  *          delete this field using decrRef() as it is no more needed.
9561  *  \throw If \a pos is not a valid time step id.
9562  */
9563 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9564 {
9565   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9566   if(!item)
9567     {
9568       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9569       throw INTERP_KERNEL::Exception(oss.str().c_str());
9570     }
9571   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9572   if(itemC)
9573     {
9574       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9575       ret->shallowCpyGlobs(*this);
9576       return ret.retn();
9577     }
9578   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9579   throw INTERP_KERNEL::Exception(oss.str().c_str());
9580 }
9581
9582 /*!
9583  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9584  * the given field is checked if its elements are sorted suitable for writing to MED file
9585  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9586  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9587  *  \param [in] field - the field to add to \a this.
9588  *  \throw If the name of \a field is empty.
9589  *  \throw If the data array of \a field is not set.
9590  *  \throw If existing time steps have different name or number of components than \a field.
9591  *  \throw If the underlying mesh of \a field has no name.
9592  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9593  */
9594 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9595 {
9596   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9597 }
9598
9599 /*!
9600  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9601  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9602  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9603  * and \a profile.
9604  *
9605  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9606  * A new profile is added only if no equal profile is missing.
9607  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9608  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9609  *  \param [in] arrOfVals - the values of the field \a field used.
9610  *  \param [in] mesh - the supporting mesh of \a field.
9611  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9612  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9613  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9614  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9615  *  \throw If the data array of \a field is not set.
9616  *  \throw If the data array of \a this is already allocated but has different number of
9617  *         components than \a field.
9618  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9619  *  \sa setFieldNoProfileSBT()
9620  */
9621 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9622 {
9623   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9624 }
9625
9626 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9627 {
9628   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9629   if(!pt)
9630     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9631   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9632   if(!ret)
9633     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 !");
9634   return ret;
9635 }
9636
9637 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9638 {
9639   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9640   if(!pt)
9641     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9642   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9643   if(!ret)
9644     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 !");
9645   return ret;
9646 }
9647
9648 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9649 {
9650   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9651 }
9652
9653 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9654 {
9655 }
9656
9657 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9658 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9659 {
9660 }
9661 catch(INTERP_KERNEL::Exception& e)
9662 { throw e; }
9663
9664 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
9665 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms)
9666 {
9667 }
9668 catch(INTERP_KERNEL::Exception& e)
9669 { throw e; }
9670
9671 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9672 {
9673   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9674 }
9675
9676 //= MEDFileFields
9677
9678 MEDFileFields *MEDFileFields::New()
9679 {
9680   return new MEDFileFields;
9681 }
9682
9683 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9684 {
9685   return new MEDFileFields(fileName,loadAll,0);
9686 }
9687
9688 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9689 {
9690   return new MEDFileFields(fileName,loadAll,ms);
9691 }
9692
9693 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9694 {
9695   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9696   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9697   return ret;
9698 }
9699
9700 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9701 {
9702   std::vector<const BigMemoryObject *> ret;
9703   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9704     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9705   return ret;
9706 }
9707
9708 MEDFileFields *MEDFileFields::deepCpy() const
9709 {
9710   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9711   std::size_t i=0;
9712   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9713     {
9714       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9715         ret->_fields[i]=(*it)->deepCpy();
9716     }
9717   ret->deepCpyGlobs(*this);
9718   return ret.retn();
9719 }
9720
9721 MEDFileFields *MEDFileFields::shallowCpy() const
9722 {
9723   return new MEDFileFields(*this);
9724 }
9725
9726 /*!
9727  * 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
9728  * 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.
9729  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9730  *
9731  * \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.
9732  * \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.
9733  * 
9734  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9735  */
9736 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9737 {
9738   std::set< std::pair<int,int> > s;
9739   bool firstShot=true;
9740   areThereSomeForgottenTS=false;
9741   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9742     {
9743       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9744         continue;
9745       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9746       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9747       if(firstShot)
9748         { s=s1; firstShot=false; }
9749       else
9750         {
9751           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9752           if(s!=s2)
9753             areThereSomeForgottenTS=true;
9754           s=s2;
9755         }
9756     }
9757   std::vector< std::pair<int,int> > ret;
9758   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9759   return ret;
9760 }
9761
9762 int MEDFileFields::getNumberOfFields() const
9763 {
9764   return _fields.size();
9765 }
9766
9767 std::vector<std::string> MEDFileFields::getFieldsNames() const
9768 {
9769   std::vector<std::string> ret(_fields.size());
9770   int i=0;
9771   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9772     {
9773       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9774       if(f)
9775         {
9776           ret[i]=f->getName();
9777         }
9778       else
9779         {
9780           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9781           throw INTERP_KERNEL::Exception(oss.str().c_str());
9782         }
9783     }
9784   return ret;
9785 }
9786
9787 std::vector<std::string> MEDFileFields::getMeshesNames() const
9788 {
9789   std::vector<std::string> ret;
9790   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9791     {
9792       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9793       if(cur)
9794         ret.push_back(cur->getMeshName());
9795     }
9796   return ret;
9797 }
9798
9799 std::string MEDFileFields::simpleRepr() const
9800 {
9801   std::ostringstream oss;
9802   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9803   simpleRepr(0,oss);
9804   return oss.str();
9805 }
9806
9807 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9808 {
9809   int nbOfFields=getNumberOfFields();
9810   std::string startLine(bkOffset,' ');
9811   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9812   int i=0;
9813   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9814     {
9815       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9816       if(cur)
9817         {
9818           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9819         }
9820       else
9821         {
9822           oss << startLine << "  - not defined !" << std::endl;
9823         }
9824     }
9825   i=0;
9826   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9827     {
9828       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9829       std::string chapter(17,'0'+i);
9830       oss << startLine << chapter << std::endl;
9831       if(cur)
9832         {
9833           cur->simpleRepr(bkOffset+2,oss,i);
9834         }
9835       else
9836         {
9837           oss << startLine << "  - not defined !" << std::endl;
9838         }
9839       oss << startLine << chapter << std::endl;
9840     }
9841   simpleReprGlobs(oss);
9842 }
9843
9844 MEDFileFields::MEDFileFields()
9845 {
9846 }
9847
9848 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9849 try:MEDFileFieldGlobsReal(fileName)
9850 {
9851   MEDFileUtilities::CheckFileForRead(fileName);
9852   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
9853   int nbFields(MEDnField(fid));
9854   _fields.resize(nbFields);
9855   med_field_type typcha;
9856   for(int i=0;i<nbFields;i++)
9857     {
9858       std::vector<std::string> infos;
9859       std::string fieldName,dtunit;
9860       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
9861       switch(typcha)
9862       {
9863         case MED_FLOAT64:
9864           {
9865             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9866             break;
9867           }
9868         case MED_INT32:
9869           {
9870             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms);
9871             break;
9872           }
9873         default:
9874           {
9875             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] !";
9876             throw INTERP_KERNEL::Exception(oss.str().c_str());
9877           }
9878       }
9879     }
9880   loadAllGlobals(fid);
9881 }
9882 catch(INTERP_KERNEL::Exception& e)
9883 {
9884     throw e;
9885 }
9886
9887 void MEDFileFields::writeLL(med_idt fid) const
9888 {
9889   int i=0;
9890   writeGlobals(fid,*this);
9891   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9892     {
9893       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9894       if(!elt)
9895         {
9896           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9897           throw INTERP_KERNEL::Exception(oss.str().c_str());
9898         }
9899       elt->writeLL(fid,*this);
9900     }
9901 }
9902
9903 void MEDFileFields::write(const std::string& fileName, int mode) const
9904 {
9905   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9906   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
9907   writeLL(fid);
9908 }
9909
9910 /*!
9911  * This method alloc the arrays and load potentially huge arrays contained in this field.
9912  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9913  * This method can be also called to refresh or reinit values from a file.
9914  * 
9915  * \throw If the fileName is not set or points to a non readable MED file.
9916  */
9917 void MEDFileFields::loadArrays()
9918 {
9919   if(getFileName().empty())
9920     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9921   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9922   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9923     {
9924       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9925       if(elt)
9926         elt->loadBigArraysRecursively(fid,*elt);
9927     }
9928 }
9929
9930 /*!
9931  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9932  * But once data loaded once, this method does nothing.
9933  * 
9934  * \throw If the fileName is not set or points to a non readable MED file.
9935  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9936  */
9937 void MEDFileFields::loadArraysIfNecessary()
9938 {
9939   if(!getFileName().empty())
9940     {
9941       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9942       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9943         {
9944           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9945           if(elt)
9946             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9947         }
9948     }
9949 }
9950
9951 /*!
9952  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9953  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9954  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9955  * 
9956  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9957  */
9958 void MEDFileFields::unloadArrays()
9959 {
9960   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9961     {
9962       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9963       if(elt)
9964         elt->unloadArrays();
9965     }
9966 }
9967
9968 /*!
9969  * 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.
9970  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9971  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9972  * 
9973  * \sa MEDFileFields::loadArraysIfNecessary
9974  */
9975 void MEDFileFields::unloadArraysWithoutDataLoss()
9976 {
9977   if(!getFileName().empty())
9978     unloadArrays();
9979 }
9980
9981 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9982 {
9983   std::vector<std::string> ret;
9984   std::set<std::string> ret2;
9985   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9986     {
9987       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9988       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9989         if(ret2.find(*it2)==ret2.end())
9990           {
9991             ret.push_back(*it2);
9992             ret2.insert(*it2);
9993           }
9994     }
9995   return ret;
9996 }
9997
9998 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9999 {
10000   std::vector<std::string> ret;
10001   std::set<std::string> ret2;
10002   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10003     {
10004       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10005       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10006         if(ret2.find(*it2)==ret2.end())
10007           {
10008             ret.push_back(*it2);
10009             ret2.insert(*it2);
10010           }
10011     }
10012   return ret;
10013 }
10014
10015 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10016 {
10017   std::vector<std::string> ret;
10018   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10019     {
10020       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10021       ret.insert(ret.end(),tmp.begin(),tmp.end());
10022     }
10023   return ret;
10024 }
10025
10026 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10027 {
10028   std::vector<std::string> ret;
10029   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10030     {
10031       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10032       ret.insert(ret.end(),tmp.begin(),tmp.end());
10033     }
10034   return ret;
10035 }
10036
10037 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10038 {
10039   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10040     (*it)->changePflsRefsNamesGen2(mapOfModif);
10041 }
10042
10043 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10044 {
10045   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10046     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10047 }
10048
10049 void MEDFileFields::resize(int newSize)
10050 {
10051   _fields.resize(newSize);
10052 }
10053
10054 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10055 {
10056   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10057     pushField(*it);
10058 }
10059
10060 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10061 {
10062   if(!field)
10063     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10064   _fields.push_back(field->getContent());
10065   appendGlobs(*field,1e-12);
10066 }
10067
10068 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10069 {
10070   if(!field)
10071     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10072   if(i>=(int)_fields.size())
10073     _fields.resize(i+1);
10074   _fields[i]=field->getContent();
10075   appendGlobs(*field,1e-12);
10076 }
10077
10078 void MEDFileFields::destroyFieldAtPos(int i)
10079 {
10080   destroyFieldsAtPos(&i,&i+1);
10081 }
10082
10083 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10084 {
10085   std::vector<bool> b(_fields.size(),true);
10086   for(const int *i=startIds;i!=endIds;i++)
10087     {
10088       if(*i<0 || *i>=(int)_fields.size())
10089         {
10090           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10091           throw INTERP_KERNEL::Exception(oss.str().c_str());
10092         }
10093       b[*i]=false;
10094     }
10095   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10096   std::size_t j=0;
10097   for(std::size_t i=0;i<_fields.size();i++)
10098     if(b[i])
10099       fields[j++]=_fields[i];
10100   _fields=fields;
10101 }
10102
10103 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10104 {
10105   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10106   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10107   std::vector<bool> b(_fields.size(),true);
10108   int k=bg;
10109   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10110     {
10111       if(k<0 || k>=(int)_fields.size())
10112         {
10113           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10114           throw INTERP_KERNEL::Exception(oss.str().c_str());
10115         }
10116       b[k]=false;
10117     }
10118   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10119   std::size_t j=0;
10120   for(std::size_t i=0;i<_fields.size();i++)
10121     if(b[i])
10122       fields[j++]=_fields[i];
10123   _fields=fields;
10124 }
10125
10126 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10127 {
10128   bool ret=false;
10129   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10130     {
10131       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10132       if(cur)
10133         ret=cur->changeMeshNames(modifTab) || ret;
10134     }
10135   return ret;
10136 }
10137
10138 /*!
10139  * \param [in] meshName the name of the mesh that will be renumbered.
10140  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10141  *             This code corresponds to the distribution of types in the corresponding mesh.
10142  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10143  * \param [in] renumO2N the old to new renumber array.
10144  * \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 
10145  *         field in \a this.
10146  */
10147 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10148 {
10149   bool ret=false;
10150   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10151     {
10152       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10153       if(fmts)
10154         {
10155           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10156         }
10157     }
10158   return ret;
10159 }
10160
10161 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10162 {
10163   if(i<0 || i>=(int)_fields.size())
10164     {
10165       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10166       throw INTERP_KERNEL::Exception(oss.str().c_str());
10167     }
10168   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10169   if(!fmts)
10170     return 0;
10171   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
10172   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10173   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10174   if(fmtsC)
10175     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10176   else if(fmtsC2)
10177     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10178   else
10179     {
10180       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10181       throw INTERP_KERNEL::Exception(oss.str().c_str());
10182     }
10183   ret->shallowCpyGlobs(*this);
10184   return ret.retn();
10185 }
10186
10187 /*!
10188  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10189  * This method is accessible in python using __getitem__ with a list in input.
10190  * \return a new object that the caller should deal with.
10191  */
10192 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10193 {
10194   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
10195   std::size_t sz=std::distance(startIds,endIds);
10196   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10197   int j=0;
10198   for(const int *i=startIds;i!=endIds;i++,j++)
10199     {
10200       if(*i<0 || *i>=(int)_fields.size())
10201         {
10202           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10203           throw INTERP_KERNEL::Exception(oss.str().c_str());
10204         }
10205       fields[j]=_fields[*i];
10206     }
10207   ret->_fields=fields;
10208   return ret.retn();
10209 }
10210
10211 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10212 {
10213   return getFieldAtPos(getPosFromFieldName(fieldName));
10214 }
10215
10216 /*!
10217  * This method removes, if any, fields in \a this having no time steps.
10218  * 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.
10219  * 
10220  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10221  */
10222 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10223 {
10224   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10225   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10226     {
10227       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10228       if(elt)
10229         {
10230           if(elt->getNumberOfTS()>0)
10231             newFields.push_back(*it);
10232         }
10233     }
10234   if(_fields.size()==newFields.size())
10235     return false;
10236   _fields=newFields;
10237   return true;
10238 }
10239
10240 /*!
10241  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10242  * This method can be seen as a filter applied on \a this, that returns an object containing
10243  * 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
10244  * shallow copied from \a this.
10245  * 
10246  * \param [in] meshName - the name of the mesh on w
10247  * \return a new object that the caller should deal with.
10248  */
10249 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10250 {
10251   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10252   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10253     {
10254       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10255       if(!cur)
10256         continue;
10257       if(cur->getMeshName()==meshName)
10258         {
10259           cur->incrRef();
10260           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10261           ret->_fields.push_back(cur2);
10262         }
10263     }
10264   ret->shallowCpyOnlyUsedGlobs(*this);
10265   return ret.retn();
10266 }
10267
10268 /*!
10269  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10270  * Input time steps are specified using a pair of integer (iteration, order).
10271  * 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,
10272  * but for each multitimestep only the time steps in \a timeSteps are kept.
10273  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10274  * 
10275  * The returned object points to shallow copy of elements in \a this.
10276  * 
10277  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10278  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10279  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10280  */
10281 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10282 {
10283   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10284   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10285     {
10286       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10287       if(!cur)
10288         continue;
10289       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10290       ret->_fields.push_back(elt);
10291     }
10292   ret->shallowCpyOnlyUsedGlobs(*this);
10293   return ret.retn();
10294 }
10295
10296 /*!
10297  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10298  */
10299 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10300 {
10301   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10302   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10303     {
10304       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10305       if(!cur)
10306         continue;
10307       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10308       if(elt->getNumberOfTS()!=0)
10309         ret->_fields.push_back(elt);
10310     }
10311   ret->shallowCpyOnlyUsedGlobs(*this);
10312   return ret.retn();
10313 }
10314
10315 MEDFileFieldsIterator *MEDFileFields::iterator()
10316 {
10317   return new MEDFileFieldsIterator(this);
10318 }
10319
10320 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10321 {
10322   std::string tmp(fieldName);
10323   std::vector<std::string> poss;
10324   for(std::size_t i=0;i<_fields.size();i++)
10325     {
10326       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10327       if(f)
10328         {
10329           std::string fname(f->getName());
10330           if(tmp==fname)
10331             return i;
10332           else
10333             poss.push_back(fname);
10334         }
10335     }
10336   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10337   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10338   oss << " !";
10339   throw INTERP_KERNEL::Exception(oss.str().c_str());
10340 }
10341
10342 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10343 {
10344   if(fs)
10345     {
10346       fs->incrRef();
10347       _nb_iter=fs->getNumberOfFields();
10348     }
10349 }
10350
10351 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10352 {
10353 }
10354
10355 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10356 {
10357   if(_iter_id<_nb_iter)
10358     {
10359       MEDFileFields *fs(_fs);
10360       if(fs)
10361         return fs->getFieldAtPos(_iter_id++);
10362       else
10363         return 0;
10364     }
10365   else
10366     return 0;
10367 }