Salome HOME
Addition of a method in MEDFileFields to filter empty fields
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25 #include "MEDFileFieldOverView.hxx"
26
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "MEDCouplingFieldDiscretization.hxx"
29
30 #include "InterpKernelAutoPtr.hxx"
31 #include "CellModel.hxx"
32
33 #include <algorithm>
34 #include <iterator>
35
36 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
37 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
38 extern med_geometry_type typmainoeud[1];
39 extern med_geometry_type typmai3[34];
40
41 using namespace ParaMEDMEM;
42
43 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
44 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
45
46 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
47 {
48   return new MEDFileFieldLoc(fid,locName);
49 }
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
52 {
53   return new MEDFileFieldLoc(fid,id);
54 }
55
56 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
57 {
58   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
59 }
60
61 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
62 {
63   med_geometry_type geotype;
64   med_geometry_type sectiongeotype;
65   int nsectionmeshcell;
66   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
67   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
69   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
70   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
71   _nb_node_per_cell=cm.getNumberOfNodes();
72   _ref_coo.resize(_dim*_nb_node_per_cell);
73   _gs_coo.resize(_dim*_nb_gauss_pt);
74   _w.resize(_nb_gauss_pt);
75   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
76 }
77
78 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
79 {
80   med_geometry_type geotype;
81   med_geometry_type sectiongeotype;
82   int nsectionmeshcell;
83   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
84   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
87   _name=locName;
88   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
89   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
90   _nb_node_per_cell=cm.getNumberOfNodes();
91   _ref_coo.resize(_dim*_nb_node_per_cell);
92   _gs_coo.resize(_dim*_nb_gauss_pt);
93   _w.resize(_nb_gauss_pt);
94   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
95 }
96
97 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
98                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
99                                                                                                                                     _w(w)
100 {
101   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
102   _dim=cm.getDimension();
103   _nb_node_per_cell=cm.getNumberOfNodes();
104   _nb_gauss_pt=_w.size();
105 }
106
107 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
108 {
109   return new MEDFileFieldLoc(*this);
110 }
111
112 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
113 {
114   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
115 }
116
117 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildren() 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(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) { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); } else { oss << "_NODE"; }
290   if(locIds)
291     {
292       if(pflName.empty())
293         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
294       if(_type!=ON_GAUSS_PT)
295         {
296           locIds->setName(oss.str().c_str());
297           glob.appendProfile(locIds);
298           _profile=oss.str();
299         }
300     }
301   _start=start;
302   switch(_type)
303     {
304     case ON_NODES:
305       {
306          _nval=idsInPfl->getNumberOfTuples();
307          getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
308          _end=_start+_nval;
309          break;
310       }
311     case ON_CELLS:
312       {
313         _nval=idsInPfl->getNumberOfTuples();
314         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
315         _end=_start+_nval;
316         break;
317       }
318     case ON_GAUSS_NE:
319       {
320         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
321         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
322         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
323         arr3->computeOffsets2();
324         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
325         int trueNval=tmp->getNumberOfTuples();
326         _nval=idsInPfl->getNumberOfTuples();
327         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
328         _end=_start+trueNval;
329         break;
330       }
331     case ON_GAUSS_PT:
332       {
333         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
334         if(!disc2)
335           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
336         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
337         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
338         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
339         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
340         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
341         //
342         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
343         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
344         //
345         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
346         int trueNval=0;
347         for(const int *pt=da4->begin();pt!=da4->end();pt++)
348           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
349         tmp->alloc(trueNval,1);
350         int *tmpPtr=tmp->getPointer();
351         for(const int *pt=da4->begin();pt!=da4->end();pt++)
352           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
353             *tmpPtr++=j;
354         //
355         _nval=da4->getNumberOfTuples();
356         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
357         _end=_start+trueNval;
358         oss << "_loc_" << _loc_id;
359         if(locIds)
360           {
361             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
362             da5->setName(oss.str().c_str());
363             glob.appendProfile(da5);
364             _profile=oss.str();
365           }
366         else
367           {
368             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
369               {
370                 da3->setName(oss.str().c_str());
371                 glob.appendProfile(da3);
372                 _profile=oss.str();
373               }
374           }
375         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
376         _localization=oss2.str();
377         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
378         break;
379       }
380     default:
381       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
382     }
383   start=_end;
384 }
385
386 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
387 {
388   _start=start;
389   _nval=arrr->getNumberOfTuples();
390   getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,_nval,1);
391   _end=_start+_nval;
392   start=_end;
393 }
394
395 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt)
396 {
397   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt);
398 }
399
400 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
401 {
402   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
403 }
404
405 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
406 {
407   return new MEDFileFieldPerMeshPerTypePerDisc(other);
408 }
409
410 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
411 {
412   return _profile.capacity()+_localization.capacity()+5*sizeof(int);
413 }
414
415 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildren() const
416 {
417   return std::vector<const BigMemoryObject *>();
418 }
419
420 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const
421 {
422   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
423   ret->_father=father;
424   return ret.retn();
425 }
426
427 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt)
428 try:_type(atype),_father(fath),_profile_it(profileIt)
429   {
430   }
431 catch(INTERP_KERNEL::Exception& e)
432 {
433   throw e;
434 }
435
436 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
437 {
438 }
439
440 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_tmp_work1(other._tmp_work1)
441 {
442 }
443
444 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
445                                                                        _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
446 {
447 }
448
449 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
450 {
451   return _father;
452 }
453
454 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
455 {
456   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
457   INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
458   std::string fieldName=nasc.getName();
459   std::string meshName=getMeshName();
460   int iteration=getIteration();
461   int order=getOrder();
462   TypeOfField type=getType();
463   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
464   int profilesize,nbi;
465   med_geometry_type mgeoti;
466   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
467   _nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it,MED_COMPACT_PFLMODE,
468                                   pflname,&profilesize,locname,&nbi);
469   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
470   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
471   _start=start;
472   _end=start+_nval*nbi;
473   start=_end;
474   if(type==ON_CELLS && !_localization.empty())
475     {
476       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
477         setType(ON_GAUSS_PT);
478       else
479         {
480           setType(ON_GAUSS_NE);
481           _localization.clear();
482         }
483     }
484 }
485
486 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
487 {
488   std::string fieldName=nasc.getName();
489   std::string meshName=getMeshName();
490   int iteration=getIteration();
491   int order=getOrder();
492   TypeOfField type=getType();
493   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
494   med_geometry_type mgeoti;
495   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
496   if(_start>_end)
497     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
498   if(_start==_end)
499     return ;
500   DataArray *arr=getOrCreateAndGetArray();//arr is not null due to the spec of getOrCreateAndGetArray
501   if(_start<0 || _start>=arr->getNumberOfTuples())
502     {
503       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
504       throw INTERP_KERNEL::Exception(oss.str().c_str());
505     }
506   if(_end<0 || _end>arr->getNumberOfTuples())
507     {
508       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
509       throw INTERP_KERNEL::Exception(oss.str().c_str());
510     }
511   med_int tmp1,nbi;
512   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
513   med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
514   int nbOfCompo=arr->getNumberOfComponents();
515   if(_end-_start!=nbValsInFile*nbi)
516     {
517       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
518       throw INTERP_KERNEL::Exception(oss.str().c_str());
519     }
520   DataArrayDouble *arrD=dynamic_cast<DataArrayDouble *>(arr);
521   if(arrD)
522     {
523       double *startFeeding=arrD->getPointer()+_start*nbOfCompo;
524       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
525                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
526       return ;
527     }
528   DataArrayInt *arrI=dynamic_cast<DataArrayInt *>(arr);
529   if(arrI)
530     {
531       int *startFeeding=arrI->getPointer()+_start*nbOfCompo;
532       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
533                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
534       return ;
535     }
536   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
537 }
538
539 /*!
540  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
541  */
542 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
543 {
544   int delta=_end-_start;
545   _start=newValueOfStart;
546   _end=_start+delta;
547 }
548
549 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
550 {
551   return _father->getIteration();
552 }
553
554 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
555 {
556   return _father->getOrder();
557 }
558
559 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
560 {
561   return _father->getTime();
562 }
563
564 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
565 {
566   return _father->getMeshName();
567 }
568
569 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
570 {
571   const char startLine[]="    ## ";
572   std::string startLine2(bkOffset,' ');
573   startLine2+=startLine;
574   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
575   oss << startLine2 << "Localization #" << id << "." << std::endl;
576   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
577   delete tmp;
578   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
579   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
580   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
581 }
582
583 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
584 {
585   return _type;
586 }
587
588 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
589 {
590   types.insert(_type);
591 }
592
593 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
594 {
595   _type=newType;
596 }
597
598 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
599 {
600   return _father->getGeoType();
601 }
602
603 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
604 {
605   return _father->getNumberOfComponents();
606 }
607
608 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
609 {
610   return _end-_start;
611 }
612
613 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
614 {
615   return _father->getOrCreateAndGetArray();
616 }
617
618 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
619 {
620   const MEDFileFieldPerMeshPerType *fath=_father;
621   return fath->getOrCreateAndGetArray();
622 }
623
624 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
625 {
626   return _father->getInfo();
627 }
628
629 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
630 {
631   return _profile;
632 }
633
634 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
635 {
636   _profile=newPflName;
637 }
638
639 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
640 {
641   return _localization;
642 }
643
644 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
645 {
646   _localization=newLocName;
647 }
648
649 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
650 {
651   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
652     {
653       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
654         {
655           _profile=(*it2).second;
656           return;
657         }
658     }
659 }
660
661 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
662 {
663   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
664     {
665       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
666         {
667           _localization=(*it2).second;
668           return;
669         }
670     }
671 }
672
673 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
674 {
675   if(type!=_type)
676     return ;
677   dads.push_back(std::pair<int,int>(_start,_end));
678   geoTypes.push_back(getGeoType());
679   if(_profile.empty())
680     pfls.push_back(0);
681   else
682     {
683       pfls.push_back(glob->getProfile(_profile.c_str()));
684     }
685   if(_localization.empty())
686     locs.push_back(-1);
687   else
688     {
689       locs.push_back(glob->getLocalizationId(_localization.c_str()));
690     }
691 }
692
693 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
694 {
695   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));
696   startEntryId++;
697 }
698
699 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
700 {
701   TypeOfField type=getType();
702   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
703   med_geometry_type mgeoti;
704   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
705   const DataArray *arr=getOrCreateAndGetArray();
706   if(!arr)
707     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
708   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
709   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
710   const unsigned char *locToWrite=0;
711   if(arrD)
712     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
713   else if(arrI)
714     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
715   else
716     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
717   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
718                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
719                              locToWrite);
720 }
721
722 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
723 {
724   type=_type;
725   pfl=_profile;
726   loc=_localization;
727   dad.first=_start; dad.second=_end;
728 }
729
730 /*!
731  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
732  *             This code corresponds to the distribution of types in the corresponding mesh.
733  * \param [out] ptToFill memory zone where the output will be stored.
734  * \return the size of data pushed into output param \a ptToFill
735  */
736 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
737 {
738   _loc_id=offset;
739   std::ostringstream oss;
740   std::size_t nbOfType=codeOfMesh.size()/3;
741   int found=-1;
742   for(std::size_t i=0;i<nbOfType && found==-1;i++)
743     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
744       found=(int)i;
745   if(found==-1)
746     {
747       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
748       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
749       throw INTERP_KERNEL::Exception(oss.str().c_str());
750     }
751   int *work=ptToFill;
752   if(_profile.empty())
753     {
754       if(_nval!=codeOfMesh[3*found+1])
755         {
756           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
757           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
758           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
759           throw INTERP_KERNEL::Exception(oss.str().c_str());
760         }
761       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
762         *work++=ii;
763     }
764   else
765     {
766       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
767       if(pfl->getNumberOfTuples()!=_nval)
768         {
769           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
770           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
771           oss << _nval;
772           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
773           throw INTERP_KERNEL::Exception(oss.str().c_str());
774         }
775       int offset2=codeOfMesh[3*found+2];
776       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
777         {
778           if(*pflId<codeOfMesh[3*found+1])
779             *work++=offset2+*pflId;
780         }
781     }
782   return _nval;
783 }
784
785 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
786 {
787   for(int i=_start;i<_end;i++)
788     *ptToFill++=i;
789   return _end-_start;
790 }
791
792 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
793 {
794   switch(type)
795     {
796     case ON_CELLS:
797       return -2;
798     case ON_GAUSS_NE:
799       return -1;
800     case ON_GAUSS_PT:
801       return locId;
802     default:
803       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
804     }
805 }
806
807 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
808 {
809   int id=0;
810   std::map<std::pair<std::string,TypeOfField>,int> m;
811   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
812   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
813     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
814       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
815   ret.resize(id);
816   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
817     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
818   return ret;
819 }
820
821 /*!
822  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
823  * 
824  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
825  * \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.
826  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
827  * \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)
828  * \param [in,out] glob if necessary by the method, new profiles can be added to it
829  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
830  * \param [out] result All new entries will be appended on it.
831  * \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 !)
832  */
833 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
834                                                        const DataArrayInt *explicitIdsInMesh,
835                                                        const std::vector<int>& newCode,
836                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
837                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
838 {
839   if(entriesOnSameDisc.empty())
840     return false;
841   TypeOfField type=entriesOnSameDisc[0]->getType();
842   int szEntities=0,szTuples=0;
843   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
844     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
845   int nbi=szTuples/szEntities;
846   if(szTuples%szEntities!=0)
847     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
848   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
849   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
850   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
851   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
852   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
853   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
854   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
855   int id=0;
856   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
857     {
858       int startOfEltIdOfChunk=(*it)->_start;
859       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
860       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
861       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
862       //
863       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
864       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
865       //
866       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
867       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
868     }
869   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
870   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
871   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
872   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
873   //
874   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
875   //
876   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
877   arrPart->renumberInPlace(renumTupleIds->begin());
878   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
879   bool ret=false;
880   const int *idIt=diffVals->begin();
881   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
882   int offset2=0;
883   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
884     {
885       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
886       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
887       int nbEntityElts=subIds->getNumberOfTuples();
888       bool ret2;
889       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
890         NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
891                                     offset+offset2,
892                                     li,glob,ret2);
893       ret=ret || ret2;
894       result.push_back(eltToAdd);
895       offset2+=nbEntityElts*nbi;
896     }
897   ret=ret || li.empty();
898   return ret;
899 }
900
901 /*!
902  * \param [in] typeF type of field of new chunk
903  * \param [in] geoType the geometric type of the chunk
904  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
905  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
906  * \param [in] nbi number of integration points
907  * \param [in] offset The offset in the **global array of data**.
908  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
909  *                 to the new chunk to create.
910  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
911  * \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
912  *              and corresponding entry erased from \a entriesOnSameDisc.
913  * \return a newly allocated chunk
914  */
915 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
916                                                                                                   bool isPfl, int nbi, int offset,
917                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
918                                                                                                   MEDFileFieldGlobsReal& glob,
919                                                                                                   bool &notInExisting) throw(INTERP_KERNEL::Exception)
920 {
921   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
922   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
923   for(;it!=entriesOnSameDisc.end();it++)
924     {
925       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
926         {
927           if(!isPfl)
928             {
929               if((*it)->_profile.empty())
930                 break;
931               else
932                 if(!(*it)->_profile.empty())
933                   {
934                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
935                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
936                       break;
937                   }
938             }
939         }
940     }
941   if(it==entriesOnSameDisc.end())
942     {
943       notInExisting=true;
944       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
945       ret->_type=typeF;
946       ret->_loc_id=(int)geoType;
947       ret->_nval=nbMeshEntities;
948       ret->_start=offset;
949       ret->_end=ret->_start+ret->_nval*nbi;
950       if(isPfl)
951         {
952           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
953           glob.appendProfile(idsOfMeshElt);
954           ret->_profile=idsOfMeshElt->getName();
955         }
956       //tony treatment of localization
957       return ret;
958     }
959   else
960     {
961       notInExisting=false;
962       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
963       ret->_loc_id=(int)geoType;
964       ret->setNewStart(offset);
965       entriesOnSameDisc.erase(it);
966       return ret;
967     }
968   
969 }
970
971 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc)
972 {
973   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc);
974 }
975
976 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
977 {
978   return new MEDFileFieldPerMeshPerType(fath,geoType);
979 }
980
981 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
982 {
983   return _field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
984 }
985
986 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildren() const
987 {
988   std::vector<const BigMemoryObject *> ret;
989   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
990     {
991       const MEDFileFieldPerMeshPerTypePerDisc *cur(*it);
992       if(cur)
993         ret.push_back(cur);
994     }
995   return ret;
996 }
997
998 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const
999 {
1000   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1001   ret->_father=father;
1002   std::size_t i=0;
1003   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1004     {
1005       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1006         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
1007     }
1008   return ret.retn();
1009 }
1010
1011 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1012 {
1013   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1014   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1015     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1016 }
1017
1018 /*!
1019  * This method is the most general one. No optimization is done here.
1020  * \param [in] multiTypePfl is the end user profile specified in high level API
1021  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1022  * \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.
1023  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1024  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1025  * \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.
1026  */
1027 void MEDFileFieldPerMeshPerType::assignFieldProfile(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)
1028 {
1029   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1030   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1031     _field_pm_pt_pd[*it]->assignFieldProfile(start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1032 }
1033
1034 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1035 {
1036   _field_pm_pt_pd.resize(1);
1037   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1038   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1039 }
1040
1041 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1042 {
1043   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1044   if(!arr || !arr->isAllocated())
1045     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1046   _field_pm_pt_pd.resize(1);
1047   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1048   _field_pm_pt_pd[0]->assignFieldProfile(start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1049 }
1050
1051 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1052 {
1053   TypeOfField type=field->getTypeOfField();
1054   if(type!=ON_GAUSS_PT)
1055     {
1056       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1057       int sz=_field_pm_pt_pd.size();
1058       bool found=false;
1059       for(int j=0;j<sz && !found;j++)
1060         {
1061           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1062             {
1063               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1064               found=true;
1065             }
1066         }
1067       if(!found)
1068         {
1069           _field_pm_pt_pd.resize(sz+1);
1070           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1071         }
1072       std::vector<int> ret(1,(int)sz);
1073       return ret;
1074     }
1075   else
1076     {
1077       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1078       int sz2=ret2.size();
1079       std::vector<int> ret3(sz2);
1080       int k=0;
1081       for(int i=0;i<sz2;i++)
1082         {
1083           int sz=_field_pm_pt_pd.size();
1084           int locIdToFind=ret2[i];
1085           bool found=false;
1086           for(int j=0;j<sz && !found;j++)
1087             {
1088               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1089                 {
1090                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1091                   ret3[k++]=j;
1092                   found=true;
1093                 }
1094             }
1095           if(!found)
1096             {
1097               _field_pm_pt_pd.resize(sz+1);
1098               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1099               ret3[k++]=sz;
1100             }
1101         }
1102       return ret3;
1103     }
1104 }
1105
1106 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1107 {
1108   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1109   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1110   if(!disc2)
1111     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1112   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1113   if(!da)
1114     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1115   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1116   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1117   if(retTmp->presenceOfValue(-1))
1118     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1119   std::vector<int> ret(retTmp->begin(),retTmp->end());
1120   return ret;
1121 }
1122
1123 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1124 {
1125   TypeOfField type=field->getTypeOfField();
1126   if(type!=ON_GAUSS_PT)
1127     {
1128       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1129       int sz=_field_pm_pt_pd.size();
1130       bool found=false;
1131       for(int j=0;j<sz && !found;j++)
1132         {
1133           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1134             {
1135               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1136               found=true;
1137             }
1138         }
1139       if(!found)
1140         {
1141           _field_pm_pt_pd.resize(sz+1);
1142           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1143         }
1144       std::vector<int> ret(1,0);
1145       return ret;
1146     }
1147   else
1148     {
1149       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1150       int sz2=ret2.size();
1151       std::vector<int> ret3(sz2);
1152       int k=0;
1153       for(int i=0;i<sz2;i++)
1154         {
1155           int sz=_field_pm_pt_pd.size();
1156           int locIdToFind=ret2[i];
1157           bool found=false;
1158           for(int j=0;j<sz && !found;j++)
1159             {
1160               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1161                 {
1162                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1163                   ret3[k++]=j;
1164                   found=true;
1165                 }
1166             }
1167           if(!found)
1168             {
1169               _field_pm_pt_pd.resize(sz+1);
1170               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1171               ret3[k++]=sz;
1172             }
1173         }
1174       return ret3;
1175     }
1176 }
1177
1178 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1179 {
1180   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1181   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1182   if(!disc2)
1183     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1184   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1185   if(!da)
1186     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1187   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1188   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1189   if(retTmp->presenceOfValue(-1))
1190     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1191   std::vector<int> ret(retTmp->begin(),retTmp->end());
1192   return ret;
1193 }
1194
1195 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1196 {
1197   return _father;
1198 }
1199
1200 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1201 {
1202   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1203   int curDim=(int)cm.getDimension();
1204   dim=std::max(dim,curDim);
1205 }
1206
1207 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1208 {
1209   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1210     {
1211       (*it)->fillTypesOfFieldAvailable(types);
1212     }
1213 }
1214
1215 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
1216 {
1217   int sz=_field_pm_pt_pd.size();
1218   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1219   for(int i=0;i<sz;i++)
1220     {
1221       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1222     }
1223 }
1224
1225 int MEDFileFieldPerMeshPerType::getIteration() const
1226 {
1227   return _father->getIteration();
1228 }
1229
1230 int MEDFileFieldPerMeshPerType::getOrder() const
1231 {
1232   return _father->getOrder();
1233 }
1234
1235 double MEDFileFieldPerMeshPerType::getTime() const
1236 {
1237   return _father->getTime();
1238 }
1239
1240 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1241 {
1242   return _father->getMeshName();
1243 }
1244
1245 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1246 {
1247   const char startLine[]="  ## ";
1248   std::string startLine2(bkOffset,' ');
1249   std::string startLine3(startLine2);
1250   startLine3+=startLine;
1251   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1252     {
1253       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1254       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1255     }
1256   else
1257     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1258   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1259   int i=0;
1260   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1261     {
1262       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1263       if(cur)
1264         cur->simpleRepr(bkOffset,oss,i);
1265       else
1266         {
1267           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1268         }
1269     }
1270 }
1271
1272 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1273 {
1274   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1275     {
1276       globalSz+=(*it)->getNumberOfTuples();
1277     }
1278   nbOfEntries+=(int)_field_pm_pt_pd.size();
1279 }
1280
1281 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1282 {
1283   return _geo_type;
1284 }
1285
1286
1287 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1288 {
1289   return _father->getNumberOfComponents();
1290 }
1291
1292 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1293 {
1294   return _father->getOrCreateAndGetArray();
1295 }
1296
1297 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1298 {
1299   const MEDFileFieldPerMesh *fath=_father;
1300   return fath->getOrCreateAndGetArray();
1301 }
1302
1303 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1304 {
1305   return _father->getInfo();
1306 }
1307
1308 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1309 {
1310   std::vector<std::string> ret;
1311   std::set<std::string> ret2;
1312   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1313     {
1314       std::string tmp=(*it1)->getProfile();
1315       if(!tmp.empty())
1316         if(ret2.find(tmp)==ret2.end())
1317           {
1318             ret.push_back(tmp);
1319             ret2.insert(tmp);
1320           }
1321     }
1322   return ret;
1323 }
1324
1325 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1326 {
1327   std::vector<std::string> ret;
1328   std::set<std::string> ret2;
1329   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1330     {
1331       std::string tmp=(*it1)->getLocalization();
1332       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1333         if(ret2.find(tmp)==ret2.end())
1334           {
1335             ret.push_back(tmp);
1336             ret2.insert(tmp);
1337           }
1338     }
1339   return ret;
1340 }
1341
1342 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1343 {
1344   std::vector<std::string> ret;
1345   std::set<std::string> ret2;
1346   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1347     {
1348       std::string tmp=(*it1)->getProfile();
1349       if(!tmp.empty())
1350         ret.push_back(tmp);
1351     }
1352   return ret;
1353 }
1354
1355 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1356 {
1357   std::vector<std::string> ret;
1358   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1359     {
1360       std::string tmp=(*it1)->getLocalization();
1361       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1362         ret.push_back(tmp);
1363     }
1364   return ret;
1365 }
1366
1367 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1368 {
1369   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1370     (*it1)->changePflsRefsNamesGen(mapOfModif);
1371 }
1372
1373 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1374 {
1375   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1376     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1377 }
1378
1379 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1380 {
1381   if(_field_pm_pt_pd.empty())
1382     {
1383       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1384       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1385       throw INTERP_KERNEL::Exception(oss.str().c_str());
1386     }
1387   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1388     return _field_pm_pt_pd[locId];
1389   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1390   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1391   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1392   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1393   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1394 }
1395
1396 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1397 {
1398   if(_field_pm_pt_pd.empty())
1399     {
1400       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1401       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1402       throw INTERP_KERNEL::Exception(oss.str().c_str());
1403     }
1404   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1405     return _field_pm_pt_pd[locId];
1406   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1407   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1408   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1409   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1410   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1411 }
1412
1413 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
1414 {
1415   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1416     {
1417       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1418       if(meshDim!=(int)cm.getDimension())
1419         return ;
1420     }
1421   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1422     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1423 }
1424
1425 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1426 {
1427   int i=0;
1428   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1429     {
1430       (*it)->fillValues(i,startEntryId,entries);
1431     }
1432 }
1433
1434 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1435 {
1436   _field_pm_pt_pd=leaves;
1437   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1438     (*it)->setFather(this);
1439 }
1440
1441 /*!
1442  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1443  *  \param [out] its - list of pair (start,stop) kept
1444  *  \return bool - false if the type of field \a tof is not contained in \a this.
1445  */
1446 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1447 {
1448   bool ret=false;
1449   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1450   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1451     if((*it)->getType()==tof)
1452       {
1453         newPmPtPd.push_back(*it);
1454         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1455         (*it)->setNewStart(globalNum);
1456         globalNum=(*it)->getEnd();
1457         its.push_back(bgEnd);
1458         ret=true;
1459       }
1460   if(ret)
1461     _field_pm_pt_pd=newPmPtPd;
1462   return ret;
1463 }
1464
1465 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1466 {
1467 }
1468
1469 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc):_father(fath),_geo_type(geoType)
1470 {
1471   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1472   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1473   med_geometry_type mgeoti;
1474   med_entity_type menti;
1475   menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1476   int nbProfiles=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1477   _field_pm_pt_pd.resize(nbProfiles);
1478   for(int i=0;i<nbProfiles;i++)
1479     {
1480       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1481     }
1482   if(type==ON_CELLS)
1483     {
1484       int nbProfiles2=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName);
1485       for(int i=0;i<nbProfiles2;i++)
1486         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i+1));
1487     }
1488 }
1489
1490 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1491 {
1492   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1493     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1494 }
1495
1496 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1497 {
1498   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1499     (*it)->loadBigArray(fid,nasc);
1500 }
1501
1502 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1503 {
1504   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1505     {
1506       (*it)->copyOptionsFrom(*this);
1507       (*it)->writeLL(fid,nasc);
1508     }
1509 }
1510
1511 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1512 {
1513   switch(ikType)
1514     {
1515     case ON_CELLS:
1516       medfGeoType=typmai3[(int)ikGeoType];
1517       return MED_CELL;
1518     case ON_NODES:
1519       medfGeoType=MED_NONE;
1520       return MED_NODE;
1521     case ON_GAUSS_NE:
1522       medfGeoType=typmai3[(int)ikGeoType];
1523       return MED_NODE_ELEMENT;
1524     case ON_GAUSS_PT:
1525       medfGeoType=typmai3[(int)ikGeoType];
1526       return MED_CELL;
1527     default:
1528       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1529     }
1530   return MED_UNDEF_ENTITY_TYPE;
1531 }
1532
1533 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc)
1534 {
1535   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc);
1536 }
1537
1538 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1539 {
1540   return new MEDFileFieldPerMesh(fath,mesh);
1541 }
1542
1543 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1544 {
1545   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1546 }
1547
1548 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildren() const
1549 {
1550   std::vector<const BigMemoryObject *> ret;
1551   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1552     {
1553       const MEDFileFieldPerMeshPerType *cur(*it);
1554       if(cur)
1555         ret.push_back(cur);
1556     }
1557   return ret;
1558 }
1559
1560 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1561 {
1562   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1563   ret->_father=father;
1564   std::size_t i=0;
1565   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1566     {
1567       if((const MEDFileFieldPerMeshPerType *)*it)
1568         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1569     }
1570   return ret.retn();
1571 }
1572
1573 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1574 {
1575   std::string startLine(bkOffset,' ');
1576   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1577   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1578   int i=0;
1579   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1580     {
1581       const MEDFileFieldPerMeshPerType *cur=*it;
1582       if(cur)
1583         cur->simpleRepr(bkOffset,oss,i);
1584       else
1585         {
1586           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1587         }
1588     }
1589 }
1590
1591 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1592 {
1593   _mesh_name=mesh->getName();
1594   mesh->getTime(_mesh_iteration,_mesh_order);
1595 }
1596
1597 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1598 {
1599   int nbOfTypes=code.size()/3;
1600   int offset=0;
1601   for(int i=0;i<nbOfTypes;i++)
1602     {
1603       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1604       int nbOfCells=code[3*i+1];
1605       int pos=addNewEntryIfNecessary(type);
1606       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1607       offset+=nbOfCells;
1608     }
1609 }
1610
1611 /*!
1612  * This method is the most general one. No optimization is done here.
1613  * \param [in] multiTypePfl is the end user profile specified in high level API
1614  * \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].
1615  * \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.
1616  * \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.
1617  * \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.
1618  * \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.
1619  */
1620 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)
1621 {
1622   int nbOfTypes=code.size()/3;
1623   for(int i=0;i<nbOfTypes;i++)
1624     {
1625       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1626       int pos=addNewEntryIfNecessary(type);
1627       DataArrayInt *pfl=0;
1628       if(code[3*i+2]!=-1)
1629         pfl=idsPerType[code[3*i+2]];
1630       int nbOfTupes2=code2.size()/3;
1631       int found=0;
1632       for(;found<nbOfTupes2;found++)
1633         if(code[3*i]==code2[3*found])
1634           break;
1635       if(found==nbOfTupes2)
1636         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1637       _field_pm_pt[pos]->assignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1638     }
1639 }
1640
1641 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1642 {
1643   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1644   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1645 }
1646
1647 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1648 {
1649   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1650   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1651 }
1652
1653 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1654 {
1655   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1656     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1657 }
1658
1659 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1660 {
1661   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1662     (*it)->loadBigArraysRecursively(fid,nasc);
1663 }
1664
1665 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1666 {
1667   int nbOfTypes=_field_pm_pt.size();
1668   for(int i=0;i<nbOfTypes;i++)
1669     {
1670       _field_pm_pt[i]->copyOptionsFrom(*this);
1671       _field_pm_pt[i]->writeLL(fid,nasc);
1672     }
1673 }
1674
1675 void MEDFileFieldPerMesh::getDimension(int& dim) const
1676 {
1677   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1678     (*it)->getDimension(dim);
1679 }
1680
1681 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1682 {
1683   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1684     (*it)->fillTypesOfFieldAvailable(types);
1685 }
1686
1687 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
1688 {
1689   int sz=_field_pm_pt.size();
1690   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1691   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1692   for(int i=0;i<sz;i++)
1693     {
1694       types[i]=_field_pm_pt[i]->getGeoType();
1695       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1696     }
1697   return ret;
1698 }
1699
1700 double MEDFileFieldPerMesh::getTime() const
1701 {
1702   int tmp1,tmp2;
1703   return _father->getTime(tmp1,tmp2);
1704 }
1705
1706 int MEDFileFieldPerMesh::getIteration() const
1707 {
1708   return _father->getIteration();
1709 }
1710
1711 int MEDFileFieldPerMesh::getOrder() const
1712 {
1713   return _father->getOrder();
1714 }
1715
1716 int MEDFileFieldPerMesh::getNumberOfComponents() const
1717 {
1718   return _father->getNumberOfComponents();
1719 }
1720
1721 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1722 {
1723   if(!_father)
1724     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1725   return _father->getOrCreateAndGetArray();
1726 }
1727
1728 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1729 {
1730   if(!_father)
1731     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1732   return _father->getOrCreateAndGetArray();
1733 }
1734
1735 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1736 {
1737   return _father->getInfo();
1738 }
1739
1740 /*!
1741  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1742  * 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.
1743  * It returns 2 output vectors :
1744  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1745  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1746  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1747  */
1748 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)
1749 {
1750   int notNullPflsSz=0;
1751   int nbOfArrs=geoTypes.size();
1752   for(int i=0;i<nbOfArrs;i++)
1753     if(pfls[i])
1754       notNullPflsSz++;
1755   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1756   int nbOfDiffGeoTypes=geoTypes3.size();
1757   code.resize(3*nbOfDiffGeoTypes);
1758   notNullPfls.resize(notNullPflsSz);
1759   notNullPflsSz=0;
1760   int j=0;
1761   for(int i=0;i<nbOfDiffGeoTypes;i++)
1762     {
1763       int startZone=j;
1764       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1765       std::vector<const DataArrayInt *> notNullTmp;
1766       if(pfls[j])
1767         notNullTmp.push_back(pfls[j]);
1768       j++;
1769       for(;j<nbOfArrs;j++)
1770         if(geoTypes[j]==refType)
1771           {
1772             if(pfls[j])
1773               notNullTmp.push_back(pfls[j]);
1774           }
1775         else
1776           break;
1777       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1778       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1779       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1780       code[3*i]=(int)refType;
1781       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1782       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1783       if(notNullTmp.empty())
1784         code[3*i+2]=-1;
1785       else
1786         {
1787           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1788           code[3*i+2]=notNullPflsSz++;
1789         }
1790     }
1791 }
1792
1793 /*!
1794  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1795  */
1796 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)
1797 {
1798   int sz=dads.size();
1799   int ret=0;
1800   for(int i=0;i<sz;i++)
1801     {
1802       if(locs[i]==-1)
1803         {
1804           if(type!=ON_GAUSS_NE)
1805             ret+=dads[i].second-dads[i].first;
1806           else
1807             {
1808               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1809               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1810             }
1811         }
1812       else
1813         {
1814           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1815           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1816         }
1817     }
1818   return ret;
1819 }
1820
1821 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1822 {
1823   std::vector<std::string> ret;
1824   std::set<std::string> ret2;
1825   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1826     {
1827       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1828       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1829         if(ret2.find(*it2)==ret2.end())
1830           {
1831             ret.push_back(*it2);
1832             ret2.insert(*it2);
1833           }
1834     }
1835   return ret;
1836 }
1837
1838 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1839 {
1840   std::vector<std::string> ret;
1841   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1842     {
1843       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1844       ret.insert(ret.end(),tmp.begin(),tmp.end());
1845     }
1846   return ret;
1847 }
1848
1849 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1850 {
1851   std::vector<std::string> ret;
1852   std::set<std::string> ret2;
1853   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1854     {
1855       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1856       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1857         if(ret2.find(*it2)==ret2.end())
1858           {
1859             ret.push_back(*it2);
1860             ret2.insert(*it2);
1861           }
1862     }
1863   return ret;
1864 }
1865
1866 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1867 {
1868   std::vector<std::string> ret;
1869   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1870     {
1871       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1872       ret.insert(ret.end(),tmp.begin(),tmp.end());
1873     }
1874   return ret;
1875 }
1876
1877 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1878 {
1879   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1880     {
1881       if((*it).first==_mesh_name)
1882         {
1883           _mesh_name=(*it).second;
1884           return true;
1885         }
1886     }
1887   return false;
1888 }
1889
1890 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1891                                                       MEDFileFieldGlobsReal& glob)
1892 {
1893   if(_mesh_name!=meshName)
1894     return false;
1895   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1896   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1897   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1898   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1899   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1900   getUndergroundDataArrayExt(entries);
1901   DataArray *arr0=getOrCreateAndGetArray();//tony
1902   if(!arr0)
1903     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
1904   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
1905   if(!arr0)
1906     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
1907   int sz=0;
1908   if(!arr)
1909     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1910   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1911     {
1912       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1913         {
1914           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1915           sz+=(*it).second.second-(*it).second.first;
1916         }
1917       else
1918         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1919     }
1920   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1921   ////////////////////
1922   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1923   int *workI2=explicitIdsOldInMesh->getPointer();
1924   int sz1=0,sz2=0,sid=1;
1925   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1926   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1927   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1928     {
1929       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1930       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1931       int *workI=explicitIdsOldInArr->getPointer();
1932       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1933         {
1934           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1935           (*itL2)->setLocId(sz2);
1936           (*itL2)->_tmp_work1=(*itL2)->getStart();
1937           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1938         }
1939       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1940     }
1941   explicitIdsOldInMesh->reAlloc(sz2);
1942   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1943   ////////////////////
1944   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1945   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1946   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1947   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1948     {
1949       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1950       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1951       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1952     }
1953   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1954   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1955   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1956     {
1957       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1958       int newStart=elt->getLocId();
1959       elt->setLocId((*it)->getGeoType());
1960       elt->setNewStart(newStart);
1961       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1962       entriesKeptNew.push_back(elt);
1963       entriesKeptNew2.push_back(elt);
1964     }
1965   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1966   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1967   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1968   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1969   bool ret=false;
1970   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1971     {
1972       sid=0;
1973       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1974         {
1975           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1976           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1977           }*/
1978       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1979                                                             glob,arr2,otherEntriesNew) || ret;
1980     }
1981   if(!ret)
1982     return false;
1983   // Assign new dispatching
1984   assignNewLeaves(otherEntriesNew);
1985   arr->cpyFrom(*arr2);
1986   return true;
1987 }
1988
1989 /*!
1990  * \param [in,out] globalNum a global numbering counter for the renumbering.
1991  * \param [out] its - list of pair (start,stop) kept
1992  */
1993 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1994 {
1995   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
1996   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1997     {
1998       std::vector< std::pair<int,int> > its2;
1999       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2000         {
2001           ret.push_back(*it);
2002           its.insert(its.end(),its2.begin(),its2.end());
2003         }
2004     }
2005   _field_pm_pt=ret;
2006 }
2007
2008 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2009 {
2010   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2011   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2012     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2013   //
2014   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2015   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2016   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2017   for(;it1!=types.end();it1++,it2++)
2018     {
2019       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2020       elt->setLeaves((*it1).second);
2021       *it2=elt;
2022     }
2023   _field_pm_pt=fieldPmPt;
2024 }
2025
2026 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2027 {
2028   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2029     (*it)->changePflsRefsNamesGen(mapOfModif);
2030 }
2031
2032 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2033 {
2034   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2035     (*it)->changeLocsRefsNamesGen(mapOfModif);
2036 }
2037
2038 /*!
2039  * \param [in] mesh is the whole mesh
2040  */
2041 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2042 {
2043   if(_field_pm_pt.empty())
2044     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2045   //
2046   std::vector< std::pair<int,int> > dads;
2047   std::vector<const DataArrayInt *> pfls;
2048   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2049   std::vector<int> locs,code;
2050   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2051   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2052     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2053   // Sort by types
2054   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2055   if(code.empty())
2056     {
2057       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2058       throw INTERP_KERNEL::Exception(oss.str().c_str());
2059     }
2060   //
2061   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2062   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2063   if(type!=ON_NODES)
2064     {
2065       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2066       if(!arr)
2067         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2068       else
2069         {
2070           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2071           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2072         }
2073     }
2074   else
2075     {
2076       if(code.size()!=3)
2077         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2078       int nb=code[1];
2079       if(code[2]==-1)
2080         {
2081           if(nb!=mesh->getNumberOfNodes())
2082             {
2083               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2084               oss << " nodes in mesh !";
2085               throw INTERP_KERNEL::Exception(oss.str().c_str());
2086             }
2087           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2088         }
2089       else
2090         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2091     }
2092 }
2093
2094 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2095 {
2096   if(_field_pm_pt.empty())
2097     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2098   //
2099   std::vector<std::pair<int,int> > dads;
2100   std::vector<const DataArrayInt *> pfls;
2101   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2102   std::vector<int> locs,code;
2103   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2104   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2105     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2106   // Sort by types
2107   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2108   if(code.empty())
2109     {
2110       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2111       throw INTERP_KERNEL::Exception(oss.str().c_str());
2112     }
2113   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2114   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2115   if(type!=ON_NODES)
2116     {
2117       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2118       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2119     }
2120   else
2121     {
2122       if(code.size()!=3)
2123         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2124       int nb=code[1];
2125       if(code[2]==-1)
2126         {
2127           if(nb!=mesh->getNumberOfNodes())
2128             {
2129               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2130               oss << " nodes in mesh !";
2131               throw INTERP_KERNEL::Exception(oss.str().c_str());
2132             }
2133         }
2134       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2135     }
2136   //
2137   return 0;
2138 }
2139
2140 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2141 {
2142   int globalSz=0;
2143   int nbOfEntries=0;
2144   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2145     {
2146       (*it)->getSizes(globalSz,nbOfEntries);
2147     }
2148   entries.resize(nbOfEntries);
2149   nbOfEntries=0;
2150   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2151     {
2152       (*it)->fillValues(nbOfEntries,entries);
2153     }
2154 }
2155
2156 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2157 {
2158   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2159     {
2160       if((*it)->getGeoType()==typ)
2161         return (*it)->getLeafGivenLocId(locId);
2162     }
2163   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2164   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2165   oss << "Possiblities are : ";
2166   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2167     {
2168       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2169       oss << "\"" << cm2.getRepr() << "\", ";
2170     }
2171   throw INTERP_KERNEL::Exception(oss.str().c_str());
2172 }
2173
2174 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2175 {
2176   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2177     {
2178       if((*it)->getGeoType()==typ)
2179         return (*it)->getLeafGivenLocId(locId);
2180     }
2181   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2182   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2183   oss << "Possiblities are : ";
2184   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2185     {
2186       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2187       oss << "\"" << cm2.getRepr() << "\", ";
2188     }
2189   throw INTERP_KERNEL::Exception(oss.str().c_str());
2190 }
2191
2192 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2193 {
2194   int i=0;
2195   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2196   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2197   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2198     {
2199       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2200       if(type==curType)
2201         return i;
2202       else
2203         {
2204           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2205           if(pos>pos2)
2206             it2=it+1;
2207         }
2208     }
2209   int ret=std::distance(_field_pm_pt.begin(),it2);
2210   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2211   return ret;
2212 }
2213
2214 /*!
2215  * 'dads' and 'locs' input parameters have the same number of elements
2216  * \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
2217  */
2218 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2219                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2220                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2221 {
2222   isPfl=false;
2223   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2224   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2225   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2226   const std::vector<std::string>& infos=getInfo();
2227   da->setInfoOnComponents(infos);
2228   da->setName("");
2229   if(type==ON_GAUSS_PT)
2230     {
2231       int offset=0;
2232       int nbOfArrs=dads.size();
2233       for(int i=0;i<nbOfArrs;i++)
2234         {
2235           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2236           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2237           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2238           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2239           di->alloc(nbOfElems,1);
2240           di->iota(offset);
2241           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2242           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2243           offset+=nbOfElems;
2244         }
2245     }
2246   arrOut=da;
2247   return ret.retn();
2248 }
2249
2250 /*!
2251  * 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.
2252  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2253  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2254  * The order of cells in the returned field is those imposed by the profile.
2255  * \param [in] mesh is the global mesh.
2256  */
2257 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2258                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2259                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2260                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2261 {
2262   if(da->isIdentity())
2263     {
2264       int nbOfTuples=da->getNumberOfTuples();
2265       if(nbOfTuples==mesh->getNumberOfCells())
2266         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2267     }
2268   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2269   m2->setName(mesh->getName().c_str());
2270   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2271   isPfl=true;
2272   return ret.retn();
2273 }
2274
2275 /*!
2276  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2277  */
2278 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2279                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2280                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const throw(INTERP_KERNEL::Exception)
2281 {
2282   if(da->isIdentity())
2283     {
2284       int nbOfTuples=da->getNumberOfTuples();
2285       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2286         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2287     }
2288   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2289   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2290   if(meshu)
2291     {
2292       if(meshu->getNodalConnectivity()==0)
2293         {
2294           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2295           int nb=da->getNbOfElems();
2296           const int *ptr=da->getConstPointer();
2297           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2298           meshuc->allocateCells(nb);
2299           for(int i=0;i<nb;i++)
2300             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2301           meshuc->finishInsertingCells();
2302           ret->setMesh(meshuc);
2303           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2304           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2305           disc->checkCoherencyBetween(meshuc,arrOut);
2306           return ret.retn();
2307         }
2308     }
2309   //
2310   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2311   isPfl=true;
2312   DataArrayInt *arr2=0;
2313   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2314   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2315   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2316   int nnodes=mesh2->getNumberOfNodes();
2317   if(nnodes==(int)da->getNbOfElems())
2318     {
2319       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2320       arrOut->renumberInPlace(da3->getConstPointer());
2321       mesh2->setName(mesh->getName().c_str());
2322       ret->setMesh(mesh2);
2323       return ret.retn();
2324     }
2325   else
2326     {
2327       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 !!!";
2328       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2329       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2330       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2331       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2332       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2333       throw INTERP_KERNEL::Exception(oss.str().c_str());
2334     }
2335   return 0;
2336 }
2337
2338 /*!
2339  * This method is the most light method of field retrieving.
2340  */
2341 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2342 {
2343   if(!pflIn)
2344     {
2345       pflOut=DataArrayInt::New();
2346       pflOut->alloc(nbOfElems,1);
2347       pflOut->iota(0);
2348     }
2349   else
2350     {
2351       pflOut=const_cast<DataArrayInt*>(pflIn);
2352       pflOut->incrRef();
2353     }
2354   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2355   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2356   const std::vector<std::string>& infos=getInfo();
2357   int nbOfComp=infos.size();
2358   for(int i=0;i<nbOfComp;i++)
2359     da->setInfoOnComponent(i,infos[i].c_str());
2360   safePfl->incrRef();
2361   return da.retn();
2362 }
2363
2364 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2365                                                                                                                                                                                                                  _mesh_csit(meshCsit),_father(fath)
2366 {
2367   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2368   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2369   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2370   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2371     {
2372       int nbProfile =MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[i],_mesh_csit,meshName,pflName,locName);
2373       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2374       int nbProfile2=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2375       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2376       if(nbProfile>0 || nbProfile2>0)
2377         {
2378           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc));
2379           if(nbProfile>0)
2380             _mesh_name=name0;
2381           else
2382             _mesh_name=name1;
2383         }
2384     }
2385   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2386   if(nbProfile>0)
2387     {
2388       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc));
2389       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2390     }
2391 }
2392
2393 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2394 {
2395   copyTinyInfoFrom(mesh);
2396 }
2397
2398 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2399 {
2400   if(id>=(int)_pfls.size())
2401     _pfls.resize(id+1);
2402   _pfls[id]=DataArrayInt::New();
2403   int lgth=MEDprofileSizeByName(fid,pflName.c_str());
2404   _pfls[id]->setName(pflName);
2405   _pfls[id]->alloc(lgth,1);
2406   MEDprofileRd(fid,pflName.c_str(),_pfls[id]->getPointer());
2407   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2408 }
2409
2410 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2411 {
2412   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2413   int sz;
2414   MEDprofileInfo(fid,i+1,pflName,&sz);
2415   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2416   if(i>=(int)_pfls.size())
2417     _pfls.resize(i+1);
2418   _pfls[i]=DataArrayInt::New();
2419   _pfls[i]->alloc(sz,1);
2420   _pfls[i]->setName(pflCpp.c_str());
2421   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2422   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2423 }
2424
2425 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2426 {
2427   int nbOfPfls=_pfls.size();
2428   for(int i=0;i<nbOfPfls;i++)
2429     {
2430       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2431       cpy->applyLin(1,1,0);
2432       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2433       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2434       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2435     }
2436   //
2437   int nbOfLocs=_locs.size();
2438   for(int i=0;i<nbOfLocs;i++)
2439     _locs[i]->writeLL(fid);
2440 }
2441
2442 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2443 {
2444   std::vector<std::string> pfls=getPfls();
2445   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2446     {
2447       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2448       if(it2==pfls.end())
2449         {
2450           _pfls.push_back(*it);
2451         }
2452       else
2453         {
2454           int id=std::distance(pfls.begin(),it2);
2455           if(!(*it)->isEqual(*_pfls[id]))
2456             {
2457               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2458               throw INTERP_KERNEL::Exception(oss.str().c_str());
2459             }
2460         }
2461     }
2462   std::vector<std::string> locs=getLocs();
2463   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2464     {
2465       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2466       if(it2==locs.end())
2467         {
2468           _locs.push_back(*it);
2469         }
2470       else
2471         {
2472           int id=std::distance(locs.begin(),it2);
2473           if(!(*it)->isEqual(*_locs[id],eps))
2474             {
2475               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2476               throw INTERP_KERNEL::Exception(oss.str().c_str());
2477             }
2478         }
2479     }
2480 }
2481
2482 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2483 {
2484   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2485     getProfile((*it).c_str());
2486 }
2487
2488 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2489 {
2490   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2491     getLocalization((*it).c_str());
2492 }
2493
2494 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2495 {
2496   std::vector<std::string> profiles=real.getPflsReallyUsed();
2497   int sz=profiles.size();
2498   _pfls.resize(sz);
2499   for(int i=0;i<sz;i++)
2500     loadProfileInFile(fid,i,profiles[i].c_str());
2501   //
2502   std::vector<std::string> locs=real.getLocsReallyUsed();
2503   sz=locs.size();
2504   _locs.resize(sz);
2505   for(int i=0;i<sz;i++)
2506     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2507 }
2508
2509 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2510 {
2511   int nProfil=MEDnProfile(fid);
2512   for(int i=0;i<nProfil;i++)
2513     loadProfileInFile(fid,i);
2514   int sz=MEDnLocalization(fid);
2515   _locs.resize(sz);
2516   for(int i=0;i<sz;i++)
2517     {
2518       _locs[i]=MEDFileFieldLoc::New(fid,i);
2519     }
2520 }
2521
2522 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2523 {
2524   return new MEDFileFieldGlobs(fname);
2525 }
2526
2527 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2528 {
2529   return new MEDFileFieldGlobs;
2530 }
2531
2532 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2533 {
2534   return _file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2535 }
2536
2537 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildren() const
2538 {
2539   std::vector<const BigMemoryObject *> ret;
2540   for(std::vector< MEDCouplingAutoRefCountObjectPtr< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2541     {
2542       const DataArrayInt *cur(*it);
2543       if(cur)
2544         ret.push_back(cur);
2545     }
2546   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2547     {
2548       const MEDFileFieldLoc *cur(*it);
2549       if(cur)
2550         ret.push_back(cur);
2551     }
2552   return ret;
2553 }
2554
2555 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const
2556 {
2557   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2558   std::size_t i=0;
2559   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2560     {
2561       if((const DataArrayInt *)*it)
2562         ret->_pfls[i]=(*it)->deepCpy();
2563     }
2564   i=0;
2565   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2566     {
2567       if((const MEDFileFieldLoc*)*it)
2568         ret->_locs[i]=(*it)->deepCpy();
2569     }
2570   return ret.retn();
2571 }
2572
2573 /*!
2574  * \throw if a profile in \a pfls in not in \a this.
2575  * \throw if a localization in \a locs in not in \a this.
2576  * \sa MEDFileFieldGlobs::deepCpyPart
2577  */
2578 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2579 {
2580   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2581   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2582     {
2583       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2584       if(!pfl)
2585         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2586       pfl->incrRef();
2587       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2588       ret->_pfls.push_back(pfl2);
2589     }
2590   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2591     {
2592       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2593       if(!loc)
2594         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2595       loc->incrRef();
2596       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2597       ret->_locs.push_back(loc2);
2598     }
2599   ret->setFileName(getFileName());
2600   return ret.retn();
2601 }
2602
2603 /*!
2604  * \throw if a profile in \a pfls in not in \a this.
2605  * \throw if a localization in \a locs in not in \a this.
2606  * \sa MEDFileFieldGlobs::shallowCpyPart
2607  */
2608 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2609 {
2610   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2611   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2612     {
2613       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2614       if(!pfl)
2615         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2616       ret->_pfls.push_back(pfl->deepCpy());
2617     }
2618   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2619     {
2620       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2621       if(!loc)
2622         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2623       ret->_locs.push_back(loc->deepCpy());
2624     }
2625   ret->setFileName(getFileName());
2626   return ret.retn();
2627 }
2628
2629 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2630 {
2631 }
2632
2633 MEDFileFieldGlobs::MEDFileFieldGlobs()
2634 {
2635 }
2636
2637 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2638 {
2639 }
2640
2641 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2642 {
2643   oss << "Profiles :\n";
2644   std::size_t n=_pfls.size();
2645   for(std::size_t i=0;i<n;i++)
2646     {
2647       oss << "  - #" << i << " ";
2648       const DataArrayInt *pfl=_pfls[i];
2649       if(pfl)
2650         oss << "\"" << pfl->getName() << "\"\n";
2651       else
2652         oss << "EMPTY !\n";
2653     }
2654   n=_locs.size();
2655   oss << "Localizations :\n";
2656   for(std::size_t i=0;i<n;i++)
2657     {
2658       oss << "  - #" << i << " ";
2659       const MEDFileFieldLoc *loc=_locs[i];
2660       if(loc)
2661         loc->simpleRepr(oss);
2662       else
2663         oss<< "EMPTY !\n";
2664     }
2665 }
2666
2667 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2668 {
2669   _file_name=fileName;
2670 }
2671
2672 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2673 {
2674   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2675     {
2676       DataArrayInt *elt(*it);
2677       if(elt)
2678         {
2679           std::string name(elt->getName());
2680           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2681             {
2682               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2683                 {
2684                   elt->setName((*it2).second.c_str());
2685                   return;
2686                 }
2687             }
2688         }
2689     }
2690 }
2691
2692 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2693 {
2694   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2695     {
2696       MEDFileFieldLoc *elt(*it);
2697       if(elt)
2698         {
2699           std::string name(elt->getName());
2700           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2701             {
2702               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2703                 {
2704                   elt->setName((*it2).second.c_str());
2705                   return;
2706                 }
2707             }
2708         }
2709     }
2710 }
2711
2712 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2713 {
2714   if(locId<0 || locId>=(int)_locs.size())
2715     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2716   return _locs[locId]->getNbOfGaussPtPerCell();
2717 }
2718
2719 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2720 {
2721   return getLocalizationFromId(getLocalizationId(locName));
2722 }
2723
2724 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2725 {
2726   if(locId<0 || locId>=(int)_locs.size())
2727     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2728   return *_locs[locId];
2729 }
2730
2731 namespace ParaMEDMEMImpl
2732 {
2733   class LocFinder
2734   {
2735   public:
2736     LocFinder(const std::string& loc):_loc(loc) { }
2737     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2738   private:
2739     const std::string &_loc;
2740   };
2741
2742   class PflFinder
2743   {
2744   public:
2745     PflFinder(const std::string& pfl):_pfl(pfl) { }
2746     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2747   private:
2748     const std::string& _pfl;
2749   };
2750 }
2751
2752 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2753 {
2754   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2755   if(it==_locs.end())
2756     {
2757       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2758       for(it=_locs.begin();it!=_locs.end();it++)
2759         oss << "\"" << (*it)->getName() << "\", ";
2760       throw INTERP_KERNEL::Exception(oss.str().c_str());
2761     }
2762   return std::distance(_locs.begin(),it);
2763 }
2764
2765 /*!
2766  * The returned value is never null.
2767  */
2768 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2769 {
2770   std::string pflNameCpp(pflName);
2771   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2772   if(it==_pfls.end())
2773     {
2774       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2775       for(it=_pfls.begin();it!=_pfls.end();it++)
2776         oss << "\"" << (*it)->getName() << "\", ";
2777       throw INTERP_KERNEL::Exception(oss.str().c_str());
2778     }
2779   return *it;
2780 }
2781
2782 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2783 {
2784   if(pflId<0 || pflId>=(int)_pfls.size())
2785     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2786   return _pfls[pflId];
2787 }
2788
2789 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
2790 {
2791   if(locId<0 || locId>=(int)_locs.size())
2792     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2793   return *_locs[locId];
2794 }
2795
2796 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
2797 {
2798   return getLocalizationFromId(getLocalizationId(locName));
2799 }
2800
2801 /*!
2802  * The returned value is never null.
2803  */
2804 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
2805 {
2806   std::string pflNameCpp(pflName);
2807   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2808   if(it==_pfls.end())
2809     {
2810       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2811       for(it=_pfls.begin();it!=_pfls.end();it++)
2812         oss << "\"" << (*it)->getName() << "\", ";
2813       throw INTERP_KERNEL::Exception(oss.str().c_str());
2814     }
2815   return *it;
2816 }
2817
2818 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
2819 {
2820   if(pflId<0 || pflId>=(int)_pfls.size())
2821     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2822   return _pfls[pflId];
2823 }
2824
2825 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
2826 {
2827   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2828   int i=0;
2829   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2830     {
2831       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2832         newPfls.push_back(*it);
2833     }
2834   _pfls=newPfls;
2835 }
2836
2837 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
2838 {
2839   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2840   int i=0;
2841   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2842     {
2843       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2844         newLocs.push_back(*it);
2845     }
2846   _locs=newLocs;
2847 }
2848
2849 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2850 {
2851   int sz=_pfls.size();
2852   std::vector<std::string> ret(sz);
2853   for(int i=0;i<sz;i++)
2854     ret[i]=_pfls[i]->getName();
2855   return ret;
2856 }
2857
2858 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2859 {
2860   int sz=_locs.size();
2861   std::vector<std::string> ret(sz);
2862   for(int i=0;i<sz;i++)
2863     ret[i]=_locs[i]->getName();
2864   return ret;
2865 }
2866
2867 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
2868 {
2869   std::vector<std::string> v=getPfls();
2870   std::string s(pflName);
2871   return std::find(v.begin(),v.end(),s)!=v.end();
2872 }
2873
2874 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
2875 {
2876   std::vector<std::string> v=getLocs();
2877   std::string s(locName);
2878   return std::find(v.begin(),v.end(),s)!=v.end();
2879 }
2880
2881 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2882 {
2883   std::map<int,std::vector<int> > m;
2884   int i=0;
2885   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2886     {
2887       const DataArrayInt *tmp=(*it);
2888       if(tmp)
2889         {
2890           m[tmp->getHashCode()].push_back(i);
2891         }
2892     }
2893   std::vector< std::vector<int> > ret;
2894   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2895     {
2896       if((*it2).second.size()>1)
2897         {
2898           std::vector<int> ret0;
2899           bool equalityOrNot=false;
2900           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2901             {
2902               std::vector<int>::const_iterator it4=it3; it4++;
2903               for(;it4!=(*it2).second.end();it4++)
2904                 {
2905                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2906                     {
2907                       if(!equalityOrNot)
2908                         ret0.push_back(*it3);
2909                       ret0.push_back(*it4);
2910                       equalityOrNot=true;
2911                     }
2912                 }
2913             }
2914           if(!ret0.empty())
2915             ret.push_back(ret0);
2916         }
2917     }
2918   return ret;
2919 }
2920
2921 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2922 {
2923   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2924 }
2925
2926 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
2927 {
2928   std::string name(pfl->getName());
2929   if(name.empty())
2930     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2931   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2932     if(name==(*it)->getName())
2933       {
2934         if(!pfl->isEqual(*(*it)))
2935           {
2936             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2937             throw INTERP_KERNEL::Exception(oss.str().c_str());
2938           }
2939       }
2940   pfl->incrRef();
2941   _pfls.push_back(pfl);
2942 }
2943
2944 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)
2945 {
2946   std::string name(locName);
2947   if(name.empty())
2948     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2949   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2950   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2951     if((*it)->isName(locName))
2952       {
2953         if(!(*it)->isEqual(*obj,1e-12))
2954           {
2955             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2956             throw INTERP_KERNEL::Exception(oss.str().c_str());
2957           }
2958       }
2959   _locs.push_back(obj);
2960 }
2961
2962 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
2963 {
2964   std::vector<std::string> names=getPfls();
2965   return CreateNewNameNotIn("NewPfl_",names);
2966 }
2967
2968 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
2969 {
2970   std::vector<std::string> names=getLocs();
2971   return CreateNewNameNotIn("NewLoc_",names);
2972 }
2973
2974 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
2975 {
2976   for(std::size_t sz=0;sz<100000;sz++)
2977     {
2978       std::ostringstream tryName;
2979       tryName << prefix << sz;
2980       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2981         return tryName.str();
2982     }
2983   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2984 }
2985
2986 /*!
2987  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
2988  *  \param [in] fname - the file name.
2989  */
2990 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
2991 {
2992 }
2993
2994 /*!
2995  * Creates an empty MEDFileFieldGlobsReal.
2996  */
2997 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
2998 {
2999 }
3000
3001 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3002 {
3003   return 0;
3004 }
3005
3006 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildren() const
3007 {
3008   std::vector<const BigMemoryObject *> ret;
3009   if((const MEDFileFieldGlobs *)_globals)
3010     ret.push_back((const MEDFileFieldGlobs *)_globals);
3011   return ret;
3012 }
3013
3014 /*!
3015  * Returns a string describing profiles and Gauss points held in \a this.
3016  *  \return std::string - the description string.
3017  */
3018 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3019 {
3020   const MEDFileFieldGlobs *glob=_globals;
3021   std::ostringstream oss2; oss2 << glob;
3022   std::string stars(oss2.str().length(),'*');
3023   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3024   if(glob)
3025     glob->simpleRepr(oss);
3026   else
3027     oss << "NO GLOBAL INFORMATION !\n";
3028 }
3029
3030 void MEDFileFieldGlobsReal::resetContent()
3031 {
3032   _globals=MEDFileFieldGlobs::New();
3033 }
3034
3035 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3036 {
3037 }
3038
3039 /*!
3040  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3041  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3042  */
3043 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3044 {
3045   _globals=other._globals;
3046 }
3047
3048 /*!
3049  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3050  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3051  */
3052 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3053 {
3054   const MEDFileFieldGlobs *otherg(other._globals);
3055   if(!otherg)
3056     return ;
3057   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3058 }
3059
3060 /*!
3061  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3062  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3063  */
3064 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3065 {
3066   const MEDFileFieldGlobs *otherg(other._globals);
3067   if(!otherg)
3068     return ;
3069   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3070 }
3071
3072 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3073 {
3074   _globals=other._globals;
3075   if((const MEDFileFieldGlobs *)_globals)
3076     _globals=other._globals->deepCpy();
3077 }
3078
3079 /*!
3080  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3081  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3082  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3083  *         \a this and \a other MEDFileFieldGlobsReal.
3084  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3085  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3086  */
3087 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3088 {
3089   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3090   if(thisGlobals==otherGlobals)
3091     return ;
3092   if(!thisGlobals)
3093     {
3094       _globals=other._globals;
3095       return ;
3096     }
3097   _globals->appendGlobs(*other._globals,eps);
3098 }
3099
3100 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3101 {
3102   checkGlobsPflsPartCoherency();
3103   checkGlobsLocsPartCoherency();
3104 }
3105
3106 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3107 {
3108   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3109 }
3110
3111 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3112 {
3113   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3114 }
3115
3116 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3117 {
3118   contentNotNull()->loadProfileInFile(fid,id,pflName);
3119 }
3120
3121 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3122 {
3123   contentNotNull()->loadProfileInFile(fid,id);
3124 }
3125
3126 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3127 {
3128   contentNotNull()->loadGlobals(fid,*this);
3129 }
3130
3131 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3132 {
3133   contentNotNull()->loadAllGlobals(fid);
3134 }
3135
3136 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3137 {
3138   contentNotNull()->writeGlobals(fid,opt);
3139 }
3140
3141 /*!
3142  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3143  * or getPflsReallyUsedMulti().
3144  *  \return std::vector<std::string> - a sequence of names of all profiles.
3145  */
3146 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3147 {
3148   return contentNotNull()->getPfls();
3149 }
3150
3151 /*!
3152  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3153  * or getLocsReallyUsedMulti().
3154  *  \return std::vector<std::string> - a sequence of names of all localizations.
3155  */
3156 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3157 {
3158   return contentNotNull()->getLocs();
3159 }
3160
3161 /*!
3162  * Checks if the profile with a given name exists.
3163  *  \param [in] pflName - the profile name of interest.
3164  *  \return bool - \c true if the profile named \a pflName exists.
3165  */
3166 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3167 {
3168   return contentNotNull()->existsPfl(pflName);
3169 }
3170
3171 /*!
3172  * Checks if the localization with a given name exists.
3173  *  \param [in] locName - the localization name of interest.
3174  *  \return bool - \c true if the localization named \a locName exists.
3175  */
3176 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3177 {
3178   return contentNotNull()->existsLoc(locName);
3179 }
3180
3181 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3182 {
3183   return contentNotNull()->createNewNameOfPfl();
3184 }
3185
3186 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3187 {
3188   return contentNotNull()->createNewNameOfLoc();
3189 }
3190
3191 /*!
3192  * Sets the name of a MED file.
3193  *  \param [inout] fileName - the file name.
3194  */
3195 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3196 {
3197   contentNotNull()->setFileName(fileName);
3198 }
3199
3200 /*!
3201  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3202  * in the same order.
3203  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3204  *          Each item of this sequence is a vector containing ids of equal profiles.
3205  */
3206 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3207 {
3208   return contentNotNull()->whichAreEqualProfiles();
3209 }
3210
3211 /*!
3212  * Finds equal localizations.
3213  *  \param [in] eps - a precision used to compare real values of the localizations.
3214  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3215  *          Each item of this sequence is a vector containing ids of equal localizations.
3216  */
3217 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3218 {
3219   return contentNotNull()->whichAreEqualLocs(eps);
3220 }
3221
3222 /*!
3223  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3224  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3225  *        this sequence is a pair whose 
3226  *        - the first item is a vector of profile names to replace by the second item,
3227  *        - the second item is a profile name to replace every profile name of the first item.
3228  */
3229 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3230 {
3231   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3232 }
3233
3234 /*!
3235  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3236  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3237  *        this sequence is a pair whose 
3238  *        - the first item is a vector of localization names to replace by the second item,
3239  *        - the second item is a localization name to replace every localization name of the first item.
3240  */
3241 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3242 {
3243   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3244 }
3245
3246 /*!
3247  * Replaces references to some profiles (a reference is a profile name) by references
3248  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3249  * them-selves accordingly. <br>
3250  * This method is a generalization of changePflName().
3251  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3252  *        this sequence is a pair whose 
3253  *        - the first item is a vector of profile names to replace by the second item,
3254  *        - the second item is a profile name to replace every profile of the first item.
3255  * \sa changePflsRefsNamesGen()
3256  * \sa changePflName()
3257  */
3258 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3259 {
3260   changePflsRefsNamesGen(mapOfModif);
3261   changePflsNamesInStruct(mapOfModif);
3262 }
3263
3264 /*!
3265  * Replaces references to some localizations (a reference is a localization name) by references
3266  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3267  * them-selves accordingly. <br>
3268  * This method is a generalization of changeLocName().
3269  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3270  *        this sequence is a pair whose 
3271  *        - the first item is a vector of localization names to replace by the second item,
3272  *        - the second item is a localization name to replace every localization of the first item.
3273  * \sa changeLocsRefsNamesGen()
3274  * \sa changeLocName()
3275  */
3276 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3277 {
3278   changeLocsRefsNamesGen(mapOfModif);
3279   changeLocsNamesInStruct(mapOfModif);
3280 }
3281
3282 /*!
3283  * Renames the profile having a given name and updates references to this profile.
3284  *  \param [in] oldName - the name of the profile to rename.
3285  *  \param [in] newName - a new name of the profile.
3286  * \sa changePflsNames().
3287  */
3288 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3289 {
3290   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3291   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3292   mapOfModif[0]=p;
3293   changePflsNames(mapOfModif);
3294 }
3295
3296 /*!
3297  * Renames the localization having a given name and updates references to this localization.
3298  *  \param [in] oldName - the name of the localization to rename.
3299  *  \param [in] newName - a new name of the localization.
3300  * \sa changeLocsNames().
3301  */
3302 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3303 {
3304   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3305   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3306   mapOfModif[0]=p;
3307   changeLocsNames(mapOfModif);
3308 }
3309
3310 /*!
3311  * Removes duplicated profiles. Returns a map used to update references to removed 
3312  * profiles via changePflsRefsNamesGen().
3313  * Equal profiles are found using whichAreEqualProfiles().
3314  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3315  *          a sequence describing the performed replacements of profiles. Each element of
3316  *          this sequence is a pair whose
3317  *          - the first item is a vector of profile names replaced by the second item,
3318  *          - the second item is a profile name replacing every profile of the first item.
3319  */
3320 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3321 {
3322   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3323   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3324   int i=0;
3325   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3326     {
3327       std::vector< std::string > tmp((*it).size());
3328       int j=0;
3329       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3330         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3331       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3332       ret[i]=p;
3333       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3334       killProfileIds(tmp2);
3335     }
3336   changePflsRefsNamesGen(ret);
3337   return ret;
3338 }
3339
3340 /*!
3341  * Removes duplicated localizations. Returns a map used to update references to removed 
3342  * localizations via changeLocsRefsNamesGen().
3343  * Equal localizations are found using whichAreEqualLocs().
3344  *  \param [in] eps - a precision used to compare real values of the localizations.
3345  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3346  *          a sequence describing the performed replacements of localizations. Each element of
3347  *          this sequence is a pair whose
3348  *          - the first item is a vector of localization names replaced by the second item,
3349  *          - the second item is a localization name replacing every localization of the first item.
3350  */
3351 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3352 {
3353   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3354   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3355   int i=0;
3356   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3357     {
3358       std::vector< std::string > tmp((*it).size());
3359       int j=0;
3360       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3361         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3362       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3363       ret[i]=p;
3364       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3365       killLocalizationIds(tmp2);
3366     }
3367   changeLocsRefsNamesGen(ret);
3368   return ret;
3369 }
3370
3371 /*!
3372  * Returns number of Gauss points per cell in a given localization.
3373  *  \param [in] locId - an id of the localization of interest.
3374  *  \return int - the number of the Gauss points per cell.
3375  */
3376 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3377 {
3378   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3379 }
3380
3381 /*!
3382  * Returns an id of a localization by its name.
3383  *  \param [in] loc - the localization name of interest.
3384  *  \return int - the id of the localization.
3385  *  \throw If there is no a localization named \a loc.
3386  */
3387 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3388 {
3389   return contentNotNull()->getLocalizationId(loc);
3390 }
3391
3392 /*!
3393  * Returns the name of the MED file.
3394  *  \return const std::string&  - the MED file name.
3395  */
3396 std::string MEDFileFieldGlobsReal::getFileName() const
3397 {
3398   return contentNotNull()->getFileName();
3399 }
3400
3401 /*!
3402  * Returns a localization object by its name.
3403  *  \param [in] locName - the name of the localization of interest.
3404  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3405  *  \throw If there is no a localization named \a locName.
3406  */
3407 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3408 {
3409   return contentNotNull()->getLocalization(locName);
3410 }
3411
3412 /*!
3413  * Returns a localization object by its id.
3414  *  \param [in] locId - the id of the localization of interest.
3415  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3416  *  \throw If there is no a localization with id \a locId.
3417  */
3418 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3419 {
3420   return contentNotNull()->getLocalizationFromId(locId);
3421 }
3422
3423 /*!
3424  * Returns a profile array by its name.
3425  *  \param [in] pflName - the name of the profile of interest.
3426  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3427  *  \throw If there is no a profile named \a pflName.
3428  */
3429 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3430 {
3431   return contentNotNull()->getProfile(pflName);
3432 }
3433
3434 /*!
3435  * Returns a profile array by its id.
3436  *  \param [in] pflId - the id of the profile of interest.
3437  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3438  *  \throw If there is no a profile with id \a pflId.
3439  */
3440 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3441 {
3442   return contentNotNull()->getProfileFromId(pflId);
3443 }
3444
3445 /*!
3446  * Returns a localization object, apt for modification, by its id.
3447  *  \param [in] locId - the id of the localization of interest.
3448  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3449  *          having the id \a locId.
3450  *  \throw If there is no a localization with id \a locId.
3451  */
3452 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3453 {
3454   return contentNotNull()->getLocalizationFromId(locId);
3455 }
3456
3457 /*!
3458  * Returns a localization object, apt for modification, by its name.
3459  *  \param [in] locName - the name of the localization of interest.
3460  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3461  *          having the name \a locName.
3462  *  \throw If there is no a localization named \a locName.
3463  */
3464 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3465 {
3466   return contentNotNull()->getLocalization(locName);
3467 }
3468
3469 /*!
3470  * Returns a profile array, apt for modification, by its name.
3471  *  \param [in] pflName - the name of the profile of interest.
3472  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3473  *  \throw If there is no a profile named \a pflName.
3474  */
3475 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3476 {
3477   return contentNotNull()->getProfile(pflName);
3478 }
3479
3480 /*!
3481  * Returns a profile array, apt for modification, by its id.
3482  *  \param [in] pflId - the id of the profile of interest.
3483  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3484  *  \throw If there is no a profile with id \a pflId.
3485  */
3486 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3487 {
3488   return contentNotNull()->getProfileFromId(pflId);
3489 }
3490
3491 /*!
3492  * Removes profiles given by their ids. No data is updated to track this removal.
3493  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3494  */
3495 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3496 {
3497   contentNotNull()->killProfileIds(pflIds);
3498 }
3499
3500 /*!
3501  * Removes localizations given by their ids. No data is updated to track this removal.
3502  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3503  */
3504 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3505 {
3506   contentNotNull()->killLocalizationIds(locIds);
3507 }
3508
3509 /*!
3510  * Stores a profile array.
3511  *  \param [in] pfl - the profile array to store.
3512  *  \throw If the name of \a pfl is empty.
3513  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3514  *         different ids.
3515  */
3516 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3517 {
3518   contentNotNull()->appendProfile(pfl);
3519 }
3520
3521 /*!
3522  * Adds a new localization of Gauss points.
3523  *  \param [in] locName - the name of the new localization.
3524  *  \param [in] geoType - a geometrical type of the reference cell.
3525  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3526  *         must be \c nbOfNodesPerCell * \c dimOfType.
3527  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3528  *         must be  _wg_.size() * \c dimOfType.
3529  *  \param [in] w - the weights of Gauss points.
3530  *  \throw If \a locName is empty.
3531  *  \throw If a localization with the name \a locName already exists but is
3532  *         different form the new one.
3533  */
3534 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)
3535 {
3536   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3537 }
3538
3539 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3540 {
3541   MEDFileFieldGlobs *g(_globals);
3542   if(!g)
3543     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3544   return g;
3545 }
3546
3547 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3548 {
3549   const MEDFileFieldGlobs *g(_globals);
3550   if(!g)
3551     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3552   return g;
3553 }
3554
3555 //= MEDFileFieldNameScope
3556
3557 MEDFileFieldNameScope::MEDFileFieldNameScope()
3558 {
3559 }
3560
3561 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3562 {
3563 }
3564
3565 /*!
3566  * Returns the name of \a this field.
3567  *  \return std::string - a string containing the field name.
3568  */
3569 std::string MEDFileFieldNameScope::getName() const
3570 {
3571   return _name;
3572 }
3573
3574 /*!
3575  * Sets name of \a this field
3576  *  \param [in] name - the new field name.
3577  */
3578 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3579 {
3580   _name=fieldName;
3581 }
3582
3583 std::string MEDFileFieldNameScope::getDtUnit() const
3584 {
3585   return _dt_unit;
3586 }
3587
3588 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3589 {
3590   _dt_unit=dtUnit;
3591 }
3592
3593 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3594 {
3595   _name=other._name;
3596   _dt_unit=other._dt_unit;
3597 }
3598
3599 //= MEDFileAnyTypeField1TSWithoutSDA
3600
3601 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3602 {
3603   _field_per_mesh.resize(other._field_per_mesh.size());
3604   std::size_t i=0;
3605   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3606     {
3607       if((const MEDFileFieldPerMesh *)*it)
3608         _field_per_mesh[i]=(*it)->deepCpy(this);
3609     }
3610 }
3611
3612 /*!
3613  * Prints a string describing \a this field into a stream. This string is outputted 
3614  * by \c print Python command.
3615  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3616  *  \param [in,out] oss - the out stream.
3617  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3618  *          info id printed, else, not.
3619  */
3620 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3621 {
3622   std::string startOfLine(bkOffset,' ');
3623   oss << startOfLine << "Field ";
3624   if(bkOffset==0)
3625     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3626   oss << "on one time Step ";
3627   if(f1tsId>=0)
3628     oss << "(" << f1tsId << ") ";
3629   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3630   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3631   const DataArray *arr=getUndergroundDataArray();
3632   if(arr)
3633     {
3634       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3635       if(f1tsId<0)
3636         {
3637           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3638           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3639             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3640         }
3641       if(arr->isAllocated())
3642         {
3643           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3644         }
3645       else
3646         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3647     }
3648   else
3649     {
3650       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3651     }
3652   oss << startOfLine << "----------------------" << std::endl;
3653   if(!_field_per_mesh.empty())
3654     {
3655       int i=0;
3656       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3657         {
3658           const MEDFileFieldPerMesh *cur=(*it2);
3659           if(cur)
3660             cur->simpleRepr(bkOffset,oss,i);
3661           else
3662             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3663         }
3664     }
3665   else
3666     {
3667       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3668     }
3669   oss << startOfLine << "----------------------" << std::endl;
3670 }
3671
3672 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3673 {
3674   const DataArray *arr(getUndergroundDataArray());
3675   if(!arr)
3676     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3677   int nbOfCompo=arr->getNumberOfComponents();
3678   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3679   for(int i=0;i<nbOfCompo;i++)
3680     {
3681       ret[i]=deepCpy();
3682       std::vector<int> v(1,i);
3683       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3684       ret[i]->setArray(arr2);
3685     }
3686   return ret;
3687 }
3688
3689 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)
3690 {
3691 }
3692
3693 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3694 {
3695 }
3696
3697 /*!
3698  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3699  * empty. Returns -1 if this in on nodes.
3700  *  \return int - the dimension of \a this.
3701  */
3702 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3703 {
3704   int ret=-2;
3705   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3706     (*it)->getDimension(ret);
3707   return ret;
3708 }
3709
3710 /*!
3711  * Returns the mesh name.
3712  *  \return std::string - a string holding the mesh name.
3713  *  \throw If \c _field_per_mesh.empty()
3714  */
3715 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3716 {
3717   if(_field_per_mesh.empty())
3718     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3719   return _field_per_mesh[0]->getMeshName();
3720 }
3721
3722 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3723 {
3724   std::string oldName(getMeshName());
3725   std::vector< std::pair<std::string,std::string> > v(1);
3726   v[0].first=oldName; v[0].second=newMeshName;
3727   changeMeshNames(v);
3728 }
3729
3730 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3731 {
3732   bool ret=false;
3733   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3734     {
3735       MEDFileFieldPerMesh *cur(*it);
3736       if(cur)
3737         ret=cur->changeMeshNames(modifTab) || ret;
3738     }
3739   return ret;
3740 }
3741
3742 /*!
3743  * Returns the number of iteration of the state of underlying mesh.
3744  *  \return int - the iteration number.
3745  *  \throw If \c _field_per_mesh.empty()
3746  */
3747 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3748 {
3749   if(_field_per_mesh.empty())
3750     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3751   return _field_per_mesh[0]->getMeshIteration();
3752 }
3753
3754 /*!
3755  * Returns the order number of iteration of the state of underlying mesh.
3756  *  \return int - the order number.
3757  *  \throw If \c _field_per_mesh.empty()
3758  */
3759 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3760 {
3761   if(_field_per_mesh.empty())
3762     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3763   return _field_per_mesh[0]->getMeshOrder();
3764 }
3765
3766 /*!
3767  * Checks if \a this field is tagged by a given iteration number and a given
3768  * iteration order number.
3769  *  \param [in] iteration - the iteration number of interest.
3770  *  \param [in] order - the iteration order number of interest.
3771  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3772  *          \a this->getOrder() == \a order.
3773  */
3774 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3775 {
3776   return iteration==_iteration && order==_order;
3777 }
3778
3779 /*!
3780  * Returns number of iteration and order number of iteration when
3781  * \a this field has been calculated.
3782  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3783  *          order number.
3784  */
3785 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3786 {
3787   std::pair<int,int> p;
3788   fillIteration(p);
3789   return p;
3790 }
3791
3792 /*!
3793  * Returns number of iteration and order number of iteration when
3794  * \a this field has been calculated.
3795  *  \param [in,out] p - a pair returning the iteration number and the iteration
3796  *          order number.
3797  */
3798 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3799 {
3800   p.first=_iteration;
3801   p.second=_order;
3802 }
3803
3804 /*!
3805  * Returns all types of spatial discretization of \a this field.
3806  *  \param [in,out] types - a sequence of types of \a this field.
3807  */
3808 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
3809 {
3810   std::set<TypeOfField> types2;
3811   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3812     {
3813       (*it)->fillTypesOfFieldAvailable(types2);
3814     }
3815   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3816   std::copy(types2.begin(),types2.end(),bi);
3817 }
3818
3819 /*!
3820  * Returns all types of spatial discretization of \a this field.
3821  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3822  *          of \a this field.
3823  */
3824 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
3825 {
3826   std::vector<TypeOfField> ret;
3827   fillTypesOfFieldAvailable(ret);
3828   return ret;
3829 }
3830
3831 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3832 {
3833   std::vector<std::string> ret;
3834   std::set<std::string> ret2;
3835   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3836     {
3837       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3838       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3839         if(ret2.find(*it2)==ret2.end())
3840           {
3841             ret.push_back(*it2);
3842             ret2.insert(*it2);
3843           }
3844     }
3845   return ret;
3846 }
3847
3848 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3849 {
3850   std::vector<std::string> ret;
3851   std::set<std::string> ret2;
3852   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3853     {
3854       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3855       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3856         if(ret2.find(*it2)==ret2.end())
3857           {
3858             ret.push_back(*it2);
3859             ret2.insert(*it2);
3860           }
3861     }
3862   return ret;
3863 }
3864
3865 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3866 {
3867   std::vector<std::string> ret;
3868   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3869     {
3870       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3871       ret.insert(ret.end(),tmp.begin(),tmp.end());
3872     }
3873   return ret;
3874 }
3875
3876 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3877 {
3878   std::vector<std::string> ret;
3879   std::set<std::string> ret2;
3880   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3881     {
3882       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3883       ret.insert(ret.end(),tmp.begin(),tmp.end());
3884     }
3885   return ret;
3886 }
3887
3888 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3889 {
3890   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3891     (*it)->changePflsRefsNamesGen(mapOfModif);
3892 }
3893
3894 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3895 {
3896   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3897     (*it)->changeLocsRefsNamesGen(mapOfModif);
3898 }
3899
3900 /*!
3901  * Returns all attributes of parts of \a this field lying on a given mesh.
3902  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3903  * item of every of returned sequences refers to the _i_-th part of \a this field.
3904  * Thus all sequences returned by this method are of the same length equal to number
3905  * of different types of supporting entities.<br>
3906  * A field part can include sub-parts with several different spatial discretizations,
3907  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3908  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3909  * of a nested sequence corresponds to a type of spatial discretization.<br>
3910  * This method allows for iteration over MEDFile DataStructure without any overhead.
3911  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3912  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3913  *          not checked if \a mname == \c NULL).
3914  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3915  *          a field part is returned. 
3916  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3917  *          This sequence is of the same length as \a types. 
3918  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3919  *          discretization. A profile name can be empty.
3920  *          Length of this and of nested sequences is the same as that of \a typesF.
3921  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3922  *          discretization. A localization name can be empty.
3923  *          Length of this and of nested sequences is the same as that of \a typesF.
3924  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3925  *          of ids of tuples within the data array, per each type of spatial
3926  *          discretization within one mesh entity type. 
3927  *          Length of this and of nested sequences is the same as that of \a typesF.
3928  *  \throw If no field is lying on \a mname.
3929  */
3930 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
3931 {
3932   int meshId=0;
3933   if(!mname.empty())
3934     meshId=getMeshIdFromMeshName(mname);
3935   else
3936     if(_field_per_mesh.empty())
3937       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3938   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3939 }
3940
3941 /*!
3942  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3943  * maximal absolute dimension and values returned via the out parameter \a levs are 
3944  * dimensions relative to the maximal absolute dimension. <br>
3945  * This method is designed for MEDFileField1TS instances that have a discretization
3946  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3947  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3948  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3949  * Only these 3 discretizations will be taken into account here. If \a this is
3950  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3951  * This method is useful to make the link between the dimension of the underlying mesh
3952  * and the levels of \a this, because it is possible that the highest dimension of \a this
3953  * field is not equal to the dimension of the underlying mesh.
3954  * 
3955  * Let's consider the following case:
3956  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3957  * TETRA4, HEXA8, TRI3 and SEG2.
3958  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
3959  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
3960  *
3961  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
3962  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
3963  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
3964  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
3965  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
3966  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
3967  * For example<br>
3968  * to retrieve the highest level of
3969  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
3970  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
3971  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
3972  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
3973  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3974  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3975  *          not checked if \a mname == \c NULL).
3976  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
3977  *          absolute one. They are in decreasing order. This sequence is cleared before
3978  *          filling it in.
3979  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
3980  *  \throw If no field is lying on \a mname.
3981  */
3982 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
3983 {
3984   levs.clear();
3985   int meshId=getMeshIdFromMeshName(mname);
3986   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3987   std::vector< std::vector<TypeOfField> > typesF;
3988   std::vector< std::vector<std::string> > pfls, locs;
3989   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3990   if(types.empty())
3991     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3992   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3993   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
3994     return -1;
3995   st.erase(INTERP_KERNEL::NORM_ERROR);
3996   std::set<int> ret1;
3997   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
3998     {
3999       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4000       ret1.insert((int)cm.getDimension());
4001     }
4002   int ret=*std::max_element(ret1.begin(),ret1.end());
4003   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4004   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4005   return ret;
4006 }
4007
4008 /*!
4009  * \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.
4010  * \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.
4011  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4012  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4013  */
4014 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4015 {
4016   int mid=getMeshIdFromMeshName(mName);
4017   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4018 }
4019
4020 /*!
4021  * \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.
4022  * \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.
4023  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4024  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4025  */
4026 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4027 {
4028   int mid=getMeshIdFromMeshName(mName);
4029   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4030 }
4031
4032 /*!
4033  * \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.
4034  */
4035 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4036 {
4037   if(_field_per_mesh.empty())
4038     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4039   if(mName.empty())
4040     return 0;
4041   std::string mName2(mName);
4042   int ret=0;
4043   std::vector<std::string> msg;
4044   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4045     if(mName2==(*it)->getMeshName())
4046       return ret;
4047     else
4048       msg.push_back((*it)->getMeshName());
4049   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4050   oss << "Possible meshes are : ";
4051   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4052     oss << "\"" << (*it2) << "\" ";
4053   throw INTERP_KERNEL::Exception(oss.str().c_str());
4054 }
4055
4056 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4057 {
4058   if(!mesh)
4059     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4060   std::string tmp(mesh->getName());
4061   if(tmp.empty())
4062     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4063   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4064   int i=0;
4065   for(;it!=_field_per_mesh.end();it++,i++)
4066     {
4067       if((*it)->getMeshName()==tmp)
4068         return i;
4069     }
4070   int sz=_field_per_mesh.size();
4071   _field_per_mesh.resize(sz+1);
4072   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4073   return sz;
4074 }
4075
4076 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4077                                                             MEDFileFieldGlobsReal& glob)
4078 {
4079   bool ret=false;
4080   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4081     {
4082       MEDFileFieldPerMesh *fpm(*it);
4083       if(fpm)
4084         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4085     }
4086   return ret;
4087 }
4088
4089 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4090 {
4091   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4092   std::vector< std::vector<TypeOfField> > typesF;
4093   std::vector< std::vector<std::string> > pfls,locs;
4094   std::vector< std::vector<std::pair<int,int> > > bgEnd=getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs);
4095   std::set<TypeOfField> allEnt;
4096   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4097     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4098       allEnt.insert(*it2);
4099   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4100   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4101   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4102     {
4103       std::vector< std::pair<int,int> > its;
4104       ret[i]=shallowCpy();
4105       int newLgth=ret[i]->keepOnlySpatialDiscretization(*it3,its);
4106       ret[i]->updateData(newLgth,its);
4107     }
4108   return ret;
4109 }
4110
4111 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4112 {
4113   int globalCounter=0;
4114   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4115     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4116   return globalCounter;
4117 }
4118
4119 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4120 {
4121   if(_nb_of_tuples_to_be_allocated>=0)
4122     {
4123       _nb_of_tuples_to_be_allocated=newLgth;
4124       const DataArray *oldArr(getUndergroundDataArray());
4125       if(oldArr)
4126         {
4127           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4128           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4129           setArray(newArr);
4130           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4131         }
4132       return ;
4133     }
4134   if(_nb_of_tuples_to_be_allocated==-1)
4135     return ;
4136   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4137     {
4138       const DataArray *oldArr(getUndergroundDataArray());
4139       if(!oldArr || !oldArr->isAllocated())
4140         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4141       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4142       newArr->alloc(newLgth,getNumberOfComponents());
4143       if(oldArr)
4144         newArr->copyStringInfoFrom(*oldArr);
4145       int pos=0;
4146       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4147         {
4148           if((*it).second<(*it).first)
4149             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4150           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4151           pos+=(*it).second-(*it).first;
4152         }
4153       setArray(newArr);
4154       return ;
4155     }
4156   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4157 }
4158
4159 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4160 {
4161   if(_field_per_mesh.empty())
4162     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4163   if(_field_per_mesh.size()>1)
4164     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4165   _field_per_mesh[0]->copyOptionsFrom(opts);
4166   _field_per_mesh[0]->writeLL(fid,nasc);
4167 }
4168
4169 /*!
4170  * 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.
4171  * If false is returned the memory allocation is not required.
4172  */
4173 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4174 {
4175   if(_nb_of_tuples_to_be_allocated>=0)
4176     {
4177       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4178       _nb_of_tuples_to_be_allocated=-2;
4179       return true;
4180     }
4181   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4182     return false;
4183   if(_nb_of_tuples_to_be_allocated==-1)
4184     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4185   if(_nb_of_tuples_to_be_allocated<-3)
4186     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4187   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4188 }
4189
4190 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4191 {
4192   med_int numdt,numit;
4193   med_float dt;
4194   med_int nmesh;
4195   med_bool localMesh;
4196   med_int meshnumdt,meshnumit;
4197   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4198   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4199   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4200   if(_iteration!=numdt || _order!=numit)
4201     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4202   _field_per_mesh.resize(nmesh);
4203   for(int i=0;i<nmesh;i++)
4204     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit,nasc);//tony
4205   _nb_of_tuples_to_be_allocated=0;
4206   for(int i=0;i<nmesh;i++)
4207     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4208 }
4209
4210 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4211 {
4212   allocIfNecessaryTheArrayToReceiveDataFromFile();
4213   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4214     (*it)->loadBigArraysRecursively(fid,nasc);
4215 }
4216
4217 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4218 {
4219   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4220     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4221       (*it)->loadBigArraysRecursively(fid,nasc);
4222 }
4223
4224 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4225 {
4226   loadOnlyStructureOfDataRecursively(fid,nasc);
4227   loadBigArraysRecursively(fid,nasc);
4228 }
4229
4230 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4231 {
4232   DataArray *thisArr(getUndergroundDataArray());
4233   if(thisArr && thisArr->isAllocated())
4234     {
4235       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4236       thisArr->desallocate();
4237     }
4238 }
4239
4240 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4241 {
4242   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4243 }
4244
4245 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildren() const
4246 {
4247   std::vector<const BigMemoryObject *> ret;
4248   if(getUndergroundDataArray())
4249     ret.push_back(getUndergroundDataArray());
4250   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4251     {
4252       const MEDFileFieldPerMesh *cur(*it);
4253       if(cur)
4254         ret.push_back(cur);
4255     }
4256   return ret;
4257 }
4258
4259 /*!
4260  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4261  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4262  * "Sort By Type"), if not, an exception is thrown. 
4263  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4264  *  \param [in] arr - the array of values.
4265  *  \param [in,out] glob - the global data where profiles and localization present in
4266  *          \a field, if any, are added.
4267  *  \throw If the name of \a field is empty.
4268  *  \throw If the data array of \a field is not set.
4269  *  \throw If \a this->_arr is already allocated but has different number of components
4270  *         than \a field.
4271  *  \throw If the underlying mesh of \a field has no name.
4272  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4273  */
4274 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4275 {
4276   const MEDCouplingMesh *mesh=field->getMesh();
4277   //
4278   TypeOfField type=field->getTypeOfField();
4279   std::vector<DataArrayInt *> dummy;
4280   int start=copyTinyInfoFrom(field,arr);
4281   int pos=addNewEntryIfNecessary(mesh);
4282   if(type!=ON_NODES)
4283     {
4284       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4285       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4286     }
4287   else
4288     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4289 }
4290
4291 /*!
4292  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4293  * of a given mesh are used as the support of the given field (a real support is not used). 
4294  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4295  * Order of underlying mesh entities of the given field specified by \a profile parameter
4296  * is not prescribed; this method permutes field values to have them sorted by element
4297  * type as required for writing to MED file. A new profile is added only if no equal
4298  * profile is missing. 
4299  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4300  *  \param [in] arrOfVals - the values of the field \a field used.
4301  *  \param [in] mesh - the supporting mesh of \a field.
4302  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4303  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4304  *  \param [in,out] glob - the global data where profiles and localization present in
4305  *          \a field, if any, are added.
4306  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4307  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4308  *  \throw If the data array of \a field is not set.
4309  *  \throw If \a this->_arr is already allocated but has different number of components
4310  *         than \a field.
4311  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4312  *  \sa setFieldNoProfileSBT()
4313  */
4314 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4315 {
4316   if(!field)
4317     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4318   if(!arrOfVals || !arrOfVals->isAllocated())
4319     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4320   TypeOfField type=field->getTypeOfField();
4321   std::vector<DataArrayInt *> idsInPflPerType;
4322   std::vector<DataArrayInt *> idsPerType;
4323   std::vector<int> code,code2;
4324   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4325   if(type!=ON_NODES)
4326     {
4327       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4328       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4329       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4330       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4331       // start of check
4332       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4333       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4334       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4335         {
4336           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4337           throw INTERP_KERNEL::Exception(oss.str().c_str());
4338         }
4339       // end of check
4340       int start=copyTinyInfoFrom(field,arrOfVals);
4341       code2=m->getDistributionOfTypes();
4342       //
4343       int pos=addNewEntryIfNecessary(m);
4344       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4345     }
4346   else
4347     {
4348       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4349         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4350       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4351       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4352       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4353       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4354         {
4355           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4356           throw INTERP_KERNEL::Exception(oss.str().c_str());
4357         }
4358       int start=copyTinyInfoFrom(field,arrOfVals);
4359       int pos=addNewEntryIfNecessary(m);
4360       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4361     }
4362 }
4363
4364 /*!
4365  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4366  */
4367 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4368 {
4369   if(_nb_of_tuples_to_be_allocated>=0)
4370     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 !");
4371   DataArray *arr(getOrCreateAndGetArray());
4372   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4373   _nb_of_tuples_to_be_allocated=-3;
4374 }
4375
4376 /*!
4377  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4378  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4379  * larger by the size of \a field. Returns an id of the first not filled
4380  * tuple of \a this->_arr.
4381  *  \param [in] field - the field to copy the info on components and the name from.
4382  *  \return int - the id of first not initialized tuple of \a this->_arr.
4383  *  \throw If the name of \a field is empty.
4384  *  \throw If the data array of \a field is not set.
4385  *  \throw If \a this->_arr is already allocated but has different number of components
4386  *         than \a field.
4387  */
4388 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4389 {
4390   if(!field)
4391     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4392   std::string name(field->getName());
4393   setName(name.c_str());
4394   setDtUnit(field->getTimeUnit());
4395   if(name.empty())
4396     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4397   if(!arr)
4398     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4399   if(!arr->isAllocated())
4400     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4401   _dt=field->getTime(_iteration,_order);
4402   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4403   if(!getOrCreateAndGetArray()->isAllocated())
4404     {
4405       allocNotFromFile(arr->getNumberOfTuples());
4406       return 0;
4407     }
4408   else
4409     {
4410       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4411       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4412       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4413       _nb_of_tuples_to_be_allocated=-3;
4414       return oldNbOfTuples;
4415     }
4416 }
4417
4418 /*!
4419  * Returns number of components in \a this field
4420  *  \return int - the number of components.
4421  */
4422 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4423 {
4424   return getOrCreateAndGetArray()->getNumberOfComponents();
4425 }
4426
4427 /*!
4428  * Change info on components in \a this.
4429  * \throw If size of \a infos is not equal to the number of components already in \a this.
4430  */
4431 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4432 {
4433   DataArray *arr=getOrCreateAndGetArray();
4434   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4435 }
4436
4437 /*!
4438  * Returns info on components of \a this field.
4439  *  \return const std::vector<std::string>& - a sequence of strings each being an
4440  *          information on _i_-th component.
4441  */
4442 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4443 {
4444   const DataArray *arr=getOrCreateAndGetArray();
4445   return arr->getInfoOnComponents();
4446 }
4447
4448 /*!
4449  * Returns a mutable info on components of \a this field.
4450  *  \return std::vector<std::string>& - a sequence of strings each being an
4451  *          information on _i_-th component.
4452  */
4453 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4454 {
4455   DataArray *arr=getOrCreateAndGetArray();
4456   return arr->getInfoOnComponents();
4457 }
4458
4459 /*!
4460  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4461  *  \param [in] type - a spatial discretization of the new field.
4462  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4463  *  \param [in] mName - a name of the supporting mesh.
4464  *  \param [in] renumPol - specifies how to permute values of the result field according to
4465  *          the optional numbers of cells and nodes, if any. The valid values are
4466  *          - 0 - do not permute.
4467  *          - 1 - permute cells.
4468  *          - 2 - permute nodes.
4469  *          - 3 - permute cells and nodes.
4470  *
4471  *  \param [in] glob - the global data storing profiles and localization.
4472  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4473  *          caller is to delete this field using decrRef() as it is no more needed. 
4474  *  \throw If the MED file is not readable.
4475  *  \throw If there is no mesh named \a mName in the MED file.
4476  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4477  *  \throw If no field of \a this is lying on the mesh \a mName.
4478  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4479  */
4480 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4481 {
4482   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4483   if(mName.empty())
4484     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4485   else
4486     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4487   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4488 }
4489
4490 /*!
4491  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4492  *  \param [in] type - a spatial discretization of the new field.
4493  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4494  *  \param [in] renumPol - specifies how to permute values of the result field according to
4495  *          the optional numbers of cells and nodes, if any. The valid values are
4496  *          - 0 - do not permute.
4497  *          - 1 - permute cells.
4498  *          - 2 - permute nodes.
4499  *          - 3 - permute cells and nodes.
4500  *
4501  *  \param [in] glob - the global data storing profiles and localization.
4502  *  \param [in] mesh - the supporting mesh.
4503  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4504  *          caller is to delete this field using decrRef() as it is no more needed. 
4505  *  \throw If the MED file is not readable.
4506  *  \throw If no field of \a this is lying on \a mesh.
4507  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4508  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4509  */
4510 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4511 {
4512   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4513   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4514   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4515   if(meshDimRelToMax==1)
4516     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4517   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4518 }
4519
4520 /*!
4521  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4522  * given mesh. 
4523  *  \param [in] type - a spatial discretization of the new field.
4524  *  \param [in] mName - a name of the supporting mesh.
4525  *  \param [in] renumPol - specifies how to permute values of the result field according to
4526  *          the optional numbers of cells and nodes, if any. The valid values are
4527  *          - 0 - do not permute.
4528  *          - 1 - permute cells.
4529  *          - 2 - permute nodes.
4530  *          - 3 - permute cells and nodes.
4531  *
4532  *  \param [in] glob - the global data storing profiles and localization.
4533  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4534  *          caller is to delete this field using decrRef() as it is no more needed. 
4535  *  \throw If the MED file is not readable.
4536  *  \throw If there is no mesh named \a mName in the MED file.
4537  *  \throw If there are no mesh entities in the mesh.
4538  *  \throw If no field values of the given \a type are available.
4539  */
4540 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4541 {
4542   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4543   if(mName.empty())
4544     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4545   else
4546     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4547   int absDim=getDimension();
4548   int meshDimRelToMax=absDim-mm->getMeshDimension();
4549   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4550 }
4551
4552 /*!
4553  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4554  *  \param [in] type - a spatial discretization of the new field.
4555  *  \param [in] renumPol - specifies how to permute values of the result field according to
4556  *          the optional numbers of cells and nodes, if any. The valid values are
4557  *          - 0 - do not permute.
4558  *          - 1 - permute cells.
4559  *          - 2 - permute nodes.
4560  *          - 3 - permute cells and nodes.
4561  *
4562  *  \param [in] glob - the global data storing profiles and localization.
4563  *  \param [in] mesh - the supporting mesh.
4564  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4565  *         field according to \a renumPol.
4566  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4567  *         field according to \a renumPol.
4568  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4569  *          caller is to delete this field using decrRef() as it is no more needed. 
4570  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4571  *  \throw If no field of \a this is lying on \a mesh.
4572  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4573  */
4574 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
4575 {
4576   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4577   int meshId=getMeshIdFromMeshName(mesh->getName());
4578   bool isPfl=false;
4579   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4580   switch(renumPol)
4581     {
4582     case 0:
4583       {
4584         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4585         return ret.retn();
4586       }
4587     case 3:
4588     case 1:
4589       {
4590         if(isPfl)
4591           throw INTERP_KERNEL::Exception(msg1);
4592         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4593         if(cellRenum)
4594           {
4595             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4596               {
4597                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4598                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4599                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4600               }
4601             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4602             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4603             std::vector<DataArray *> arrOut2(1,arrOut);
4604             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4605             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4606             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4607           }
4608         if(renumPol==1)
4609           return ret.retn();
4610       }
4611     case 2:
4612       {
4613         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4614         if(isPfl)
4615           throw INTERP_KERNEL::Exception(msg1);
4616         if(nodeRenum)
4617           {
4618             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4619               {
4620                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4621                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4622                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4623               }
4624             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4625             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4626               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4627             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4628           }
4629         return ret.retn();
4630       }
4631     default:
4632       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4633     }
4634 }
4635
4636 /*!
4637  * Returns values and a profile of the field of a given type lying on a given support.
4638  *  \param [in] type - a spatial discretization of the field.
4639  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4640  *  \param [in] mesh - the supporting mesh.
4641  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4642  *          field of interest lies on. If the field lies on all entities of the given
4643  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4644  *          using decrRef() as it is no more needed.  
4645  *  \param [in] glob - the global data storing profiles and localization.
4646  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4647  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4648  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4649  *  \throw If no field of \a this is lying on \a mesh.
4650  *  \throw If no field values of the given \a type are available.
4651  */
4652 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4653 {
4654   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4655   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4656   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4657   ret->setName(nasc.getName().c_str());
4658   return ret.retn();
4659 }
4660
4661 //= MEDFileField1TSWithoutSDA
4662
4663 /*!
4664  * Throws if a given value is not a valid (non-extended) relative dimension.
4665  *  \param [in] meshDimRelToMax - the relative dimension value.
4666  *  \throw If \a meshDimRelToMax > 0.
4667  */
4668 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4669 {
4670   if(meshDimRelToMax>0)
4671     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4672 }
4673
4674 /*!
4675  * Checks if elements of a given mesh are in the order suitable for writing 
4676  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4677  * vector describing types of elements and their number.
4678  *  \param [in] mesh - the mesh to check.
4679  *  \return std::vector<int> - a vector holding for each element type (1) item of
4680  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4681  *          These values are in full-interlace mode.
4682  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4683  */
4684 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4685 {
4686   if(!mesh)
4687     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4688   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4689   int nbOfTypes=geoTypes.size();
4690   std::vector<int> code(3*nbOfTypes);
4691   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4692   arr1->alloc(nbOfTypes,1);
4693   int *arrPtr=arr1->getPointer();
4694   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4695   for(int i=0;i<nbOfTypes;i++,it++)
4696     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4697   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4698   const int *arrPtr2=arr2->getConstPointer();
4699   int i=0;
4700   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4701     {
4702       int pos=arrPtr2[i];
4703       int nbCells=mesh->getNumberOfCellsWithType(*it);
4704       code[3*pos]=(int)(*it);
4705       code[3*pos+1]=nbCells;
4706       code[3*pos+2]=-1;//no profiles
4707     }
4708   std::vector<const DataArrayInt *> idsPerType;//no profiles
4709   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4710   if(da)
4711     {
4712       da->decrRef();
4713       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4714     }
4715   return code;
4716 }
4717
4718 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4719 {
4720   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4721 }
4722
4723 /*!
4724  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4725  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4726  * item of every of returned sequences refers to the _i_-th part of \a this field.
4727  * Thus all sequences returned by this method are of the same length equal to number
4728  * of different types of supporting entities.<br>
4729  * A field part can include sub-parts with several different spatial discretizations,
4730  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4731  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4732  * of a nested sequence corresponds to a type of spatial discretization.<br>
4733  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4734  * The overhead is due to selecting values into new instances of DataArrayDouble.
4735  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4736  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4737  *          not checked if \a mname == \c NULL).
4738  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4739  *          a field part is returned. 
4740  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4741  *          A field part can include sub-parts with several different spatial discretizations,
4742  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4743  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4744  *          This sequence is of the same length as \a types. 
4745  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4746  *          discretization. A profile name can be empty.
4747  *          Length of this and of nested sequences is the same as that of \a typesF.
4748  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4749  *          discretization. A localization name can be empty.
4750  *          Length of this and of nested sequences is the same as that of \a typesF.
4751  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4752  *          per each type of spatial discretization within one mesh entity type.
4753  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4754  *          Length of this and of nested sequences is the same as that of \a typesF.
4755  *  \throw If no field is lying on \a mname.
4756  */
4757 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
4758 {
4759   int meshId=0;
4760   if(!mname.empty())
4761     meshId=getMeshIdFromMeshName(mname);
4762   else
4763     if(_field_per_mesh.empty())
4764       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4765   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4766   int nbOfRet=ret0.size();
4767   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4768   for(int i=0;i<nbOfRet;i++)
4769     {
4770       const std::vector< std::pair<int,int> >& p=ret0[i];
4771       int nbOfRet1=p.size();
4772       ret[i].resize(nbOfRet1);
4773       for(int j=0;j<nbOfRet1;j++)
4774         {
4775           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4776           ret[i][j]=tmp;
4777         }
4778     }
4779   return ret;
4780 }
4781
4782 /*!
4783  * Returns a pointer to the underground DataArrayDouble instance. So the
4784  * caller should not decrRef() it. This method allows for a direct access to the field
4785  * values. This method is quite unusable if there is more than a nodal field or a cell
4786  * field on single geometric cell type. 
4787  *  \return DataArrayDouble * - the pointer to the field values array.
4788  */
4789 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
4790 {
4791   const DataArrayDouble *ret=_arr;
4792   if(ret)
4793     return const_cast<DataArrayDouble *>(ret);
4794   else
4795     return 0;
4796 }
4797
4798 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
4799 {
4800   return TYPE_STR;
4801 }
4802
4803 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
4804 {
4805   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4806   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4807   ret->deepCpyLeavesFrom(*this);
4808   const DataArrayDouble *arr(_arr);
4809   if(arr)
4810     {
4811       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4812       ret->setArray(arr2);
4813     }
4814   return ret.retn();
4815 }
4816
4817 /*!
4818  * Returns a pointer to the underground DataArrayDouble instance. So the
4819  * caller should not decrRef() it. This method allows for a direct access to the field
4820  * values. This method is quite unusable if there is more than a nodal field or a cell
4821  * field on single geometric cell type. 
4822  *  \return DataArrayDouble * - the pointer to the field values array.
4823  */
4824 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
4825 {
4826   return getUndergroundDataArrayDouble();
4827 }
4828
4829 /*!
4830  * Returns a pointer to the underground DataArrayDouble instance and a
4831  * sequence describing parameters of a support of each part of \a this field. The
4832  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4833  * direct access to the field values. This method is intended for the field lying on one
4834  * mesh only.
4835  *  \param [in,out] entries - the sequence describing parameters of a support of each
4836  *         part of \a this field. Each item of this sequence consists of two parts. The
4837  *         first part describes a type of mesh entity and an id of discretization of a
4838  *         current field part. The second part describes a range of values [begin,end)
4839  *         within the returned array relating to the current field part.
4840  *  \return DataArrayDouble * - the pointer to the field values array.
4841  *  \throw If the number of underlying meshes is not equal to 1.
4842  *  \throw If no field values are available.
4843  *  \sa getUndergroundDataArray()
4844  */
4845 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4846 {
4847   if(_field_per_mesh.size()!=1)
4848     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4849   if(_field_per_mesh[0]==0)
4850     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4851   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4852   return getUndergroundDataArrayDouble();
4853 }
4854
4855 /*!
4856  * Returns a pointer to the underground DataArrayDouble instance and a
4857  * sequence describing parameters of a support of each part of \a this field. The
4858  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4859  * direct access to the field values. This method is intended for the field lying on one
4860  * mesh only.
4861  *  \param [in,out] entries - the sequence describing parameters of a support of each
4862  *         part of \a this field. Each item of this sequence consists of two parts. The
4863  *         first part describes a type of mesh entity and an id of discretization of a
4864  *         current field part. The second part describes a range of values [begin,end)
4865  *         within the returned array relating to the current field part.
4866  *  \return DataArrayDouble * - the pointer to the field values array.
4867  *  \throw If the number of underlying meshes is not equal to 1.
4868  *  \throw If no field values are available.
4869  *  \sa getUndergroundDataArray()
4870  */
4871 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4872 {
4873   return getUndergroundDataArrayDoubleExt(entries);
4874 }
4875
4876 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
4877                                                      const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4878 {
4879   DataArrayDouble *arr=getOrCreateAndGetArrayDouble();
4880   arr->setInfoAndChangeNbOfCompo(infos);
4881 }
4882
4883 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4884 {
4885 }
4886
4887 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
4888 {
4889   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4890   ret->deepCpyLeavesFrom(*this);
4891   return ret.retn();
4892 }
4893
4894 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
4895 {
4896   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4897   if((const DataArrayDouble *)_arr)
4898     ret->_arr=_arr->deepCpy();
4899   return ret.retn();
4900 }
4901
4902 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
4903 {
4904   if(!arr)
4905     {
4906       _nb_of_tuples_to_be_allocated=-1;
4907       _arr=0;
4908       return ;
4909     }
4910   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4911   if(!arrC)
4912     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4913   else
4914     _nb_of_tuples_to_be_allocated=-3;
4915   arrC->incrRef();
4916   _arr=arrC;
4917 }
4918
4919 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4920 {
4921   return DataArrayDouble::New();
4922 }
4923
4924 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4925 {
4926   DataArrayDouble *ret=_arr;
4927   if(ret)
4928     return ret;
4929   _arr=DataArrayDouble::New();
4930   return _arr;
4931 }
4932
4933 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4934 {
4935   return getOrCreateAndGetArrayDouble();
4936 }
4937
4938 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4939 {
4940   const DataArrayDouble *ret=_arr;
4941   if(ret)
4942     return ret;
4943   DataArrayDouble *ret2=DataArrayDouble::New();
4944   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4945   return ret2;
4946 }
4947
4948 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4949 {
4950   return getOrCreateAndGetArrayDouble();
4951 }
4952
4953 //= MEDFileIntField1TSWithoutSDA
4954
4955 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order,
4956                                                                 const std::vector<std::string>& infos)
4957 {
4958   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4959 }
4960
4961 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4962 {
4963 }
4964
4965 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
4966                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4967 {
4968   DataArrayInt *arr=getOrCreateAndGetArrayInt();
4969   arr->setInfoAndChangeNbOfCompo(infos);
4970 }
4971
4972 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
4973 {
4974   return TYPE_STR;
4975 }
4976
4977 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
4978 {
4979   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
4980   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4981   ret->deepCpyLeavesFrom(*this);
4982   const DataArrayInt *arr(_arr);
4983   if(arr)
4984     {
4985       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
4986       ret->setArray(arr2);
4987     }
4988   return ret.retn();
4989 }
4990
4991 /*!
4992  * Returns a pointer to the underground DataArrayInt instance. So the
4993  * caller should not decrRef() it. This method allows for a direct access to the field
4994  * values. This method is quite unusable if there is more than a nodal field or a cell
4995  * field on single geometric cell type. 
4996  *  \return DataArrayInt * - the pointer to the field values array.
4997  */
4998 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
4999 {
5000   return getUndergroundDataArrayInt();
5001 }
5002
5003 /*!
5004  * Returns a pointer to the underground DataArrayInt instance. So the
5005  * caller should not decrRef() it. This method allows for a direct access to the field
5006  * values. This method is quite unusable if there is more than a nodal field or a cell
5007  * field on single geometric cell type. 
5008  *  \return DataArrayInt * - the pointer to the field values array.
5009  */
5010 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5011 {
5012   const DataArrayInt *ret=_arr;
5013   if(ret)
5014     return const_cast<DataArrayInt *>(ret);
5015   else
5016     return 0;
5017 }
5018
5019 /*!
5020  * Returns a pointer to the underground DataArrayInt instance and a
5021  * sequence describing parameters of a support of each part of \a this field. The
5022  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5023  * direct access to the field values. This method is intended for the field lying on one
5024  * mesh only.
5025  *  \param [in,out] entries - the sequence describing parameters of a support of each
5026  *         part of \a this field. Each item of this sequence consists of two parts. The
5027  *         first part describes a type of mesh entity and an id of discretization of a
5028  *         current field part. The second part describes a range of values [begin,end)
5029  *         within the returned array relating to the current field part.
5030  *  \return DataArrayInt * - the pointer to the field values array.
5031  *  \throw If the number of underlying meshes is not equal to 1.
5032  *  \throw If no field values are available.
5033  *  \sa getUndergroundDataArray()
5034  */
5035 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5036 {
5037   return getUndergroundDataArrayIntExt(entries);
5038 }
5039
5040 /*!
5041  * Returns a pointer to the underground DataArrayInt instance and a
5042  * sequence describing parameters of a support of each part of \a this field. The
5043  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5044  * direct access to the field values. This method is intended for the field lying on one
5045  * mesh only.
5046  *  \param [in,out] entries - the sequence describing parameters of a support of each
5047  *         part of \a this field. Each item of this sequence consists of two parts. The
5048  *         first part describes a type of mesh entity and an id of discretization of a
5049  *         current field part. The second part describes a range of values [begin,end)
5050  *         within the returned array relating to the current field part.
5051  *  \return DataArrayInt * - the pointer to the field values array.
5052  *  \throw If the number of underlying meshes is not equal to 1.
5053  *  \throw If no field values are available.
5054  *  \sa getUndergroundDataArray()
5055  */
5056 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5057 {
5058   if(_field_per_mesh.size()!=1)
5059     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5060   if(_field_per_mesh[0]==0)
5061     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5062   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5063   return getUndergroundDataArrayInt();
5064 }
5065
5066 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5067 {
5068   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5069   ret->deepCpyLeavesFrom(*this);
5070   return ret.retn();
5071 }
5072
5073 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5074 {
5075   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5076   if((const DataArrayInt *)_arr)
5077     ret->_arr=_arr->deepCpy();
5078   return ret.retn();
5079 }
5080
5081 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5082 {
5083   if(!arr)
5084     {
5085       _nb_of_tuples_to_be_allocated=-1;
5086       _arr=0;
5087       return ;
5088     }
5089   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5090   if(!arrC)
5091     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5092   else
5093     _nb_of_tuples_to_be_allocated=-3;
5094   arrC->incrRef();
5095   _arr=arrC;
5096 }
5097
5098 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5099 {
5100   return DataArrayInt::New();
5101 }
5102
5103 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5104 {
5105   DataArrayInt *ret=_arr;
5106   if(ret)
5107     return ret;
5108   _arr=DataArrayInt::New();
5109   return _arr;
5110 }
5111
5112 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5113 {
5114   return getOrCreateAndGetArrayInt();
5115 }
5116
5117 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5118 {
5119   const DataArrayInt *ret=_arr;
5120   if(ret)
5121     return ret;
5122   DataArrayInt *ret2=DataArrayInt::New();
5123   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5124   return ret2;
5125 }
5126
5127 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5128 {
5129   return getOrCreateAndGetArrayInt();
5130 }
5131
5132 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5133 {
5134 }
5135
5136 //= MEDFileAnyTypeField1TS
5137
5138 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll)
5139 {
5140   med_field_type typcha;
5141   //
5142   std::vector<std::string> infos;
5143   std::string dtunit,fieldName;
5144   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5145   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5146   switch(typcha)
5147     {
5148     case MED_FLOAT64:
5149       {
5150         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5151         break;
5152       }
5153     case MED_INT32:
5154       {
5155         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5156         break;
5157       }
5158     default:
5159       {
5160         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] !";
5161         throw INTERP_KERNEL::Exception(oss.str().c_str());
5162       }
5163     }
5164   ret->setDtUnit(dtunit.c_str());
5165   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5166   //
5167   med_int numdt,numit;
5168   med_float dt;
5169   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5170   ret->setTime(numdt,numit,dt);
5171   ret->_csit=1;
5172   if(loadAll)
5173     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5174   else
5175     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5176   return ret.retn();
5177 }
5178
5179 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll)
5180 try:MEDFileFieldGlobsReal(fileName)
5181 {
5182   MEDFileUtilities::CheckFileForRead(fileName);
5183   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5184   _content=BuildContentFrom(fid,fileName,loadAll);
5185   loadGlobals(fid);
5186 }
5187 catch(INTERP_KERNEL::Exception& e)
5188   {
5189     throw e;
5190   }
5191
5192 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll)
5193 {
5194   med_field_type typcha;
5195   std::vector<std::string> infos;
5196   std::string dtunit;
5197   int iii=-1;
5198   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5199   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5200   switch(typcha)
5201     {
5202     case MED_FLOAT64:
5203       {
5204         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5205         break;
5206       }
5207     case MED_INT32:
5208       {
5209         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5210         break;
5211       }
5212     default:
5213       {
5214         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] !";
5215         throw INTERP_KERNEL::Exception(oss.str().c_str());
5216       }
5217     }
5218   ret->setDtUnit(dtunit.c_str());
5219   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5220   //
5221   if(nbSteps<1)
5222     {
5223       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5224       throw INTERP_KERNEL::Exception(oss.str().c_str());
5225     }
5226   //
5227   med_int numdt,numit;
5228   med_float dt;
5229   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5230   ret->setTime(numdt,numit,dt);
5231   ret->_csit=1;
5232   if(loadAll)
5233     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5234   else
5235     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5236   return ret.retn();
5237 }
5238
5239 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll)
5240 try:MEDFileFieldGlobsReal(fileName)
5241 {
5242   MEDFileUtilities::CheckFileForRead(fileName);
5243   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5244   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
5245   loadGlobals(fid);
5246 }
5247 catch(INTERP_KERNEL::Exception& e)
5248   {
5249     throw e;
5250   }
5251
5252 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5253 {
5254   if(!c)
5255     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5256   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5257     {
5258       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5259       ret->setFileName(fileName);
5260       ret->_content=c; c->incrRef();
5261       return ret.retn();
5262     }
5263   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5264     {
5265       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5266       ret->setFileName(fileName);
5267       ret->_content=c; c->incrRef();
5268       return ret.retn();
5269     }
5270   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5271 }
5272
5273 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5274 {
5275   MEDFileUtilities::CheckFileForRead(fileName);
5276   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5277   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
5278   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5279   ret->loadGlobals(fid);
5280   return ret.retn();
5281 }
5282
5283 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5284 {
5285   MEDFileUtilities::CheckFileForRead(fileName);
5286   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5287   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
5288   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5289   ret->loadGlobals(fid);
5290   return ret.retn();
5291 }
5292
5293 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5294 {
5295   MEDFileUtilities::CheckFileForRead(fileName);
5296   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5297   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll);
5298   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5299   ret->loadGlobals(fid);
5300   return ret.retn();
5301 }
5302
5303 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5304 {
5305   med_field_type typcha;
5306   std::vector<std::string> infos;
5307   std::string dtunit;
5308   int iii=-1;
5309   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5310   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5311   switch(typcha)
5312     {
5313     case MED_FLOAT64:
5314       {
5315         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5316         break;
5317       }
5318     case MED_INT32:
5319       {
5320         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5321         break;
5322       }
5323     default:
5324       {
5325         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] !";
5326         throw INTERP_KERNEL::Exception(oss.str().c_str());
5327       }
5328     }
5329   ret->setDtUnit(dtunit.c_str());
5330   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5331   //
5332   bool found=false;
5333   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5334   for(int i=0;i<nbOfStep2 && !found;i++)
5335     {
5336       med_int numdt,numit;
5337       med_float dt;
5338       MEDfieldComputingStepInfo(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt);
5339       if(numdt==iteration && numit==order)
5340         {
5341           found=true;
5342           ret->_csit=i+1;
5343         }
5344       else
5345         dtits[i]=std::pair<int,int>(numdt,numit);
5346     }
5347   if(!found)
5348     {
5349       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5350       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5351         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5352       throw INTERP_KERNEL::Exception(oss.str().c_str());
5353     }
5354   if(loadAll)
5355     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5356   else
5357     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5358   return ret.retn();
5359 }
5360
5361 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5362 try:MEDFileFieldGlobsReal(fileName)
5363 {
5364   MEDFileUtilities::CheckFileForRead(fileName);
5365   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5366   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll);
5367   loadGlobals(fid);
5368 }
5369 catch(INTERP_KERNEL::Exception& e)
5370   {
5371     throw e;
5372   }
5373
5374 /*!
5375  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5376  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5377  *
5378  * \warning this is a shallow copy constructor
5379  */
5380 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5381 {
5382   if(!shallowCopyOfContent)
5383     {
5384       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5385       otherPtr->incrRef();
5386       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5387     }
5388   else
5389     {
5390       _content=other.shallowCpy();
5391     }
5392 }
5393
5394 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)
5395 {
5396   if(checkFieldId)
5397     {
5398       int nbFields=MEDnField(fid);
5399       if(fieldIdCFormat>=nbFields)
5400         {
5401           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5402           throw INTERP_KERNEL::Exception(oss.str().c_str());
5403         }
5404     }
5405   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5406   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5407   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5408   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5409   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5410   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5411   med_bool localMesh;
5412   int nbOfStep;
5413   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5414   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5415   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5416   infos.clear(); infos.resize(ncomp);
5417   for(int j=0;j<ncomp;j++)
5418     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5419   return nbOfStep;
5420 }
5421
5422 /*!
5423  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5424  * 
5425  * \param [out]
5426  * \return in case of success the number of time steps available for the field with name \a fieldName.
5427  */
5428 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)
5429 {
5430   int nbFields=MEDnField(fid);
5431   bool found=false;
5432   std::vector<std::string> fns(nbFields);
5433   int nbOfStep2=-1;
5434   for(int i=0;i<nbFields && !found;i++)
5435     {
5436       std::string tmp;
5437       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5438       fns[i]=tmp;
5439       found=(tmp==fieldName);
5440       if(found)
5441         posCFormat=i;
5442     }
5443   if(!found)
5444     {
5445       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5446       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5447         oss << "\"" << *it << "\" ";
5448       throw INTERP_KERNEL::Exception(oss.str().c_str());
5449     }
5450   return nbOfStep2;
5451 }
5452
5453 /*!
5454  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5455  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5456  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5457  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5458  * to keep a valid instance.
5459  * 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.
5460  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5461  * 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.
5462  *
5463  * \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.
5464  * \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.
5465  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5466  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5467  * \param [in] newLocName is the new localization name.
5468  * \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.
5469  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5470  */
5471 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5472 {
5473   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5474   std::string oldPflName=disc->getProfile();
5475   std::vector<std::string> vv=getPflsReallyUsedMulti();
5476   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5477   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5478     {
5479       disc->setProfile(newPflName);
5480       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5481       pfl->setName(newPflName);
5482     }
5483   else
5484     {
5485       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5486       throw INTERP_KERNEL::Exception(oss.str().c_str());
5487     }
5488 }
5489
5490 /*!
5491  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5492  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5493  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5494  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5495  * to keep a valid instance.
5496  * 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.
5497  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5498  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5499  * 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.
5500  *
5501  * \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.
5502  * \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.
5503  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5504  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5505  * \param [in] newLocName is the new localization name.
5506  * \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.
5507  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5508  */
5509 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5510 {
5511   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5512   std::string oldLocName=disc->getLocalization();
5513   std::vector<std::string> vv=getLocsReallyUsedMulti();
5514   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5515   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5516     {
5517       disc->setLocalization(newLocName);
5518       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5519       loc.setName(newLocName);
5520     }
5521   else
5522     {
5523       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5524       throw INTERP_KERNEL::Exception(oss.str().c_str());
5525     }
5526 }
5527
5528 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5529 {
5530   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5531   if(!ret)
5532     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5533   return ret;
5534 }
5535
5536 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5537 {
5538   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5539   if(!ret)
5540     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5541   return ret;
5542 }
5543
5544 /*!
5545  * Writes \a this field into a MED file specified by its name.
5546  *  \param [in] fileName - the MED file name.
5547  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5548  * - 2 - erase; an existing file is removed.
5549  * - 1 - append; same data should not be present in an existing file.
5550  * - 0 - overwrite; same data present in an existing file is overwritten.
5551  *  \throw If the field name is not set.
5552  *  \throw If no field data is set.
5553  *  \throw If \a mode == 1 and the same data is present in an existing file.
5554  */
5555 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5556 {
5557   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5558   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5559   writeLL(fid);
5560 }
5561
5562 /*!
5563  * This method alloc the arrays and load potentially huge arrays contained in this field.
5564  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5565  * This method can be also called to refresh or reinit values from a file.
5566  * 
5567  * \throw If the fileName is not set or points to a non readable MED file.
5568  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5569  */
5570 void MEDFileAnyTypeField1TS::loadArrays()
5571 {
5572   if(getFileName().empty())
5573     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5574   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5575   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5576 }
5577
5578 /*!
5579  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5580  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5581  * this method does not throw if \a this does not come from file read.
5582  * 
5583  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5584  */
5585 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5586 {
5587   if(!getFileName().empty())
5588     {
5589       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5590       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5591     }
5592 }
5593
5594 /*!
5595  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5596  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5597  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5598  * 
5599  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5600  */
5601 void MEDFileAnyTypeField1TS::unloadArrays()
5602 {
5603   contentNotNullBase()->unloadArrays();
5604 }
5605
5606 /*!
5607  * 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.
5608  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5609  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5610  * 
5611  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5612  */
5613 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5614 {
5615   if(!getFileName().empty())
5616     contentNotNullBase()->unloadArrays();
5617 }
5618
5619 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5620 {
5621   int nbComp=getNumberOfComponents();
5622   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5623   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5624   for(int i=0;i<nbComp;i++)
5625     {
5626       std::string info=getInfo()[i];
5627       std::string c,u;
5628       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5629       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5630       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5631     }
5632   if(getName().empty())
5633     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5634   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5635   writeGlobals(fid,*this);
5636   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5637 }
5638
5639 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5640 {
5641   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5642 }
5643
5644 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildren() const
5645 {
5646   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildren());
5647   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5648     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5649   return ret;
5650 }
5651
5652 /*!
5653  * Returns a string describing \a this field. This string is outputted 
5654  * by \c print Python command.
5655  */
5656 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5657 {
5658   std::ostringstream oss;
5659   contentNotNullBase()->simpleRepr(0,oss,-1);
5660   simpleReprGlobs(oss);
5661   return oss.str();
5662 }
5663
5664 /*!
5665  * This method returns all profiles whose name is non empty used.
5666  * \b WARNING If profile is used several times it will be reported \b only \b once.
5667  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5668  */
5669 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5670 {
5671   return contentNotNullBase()->getPflsReallyUsed2();
5672 }
5673
5674 /*!
5675  * This method returns all localizations whose name is non empty used.
5676  * \b WARNING If localization is used several times it will be reported \b only \b once.
5677  */
5678 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5679 {
5680   return contentNotNullBase()->getLocsReallyUsed2();
5681 }
5682
5683 /*!
5684  * This method returns all profiles whose name is non empty used.
5685  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5686  */
5687 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5688 {
5689   return contentNotNullBase()->getPflsReallyUsedMulti2();
5690 }
5691
5692 /*!
5693  * This method returns all localizations whose name is non empty used.
5694  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5695  */
5696 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5697 {
5698   return contentNotNullBase()->getLocsReallyUsedMulti2();
5699 }
5700
5701 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5702 {
5703   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5704 }
5705
5706 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5707 {
5708   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5709 }
5710
5711 int MEDFileAnyTypeField1TS::getDimension() const
5712 {
5713   return contentNotNullBase()->getDimension();
5714 }
5715
5716 int MEDFileAnyTypeField1TS::getIteration() const
5717 {
5718   return contentNotNullBase()->getIteration();
5719 }
5720
5721 int MEDFileAnyTypeField1TS::getOrder() const
5722 {
5723   return contentNotNullBase()->getOrder();
5724 }
5725
5726 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5727 {
5728   return contentNotNullBase()->getTime(iteration,order);
5729 }
5730
5731 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5732 {
5733   contentNotNullBase()->setTime(iteration,order,val);
5734 }
5735
5736 std::string MEDFileAnyTypeField1TS::getName() const
5737 {
5738   return contentNotNullBase()->getName();
5739 }
5740
5741 void MEDFileAnyTypeField1TS::setName(const std::string& name)
5742 {
5743   contentNotNullBase()->setName(name);
5744 }
5745
5746 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5747 {
5748   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5749 }
5750
5751 std::string MEDFileAnyTypeField1TS::getDtUnit() const
5752 {
5753   return contentNotNullBase()->getDtUnit();
5754 }
5755
5756 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
5757 {
5758   contentNotNullBase()->setDtUnit(dtUnit);
5759 }
5760
5761 std::string MEDFileAnyTypeField1TS::getMeshName() const
5762 {
5763   return contentNotNullBase()->getMeshName();
5764 }
5765
5766 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
5767 {
5768   contentNotNullBase()->setMeshName(newMeshName);
5769 }
5770
5771 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
5772 {
5773   return contentNotNullBase()->changeMeshNames(modifTab);
5774 }
5775
5776 int MEDFileAnyTypeField1TS::getMeshIteration() const
5777 {
5778   return contentNotNullBase()->getMeshIteration();
5779 }
5780
5781 int MEDFileAnyTypeField1TS::getMeshOrder() const
5782 {
5783   return contentNotNullBase()->getMeshOrder();
5784 }
5785
5786 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5787 {
5788   return contentNotNullBase()->getNumberOfComponents();
5789 }
5790
5791 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5792 {
5793   return contentNotNullBase()->isDealingTS(iteration,order);
5794 }
5795
5796 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5797 {
5798   return contentNotNullBase()->getDtIt();
5799 }
5800
5801 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5802 {
5803   contentNotNullBase()->fillIteration(p);
5804 }
5805
5806 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
5807 {
5808   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5809 }
5810
5811 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
5812 {
5813   contentNotNullBase()->setInfo(infos);
5814 }
5815
5816 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5817 {
5818   return contentNotNullBase()->getInfo();
5819 }
5820 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5821 {
5822   return contentNotNullBase()->getInfo();
5823 }
5824
5825 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
5826 {
5827   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5828 }
5829
5830 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
5831 {
5832   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5833 }
5834
5835 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
5836 {
5837   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5838 }
5839
5840 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
5841 {
5842   return contentNotNullBase()->getTypesOfFieldAvailable();
5843 }
5844
5845 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,
5846                                                                                        std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
5847 {
5848   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5849 }
5850
5851 /*!
5852  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5853  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5854  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5855  */
5856 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
5857 {
5858   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5859   if(!content)
5860     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5861   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5862   std::size_t sz(contentsSplit.size());
5863   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5864   for(std::size_t i=0;i<sz;i++)
5865     {
5866       ret[i]=shallowCpy();
5867       ret[i]->_content=contentsSplit[i];
5868     }
5869   return ret;
5870 }
5871
5872 /*!
5873  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
5874  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5875  */
5876 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
5877 {
5878   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5879   if(!content)
5880     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
5881   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitDiscretizations();
5882   std::size_t sz(contentsSplit.size());
5883   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5884   for(std::size_t i=0;i<sz;i++)
5885     {
5886       ret[i]=shallowCpy();
5887       ret[i]->_content=contentsSplit[i];
5888     }
5889   return ret;
5890 }
5891
5892 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
5893 {
5894   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5895   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5896     ret->_content=_content->deepCpy();
5897   ret->deepCpyGlobs(*this);
5898   return ret.retn();
5899 }
5900
5901 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5902 {
5903   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5904 }
5905
5906 //= MEDFileField1TS
5907
5908 /*!
5909  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5910  * the first field that has been read from a specified MED file.
5911  *  \param [in] fileName - the name of the MED file to read.
5912  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5913  *          is to delete this field using decrRef() as it is no more needed.
5914  *  \throw If reading the file fails.
5915  */
5916 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
5917 {
5918   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,loadAll);
5919   ret->contentNotNull();
5920   return ret.retn();
5921 }
5922
5923 /*!
5924  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5925  * a given field that has been read from a specified MED file.
5926  *  \param [in] fileName - the name of the MED file to read.
5927  *  \param [in] fieldName - the name of the field to read.
5928  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5929  *          is to delete this field using decrRef() as it is no more needed.
5930  *  \throw If reading the file fails.
5931  *  \throw If there is no field named \a fieldName in the file.
5932  */
5933 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5934 {
5935   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,loadAll);
5936   ret->contentNotNull();
5937   return ret.retn();
5938 }
5939
5940 /*!
5941  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5942  * a given field that has been read from a specified MED file.
5943  *  \param [in] fileName - the name of the MED file to read.
5944  *  \param [in] fieldName - the name of the field to read.
5945  *  \param [in] iteration - the iteration number of a required time step.
5946  *  \param [in] order - the iteration order number of required time step.
5947  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5948  *          is to delete this field using decrRef() as it is no more needed.
5949  *  \throw If reading the file fails.
5950  *  \throw If there is no field named \a fieldName in the file.
5951  *  \throw If the required time step is missing from the file.
5952  */
5953 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5954 {
5955   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll);
5956   ret->contentNotNull();
5957   return ret.retn();
5958 }
5959
5960 /*!
5961  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5962  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5963  *
5964  * Returns a new instance of MEDFileField1TS holding either a shallow copy
5965  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
5966  * \warning this is a shallow copy constructor
5967  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
5968  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
5969  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5970  *          is to delete this field using decrRef() as it is no more needed.
5971  */
5972 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5973 {
5974   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
5975   ret->contentNotNull();
5976   return ret.retn();
5977 }
5978
5979 /*!
5980  * Returns a new empty instance of MEDFileField1TS.
5981  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5982  *          is to delete this field using decrRef() as it is no more needed.
5983  */
5984 MEDFileField1TS *MEDFileField1TS::New()
5985 {
5986   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
5987   ret->contentNotNull();
5988   return ret.retn();
5989 }
5990
5991 /*!
5992  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
5993  * following the given input policy.
5994  *
5995  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
5996  *                            By default (true) the globals are deeply copied.
5997  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
5998  */
5999 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6000 {
6001   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
6002   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6003   if(content)
6004     {
6005       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6006       if(!contc)
6007         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6008       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6009       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6010     }
6011   else
6012     ret=MEDFileIntField1TS::New();
6013   if(isDeepCpyGlobs)
6014     ret->deepCpyGlobs(*this);
6015   else
6016     ret->shallowCpyGlobs(*this);
6017   return ret.retn();
6018 }
6019
6020 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6021 {
6022   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6023   if(!pt)
6024     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6025   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6026   if(!ret)
6027     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 !");
6028   return ret;
6029 }
6030
6031 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6032 {
6033   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6034   if(!pt)
6035     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6036   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6037   if(!ret)
6038     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 !");
6039   return ret;
6040 }
6041
6042 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6043 {
6044   if(!f)
6045     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6046   if(!((DataArray*)arr))
6047     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6048   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6049   if(!arrOutC)
6050     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6051   f->setArray(arrOutC);
6052 }
6053
6054 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6055 {
6056   if(!((DataArray*)arr))
6057     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6058   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6059   if(!arrOutC)
6060     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6061   arrOutC->incrRef();
6062   return arrOutC;
6063 }
6064
6065 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll)
6066 try:MEDFileAnyTypeField1TS(fileName,loadAll)
6067 {
6068 }
6069 catch(INTERP_KERNEL::Exception& e)
6070   { throw e; }
6071
6072 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll)
6073 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
6074 {
6075 }
6076 catch(INTERP_KERNEL::Exception& e)
6077   { throw e; }
6078
6079 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6080 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
6081 {
6082 }
6083 catch(INTERP_KERNEL::Exception& e)
6084   { throw e; }
6085
6086 /*!
6087  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6088  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6089  *
6090  * \warning this is a shallow copy constructor
6091  */
6092 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6093 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6094 {
6095 }
6096 catch(INTERP_KERNEL::Exception& e)
6097   { throw e; }
6098
6099 MEDFileField1TS::MEDFileField1TS()
6100 {
6101   _content=new MEDFileField1TSWithoutSDA;
6102 }
6103
6104 /*!
6105  * Returns a new MEDCouplingFieldDouble of a given type lying on
6106  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6107  * has not been constructed via file reading, an exception is thrown.
6108  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6109  *  \param [in] type - a spatial discretization of interest.
6110  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6111  *  \param [in] renumPol - specifies how to permute values of the result field according to
6112  *          the optional numbers of cells and nodes, if any. The valid values are
6113  *          - 0 - do not permute.
6114  *          - 1 - permute cells.
6115  *          - 2 - permute nodes.
6116  *          - 3 - permute cells and nodes.
6117  *
6118  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6119  *          caller is to delete this field using decrRef() as it is no more needed. 
6120  *  \throw If \a this field has not been constructed via file reading.
6121  *  \throw If the MED file is not readable.
6122  *  \throw If there is no mesh in the MED file.
6123  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6124  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6125  *  \sa getFieldOnMeshAtLevel()
6126  */
6127 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6128 {
6129   if(getFileName().empty())
6130     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6131   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6132   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6133   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6134   return ret.retn();
6135 }
6136
6137 /*!
6138  * Returns a new MEDCouplingFieldDouble of a given type lying on
6139  * the top level cells of the first mesh in MED file. If \a this field 
6140  * has not been constructed via file reading, an exception is thrown.
6141  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6142  *  \param [in] type - a spatial discretization of interest.
6143  *  \param [in] renumPol - specifies how to permute values of the result field according to
6144  *          the optional numbers of cells and nodes, if any. The valid values are
6145  *          - 0 - do not permute.
6146  *          - 1 - permute cells.
6147  *          - 2 - permute nodes.
6148  *          - 3 - permute cells and nodes.
6149  *
6150  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6151  *          caller is to delete this field using decrRef() as it is no more needed. 
6152  *  \throw If \a this field has not been constructed via file reading.
6153  *  \throw If the MED file is not readable.
6154  *  \throw If there is no mesh in the MED file.
6155  *  \throw If no field values of the given \a type.
6156  *  \throw If no field values lying on the top level support.
6157  *  \sa getFieldAtLevel()
6158  */
6159 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6160 {
6161   if(getFileName().empty())
6162     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6163   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6164   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6165   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6166   return ret.retn();
6167 }
6168
6169 /*!
6170  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6171  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6172  *  \param [in] type - a spatial discretization of the new field.
6173  *  \param [in] mesh - the supporting mesh.
6174  *  \param [in] renumPol - specifies how to permute values of the result field according to
6175  *          the optional numbers of cells and nodes, if any. The valid values are
6176  *          - 0 - do not permute.
6177  *          - 1 - permute cells.
6178  *          - 2 - permute nodes.
6179  *          - 3 - permute cells and nodes.
6180  *
6181  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6182  *          caller is to delete this field using decrRef() as it is no more needed. 
6183  *  \throw If no field of \a this is lying on \a mesh.
6184  *  \throw If the mesh is empty.
6185  *  \throw If no field values of the given \a type are available.
6186  *  \sa getFieldAtLevel()
6187  *  \sa getFieldOnMeshAtLevel() 
6188  */
6189 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6190 {
6191   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6192   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6193   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6194   return ret.retn();
6195 }
6196
6197 /*!
6198  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6199  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6200  *  \param [in] type - a spatial discretization of interest.
6201  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6202  *  \param [in] mesh - the supporting mesh.
6203  *  \param [in] renumPol - specifies how to permute values of the result field according to
6204  *          the optional numbers of cells and nodes, if any. The valid values are
6205  *          - 0 - do not permute.
6206  *          - 1 - permute cells.
6207  *          - 2 - permute nodes.
6208  *          - 3 - permute cells and nodes.
6209  *
6210  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6211  *          caller is to delete this field using decrRef() as it is no more needed. 
6212  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6213  *  \throw If no field of \a this is lying on \a mesh.
6214  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6215  *  \sa getFieldAtLevel()
6216  *  \sa getFieldOnMeshAtLevel() 
6217  */
6218 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6219 {
6220   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6221   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6222   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6223   return ret.retn();
6224 }
6225
6226 /*!
6227  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6228  * This method is called "Old" because in MED3 norm a field has only one meshName
6229  * attached, so this method is for readers of MED2 files. If \a this field 
6230  * has not been constructed via file reading, an exception is thrown.
6231  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6232  *  \param [in] type - a spatial discretization of interest.
6233  *  \param [in] mName - a name of the supporting mesh.
6234  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6235  *  \param [in] renumPol - specifies how to permute values of the result field according to
6236  *          the optional numbers of cells and nodes, if any. The valid values are
6237  *          - 0 - do not permute.
6238  *          - 1 - permute cells.
6239  *          - 2 - permute nodes.
6240  *          - 3 - permute cells and nodes.
6241  *
6242  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6243  *          caller is to delete this field using decrRef() as it is no more needed. 
6244  *  \throw If the MED file is not readable.
6245  *  \throw If there is no mesh named \a mName in the MED file.
6246  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6247  *  \throw If \a this field has not been constructed via file reading.
6248  *  \throw If no field of \a this is lying on the mesh named \a mName.
6249  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6250  *  \sa getFieldAtLevel()
6251  */
6252 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6253 {
6254   if(getFileName().empty())
6255     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6256   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6257   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6258   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6259   return ret.retn();
6260 }
6261
6262 /*!
6263  * Returns values and a profile of the field of a given type lying on a given support.
6264  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6265  *  \param [in] type - a spatial discretization of the field.
6266  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6267  *  \param [in] mesh - the supporting mesh.
6268  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6269  *          field of interest lies on. If the field lies on all entities of the given
6270  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6271  *          using decrRef() as it is no more needed.  
6272  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6273  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6274  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6275  *  \throw If no field of \a this is lying on \a mesh.
6276  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6277  */
6278 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6279 {
6280   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6281   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6282 }
6283
6284 /*!
6285  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6286  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6287  * "Sort By Type"), if not, an exception is thrown. 
6288  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6289  *  \param [in] field - the field to add to \a this.
6290  *  \throw If the name of \a field is empty.
6291  *  \throw If the data array of \a field is not set.
6292  *  \throw If the data array is already allocated but has different number of components
6293  *         than \a field.
6294  *  \throw If the underlying mesh of \a field has no name.
6295  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6296  */
6297 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6298 {
6299   setFileName("");
6300   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6301 }
6302
6303 /*!
6304  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6305  * can be an aggregation of several MEDCouplingFieldDouble instances.
6306  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6307  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6308  * and \a profile.
6309  *
6310  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6311  * A new profile is added only if no equal profile is missing.
6312  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6313  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6314  *  \param [in] mesh - the supporting mesh of \a field.
6315  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6316  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6317  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6318  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6319  *  \throw If the data array of \a field is not set.
6320  *  \throw If the data array of \a this is already allocated but has different number of
6321  *         components than \a field.
6322  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6323  *  \sa setFieldNoProfileSBT()
6324  */
6325 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6326 {
6327   setFileName("");
6328   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6329 }
6330
6331 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6332 {
6333   return new MEDFileField1TS(*this);
6334 }
6335
6336 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6337 {
6338   return contentNotNull()->getUndergroundDataArrayDouble();
6339 }
6340
6341 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6342 {
6343   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6344 }
6345
6346 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6347                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const throw(INTERP_KERNEL::Exception)
6348 {
6349   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6350 }
6351
6352 //= MEDFileIntField1TS
6353
6354 MEDFileIntField1TS *MEDFileIntField1TS::New()
6355 {
6356   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6357   ret->contentNotNull();
6358   return ret.retn();
6359 }
6360
6361 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6362 {
6363   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,loadAll);
6364   ret->contentNotNull();
6365   return ret.retn();
6366 }
6367
6368 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6369 {
6370   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,loadAll);
6371   ret->contentNotNull();
6372   return ret.retn();
6373 }
6374
6375 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6376 {
6377   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll);
6378   ret->contentNotNull();
6379   return ret.retn();
6380 }
6381
6382 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6383 {
6384   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6385   ret->contentNotNull();
6386   return ret.retn();
6387 }
6388
6389 MEDFileIntField1TS::MEDFileIntField1TS()
6390 {
6391   _content=new MEDFileIntField1TSWithoutSDA;
6392 }
6393
6394 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll)
6395 try:MEDFileAnyTypeField1TS(fileName,loadAll)
6396 {
6397 }
6398 catch(INTERP_KERNEL::Exception& e)
6399   { throw e; }
6400
6401 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll)
6402 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
6403 {
6404 }
6405 catch(INTERP_KERNEL::Exception& e)
6406   { throw e; }
6407
6408 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6409 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
6410 {
6411 }
6412 catch(INTERP_KERNEL::Exception& e)
6413   { throw e; }
6414
6415 /*!
6416  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6417  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6418  *
6419  * \warning this is a shallow copy constructor
6420  */
6421 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6422 {
6423 }
6424
6425 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6426 {
6427   return new MEDFileIntField1TS(*this);
6428 }
6429
6430 /*!
6431  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6432  * following the given input policy.
6433  *
6434  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6435  *                            By default (true) the globals are deeply copied.
6436  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6437  */
6438 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6439 {
6440   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6441   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6442   if(content)
6443     {
6444       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6445       if(!contc)
6446         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6447       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6448       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6449     }
6450   else
6451     ret=MEDFileField1TS::New();
6452   if(isDeepCpyGlobs)
6453     ret->deepCpyGlobs(*this);
6454   else
6455     ret->shallowCpyGlobs(*this);
6456   return ret.retn();
6457 }
6458
6459 /*!
6460  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6461  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6462  * "Sort By Type"), if not, an exception is thrown. 
6463  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6464  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6465  *  \param [in] arrOfVals - the values of the field \a field used.
6466  *  \throw If the name of \a field is empty.
6467  *  \throw If the data array of \a field is not set.
6468  *  \throw If the data array is already allocated but has different number of components
6469  *         than \a field.
6470  *  \throw If the underlying mesh of \a field has no name.
6471  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6472  */
6473 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6474 {
6475   setFileName("");
6476   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6477 }
6478
6479 /*!
6480  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6481  * can be an aggregation of several MEDCouplingFieldDouble instances.
6482  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6483  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6484  * and \a profile.
6485  *
6486  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6487  * A new profile is added only if no equal profile is missing.
6488  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6489  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6490  *  \param [in] arrOfVals - the values of the field \a field used.
6491  *  \param [in] mesh - the supporting mesh of \a field.
6492  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6493  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6494  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6495  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6496  *  \throw If the data array of \a field is not set.
6497  *  \throw If the data array of \a this is already allocated but has different number of
6498  *         components than \a field.
6499  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6500  *  \sa setFieldNoProfileSBT()
6501  */
6502 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6503 {
6504   setFileName("");
6505   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6506 }
6507
6508 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6509 {
6510   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6511   if(!pt)
6512     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6513   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6514   if(!ret)
6515     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 !");
6516   return ret;
6517 }
6518
6519 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6520 {
6521   if(getFileName().empty())
6522     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6523   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6524   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6525   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6526   if(!arrOutC)
6527     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6528   arrOut=arrOutC;
6529   return ret.retn();
6530 }
6531
6532 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6533 {
6534   if(!((DataArray *)arr))
6535     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6536   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6537   if(!arrC)
6538     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6539   arrC->incrRef();
6540   return arrC;
6541 }
6542
6543 /*!
6544  * Returns a new MEDCouplingFieldDouble of a given type lying on
6545  * the top level cells of the first mesh in MED file. If \a this field 
6546  * has not been constructed via file reading, an exception is thrown.
6547  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6548  *  \param [in] type - a spatial discretization of interest.
6549  *  \param [out] arrOut - the DataArrayInt containing values of field.
6550  *  \param [in] renumPol - specifies how to permute values of the result field according to
6551  *          the optional numbers of cells and nodes, if any. The valid values are
6552  *          - 0 - do not permute.
6553  *          - 1 - permute cells.
6554  *          - 2 - permute nodes.
6555  *          - 3 - permute cells and nodes.
6556  *
6557  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6558  *          caller is to delete this field using decrRef() as it is no more needed. 
6559  *  \throw If \a this field has not been constructed via file reading.
6560  *  \throw If the MED file is not readable.
6561  *  \throw If there is no mesh in the MED file.
6562  *  \throw If no field values of the given \a type.
6563  *  \throw If no field values lying on the top level support.
6564  *  \sa getFieldAtLevel()
6565  */
6566 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6567 {
6568   if(getFileName().empty())
6569     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6570   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6571   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6572   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6573   return ret.retn();
6574 }
6575
6576 /*!
6577  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6578  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6579  *  \param [in] type - a spatial discretization of the new field.
6580  *  \param [in] mesh - the supporting mesh.
6581  *  \param [out] arrOut - the DataArrayInt containing values of field.
6582  *  \param [in] renumPol - specifies how to permute values of the result field according to
6583  *          the optional numbers of cells and nodes, if any. The valid values are
6584  *          - 0 - do not permute.
6585  *          - 1 - permute cells.
6586  *          - 2 - permute nodes.
6587  *          - 3 - permute cells and nodes.
6588  *
6589  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6590  *          caller is to delete this field using decrRef() as it is no more needed. 
6591  *  \throw If no field of \a this is lying on \a mesh.
6592  *  \throw If the mesh is empty.
6593  *  \throw If no field values of the given \a type are available.
6594  *  \sa getFieldAtLevel()
6595  *  \sa getFieldOnMeshAtLevel() 
6596  */
6597 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6598 {
6599   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6600   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6601   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6602   return ret.retn();
6603 }
6604
6605 /*!
6606  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6607  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6608  *  \param [in] type - a spatial discretization of interest.
6609  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6610  *  \param [out] arrOut - the DataArrayInt containing values of field.
6611  *  \param [in] mesh - the supporting mesh.
6612  *  \param [in] renumPol - specifies how to permute values of the result field according to
6613  *          the optional numbers of cells and nodes, if any. The valid values are
6614  *          - 0 - do not permute.
6615  *          - 1 - permute cells.
6616  *          - 2 - permute nodes.
6617  *          - 3 - permute cells and nodes.
6618  *
6619  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6620  *          caller is to delete this field using decrRef() as it is no more needed. 
6621  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6622  *  \throw If no field of \a this is lying on \a mesh.
6623  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6624  *  \sa getFieldAtLevel()
6625  *  \sa getFieldOnMeshAtLevel() 
6626  */
6627 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6628 {
6629   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6630   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6631   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6632   return ret.retn();
6633 }
6634
6635 /*!
6636  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6637  * This method is called "Old" because in MED3 norm a field has only one meshName
6638  * attached, so this method is for readers of MED2 files. If \a this field 
6639  * has not been constructed via file reading, an exception is thrown.
6640  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6641  *  \param [in] type - a spatial discretization of interest.
6642  *  \param [in] mName - a name of the supporting mesh.
6643  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6644  *  \param [out] arrOut - the DataArrayInt containing values of field.
6645  *  \param [in] renumPol - specifies how to permute values of the result field according to
6646  *          the optional numbers of cells and nodes, if any. The valid values are
6647  *          - 0 - do not permute.
6648  *          - 1 - permute cells.
6649  *          - 2 - permute nodes.
6650  *          - 3 - permute cells and nodes.
6651  *
6652  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6653  *          caller is to delete this field using decrRef() as it is no more needed. 
6654  *  \throw If the MED file is not readable.
6655  *  \throw If there is no mesh named \a mName in the MED file.
6656  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6657  *  \throw If \a this field has not been constructed via file reading.
6658  *  \throw If no field of \a this is lying on the mesh named \a mName.
6659  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6660  *  \sa getFieldAtLevel()
6661  */
6662 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6663 {
6664   if(getFileName().empty())
6665     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6666   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6667   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6668   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6669   return ret.retn();
6670 }
6671
6672 /*!
6673  * Returns values and a profile of the field of a given type lying on a given support.
6674  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6675  *  \param [in] type - a spatial discretization of the field.
6676  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6677  *  \param [in] mesh - the supporting mesh.
6678  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6679  *          field of interest lies on. If the field lies on all entities of the given
6680  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6681  *          using decrRef() as it is no more needed.  
6682  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6683  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6684  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6685  *  \throw If no field of \a this is lying on \a mesh.
6686  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6687  */
6688 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6689 {
6690   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6691   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6692 }
6693
6694 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
6695 {
6696   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6697   if(!pt)
6698     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6699   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6700   if(!ret)
6701     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 !");
6702   return ret;
6703 }
6704
6705 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
6706 {
6707   return contentNotNull()->getUndergroundDataArrayInt();
6708 }
6709
6710 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6711
6712 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6713 {
6714 }
6715
6716 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
6717 {
6718 }
6719
6720 /*!
6721  * \param [in] fieldId field id in C mode
6722  */
6723 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll)
6724 {
6725   med_field_type typcha;
6726   std::string dtunitOut;
6727   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6728   setDtUnit(dtunitOut.c_str());
6729   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll);
6730 }
6731
6732 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)
6733 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6734 {
6735   setDtUnit(dtunit.c_str());
6736   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll);
6737 }
6738 catch(INTERP_KERNEL::Exception& e)
6739 {
6740   throw e;
6741 }
6742
6743 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
6744 {
6745   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
6746   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6747     ret+=(*it).capacity();
6748   return ret;
6749 }
6750
6751 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildren() const
6752 {
6753   std::vector<const BigMemoryObject *> ret;
6754   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6755     {
6756       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6757       if(cur)
6758         ret.push_back(cur);
6759     }
6760   return ret;
6761 }
6762
6763 /*!
6764  * 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
6765  * NULL.
6766  */
6767 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
6768 {
6769   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6770   ret->setInfo(_infos);
6771   int sz=(int)_time_steps.size();
6772   for(const int *id=startIds;id!=endIds;id++)
6773     {
6774       if(*id>=0 && *id<sz)
6775         {
6776           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6777           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6778           if(tse)
6779             {
6780               tse->incrRef();
6781               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6782             }
6783           ret->pushBackTimeStep(tse2);
6784         }
6785       else
6786         {
6787           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6788           oss << " ! Should be in [0," << sz << ") !";
6789           throw INTERP_KERNEL::Exception(oss.str().c_str());
6790         }
6791     }
6792   if(ret->getNumberOfTS()>0)
6793     ret->synchronizeNameScope();
6794   ret->copyNameScope(*this);
6795   return ret.retn();
6796 }
6797
6798 /*!
6799  * 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
6800  * NULL.
6801  */
6802 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
6803 {
6804   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6805   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6806   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6807   ret->setInfo(_infos);
6808   int sz=(int)_time_steps.size();
6809   int j=bg;
6810   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6811     {
6812       if(j>=0 && j<sz)
6813         {
6814           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6815           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6816           if(tse)
6817             {
6818               tse->incrRef();
6819               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6820             }
6821           ret->pushBackTimeStep(tse2);
6822         }
6823       else
6824         {
6825           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6826           oss << " ! Should be in [0," << sz << ") !";
6827           throw INTERP_KERNEL::Exception(oss.str().c_str());
6828         }
6829     }
6830   if(ret->getNumberOfTS()>0)
6831     ret->synchronizeNameScope();
6832   ret->copyNameScope(*this);
6833   return ret.retn();
6834 }
6835
6836 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6837 {
6838   int id=0;
6839   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6840   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6841     {
6842       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6843       if(!cur)
6844         continue;
6845       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6846       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6847         ids->pushBackSilent(id);
6848     }
6849   return buildFromTimeStepIds(ids->begin(),ids->end());
6850 }
6851
6852 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6853 {
6854   int id=0;
6855   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6856   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6857     {
6858       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6859       if(!cur)
6860         continue;
6861       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6862       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6863         ids->pushBackSilent(id);
6864     }
6865   return buildFromTimeStepIds(ids->begin(),ids->end());
6866 }
6867
6868 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
6869 {
6870   return _infos;
6871 }
6872
6873 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
6874 {
6875   _infos=info;
6876 }
6877
6878 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
6879 {
6880   int ret=0;
6881   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6882     {
6883       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6884       if(pt->isDealingTS(iteration,order))
6885         return ret;
6886     }
6887   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6888   std::vector< std::pair<int,int> > vp=getIterations();
6889   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6890     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6891   throw INTERP_KERNEL::Exception(oss.str().c_str());
6892 }
6893
6894 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
6895 {
6896   return *_time_steps[getTimeStepPos(iteration,order)];
6897 }
6898
6899 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
6900 {
6901   return *_time_steps[getTimeStepPos(iteration,order)];
6902 }
6903
6904 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
6905 {
6906   if(_time_steps.empty())
6907     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6908   return _time_steps[0]->getMeshName();
6909 }
6910
6911 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
6912 {
6913   std::string oldName(getMeshName());
6914   std::vector< std::pair<std::string,std::string> > v(1);
6915   v[0].first=oldName; v[0].second=newMeshName;
6916   changeMeshNames(v);
6917 }
6918
6919 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6920 {
6921   bool ret=false;
6922   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6923     {
6924       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6925       if(cur)
6926         ret=cur->changeMeshNames(modifTab) || ret;
6927     }
6928   return ret;
6929 }
6930
6931 /*!
6932  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6933  */
6934 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
6935 {
6936   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6937 }
6938
6939 /*!
6940  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6941  */
6942 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6943 {
6944   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6945 }
6946
6947 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6948                                                                 MEDFileFieldGlobsReal& glob)
6949 {
6950   bool ret=false;
6951   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6952     {
6953       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6954       if(f1ts)
6955         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6956     }
6957   return ret;
6958 }
6959
6960 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6961 {
6962   std::string startLine(bkOffset,' ');
6963   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
6964   if(fmtsId>=0)
6965     oss << " (" << fmtsId << ")";
6966   oss << " has the following name: \"" << _name << "\"." << std::endl;
6967   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
6968   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6969     {
6970       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
6971     }
6972   int i=0;
6973   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
6974     {
6975       std::string chapter(17,'0'+i);
6976       oss << startLine << chapter << std::endl;
6977       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6978       if(cur)
6979         cur->simpleRepr(bkOffset+2,oss,i);
6980       else
6981         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
6982       oss << startLine << chapter << std::endl;
6983     }
6984 }
6985
6986 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
6987 {
6988   std::size_t sz=_time_steps.size();
6989   std::vector< std::pair<int,int> > ret(sz);
6990   ret1.resize(sz);
6991   for(std::size_t i=0;i<sz;i++)
6992     {
6993       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
6994       if(f1ts)
6995         {
6996           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
6997         }
6998       else
6999         {
7000           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7001           throw INTERP_KERNEL::Exception(oss.str().c_str());
7002         }
7003     }
7004   return ret;
7005 }
7006
7007 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7008 {
7009   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7010   if(!tse2)
7011     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7012   checkCoherencyOfType(tse2);
7013   if(_time_steps.empty())
7014     {
7015       setName(tse2->getName().c_str());
7016       setInfo(tse2->getInfo());
7017     }
7018   checkThatComponentsMatch(tse2->getInfo());
7019   _time_steps.push_back(tse);
7020 }
7021
7022 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7023 {
7024   std::size_t nbOfCompo=_infos.size();
7025   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7026     {
7027       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7028       if(cur)
7029         {
7030           if((cur->getInfo()).size()!=nbOfCompo)
7031             {
7032               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7033               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7034               throw INTERP_KERNEL::Exception(oss.str().c_str());
7035             }
7036           cur->copyNameScope(*this);
7037         }
7038     }
7039 }
7040
7041 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll)
7042 {
7043   _time_steps.resize(nbPdt);
7044   for(int i=0;i<nbPdt;i++)
7045     {
7046       std::vector< std::pair<int,int> > ts;
7047       med_int numdt=0,numo=0;
7048       med_int meshIt=0,meshOrder=0;
7049       med_float dt=0.0;
7050       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
7051       switch(fieldTyp)
7052         {
7053         case MED_FLOAT64:
7054           {
7055             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7056             break;
7057           }
7058         case MED_INT32:
7059           {
7060             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7061             break;
7062           }
7063         default:
7064           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7065         }
7066       if(loadAll)
7067         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this);
7068       else
7069         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this);
7070     }
7071 }
7072
7073 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7074 {
7075   if(_time_steps.empty())
7076     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7077   checkThatNbOfCompoOfTSMatchThis();
7078   std::vector<std::string> infos(getInfo());
7079   int nbComp=infos.size();
7080   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7081   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7082   for(int i=0;i<nbComp;i++)
7083     {
7084       std::string info=infos[i];
7085       std::string c,u;
7086       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7087       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7088       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7089     }
7090   if(_name.empty())
7091     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7092   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7093   int nbOfTS=_time_steps.size();
7094   for(int i=0;i<nbOfTS;i++)
7095     _time_steps[i]->writeLL(fid,opts,*this);
7096 }
7097
7098 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7099 {
7100   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7101     {
7102       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7103       if(elt)
7104         elt->loadBigArraysRecursively(fid,nasc);
7105     }
7106 }
7107   
7108 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7109 {
7110   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7111     {
7112       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7113       if(elt)
7114         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7115     }
7116 }
7117
7118 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7119 {
7120   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7121     {
7122       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7123       if(elt)
7124         elt->unloadArrays();
7125     }
7126 }
7127
7128 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7129 {
7130   return _time_steps.size();
7131 }
7132
7133 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7134 {
7135   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7136   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7137     {
7138       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7139       if(tmp)
7140         newTS.push_back(*it);
7141     }
7142   _time_steps=newTS;
7143 }
7144
7145 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7146 {
7147   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7148   int maxId=(int)_time_steps.size();
7149   int ii=0;
7150   std::set<int> idsToDel;
7151   for(const int *id=startIds;id!=endIds;id++,ii++)
7152     {
7153       if(*id>=0 && *id<maxId)
7154         {
7155           idsToDel.insert(*id);
7156         }
7157       else
7158         {
7159           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7160           throw INTERP_KERNEL::Exception(oss.str().c_str());
7161         }
7162     }
7163   for(int iii=0;iii<maxId;iii++)
7164     if(idsToDel.find(iii)==idsToDel.end())
7165       newTS.push_back(_time_steps[iii]);
7166   _time_steps=newTS;
7167 }
7168
7169 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7170 {
7171   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7172   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7173   if(nbOfEntriesToKill==0)
7174     return ;
7175   std::size_t sz=_time_steps.size();
7176   std::vector<bool> b(sz,true);
7177   int j=bg;
7178   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7179     b[j]=false;
7180   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7181   for(std::size_t i=0;i<sz;i++)
7182     if(b[i])
7183       newTS.push_back(_time_steps[i]);
7184   _time_steps=newTS;
7185 }
7186
7187 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7188 {
7189   int ret=0;
7190   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7191   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7192     {
7193       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7194       if(tmp)
7195         {
7196           int it2,ord;
7197           tmp->getTime(it2,ord);
7198           if(it2==iteration && order==ord)
7199             return ret;
7200           else
7201             oss << "(" << it2 << ","  << ord << "), ";
7202         }
7203     }
7204   throw INTERP_KERNEL::Exception(oss.str().c_str());
7205 }
7206
7207 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7208 {
7209   int ret=0;
7210   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7211   oss.precision(15);
7212   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7213     {
7214       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7215       if(tmp)
7216         {
7217           int it2,ord;
7218           double ti=tmp->getTime(it2,ord);
7219           if(fabs(time-ti)<eps)
7220             return ret;
7221           else
7222             oss << ti << ", ";
7223         }
7224     }
7225   throw INTERP_KERNEL::Exception(oss.str().c_str());
7226 }
7227
7228 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7229 {
7230   int lgth=_time_steps.size();
7231   std::vector< std::pair<int,int> > ret(lgth);
7232   for(int i=0;i<lgth;i++)
7233     _time_steps[i]->fillIteration(ret[i]);
7234   return ret;
7235 }
7236
7237 /*!
7238  * 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'
7239  * This method returns two things.
7240  * - The absolute dimension of 'this' in first parameter. 
7241  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7242  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7243  *
7244  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7245  * Only these 3 discretizations will be taken into account here.
7246  *
7247  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7248  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7249  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7250  *
7251  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7252  * 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'.
7253  * 
7254  * Let's consider the typical following case :
7255  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7256  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7257  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7258  *   TETRA4 and SEG2
7259  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7260  *
7261  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7262  * 
7263  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7264  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7265  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7266  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7267  */
7268 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7269 {
7270   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7271 }
7272
7273 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7274 {
7275   if(pos<0 || pos>=(int)_time_steps.size())
7276     {
7277       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7278       throw INTERP_KERNEL::Exception(oss.str().c_str());
7279     }
7280   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7281   if(item==0)
7282     {
7283       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7284       oss << "\nTry to use following method eraseEmptyTS !";
7285       throw INTERP_KERNEL::Exception(oss.str().c_str());
7286     }
7287   return item;
7288 }
7289
7290 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7291 {
7292   if(pos<0 || pos>=(int)_time_steps.size())
7293     {
7294       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7295       throw INTERP_KERNEL::Exception(oss.str().c_str());
7296     }
7297   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7298   if(item==0)
7299     {
7300       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7301       oss << "\nTry to use following method eraseEmptyTS !";
7302       throw INTERP_KERNEL::Exception(oss.str().c_str());
7303     }
7304   return item;
7305 }
7306
7307 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7308 {
7309   std::vector<std::string> ret;
7310   std::set<std::string> ret2;
7311   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7312     {
7313       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7314       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7315         if(ret2.find(*it2)==ret2.end())
7316           {
7317             ret.push_back(*it2);
7318             ret2.insert(*it2);
7319           }
7320     }
7321   return ret;
7322 }
7323
7324 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7325 {
7326   std::vector<std::string> ret;
7327   std::set<std::string> ret2;
7328   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7329     {
7330       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7331       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7332         if(ret2.find(*it2)==ret2.end())
7333           {
7334             ret.push_back(*it2);
7335             ret2.insert(*it2);
7336           }
7337     }
7338   return ret;
7339 }
7340
7341 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7342 {
7343   std::vector<std::string> ret;
7344   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7345     {
7346       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7347       ret.insert(ret.end(),tmp.begin(),tmp.end());
7348     }
7349   return ret;
7350 }
7351
7352 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7353 {
7354   std::vector<std::string> ret;
7355   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7356     {
7357       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7358       ret.insert(ret.end(),tmp.begin(),tmp.end());
7359     }
7360   return ret;
7361 }
7362
7363 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7364 {
7365   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7366     (*it)->changePflsRefsNamesGen2(mapOfModif);
7367 }
7368
7369 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7370 {
7371   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7372     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7373 }
7374
7375 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7376 {
7377   int lgth=_time_steps.size();
7378   std::vector< std::vector<TypeOfField> > ret(lgth);
7379   for(int i=0;i<lgth;i++)
7380     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7381   return ret;
7382 }
7383
7384 /*!
7385  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7386  */
7387 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
7388 {
7389   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7390 }
7391
7392 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7393 {
7394   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7395   std::size_t i=0;
7396   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7397     {
7398       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7399         ret->_time_steps[i]=(*it)->deepCpy();
7400     }
7401   return ret.retn();
7402 }
7403
7404 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7405 {
7406   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7407   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7408   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7409   for(std::size_t i=0;i<sz;i++)
7410     {
7411       ret[i]=shallowCpy();
7412       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7413     }
7414   for(std::size_t i=0;i<sz2;i++)
7415     {
7416       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7417       if(ret1.size()!=sz)
7418         {
7419           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7420           throw INTERP_KERNEL::Exception(oss.str().c_str());
7421         }
7422       ts[i]=ret1;
7423     }
7424   for(std::size_t i=0;i<sz;i++)
7425     for(std::size_t j=0;j<sz2;j++)
7426       ret[i]->_time_steps[j]=ts[j][i];
7427   return ret;
7428 }
7429
7430 /*!
7431  * This method splits into discretization each time steps in \a this.
7432  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7433  */
7434 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7435 {
7436   std::size_t sz(_time_steps.size());
7437   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7438   for(std::size_t i=0;i<sz;i++)
7439     {
7440       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7441       if(!timeStep)
7442         {
7443           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7444           throw INTERP_KERNEL::Exception(oss.str().c_str());
7445         }
7446       items[i]=timeStep->splitDiscretizations();  
7447     }
7448   //
7449   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7450   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7451   std::vector< TypeOfField > types;
7452   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7453     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7454       {
7455         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7456         if(ts.size()!=1)
7457           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7458         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7459         if(it2==types.end())
7460           types.push_back(ts[0]);
7461       }
7462   ret.resize(types.size()); ret2.resize(types.size());
7463   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7464     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7465       {
7466         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7467         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7468         ret2[pos].push_back(*it1);
7469       }
7470   for(std::size_t i=0;i<types.size();i++)
7471     {
7472       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=createNew();
7473       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7474         elt->pushBackTimeStep(*it1);//also updates infos in elt
7475       ret[i]=elt;
7476       elt->MEDFileFieldNameScope::operator=(*this);
7477     }
7478   return ret;
7479 }
7480
7481 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7482 {
7483   _name=field->getName();
7484   if(_name.empty())
7485     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7486   if(!arr)
7487     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7488   _infos=arr->getInfoOnComponents();
7489 }
7490
7491 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7492 {
7493   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7494   if(_name!=field->getName())
7495     {
7496       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7497       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7498       throw INTERP_KERNEL::Exception(oss.str().c_str());
7499     }
7500   if(!arr)
7501     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7502   checkThatComponentsMatch(arr->getInfoOnComponents());
7503 }
7504
7505 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7506 {
7507   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7508   if(getInfo().size()!=compos.size())
7509     {
7510       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7511       oss << " number of components of element to append (" << compos.size() << ") !";
7512       throw INTERP_KERNEL::Exception(oss.str().c_str());
7513     }
7514   if(_infos!=compos)
7515     {
7516       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7517       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7518       oss << " But compo in input fields are : ";
7519       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7520       oss << " !";
7521       throw INTERP_KERNEL::Exception(oss.str().c_str());
7522     }
7523 }
7524
7525 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7526 {
7527   std::size_t sz=_infos.size();
7528   int j=0;
7529   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7530     {
7531       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7532       if(elt)
7533         if(elt->getInfo().size()!=sz)
7534           {
7535             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7536             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7537             throw INTERP_KERNEL::Exception(oss.str().c_str());
7538           }
7539     }
7540 }
7541
7542 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7543 {
7544   if(!field)
7545     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7546   if(!_time_steps.empty())
7547     checkCoherencyOfTinyInfo(field,arr);
7548   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7549   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7550   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7551   copyTinyInfoFrom(field,arr);
7552   _time_steps.push_back(obj);
7553 }
7554
7555 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7556 {
7557   if(!field)
7558     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7559   if(!_time_steps.empty())
7560     checkCoherencyOfTinyInfo(field,arr);
7561   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7562   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7563   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7564   copyTinyInfoFrom(field,arr);
7565   _time_steps.push_back(obj);
7566 }
7567
7568 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7569 {
7570   int sz=(int)_time_steps.size();
7571   if(i<0 || i>=sz)
7572     {
7573       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7574       throw INTERP_KERNEL::Exception(oss.str().c_str());
7575     }
7576   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7577   if(tsPtr)
7578     {
7579       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7580         {
7581           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7582           throw INTERP_KERNEL::Exception(oss.str().c_str());
7583         }
7584     }
7585   _time_steps[i]=ts;
7586 }
7587
7588 //= MEDFileFieldMultiTSWithoutSDA
7589
7590 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)
7591 {
7592   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7593 }
7594
7595 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7596 {
7597 }
7598
7599 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7600 {
7601 }
7602
7603 /*!
7604  * \param [in] fieldId field id in C mode
7605  */
7606 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll)
7607 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7608 {
7609 }
7610 catch(INTERP_KERNEL::Exception& e)
7611   { throw e; }
7612
7613 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)
7614 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7615 {
7616 }
7617 catch(INTERP_KERNEL::Exception& e)
7618 { throw e; }
7619
7620 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7621 {
7622   return new MEDFileField1TSWithoutSDA;
7623 }
7624
7625 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7626 {
7627   if(!f1ts)
7628     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7629   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7630   if(!f1tsC)
7631     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7632 }
7633
7634 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7635 {
7636   return MEDFileField1TSWithoutSDA::TYPE_STR;
7637 }
7638
7639 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7640 {
7641   return new MEDFileFieldMultiTSWithoutSDA(*this);
7642 }
7643
7644 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7645 {
7646   return new MEDFileFieldMultiTSWithoutSDA;
7647 }
7648
7649 /*!
7650  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7651  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7652  */
7653 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
7654 {
7655   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7656   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7657   if(!myF1TSC)
7658     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7659   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7660 }
7661
7662 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
7663 {
7664   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7665   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7666   int i=0;
7667   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7668     {
7669       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7670       if(eltToConv)
7671         {
7672           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7673           if(!eltToConvC)
7674             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7675           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7676           ret->setIteration(i,elt);
7677         }
7678     }
7679   return ret.retn();
7680 }
7681
7682 //= MEDFileAnyTypeFieldMultiTS
7683
7684 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7685 {
7686 }
7687
7688 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll)
7689 try:MEDFileFieldGlobsReal(fileName)
7690 {
7691   MEDFileUtilities::CheckFileForRead(fileName);
7692   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7693   _content=BuildContentFrom(fid,fileName,loadAll);
7694   loadGlobals(fid);
7695 }
7696 catch(INTERP_KERNEL::Exception& e)
7697   {
7698     throw e;
7699   }
7700
7701 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll)
7702 {
7703   med_field_type typcha;
7704   std::vector<std::string> infos;
7705   std::string dtunit;
7706   int i=-1;
7707   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7708   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7709   switch(typcha)
7710     {
7711     case MED_FLOAT64:
7712       {
7713         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll);
7714         break;
7715       }
7716     case MED_INT32:
7717       {
7718         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll);
7719         break;
7720       }
7721     default:
7722       {
7723         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] !";
7724         throw INTERP_KERNEL::Exception(oss.str().c_str());
7725       }
7726     }
7727   ret->setDtUnit(dtunit.c_str());
7728   return ret.retn();
7729 }
7730
7731 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll)
7732 {
7733   med_field_type typcha;
7734   //
7735   std::vector<std::string> infos;
7736   std::string dtunit,fieldName;
7737   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7738   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7739   switch(typcha)
7740     {
7741     case MED_FLOAT64:
7742       {
7743         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll);
7744         break;
7745       }
7746     case MED_INT32:
7747       {
7748         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll);
7749         break;
7750       }
7751     default:
7752       {
7753         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] !";
7754         throw INTERP_KERNEL::Exception(oss.str().c_str());
7755       }
7756     }
7757   ret->setDtUnit(dtunit.c_str());
7758   return ret.retn();
7759 }
7760
7761 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
7762 {
7763   if(!c)
7764     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7765   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7766     {
7767       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7768       ret->setFileName(fileName);
7769       ret->_content=c;  c->incrRef();
7770       return ret.retn();
7771     }
7772   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7773     {
7774       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7775       ret->setFileName(fileName);
7776       ret->_content=c;  c->incrRef();
7777       return ret.retn();
7778     }
7779   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7780 }
7781
7782 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll)
7783 try:MEDFileFieldGlobsReal(fileName)
7784 {
7785   MEDFileUtilities::CheckFileForRead(fileName);
7786   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7787   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
7788   loadGlobals(fid);
7789 }
7790 catch(INTERP_KERNEL::Exception& e)
7791   {
7792     throw e;
7793   }
7794
7795 //= MEDFileIntFieldMultiTSWithoutSDA
7796
7797 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)
7798 {
7799   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7800 }
7801
7802 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7803 {
7804 }
7805
7806 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7807 {
7808 }
7809
7810 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)
7811 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7812 {
7813 }
7814 catch(INTERP_KERNEL::Exception& e)
7815 { throw e; }
7816
7817 /*!
7818  * \param [in] fieldId field id in C mode
7819  */
7820 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll)
7821 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7822 {
7823 }
7824 catch(INTERP_KERNEL::Exception& e)
7825   { throw e; }
7826
7827 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7828 {
7829   return new MEDFileIntField1TSWithoutSDA;
7830 }
7831
7832 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7833 {
7834   if(!f1ts)
7835     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7836   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7837   if(!f1tsC)
7838     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7839 }
7840
7841 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
7842 {
7843   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7844 }
7845
7846 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
7847 {
7848   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7849 }
7850
7851 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
7852 {
7853   return new MEDFileIntFieldMultiTSWithoutSDA;
7854 }
7855
7856 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
7857 {
7858   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7859   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7860   int i=0;
7861   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7862     {
7863       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7864       if(eltToConv)
7865         {
7866           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7867           if(!eltToConvC)
7868             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7869           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7870           ret->setIteration(i,elt);
7871         }
7872     }
7873   return ret.retn();
7874 }
7875
7876 //= MEDFileAnyTypeFieldMultiTS
7877
7878 /*!
7879  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7880  * that has been read from a specified MED file.
7881  *  \param [in] fileName - the name of the MED file to read.
7882  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7883  *          is to delete this field using decrRef() as it is no more needed.
7884  *  \throw If reading the file fails.
7885  */
7886 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
7887 {
7888   MEDFileUtilities::CheckFileForRead(fileName);
7889   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7890   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
7891   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7892   ret->loadGlobals(fid);
7893   return ret.retn();
7894 }
7895
7896 /*!
7897  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7898  * that has been read from a specified MED file.
7899  *  \param [in] fileName - the name of the MED file to read.
7900  *  \param [in] fieldName - the name of the field to read.
7901  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7902  *          is to delete this field using decrRef() as it is no more needed.
7903  *  \throw If reading the file fails.
7904  *  \throw If there is no field named \a fieldName in the file.
7905  */
7906 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
7907 {
7908   MEDFileUtilities::CheckFileForRead(fileName);
7909   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7910   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
7911   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7912   ret->loadGlobals(fid);
7913   return ret.retn();
7914 }
7915
7916 /*!
7917  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7918  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7919  *
7920  * \warning this is a shallow copy constructor
7921  */
7922 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7923 {
7924   if(!shallowCopyOfContent)
7925     {
7926       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7927       otherPtr->incrRef();
7928       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7929     }
7930   else
7931     {
7932       _content=other.shallowCpy();
7933     }
7934 }
7935
7936 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
7937 {
7938   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7939   if(!ret)
7940     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7941   return ret;
7942 }
7943
7944 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
7945 {
7946   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7947   if(!ret)
7948     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7949   return ret;
7950 }
7951
7952 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7953 {
7954   return contentNotNullBase()->getPflsReallyUsed2();
7955 }
7956
7957 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7958 {
7959   return contentNotNullBase()->getLocsReallyUsed2();
7960 }
7961
7962 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
7963 {
7964   return contentNotNullBase()->getPflsReallyUsedMulti2();
7965 }
7966
7967 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
7968 {
7969   return contentNotNullBase()->getLocsReallyUsedMulti2();
7970 }
7971
7972 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7973 {
7974   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
7975 }
7976
7977 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7978 {
7979   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
7980 }
7981
7982 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
7983 {
7984   return contentNotNullBase()->getNumberOfTS();
7985 }
7986
7987 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
7988 {
7989   contentNotNullBase()->eraseEmptyTS();
7990 }
7991
7992 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
7993 {
7994   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
7995 }
7996
7997 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
7998 {
7999   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8000 }
8001
8002 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8003 {
8004   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8005   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8006   ret->_content=c;
8007   return ret.retn();
8008 }
8009
8010 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8011 {
8012   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8013   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8014   ret->_content=c;
8015   return ret.retn();
8016 }
8017
8018 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8019 {
8020   return contentNotNullBase()->getIterations();
8021 }
8022
8023 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8024 {
8025   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8026     pushBackTimeStep(*it);
8027 }
8028
8029 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8030 {
8031   if(!f1ts)
8032     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8033   checkCoherencyOfType(f1ts);
8034   f1ts->incrRef();
8035   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8036   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8037   c->incrRef();
8038   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8039   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8040     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8041   _content->pushBackTimeStep(cSafe);
8042   appendGlobs(*f1ts,1e-12);
8043 }
8044
8045 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8046 {
8047   contentNotNullBase()->synchronizeNameScope();
8048 }
8049
8050 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8051 {
8052   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8053 }
8054
8055 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8056 {
8057   return contentNotNullBase()->getPosGivenTime(time,eps);
8058 }
8059
8060 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8061 {
8062   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8063 }
8064
8065 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8066 {
8067   return contentNotNullBase()->getTypesOfFieldAvailable();
8068 }
8069
8070 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
8071 {
8072   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8073 }
8074
8075 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8076 {
8077   return contentNotNullBase()->getName();
8078 }
8079
8080 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8081 {
8082   contentNotNullBase()->setName(name);
8083 }
8084
8085 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8086 {
8087   return contentNotNullBase()->getDtUnit();
8088 }
8089
8090 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8091 {
8092   contentNotNullBase()->setDtUnit(dtUnit);
8093 }
8094
8095 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8096 {
8097   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8098 }
8099
8100 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8101 {
8102   return contentNotNullBase()->getTimeSteps(ret1);
8103 }
8104
8105 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8106 {
8107   return contentNotNullBase()->getMeshName();
8108 }
8109
8110 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8111 {
8112   contentNotNullBase()->setMeshName(newMeshName);
8113 }
8114
8115 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8116 {
8117   return contentNotNullBase()->changeMeshNames(modifTab);
8118 }
8119
8120 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8121 {
8122   return contentNotNullBase()->getInfo();
8123 }
8124
8125 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8126 {
8127   return contentNotNullBase()->setInfo(info);
8128 }
8129
8130 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8131 {
8132   const std::vector<std::string> ret=getInfo();
8133   return (int)ret.size();
8134 }
8135
8136 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8137 {
8138   writeGlobals(fid,*this);
8139   contentNotNullBase()->writeLL(fid,*this);
8140 }
8141
8142 /*!
8143  * Writes \a this field into a MED file specified by its name.
8144  *  \param [in] fileName - the MED file name.
8145  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8146  * - 2 - erase; an existing file is removed.
8147  * - 1 - append; same data should not be present in an existing file.
8148  * - 0 - overwrite; same data present in an existing file is overwritten.
8149  *  \throw If the field name is not set.
8150  *  \throw If no field data is set.
8151  *  \throw If \a mode == 1 and the same data is present in an existing file.
8152  */
8153 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8154 {
8155   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8156   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8157   writeLL(fid);
8158 }
8159
8160 /*!
8161  * This method alloc the arrays and load potentially huge arrays contained in this field.
8162  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8163  * This method can be also called to refresh or reinit values from a file.
8164  * 
8165  * \throw If the fileName is not set or points to a non readable MED file.
8166  */
8167 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8168 {
8169   if(getFileName().empty())
8170     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8171   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8172   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8173 }
8174
8175 /*!
8176  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8177  * But once data loaded once, this method does nothing.
8178  * 
8179  * \throw If the fileName is not set or points to a non readable MED file.
8180  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8181  */
8182 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8183 {
8184   if(!getFileName().empty())
8185     {
8186       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8187       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8188     }
8189 }
8190
8191 /*!
8192  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8193  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8194  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8195  * 
8196  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8197  */
8198 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8199 {
8200   contentNotNullBase()->unloadArrays();
8201 }
8202
8203 /*!
8204  * 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.
8205  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8206  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8207  * 
8208  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8209  */
8210 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8211 {
8212   if(!getFileName().empty())
8213     contentNotNullBase()->unloadArrays();
8214 }
8215
8216 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8217 {
8218   std::ostringstream oss;
8219   contentNotNullBase()->simpleRepr(0,oss,-1);
8220   simpleReprGlobs(oss);
8221   return oss.str();
8222 }
8223
8224 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8225 {
8226   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8227 }
8228
8229 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildren() const
8230 {
8231   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildren());
8232   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8233     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8234   return ret;
8235 }
8236
8237 /*!
8238  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8239  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8240  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8241  */
8242 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8243 {
8244   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8245   if(!content)
8246     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8247   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8248   std::size_t sz(contentsSplit.size());
8249   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8250   for(std::size_t i=0;i<sz;i++)
8251     {
8252       ret[i]=shallowCpy();
8253       ret[i]->_content=contentsSplit[i];
8254     }
8255   return ret;
8256 }
8257
8258 /*!
8259  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8260  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8261  */
8262 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8263 {
8264   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8265   if(!content)
8266     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8267   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitDiscretizations();
8268   std::size_t sz(contentsSplit.size());
8269   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8270   for(std::size_t i=0;i<sz;i++)
8271     {
8272       ret[i]=shallowCpy();
8273       ret[i]->_content=contentsSplit[i];
8274     }
8275   return ret;
8276 }
8277
8278 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8279 {
8280   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8281   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8282     ret->_content=_content->deepCpy();
8283   ret->deepCpyGlobs(*this);
8284   return ret.retn();
8285 }
8286
8287 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8288 {
8289   return _content;
8290 }
8291
8292 /*!
8293  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8294  *  \param [in] iteration - the iteration number of a required time step.
8295  *  \param [in] order - the iteration order number of required time step.
8296  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8297  *          delete this field using decrRef() as it is no more needed.
8298  *  \throw If there is no required time step in \a this field.
8299  */
8300 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8301 {
8302   int pos=getPosOfTimeStep(iteration,order);
8303   return getTimeStepAtPos(pos);
8304 }
8305
8306 /*!
8307  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8308  *  \param [in] time - the time of the time step of interest.
8309  *  \param [in] eps - a precision used to compare time values.
8310  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8311  *          delete this field using decrRef() as it is no more needed.
8312  *  \throw If there is no required time step in \a this field.
8313  */
8314 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8315 {
8316   int pos=getPosGivenTime(time,eps);
8317   return getTimeStepAtPos(pos);
8318 }
8319
8320 /*!
8321  * 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.
8322  * The float64 value of time attached to the pair of integers are not considered here.
8323  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8324  *
8325  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8326  * \throw If there is a null pointer in \a vectFMTS.
8327  */
8328 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8329 {
8330   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8331   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8332   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8333   while(!lstFMTS.empty())
8334     {
8335       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8336       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8337       if(!curIt)
8338         throw INTERP_KERNEL::Exception(msg);
8339       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8340       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8341       elt.push_back(curIt); it=lstFMTS.erase(it);
8342       while(it!=lstFMTS.end())
8343         {
8344           curIt=*it;
8345           if(!curIt)
8346             throw INTERP_KERNEL::Exception(msg);
8347           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8348           if(refIts==curIts)
8349             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8350           else
8351             it++;
8352         }
8353       ret.push_back(elt);
8354     }
8355   return ret;
8356 }
8357
8358 /*!
8359  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8360  * All returned instances in a subvector can be safely loaded, rendered along time
8361  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8362  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8363  * 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).
8364  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8365  * 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.
8366  *
8367  * \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().
8368  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8369  * \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.
8370  * \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.
8371  *
8372  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8373  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8374  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8375  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8376  * \throw If mesh is null.
8377  * \throw If an element in \a vectFMTS is null.
8378  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8379  */
8380 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8381 {
8382   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8383   if(!mesh)
8384     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8385   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8386   if(vectFMTS.empty())
8387     return ret;
8388   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8389   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8390   if(!frstElt)
8391     throw INTERP_KERNEL::Exception(msg);
8392   std::size_t i=0;
8393   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8394   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8395   for(;it!=vectFMTS.end();it++,i++)
8396     {
8397       if(!(*it))
8398         throw INTERP_KERNEL::Exception(msg);
8399       TypeOfField tof0,tof1;
8400       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8401         {
8402           if(tof1!=ON_NODES)
8403             vectFMTSNotNodes.push_back(*it);
8404           else
8405             vectFMTSNodes.push_back(*it);
8406         }
8407       else
8408         vectFMTSNotNodes.push_back(*it);
8409     }
8410   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8411   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8412   ret=retCell;
8413   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8414     {
8415       i=0;
8416       bool isFetched(false);
8417       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8418         {
8419           if((*it0).empty())
8420             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8421           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8422             { ret[i].push_back(*it2); isFetched=true; }
8423         }
8424       if(!isFetched)
8425         {
8426           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8427           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8428           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8429         }
8430     }
8431   fsc=cmps;
8432   return ret;
8433 }
8434
8435 /*!
8436  * 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.
8437  * \param [out] cmps - same size than the returned vector.
8438  */
8439 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8440 {
8441   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8442   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8443   while(!lstFMTS.empty())
8444     {
8445       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8446       MEDFileAnyTypeFieldMultiTS *ref(*it);
8447       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8448       elt.push_back(ref); it=lstFMTS.erase(it);
8449       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8450       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8451       while(it!=lstFMTS.end())
8452         {
8453           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8454           if(cmp->isEqual(curIt))
8455             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8456           else
8457             it++;
8458         }
8459       ret.push_back(elt); cmps.push_back(cmp);
8460     }
8461   return ret;
8462 }
8463
8464 /*!
8465  * 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.
8466  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8467  *
8468  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8469  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8470  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8471  * \thorw If \a f0 and \a f1 do not have the same times steps.
8472  * \throw If mesh is null.
8473  * \throw If \a f0 or \a f1 is null.
8474  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8475  */
8476 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8477 {
8478   if(!mesh)
8479     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8480   if(!f0 || !f1)
8481     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8482   if(f0->getMeshName()!=mesh->getName())
8483     {
8484       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8485       throw INTERP_KERNEL::Exception(oss.str().c_str());
8486     }
8487   if(f1->getMeshName()!=mesh->getName())
8488     {
8489       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8490       throw INTERP_KERNEL::Exception(oss.str().c_str());
8491     }
8492   int nts=f0->getNumberOfTS();
8493   if(nts!=f1->getNumberOfTS())
8494     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8495   if(nts==0)
8496     return nts;
8497   for(int i=0;i<nts;i++)
8498     {
8499       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8500       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8501       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8502       if(tofs0.size()!=1 || tofs1.size()!=1)
8503         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8504       if(i!=0)
8505         {
8506           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8507             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8508         }
8509       else
8510         { tof0=tofs0[0]; tof1=tofs1[0]; }
8511       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8512         {
8513           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() << ") !";
8514           throw INTERP_KERNEL::Exception(oss.str().c_str());
8515         }
8516       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8517         {
8518           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() << ") !";
8519           throw INTERP_KERNEL::Exception(oss.str().c_str());
8520         }
8521       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8522         {
8523           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() << ") !";
8524           throw INTERP_KERNEL::Exception(oss.str().c_str());
8525         }
8526     }
8527   return nts;
8528 }
8529
8530 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8531 {
8532   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8533 }
8534
8535 //= MEDFileFieldMultiTS
8536
8537 /*!
8538  * Returns a new empty instance of MEDFileFieldMultiTS.
8539  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8540  *          is to delete this field using decrRef() as it is no more needed.
8541  */
8542 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8543 {
8544   return new MEDFileFieldMultiTS;
8545 }
8546
8547 /*!
8548  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8549  * that has been read from a specified MED file.
8550  *  \param [in] fileName - the name of the MED file to read.
8551  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8552  *          is to delete this field using decrRef() as it is no more needed.
8553  *  \throw If reading the file fails.
8554  */
8555 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8556 {
8557   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll);
8558   ret->contentNotNull();//to check that content type matches with \a this type.
8559   return ret.retn();
8560 }
8561
8562 /*!
8563  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8564  * that has been read from a specified MED file.
8565  *  \param [in] fileName - the name of the MED file to read.
8566  *  \param [in] fieldName - the name of the field to read.
8567  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8568  *          is to delete this field using decrRef() as it is no more needed.
8569  *  \throw If reading the file fails.
8570  *  \throw If there is no field named \a fieldName in the file.
8571  */
8572 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8573 {
8574   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll);
8575   ret->contentNotNull();//to check that content type matches with \a this type.
8576   return ret.retn();
8577 }
8578
8579 /*!
8580  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8581  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8582  *
8583  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8584  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8585  * \warning this is a shallow copy constructor
8586  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8587  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8588  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8589  *          is to delete this field using decrRef() as it is no more needed.
8590  */
8591 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8592 {
8593   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8594 }
8595
8596 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8597 {
8598   return new MEDFileFieldMultiTS(*this);
8599 }
8600
8601 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8602 {
8603   if(!f1ts)
8604     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8605   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8606   if(!f1tsC)
8607     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8608 }
8609
8610 /*!
8611  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8612  * following the given input policy.
8613  *
8614  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8615  *                            By default (true) the globals are deeply copied.
8616  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8617  */
8618 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8619 {
8620   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8621   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8622   if(content)
8623     {
8624       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8625       if(!contc)
8626         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8627       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8628       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8629     }
8630   else
8631     ret=MEDFileIntFieldMultiTS::New();
8632   if(isDeepCpyGlobs)
8633     ret->deepCpyGlobs(*this);
8634   else
8635     ret->shallowCpyGlobs(*this);
8636   return ret.retn();
8637 }
8638
8639 /*!
8640  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8641  *  \param [in] pos - a time step id.
8642  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8643  *          delete this field using decrRef() as it is no more needed.
8644  *  \throw If \a pos is not a valid time step id.
8645  */
8646 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
8647 {
8648   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8649   if(!item)
8650     {
8651       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8652       throw INTERP_KERNEL::Exception(oss.str().c_str());
8653     }
8654   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8655   if(itemC)
8656     {
8657       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8658       ret->shallowCpyGlobs(*this);
8659       return ret.retn();
8660     }
8661   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8662   throw INTERP_KERNEL::Exception(oss.str().c_str());
8663 }
8664
8665 /*!
8666  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8667  * mesh entities of a given dimension of the first mesh in MED file.
8668  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8669  *  \param [in] type - a spatial discretization of interest.
8670  *  \param [in] iteration - the iteration number of a required time step.
8671  *  \param [in] order - the iteration order number of required time step.
8672  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8673  *  \param [in] renumPol - specifies how to permute values of the result field according to
8674  *          the optional numbers of cells and nodes, if any. The valid values are
8675  *          - 0 - do not permute.
8676  *          - 1 - permute cells.
8677  *          - 2 - permute nodes.
8678  *          - 3 - permute cells and nodes.
8679  *
8680  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8681  *          caller is to delete this field using decrRef() as it is no more needed. 
8682  *  \throw If the MED file is not readable.
8683  *  \throw If there is no mesh in the MED file.
8684  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8685  *  \throw If no field values of the required parameters are available.
8686  */
8687 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
8688 {
8689   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8690   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8691   if(!myF1TSC)
8692     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8693   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8694   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8695   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8696   return ret.retn();
8697 }
8698
8699 /*!
8700  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8701  * the top level cells of the first mesh in MED file.
8702  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8703  *  \param [in] type - a spatial discretization of interest.
8704  *  \param [in] iteration - the iteration number of a required time step.
8705  *  \param [in] order - the iteration order number of required time step.
8706  *  \param [in] renumPol - specifies how to permute values of the result field according to
8707  *          the optional numbers of cells and nodes, if any. The valid values are
8708  *          - 0 - do not permute.
8709  *          - 1 - permute cells.
8710  *          - 2 - permute nodes.
8711  *          - 3 - permute cells and nodes.
8712  *
8713  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8714  *          caller is to delete this field using decrRef() as it is no more needed. 
8715  *  \throw If the MED file is not readable.
8716  *  \throw If there is no mesh in the MED file.
8717  *  \throw If no field values of the required parameters are available.
8718  */
8719 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
8720 {
8721   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8722   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8723   if(!myF1TSC)
8724     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8725   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8726   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8727   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8728   return ret.retn();
8729 }
8730
8731 /*!
8732  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8733  * a given support.
8734  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8735  *  \param [in] type - a spatial discretization of interest.
8736  *  \param [in] iteration - the iteration number of a required time step.
8737  *  \param [in] order - the iteration order number of required time step.
8738  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8739  *  \param [in] mesh - the supporting mesh.
8740  *  \param [in] renumPol - specifies how to permute values of the result field according to
8741  *          the optional numbers of cells and nodes, if any. The valid values are
8742  *          - 0 - do not permute.
8743  *          - 1 - permute cells.
8744  *          - 2 - permute nodes.
8745  *          - 3 - permute cells and nodes.
8746  *
8747  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8748  *          caller is to delete this field using decrRef() as it is no more needed. 
8749  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8750  *  \throw If no field of \a this is lying on \a mesh.
8751  *  \throw If no field values of the required parameters are available.
8752  */
8753 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
8754 {
8755   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8756   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8757   if(!myF1TSC)
8758     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8759   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8760   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8761   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8762   return ret.retn();
8763 }
8764
8765 /*!
8766  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8767  * given support. 
8768  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8769  *  \param [in] type - a spatial discretization of the new field.
8770  *  \param [in] iteration - the iteration number of a required time step.
8771  *  \param [in] order - the iteration order number of required time step.
8772  *  \param [in] mesh - the supporting mesh.
8773  *  \param [in] renumPol - specifies how to permute values of the result field according to
8774  *          the optional numbers of cells and nodes, if any. The valid values are
8775  *          - 0 - do not permute.
8776  *          - 1 - permute cells.
8777  *          - 2 - permute nodes.
8778  *          - 3 - permute cells and nodes.
8779  *
8780  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8781  *          caller is to delete this field using decrRef() as it is no more needed. 
8782  *  \throw If no field of \a this is lying on \a mesh.
8783  *  \throw If no field values of the required parameters are available.
8784  */
8785 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
8786 {
8787   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8788   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8789   if(!myF1TSC)
8790     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8791   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8792   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8793   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8794   return ret.retn();
8795 }
8796
8797 /*!
8798  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8799  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8800  * This method is useful for MED2 file format when field on different mesh was autorized.
8801  */
8802 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
8803 {
8804   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8805   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8806   if(!myF1TSC)
8807     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8808   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8809   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8810   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8811   return ret.retn();
8812 }
8813
8814 /*!
8815  * Returns values and a profile of the field of a given type, of a given time step,
8816  * lying on a given support.
8817  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8818  *  \param [in] type - a spatial discretization of the field.
8819  *  \param [in] iteration - the iteration number of a required time step.
8820  *  \param [in] order - the iteration order number of required time step.
8821  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8822  *  \param [in] mesh - the supporting mesh.
8823  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8824  *          field of interest lies on. If the field lies on all entities of the given
8825  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8826  *          using decrRef() as it is no more needed.  
8827  *  \param [in] glob - the global data storing profiles and localization.
8828  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8829  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8830  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8831  *  \throw If no field of \a this is lying on \a mesh.
8832  *  \throw If no field values of the required parameters are available.
8833  */
8834 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
8835 {
8836   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8837   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8838   if(!myF1TSC)
8839     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8840   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8841   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8842 }
8843
8844 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
8845 {
8846   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8847   if(!pt)
8848     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8849   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8850   if(!ret)
8851     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 !");
8852   return ret;
8853 }
8854
8855  MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
8856 {
8857   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8858   if(!pt)
8859     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8860   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8861   if(!ret)
8862     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 !");
8863   return ret;
8864 }
8865
8866 /*!
8867  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8868  * the given field is checked if its elements are sorted suitable for writing to MED file
8869  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8870  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8871  *  \param [in] field - the field to add to \a this.
8872  *  \throw If the name of \a field is empty.
8873  *  \throw If the data array of \a field is not set.
8874  *  \throw If existing time steps have different name or number of components than \a field.
8875  *  \throw If the underlying mesh of \a field has no name.
8876  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8877  */
8878 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
8879 {
8880   const DataArrayDouble *arr=0;
8881   if(field)
8882     arr=field->getArray();
8883   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8884 }
8885
8886 /*!
8887  * Adds a MEDCouplingFieldDouble to \a this as another time step.
8888  * The mesh support of input parameter \a field is ignored here, it can be NULL.
8889  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
8890  * and \a profile.
8891  *
8892  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
8893  * A new profile is added only if no equal profile is missing.
8894  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8895  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
8896  *  \param [in] mesh - the supporting mesh of \a field.
8897  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
8898  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8899  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8900  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8901  *  \throw If the data array of \a field is not set.
8902  *  \throw If the data array of \a this is already allocated but has different number of
8903  *         components than \a field.
8904  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8905  *  \sa setFieldNoProfileSBT()
8906  */
8907 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
8908 {
8909   const DataArrayDouble *arr=0;
8910   if(field)
8911     arr=field->getArray();
8912   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8913 }
8914
8915 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8916 {
8917   _content=new MEDFileFieldMultiTSWithoutSDA;
8918 }
8919
8920 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll)
8921 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
8922 {
8923 }
8924 catch(INTERP_KERNEL::Exception& e)
8925   { throw e; }
8926
8927 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll)
8928 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
8929 {
8930 }
8931 catch(INTERP_KERNEL::Exception& e)
8932   { throw e; }
8933
8934 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8935 {
8936 }
8937
8938 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
8939 {
8940   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8941 }
8942
8943 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
8944 {
8945   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8946 }
8947
8948 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
8949 {
8950   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8951 }
8952
8953 //= MEDFileAnyTypeFieldMultiTSIterator
8954
8955 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8956 {
8957   if(fmts)
8958     {
8959       fmts->incrRef();
8960       _nb_iter=fmts->getNumberOfTS();
8961     }
8962 }
8963
8964 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
8965 {
8966 }
8967
8968 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
8969 {
8970   if(_iter_id<_nb_iter)
8971     {
8972       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
8973       if(fmts)
8974         return fmts->getTimeStepAtPos(_iter_id++);
8975       else
8976         return 0;
8977     }
8978   else
8979     return 0;
8980 }
8981
8982 //= MEDFileIntFieldMultiTS
8983
8984 /*!
8985  * Returns a new empty instance of MEDFileFieldMultiTS.
8986  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8987  *          is to delete this field using decrRef() as it is no more needed.
8988  */
8989 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
8990 {
8991   return new MEDFileIntFieldMultiTS;
8992 }
8993
8994 /*!
8995  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
8996  * that has been read from a specified MED file.
8997  *  \param [in] fileName - the name of the MED file to read.
8998  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8999  *          is to delete this field using decrRef() as it is no more needed.
9000  *  \throw If reading the file fails.
9001  */
9002 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9003 {
9004   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll);
9005   ret->contentNotNull();//to check that content type matches with \a this type.
9006   return ret.retn();
9007 }
9008
9009 /*!
9010  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9011  * that has been read from a specified MED file.
9012  *  \param [in] fileName - the name of the MED file to read.
9013  *  \param [in] fieldName - the name of the field to read.
9014  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9015  *          is to delete this field using decrRef() as it is no more needed.
9016  *  \throw If reading the file fails.
9017  *  \throw If there is no field named \a fieldName in the file.
9018  */
9019 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9020 {
9021   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll);
9022   ret->contentNotNull();//to check that content type matches with \a this type.
9023   return ret.retn();
9024 }
9025
9026 /*!
9027  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9028  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9029  *
9030  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9031  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9032  * \warning this is a shallow copy constructor
9033  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9034  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9035  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9036  *          is to delete this field using decrRef() as it is no more needed.
9037  */
9038 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9039 {
9040   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9041 }
9042
9043 /*!
9044  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9045  * following the given input policy.
9046  *
9047  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9048  *                            By default (true) the globals are deeply copied.
9049  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9050  */
9051 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9052 {
9053   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9054   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9055   if(content)
9056     {
9057       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9058       if(!contc)
9059         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9060       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9061       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9062     }
9063   else
9064     ret=MEDFileFieldMultiTS::New();
9065   if(isDeepCpyGlobs)
9066     ret->deepCpyGlobs(*this);
9067   else
9068     ret->shallowCpyGlobs(*this);
9069   return ret.retn();
9070 }
9071
9072 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9073 {
9074   return new MEDFileIntFieldMultiTS(*this);
9075 }
9076
9077 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9078 {
9079   if(!f1ts)
9080     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9081   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9082   if(!f1tsC)
9083     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9084 }
9085
9086 /*!
9087  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9088  * mesh entities of a given dimension of the first mesh in MED file.
9089  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9090  *  \param [in] type - a spatial discretization of interest.
9091  *  \param [in] iteration - the iteration number of a required time step.
9092  *  \param [in] order - the iteration order number of required time step.
9093  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9094  *  \param [out] arrOut - the DataArrayInt containing values of field.
9095  *  \param [in] renumPol - specifies how to permute values of the result field according to
9096  *          the optional numbers of cells and nodes, if any. The valid values are
9097  *          - 0 - do not permute.
9098  *          - 1 - permute cells.
9099  *          - 2 - permute nodes.
9100  *          - 3 - permute cells and nodes.
9101  *
9102  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9103  *          caller is to delete this field using decrRef() as it is no more needed. 
9104  *  \throw If the MED file is not readable.
9105  *  \throw If there is no mesh in the MED file.
9106  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9107  *  \throw If no field values of the required parameters are available.
9108  */
9109 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9110 {
9111   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9112   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9113   if(!myF1TSC)
9114     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9115   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9116   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9117   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9118   return ret.retn();
9119 }
9120
9121 /*!
9122  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9123  * the top level cells of the first mesh in MED file.
9124  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9125  *  \param [in] type - a spatial discretization of interest.
9126  *  \param [in] iteration - the iteration number of a required time step.
9127  *  \param [in] order - the iteration order number of required time step.
9128  *  \param [out] arrOut - the DataArrayInt containing values of field.
9129  *  \param [in] renumPol - specifies how to permute values of the result field according to
9130  *          the optional numbers of cells and nodes, if any. The valid values are
9131  *          - 0 - do not permute.
9132  *          - 1 - permute cells.
9133  *          - 2 - permute nodes.
9134  *          - 3 - permute cells and nodes.
9135  *
9136  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9137  *          caller is to delete this field using decrRef() as it is no more needed. 
9138  *  \throw If the MED file is not readable.
9139  *  \throw If there is no mesh in the MED file.
9140  *  \throw If no field values of the required parameters are available.
9141  */
9142 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9143 {
9144   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9145   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9146   if(!myF1TSC)
9147     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9148   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9149   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9150   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9151   return ret.retn();
9152 }
9153
9154 /*!
9155  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9156  * a given support.
9157  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9158  *  \param [in] type - a spatial discretization of interest.
9159  *  \param [in] iteration - the iteration number of a required time step.
9160  *  \param [in] order - the iteration order number of required time step.
9161  *  \param [out] arrOut - the DataArrayInt containing values of field.
9162  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9163  *  \param [in] mesh - the supporting mesh.
9164  *  \param [in] renumPol - specifies how to permute values of the result field according to
9165  *          the optional numbers of cells and nodes, if any. The valid values are
9166  *          - 0 - do not permute.
9167  *          - 1 - permute cells.
9168  *          - 2 - permute nodes.
9169  *          - 3 - permute cells and nodes.
9170  *
9171  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9172  *          caller is to delete this field using decrRef() as it is no more needed. 
9173  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9174  *  \throw If no field of \a this is lying on \a mesh.
9175  *  \throw If no field values of the required parameters are available.
9176  */
9177 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9178 {
9179   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9180   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9181   if(!myF1TSC)
9182     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9183   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9184   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9185   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9186   return ret.retn();
9187 }
9188
9189 /*!
9190  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9191  * given support. 
9192  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9193  *  \param [in] type - a spatial discretization of the new field.
9194  *  \param [in] iteration - the iteration number of a required time step.
9195  *  \param [in] order - the iteration order number of required time step.
9196  *  \param [in] mesh - the supporting mesh.
9197  *  \param [out] arrOut - the DataArrayInt containing values of field.
9198  *  \param [in] renumPol - specifies how to permute values of the result field according to
9199  *          the optional numbers of cells and nodes, if any. The valid values are
9200  *          - 0 - do not permute.
9201  *          - 1 - permute cells.
9202  *          - 2 - permute nodes.
9203  *          - 3 - permute cells and nodes.
9204  *
9205  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9206  *          caller is to delete this field using decrRef() as it is no more needed. 
9207  *  \throw If no field of \a this is lying on \a mesh.
9208  *  \throw If no field values of the required parameters are available.
9209  */
9210 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9211 {
9212   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9213   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9214   if(!myF1TSC)
9215     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9216   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9217   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9218   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9219   return ret.retn();
9220 }
9221
9222 /*!
9223  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9224  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9225  * This method is useful for MED2 file format when field on different mesh was autorized.
9226  */
9227 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9228 {
9229   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9230   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9231   if(!myF1TSC)
9232     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9233   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9234   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9235   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9236   return ret.retn();
9237 }
9238
9239 /*!
9240  * Returns values and a profile of the field of a given type, of a given time step,
9241  * lying on a given support.
9242  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9243  *  \param [in] type - a spatial discretization of the field.
9244  *  \param [in] iteration - the iteration number of a required time step.
9245  *  \param [in] order - the iteration order number of required time step.
9246  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9247  *  \param [in] mesh - the supporting mesh.
9248  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9249  *          field of interest lies on. If the field lies on all entities of the given
9250  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9251  *          using decrRef() as it is no more needed.  
9252  *  \param [in] glob - the global data storing profiles and localization.
9253  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9254  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9255  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9256  *  \throw If no field of \a this is lying on \a mesh.
9257  *  \throw If no field values of the required parameters are available.
9258  */
9259 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9260 {
9261   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9262   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9263   if(!myF1TSC)
9264     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9265   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9266   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9267 }
9268
9269 /*!
9270  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9271  *  \param [in] pos - a time step id.
9272  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9273  *          delete this field using decrRef() as it is no more needed.
9274  *  \throw If \a pos is not a valid time step id.
9275  */
9276 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9277 {
9278   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9279   if(!item)
9280     {
9281       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9282       throw INTERP_KERNEL::Exception(oss.str().c_str());
9283     }
9284   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9285   if(itemC)
9286     {
9287       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9288       ret->shallowCpyGlobs(*this);
9289       return ret.retn();
9290     }
9291   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9292   throw INTERP_KERNEL::Exception(oss.str().c_str());
9293 }
9294
9295 /*!
9296  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9297  * the given field is checked if its elements are sorted suitable for writing to MED file
9298  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9299  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9300  *  \param [in] field - the field to add to \a this.
9301  *  \throw If the name of \a field is empty.
9302  *  \throw If the data array of \a field is not set.
9303  *  \throw If existing time steps have different name or number of components than \a field.
9304  *  \throw If the underlying mesh of \a field has no name.
9305  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9306  */
9307 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9308 {
9309   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9310 }
9311
9312 /*!
9313  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9314  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9315  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9316  * and \a profile.
9317  *
9318  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9319  * A new profile is added only if no equal profile is missing.
9320  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9321  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9322  *  \param [in] arrOfVals - the values of the field \a field used.
9323  *  \param [in] mesh - the supporting mesh of \a field.
9324  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9325  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9326  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9327  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9328  *  \throw If the data array of \a field is not set.
9329  *  \throw If the data array of \a this is already allocated but has different number of
9330  *         components than \a field.
9331  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9332  *  \sa setFieldNoProfileSBT()
9333  */
9334 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9335 {
9336   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9337 }
9338
9339 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9340 {
9341   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9342   if(!pt)
9343     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9344   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9345   if(!ret)
9346     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 !");
9347   return ret;
9348 }
9349
9350  MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9351 {
9352   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9353   if(!pt)
9354     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9355   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9356   if(!ret)
9357     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 !");
9358   return ret;
9359 }
9360
9361 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9362 {
9363   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9364 }
9365
9366 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9367 {
9368 }
9369
9370 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll)
9371 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
9372 {
9373 }
9374 catch(INTERP_KERNEL::Exception& e)
9375   { throw e; }
9376
9377 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll)
9378 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
9379 {
9380 }
9381 catch(INTERP_KERNEL::Exception& e)
9382   { throw e; }
9383
9384 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9385 {
9386   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9387 }
9388
9389 //= MEDFileFields
9390
9391 MEDFileFields *MEDFileFields::New()
9392 {
9393   return new MEDFileFields;
9394 }
9395
9396 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9397 {
9398   return new MEDFileFields(fileName,loadAll);
9399 }
9400
9401 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9402 {
9403   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9404   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9405   return ret;
9406 }
9407
9408 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildren() const
9409 {
9410   std::vector<const BigMemoryObject *> ret;
9411   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9412     {
9413       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9414       if(cur)
9415         ret.push_back(cur);
9416     }
9417   return ret;
9418 }
9419
9420 MEDFileFields *MEDFileFields::deepCpy() const
9421 {
9422   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9423   std::size_t i=0;
9424   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9425     {
9426       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9427         ret->_fields[i]=(*it)->deepCpy();
9428     }
9429   ret->deepCpyGlobs(*this);
9430   return ret.retn();
9431 }
9432
9433 MEDFileFields *MEDFileFields::shallowCpy() const
9434 {
9435   return new MEDFileFields(*this);
9436 }
9437
9438 /*!
9439  * 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
9440  * 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.
9441  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9442  *
9443  * \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.
9444  * \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.
9445  * 
9446  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9447  */
9448 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9449 {
9450   std::set< std::pair<int,int> > s;
9451   bool firstShot=true;
9452   areThereSomeForgottenTS=false;
9453   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9454     {
9455       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9456         continue;
9457       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9458       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9459       if(firstShot)
9460         { s=s1; firstShot=false; }
9461       else
9462         {
9463           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9464           if(s!=s2)
9465             areThereSomeForgottenTS=true;
9466           s=s2;
9467         }
9468     }
9469   std::vector< std::pair<int,int> > ret;
9470   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9471   return ret;
9472 }
9473
9474 int MEDFileFields::getNumberOfFields() const
9475 {
9476   return _fields.size();
9477 }
9478
9479 std::vector<std::string> MEDFileFields::getFieldsNames() const
9480 {
9481   std::vector<std::string> ret(_fields.size());
9482   int i=0;
9483   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9484     {
9485       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9486       if(f)
9487         {
9488           ret[i]=f->getName();
9489         }
9490       else
9491         {
9492           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9493           throw INTERP_KERNEL::Exception(oss.str().c_str());
9494         }
9495     }
9496   return ret;
9497 }
9498
9499 std::vector<std::string> MEDFileFields::getMeshesNames() const
9500 {
9501   std::vector<std::string> ret;
9502   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9503     {
9504       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9505       if(cur)
9506         ret.push_back(cur->getMeshName());
9507     }
9508   return ret;
9509 }
9510
9511 std::string MEDFileFields::simpleRepr() const
9512 {
9513   std::ostringstream oss;
9514   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9515   simpleRepr(0,oss);
9516   return oss.str();
9517 }
9518
9519 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9520 {
9521   int nbOfFields=getNumberOfFields();
9522   std::string startLine(bkOffset,' ');
9523   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9524   int i=0;
9525   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9526     {
9527       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9528       if(cur)
9529         {
9530           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9531         }
9532       else
9533         {
9534           oss << startLine << "  - not defined !" << std::endl;
9535         }
9536     }
9537   i=0;
9538   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9539     {
9540       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9541       std::string chapter(17,'0'+i);
9542       oss << startLine << chapter << std::endl;
9543       if(cur)
9544         {
9545           cur->simpleRepr(bkOffset+2,oss,i);
9546         }
9547       else
9548         {
9549           oss << startLine << "  - not defined !" << std::endl;
9550         }
9551       oss << startLine << chapter << std::endl;
9552     }
9553   simpleReprGlobs(oss);
9554 }
9555
9556 MEDFileFields::MEDFileFields()
9557 {
9558 }
9559
9560 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll)
9561 try:MEDFileFieldGlobsReal(fileName)
9562   {
9563     MEDFileUtilities::CheckFileForRead(fileName);
9564     MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
9565     int nbFields=MEDnField(fid);
9566     _fields.resize(nbFields);
9567     med_field_type typcha;
9568     for(int i=0;i<nbFields;i++)
9569       {
9570         std::vector<std::string> infos;
9571         std::string fieldName,dtunit;
9572         int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit);
9573         switch(typcha)
9574           {
9575           case MED_FLOAT64:
9576             {
9577               _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9578               break;
9579             }
9580           case MED_INT32:
9581             {
9582               _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9583               break;
9584             }
9585           default:
9586             {
9587               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] !";
9588               throw INTERP_KERNEL::Exception(oss.str().c_str());
9589             }
9590           }
9591       }
9592     loadAllGlobals(fid);
9593   }
9594 catch(INTERP_KERNEL::Exception& e)
9595   {
9596     throw e;
9597   }
9598
9599 void MEDFileFields::writeLL(med_idt fid) const
9600 {
9601   int i=0;
9602   writeGlobals(fid,*this);
9603   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9604     {
9605       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9606       if(!elt)
9607         {
9608           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9609           throw INTERP_KERNEL::Exception(oss.str().c_str());
9610         }
9611       elt->writeLL(fid,*this);
9612     }
9613 }
9614
9615 void MEDFileFields::write(const std::string& fileName, int mode) const
9616 {
9617   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9618   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
9619   writeLL(fid);
9620 }
9621
9622 /*!
9623  * This method alloc the arrays and load potentially huge arrays contained in this field.
9624  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9625  * This method can be also called to refresh or reinit values from a file.
9626  * 
9627  * \throw If the fileName is not set or points to a non readable MED file.
9628  */
9629 void MEDFileFields::loadArrays()
9630 {
9631   if(getFileName().empty())
9632     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9633   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9634   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9635     {
9636       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9637       if(elt)
9638         elt->loadBigArraysRecursively(fid,*elt);
9639     }
9640 }
9641
9642 /*!
9643  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9644  * But once data loaded once, this method does nothing.
9645  * 
9646  * \throw If the fileName is not set or points to a non readable MED file.
9647  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9648  */
9649 void MEDFileFields::loadArraysIfNecessary()
9650 {
9651   if(!getFileName().empty())
9652     {
9653       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9654       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9655         {
9656           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9657           if(elt)
9658             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9659         }
9660     }
9661 }
9662
9663 /*!
9664  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9665  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9666  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9667  * 
9668  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9669  */
9670 void MEDFileFields::unloadArrays()
9671 {
9672   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9673     {
9674       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9675       if(elt)
9676         elt->unloadArrays();
9677     }
9678 }
9679
9680 /*!
9681  * 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.
9682  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9683  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9684  * 
9685  * \sa MEDFileFields::loadArraysIfNecessary
9686  */
9687 void MEDFileFields::unloadArraysWithoutDataLoss()
9688 {
9689   if(!getFileName().empty())
9690     unloadArrays();
9691 }
9692
9693 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9694 {
9695   std::vector<std::string> ret;
9696   std::set<std::string> ret2;
9697   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9698     {
9699       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9700       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9701         if(ret2.find(*it2)==ret2.end())
9702           {
9703             ret.push_back(*it2);
9704             ret2.insert(*it2);
9705           }
9706     }
9707   return ret;
9708 }
9709
9710 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9711 {
9712   std::vector<std::string> ret;
9713   std::set<std::string> ret2;
9714   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9715     {
9716       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9717       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9718         if(ret2.find(*it2)==ret2.end())
9719           {
9720             ret.push_back(*it2);
9721             ret2.insert(*it2);
9722           }
9723     }
9724   return ret;
9725 }
9726
9727 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9728 {
9729   std::vector<std::string> ret;
9730   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9731     {
9732       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
9733       ret.insert(ret.end(),tmp.begin(),tmp.end());
9734     }
9735   return ret;
9736 }
9737
9738 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9739 {
9740   std::vector<std::string> ret;
9741   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9742     {
9743       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9744       ret.insert(ret.end(),tmp.begin(),tmp.end());
9745     }
9746   return ret;
9747 }
9748
9749 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9750 {
9751   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9752     (*it)->changePflsRefsNamesGen2(mapOfModif);
9753 }
9754
9755 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9756 {
9757   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9758     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9759 }
9760
9761 void MEDFileFields::resize(int newSize)
9762 {
9763   _fields.resize(newSize);
9764 }
9765
9766 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
9767 {
9768   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9769     pushField(*it);
9770 }
9771
9772 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
9773 {
9774   if(!field)
9775     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9776   _fields.push_back(field->getContent());
9777   appendGlobs(*field,1e-12);
9778 }
9779
9780 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
9781 {
9782   if(!field)
9783     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9784   if(i>=(int)_fields.size())
9785     _fields.resize(i+1);
9786   _fields[i]=field->getContent();
9787   appendGlobs(*field,1e-12);
9788 }
9789
9790 void MEDFileFields::destroyFieldAtPos(int i)
9791 {
9792   destroyFieldsAtPos(&i,&i+1);
9793 }
9794
9795 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
9796 {
9797   std::vector<bool> b(_fields.size(),true);
9798   for(const int *i=startIds;i!=endIds;i++)
9799     {
9800       if(*i<0 || *i>=(int)_fields.size())
9801         {
9802           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9803           throw INTERP_KERNEL::Exception(oss.str().c_str());
9804         }
9805       b[*i]=false;
9806     }
9807   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9808   std::size_t j=0;
9809   for(std::size_t i=0;i<_fields.size();i++)
9810     if(b[i])
9811       fields[j++]=_fields[i];
9812   _fields=fields;
9813 }
9814
9815 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
9816 {
9817   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9818   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9819   std::vector<bool> b(_fields.size(),true);
9820   int k=bg;
9821   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9822     {
9823       if(k<0 || k>=(int)_fields.size())
9824         {
9825           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9826           throw INTERP_KERNEL::Exception(oss.str().c_str());
9827         }
9828       b[k]=false;
9829     }
9830   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9831   std::size_t j=0;
9832   for(std::size_t i=0;i<_fields.size();i++)
9833     if(b[i])
9834       fields[j++]=_fields[i];
9835   _fields=fields;
9836 }
9837
9838 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9839 {
9840   bool ret=false;
9841   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9842     {
9843       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9844       if(cur)
9845         ret=cur->changeMeshNames(modifTab) || ret;
9846     }
9847   return ret;
9848 }
9849
9850 /*!
9851  * \param [in] meshName the name of the mesh that will be renumbered.
9852  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9853  *             This code corresponds to the distribution of types in the corresponding mesh.
9854  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9855  * \param [in] renumO2N the old to new renumber array.
9856  * \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 
9857  *         field in \a this.
9858  */
9859 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
9860 {
9861   bool ret=false;
9862   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9863     {
9864       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9865       if(fmts)
9866         {
9867           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9868         }
9869     }
9870   return ret;
9871 }
9872
9873 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
9874 {
9875   if(i<0 || i>=(int)_fields.size())
9876     {
9877       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9878       throw INTERP_KERNEL::Exception(oss.str().c_str());
9879     }
9880   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9881   if(!fmts)
9882     return 0;
9883   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9884   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9885   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9886   if(fmtsC)
9887     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9888   else if(fmtsC2)
9889     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9890   else
9891     {
9892       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9893       throw INTERP_KERNEL::Exception(oss.str().c_str());
9894     }
9895   ret->shallowCpyGlobs(*this);
9896   return ret.retn();
9897 }
9898
9899 /*!
9900  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9901  * This method is accessible in python using __getitem__ with a list in input.
9902  * \return a new object that the caller should deal with.
9903  */
9904 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
9905 {
9906   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9907   std::size_t sz=std::distance(startIds,endIds);
9908   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9909   int j=0;
9910   for(const int *i=startIds;i!=endIds;i++,j++)
9911     {
9912       if(*i<0 || *i>=(int)_fields.size())
9913         {
9914           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9915           throw INTERP_KERNEL::Exception(oss.str().c_str());
9916         }
9917       fields[j]=_fields[*i];
9918     }
9919   ret->_fields=fields;
9920   return ret.retn();
9921 }
9922
9923 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
9924 {
9925   return getFieldAtPos(getPosFromFieldName(fieldName));
9926 }
9927
9928 /*!
9929  * This method removes, if any, fields in \a this having no time steps.
9930  * 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.
9931  * 
9932  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
9933  */
9934 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
9935 {
9936   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
9937   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9938     {
9939       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9940       if(elt)
9941         {
9942           if(elt->getNumberOfTS()>0)
9943             newFields.push_back(*it);
9944         }
9945     }
9946   if(_fields.size()==newFields.size())
9947     return false;
9948   _fields=newFields;
9949   return true;
9950 }
9951
9952 /*!
9953  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9954  * This method can be seen as a filter applied on \a this, that returns an object containing
9955  * 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
9956  * shallow copied from \a this.
9957  * 
9958  * \param [in] meshName - the name of the mesh on w
9959  * \return a new object that the caller should deal with.
9960  */
9961 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
9962 {
9963   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9964   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9965     {
9966       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9967       if(!cur)
9968         continue;
9969       if(cur->getMeshName()==meshName)
9970         {
9971           cur->incrRef();
9972           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9973           ret->_fields.push_back(cur2);
9974         }
9975     }
9976   ret->shallowCpyOnlyUsedGlobs(*this);
9977   return ret.retn();
9978 }
9979
9980 /*!
9981  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9982  * Input time steps are specified using a pair of integer (iteration, order).
9983  * 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,
9984  * but for each multitimestep only the time steps in \a timeSteps are kept.
9985  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9986  * 
9987  * The returned object points to shallow copy of elements in \a this.
9988  * 
9989  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9990  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9991  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9992  */
9993 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
9994 {
9995   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9996   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9997     {
9998       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9999       if(!cur)
10000         continue;
10001       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10002       ret->_fields.push_back(elt);
10003     }
10004   ret->shallowCpyOnlyUsedGlobs(*this);
10005   return ret.retn();
10006 }
10007
10008 /*!
10009  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10010  */
10011 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10012 {
10013   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10014   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10015     {
10016       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10017       if(!cur)
10018         continue;
10019       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10020       if(elt->getNumberOfTS()!=0)
10021         ret->_fields.push_back(elt);
10022     }
10023   ret->shallowCpyOnlyUsedGlobs(*this);
10024   return ret.retn();
10025 }
10026
10027 MEDFileFieldsIterator *MEDFileFields::iterator()
10028 {
10029   return new MEDFileFieldsIterator(this);
10030 }
10031
10032 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10033 {
10034   std::string tmp(fieldName);
10035   std::vector<std::string> poss;
10036   for(std::size_t i=0;i<_fields.size();i++)
10037     {
10038       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10039       if(f)
10040         {
10041           std::string fname(f->getName());
10042           if(tmp==fname)
10043             return i;
10044           else
10045             poss.push_back(fname);
10046         }
10047     }
10048   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10049   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10050   oss << " !";
10051   throw INTERP_KERNEL::Exception(oss.str().c_str());
10052 }
10053
10054 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10055 {
10056   if(fs)
10057     {
10058       fs->incrRef();
10059       _nb_iter=fs->getNumberOfFields();
10060     }
10061 }
10062
10063 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10064 {
10065 }
10066
10067 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10068 {
10069   if(_iter_id<_nb_iter)
10070     {
10071       MEDFileFields *fs(_fs);
10072       if(fs)
10073         return fs->getFieldAtPos(_iter_id++);
10074       else
10075         return 0;
10076     }
10077   else
10078     return 0;
10079 }