Salome HOME
Addition of MEDFileUMesh.__delitem__ in py bindings + LoadSpecificEntities for MEDFil...
[modules/med.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25 #include "MEDFileFieldOverView.hxx"
26
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "MEDCouplingFieldDiscretization.hxx"
29
30 #include "InterpKernelAutoPtr.hxx"
31 #include "CellModel.hxx"
32
33 #include <algorithm>
34 #include <iterator>
35
36 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
37 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
38 extern med_geometry_type typmainoeud[1];
39 extern med_geometry_type typmai3[34];
40
41 using namespace ParaMEDMEM;
42
43 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
44 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
45
46 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
47 {
48   return new MEDFileFieldLoc(fid,locName);
49 }
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
52 {
53   return new MEDFileFieldLoc(fid,id);
54 }
55
56 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
57 {
58   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
59 }
60
61 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
62 {
63   med_geometry_type geotype;
64   med_geometry_type sectiongeotype;
65   int nsectionmeshcell;
66   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
67   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
69   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
70   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
71   _nb_node_per_cell=cm.getNumberOfNodes();
72   _ref_coo.resize(_dim*_nb_node_per_cell);
73   _gs_coo.resize(_dim*_nb_gauss_pt);
74   _w.resize(_nb_gauss_pt);
75   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
76 }
77
78 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
79 {
80   med_geometry_type geotype;
81   med_geometry_type sectiongeotype;
82   int nsectionmeshcell;
83   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
84   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
87   _name=locName;
88   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
89   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
90   _nb_node_per_cell=cm.getNumberOfNodes();
91   _ref_coo.resize(_dim*_nb_node_per_cell);
92   _gs_coo.resize(_dim*_nb_gauss_pt);
93   _w.resize(_nb_gauss_pt);
94   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
95 }
96
97 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
98                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
99                                      _w(w)
100 {
101   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
102   _dim=cm.getDimension();
103   _nb_node_per_cell=cm.getNumberOfNodes();
104   _nb_gauss_pt=_w.size();
105 }
106
107 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
108 {
109   return new MEDFileFieldLoc(*this);
110 }
111
112 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
113 {
114   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
115 }
116
117 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
118 {
119   return std::vector<const BigMemoryObject *>();
120 }
121
122 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
123 {
124   static const char OFF7[]="\n    ";
125   oss << "\"" << _name << "\"" << OFF7;
126   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
127   oss << "Dimension=" << _dim << OFF7;
128   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
129   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
130   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
131   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
132   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
133 }
134
135 void MEDFileFieldLoc::setName(const std::string& name)
136 {
137   _name=name;
138 }
139
140 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
141 {
142   if(_name!=other._name)
143     return false;
144   if(_dim!=other._dim)
145     return false;
146   if(_nb_gauss_pt!=other._nb_gauss_pt)
147     return false;
148   if(_nb_node_per_cell!=other._nb_node_per_cell)
149     return false;
150   if(_geo_type!=other._geo_type)
151     return false;
152   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
153     return false;
154   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
155     return false;
156   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
157     return false;
158
159   return true;
160 }
161
162 void MEDFileFieldLoc::writeLL(med_idt fid) const
163 {
164   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
165 }
166
167 std::string MEDFileFieldLoc::repr() const
168 {
169   std::ostringstream oss; oss.precision(15);
170   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
171   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
172   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
173   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
174   oss << "\n  - Ref coords are : ";
175   int sz=_ref_coo.size();
176   if(sz%_dim==0)
177     {
178       int nbOfTuples=sz/_dim;
179       for(int i=0;i<nbOfTuples;i++)
180         {
181           oss << "(";
182           for(int j=0;j<_dim;j++)
183             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
184           oss << ") ";
185         }
186     }
187   else
188     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
189   oss << "\n  - Gauss coords in reference element : ";
190   sz=_gs_coo.size();
191   if(sz%_dim==0)
192     {
193       int nbOfTuples=sz/_dim;
194       for(int i=0;i<nbOfTuples;i++)
195         {
196           oss << "(";
197           for(int j=0;j<_dim;j++)
198             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
199           oss << ") ";
200         }
201     }
202   else
203     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
204   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
205   return oss.str();
206 }
207
208 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
209 {
210   _type=field->getTypeOfField();
211   _start=start;
212   switch(_type)
213   {
214     case ON_CELLS:
215       {
216         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,offset,offset+nbOfCells,1);
217         _end=_start+nbOfCells;
218         _nval=nbOfCells;
219         break;
220       }
221     case ON_GAUSS_NE:
222       {
223         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
224         const int *arrPtr=arr->getConstPointer();
225         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
226         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
227         _nval=nbOfCells;
228         break;
229       }
230     case ON_GAUSS_PT:
231       {
232         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
233         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
234         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
235         if(!disc2)
236           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
237         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
238         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
239         const int *dai2Ptr=dai2->getConstPointer();
240         int nbi=gsLoc.getWeights().size();
241         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
242         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
243         const int *da3Ptr=da3->getConstPointer();
244         if(da3->getNumberOfTuples()!=nbOfCells)
245           {//profile : for gauss even in NoProfile !!!
246             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
247             _profile=oss.str();
248             da3->setName(_profile.c_str());
249             glob.appendProfile(da3);
250           }
251         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
252         _nval=da3->getNbOfElems();
253         da4->alloc(_nval*nbi,1);
254         int *da4Ptr=da4->getPointer();
255         for(int i=0;i<_nval;i++)
256           {
257             int ref=dai2Ptr[offset+da3Ptr[i]];
258             for(int j=0;j<nbi;j++)
259               *da4Ptr++=ref+j;
260           }
261         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
262         _localization=oss2.str();
263         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
264         _end=_start+_nval*nbi;
265         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
266         break;
267       }
268     default:
269       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
270   }
271   start=_end;
272 }
273
274 /*!
275  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
276  * \param [in] pflName input containing name of profile if any. 0 if no profile (except for GAUSS_PT where a no profile can hide a profile when splitted by loc_id).
277  * \param [in] multiTypePfl is the end user profile specified in high level API
278  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
279  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
280  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
281  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
282  */
283 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
284 {
285   _profile.clear();
286   _type=field->getTypeOfField();
287   std::string pflName(multiTypePfl->getName());
288   std::ostringstream oss; oss << pflName;
289   if(_type!=ON_NODES)
290     {
291       if(!isPflAlone)
292         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
293     }
294   else
295     { oss << "_NODE"; }
296   if(locIds)
297     {
298       if(pflName.empty())
299         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
300       if(_type!=ON_GAUSS_PT)
301         {
302           locIds->setName(oss.str().c_str());
303           glob.appendProfile(locIds);
304           _profile=oss.str();
305         }
306     }
307   _start=start;
308   switch(_type)
309   {
310     case ON_NODES:
311       {
312         _nval=idsInPfl->getNumberOfTuples();
313         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
314         _end=_start+_nval;
315         break;
316       }
317     case ON_CELLS:
318       {
319         _nval=idsInPfl->getNumberOfTuples();
320         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
321         _end=_start+_nval;
322         break;
323       }
324     case ON_GAUSS_NE:
325       {
326         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
327         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
328         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
329         arr3->computeOffsets2();
330         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
331         int trueNval=tmp->getNumberOfTuples();
332         _nval=idsInPfl->getNumberOfTuples();
333         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
334         _end=_start+trueNval;
335         break;
336       }
337     case ON_GAUSS_PT:
338       {
339         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
340         if(!disc2)
341           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
342         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
343         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
344         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
345         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
346         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
347         //
348         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
349         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
350         //
351         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
352         int trueNval=0;
353         for(const int *pt=da4->begin();pt!=da4->end();pt++)
354           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
355         tmp->alloc(trueNval,1);
356         int *tmpPtr=tmp->getPointer();
357         for(const int *pt=da4->begin();pt!=da4->end();pt++)
358           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
359             *tmpPtr++=j;
360         //
361         _nval=da4->getNumberOfTuples();
362         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
363         _end=_start+trueNval;
364         oss << "_loc_" << _loc_id;
365         if(locIds)
366           {
367             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
368             da5->setName(oss.str().c_str());
369             glob.appendProfile(da5);
370             _profile=oss.str();
371           }
372         else
373           {
374             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
375               {
376                 da3->setName(oss.str().c_str());
377                 glob.appendProfile(da3);
378                 _profile=oss.str();
379               }
380           }
381         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
382         _localization=oss2.str();
383         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
384         break;
385       }
386     default:
387       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
388   }
389   start=_end;
390 }
391
392 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
393 {
394   _start=start;
395   _nval=arrr->getNumberOfTuples();
396   getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,_nval,1);
397   _end=_start+_nval;
398   start=_end;
399 }
400
401 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
402 {
403   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
404 }
405
406 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
407 {
408   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
409 }
410
411 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
412 {
413   return new MEDFileFieldPerMeshPerTypePerDisc(other);
414 }
415
416 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
417 {
418   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
419 }
420
421 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
422 {
423   std::vector<const BigMemoryObject *> ret(1);
424   ret[0]=(const PartDefinition*)_pd;
425   return ret;
426 }
427
428 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const
429 {
430   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
431   ret->_father=father;
432   return ret.retn();
433 }
434
435 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
436 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
437 {
438   if(pd)
439     pd->incrRef();
440 }
441 catch(INTERP_KERNEL::Exception& e)
442 {
443     throw e;
444 }
445
446 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
447 {
448 }
449
450 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_profile_it(other._profile_it),_pd(other._pd),_tmp_work1(other._tmp_work1)
451 {
452 }
453
454 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
455     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
456 {
457 }
458
459 void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const std::string& fieldName, int nbOfCompo, int iteration, int order, med_entity_type menti, med_geometry_type mgeoti, unsigned char *startFeedingPtr)
460 {
461   const PartDefinition *pd(_pd);
462   if(!pd)
463     {
464       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
465       int nbi,tmp1;
466       med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
467       if(_end-_start!=nbValsInFile*nbi)
468         {
469           std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
470           throw INTERP_KERNEL::Exception(oss.str().c_str());
471         }
472       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr);
473     }
474   else
475     {
476       if(!_profile.empty())
477         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
478       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
479       int profilesize,nbi;
480       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
481       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
482       if(spd)
483         {
484           int start,stop,step;
485           spd->getSlice(start,stop,step);
486           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
487           med_filter filter=MED_FILTER_INIT;
488           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
489                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
490                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
491                                    /*lastblocksize=useless because count=1*/0,&filter);
492           MEDfieldValueAdvancedRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr);
493           MEDfilterClose(&filter);
494           return ;
495         }
496       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
497       if(dpd)
498         {
499           dpd->checkCoherency();
500           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> myIds(dpd->toDAI());
501           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
502           myIds->applyLin(1,-a);
503           int nbOfEltsToLoad(b-a+1);
504           med_filter filter=MED_FILTER_INIT;
505           {//TODO : manage int32 !
506             MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(DataArrayDouble::New());
507             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
508             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
509                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
510                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
511                                      /*lastblocksize=useless because count=1*/0,&filter);
512             MEDfieldValueAdvancedRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer()));
513             MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> feeder(DataArrayDouble::New());
514             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
515             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
516           }
517           MEDfilterClose(&filter);
518         }
519       else
520         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
521     }
522 }
523
524 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
525 {
526   return _father;
527 }
528
529 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
530 {
531   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
532   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
533   std::string fieldName(nasc.getName()),meshName(getMeshName());
534   int iteration(getIteration()),order(getOrder());
535   TypeOfField type(getType());
536   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
537   int profilesize,nbi;
538   med_geometry_type mgeoti;
539   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
540   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
541   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
542   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
543   const PartDefinition *pd(_pd);
544   if(!pd)
545     {
546       _nval=zeNVal;
547     }
548   else
549     {
550       if(!_profile.empty())
551         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
552       _nval=pd->getNumberOfElems();
553     }
554   _start=start;
555   _end=start+_nval*nbi;
556   start=_end;
557   if(type==ON_CELLS && !_localization.empty())
558     {
559       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
560         setType(ON_GAUSS_PT);
561       else
562         {
563           setType(ON_GAUSS_NE);
564           _localization.clear();
565         }
566     }
567 }
568
569 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
570 {
571   std::string fieldName(nasc.getName()),meshName(getMeshName());
572   int iteration(getIteration()),order(getOrder());
573   TypeOfField type(getType());
574   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
575   med_geometry_type mgeoti;
576   med_entity_type menti(MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti));
577   if(_start>_end)
578     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
579   if(_start==_end)
580     return ;
581   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
582   if(_start<0 || _start>=arr->getNumberOfTuples())
583     {
584       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
585       throw INTERP_KERNEL::Exception(oss.str().c_str());
586     }
587   if(_end<0 || _end>arr->getNumberOfTuples())
588     {
589       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
590       throw INTERP_KERNEL::Exception(oss.str().c_str());
591     }
592   int nbOfCompo(arr->getNumberOfComponents());
593   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
594   if(arrD)
595     {
596       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
597       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
598       return ;
599     }
600   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
601   if(arrI)
602     {
603       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
604       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
605       return ;
606     }
607   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
608 }
609
610 /*!
611  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
612  */
613 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
614 {
615   int delta=_end-_start;
616   _start=newValueOfStart;
617   _end=_start+delta;
618 }
619
620 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
621 {
622   return _father->getIteration();
623 }
624
625 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
626 {
627   return _father->getOrder();
628 }
629
630 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
631 {
632   return _father->getTime();
633 }
634
635 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
636 {
637   return _father->getMeshName();
638 }
639
640 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
641 {
642   const char startLine[]="    ## ";
643   std::string startLine2(bkOffset,' ');
644   startLine2+=startLine;
645   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
646   oss << startLine2 << "Localization #" << id << "." << std::endl;
647   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
648   delete tmp;
649   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
650   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
651   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
652 }
653
654 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
655 {
656   return _type;
657 }
658
659 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
660 {
661   types.insert(_type);
662 }
663
664 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
665 {
666   _type=newType;
667 }
668
669 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
670 {
671   return _father->getGeoType();
672 }
673
674 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
675 {
676   return _father->getNumberOfComponents();
677 }
678
679 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
680 {
681   return _end-_start;
682 }
683
684 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
685 {
686   return _father->getOrCreateAndGetArray();
687 }
688
689 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
690 {
691   const MEDFileFieldPerMeshPerType *fath=_father;
692   return fath->getOrCreateAndGetArray();
693 }
694
695 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
696 {
697   return _father->getInfo();
698 }
699
700 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
701 {
702   return _profile;
703 }
704
705 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
706 {
707   _profile=newPflName;
708 }
709
710 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
711 {
712   return _localization;
713 }
714
715 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
716 {
717   _localization=newLocName;
718 }
719
720 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
721 {
722   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
723     {
724       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
725         {
726           _profile=(*it2).second;
727           return;
728         }
729     }
730 }
731
732 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
733 {
734   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
735     {
736       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
737         {
738           _localization=(*it2).second;
739           return;
740         }
741     }
742 }
743
744 void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
745 {
746   if(type!=_type)
747     return ;
748   dads.push_back(std::pair<int,int>(_start,_end));
749   geoTypes.push_back(getGeoType());
750   if(_profile.empty())
751     pfls.push_back(0);
752   else
753     {
754       pfls.push_back(glob->getProfile(_profile.c_str()));
755     }
756   if(_localization.empty())
757     locs.push_back(-1);
758   else
759     {
760       locs.push_back(glob->getLocalizationId(_localization.c_str()));
761     }
762 }
763
764 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
765 {
766   entries[startEntryId]=std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int> ,std::pair<int,int> >(std::pair<INTERP_KERNEL::NormalizedCellType,int>(getGeoType(),discId),std::pair<int,int>(_start,_end));
767   startEntryId++;
768 }
769
770 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
771 {
772   TypeOfField type=getType();
773   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
774   med_geometry_type mgeoti;
775   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
776   const DataArray *arr=getOrCreateAndGetArray();
777   if(!arr)
778     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
779   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
780   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
781   const unsigned char *locToWrite=0;
782   if(arrD)
783     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
784   else if(arrI)
785     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
786   else
787     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
788   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
789                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
790                              locToWrite);
791 }
792
793 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
794 {
795   type=_type;
796   pfl=_profile;
797   loc=_localization;
798   dad.first=_start; dad.second=_end;
799 }
800
801 /*!
802  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
803  *             This code corresponds to the distribution of types in the corresponding mesh.
804  * \param [out] ptToFill memory zone where the output will be stored.
805  * \return the size of data pushed into output param \a ptToFill
806  */
807 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
808 {
809   _loc_id=offset;
810   std::ostringstream oss;
811   std::size_t nbOfType=codeOfMesh.size()/3;
812   int found=-1;
813   for(std::size_t i=0;i<nbOfType && found==-1;i++)
814     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
815       found=(int)i;
816   if(found==-1)
817     {
818       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
819       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
820       throw INTERP_KERNEL::Exception(oss.str().c_str());
821     }
822   int *work=ptToFill;
823   if(_profile.empty())
824     {
825       if(_nval!=codeOfMesh[3*found+1])
826         {
827           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
828           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
829           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
830           throw INTERP_KERNEL::Exception(oss.str().c_str());
831         }
832       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
833         *work++=ii;
834     }
835   else
836     {
837       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
838       if(pfl->getNumberOfTuples()!=_nval)
839         {
840           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
841           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
842           oss << _nval;
843           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
844           throw INTERP_KERNEL::Exception(oss.str().c_str());
845         }
846       int offset2=codeOfMesh[3*found+2];
847       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
848         {
849           if(*pflId<codeOfMesh[3*found+1])
850             *work++=offset2+*pflId;
851         }
852     }
853   return _nval;
854 }
855
856 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
857 {
858   for(int i=_start;i<_end;i++)
859     *ptToFill++=i;
860   return _end-_start;
861 }
862
863 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
864 {
865   switch(type)
866   {
867     case ON_CELLS:
868       return -2;
869     case ON_GAUSS_NE:
870       return -1;
871     case ON_GAUSS_PT:
872       return locId;
873     default:
874       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
875   }
876 }
877
878 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
879 {
880   int id=0;
881   std::map<std::pair<std::string,TypeOfField>,int> m;
882   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
883   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
884     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
885       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
886   ret.resize(id);
887   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
888     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
889   return ret;
890 }
891
892 /*!
893  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
894  * 
895  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
896  * \param [in] entriesOnSameDisc some entries **on same localization** if not the result can be invalid. The _start and _end on them are relative to \a arr parameter.
897  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
898  * \param [in] newCode one of the input parameter to explicit the new geo type dispatch (in classical format same than those asked by MEDFileFields::renumberEntitiesLyingOnMesh)
899  * \param [in,out] glob if necessary by the method, new profiles can be added to it
900  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
901  * \param [out] result All new entries will be appended on it.
902  * \return false if the configuration of renumbering leads to an unnecessary resplit of input \a entriesOnSameDisc. If not true is returned (the most general case !)
903  */
904 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
905                                                        const DataArrayInt *explicitIdsInMesh,
906                                                        const std::vector<int>& newCode,
907                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
908                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
909 {
910   if(entriesOnSameDisc.empty())
911     return false;
912   TypeOfField type=entriesOnSameDisc[0]->getType();
913   int szEntities=0,szTuples=0;
914   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
915     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
916   int nbi=szTuples/szEntities;
917   if(szTuples%szEntities!=0)
918     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
919   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
920   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
921   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
922   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
923   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
924   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
925   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
926   int id=0;
927   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
928     {
929       int startOfEltIdOfChunk=(*it)->_start;
930       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
931       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
932       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
933       //
934       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
935       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
936       //
937       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
938       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
939     }
940   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
941   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
942   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
943   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
944   //
945   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
946   //
947   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
948   arrPart->renumberInPlace(renumTupleIds->begin());
949   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
950   bool ret=false;
951   const int *idIt=diffVals->begin();
952   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
953   int offset2=0;
954   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
955     {
956       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
957       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
958       int nbEntityElts=subIds->getNumberOfTuples();
959       bool ret2;
960       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
961           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
962                                       offset+offset2,
963                                       li,glob,ret2);
964       ret=ret || ret2;
965       result.push_back(eltToAdd);
966       offset2+=nbEntityElts*nbi;
967     }
968   ret=ret || li.empty();
969   return ret;
970 }
971
972 /*!
973  * \param [in] typeF type of field of new chunk
974  * \param [in] geoType the geometric type of the chunk
975  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
976  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
977  * \param [in] nbi number of integration points
978  * \param [in] offset The offset in the **global array of data**.
979  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
980  *                 to the new chunk to create.
981  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
982  * \param [out] notInExisting If false the return newly allocated entry is not coming from \a entriesOnSameDisc. If true the output comes from copy of \a entriesOnSameDisc
983  *              and corresponding entry erased from \a entriesOnSameDisc.
984  * \return a newly allocated chunk
985  */
986 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
987                                                                                                   bool isPfl, int nbi, int offset,
988                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
989                                                                                                   MEDFileFieldGlobsReal& glob,
990                                                                                                   bool &notInExisting)
991 {
992   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
993   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
994   for(;it!=entriesOnSameDisc.end();it++)
995     {
996       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
997         {
998           if(!isPfl)
999             {
1000               if((*it)->_profile.empty())
1001                 break;
1002               else
1003                 if(!(*it)->_profile.empty())
1004                   {
1005                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1006                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1007                       break;
1008                   }
1009             }
1010         }
1011     }
1012   if(it==entriesOnSameDisc.end())
1013     {
1014       notInExisting=true;
1015       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1016       ret->_type=typeF;
1017       ret->_loc_id=(int)geoType;
1018       ret->_nval=nbMeshEntities;
1019       ret->_start=offset;
1020       ret->_end=ret->_start+ret->_nval*nbi;
1021       if(isPfl)
1022         {
1023           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1024           glob.appendProfile(idsOfMeshElt);
1025           ret->_profile=idsOfMeshElt->getName();
1026         }
1027       //tony treatment of localization
1028       return ret;
1029     }
1030   else
1031     {
1032       notInExisting=false;
1033       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1034       ret->_loc_id=(int)geoType;
1035       ret->setNewStart(offset);
1036       entriesOnSameDisc.erase(it);
1037       return ret;
1038     }
1039
1040 }
1041
1042 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1043 {
1044   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1045 }
1046
1047 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1048 {
1049   return new MEDFileFieldPerMeshPerType(fath,geoType);
1050 }
1051
1052 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
1053 {
1054   return _field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
1055 }
1056
1057 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildrenWithNull() const
1058 {
1059   std::vector<const BigMemoryObject *> ret;
1060   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1061     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1062   return ret;
1063 }
1064
1065 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const
1066 {
1067   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1068   ret->_father=father;
1069   std::size_t i=0;
1070   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1071     {
1072       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1073         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
1074     }
1075   return ret.retn();
1076 }
1077
1078 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1079 {
1080   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1081   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1082     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1083 }
1084
1085 /*!
1086  * This method is the most general one. No optimization is done here.
1087  * \param [in] multiTypePfl is the end user profile specified in high level API
1088  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1089  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
1090  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1091  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1092  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
1093  */
1094 void MEDFileFieldPerMeshPerType::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1095 {
1096   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1097   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1098     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1099 }
1100
1101 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1102 {
1103   _field_pm_pt_pd.resize(1);
1104   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1105   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1106 }
1107
1108 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1109 {
1110   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1111   if(!arr || !arr->isAllocated())
1112     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1113   _field_pm_pt_pd.resize(1);
1114   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1115   _field_pm_pt_pd[0]->assignFieldProfile(true,start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1116 }
1117
1118 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1119 {
1120   TypeOfField type=field->getTypeOfField();
1121   if(type!=ON_GAUSS_PT)
1122     {
1123       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1124       int sz=_field_pm_pt_pd.size();
1125       bool found=false;
1126       for(int j=0;j<sz && !found;j++)
1127         {
1128           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1129             {
1130               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1131               found=true;
1132             }
1133         }
1134       if(!found)
1135         {
1136           _field_pm_pt_pd.resize(sz+1);
1137           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1138         }
1139       std::vector<int> ret(1,(int)sz);
1140       return ret;
1141     }
1142   else
1143     {
1144       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1145       int sz2=ret2.size();
1146       std::vector<int> ret3(sz2);
1147       int k=0;
1148       for(int i=0;i<sz2;i++)
1149         {
1150           int sz=_field_pm_pt_pd.size();
1151           int locIdToFind=ret2[i];
1152           bool found=false;
1153           for(int j=0;j<sz && !found;j++)
1154             {
1155               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1156                 {
1157                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1158                   ret3[k++]=j;
1159                   found=true;
1160                 }
1161             }
1162           if(!found)
1163             {
1164               _field_pm_pt_pd.resize(sz+1);
1165               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1166               ret3[k++]=sz;
1167             }
1168         }
1169       return ret3;
1170     }
1171 }
1172
1173 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1174 {
1175   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1176   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1177   if(!disc2)
1178     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1179   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1180   if(!da)
1181     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1182   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1183   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1184   if(retTmp->presenceOfValue(-1))
1185     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1186   std::vector<int> ret(retTmp->begin(),retTmp->end());
1187   return ret;
1188 }
1189
1190 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1191 {
1192   TypeOfField type=field->getTypeOfField();
1193   if(type!=ON_GAUSS_PT)
1194     {
1195       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1196       int sz=_field_pm_pt_pd.size();
1197       bool found=false;
1198       for(int j=0;j<sz && !found;j++)
1199         {
1200           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1201             {
1202               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1203               found=true;
1204             }
1205         }
1206       if(!found)
1207         {
1208           _field_pm_pt_pd.resize(sz+1);
1209           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1210         }
1211       std::vector<int> ret(1,0);
1212       return ret;
1213     }
1214   else
1215     {
1216       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1217       int sz2=ret2.size();
1218       std::vector<int> ret3(sz2);
1219       int k=0;
1220       for(int i=0;i<sz2;i++)
1221         {
1222           int sz=_field_pm_pt_pd.size();
1223           int locIdToFind=ret2[i];
1224           bool found=false;
1225           for(int j=0;j<sz && !found;j++)
1226             {
1227               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1228                 {
1229                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1230                   ret3[k++]=j;
1231                   found=true;
1232                 }
1233             }
1234           if(!found)
1235             {
1236               _field_pm_pt_pd.resize(sz+1);
1237               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1238               ret3[k++]=sz;
1239             }
1240         }
1241       return ret3;
1242     }
1243 }
1244
1245 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1246 {
1247   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1248   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1249   if(!disc2)
1250     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1251   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1252   if(!da)
1253     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1254   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1255   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1256   if(retTmp->presenceOfValue(-1))
1257     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1258   std::vector<int> ret(retTmp->begin(),retTmp->end());
1259   return ret;
1260 }
1261
1262 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1263 {
1264   return _father;
1265 }
1266
1267 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1268 {
1269   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1270   int curDim=(int)cm.getDimension();
1271   dim=std::max(dim,curDim);
1272 }
1273
1274 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1275 {
1276   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1277     {
1278       (*it)->fillTypesOfFieldAvailable(types);
1279     }
1280 }
1281
1282 void MEDFileFieldPerMeshPerType::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1283 {
1284   int sz=_field_pm_pt_pd.size();
1285   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1286   for(int i=0;i<sz;i++)
1287     {
1288       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1289     }
1290 }
1291
1292 int MEDFileFieldPerMeshPerType::getIteration() const
1293 {
1294   return _father->getIteration();
1295 }
1296
1297 int MEDFileFieldPerMeshPerType::getOrder() const
1298 {
1299   return _father->getOrder();
1300 }
1301
1302 double MEDFileFieldPerMeshPerType::getTime() const
1303 {
1304   return _father->getTime();
1305 }
1306
1307 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1308 {
1309   return _father->getMeshName();
1310 }
1311
1312 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1313 {
1314   const char startLine[]="  ## ";
1315   std::string startLine2(bkOffset,' ');
1316   std::string startLine3(startLine2);
1317   startLine3+=startLine;
1318   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1319     {
1320       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1321       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1322     }
1323   else
1324     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1325   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1326   int i=0;
1327   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1328     {
1329       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1330       if(cur)
1331         cur->simpleRepr(bkOffset,oss,i);
1332       else
1333         {
1334           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1335         }
1336     }
1337 }
1338
1339 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1340 {
1341   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1342     {
1343       globalSz+=(*it)->getNumberOfTuples();
1344     }
1345   nbOfEntries+=(int)_field_pm_pt_pd.size();
1346 }
1347
1348 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1349 {
1350   return _geo_type;
1351 }
1352
1353
1354 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1355 {
1356   return _father->getNumberOfComponents();
1357 }
1358
1359 bool MEDFileFieldPerMeshPerType::presenceOfMultiDiscPerGeoType() const
1360 {
1361   std::size_t nb(0);
1362   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1363     {
1364       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1365       if(fmtd)
1366         nb++;
1367     }
1368   return nb>1;
1369 }
1370
1371 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1372 {
1373   return _father->getOrCreateAndGetArray();
1374 }
1375
1376 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1377 {
1378   const MEDFileFieldPerMesh *fath=_father;
1379   return fath->getOrCreateAndGetArray();
1380 }
1381
1382 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1383 {
1384   return _father->getInfo();
1385 }
1386
1387 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1388 {
1389   std::vector<std::string> ret;
1390   std::set<std::string> ret2;
1391   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1392     {
1393       std::string tmp=(*it1)->getProfile();
1394       if(!tmp.empty())
1395         if(ret2.find(tmp)==ret2.end())
1396           {
1397             ret.push_back(tmp);
1398             ret2.insert(tmp);
1399           }
1400     }
1401   return ret;
1402 }
1403
1404 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1405 {
1406   std::vector<std::string> ret;
1407   std::set<std::string> ret2;
1408   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1409     {
1410       std::string tmp=(*it1)->getLocalization();
1411       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1412         if(ret2.find(tmp)==ret2.end())
1413           {
1414             ret.push_back(tmp);
1415             ret2.insert(tmp);
1416           }
1417     }
1418   return ret;
1419 }
1420
1421 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1422 {
1423   std::vector<std::string> ret;
1424   std::set<std::string> ret2;
1425   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1426     {
1427       std::string tmp=(*it1)->getProfile();
1428       if(!tmp.empty())
1429         ret.push_back(tmp);
1430     }
1431   return ret;
1432 }
1433
1434 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1435 {
1436   std::vector<std::string> ret;
1437   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1438     {
1439       std::string tmp=(*it1)->getLocalization();
1440       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1441         ret.push_back(tmp);
1442     }
1443   return ret;
1444 }
1445
1446 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1447 {
1448   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1449     (*it1)->changePflsRefsNamesGen(mapOfModif);
1450 }
1451
1452 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1453 {
1454   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1455     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1456 }
1457
1458 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1459 {
1460   if(_field_pm_pt_pd.empty())
1461     {
1462       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1463       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1464       throw INTERP_KERNEL::Exception(oss.str().c_str());
1465     }
1466   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1467     return _field_pm_pt_pd[locId];
1468   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1469   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1470   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1471   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1472   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1473 }
1474
1475 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1476 {
1477   if(_field_pm_pt_pd.empty())
1478     {
1479       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1480       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1481       throw INTERP_KERNEL::Exception(oss.str().c_str());
1482     }
1483   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1484     return _field_pm_pt_pd[locId];
1485   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1486   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1487   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1488   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1489   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1490 }
1491
1492 void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1493 {
1494   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1495     {
1496       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1497       if(meshDim!=(int)cm.getDimension())
1498         return ;
1499     }
1500   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1501     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1502 }
1503
1504 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1505 {
1506   int i=0;
1507   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1508     {
1509       (*it)->fillValues(i,startEntryId,entries);
1510     }
1511 }
1512
1513 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1514 {
1515   _field_pm_pt_pd=leaves;
1516   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1517     (*it)->setFather(this);
1518 }
1519
1520 /*!
1521  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1522  *  \param [out] its - list of pair (start,stop) kept
1523  *  \return bool - false if the type of field \a tof is not contained in \a this.
1524  */
1525 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1526 {
1527   bool ret(false);
1528   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1529   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1530     if((*it)->getType()==tof)
1531       {
1532         newPmPtPd.push_back(*it);
1533         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1534         (*it)->setNewStart(globalNum);
1535         globalNum=(*it)->getEnd();
1536         its.push_back(bgEnd);
1537         ret=true;
1538       }
1539   if(ret)
1540     _field_pm_pt_pd=newPmPtPd;
1541   return ret;
1542 }
1543
1544 /*!
1545  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1546  *  \param [out] its - list of pair (start,stop) kept
1547  *  \return bool - false if the type of field \a tof is not contained in \a this.
1548  */
1549 bool MEDFileFieldPerMeshPerType::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1550 {
1551   if(_field_pm_pt_pd.size()<=idOfDisc)
1552     return false;
1553   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1554   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1555   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1556   elt->setNewStart(globalNum);
1557   globalNum=elt->getEnd();
1558   its.push_back(bgEnd);
1559   _field_pm_pt_pd=newPmPtPd;
1560   return true;
1561 }
1562
1563 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1564 {
1565 }
1566
1567 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):_father(fath),_geo_type(geoType)
1568 {
1569   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1570   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1571   med_geometry_type mgeoti;
1572   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1573   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1574   _field_pm_pt_pd.resize(nbProfiles);
1575   for(int i=0;i<nbProfiles;i++)
1576     {
1577       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1578     }
1579   if(type==ON_CELLS)
1580     {
1581       int nbProfiles2=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName);
1582       for(int i=0;i<nbProfiles2;i++)
1583         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1584     }
1585 }
1586
1587 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1588 {
1589   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1590     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1591 }
1592
1593 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1594 {
1595   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1596     (*it)->loadBigArray(fid,nasc);
1597 }
1598
1599 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1600 {
1601   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1602     {
1603       (*it)->copyOptionsFrom(*this);
1604       (*it)->writeLL(fid,nasc);
1605     }
1606 }
1607
1608 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1609 {
1610   switch(ikType)
1611   {
1612     case ON_CELLS:
1613       medfGeoType=typmai3[(int)ikGeoType];
1614       return MED_CELL;
1615     case ON_NODES:
1616       medfGeoType=MED_NONE;
1617       return MED_NODE;
1618     case ON_GAUSS_NE:
1619       medfGeoType=typmai3[(int)ikGeoType];
1620       return MED_NODE_ELEMENT;
1621     case ON_GAUSS_PT:
1622       medfGeoType=typmai3[(int)ikGeoType];
1623       return MED_CELL;
1624     default:
1625       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1626   }
1627   return MED_UNDEF_ENTITY_TYPE;
1628 }
1629
1630 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
1631 {
1632   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1633 }
1634
1635 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1636 {
1637   return new MEDFileFieldPerMesh(fath,mesh);
1638 }
1639
1640 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1641 {
1642   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1643 }
1644
1645 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1646 {
1647   std::vector<const BigMemoryObject *> ret;
1648   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1649     ret.push_back((const MEDFileFieldPerMeshPerType *)*it);
1650   return ret;
1651 }
1652
1653 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1654 {
1655   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1656   ret->_father=father;
1657   std::size_t i=0;
1658   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1659     {
1660       if((const MEDFileFieldPerMeshPerType *)*it)
1661         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1662     }
1663   return ret.retn();
1664 }
1665
1666 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1667 {
1668   std::string startLine(bkOffset,' ');
1669   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1670   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1671   int i=0;
1672   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1673     {
1674       const MEDFileFieldPerMeshPerType *cur=*it;
1675       if(cur)
1676         cur->simpleRepr(bkOffset,oss,i);
1677       else
1678         {
1679           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1680         }
1681     }
1682 }
1683
1684 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1685 {
1686   _mesh_name=mesh->getName();
1687   mesh->getTime(_mesh_iteration,_mesh_order);
1688 }
1689
1690 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1691 {
1692   int nbOfTypes=code.size()/3;
1693   int offset=0;
1694   for(int i=0;i<nbOfTypes;i++)
1695     {
1696       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1697       int nbOfCells=code[3*i+1];
1698       int pos=addNewEntryIfNecessary(type);
1699       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1700       offset+=nbOfCells;
1701     }
1702 }
1703
1704 /*!
1705  * This method is the most general one. No optimization is done here.
1706  * \param [in] multiTypePfl is the end user profile specified in high level API
1707  * \param [in] code is the code of \a mesh[multiTypePfl] mesh. It is of size of number of different geometric types into \a mesh[multiTypePfl].
1708  * \param [in] code2 is the code of the \b WHOLE mesh on the same level. So all types in \a code are in \a code2.
1709  * \param [in] idsInPflPerType is the selection into the \a multiTypePfl whole profile that corresponds to the given geometric type. This vector is always 3 times smaller than \a code.
1710  * \param [in] idsPerType is a vector containing the profiles needed to be created for MED file format. \b WARNING these processed MED file profiles can be subdivided again in case of Gauss points.
1711  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
1712  */
1713 void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector<int>& code, const std::vector<int>& code2, const std::vector<DataArrayInt *>& idsInPflPerType, const std::vector<DataArrayInt *>& idsPerType, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1714 {
1715   int nbOfTypes(code.size()/3);
1716   for(int i=0;i<nbOfTypes;i++)
1717     {
1718       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1719       int pos=addNewEntryIfNecessary(type);
1720       DataArrayInt *pfl=0;
1721       if(code[3*i+2]!=-1)
1722         pfl=idsPerType[code[3*i+2]];
1723       int nbOfTupes2=code2.size()/3;
1724       int found=0;
1725       for(;found<nbOfTupes2;found++)
1726         if(code[3*i]==code2[3*found])
1727           break;
1728       if(found==nbOfTupes2)
1729         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1730       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1731     }
1732 }
1733
1734 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1735 {
1736   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1737   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1738 }
1739
1740 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1741 {
1742   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1743   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1744 }
1745
1746 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1747 {
1748   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1749     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1750 }
1751
1752 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1753 {
1754   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1755     (*it)->loadBigArraysRecursively(fid,nasc);
1756 }
1757
1758 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1759 {
1760   int nbOfTypes=_field_pm_pt.size();
1761   for(int i=0;i<nbOfTypes;i++)
1762     {
1763       _field_pm_pt[i]->copyOptionsFrom(*this);
1764       _field_pm_pt[i]->writeLL(fid,nasc);
1765     }
1766 }
1767
1768 void MEDFileFieldPerMesh::getDimension(int& dim) const
1769 {
1770   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1771     (*it)->getDimension(dim);
1772 }
1773
1774 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1775 {
1776   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1777     (*it)->fillTypesOfFieldAvailable(types);
1778 }
1779
1780 std::vector< std::vector< std::pair<int,int> > > MEDFileFieldPerMesh::getFieldSplitedByType(std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF, std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> > & locs) const
1781 {
1782   int sz=_field_pm_pt.size();
1783   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1784   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1785   for(int i=0;i<sz;i++)
1786     {
1787       types[i]=_field_pm_pt[i]->getGeoType();
1788       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1789     }
1790   return ret;
1791 }
1792
1793 double MEDFileFieldPerMesh::getTime() const
1794 {
1795   int tmp1,tmp2;
1796   return _father->getTime(tmp1,tmp2);
1797 }
1798
1799 int MEDFileFieldPerMesh::getIteration() const
1800 {
1801   return _father->getIteration();
1802 }
1803
1804 int MEDFileFieldPerMesh::getOrder() const
1805 {
1806   return _father->getOrder();
1807 }
1808
1809 int MEDFileFieldPerMesh::getNumberOfComponents() const
1810 {
1811   return _father->getNumberOfComponents();
1812 }
1813
1814 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1815 {
1816   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1817     {
1818       const MEDFileFieldPerMeshPerType *fpmt(*it);
1819       if(!fpmt)
1820         continue;
1821       if(fpmt->presenceOfMultiDiscPerGeoType())
1822         return true;
1823     }
1824   return false;
1825 }
1826
1827 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1828 {
1829   if(!_father)
1830     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1831   return _father->getOrCreateAndGetArray();
1832 }
1833
1834 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1835 {
1836   if(!_father)
1837     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1838   return _father->getOrCreateAndGetArray();
1839 }
1840
1841 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1842 {
1843   return _father->getInfo();
1844 }
1845
1846 /*!
1847  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1848  * Before the call of this method 'geoTypes','dads','pfls','locs' must be reorganized so that types in geoTypes are contiguous and ordered following typmai2 array.
1849  * It returns 2 output vectors :
1850  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1851  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1852  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1853  */
1854 void MEDFileFieldPerMesh::SortArraysPerType(const MEDFileFieldGlobsReal *glob, TypeOfField type, const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes, const std::vector< std::pair<int,int> >& dads, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& locs, std::vector<int>& code, std::vector<DataArrayInt *>& notNullPfls)
1855 {
1856   int notNullPflsSz=0;
1857   int nbOfArrs=geoTypes.size();
1858   for(int i=0;i<nbOfArrs;i++)
1859     if(pfls[i])
1860       notNullPflsSz++;
1861   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1862   int nbOfDiffGeoTypes=geoTypes3.size();
1863   code.resize(3*nbOfDiffGeoTypes);
1864   notNullPfls.resize(notNullPflsSz);
1865   notNullPflsSz=0;
1866   int j=0;
1867   for(int i=0;i<nbOfDiffGeoTypes;i++)
1868     {
1869       int startZone=j;
1870       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1871       std::vector<const DataArrayInt *> notNullTmp;
1872       if(pfls[j])
1873         notNullTmp.push_back(pfls[j]);
1874       j++;
1875       for(;j<nbOfArrs;j++)
1876         if(geoTypes[j]==refType)
1877           {
1878             if(pfls[j])
1879               notNullTmp.push_back(pfls[j]);
1880           }
1881         else
1882           break;
1883       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1884       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1885       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1886       code[3*i]=(int)refType;
1887       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1888       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1889       if(notNullTmp.empty())
1890         code[3*i+2]=-1;
1891       else
1892         {
1893           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1894           code[3*i+2]=notNullPflsSz++;
1895         }
1896     }
1897 }
1898
1899 /*!
1900  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1901  */
1902 int MEDFileFieldPerMesh::ComputeNbOfElems(const MEDFileFieldGlobsReal *glob, TypeOfField type, const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes, const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs)
1903 {
1904   int sz=dads.size();
1905   int ret=0;
1906   for(int i=0;i<sz;i++)
1907     {
1908       if(locs[i]==-1)
1909         {
1910           if(type!=ON_GAUSS_NE)
1911             ret+=dads[i].second-dads[i].first;
1912           else
1913             {
1914               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1915               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1916             }
1917         }
1918       else
1919         {
1920           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1921           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1922         }
1923     }
1924   return ret;
1925 }
1926
1927 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1928 {
1929   std::vector<std::string> ret;
1930   std::set<std::string> ret2;
1931   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1932     {
1933       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1934       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1935         if(ret2.find(*it2)==ret2.end())
1936           {
1937             ret.push_back(*it2);
1938             ret2.insert(*it2);
1939           }
1940     }
1941   return ret;
1942 }
1943
1944 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1945 {
1946   std::vector<std::string> ret;
1947   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1948     {
1949       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1950       ret.insert(ret.end(),tmp.begin(),tmp.end());
1951     }
1952   return ret;
1953 }
1954
1955 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1956 {
1957   std::vector<std::string> ret;
1958   std::set<std::string> ret2;
1959   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1960     {
1961       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1962       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1963         if(ret2.find(*it2)==ret2.end())
1964           {
1965             ret.push_back(*it2);
1966             ret2.insert(*it2);
1967           }
1968     }
1969   return ret;
1970 }
1971
1972 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1973 {
1974   std::vector<std::string> ret;
1975   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1976     {
1977       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1978       ret.insert(ret.end(),tmp.begin(),tmp.end());
1979     }
1980   return ret;
1981 }
1982
1983 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1984 {
1985   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1986     {
1987       if((*it).first==_mesh_name)
1988         {
1989           _mesh_name=(*it).second;
1990           return true;
1991         }
1992     }
1993   return false;
1994 }
1995
1996 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1997                                                       MEDFileFieldGlobsReal& glob)
1998 {
1999   if(_mesh_name!=meshName)
2000     return false;
2001   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2002   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2003   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2004   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2005   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2006   getUndergroundDataArrayExt(entries);
2007   DataArray *arr0=getOrCreateAndGetArray();//tony
2008   if(!arr0)
2009     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2010   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
2011   if(!arr0)
2012     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2013   int sz=0;
2014   if(!arr)
2015     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2016   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2017     {
2018       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2019         {
2020           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2021           sz+=(*it).second.second-(*it).second.first;
2022         }
2023       else
2024         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2025     }
2026   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2027   ////////////////////
2028   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2029   int *workI2=explicitIdsOldInMesh->getPointer();
2030   int sz1=0,sz2=0,sid=1;
2031   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2032   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2033   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2034     {
2035       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2036       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2037       int *workI=explicitIdsOldInArr->getPointer();
2038       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2039         {
2040           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2041           (*itL2)->setLocId(sz2);
2042           (*itL2)->_tmp_work1=(*itL2)->getStart();
2043           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2044         }
2045       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2046     }
2047   explicitIdsOldInMesh->reAlloc(sz2);
2048   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2049   ////////////////////
2050   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2051   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2052   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2053   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2054     {
2055       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2056       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2057       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2058     }
2059   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2060   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2061   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2062     {
2063       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2064       int newStart=elt->getLocId();
2065       elt->setLocId((*it)->getGeoType());
2066       elt->setNewStart(newStart);
2067       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2068       entriesKeptNew.push_back(elt);
2069       entriesKeptNew2.push_back(elt);
2070     }
2071   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2072   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2073   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2074   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2075   bool ret=false;
2076   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2077     {
2078       sid=0;
2079       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2080         {
2081           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2082           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2083           }*/
2084       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2085                                                             glob,arr2,otherEntriesNew) || ret;
2086     }
2087   if(!ret)
2088     return false;
2089   // Assign new dispatching
2090   assignNewLeaves(otherEntriesNew);
2091   arr->cpyFrom(*arr2);
2092   return true;
2093 }
2094
2095 /*!
2096  * \param [in,out] globalNum a global numbering counter for the renumbering.
2097  * \param [out] its - list of pair (start,stop) kept
2098  */
2099 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2100 {
2101   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2102   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2103     {
2104       std::vector< std::pair<int,int> > its2;
2105       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2106         {
2107           ret.push_back(*it);
2108           its.insert(its.end(),its2.begin(),its2.end());
2109         }
2110     }
2111   _field_pm_pt=ret;
2112 }
2113
2114 /*!
2115  * \param [in,out] globalNum a global numbering counter for the renumbering.
2116  * \param [out] its - list of pair (start,stop) kept
2117  */
2118 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2119 {
2120   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2121   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2122     {
2123       std::vector< std::pair<int,int> > its2;
2124       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2125         {
2126           ret.push_back(*it);
2127           its.insert(its.end(),its2.begin(),its2.end());
2128         }
2129     }
2130   _field_pm_pt=ret;
2131 }
2132
2133 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2134 {
2135   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2136   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2137     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2138   //
2139   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2140   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2141   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2142   for(;it1!=types.end();it1++,it2++)
2143     {
2144       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2145       elt->setLeaves((*it1).second);
2146       *it2=elt;
2147     }
2148   _field_pm_pt=fieldPmPt;
2149 }
2150
2151 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2152 {
2153   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2154     (*it)->changePflsRefsNamesGen(mapOfModif);
2155 }
2156
2157 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2158 {
2159   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2160     (*it)->changeLocsRefsNamesGen(mapOfModif);
2161 }
2162
2163 /*!
2164  * \param [in] mesh is the whole mesh
2165  */
2166 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2167 {
2168   if(_field_pm_pt.empty())
2169     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2170   //
2171   std::vector< std::pair<int,int> > dads;
2172   std::vector<const DataArrayInt *> pfls;
2173   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2174   std::vector<int> locs,code;
2175   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2176   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2177     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2178   // Sort by types
2179   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2180   if(code.empty())
2181     {
2182       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2183       throw INTERP_KERNEL::Exception(oss.str().c_str());
2184     }
2185   //
2186   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2187   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2188   if(type!=ON_NODES)
2189     {
2190       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2191       if(!arr)
2192         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2193       else
2194         {
2195           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2196           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2197         }
2198     }
2199   else
2200     {
2201       if(code.size()!=3)
2202         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2203       int nb=code[1];
2204       if(code[2]==-1)
2205         {
2206           if(nb!=mesh->getNumberOfNodes())
2207             {
2208               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2209               oss << " nodes in mesh !";
2210               throw INTERP_KERNEL::Exception(oss.str().c_str());
2211             }
2212           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2213         }
2214       else
2215         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2216     }
2217 }
2218
2219 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2220 {
2221   if(_field_pm_pt.empty())
2222     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2223   //
2224   std::vector<std::pair<int,int> > dads;
2225   std::vector<const DataArrayInt *> pfls;
2226   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2227   std::vector<int> locs,code;
2228   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2229   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2230     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2231   // Sort by types
2232   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2233   if(code.empty())
2234     {
2235       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2236       throw INTERP_KERNEL::Exception(oss.str().c_str());
2237     }
2238   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2239   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2240   if(type!=ON_NODES)
2241     {
2242       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2243       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2244     }
2245   else
2246     {
2247       if(code.size()!=3)
2248         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2249       int nb=code[1];
2250       if(code[2]==-1)
2251         {
2252           if(nb!=mesh->getNumberOfNodes())
2253             {
2254               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2255               oss << " nodes in mesh !";
2256               throw INTERP_KERNEL::Exception(oss.str().c_str());
2257             }
2258         }
2259       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2260     }
2261   //
2262   return 0;
2263 }
2264
2265 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2266 {
2267   int globalSz=0;
2268   int nbOfEntries=0;
2269   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2270     {
2271       (*it)->getSizes(globalSz,nbOfEntries);
2272     }
2273   entries.resize(nbOfEntries);
2274   nbOfEntries=0;
2275   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2276     {
2277       (*it)->fillValues(nbOfEntries,entries);
2278     }
2279 }
2280
2281 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2282 {
2283   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2284     {
2285       if((*it)->getGeoType()==typ)
2286         return (*it)->getLeafGivenLocId(locId);
2287     }
2288   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2289   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2290   oss << "Possiblities are : ";
2291   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2292     {
2293       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2294       oss << "\"" << cm2.getRepr() << "\", ";
2295     }
2296   throw INTERP_KERNEL::Exception(oss.str().c_str());
2297 }
2298
2299 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2300 {
2301   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2302     {
2303       if((*it)->getGeoType()==typ)
2304         return (*it)->getLeafGivenLocId(locId);
2305     }
2306   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2307   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2308   oss << "Possiblities are : ";
2309   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2310     {
2311       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2312       oss << "\"" << cm2.getRepr() << "\", ";
2313     }
2314   throw INTERP_KERNEL::Exception(oss.str().c_str());
2315 }
2316
2317 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2318 {
2319   int i=0;
2320   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2321   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2322   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2323     {
2324       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2325       if(type==curType)
2326         return i;
2327       else
2328         {
2329           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2330           if(pos>pos2)
2331             it2=it+1;
2332         }
2333     }
2334   int ret=std::distance(_field_pm_pt.begin(),it2);
2335   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2336   return ret;
2337 }
2338
2339 /*!
2340  * 'dads' and 'locs' input parameters have the same number of elements
2341  * \param [in] mesh is \b NOT the global mesh, but the possibly reduced mesh. \a mesh parameter will be directly aggregated in the returned field
2342  */
2343 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2344                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2345                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2346 {
2347   isPfl=false;
2348   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2349   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2350   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2351   const std::vector<std::string>& infos=getInfo();
2352   da->setInfoOnComponents(infos);
2353   da->setName("");
2354   if(type==ON_GAUSS_PT)
2355     {
2356       int offset=0;
2357       int nbOfArrs=dads.size();
2358       for(int i=0;i<nbOfArrs;i++)
2359         {
2360           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2361           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2362           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2363           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2364           di->alloc(nbOfElems,1);
2365           di->iota(offset);
2366           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2367           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2368           offset+=nbOfElems;
2369         }
2370     }
2371   arrOut=da;
2372   return ret.retn();
2373 }
2374
2375 /*!
2376  * This method is an extension of MEDFileFieldPerMesh::finishField method. It deals with profiles. This method should be called when type is different from ON_NODES.
2377  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2378  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2379  * The order of cells in the returned field is those imposed by the profile.
2380  * \param [in] mesh is the global mesh.
2381  */
2382 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2383                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2384                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2385                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2386 {
2387   if(da->isIdentity())
2388     {
2389       int nbOfTuples=da->getNumberOfTuples();
2390       if(nbOfTuples==mesh->getNumberOfCells())
2391         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2392     }
2393   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2394   m2->setName(mesh->getName().c_str());
2395   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2396   isPfl=true;
2397   return ret.retn();
2398 }
2399
2400 /*!
2401  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2402  */
2403 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2404                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2405                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2406 {
2407   if(da->isIdentity())
2408     {
2409       int nbOfTuples=da->getNumberOfTuples();
2410       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2411         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2412     }
2413   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2414   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2415   if(meshu)
2416     {
2417       if(meshu->getNodalConnectivity()==0)
2418         {
2419           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2420           int nb=da->getNbOfElems();
2421           const int *ptr=da->getConstPointer();
2422           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2423           meshuc->allocateCells(nb);
2424           for(int i=0;i<nb;i++)
2425             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2426           meshuc->finishInsertingCells();
2427           ret->setMesh(meshuc);
2428           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2429           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2430           disc->checkCoherencyBetween(meshuc,arrOut);
2431           return ret.retn();
2432         }
2433     }
2434   //
2435   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2436   isPfl=true;
2437   DataArrayInt *arr2=0;
2438   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2439   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2440   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2441   int nnodes=mesh2->getNumberOfNodes();
2442   if(nnodes==(int)da->getNbOfElems())
2443     {
2444       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2445       arrOut->renumberInPlace(da3->getConstPointer());
2446       mesh2->setName(mesh->getName().c_str());
2447       ret->setMesh(mesh2);
2448       return ret.retn();
2449     }
2450   else
2451     {
2452       std::ostringstream oss; oss << "MEDFileFieldPerMesh::finishFieldNode2 : The field on nodes lies on a node profile so that it is impossible to find a submesh having exactly the same nodes of that profile !!!";
2453       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2454       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2455       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2456       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2457       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2458       throw INTERP_KERNEL::Exception(oss.str().c_str());
2459     }
2460   return 0;
2461 }
2462
2463 /*!
2464  * This method is the most light method of field retrieving.
2465  */
2466 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2467 {
2468   if(!pflIn)
2469     {
2470       pflOut=DataArrayInt::New();
2471       pflOut->alloc(nbOfElems,1);
2472       pflOut->iota(0);
2473     }
2474   else
2475     {
2476       pflOut=const_cast<DataArrayInt*>(pflIn);
2477       pflOut->incrRef();
2478     }
2479   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2480   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2481   const std::vector<std::string>& infos=getInfo();
2482   int nbOfComp=infos.size();
2483   for(int i=0;i<nbOfComp;i++)
2484     da->setInfoOnComponent(i,infos[i].c_str());
2485   safePfl->incrRef();
2486   return da.retn();
2487 }
2488
2489
2490 /// @cond INTERNAL
2491
2492 class MFFPMIter
2493 {
2494 public:
2495   static MFFPMIter *NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2496   static bool IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities);
2497   virtual ~MFFPMIter() { }
2498   virtual void begin() = 0;
2499   virtual bool finished() const = 0;
2500   virtual void next() = 0;
2501   virtual int current() const = 0;
2502 };
2503
2504 class MFFPMIterSimple : public MFFPMIter
2505 {
2506 public:
2507   MFFPMIterSimple():_pos(0) { }
2508   void begin() { _pos=0; }
2509   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2510   void next() { _pos++; }
2511   int current() const { return _pos; }
2512 private:
2513   int _pos;
2514 };
2515
2516 class MFFPMIter2 : public MFFPMIter
2517 {
2518 public:
2519   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2520   void begin() { _it=_ids.begin(); }
2521   bool finished() const { return _it==_ids.end(); }
2522   void next() { _it++; }
2523   int current() const { return *_it; }
2524 private:
2525   std::vector<int> _ids;
2526   std::vector<int>::const_iterator _it;
2527 };
2528
2529 MFFPMIter *MFFPMIter::NewCell(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2530 {
2531   if(!entities)
2532     return new MFFPMIterSimple;
2533   else
2534     {
2535       std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2536       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2537         {
2538           if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2539             tmp.push_back((*it).second);
2540         }
2541       return new MFFPMIter2(tmp);
2542     }
2543 }
2544
2545 bool MFFPMIter::IsPresenceOfNode(const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
2546 {
2547   if(!entities)
2548     return true;
2549   else
2550     {
2551       for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=(*entities).begin();it!=(*entities).end();it++)
2552         if((*it).first==ON_NODES)
2553           return true;
2554       return false;
2555     }
2556 }
2557
2558 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2559 {
2560   std::size_t sz(cts.size());
2561   _ids.resize(sz);
2562   for(std::size_t i=0;i<sz;i++)
2563     {
2564       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2565       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2566         _ids[i]=(int)std::distance(typmai2,loc);
2567       else
2568         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2569     }
2570 }
2571
2572 /// @cond INTERNAL
2573
2574 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2575     _father(fath)
2576 {
2577   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2578   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2579   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2580   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2581   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2582   for(iter0->begin();!iter0->finished();iter0->next())
2583     {
2584       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2585       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2586       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2587       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2588       if(nbProfile>0 || nbProfile2>0)
2589         {
2590           const PartDefinition *pd(0);
2591           if(mmu)
2592             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2593           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2594           if(nbProfile>0)
2595             _mesh_name=name0;
2596           else
2597             _mesh_name=name1;
2598         }
2599     }
2600   if(MFFPMIter::IsPresenceOfNode(entities))
2601     {
2602       int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName);
2603       if(nbProfile>0)
2604         {
2605           const PartDefinition *pd(0);
2606           if(mmu)
2607             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2608           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2609           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2610         }
2611     }
2612 }
2613
2614 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2615 {
2616   copyTinyInfoFrom(mesh);
2617 }
2618
2619 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2620 {
2621   if(id>=(int)_pfls.size())
2622     _pfls.resize(id+1);
2623   _pfls[id]=DataArrayInt::New();
2624   int lgth=MEDprofileSizeByName(fid,pflName.c_str());
2625   _pfls[id]->setName(pflName);
2626   _pfls[id]->alloc(lgth,1);
2627   MEDprofileRd(fid,pflName.c_str(),_pfls[id]->getPointer());
2628   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2629 }
2630
2631 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2632 {
2633   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2634   int sz;
2635   MEDprofileInfo(fid,i+1,pflName,&sz);
2636   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2637   if(i>=(int)_pfls.size())
2638     _pfls.resize(i+1);
2639   _pfls[i]=DataArrayInt::New();
2640   _pfls[i]->alloc(sz,1);
2641   _pfls[i]->setName(pflCpp.c_str());
2642   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2643   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2644 }
2645
2646 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2647 {
2648   int nbOfPfls=_pfls.size();
2649   for(int i=0;i<nbOfPfls;i++)
2650     {
2651       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2652       cpy->applyLin(1,1,0);
2653       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2654       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2655       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2656     }
2657   //
2658   int nbOfLocs=_locs.size();
2659   for(int i=0;i<nbOfLocs;i++)
2660     _locs[i]->writeLL(fid);
2661 }
2662
2663 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2664 {
2665   std::vector<std::string> pfls=getPfls();
2666   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2667     {
2668       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2669       if(it2==pfls.end())
2670         {
2671           _pfls.push_back(*it);
2672         }
2673       else
2674         {
2675           int id=std::distance(pfls.begin(),it2);
2676           if(!(*it)->isEqual(*_pfls[id]))
2677             {
2678               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2679               throw INTERP_KERNEL::Exception(oss.str().c_str());
2680             }
2681         }
2682     }
2683   std::vector<std::string> locs=getLocs();
2684   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2685     {
2686       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2687       if(it2==locs.end())
2688         {
2689           _locs.push_back(*it);
2690         }
2691       else
2692         {
2693           int id=std::distance(locs.begin(),it2);
2694           if(!(*it)->isEqual(*_locs[id],eps))
2695             {
2696               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2697               throw INTERP_KERNEL::Exception(oss.str().c_str());
2698             }
2699         }
2700     }
2701 }
2702
2703 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2704 {
2705   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2706     getProfile((*it).c_str());
2707 }
2708
2709 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2710 {
2711   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2712     getLocalization((*it).c_str());
2713 }
2714
2715 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2716 {
2717   std::vector<std::string> profiles=real.getPflsReallyUsed();
2718   int sz=profiles.size();
2719   _pfls.resize(sz);
2720   for(int i=0;i<sz;i++)
2721     loadProfileInFile(fid,i,profiles[i].c_str());
2722   //
2723   std::vector<std::string> locs=real.getLocsReallyUsed();
2724   sz=locs.size();
2725   _locs.resize(sz);
2726   for(int i=0;i<sz;i++)
2727     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2728 }
2729
2730 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2731 {
2732   int nProfil=MEDnProfile(fid);
2733   for(int i=0;i<nProfil;i++)
2734     loadProfileInFile(fid,i);
2735   int sz=MEDnLocalization(fid);
2736   _locs.resize(sz);
2737   for(int i=0;i<sz;i++)
2738     {
2739       _locs[i]=MEDFileFieldLoc::New(fid,i);
2740     }
2741 }
2742
2743 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2744 {
2745   return new MEDFileFieldGlobs(fname);
2746 }
2747
2748 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2749 {
2750   return new MEDFileFieldGlobs;
2751 }
2752
2753 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2754 {
2755   return _file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2756 }
2757
2758 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2759 {
2760   std::vector<const BigMemoryObject *> ret;
2761   for(std::vector< MEDCouplingAutoRefCountObjectPtr< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2762     ret.push_back((const DataArrayInt *)*it);
2763   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2764     ret.push_back((const MEDFileFieldLoc *)*it);
2765   return ret;
2766 }
2767
2768 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const
2769 {
2770   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2771   std::size_t i=0;
2772   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2773     {
2774       if((const DataArrayInt *)*it)
2775         ret->_pfls[i]=(*it)->deepCpy();
2776     }
2777   i=0;
2778   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2779     {
2780       if((const MEDFileFieldLoc*)*it)
2781         ret->_locs[i]=(*it)->deepCpy();
2782     }
2783   return ret.retn();
2784 }
2785
2786 /*!
2787  * \throw if a profile in \a pfls in not in \a this.
2788  * \throw if a localization in \a locs in not in \a this.
2789  * \sa MEDFileFieldGlobs::deepCpyPart
2790  */
2791 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2792 {
2793   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2794   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2795     {
2796       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2797       if(!pfl)
2798         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2799       pfl->incrRef();
2800       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2801       ret->_pfls.push_back(pfl2);
2802     }
2803   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2804     {
2805       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2806       if(!loc)
2807         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2808       loc->incrRef();
2809       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2810       ret->_locs.push_back(loc2);
2811     }
2812   ret->setFileName(getFileName());
2813   return ret.retn();
2814 }
2815
2816 /*!
2817  * \throw if a profile in \a pfls in not in \a this.
2818  * \throw if a localization in \a locs in not in \a this.
2819  * \sa MEDFileFieldGlobs::shallowCpyPart
2820  */
2821 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2822 {
2823   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2824   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2825     {
2826       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2827       if(!pfl)
2828         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2829       ret->_pfls.push_back(pfl->deepCpy());
2830     }
2831   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2832     {
2833       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2834       if(!loc)
2835         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2836       ret->_locs.push_back(loc->deepCpy());
2837     }
2838   ret->setFileName(getFileName());
2839   return ret.retn();
2840 }
2841
2842 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2843 {
2844 }
2845
2846 MEDFileFieldGlobs::MEDFileFieldGlobs()
2847 {
2848 }
2849
2850 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2851 {
2852 }
2853
2854 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2855 {
2856   oss << "Profiles :\n";
2857   std::size_t n=_pfls.size();
2858   for(std::size_t i=0;i<n;i++)
2859     {
2860       oss << "  - #" << i << " ";
2861       const DataArrayInt *pfl=_pfls[i];
2862       if(pfl)
2863         oss << "\"" << pfl->getName() << "\"\n";
2864       else
2865         oss << "EMPTY !\n";
2866     }
2867   n=_locs.size();
2868   oss << "Localizations :\n";
2869   for(std::size_t i=0;i<n;i++)
2870     {
2871       oss << "  - #" << i << " ";
2872       const MEDFileFieldLoc *loc=_locs[i];
2873       if(loc)
2874         loc->simpleRepr(oss);
2875       else
2876         oss<< "EMPTY !\n";
2877     }
2878 }
2879
2880 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2881 {
2882   _file_name=fileName;
2883 }
2884
2885 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2886 {
2887   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2888     {
2889       DataArrayInt *elt(*it);
2890       if(elt)
2891         {
2892           std::string name(elt->getName());
2893           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2894             {
2895               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2896                 {
2897                   elt->setName((*it2).second.c_str());
2898                   return;
2899                 }
2900             }
2901         }
2902     }
2903 }
2904
2905 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2906 {
2907   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2908     {
2909       MEDFileFieldLoc *elt(*it);
2910       if(elt)
2911         {
2912           std::string name(elt->getName());
2913           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2914             {
2915               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2916                 {
2917                   elt->setName((*it2).second.c_str());
2918                   return;
2919                 }
2920             }
2921         }
2922     }
2923 }
2924
2925 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2926 {
2927   if(locId<0 || locId>=(int)_locs.size())
2928     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2929   return _locs[locId]->getNbOfGaussPtPerCell();
2930 }
2931
2932 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2933 {
2934   return getLocalizationFromId(getLocalizationId(locName));
2935 }
2936
2937 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2938 {
2939   if(locId<0 || locId>=(int)_locs.size())
2940     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2941   return *_locs[locId];
2942 }
2943
2944 namespace ParaMEDMEMImpl
2945 {
2946   class LocFinder
2947   {
2948   public:
2949     LocFinder(const std::string& loc):_loc(loc) { }
2950     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2951   private:
2952     const std::string &_loc;
2953   };
2954
2955   class PflFinder
2956   {
2957   public:
2958     PflFinder(const std::string& pfl):_pfl(pfl) { }
2959     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2960   private:
2961     const std::string& _pfl;
2962   };
2963 }
2964
2965 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2966 {
2967   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2968   if(it==_locs.end())
2969     {
2970       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2971       for(it=_locs.begin();it!=_locs.end();it++)
2972         oss << "\"" << (*it)->getName() << "\", ";
2973       throw INTERP_KERNEL::Exception(oss.str().c_str());
2974     }
2975   return std::distance(_locs.begin(),it);
2976 }
2977
2978 /*!
2979  * The returned value is never null.
2980  */
2981 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2982 {
2983   std::string pflNameCpp(pflName);
2984   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2985   if(it==_pfls.end())
2986     {
2987       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2988       for(it=_pfls.begin();it!=_pfls.end();it++)
2989         oss << "\"" << (*it)->getName() << "\", ";
2990       throw INTERP_KERNEL::Exception(oss.str().c_str());
2991     }
2992   return *it;
2993 }
2994
2995 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2996 {
2997   if(pflId<0 || pflId>=(int)_pfls.size())
2998     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2999   return _pfls[pflId];
3000 }
3001
3002 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3003 {
3004   if(locId<0 || locId>=(int)_locs.size())
3005     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3006   return *_locs[locId];
3007 }
3008
3009 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3010 {
3011   return getLocalizationFromId(getLocalizationId(locName));
3012 }
3013
3014 /*!
3015  * The returned value is never null.
3016  */
3017 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3018 {
3019   std::string pflNameCpp(pflName);
3020   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
3021   if(it==_pfls.end())
3022     {
3023       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3024       for(it=_pfls.begin();it!=_pfls.end();it++)
3025         oss << "\"" << (*it)->getName() << "\", ";
3026       throw INTERP_KERNEL::Exception(oss.str().c_str());
3027     }
3028   return *it;
3029 }
3030
3031 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3032 {
3033   if(pflId<0 || pflId>=(int)_pfls.size())
3034     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3035   return _pfls[pflId];
3036 }
3037
3038 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3039 {
3040   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
3041   int i=0;
3042   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3043     {
3044       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3045         newPfls.push_back(*it);
3046     }
3047   _pfls=newPfls;
3048 }
3049
3050 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3051 {
3052   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
3053   int i=0;
3054   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3055     {
3056       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3057         newLocs.push_back(*it);
3058     }
3059   _locs=newLocs;
3060 }
3061
3062 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3063 {
3064   int sz=_pfls.size();
3065   std::vector<std::string> ret(sz);
3066   for(int i=0;i<sz;i++)
3067     ret[i]=_pfls[i]->getName();
3068   return ret;
3069 }
3070
3071 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3072 {
3073   int sz=_locs.size();
3074   std::vector<std::string> ret(sz);
3075   for(int i=0;i<sz;i++)
3076     ret[i]=_locs[i]->getName();
3077   return ret;
3078 }
3079
3080 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3081 {
3082   std::vector<std::string> v=getPfls();
3083   std::string s(pflName);
3084   return std::find(v.begin(),v.end(),s)!=v.end();
3085 }
3086
3087 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3088 {
3089   std::vector<std::string> v=getLocs();
3090   std::string s(locName);
3091   return std::find(v.begin(),v.end(),s)!=v.end();
3092 }
3093
3094 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3095 {
3096   std::map<int,std::vector<int> > m;
3097   int i=0;
3098   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3099     {
3100       const DataArrayInt *tmp=(*it);
3101       if(tmp)
3102         {
3103           m[tmp->getHashCode()].push_back(i);
3104         }
3105     }
3106   std::vector< std::vector<int> > ret;
3107   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3108     {
3109       if((*it2).second.size()>1)
3110         {
3111           std::vector<int> ret0;
3112           bool equalityOrNot=false;
3113           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3114             {
3115               std::vector<int>::const_iterator it4=it3; it4++;
3116               for(;it4!=(*it2).second.end();it4++)
3117                 {
3118                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3119                     {
3120                       if(!equalityOrNot)
3121                         ret0.push_back(*it3);
3122                       ret0.push_back(*it4);
3123                       equalityOrNot=true;
3124                     }
3125                 }
3126             }
3127           if(!ret0.empty())
3128             ret.push_back(ret0);
3129         }
3130     }
3131   return ret;
3132 }
3133
3134 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3135 {
3136   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3137 }
3138
3139 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3140 {
3141   std::string name(pfl->getName());
3142   if(name.empty())
3143     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3144   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3145     if(name==(*it)->getName())
3146       {
3147         if(!pfl->isEqual(*(*it)))
3148           {
3149             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3150             throw INTERP_KERNEL::Exception(oss.str().c_str());
3151           }
3152       }
3153   pfl->incrRef();
3154   _pfls.push_back(pfl);
3155 }
3156
3157 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)
3158 {
3159   std::string name(locName);
3160   if(name.empty())
3161     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3162   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3163   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3164     if((*it)->isName(locName))
3165       {
3166         if(!(*it)->isEqual(*obj,1e-12))
3167           {
3168             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3169             throw INTERP_KERNEL::Exception(oss.str().c_str());
3170           }
3171       }
3172   _locs.push_back(obj);
3173 }
3174
3175 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3176 {
3177   std::vector<std::string> names=getPfls();
3178   return CreateNewNameNotIn("NewPfl_",names);
3179 }
3180
3181 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3182 {
3183   std::vector<std::string> names=getLocs();
3184   return CreateNewNameNotIn("NewLoc_",names);
3185 }
3186
3187 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3188 {
3189   for(std::size_t sz=0;sz<100000;sz++)
3190     {
3191       std::ostringstream tryName;
3192       tryName << prefix << sz;
3193       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3194         return tryName.str();
3195     }
3196   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3197 }
3198
3199 /*!
3200  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3201  *  \param [in] fname - the file name.
3202  */
3203 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
3204 {
3205 }
3206
3207 /*!
3208  * Creates an empty MEDFileFieldGlobsReal.
3209  */
3210 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3211 {
3212 }
3213
3214 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3215 {
3216   return 0;
3217 }
3218
3219 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3220 {
3221   std::vector<const BigMemoryObject *> ret;
3222   ret.push_back((const MEDFileFieldGlobs *)_globals);
3223   return ret;
3224 }
3225
3226 /*!
3227  * Returns a string describing profiles and Gauss points held in \a this.
3228  *  \return std::string - the description string.
3229  */
3230 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3231 {
3232   const MEDFileFieldGlobs *glob=_globals;
3233   std::ostringstream oss2; oss2 << glob;
3234   std::string stars(oss2.str().length(),'*');
3235   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3236   if(glob)
3237     glob->simpleRepr(oss);
3238   else
3239     oss << "NO GLOBAL INFORMATION !\n";
3240 }
3241
3242 void MEDFileFieldGlobsReal::resetContent()
3243 {
3244   _globals=MEDFileFieldGlobs::New();
3245 }
3246
3247 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3248 {
3249 }
3250
3251 /*!
3252  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3253  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3254  */
3255 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3256 {
3257   _globals=other._globals;
3258 }
3259
3260 /*!
3261  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3262  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3263  */
3264 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3265 {
3266   const MEDFileFieldGlobs *otherg(other._globals);
3267   if(!otherg)
3268     return ;
3269   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3270 }
3271
3272 /*!
3273  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3274  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3275  */
3276 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3277 {
3278   const MEDFileFieldGlobs *otherg(other._globals);
3279   if(!otherg)
3280     return ;
3281   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3282 }
3283
3284 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3285 {
3286   _globals=other._globals;
3287   if((const MEDFileFieldGlobs *)_globals)
3288     _globals=other._globals->deepCpy();
3289 }
3290
3291 /*!
3292  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3293  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3294  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3295  *         \a this and \a other MEDFileFieldGlobsReal.
3296  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3297  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3298  */
3299 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3300 {
3301   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3302   if(thisGlobals==otherGlobals)
3303     return ;
3304   if(!thisGlobals)
3305     {
3306       _globals=other._globals;
3307       return ;
3308     }
3309   _globals->appendGlobs(*other._globals,eps);
3310 }
3311
3312 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3313 {
3314   checkGlobsPflsPartCoherency();
3315   checkGlobsLocsPartCoherency();
3316 }
3317
3318 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3319 {
3320   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3321 }
3322
3323 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3324 {
3325   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3326 }
3327
3328 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3329 {
3330   contentNotNull()->loadProfileInFile(fid,id,pflName);
3331 }
3332
3333 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3334 {
3335   contentNotNull()->loadProfileInFile(fid,id);
3336 }
3337
3338 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3339 {
3340   contentNotNull()->loadGlobals(fid,*this);
3341 }
3342
3343 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3344 {
3345   contentNotNull()->loadAllGlobals(fid);
3346 }
3347
3348 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3349 {
3350   contentNotNull()->writeGlobals(fid,opt);
3351 }
3352
3353 /*!
3354  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3355  * or getPflsReallyUsedMulti().
3356  *  \return std::vector<std::string> - a sequence of names of all profiles.
3357  */
3358 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3359 {
3360   return contentNotNull()->getPfls();
3361 }
3362
3363 /*!
3364  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3365  * or getLocsReallyUsedMulti().
3366  *  \return std::vector<std::string> - a sequence of names of all localizations.
3367  */
3368 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3369 {
3370   return contentNotNull()->getLocs();
3371 }
3372
3373 /*!
3374  * Checks if the profile with a given name exists.
3375  *  \param [in] pflName - the profile name of interest.
3376  *  \return bool - \c true if the profile named \a pflName exists.
3377  */
3378 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3379 {
3380   return contentNotNull()->existsPfl(pflName);
3381 }
3382
3383 /*!
3384  * Checks if the localization with a given name exists.
3385  *  \param [in] locName - the localization name of interest.
3386  *  \return bool - \c true if the localization named \a locName exists.
3387  */
3388 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3389 {
3390   return contentNotNull()->existsLoc(locName);
3391 }
3392
3393 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3394 {
3395   return contentNotNull()->createNewNameOfPfl();
3396 }
3397
3398 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3399 {
3400   return contentNotNull()->createNewNameOfLoc();
3401 }
3402
3403 /*!
3404  * Sets the name of a MED file.
3405  *  \param [inout] fileName - the file name.
3406  */
3407 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3408 {
3409   contentNotNull()->setFileName(fileName);
3410 }
3411
3412 /*!
3413  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3414  * in the same order.
3415  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3416  *          Each item of this sequence is a vector containing ids of equal profiles.
3417  */
3418 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3419 {
3420   return contentNotNull()->whichAreEqualProfiles();
3421 }
3422
3423 /*!
3424  * Finds equal localizations.
3425  *  \param [in] eps - a precision used to compare real values of the localizations.
3426  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3427  *          Each item of this sequence is a vector containing ids of equal localizations.
3428  */
3429 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3430 {
3431   return contentNotNull()->whichAreEqualLocs(eps);
3432 }
3433
3434 /*!
3435  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3436  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3437  *        this sequence is a pair whose 
3438  *        - the first item is a vector of profile names to replace by the second item,
3439  *        - the second item is a profile name to replace every profile name of the first item.
3440  */
3441 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3442 {
3443   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3444 }
3445
3446 /*!
3447  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3448  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3449  *        this sequence is a pair whose 
3450  *        - the first item is a vector of localization names to replace by the second item,
3451  *        - the second item is a localization name to replace every localization name of the first item.
3452  */
3453 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3454 {
3455   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3456 }
3457
3458 /*!
3459  * Replaces references to some profiles (a reference is a profile name) by references
3460  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3461  * them-selves accordingly. <br>
3462  * This method is a generalization of changePflName().
3463  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3464  *        this sequence is a pair whose 
3465  *        - the first item is a vector of profile names to replace by the second item,
3466  *        - the second item is a profile name to replace every profile of the first item.
3467  * \sa changePflsRefsNamesGen()
3468  * \sa changePflName()
3469  */
3470 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3471 {
3472   changePflsRefsNamesGen(mapOfModif);
3473   changePflsNamesInStruct(mapOfModif);
3474 }
3475
3476 /*!
3477  * Replaces references to some localizations (a reference is a localization name) by references
3478  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3479  * them-selves accordingly. <br>
3480  * This method is a generalization of changeLocName().
3481  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3482  *        this sequence is a pair whose 
3483  *        - the first item is a vector of localization names to replace by the second item,
3484  *        - the second item is a localization name to replace every localization of the first item.
3485  * \sa changeLocsRefsNamesGen()
3486  * \sa changeLocName()
3487  */
3488 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3489 {
3490   changeLocsRefsNamesGen(mapOfModif);
3491   changeLocsNamesInStruct(mapOfModif);
3492 }
3493
3494 /*!
3495  * Renames the profile having a given name and updates references to this profile.
3496  *  \param [in] oldName - the name of the profile to rename.
3497  *  \param [in] newName - a new name of the profile.
3498  * \sa changePflsNames().
3499  */
3500 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3501 {
3502   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3503   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3504   mapOfModif[0]=p;
3505   changePflsNames(mapOfModif);
3506 }
3507
3508 /*!
3509  * Renames the localization having a given name and updates references to this localization.
3510  *  \param [in] oldName - the name of the localization to rename.
3511  *  \param [in] newName - a new name of the localization.
3512  * \sa changeLocsNames().
3513  */
3514 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3515 {
3516   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3517   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3518   mapOfModif[0]=p;
3519   changeLocsNames(mapOfModif);
3520 }
3521
3522 /*!
3523  * Removes duplicated profiles. Returns a map used to update references to removed 
3524  * profiles via changePflsRefsNamesGen().
3525  * Equal profiles are found using whichAreEqualProfiles().
3526  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3527  *          a sequence describing the performed replacements of profiles. Each element of
3528  *          this sequence is a pair whose
3529  *          - the first item is a vector of profile names replaced by the second item,
3530  *          - the second item is a profile name replacing every profile of the first item.
3531  */
3532 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3533 {
3534   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3535   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3536   int i=0;
3537   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3538     {
3539       std::vector< std::string > tmp((*it).size());
3540       int j=0;
3541       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3542         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3543       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3544       ret[i]=p;
3545       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3546       killProfileIds(tmp2);
3547     }
3548   changePflsRefsNamesGen(ret);
3549   return ret;
3550 }
3551
3552 /*!
3553  * Removes duplicated localizations. Returns a map used to update references to removed 
3554  * localizations via changeLocsRefsNamesGen().
3555  * Equal localizations are found using whichAreEqualLocs().
3556  *  \param [in] eps - a precision used to compare real values of the localizations.
3557  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3558  *          a sequence describing the performed replacements of localizations. Each element of
3559  *          this sequence is a pair whose
3560  *          - the first item is a vector of localization names replaced by the second item,
3561  *          - the second item is a localization name replacing every localization of the first item.
3562  */
3563 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3564 {
3565   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3566   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3567   int i=0;
3568   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3569     {
3570       std::vector< std::string > tmp((*it).size());
3571       int j=0;
3572       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3573         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3574       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3575       ret[i]=p;
3576       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3577       killLocalizationIds(tmp2);
3578     }
3579   changeLocsRefsNamesGen(ret);
3580   return ret;
3581 }
3582
3583 /*!
3584  * Returns number of Gauss points per cell in a given localization.
3585  *  \param [in] locId - an id of the localization of interest.
3586  *  \return int - the number of the Gauss points per cell.
3587  */
3588 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3589 {
3590   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3591 }
3592
3593 /*!
3594  * Returns an id of a localization by its name.
3595  *  \param [in] loc - the localization name of interest.
3596  *  \return int - the id of the localization.
3597  *  \throw If there is no a localization named \a loc.
3598  */
3599 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3600 {
3601   return contentNotNull()->getLocalizationId(loc);
3602 }
3603
3604 /*!
3605  * Returns the name of the MED file.
3606  *  \return const std::string&  - the MED file name.
3607  */
3608 std::string MEDFileFieldGlobsReal::getFileName() const
3609 {
3610   return contentNotNull()->getFileName();
3611 }
3612
3613 /*!
3614  * Returns a localization object by its name.
3615  *  \param [in] locName - the name of the localization of interest.
3616  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3617  *  \throw If there is no a localization named \a locName.
3618  */
3619 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3620 {
3621   return contentNotNull()->getLocalization(locName);
3622 }
3623
3624 /*!
3625  * Returns a localization object by its id.
3626  *  \param [in] locId - the id of the localization of interest.
3627  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3628  *  \throw If there is no a localization with id \a locId.
3629  */
3630 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3631 {
3632   return contentNotNull()->getLocalizationFromId(locId);
3633 }
3634
3635 /*!
3636  * Returns a profile array by its name.
3637  *  \param [in] pflName - the name of the profile of interest.
3638  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3639  *  \throw If there is no a profile named \a pflName.
3640  */
3641 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3642 {
3643   return contentNotNull()->getProfile(pflName);
3644 }
3645
3646 /*!
3647  * Returns a profile array by its id.
3648  *  \param [in] pflId - the id of the profile of interest.
3649  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3650  *  \throw If there is no a profile with id \a pflId.
3651  */
3652 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3653 {
3654   return contentNotNull()->getProfileFromId(pflId);
3655 }
3656
3657 /*!
3658  * Returns a localization object, apt for modification, by its id.
3659  *  \param [in] locId - the id of the localization of interest.
3660  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3661  *          having the id \a locId.
3662  *  \throw If there is no a localization with id \a locId.
3663  */
3664 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3665 {
3666   return contentNotNull()->getLocalizationFromId(locId);
3667 }
3668
3669 /*!
3670  * Returns a localization object, apt for modification, by its name.
3671  *  \param [in] locName - the name of the localization of interest.
3672  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3673  *          having the name \a locName.
3674  *  \throw If there is no a localization named \a locName.
3675  */
3676 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3677 {
3678   return contentNotNull()->getLocalization(locName);
3679 }
3680
3681 /*!
3682  * Returns a profile array, apt for modification, by its name.
3683  *  \param [in] pflName - the name of the profile of interest.
3684  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3685  *  \throw If there is no a profile named \a pflName.
3686  */
3687 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3688 {
3689   return contentNotNull()->getProfile(pflName);
3690 }
3691
3692 /*!
3693  * Returns a profile array, apt for modification, by its id.
3694  *  \param [in] pflId - the id of the profile of interest.
3695  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3696  *  \throw If there is no a profile with id \a pflId.
3697  */
3698 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3699 {
3700   return contentNotNull()->getProfileFromId(pflId);
3701 }
3702
3703 /*!
3704  * Removes profiles given by their ids. No data is updated to track this removal.
3705  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3706  */
3707 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3708 {
3709   contentNotNull()->killProfileIds(pflIds);
3710 }
3711
3712 /*!
3713  * Removes localizations given by their ids. No data is updated to track this removal.
3714  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3715  */
3716 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3717 {
3718   contentNotNull()->killLocalizationIds(locIds);
3719 }
3720
3721 /*!
3722  * Stores a profile array.
3723  *  \param [in] pfl - the profile array to store.
3724  *  \throw If the name of \a pfl is empty.
3725  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3726  *         different ids.
3727  */
3728 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3729 {
3730   contentNotNull()->appendProfile(pfl);
3731 }
3732
3733 /*!
3734  * Adds a new localization of Gauss points.
3735  *  \param [in] locName - the name of the new localization.
3736  *  \param [in] geoType - a geometrical type of the reference cell.
3737  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3738  *         must be \c nbOfNodesPerCell * \c dimOfType.
3739  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3740  *         must be  _wg_.size() * \c dimOfType.
3741  *  \param [in] w - the weights of Gauss points.
3742  *  \throw If \a locName is empty.
3743  *  \throw If a localization with the name \a locName already exists but is
3744  *         different form the new one.
3745  */
3746 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)
3747 {
3748   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3749 }
3750
3751 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3752 {
3753   MEDFileFieldGlobs *g(_globals);
3754   if(!g)
3755     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3756   return g;
3757 }
3758
3759 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3760 {
3761   const MEDFileFieldGlobs *g(_globals);
3762   if(!g)
3763     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3764   return g;
3765 }
3766
3767 //= MEDFileFieldNameScope
3768
3769 MEDFileFieldNameScope::MEDFileFieldNameScope()
3770 {
3771 }
3772
3773 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3774 {
3775 }
3776
3777 /*!
3778  * Returns the name of \a this field.
3779  *  \return std::string - a string containing the field name.
3780  */
3781 std::string MEDFileFieldNameScope::getName() const
3782 {
3783   return _name;
3784 }
3785
3786 /*!
3787  * Sets name of \a this field
3788  *  \param [in] name - the new field name.
3789  */
3790 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3791 {
3792   _name=fieldName;
3793 }
3794
3795 std::string MEDFileFieldNameScope::getDtUnit() const
3796 {
3797   return _dt_unit;
3798 }
3799
3800 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3801 {
3802   _dt_unit=dtUnit;
3803 }
3804
3805 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3806 {
3807   _name=other._name;
3808   _dt_unit=other._dt_unit;
3809 }
3810
3811 //= MEDFileAnyTypeField1TSWithoutSDA
3812
3813 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3814 {
3815   _field_per_mesh.resize(other._field_per_mesh.size());
3816   std::size_t i=0;
3817   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3818     {
3819       if((const MEDFileFieldPerMesh *)*it)
3820         _field_per_mesh[i]=(*it)->deepCpy(this);
3821     }
3822 }
3823
3824 /*!
3825  * Prints a string describing \a this field into a stream. This string is outputted 
3826  * by \c print Python command.
3827  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3828  *  \param [in,out] oss - the out stream.
3829  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3830  *          info id printed, else, not.
3831  */
3832 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3833 {
3834   std::string startOfLine(bkOffset,' ');
3835   oss << startOfLine << "Field ";
3836   if(bkOffset==0)
3837     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3838   oss << "on one time Step ";
3839   if(f1tsId>=0)
3840     oss << "(" << f1tsId << ") ";
3841   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3842   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3843   const DataArray *arr=getUndergroundDataArray();
3844   if(arr)
3845     {
3846       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3847       if(f1tsId<0)
3848         {
3849           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3850           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3851             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3852         }
3853       if(arr->isAllocated())
3854         {
3855           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3856         }
3857       else
3858         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3859     }
3860   else
3861     {
3862       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3863     }
3864   oss << startOfLine << "----------------------" << std::endl;
3865   if(!_field_per_mesh.empty())
3866     {
3867       int i=0;
3868       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3869         {
3870           const MEDFileFieldPerMesh *cur=(*it2);
3871           if(cur)
3872             cur->simpleRepr(bkOffset,oss,i);
3873           else
3874             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3875         }
3876     }
3877   else
3878     {
3879       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3880     }
3881   oss << startOfLine << "----------------------" << std::endl;
3882 }
3883
3884 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3885 {
3886   const DataArray *arr(getUndergroundDataArray());
3887   if(!arr)
3888     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3889   int nbOfCompo=arr->getNumberOfComponents();
3890   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3891   for(int i=0;i<nbOfCompo;i++)
3892     {
3893       ret[i]=deepCpy();
3894       std::vector<int> v(1,i);
3895       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3896       ret[i]->setArray(arr2);
3897     }
3898   return ret;
3899 }
3900
3901 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)
3902 {
3903 }
3904
3905 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3906 {
3907 }
3908
3909 /*!
3910  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3911  * empty. Returns -1 if this in on nodes.
3912  *  \return int - the dimension of \a this.
3913  */
3914 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3915 {
3916   int ret=-2;
3917   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3918     (*it)->getDimension(ret);
3919   return ret;
3920 }
3921
3922 /*!
3923  * Returns the mesh name.
3924  *  \return std::string - a string holding the mesh name.
3925  *  \throw If \c _field_per_mesh.empty()
3926  */
3927 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3928 {
3929   if(_field_per_mesh.empty())
3930     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3931   return _field_per_mesh[0]->getMeshName();
3932 }
3933
3934 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3935 {
3936   std::string oldName(getMeshName());
3937   std::vector< std::pair<std::string,std::string> > v(1);
3938   v[0].first=oldName; v[0].second=newMeshName;
3939   changeMeshNames(v);
3940 }
3941
3942 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3943 {
3944   bool ret=false;
3945   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3946     {
3947       MEDFileFieldPerMesh *cur(*it);
3948       if(cur)
3949         ret=cur->changeMeshNames(modifTab) || ret;
3950     }
3951   return ret;
3952 }
3953
3954 /*!
3955  * Returns the number of iteration of the state of underlying mesh.
3956  *  \return int - the iteration number.
3957  *  \throw If \c _field_per_mesh.empty()
3958  */
3959 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3960 {
3961   if(_field_per_mesh.empty())
3962     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3963   return _field_per_mesh[0]->getMeshIteration();
3964 }
3965
3966 /*!
3967  * Returns the order number of iteration of the state of underlying mesh.
3968  *  \return int - the order number.
3969  *  \throw If \c _field_per_mesh.empty()
3970  */
3971 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3972 {
3973   if(_field_per_mesh.empty())
3974     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3975   return _field_per_mesh[0]->getMeshOrder();
3976 }
3977
3978 /*!
3979  * Checks if \a this field is tagged by a given iteration number and a given
3980  * iteration order number.
3981  *  \param [in] iteration - the iteration number of interest.
3982  *  \param [in] order - the iteration order number of interest.
3983  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3984  *          \a this->getOrder() == \a order.
3985  */
3986 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3987 {
3988   return iteration==_iteration && order==_order;
3989 }
3990
3991 /*!
3992  * Returns number of iteration and order number of iteration when
3993  * \a this field has been calculated.
3994  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3995  *          order number.
3996  */
3997 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3998 {
3999   std::pair<int,int> p;
4000   fillIteration(p);
4001   return p;
4002 }
4003
4004 /*!
4005  * Returns number of iteration and order number of iteration when
4006  * \a this field has been calculated.
4007  *  \param [in,out] p - a pair returning the iteration number and the iteration
4008  *          order number.
4009  */
4010 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4011 {
4012   p.first=_iteration;
4013   p.second=_order;
4014 }
4015
4016 /*!
4017  * Returns all types of spatial discretization of \a this field.
4018  *  \param [in,out] types - a sequence of types of \a this field.
4019  */
4020 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4021 {
4022   std::set<TypeOfField> types2;
4023   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4024     {
4025       (*it)->fillTypesOfFieldAvailable(types2);
4026     }
4027   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4028   std::copy(types2.begin(),types2.end(),bi);
4029 }
4030
4031 /*!
4032  * Returns all types of spatial discretization of \a this field.
4033  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4034  *          of \a this field.
4035  */
4036 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4037 {
4038   std::vector<TypeOfField> ret;
4039   fillTypesOfFieldAvailable(ret);
4040   return ret;
4041 }
4042
4043 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4044 {
4045   std::vector<std::string> ret;
4046   std::set<std::string> ret2;
4047   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4048     {
4049       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4050       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4051         if(ret2.find(*it2)==ret2.end())
4052           {
4053             ret.push_back(*it2);
4054             ret2.insert(*it2);
4055           }
4056     }
4057   return ret;
4058 }
4059
4060 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4061 {
4062   std::vector<std::string> ret;
4063   std::set<std::string> ret2;
4064   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4065     {
4066       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4067       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4068         if(ret2.find(*it2)==ret2.end())
4069           {
4070             ret.push_back(*it2);
4071             ret2.insert(*it2);
4072           }
4073     }
4074   return ret;
4075 }
4076
4077 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4078 {
4079   std::vector<std::string> ret;
4080   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4081     {
4082       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4083       ret.insert(ret.end(),tmp.begin(),tmp.end());
4084     }
4085   return ret;
4086 }
4087
4088 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4089 {
4090   std::vector<std::string> ret;
4091   std::set<std::string> ret2;
4092   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4093     {
4094       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4095       ret.insert(ret.end(),tmp.begin(),tmp.end());
4096     }
4097   return ret;
4098 }
4099
4100 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4101 {
4102   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4103     (*it)->changePflsRefsNamesGen(mapOfModif);
4104 }
4105
4106 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4107 {
4108   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4109     (*it)->changeLocsRefsNamesGen(mapOfModif);
4110 }
4111
4112 /*!
4113  * Returns all attributes of parts of \a this field lying on a given mesh.
4114  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4115  * item of every of returned sequences refers to the _i_-th part of \a this field.
4116  * Thus all sequences returned by this method are of the same length equal to number
4117  * of different types of supporting entities.<br>
4118  * A field part can include sub-parts with several different spatial discretizations,
4119  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4120  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4121  * of a nested sequence corresponds to a type of spatial discretization.<br>
4122  * This method allows for iteration over MEDFile DataStructure without any overhead.
4123  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4124  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4125  *          not checked if \a mname == \c NULL).
4126  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4127  *          a field part is returned. 
4128  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4129  *          This sequence is of the same length as \a types. 
4130  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4131  *          discretization. A profile name can be empty.
4132  *          Length of this and of nested sequences is the same as that of \a typesF.
4133  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4134  *          discretization. A localization name can be empty.
4135  *          Length of this and of nested sequences is the same as that of \a typesF.
4136  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4137  *          of ids of tuples within the data array, per each type of spatial
4138  *          discretization within one mesh entity type. 
4139  *          Length of this and of nested sequences is the same as that of \a typesF.
4140  *  \throw If no field is lying on \a mname.
4141  */
4142 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
4143 {
4144   int meshId=0;
4145   if(!mname.empty())
4146     meshId=getMeshIdFromMeshName(mname);
4147   else
4148     if(_field_per_mesh.empty())
4149       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4150   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4151 }
4152
4153 /*!
4154  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4155  * maximal absolute dimension and values returned via the out parameter \a levs are 
4156  * dimensions relative to the maximal absolute dimension. <br>
4157  * This method is designed for MEDFileField1TS instances that have a discretization
4158  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
4159  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
4160  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
4161  * Only these 3 discretizations will be taken into account here. If \a this is
4162  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4163  * This method is useful to make the link between the dimension of the underlying mesh
4164  * and the levels of \a this, because it is possible that the highest dimension of \a this
4165  * field is not equal to the dimension of the underlying mesh.
4166  * 
4167  * Let's consider the following case:
4168  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4169  * TETRA4, HEXA8, TRI3 and SEG2.
4170  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4171  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4172  *
4173  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4174  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4175  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4176  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4177  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4178  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4179  * For example<br>
4180  * to retrieve the highest level of
4181  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4182  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4183  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4184  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4185  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4186  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4187  *          not checked if \a mname == \c NULL).
4188  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4189  *          absolute one. They are in decreasing order. This sequence is cleared before
4190  *          filling it in.
4191  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4192  *  \throw If no field is lying on \a mname.
4193  */
4194 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4195 {
4196   levs.clear();
4197   int meshId=getMeshIdFromMeshName(mname);
4198   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4199   std::vector< std::vector<TypeOfField> > typesF;
4200   std::vector< std::vector<std::string> > pfls, locs;
4201   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4202   if(types.empty())
4203     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4204   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4205   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4206     return -1;
4207   st.erase(INTERP_KERNEL::NORM_ERROR);
4208   std::set<int> ret1;
4209   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4210     {
4211       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4212       ret1.insert((int)cm.getDimension());
4213     }
4214   int ret=*std::max_element(ret1.begin(),ret1.end());
4215   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4216   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4217   return ret;
4218 }
4219
4220 /*!
4221  * \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.
4222  * \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.
4223  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4224  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4225  */
4226 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4227 {
4228   int mid=getMeshIdFromMeshName(mName);
4229   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4230 }
4231
4232 /*!
4233  * \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.
4234  * \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.
4235  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4236  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4237  */
4238 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4239 {
4240   int mid=getMeshIdFromMeshName(mName);
4241   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4242 }
4243
4244 /*!
4245  * \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.
4246  */
4247 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4248 {
4249   if(_field_per_mesh.empty())
4250     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4251   if(mName.empty())
4252     return 0;
4253   std::string mName2(mName);
4254   int ret=0;
4255   std::vector<std::string> msg;
4256   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4257     if(mName2==(*it)->getMeshName())
4258       return ret;
4259     else
4260       msg.push_back((*it)->getMeshName());
4261   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4262   oss << "Possible meshes are : ";
4263   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4264     oss << "\"" << (*it2) << "\" ";
4265   throw INTERP_KERNEL::Exception(oss.str().c_str());
4266 }
4267
4268 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4269 {
4270   if(!mesh)
4271     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4272   std::string tmp(mesh->getName());
4273   if(tmp.empty())
4274     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4275   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4276   int i=0;
4277   for(;it!=_field_per_mesh.end();it++,i++)
4278     {
4279       if((*it)->getMeshName()==tmp)
4280         return i;
4281     }
4282   int sz=_field_per_mesh.size();
4283   _field_per_mesh.resize(sz+1);
4284   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4285   return sz;
4286 }
4287
4288 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4289                                                                    MEDFileFieldGlobsReal& glob)
4290 {
4291   bool ret=false;
4292   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4293     {
4294       MEDFileFieldPerMesh *fpm(*it);
4295       if(fpm)
4296         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4297     }
4298   return ret;
4299 }
4300
4301 /*!
4302  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4303  * splitting that leads to single spatial discretization of this.
4304  *
4305  * \sa splitMultiDiscrPerGeoTypes
4306  */
4307 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4308 {
4309   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4310   std::vector< std::vector<TypeOfField> > typesF;
4311   std::vector< std::vector<std::string> > pfls,locs;
4312   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4313   std::set<TypeOfField> allEnt;
4314   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4315     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4316       allEnt.insert(*it2);
4317   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4318   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4319   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4320     {
4321       std::vector< std::pair<int,int> > its;
4322       ret[i]=shallowCpy();
4323       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4324       ret[i]->updateData(newLgth,its);
4325     }
4326   return ret;
4327 }
4328
4329 /*!
4330  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4331  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4332  *
4333  * \sa splitDiscretizations
4334  */
4335 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4336 {
4337   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4338   std::vector< std::vector<TypeOfField> > typesF;
4339   std::vector< std::vector<std::string> > pfls,locs;
4340   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4341   std::set<TypeOfField> allEnt;
4342   std::size_t nbOfMDPGT(0),ii(0);
4343   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4344     {
4345       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4346       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4347         allEnt.insert(*it2);
4348     }
4349         if(allEnt.size()!=1)
4350           throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4351         if(nbOfMDPGT==0)
4352           throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4353   if(nbOfMDPGT==1)
4354     {
4355       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4356       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4357       return ret0;
4358     }
4359   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4360   for(std::size_t i=0;i<nbOfMDPGT;i++)
4361     {
4362       std::vector< std::pair<int,int> > its;
4363       ret[i]=shallowCpy();
4364       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4365       ret[i]->updateData(newLgth,its);
4366     }
4367   return ret;
4368 }
4369
4370 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4371 {
4372   int globalCounter(0);
4373   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4374     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4375   return globalCounter;
4376 }
4377
4378 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4379 {
4380   int globalCounter(0);
4381   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4382     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4383   return globalCounter;
4384 }
4385
4386 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4387 {
4388   if(_nb_of_tuples_to_be_allocated>=0)
4389     {
4390       _nb_of_tuples_to_be_allocated=newLgth;
4391       const DataArray *oldArr(getUndergroundDataArray());
4392       if(oldArr)
4393         {
4394           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4395           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4396           setArray(newArr);
4397           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4398         }
4399       return ;
4400     }
4401   if(_nb_of_tuples_to_be_allocated==-1)
4402     return ;
4403   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4404     {
4405       const DataArray *oldArr(getUndergroundDataArray());
4406       if(!oldArr || !oldArr->isAllocated())
4407         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4408       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4409       newArr->alloc(newLgth,getNumberOfComponents());
4410       if(oldArr)
4411         newArr->copyStringInfoFrom(*oldArr);
4412       int pos=0;
4413       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4414         {
4415           if((*it).second<(*it).first)
4416             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4417           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4418           pos+=(*it).second-(*it).first;
4419         }
4420       setArray(newArr);
4421       return ;
4422     }
4423   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4424 }
4425
4426 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4427 {
4428   if(_field_per_mesh.empty())
4429     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4430   if(_field_per_mesh.size()>1)
4431     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4432   _field_per_mesh[0]->copyOptionsFrom(opts);
4433   _field_per_mesh[0]->writeLL(fid,nasc);
4434 }
4435
4436 /*!
4437  * 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.
4438  * If false is returned the memory allocation is not required.
4439  */
4440 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4441 {
4442   if(_nb_of_tuples_to_be_allocated>=0)
4443     {
4444       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4445       _nb_of_tuples_to_be_allocated=-2;
4446       return true;
4447     }
4448   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4449     return false;
4450   if(_nb_of_tuples_to_be_allocated==-1)
4451     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4452   if(_nb_of_tuples_to_be_allocated<-3)
4453     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4454   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4455 }
4456
4457 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4458 {
4459   med_int numdt,numit;
4460   med_float dt;
4461   med_int nmesh;
4462   med_bool localMesh;
4463   med_int meshnumdt,meshnumit;
4464   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4465   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4466   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4467   if(_iteration!=numdt || _order!=numit)
4468     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4469   _field_per_mesh.resize(nmesh);
4470   //
4471   MEDFileMesh *mm(0);
4472   if(ms)
4473     {
4474       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4475       mm=ms->getMeshWithName(meshNameCpp);
4476     }
4477   //
4478   for(int i=0;i<nmesh;i++)
4479     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4480   _nb_of_tuples_to_be_allocated=0;
4481   for(int i=0;i<nmesh;i++)
4482     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4483 }
4484
4485 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4486 {
4487   allocIfNecessaryTheArrayToReceiveDataFromFile();
4488   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4489     (*it)->loadBigArraysRecursively(fid,nasc);
4490 }
4491
4492 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4493 {
4494   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4495     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4496       (*it)->loadBigArraysRecursively(fid,nasc);
4497 }
4498
4499 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
4500 {
4501   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4502   loadBigArraysRecursively(fid,nasc);
4503 }
4504
4505 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4506 {
4507   DataArray *thisArr(getUndergroundDataArray());
4508   if(thisArr && thisArr->isAllocated())
4509     {
4510       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4511       thisArr->desallocate();
4512     }
4513 }
4514
4515 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4516 {
4517   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4518 }
4519
4520 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4521 {
4522   std::vector<const BigMemoryObject *> ret;
4523   if(getUndergroundDataArray())
4524     ret.push_back(getUndergroundDataArray());
4525   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4526     ret.push_back((const MEDFileFieldPerMesh *)*it);
4527   return ret;
4528 }
4529
4530 /*!
4531  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4532  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4533  * "Sort By Type"), if not, an exception is thrown. 
4534  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4535  *  \param [in] arr - the array of values.
4536  *  \param [in,out] glob - the global data where profiles and localization present in
4537  *          \a field, if any, are added.
4538  *  \throw If the name of \a field is empty.
4539  *  \throw If the data array of \a field is not set.
4540  *  \throw If \a this->_arr is already allocated but has different number of components
4541  *         than \a field.
4542  *  \throw If the underlying mesh of \a field has no name.
4543  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4544  */
4545 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4546 {
4547   const MEDCouplingMesh *mesh=field->getMesh();
4548   //
4549   TypeOfField type=field->getTypeOfField();
4550   std::vector<DataArrayInt *> dummy;
4551   int start=copyTinyInfoFrom(field,arr);
4552   int pos=addNewEntryIfNecessary(mesh);
4553   if(type!=ON_NODES)
4554     {
4555       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4556       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4557     }
4558   else
4559     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4560 }
4561
4562 /*!
4563  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4564  * of a given mesh are used as the support of the given field (a real support is not used). 
4565  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4566  * Order of underlying mesh entities of the given field specified by \a profile parameter
4567  * is not prescribed; this method permutes field values to have them sorted by element
4568  * type as required for writing to MED file. A new profile is added only if no equal
4569  * profile is missing. 
4570  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4571  *  \param [in] arrOfVals - the values of the field \a field used.
4572  *  \param [in] mesh - the supporting mesh of \a field.
4573  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4574  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4575  *  \param [in,out] glob - the global data where profiles and localization present in
4576  *          \a field, if any, are added.
4577  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4578  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4579  *  \throw If the data array of \a field is not set.
4580  *  \throw If \a this->_arr is already allocated but has different number of components
4581  *         than \a field.
4582  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4583  *  \sa setFieldNoProfileSBT()
4584  */
4585 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4586 {
4587   if(!field)
4588     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4589   if(!arrOfVals || !arrOfVals->isAllocated())
4590     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4591   TypeOfField type=field->getTypeOfField();
4592   std::vector<DataArrayInt *> idsInPflPerType;
4593   std::vector<DataArrayInt *> idsPerType;
4594   std::vector<int> code,code2;
4595   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4596   if(type!=ON_NODES)
4597     {
4598       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4599       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4600       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4601       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4602       // start of check
4603       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4604       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4605       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4606         {
4607           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4608           throw INTERP_KERNEL::Exception(oss.str().c_str());
4609         }
4610       // end of check
4611       int start=copyTinyInfoFrom(field,arrOfVals);
4612       code2=m->getDistributionOfTypes();
4613       //
4614       int pos=addNewEntryIfNecessary(m);
4615       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4616     }
4617   else
4618     {
4619       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4620         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4621       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4622       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4623       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4624       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4625         {
4626           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4627           throw INTERP_KERNEL::Exception(oss.str().c_str());
4628         }
4629       int start=copyTinyInfoFrom(field,arrOfVals);
4630       int pos=addNewEntryIfNecessary(m);
4631       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4632     }
4633 }
4634
4635 /*!
4636  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4637  */
4638 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4639 {
4640   if(_nb_of_tuples_to_be_allocated>=0)
4641     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 !");
4642   DataArray *arr(getOrCreateAndGetArray());
4643   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4644   _nb_of_tuples_to_be_allocated=-3;
4645 }
4646
4647 /*!
4648  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4649  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4650  * larger by the size of \a field. Returns an id of the first not filled
4651  * tuple of \a this->_arr.
4652  *  \param [in] field - the field to copy the info on components and the name from.
4653  *  \return int - the id of first not initialized tuple of \a this->_arr.
4654  *  \throw If the name of \a field is empty.
4655  *  \throw If the data array of \a field is not set.
4656  *  \throw If \a this->_arr is already allocated but has different number of components
4657  *         than \a field.
4658  */
4659 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4660 {
4661   if(!field)
4662     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4663   std::string name(field->getName());
4664   setName(name.c_str());
4665   setDtUnit(field->getTimeUnit());
4666   if(name.empty())
4667     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4668   if(!arr)
4669     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4670   if(!arr->isAllocated())
4671     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4672   _dt=field->getTime(_iteration,_order);
4673   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4674   if(!getOrCreateAndGetArray()->isAllocated())
4675     {
4676       allocNotFromFile(arr->getNumberOfTuples());
4677       return 0;
4678     }
4679   else
4680     {
4681       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4682       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4683       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4684       _nb_of_tuples_to_be_allocated=-3;
4685       return oldNbOfTuples;
4686     }
4687 }
4688
4689 /*!
4690  * Returns number of components in \a this field
4691  *  \return int - the number of components.
4692  */
4693 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4694 {
4695   return getOrCreateAndGetArray()->getNumberOfComponents();
4696 }
4697
4698 /*!
4699  * Change info on components in \a this.
4700  * \throw If size of \a infos is not equal to the number of components already in \a this.
4701  */
4702 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4703 {
4704   DataArray *arr=getOrCreateAndGetArray();
4705   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4706 }
4707
4708 /*!
4709  * Returns info on components of \a this field.
4710  *  \return const std::vector<std::string>& - a sequence of strings each being an
4711  *          information on _i_-th component.
4712  */
4713 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4714 {
4715   const DataArray *arr=getOrCreateAndGetArray();
4716   return arr->getInfoOnComponents();
4717 }
4718
4719 /*!
4720  * Returns a mutable info on components of \a this field.
4721  *  \return std::vector<std::string>& - a sequence of strings each being an
4722  *          information on _i_-th component.
4723  */
4724 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4725 {
4726   DataArray *arr=getOrCreateAndGetArray();
4727   return arr->getInfoOnComponents();
4728 }
4729
4730 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4731 {
4732   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4733     {
4734       const MEDFileFieldPerMesh *fpm(*it);
4735       if(!fpm)
4736         continue;
4737       if(fpm->presenceOfMultiDiscPerGeoType())
4738         return true;
4739     }
4740   return false;
4741 }
4742
4743 /*!
4744  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4745  *  \param [in] type - a spatial discretization of the new field.
4746  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4747  *  \param [in] mName - a name of the supporting mesh.
4748  *  \param [in] renumPol - specifies how to permute values of the result field according to
4749  *          the optional numbers of cells and nodes, if any. The valid values are
4750  *          - 0 - do not permute.
4751  *          - 1 - permute cells.
4752  *          - 2 - permute nodes.
4753  *          - 3 - permute cells and nodes.
4754  *
4755  *  \param [in] glob - the global data storing profiles and localization.
4756  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4757  *          caller is to delete this field using decrRef() as it is no more needed. 
4758  *  \throw If the MED file is not readable.
4759  *  \throw If there is no mesh named \a mName in the MED file.
4760  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4761  *  \throw If no field of \a this is lying on the mesh \a mName.
4762  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4763  */
4764 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4765 {
4766   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4767   if(mName.empty())
4768     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4769   else
4770     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4771   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4772 }
4773
4774 /*!
4775  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4776  *  \param [in] type - a spatial discretization of the new field.
4777  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4778  *  \param [in] renumPol - specifies how to permute values of the result field according to
4779  *          the optional numbers of cells and nodes, if any. The valid values are
4780  *          - 0 - do not permute.
4781  *          - 1 - permute cells.
4782  *          - 2 - permute nodes.
4783  *          - 3 - permute cells and nodes.
4784  *
4785  *  \param [in] glob - the global data storing profiles and localization.
4786  *  \param [in] mesh - the supporting mesh.
4787  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4788  *          caller is to delete this field using decrRef() as it is no more needed. 
4789  *  \throw If the MED file is not readable.
4790  *  \throw If no field of \a this is lying on \a mesh.
4791  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4792  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4793  */
4794 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4795 {
4796   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4797   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4798   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4799   if(meshDimRelToMax==1)
4800     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4801   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4802 }
4803
4804 /*!
4805  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4806  * given mesh. 
4807  *  \param [in] type - a spatial discretization of the new field.
4808  *  \param [in] mName - a name of the supporting mesh.
4809  *  \param [in] renumPol - specifies how to permute values of the result field according to
4810  *          the optional numbers of cells and nodes, if any. The valid values are
4811  *          - 0 - do not permute.
4812  *          - 1 - permute cells.
4813  *          - 2 - permute nodes.
4814  *          - 3 - permute cells and nodes.
4815  *
4816  *  \param [in] glob - the global data storing profiles and localization.
4817  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4818  *          caller is to delete this field using decrRef() as it is no more needed. 
4819  *  \throw If the MED file is not readable.
4820  *  \throw If there is no mesh named \a mName in the MED file.
4821  *  \throw If there are no mesh entities in the mesh.
4822  *  \throw If no field values of the given \a type are available.
4823  */
4824 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4825 {
4826   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4827   if(mName.empty())
4828     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4829   else
4830     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4831   int absDim=getDimension();
4832   int meshDimRelToMax=absDim-mm->getMeshDimension();
4833   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4834 }
4835
4836 /*!
4837  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4838  *  \param [in] type - a spatial discretization of the new field.
4839  *  \param [in] renumPol - specifies how to permute values of the result field according to
4840  *          the optional numbers of cells and nodes, if any. The valid values are
4841  *          - 0 - do not permute.
4842  *          - 1 - permute cells.
4843  *          - 2 - permute nodes.
4844  *          - 3 - permute cells and nodes.
4845  *
4846  *  \param [in] glob - the global data storing profiles and localization.
4847  *  \param [in] mesh - the supporting mesh.
4848  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4849  *         field according to \a renumPol.
4850  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4851  *         field according to \a renumPol.
4852  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4853  *          caller is to delete this field using decrRef() as it is no more needed. 
4854  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4855  *  \throw If no field of \a this is lying on \a mesh.
4856  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4857  */
4858 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
4859 {
4860   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4861   int meshId=getMeshIdFromMeshName(mesh->getName());
4862   bool isPfl=false;
4863   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4864   switch(renumPol)
4865   {
4866     case 0:
4867       {
4868         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4869         return ret.retn();
4870       }
4871     case 3:
4872     case 1:
4873       {
4874         if(isPfl)
4875           throw INTERP_KERNEL::Exception(msg1);
4876         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4877         if(cellRenum)
4878           {
4879             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4880               {
4881                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4882                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4883                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4884               }
4885             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4886             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4887             std::vector<DataArray *> arrOut2(1,arrOut);
4888             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4889             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4890             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4891           }
4892         if(renumPol==1)
4893           return ret.retn();
4894       }
4895     case 2:
4896       {
4897         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4898         if(isPfl)
4899           throw INTERP_KERNEL::Exception(msg1);
4900         if(nodeRenum)
4901           {
4902             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4903               {
4904                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4905                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4906                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4907               }
4908             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4909             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4910               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4911             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4912           }
4913         return ret.retn();
4914       }
4915     default:
4916       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4917   }
4918 }
4919
4920 /*!
4921  * Returns values and a profile of the field of a given type lying on a given support.
4922  *  \param [in] type - a spatial discretization of the field.
4923  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4924  *  \param [in] mesh - the supporting mesh.
4925  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4926  *          field of interest lies on. If the field lies on all entities of the given
4927  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4928  *          using decrRef() as it is no more needed.  
4929  *  \param [in] glob - the global data storing profiles and localization.
4930  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4931  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4932  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4933  *  \throw If no field of \a this is lying on \a mesh.
4934  *  \throw If no field values of the given \a type are available.
4935  */
4936 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4937 {
4938   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4939   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4940   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4941   ret->setName(nasc.getName().c_str());
4942   return ret.retn();
4943 }
4944
4945 //= MEDFileField1TSWithoutSDA
4946
4947 /*!
4948  * Throws if a given value is not a valid (non-extended) relative dimension.
4949  *  \param [in] meshDimRelToMax - the relative dimension value.
4950  *  \throw If \a meshDimRelToMax > 0.
4951  */
4952 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4953 {
4954   if(meshDimRelToMax>0)
4955     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4956 }
4957
4958 /*!
4959  * Checks if elements of a given mesh are in the order suitable for writing 
4960  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4961  * vector describing types of elements and their number.
4962  *  \param [in] mesh - the mesh to check.
4963  *  \return std::vector<int> - a vector holding for each element type (1) item of
4964  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4965  *          These values are in full-interlace mode.
4966  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4967  */
4968 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4969 {
4970   if(!mesh)
4971     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4972   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4973   int nbOfTypes=geoTypes.size();
4974   std::vector<int> code(3*nbOfTypes);
4975   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4976   arr1->alloc(nbOfTypes,1);
4977   int *arrPtr=arr1->getPointer();
4978   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4979   for(int i=0;i<nbOfTypes;i++,it++)
4980     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4981   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4982   const int *arrPtr2=arr2->getConstPointer();
4983   int i=0;
4984   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4985     {
4986       int pos=arrPtr2[i];
4987       int nbCells=mesh->getNumberOfCellsWithType(*it);
4988       code[3*pos]=(int)(*it);
4989       code[3*pos+1]=nbCells;
4990       code[3*pos+2]=-1;//no profiles
4991     }
4992   std::vector<const DataArrayInt *> idsPerType;//no profiles
4993   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4994   if(da)
4995     {
4996       da->decrRef();
4997       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4998     }
4999   return code;
5000 }
5001
5002 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5003 {
5004   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5005 }
5006
5007 /*!
5008  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5009  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5010  * item of every of returned sequences refers to the _i_-th part of \a this field.
5011  * Thus all sequences returned by this method are of the same length equal to number
5012  * of different types of supporting entities.<br>
5013  * A field part can include sub-parts with several different spatial discretizations,
5014  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
5015  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5016  * of a nested sequence corresponds to a type of spatial discretization.<br>
5017  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5018  * The overhead is due to selecting values into new instances of DataArrayDouble.
5019  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5020  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5021  *          not checked if \a mname == \c NULL).
5022  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5023  *          a field part is returned. 
5024  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5025  *          A field part can include sub-parts with several different spatial discretizations,
5026  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
5027  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5028  *          This sequence is of the same length as \a types. 
5029  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5030  *          discretization. A profile name can be empty.
5031  *          Length of this and of nested sequences is the same as that of \a typesF.
5032  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5033  *          discretization. A localization name can be empty.
5034  *          Length of this and of nested sequences is the same as that of \a typesF.
5035  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5036  *          per each type of spatial discretization within one mesh entity type.
5037  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5038  *          Length of this and of nested sequences is the same as that of \a typesF.
5039  *  \throw If no field is lying on \a mname.
5040  */
5041 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
5042 {
5043   int meshId=0;
5044   if(!mname.empty())
5045     meshId=getMeshIdFromMeshName(mname);
5046   else
5047     if(_field_per_mesh.empty())
5048       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5049   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5050   int nbOfRet=ret0.size();
5051   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5052   for(int i=0;i<nbOfRet;i++)
5053     {
5054       const std::vector< std::pair<int,int> >& p=ret0[i];
5055       int nbOfRet1=p.size();
5056       ret[i].resize(nbOfRet1);
5057       for(int j=0;j<nbOfRet1;j++)
5058         {
5059           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
5060           ret[i][j]=tmp;
5061         }
5062     }
5063   return ret;
5064 }
5065
5066 /*!
5067  * Returns a pointer to the underground DataArrayDouble instance. So the
5068  * caller should not decrRef() it. This method allows for a direct access to the field
5069  * values. This method is quite unusable if there is more than a nodal field or a cell
5070  * field on single geometric cell type. 
5071  *  \return DataArrayDouble * - the pointer to the field values array.
5072  */
5073 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
5074 {
5075   const DataArrayDouble *ret=_arr;
5076   if(ret)
5077     return const_cast<DataArrayDouble *>(ret);
5078   else
5079     return 0;
5080 }
5081
5082 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5083 {
5084   return TYPE_STR;
5085 }
5086
5087 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5088 {
5089   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5090   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5091   ret->deepCpyLeavesFrom(*this);
5092   const DataArrayDouble *arr(_arr);
5093   if(arr)
5094     {
5095       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
5096       ret->setArray(arr2);
5097     }
5098   return ret.retn();
5099 }
5100
5101 /*!
5102  * Returns a pointer to the underground DataArrayDouble instance. So the
5103  * caller should not decrRef() it. This method allows for a direct access to the field
5104  * values. This method is quite unusable if there is more than a nodal field or a cell
5105  * field on single geometric cell type. 
5106  *  \return DataArrayDouble * - the pointer to the field values array.
5107  */
5108 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
5109 {
5110   return getUndergroundDataArrayDouble();
5111 }
5112
5113 /*!
5114  * Returns a pointer to the underground DataArrayDouble instance and a
5115  * sequence describing parameters of a support of each part of \a this field. The
5116  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5117  * direct access to the field values. This method is intended for the field lying on one
5118  * mesh only.
5119  *  \param [in,out] entries - the sequence describing parameters of a support of each
5120  *         part of \a this field. Each item of this sequence consists of two parts. The
5121  *         first part describes a type of mesh entity and an id of discretization of a
5122  *         current field part. The second part describes a range of values [begin,end)
5123  *         within the returned array relating to the current field part.
5124  *  \return DataArrayDouble * - the pointer to the field values array.
5125  *  \throw If the number of underlying meshes is not equal to 1.
5126  *  \throw If no field values are available.
5127  *  \sa getUndergroundDataArray()
5128  */
5129 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5130 {
5131   if(_field_per_mesh.size()!=1)
5132     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5133   if(_field_per_mesh[0]==0)
5134     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5135   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5136   return getUndergroundDataArrayDouble();
5137 }
5138
5139 /*!
5140  * Returns a pointer to the underground DataArrayDouble instance and a
5141  * sequence describing parameters of a support of each part of \a this field. The
5142  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5143  * direct access to the field values. This method is intended for the field lying on one
5144  * mesh only.
5145  *  \param [in,out] entries - the sequence describing parameters of a support of each
5146  *         part of \a this field. Each item of this sequence consists of two parts. The
5147  *         first part describes a type of mesh entity and an id of discretization of a
5148  *         current field part. The second part describes a range of values [begin,end)
5149  *         within the returned array relating to the current field part.
5150  *  \return DataArrayDouble * - the pointer to the field values array.
5151  *  \throw If the number of underlying meshes is not equal to 1.
5152  *  \throw If no field values are available.
5153  *  \sa getUndergroundDataArray()
5154  */
5155 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5156 {
5157   return getUndergroundDataArrayDoubleExt(entries);
5158 }
5159
5160 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5161 {
5162   DataArrayDouble *arr(getOrCreateAndGetArrayDouble());
5163   arr->setInfoAndChangeNbOfCompo(infos);
5164 }
5165
5166 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5167 {
5168 }
5169
5170 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5171 {
5172   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5173   ret->deepCpyLeavesFrom(*this);
5174   return ret.retn();
5175 }
5176
5177 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
5178 {
5179   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5180   if((const DataArrayDouble *)_arr)
5181     ret->_arr=_arr->deepCpy();
5182   return ret.retn();
5183 }
5184
5185 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
5186 {
5187   if(!arr)
5188     {
5189       _nb_of_tuples_to_be_allocated=-1;
5190       _arr=0;
5191       return ;
5192     }
5193   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
5194   if(!arrC)
5195     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
5196   else
5197     _nb_of_tuples_to_be_allocated=-3;
5198   arrC->incrRef();
5199   _arr=arrC;
5200 }
5201
5202 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5203 {
5204   return DataArrayDouble::New();
5205 }
5206
5207 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
5208 {
5209   DataArrayDouble *ret=_arr;
5210   if(ret)
5211     return ret;
5212   _arr=DataArrayDouble::New();
5213   return _arr;
5214 }
5215
5216 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
5217 {
5218   return getOrCreateAndGetArrayDouble();
5219 }
5220
5221 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
5222 {
5223   const DataArrayDouble *ret=_arr;
5224   if(ret)
5225     return ret;
5226   DataArrayDouble *ret2=DataArrayDouble::New();
5227   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
5228   return ret2;
5229 }
5230
5231 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
5232 {
5233   return getOrCreateAndGetArrayDouble();
5234 }
5235
5236 //= MEDFileIntField1TSWithoutSDA
5237
5238 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5239 {
5240   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5241 }
5242
5243 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
5244 {
5245 }
5246
5247 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5248                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
5249 {
5250   DataArrayInt *arr(getOrCreateAndGetArrayInt());
5251   arr->setInfoAndChangeNbOfCompo(infos);
5252 }
5253
5254 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5255 {
5256   return TYPE_STR;
5257 }
5258
5259 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5260 {
5261   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5262   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5263   ret->deepCpyLeavesFrom(*this);
5264   const DataArrayInt *arr(_arr);
5265   if(arr)
5266     {
5267       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
5268       ret->setArray(arr2);
5269     }
5270   return ret.retn();
5271 }
5272
5273 /*!
5274  * Returns a pointer to the underground DataArrayInt instance. So the
5275  * caller should not decrRef() it. This method allows for a direct access to the field
5276  * values. This method is quite unusable if there is more than a nodal field or a cell
5277  * field on single geometric cell type. 
5278  *  \return DataArrayInt * - the pointer to the field values array.
5279  */
5280 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5281 {
5282   return getUndergroundDataArrayInt();
5283 }
5284
5285 /*!
5286  * Returns a pointer to the underground DataArrayInt instance. So the
5287  * caller should not decrRef() it. This method allows for a direct access to the field
5288  * values. This method is quite unusable if there is more than a nodal field or a cell
5289  * field on single geometric cell type. 
5290  *  \return DataArrayInt * - the pointer to the field values array.
5291  */
5292 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5293 {
5294   const DataArrayInt *ret=_arr;
5295   if(ret)
5296     return const_cast<DataArrayInt *>(ret);
5297   else
5298     return 0;
5299 }
5300
5301 /*!
5302  * Returns a pointer to the underground DataArrayInt instance and a
5303  * sequence describing parameters of a support of each part of \a this field. The
5304  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5305  * direct access to the field values. This method is intended for the field lying on one
5306  * mesh only.
5307  *  \param [in,out] entries - the sequence describing parameters of a support of each
5308  *         part of \a this field. Each item of this sequence consists of two parts. The
5309  *         first part describes a type of mesh entity and an id of discretization of a
5310  *         current field part. The second part describes a range of values [begin,end)
5311  *         within the returned array relating to the current field part.
5312  *  \return DataArrayInt * - the pointer to the field values array.
5313  *  \throw If the number of underlying meshes is not equal to 1.
5314  *  \throw If no field values are available.
5315  *  \sa getUndergroundDataArray()
5316  */
5317 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5318 {
5319   return getUndergroundDataArrayIntExt(entries);
5320 }
5321
5322 /*!
5323  * Returns a pointer to the underground DataArrayInt instance and a
5324  * sequence describing parameters of a support of each part of \a this field. The
5325  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5326  * direct access to the field values. This method is intended for the field lying on one
5327  * mesh only.
5328  *  \param [in,out] entries - the sequence describing parameters of a support of each
5329  *         part of \a this field. Each item of this sequence consists of two parts. The
5330  *         first part describes a type of mesh entity and an id of discretization of a
5331  *         current field part. The second part describes a range of values [begin,end)
5332  *         within the returned array relating to the current field part.
5333  *  \return DataArrayInt * - the pointer to the field values array.
5334  *  \throw If the number of underlying meshes is not equal to 1.
5335  *  \throw If no field values are available.
5336  *  \sa getUndergroundDataArray()
5337  */
5338 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5339 {
5340   if(_field_per_mesh.size()!=1)
5341     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5342   if(_field_per_mesh[0]==0)
5343     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5344   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5345   return getUndergroundDataArrayInt();
5346 }
5347
5348 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5349 {
5350   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5351   ret->deepCpyLeavesFrom(*this);
5352   return ret.retn();
5353 }
5354
5355 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5356 {
5357   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5358   if((const DataArrayInt *)_arr)
5359     ret->_arr=_arr->deepCpy();
5360   return ret.retn();
5361 }
5362
5363 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5364 {
5365   if(!arr)
5366     {
5367       _nb_of_tuples_to_be_allocated=-1;
5368       _arr=0;
5369       return ;
5370     }
5371   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5372   if(!arrC)
5373     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5374   else
5375     _nb_of_tuples_to_be_allocated=-3;
5376   arrC->incrRef();
5377   _arr=arrC;
5378 }
5379
5380 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5381 {
5382   return DataArrayInt::New();
5383 }
5384
5385 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5386 {
5387   DataArrayInt *ret=_arr;
5388   if(ret)
5389     return ret;
5390   _arr=DataArrayInt::New();
5391   return _arr;
5392 }
5393
5394 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5395 {
5396   return getOrCreateAndGetArrayInt();
5397 }
5398
5399 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5400 {
5401   const DataArrayInt *ret=_arr;
5402   if(ret)
5403     return ret;
5404   DataArrayInt *ret2=DataArrayInt::New();
5405   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5406   return ret2;
5407 }
5408
5409 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5410 {
5411   return getOrCreateAndGetArrayInt();
5412 }
5413
5414 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5415 {
5416 }
5417
5418 //= MEDFileAnyTypeField1TS
5419
5420 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5421 {
5422   med_field_type typcha;
5423   //
5424   std::vector<std::string> infos;
5425   std::string dtunit,fieldName;
5426   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5427   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5428   switch(typcha)
5429   {
5430     case MED_FLOAT64:
5431       {
5432         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5433         break;
5434       }
5435     case MED_INT32:
5436       {
5437         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5438         break;
5439       }
5440     default:
5441       {
5442         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] !";
5443         throw INTERP_KERNEL::Exception(oss.str().c_str());
5444       }
5445   }
5446   ret->setDtUnit(dtunit.c_str());
5447   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5448   //
5449   med_int numdt,numit;
5450   med_float dt;
5451   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5452   ret->setTime(numdt,numit,dt);
5453   ret->_csit=1;
5454   if(loadAll)
5455     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5456   else
5457     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5458   return ret.retn();
5459 }
5460
5461 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
5462 try:MEDFileFieldGlobsReal(fileName)
5463 {
5464   MEDFileUtilities::CheckFileForRead(fileName);
5465   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5466   _content=BuildContentFrom(fid,fileName,loadAll,ms);
5467   loadGlobals(fid);
5468 }
5469 catch(INTERP_KERNEL::Exception& e)
5470 {
5471     throw e;
5472 }
5473
5474 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5475 {
5476   med_field_type typcha;
5477   std::vector<std::string> infos;
5478   std::string dtunit;
5479   int iii=-1;
5480   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5481   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5482   switch(typcha)
5483   {
5484     case MED_FLOAT64:
5485       {
5486         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5487         break;
5488       }
5489     case MED_INT32:
5490       {
5491         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5492         break;
5493       }
5494     default:
5495       {
5496         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] !";
5497         throw INTERP_KERNEL::Exception(oss.str().c_str());
5498       }
5499   }
5500   ret->setDtUnit(dtunit.c_str());
5501   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5502   //
5503   if(nbSteps<1)
5504     {
5505       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5506       throw INTERP_KERNEL::Exception(oss.str().c_str());
5507     }
5508   //
5509   med_int numdt,numit;
5510   med_float dt;
5511   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5512   ret->setTime(numdt,numit,dt);
5513   ret->_csit=1;
5514   if(loadAll)
5515     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5516   else
5517     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5518   return ret.retn();
5519 }
5520
5521 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5522 try:MEDFileFieldGlobsReal(fileName)
5523 {
5524   MEDFileUtilities::CheckFileForRead(fileName);
5525   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5526   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms);
5527   loadGlobals(fid);
5528 }
5529 catch(INTERP_KERNEL::Exception& e)
5530 {
5531     throw e;
5532 }
5533
5534 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5535 {
5536   if(!c)
5537     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5538   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5539     {
5540       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5541       ret->setFileName(fileName);
5542       ret->_content=c; c->incrRef();
5543       return ret.retn();
5544     }
5545   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5546     {
5547       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5548       ret->setFileName(fileName);
5549       ret->_content=c; c->incrRef();
5550       return ret.retn();
5551     }
5552   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5553 }
5554
5555 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5556 {
5557   MEDFileUtilities::CheckFileForRead(fileName);
5558   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5559   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
5560   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5561   ret->loadGlobals(fid);
5562   return ret.retn();
5563 }
5564
5565 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5566 {
5567   MEDFileUtilities::CheckFileForRead(fileName);
5568   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5569   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll,0);
5570   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5571   ret->loadGlobals(fid);
5572   return ret.retn();
5573 }
5574
5575 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5576 {
5577   MEDFileUtilities::CheckFileForRead(fileName);
5578   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5579   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll,0);
5580   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5581   ret->loadGlobals(fid);
5582   return ret.retn();
5583 }
5584
5585 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5586 {
5587   med_field_type typcha;
5588   std::vector<std::string> infos;
5589   std::string dtunit;
5590   int iii=-1;
5591   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5592   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5593   switch(typcha)
5594   {
5595     case MED_FLOAT64:
5596       {
5597         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5598         break;
5599       }
5600     case MED_INT32:
5601       {
5602         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5603         break;
5604       }
5605     default:
5606       {
5607         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] !";
5608         throw INTERP_KERNEL::Exception(oss.str().c_str());
5609       }
5610   }
5611   ret->setDtUnit(dtunit.c_str());
5612   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5613   //
5614   bool found=false;
5615   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5616   for(int i=0;i<nbOfStep2 && !found;i++)
5617     {
5618       med_int numdt,numit;
5619       med_float dt;
5620       MEDfieldComputingStepInfo(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt);
5621       if(numdt==iteration && numit==order)
5622         {
5623           found=true;
5624           ret->_csit=i+1;
5625         }
5626       else
5627         dtits[i]=std::pair<int,int>(numdt,numit);
5628     }
5629   if(!found)
5630     {
5631       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5632       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5633         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5634       throw INTERP_KERNEL::Exception(oss.str().c_str());
5635     }
5636   if(loadAll)
5637     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5638   else
5639     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5640   return ret.retn();
5641 }
5642
5643 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5644 try:MEDFileFieldGlobsReal(fileName)
5645 {
5646   MEDFileUtilities::CheckFileForRead(fileName);
5647   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5648   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll,ms);
5649   loadGlobals(fid);
5650 }
5651 catch(INTERP_KERNEL::Exception& e)
5652 {
5653     throw e;
5654 }
5655
5656 /*!
5657  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5658  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5659  *
5660  * \warning this is a shallow copy constructor
5661  */
5662 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5663 {
5664   if(!shallowCopyOfContent)
5665     {
5666       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5667       otherPtr->incrRef();
5668       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5669     }
5670   else
5671     {
5672       _content=other.shallowCpy();
5673     }
5674 }
5675
5676 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)
5677 {
5678   if(checkFieldId)
5679     {
5680       int nbFields=MEDnField(fid);
5681       if(fieldIdCFormat>=nbFields)
5682         {
5683           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5684           throw INTERP_KERNEL::Exception(oss.str().c_str());
5685         }
5686     }
5687   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5688   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5689   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5690   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5691   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5692   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5693   med_bool localMesh;
5694   int nbOfStep;
5695   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5696   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5697   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5698   infos.clear(); infos.resize(ncomp);
5699   for(int j=0;j<ncomp;j++)
5700     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5701   return nbOfStep;
5702 }
5703
5704 /*!
5705  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5706  * 
5707  * \param [out]
5708  * \return in case of success the number of time steps available for the field with name \a fieldName.
5709  */
5710 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)
5711 {
5712   int nbFields=MEDnField(fid);
5713   bool found=false;
5714   std::vector<std::string> fns(nbFields);
5715   int nbOfStep2=-1;
5716   for(int i=0;i<nbFields && !found;i++)
5717     {
5718       std::string tmp;
5719       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5720       fns[i]=tmp;
5721       found=(tmp==fieldName);
5722       if(found)
5723         posCFormat=i;
5724     }
5725   if(!found)
5726     {
5727       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5728       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5729         oss << "\"" << *it << "\" ";
5730       throw INTERP_KERNEL::Exception(oss.str().c_str());
5731     }
5732   return nbOfStep2;
5733 }
5734
5735 /*!
5736  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5737  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5738  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5739  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5740  * to keep a valid instance.
5741  * 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.
5742  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5743  * 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.
5744  *
5745  * \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.
5746  * \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.
5747  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5748  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5749  * \param [in] newLocName is the new localization name.
5750  * \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.
5751  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5752  */
5753 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5754 {
5755   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5756   std::string oldPflName=disc->getProfile();
5757   std::vector<std::string> vv=getPflsReallyUsedMulti();
5758   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5759   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5760     {
5761       disc->setProfile(newPflName);
5762       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5763       pfl->setName(newPflName);
5764     }
5765   else
5766     {
5767       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5768       throw INTERP_KERNEL::Exception(oss.str().c_str());
5769     }
5770 }
5771
5772 /*!
5773  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5774  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5775  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5776  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5777  * to keep a valid instance.
5778  * 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.
5779  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5780  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5781  * 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.
5782  *
5783  * \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.
5784  * \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.
5785  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5786  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5787  * \param [in] newLocName is the new localization name.
5788  * \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.
5789  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5790  */
5791 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5792 {
5793   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5794   std::string oldLocName=disc->getLocalization();
5795   std::vector<std::string> vv=getLocsReallyUsedMulti();
5796   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5797   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5798     {
5799       disc->setLocalization(newLocName);
5800       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5801       loc.setName(newLocName);
5802     }
5803   else
5804     {
5805       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5806       throw INTERP_KERNEL::Exception(oss.str().c_str());
5807     }
5808 }
5809
5810 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5811 {
5812   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5813   if(!ret)
5814     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5815   return ret;
5816 }
5817
5818 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5819 {
5820   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5821   if(!ret)
5822     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5823   return ret;
5824 }
5825
5826 /*!
5827  * Writes \a this field into a MED file specified by its name.
5828  *  \param [in] fileName - the MED file name.
5829  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5830  * - 2 - erase; an existing file is removed.
5831  * - 1 - append; same data should not be present in an existing file.
5832  * - 0 - overwrite; same data present in an existing file is overwritten.
5833  *  \throw If the field name is not set.
5834  *  \throw If no field data is set.
5835  *  \throw If \a mode == 1 and the same data is present in an existing file.
5836  */
5837 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5838 {
5839   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5840   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5841   writeLL(fid);
5842 }
5843
5844 /*!
5845  * This method alloc the arrays and load potentially huge arrays contained in this field.
5846  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5847  * This method can be also called to refresh or reinit values from a file.
5848  * 
5849  * \throw If the fileName is not set or points to a non readable MED file.
5850  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5851  */
5852 void MEDFileAnyTypeField1TS::loadArrays()
5853 {
5854   if(getFileName().empty())
5855     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5856   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5857   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5858 }
5859
5860 /*!
5861  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5862  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5863  * this method does not throw if \a this does not come from file read.
5864  * 
5865  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5866  */
5867 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5868 {
5869   if(!getFileName().empty())
5870     {
5871       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5872       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5873     }
5874 }
5875
5876 /*!
5877  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5878  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5879  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5880  * 
5881  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5882  */
5883 void MEDFileAnyTypeField1TS::unloadArrays()
5884 {
5885   contentNotNullBase()->unloadArrays();
5886 }
5887
5888 /*!
5889  * 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.
5890  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5891  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5892  * 
5893  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5894  */
5895 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5896 {
5897   if(!getFileName().empty())
5898     contentNotNullBase()->unloadArrays();
5899 }
5900
5901 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5902 {
5903   int nbComp=getNumberOfComponents();
5904   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5905   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5906   for(int i=0;i<nbComp;i++)
5907     {
5908       std::string info=getInfo()[i];
5909       std::string c,u;
5910       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5911       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5912       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5913     }
5914   if(getName().empty())
5915     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5916   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5917   writeGlobals(fid,*this);
5918   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5919 }
5920
5921 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5922 {
5923   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5924 }
5925
5926 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5927 {
5928   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5929   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5930   return ret;
5931 }
5932
5933 /*!
5934  * Returns a string describing \a this field. This string is outputted 
5935  * by \c print Python command.
5936  */
5937 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5938 {
5939   std::ostringstream oss;
5940   contentNotNullBase()->simpleRepr(0,oss,-1);
5941   simpleReprGlobs(oss);
5942   return oss.str();
5943 }
5944
5945 /*!
5946  * This method returns all profiles whose name is non empty used.
5947  * \b WARNING If profile is used several times it will be reported \b only \b once.
5948  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5949  */
5950 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5951 {
5952   return contentNotNullBase()->getPflsReallyUsed2();
5953 }
5954
5955 /*!
5956  * This method returns all localizations whose name is non empty used.
5957  * \b WARNING If localization is used several times it will be reported \b only \b once.
5958  */
5959 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5960 {
5961   return contentNotNullBase()->getLocsReallyUsed2();
5962 }
5963
5964 /*!
5965  * This method returns all profiles whose name is non empty used.
5966  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5967  */
5968 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5969 {
5970   return contentNotNullBase()->getPflsReallyUsedMulti2();
5971 }
5972
5973 /*!
5974  * This method returns all localizations whose name is non empty used.
5975  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5976  */
5977 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5978 {
5979   return contentNotNullBase()->getLocsReallyUsedMulti2();
5980 }
5981
5982 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5983 {
5984   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5985 }
5986
5987 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5988 {
5989   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5990 }
5991
5992 int MEDFileAnyTypeField1TS::getDimension() const
5993 {
5994   return contentNotNullBase()->getDimension();
5995 }
5996
5997 int MEDFileAnyTypeField1TS::getIteration() const
5998 {
5999   return contentNotNullBase()->getIteration();
6000 }
6001
6002 int MEDFileAnyTypeField1TS::getOrder() const
6003 {
6004   return contentNotNullBase()->getOrder();
6005 }
6006
6007 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6008 {
6009   return contentNotNullBase()->getTime(iteration,order);
6010 }
6011
6012 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6013 {
6014   contentNotNullBase()->setTime(iteration,order,val);
6015 }
6016
6017 std::string MEDFileAnyTypeField1TS::getName() const
6018 {
6019   return contentNotNullBase()->getName();
6020 }
6021
6022 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6023 {
6024   contentNotNullBase()->setName(name);
6025 }
6026
6027 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6028 {
6029   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6030 }
6031
6032 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6033 {
6034   return contentNotNullBase()->getDtUnit();
6035 }
6036
6037 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6038 {
6039   contentNotNullBase()->setDtUnit(dtUnit);
6040 }
6041
6042 std::string MEDFileAnyTypeField1TS::getMeshName() const
6043 {
6044   return contentNotNullBase()->getMeshName();
6045 }
6046
6047 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6048 {
6049   contentNotNullBase()->setMeshName(newMeshName);
6050 }
6051
6052 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6053 {
6054   return contentNotNullBase()->changeMeshNames(modifTab);
6055 }
6056
6057 int MEDFileAnyTypeField1TS::getMeshIteration() const
6058 {
6059   return contentNotNullBase()->getMeshIteration();
6060 }
6061
6062 int MEDFileAnyTypeField1TS::getMeshOrder() const
6063 {
6064   return contentNotNullBase()->getMeshOrder();
6065 }
6066
6067 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6068 {
6069   return contentNotNullBase()->getNumberOfComponents();
6070 }
6071
6072 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6073 {
6074   return contentNotNullBase()->isDealingTS(iteration,order);
6075 }
6076
6077 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6078 {
6079   return contentNotNullBase()->getDtIt();
6080 }
6081
6082 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6083 {
6084   contentNotNullBase()->fillIteration(p);
6085 }
6086
6087 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6088 {
6089   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6090 }
6091
6092 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6093 {
6094   contentNotNullBase()->setInfo(infos);
6095 }
6096
6097 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6098 {
6099   return contentNotNullBase()->getInfo();
6100 }
6101 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6102 {
6103   return contentNotNullBase()->getInfo();
6104 }
6105
6106 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6107 {
6108   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6109 }
6110
6111 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6112 {
6113   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6114 }
6115
6116 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6117 {
6118   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6119 }
6120
6121 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6122 {
6123   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6124 }
6125
6126 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6127 {
6128   return contentNotNullBase()->getTypesOfFieldAvailable();
6129 }
6130
6131 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,
6132                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6133 {
6134   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6135 }
6136
6137 /*!
6138  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6139  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6140  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6141  */
6142 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6143 {
6144   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6145   if(!content)
6146     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6147   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6148   std::size_t sz(contentsSplit.size());
6149   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6150   for(std::size_t i=0;i<sz;i++)
6151     {
6152       ret[i]=shallowCpy();
6153       ret[i]->_content=contentsSplit[i];
6154     }
6155   return ret;
6156 }
6157
6158 /*!
6159  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6160  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6161  */
6162 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6163 {
6164   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6165   if(!content)
6166     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6167   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6168   std::size_t sz(contentsSplit.size());
6169   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6170   for(std::size_t i=0;i<sz;i++)
6171     {
6172       ret[i]=shallowCpy();
6173       ret[i]->_content=contentsSplit[i];
6174     }
6175   return ret;
6176 }
6177
6178 /*!
6179  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6180  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6181  */
6182 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6183 {
6184   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6185   if(!content)
6186     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6187   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6188   std::size_t sz(contentsSplit.size());
6189   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
6190   for(std::size_t i=0;i<sz;i++)
6191     {
6192       ret[i]=shallowCpy();
6193       ret[i]->_content=contentsSplit[i];
6194     }
6195   return ret;
6196 }
6197
6198 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
6199 {
6200   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
6201   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6202     ret->_content=_content->deepCpy();
6203   ret->deepCpyGlobs(*this);
6204   return ret.retn();
6205 }
6206
6207 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6208 {
6209   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6210 }
6211
6212 //= MEDFileField1TS
6213
6214 /*!
6215  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6216  * the first field that has been read from a specified MED file.
6217  *  \param [in] fileName - the name of the MED file to read.
6218  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6219  *          is to delete this field using decrRef() as it is no more needed.
6220  *  \throw If reading the file fails.
6221  */
6222 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6223 {
6224   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,loadAll,0));
6225   ret->contentNotNull();
6226   return ret.retn();
6227 }
6228
6229 /*!
6230  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6231  * a given field that has been read from a specified MED file.
6232  *  \param [in] fileName - the name of the MED file to read.
6233  *  \param [in] fieldName - the name of the field to read.
6234  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6235  *          is to delete this field using decrRef() as it is no more needed.
6236  *  \throw If reading the file fails.
6237  *  \throw If there is no field named \a fieldName in the file.
6238  */
6239 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6240 {
6241   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,loadAll,0));
6242   ret->contentNotNull();
6243   return ret.retn();
6244 }
6245
6246 /*!
6247  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6248  * a given field that has been read from a specified MED file.
6249  *  \param [in] fileName - the name of the MED file to read.
6250  *  \param [in] fieldName - the name of the field to read.
6251  *  \param [in] iteration - the iteration number of a required time step.
6252  *  \param [in] order - the iteration order number of required time step.
6253  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6254  *          is to delete this field using decrRef() as it is no more needed.
6255  *  \throw If reading the file fails.
6256  *  \throw If there is no field named \a fieldName in the file.
6257  *  \throw If the required time step is missing from the file.
6258  */
6259 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6260 {
6261   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret(new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll,0));
6262   ret->contentNotNull();
6263   return ret.retn();
6264 }
6265
6266 /*!
6267  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6268  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6269  *
6270  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6271  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6272  * \warning this is a shallow copy constructor
6273  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6274  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6275  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6276  *          is to delete this field using decrRef() as it is no more needed.
6277  */
6278 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6279 {
6280   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
6281   ret->contentNotNull();
6282   return ret.retn();
6283 }
6284
6285 /*!
6286  * Returns a new empty instance of MEDFileField1TS.
6287  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6288  *          is to delete this field using decrRef() as it is no more needed.
6289  */
6290 MEDFileField1TS *MEDFileField1TS::New()
6291 {
6292   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
6293   ret->contentNotNull();
6294   return ret.retn();
6295 }
6296
6297 /*!
6298  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6299  * following the given input policy.
6300  *
6301  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6302  *                            By default (true) the globals are deeply copied.
6303  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6304  */
6305 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6306 {
6307   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
6308   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6309   if(content)
6310     {
6311       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6312       if(!contc)
6313         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6314       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6315       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6316     }
6317   else
6318     ret=MEDFileIntField1TS::New();
6319   if(isDeepCpyGlobs)
6320     ret->deepCpyGlobs(*this);
6321   else
6322     ret->shallowCpyGlobs(*this);
6323   return ret.retn();
6324 }
6325
6326 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6327 {
6328   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6329   if(!pt)
6330     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6331   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6332   if(!ret)
6333     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 !");
6334   return ret;
6335 }
6336
6337 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6338 {
6339   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6340   if(!pt)
6341     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6342   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6343   if(!ret)
6344     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 !");
6345   return ret;
6346 }
6347
6348 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6349 {
6350   if(!f)
6351     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6352   if(!((DataArray*)arr))
6353     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6354   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6355   if(!arrOutC)
6356     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6357   f->setArray(arrOutC);
6358 }
6359
6360 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6361 {
6362   if(!((DataArray*)arr))
6363     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6364   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6365   if(!arrOutC)
6366     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6367   arrOutC->incrRef();
6368   return arrOutC;
6369 }
6370
6371 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6372 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6373 {
6374 }
6375 catch(INTERP_KERNEL::Exception& e)
6376 { throw e; }
6377
6378 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6379 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6380 {
6381 }
6382 catch(INTERP_KERNEL::Exception& e)
6383 { throw e; }
6384
6385 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6386 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6387 {
6388 }
6389 catch(INTERP_KERNEL::Exception& e)
6390 { throw e; }
6391
6392 /*!
6393  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6394  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6395  *
6396  * \warning this is a shallow copy constructor
6397  */
6398 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6399 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6400 {
6401 }
6402 catch(INTERP_KERNEL::Exception& e)
6403 { throw e; }
6404
6405 MEDFileField1TS::MEDFileField1TS()
6406 {
6407   _content=new MEDFileField1TSWithoutSDA;
6408 }
6409
6410 /*!
6411  * Returns a new MEDCouplingFieldDouble of a given type lying on
6412  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6413  * has not been constructed via file reading, an exception is thrown.
6414  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6415  *  \param [in] type - a spatial discretization of interest.
6416  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6417  *  \param [in] renumPol - specifies how to permute values of the result field according to
6418  *          the optional numbers of cells and nodes, if any. The valid values are
6419  *          - 0 - do not permute.
6420  *          - 1 - permute cells.
6421  *          - 2 - permute nodes.
6422  *          - 3 - permute cells and nodes.
6423  *
6424  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6425  *          caller is to delete this field using decrRef() as it is no more needed. 
6426  *  \throw If \a this field has not been constructed via file reading.
6427  *  \throw If the MED file is not readable.
6428  *  \throw If there is no mesh in the MED file.
6429  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6430  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6431  *  \sa getFieldOnMeshAtLevel()
6432  */
6433 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6434 {
6435   if(getFileName().empty())
6436     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6437   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6438   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6439   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6440   return ret.retn();
6441 }
6442
6443 /*!
6444  * Returns a new MEDCouplingFieldDouble of a given type lying on
6445  * the top level cells of the first mesh in MED file. If \a this field 
6446  * has not been constructed via file reading, an exception is thrown.
6447  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6448  *  \param [in] type - a spatial discretization of interest.
6449  *  \param [in] renumPol - specifies how to permute values of the result field according to
6450  *          the optional numbers of cells and nodes, if any. The valid values are
6451  *          - 0 - do not permute.
6452  *          - 1 - permute cells.
6453  *          - 2 - permute nodes.
6454  *          - 3 - permute cells and nodes.
6455  *
6456  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6457  *          caller is to delete this field using decrRef() as it is no more needed. 
6458  *  \throw If \a this field has not been constructed via file reading.
6459  *  \throw If the MED file is not readable.
6460  *  \throw If there is no mesh in the MED file.
6461  *  \throw If no field values of the given \a type.
6462  *  \throw If no field values lying on the top level support.
6463  *  \sa getFieldAtLevel()
6464  */
6465 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6466 {
6467   if(getFileName().empty())
6468     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6469   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6470   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6471   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6472   return ret.retn();
6473 }
6474
6475 /*!
6476  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6477  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6478  *  \param [in] type - a spatial discretization of the new field.
6479  *  \param [in] mesh - the supporting mesh.
6480  *  \param [in] renumPol - specifies how to permute values of the result field according to
6481  *          the optional numbers of cells and nodes, if any. The valid values are
6482  *          - 0 - do not permute.
6483  *          - 1 - permute cells.
6484  *          - 2 - permute nodes.
6485  *          - 3 - permute cells and nodes.
6486  *
6487  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6488  *          caller is to delete this field using decrRef() as it is no more needed. 
6489  *  \throw If no field of \a this is lying on \a mesh.
6490  *  \throw If the mesh is empty.
6491  *  \throw If no field values of the given \a type are available.
6492  *  \sa getFieldAtLevel()
6493  *  \sa getFieldOnMeshAtLevel() 
6494  */
6495 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6496 {
6497   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6498   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6499   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6500   return ret.retn();
6501 }
6502
6503 /*!
6504  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6505  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6506  *  \param [in] type - a spatial discretization of interest.
6507  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6508  *  \param [in] mesh - the supporting mesh.
6509  *  \param [in] renumPol - specifies how to permute values of the result field according to
6510  *          the optional numbers of cells and nodes, if any. The valid values are
6511  *          - 0 - do not permute.
6512  *          - 1 - permute cells.
6513  *          - 2 - permute nodes.
6514  *          - 3 - permute cells and nodes.
6515  *
6516  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6517  *          caller is to delete this field using decrRef() as it is no more needed. 
6518  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6519  *  \throw If no field of \a this is lying on \a mesh.
6520  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6521  *  \sa getFieldAtLevel()
6522  *  \sa getFieldOnMeshAtLevel() 
6523  */
6524 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6525 {
6526   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6527   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6528   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6529   return ret.retn();
6530 }
6531
6532 /*!
6533  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6534  * This method is called "Old" because in MED3 norm a field has only one meshName
6535  * attached, so this method is for readers of MED2 files. If \a this field 
6536  * has not been constructed via file reading, an exception is thrown.
6537  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6538  *  \param [in] type - a spatial discretization of interest.
6539  *  \param [in] mName - a name of the supporting mesh.
6540  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6541  *  \param [in] renumPol - specifies how to permute values of the result field according to
6542  *          the optional numbers of cells and nodes, if any. The valid values are
6543  *          - 0 - do not permute.
6544  *          - 1 - permute cells.
6545  *          - 2 - permute nodes.
6546  *          - 3 - permute cells and nodes.
6547  *
6548  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6549  *          caller is to delete this field using decrRef() as it is no more needed. 
6550  *  \throw If the MED file is not readable.
6551  *  \throw If there is no mesh named \a mName in the MED file.
6552  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6553  *  \throw If \a this field has not been constructed via file reading.
6554  *  \throw If no field of \a this is lying on the mesh named \a mName.
6555  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6556  *  \sa getFieldAtLevel()
6557  */
6558 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6559 {
6560   if(getFileName().empty())
6561     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6562   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6563   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6564   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6565   return ret.retn();
6566 }
6567
6568 /*!
6569  * Returns values and a profile of the field of a given type lying on a given support.
6570  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6571  *  \param [in] type - a spatial discretization of the field.
6572  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6573  *  \param [in] mesh - the supporting mesh.
6574  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6575  *          field of interest lies on. If the field lies on all entities of the given
6576  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6577  *          using decrRef() as it is no more needed.  
6578  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6579  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6580  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6581  *  \throw If no field of \a this is lying on \a mesh.
6582  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6583  */
6584 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6585 {
6586   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6587   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6588 }
6589
6590 /*!
6591  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6592  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6593  * "Sort By Type"), if not, an exception is thrown. 
6594  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6595  *  \param [in] field - the field to add to \a this.
6596  *  \throw If the name of \a field is empty.
6597  *  \throw If the data array of \a field is not set.
6598  *  \throw If the data array is already allocated but has different number of components
6599  *         than \a field.
6600  *  \throw If the underlying mesh of \a field has no name.
6601  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6602  */
6603 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6604 {
6605   setFileName("");
6606   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6607 }
6608
6609 /*!
6610  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6611  * can be an aggregation of several MEDCouplingFieldDouble instances.
6612  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6613  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6614  * and \a profile.
6615  *
6616  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6617  * A new profile is added only if no equal profile is missing.
6618  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6619  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6620  *  \param [in] mesh - the supporting mesh of \a field.
6621  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6622  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6623  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6624  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6625  *  \throw If the data array of \a field is not set.
6626  *  \throw If the data array of \a this is already allocated but has different number of
6627  *         components than \a field.
6628  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6629  *  \sa setFieldNoProfileSBT()
6630  */
6631 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6632 {
6633   setFileName("");
6634   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6635 }
6636
6637 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6638 {
6639   return new MEDFileField1TS(*this);
6640 }
6641
6642 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6643 {
6644   return contentNotNull()->getUndergroundDataArrayDouble();
6645 }
6646
6647 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6648 {
6649   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6650 }
6651
6652 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6653                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6654 {
6655   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6656 }
6657
6658 //= MEDFileIntField1TS
6659
6660 MEDFileIntField1TS *MEDFileIntField1TS::New()
6661 {
6662   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6663   ret->contentNotNull();
6664   return ret.retn();
6665 }
6666
6667 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6668 {
6669   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,loadAll,0));
6670   ret->contentNotNull();
6671   return ret.retn();
6672 }
6673
6674 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6675 {
6676   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,loadAll,0));
6677   ret->contentNotNull();
6678   return ret.retn();
6679 }
6680
6681 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6682 {
6683   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll,0));
6684   ret->contentNotNull();
6685   return ret.retn();
6686 }
6687
6688 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6689 {
6690   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6691   ret->contentNotNull();
6692   return ret.retn();
6693 }
6694
6695 MEDFileIntField1TS::MEDFileIntField1TS()
6696 {
6697   _content=new MEDFileIntField1TSWithoutSDA;
6698 }
6699
6700 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
6701 try:MEDFileAnyTypeField1TS(fileName,loadAll,ms)
6702 {
6703 }
6704 catch(INTERP_KERNEL::Exception& e)
6705 { throw e; }
6706
6707 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6708 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll,ms)
6709 {
6710 }
6711 catch(INTERP_KERNEL::Exception& e)
6712 { throw e; }
6713
6714 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6715 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll,ms)
6716 {
6717 }
6718 catch(INTERP_KERNEL::Exception& e)
6719 { throw e; }
6720
6721 /*!
6722  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6723  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6724  *
6725  * \warning this is a shallow copy constructor
6726  */
6727 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6728 {
6729 }
6730
6731 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6732 {
6733   return new MEDFileIntField1TS(*this);
6734 }
6735
6736 /*!
6737  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6738  * following the given input policy.
6739  *
6740  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6741  *                            By default (true) the globals are deeply copied.
6742  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6743  */
6744 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6745 {
6746   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6747   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6748   if(content)
6749     {
6750       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6751       if(!contc)
6752         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6753       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6754       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6755     }
6756   else
6757     ret=MEDFileField1TS::New();
6758   if(isDeepCpyGlobs)
6759     ret->deepCpyGlobs(*this);
6760   else
6761     ret->shallowCpyGlobs(*this);
6762   return ret.retn();
6763 }
6764
6765 /*!
6766  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6767  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6768  * "Sort By Type"), if not, an exception is thrown. 
6769  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6770  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6771  *  \param [in] arrOfVals - the values of the field \a field used.
6772  *  \throw If the name of \a field is empty.
6773  *  \throw If the data array of \a field is not set.
6774  *  \throw If the data array is already allocated but has different number of components
6775  *         than \a field.
6776  *  \throw If the underlying mesh of \a field has no name.
6777  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6778  */
6779 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6780 {
6781   setFileName("");
6782   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6783 }
6784
6785 /*!
6786  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6787  * can be an aggregation of several MEDCouplingFieldDouble instances.
6788  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6789  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6790  * and \a profile.
6791  *
6792  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6793  * A new profile is added only if no equal profile is missing.
6794  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6795  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6796  *  \param [in] arrOfVals - the values of the field \a field used.
6797  *  \param [in] mesh - the supporting mesh of \a field.
6798  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6799  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6800  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6801  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6802  *  \throw If the data array of \a field is not set.
6803  *  \throw If the data array of \a this is already allocated but has different number of
6804  *         components than \a field.
6805  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6806  *  \sa setFieldNoProfileSBT()
6807  */
6808 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6809 {
6810   setFileName("");
6811   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6812 }
6813
6814 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6815 {
6816   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6817   if(!pt)
6818     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6819   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6820   if(!ret)
6821     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 !");
6822   return ret;
6823 }
6824
6825 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6826 {
6827   if(getFileName().empty())
6828     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6829   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6830   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6831   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6832   if(!arrOutC)
6833     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6834   arrOut=arrOutC;
6835   arrOut->incrRef();  // arrOut2 dies at the end of the func
6836   return ret.retn();
6837 }
6838
6839 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6840 {
6841   if(!((DataArray *)arr))
6842     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6843   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6844   if(!arrC)
6845     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6846   arrC->incrRef();
6847   return arrC;
6848 }
6849
6850 /*!
6851  * Returns a new MEDCouplingFieldDouble of a given type lying on
6852  * the top level cells of the first mesh in MED file. If \a this field 
6853  * has not been constructed via file reading, an exception is thrown.
6854  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6855  *  \param [in] type - a spatial discretization of interest.
6856  *  \param [out] arrOut - the DataArrayInt containing values of field.
6857  *  \param [in] renumPol - specifies how to permute values of the result field according to
6858  *          the optional numbers of cells and nodes, if any. The valid values are
6859  *          - 0 - do not permute.
6860  *          - 1 - permute cells.
6861  *          - 2 - permute nodes.
6862  *          - 3 - permute cells and nodes.
6863  *
6864  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6865  *          caller is to delete this field using decrRef() as it is no more needed. 
6866  *  \throw If \a this field has not been constructed via file reading.
6867  *  \throw If the MED file is not readable.
6868  *  \throw If there is no mesh in the MED file.
6869  *  \throw If no field values of the given \a type.
6870  *  \throw If no field values lying on the top level support.
6871  *  \sa getFieldAtLevel()
6872  */
6873 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6874 {
6875   if(getFileName().empty())
6876     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6877   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6878   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6879   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6880   return ret.retn();
6881 }
6882
6883 /*!
6884  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6885  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6886  *  \param [in] type - a spatial discretization of the new field.
6887  *  \param [in] mesh - the supporting mesh.
6888  *  \param [out] arrOut - the DataArrayInt containing values of field.
6889  *  \param [in] renumPol - specifies how to permute values of the result field according to
6890  *          the optional numbers of cells and nodes, if any. The valid values are
6891  *          - 0 - do not permute.
6892  *          - 1 - permute cells.
6893  *          - 2 - permute nodes.
6894  *          - 3 - permute cells and nodes.
6895  *
6896  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6897  *          caller is to delete this field using decrRef() as it is no more needed. 
6898  *  \throw If no field of \a this is lying on \a mesh.
6899  *  \throw If the mesh is empty.
6900  *  \throw If no field values of the given \a type are available.
6901  *  \sa getFieldAtLevel()
6902  *  \sa getFieldOnMeshAtLevel() 
6903  */
6904 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6905 {
6906   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6907   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6908   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6909   return ret.retn();
6910 }
6911
6912 /*!
6913  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6914  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6915  *  \param [in] type - a spatial discretization of interest.
6916  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6917  *  \param [out] arrOut - the DataArrayInt containing values of field.
6918  *  \param [in] mesh - the supporting mesh.
6919  *  \param [in] renumPol - specifies how to permute values of the result field according to
6920  *          the optional numbers of cells and nodes, if any. The valid values are
6921  *          - 0 - do not permute.
6922  *          - 1 - permute cells.
6923  *          - 2 - permute nodes.
6924  *          - 3 - permute cells and nodes.
6925  *
6926  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6927  *          caller is to delete this field using decrRef() as it is no more needed. 
6928  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6929  *  \throw If no field of \a this is lying on \a mesh.
6930  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6931  *  \sa getFieldAtLevel()
6932  *  \sa getFieldOnMeshAtLevel() 
6933  */
6934 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6935 {
6936   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6937   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6938   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6939   return ret.retn();
6940 }
6941
6942 /*!
6943  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6944  * This method is called "Old" because in MED3 norm a field has only one meshName
6945  * attached, so this method is for readers of MED2 files. If \a this field 
6946  * has not been constructed via file reading, an exception is thrown.
6947  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6948  *  \param [in] type - a spatial discretization of interest.
6949  *  \param [in] mName - a name of the supporting mesh.
6950  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6951  *  \param [out] arrOut - the DataArrayInt containing values of field.
6952  *  \param [in] renumPol - specifies how to permute values of the result field according to
6953  *          the optional numbers of cells and nodes, if any. The valid values are
6954  *          - 0 - do not permute.
6955  *          - 1 - permute cells.
6956  *          - 2 - permute nodes.
6957  *          - 3 - permute cells and nodes.
6958  *
6959  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6960  *          caller is to delete this field using decrRef() as it is no more needed. 
6961  *  \throw If the MED file is not readable.
6962  *  \throw If there is no mesh named \a mName in the MED file.
6963  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6964  *  \throw If \a this field has not been constructed via file reading.
6965  *  \throw If no field of \a this is lying on the mesh named \a mName.
6966  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6967  *  \sa getFieldAtLevel()
6968  */
6969 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6970 {
6971   if(getFileName().empty())
6972     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6973   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6974   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6975   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6976   return ret.retn();
6977 }
6978
6979 /*!
6980  * Returns values and a profile of the field of a given type lying on a given support.
6981  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6982  *  \param [in] type - a spatial discretization of the field.
6983  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6984  *  \param [in] mesh - the supporting mesh.
6985  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6986  *          field of interest lies on. If the field lies on all entities of the given
6987  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6988  *          using decrRef() as it is no more needed.  
6989  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6990  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6991  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6992  *  \throw If no field of \a this is lying on \a mesh.
6993  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6994  */
6995 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6996 {
6997   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6998   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6999 }
7000
7001 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7002 {
7003   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7004   if(!pt)
7005     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7006   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7007   if(!ret)
7008     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 !");
7009   return ret;
7010 }
7011
7012 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7013 {
7014   return contentNotNull()->getUndergroundDataArrayInt();
7015 }
7016
7017 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7018
7019 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7020 {
7021 }
7022
7023 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7024 {
7025 }
7026
7027 /*!
7028  * \param [in] fieldId field id in C mode
7029  */
7030 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7031 {
7032   med_field_type typcha;
7033   std::string dtunitOut;
7034   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
7035   setDtUnit(dtunitOut.c_str());
7036   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7037 }
7038
7039 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7040 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7041 {
7042   setDtUnit(dtunit.c_str());
7043   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7044 }
7045 catch(INTERP_KERNEL::Exception& e)
7046 {
7047     throw e;
7048 }
7049
7050 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7051 {
7052   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
7053   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7054     ret+=(*it).capacity();
7055   return ret;
7056 }
7057
7058 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7059 {
7060   std::vector<const BigMemoryObject *> ret;
7061   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7062     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7063   return ret;
7064 }
7065
7066 /*!
7067  * 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
7068  * NULL.
7069  */
7070 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7071 {
7072   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7073   ret->setInfo(_infos);
7074   int sz=(int)_time_steps.size();
7075   for(const int *id=startIds;id!=endIds;id++)
7076     {
7077       if(*id>=0 && *id<sz)
7078         {
7079           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7080           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7081           if(tse)
7082             {
7083               tse->incrRef();
7084               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7085             }
7086           ret->pushBackTimeStep(tse2);
7087         }
7088       else
7089         {
7090           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7091           oss << " ! Should be in [0," << sz << ") !";
7092           throw INTERP_KERNEL::Exception(oss.str().c_str());
7093         }
7094     }
7095   if(ret->getNumberOfTS()>0)
7096     ret->synchronizeNameScope();
7097   ret->copyNameScope(*this);
7098   return ret.retn();
7099 }
7100
7101 /*!
7102  * 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
7103  * NULL.
7104  */
7105 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7106 {
7107   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7108   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7109   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7110   ret->setInfo(_infos);
7111   int sz=(int)_time_steps.size();
7112   int j=bg;
7113   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7114     {
7115       if(j>=0 && j<sz)
7116         {
7117           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7118           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7119           if(tse)
7120             {
7121               tse->incrRef();
7122               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7123             }
7124           ret->pushBackTimeStep(tse2);
7125         }
7126       else
7127         {
7128           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7129           oss << " ! Should be in [0," << sz << ") !";
7130           throw INTERP_KERNEL::Exception(oss.str().c_str());
7131         }
7132     }
7133   if(ret->getNumberOfTS()>0)
7134     ret->synchronizeNameScope();
7135   ret->copyNameScope(*this);
7136   return ret.retn();
7137 }
7138
7139 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7140 {
7141   int id=0;
7142   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7143   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7144     {
7145       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7146       if(!cur)
7147         continue;
7148       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7149       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7150         ids->pushBackSilent(id);
7151     }
7152   return buildFromTimeStepIds(ids->begin(),ids->end());
7153 }
7154
7155 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7156 {
7157   int id=0;
7158   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7159   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7160     {
7161       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7162       if(!cur)
7163         continue;
7164       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7165       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7166         ids->pushBackSilent(id);
7167     }
7168   return buildFromTimeStepIds(ids->begin(),ids->end());
7169 }
7170
7171 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7172 {
7173   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7174     {
7175       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7176       if(!cur)
7177         continue;
7178       if(cur->presenceOfMultiDiscPerGeoType())
7179         return true;
7180     }
7181   return false;
7182 }
7183
7184 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7185 {
7186   return _infos;
7187 }
7188
7189 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7190 {
7191   _infos=info;
7192 }
7193
7194 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7195 {
7196   int ret=0;
7197   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7198     {
7199       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7200       if(pt->isDealingTS(iteration,order))
7201         return ret;
7202     }
7203   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7204   std::vector< std::pair<int,int> > vp=getIterations();
7205   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7206     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7207   throw INTERP_KERNEL::Exception(oss.str().c_str());
7208 }
7209
7210 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7211 {
7212   return *_time_steps[getTimeStepPos(iteration,order)];
7213 }
7214
7215 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7216 {
7217   return *_time_steps[getTimeStepPos(iteration,order)];
7218 }
7219
7220 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7221 {
7222   if(_time_steps.empty())
7223     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7224   return _time_steps[0]->getMeshName();
7225 }
7226
7227 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7228 {
7229   std::string oldName(getMeshName());
7230   std::vector< std::pair<std::string,std::string> > v(1);
7231   v[0].first=oldName; v[0].second=newMeshName;
7232   changeMeshNames(v);
7233 }
7234
7235 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7236 {
7237   bool ret=false;
7238   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7239     {
7240       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7241       if(cur)
7242         ret=cur->changeMeshNames(modifTab) || ret;
7243     }
7244   return ret;
7245 }
7246
7247 /*!
7248  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7249  */
7250 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7251 {
7252   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7253 }
7254
7255 /*!
7256  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7257  */
7258 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7259 {
7260   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7261 }
7262
7263 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7264                                                                        MEDFileFieldGlobsReal& glob)
7265 {
7266   bool ret=false;
7267   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7268     {
7269       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7270       if(f1ts)
7271         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7272     }
7273   return ret;
7274 }
7275
7276 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7277 {
7278   std::string startLine(bkOffset,' ');
7279   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7280   if(fmtsId>=0)
7281     oss << " (" << fmtsId << ")";
7282   oss << " has the following name: \"" << _name << "\"." << std::endl;
7283   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7284   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7285     {
7286       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7287     }
7288   int i=0;
7289   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7290     {
7291       std::string chapter(17,'0'+i);
7292       oss << startLine << chapter << std::endl;
7293       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7294       if(cur)
7295         cur->simpleRepr(bkOffset+2,oss,i);
7296       else
7297         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7298       oss << startLine << chapter << std::endl;
7299     }
7300 }
7301
7302 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7303 {
7304   std::size_t sz=_time_steps.size();
7305   std::vector< std::pair<int,int> > ret(sz);
7306   ret1.resize(sz);
7307   for(std::size_t i=0;i<sz;i++)
7308     {
7309       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7310       if(f1ts)
7311         {
7312           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7313         }
7314       else
7315         {
7316           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7317           throw INTERP_KERNEL::Exception(oss.str().c_str());
7318         }
7319     }
7320   return ret;
7321 }
7322
7323 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7324 {
7325   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7326   if(!tse2)
7327     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7328   checkCoherencyOfType(tse2);
7329   if(_time_steps.empty())
7330     {
7331       setName(tse2->getName().c_str());
7332       setInfo(tse2->getInfo());
7333     }
7334   checkThatComponentsMatch(tse2->getInfo());
7335   _time_steps.push_back(tse);
7336 }
7337
7338 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7339 {
7340   std::size_t nbOfCompo=_infos.size();
7341   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7342     {
7343       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7344       if(cur)
7345         {
7346           if((cur->getInfo()).size()!=nbOfCompo)
7347             {
7348               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7349               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7350               throw INTERP_KERNEL::Exception(oss.str().c_str());
7351             }
7352           cur->copyNameScope(*this);
7353         }
7354     }
7355 }
7356
7357 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7358 {
7359   _time_steps.resize(nbPdt);
7360   for(int i=0;i<nbPdt;i++)
7361     {
7362       std::vector< std::pair<int,int> > ts;
7363       med_int numdt=0,numo=0;
7364       med_int meshIt=0,meshOrder=0;
7365       med_float dt=0.0;
7366       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
7367       switch(fieldTyp)
7368       {
7369         case MED_FLOAT64:
7370           {
7371             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7372             break;
7373           }
7374         case MED_INT32:
7375           {
7376             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7377             break;
7378           }
7379         default:
7380           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7381       }
7382       if(loadAll)
7383         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7384       else
7385         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7386     }
7387 }
7388
7389 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7390 {
7391   if(_time_steps.empty())
7392     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7393   checkThatNbOfCompoOfTSMatchThis();
7394   std::vector<std::string> infos(getInfo());
7395   int nbComp=infos.size();
7396   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7397   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7398   for(int i=0;i<nbComp;i++)
7399     {
7400       std::string info=infos[i];
7401       std::string c,u;
7402       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7403       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7404       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7405     }
7406   if(_name.empty())
7407     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7408   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7409   int nbOfTS=_time_steps.size();
7410   for(int i=0;i<nbOfTS;i++)
7411     _time_steps[i]->writeLL(fid,opts,*this);
7412 }
7413
7414 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7415 {
7416   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7417     {
7418       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7419       if(elt)
7420         elt->loadBigArraysRecursively(fid,nasc);
7421     }
7422 }
7423
7424 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7425 {
7426   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7427     {
7428       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7429       if(elt)
7430         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7431     }
7432 }
7433
7434 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7435 {
7436   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7437     {
7438       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7439       if(elt)
7440         elt->unloadArrays();
7441     }
7442 }
7443
7444 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7445 {
7446   return _time_steps.size();
7447 }
7448
7449 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7450 {
7451   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7452   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7453     {
7454       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7455       if(tmp)
7456         newTS.push_back(*it);
7457     }
7458   _time_steps=newTS;
7459 }
7460
7461 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7462 {
7463   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7464   int maxId=(int)_time_steps.size();
7465   int ii=0;
7466   std::set<int> idsToDel;
7467   for(const int *id=startIds;id!=endIds;id++,ii++)
7468     {
7469       if(*id>=0 && *id<maxId)
7470         {
7471           idsToDel.insert(*id);
7472         }
7473       else
7474         {
7475           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7476           throw INTERP_KERNEL::Exception(oss.str().c_str());
7477         }
7478     }
7479   for(int iii=0;iii<maxId;iii++)
7480     if(idsToDel.find(iii)==idsToDel.end())
7481       newTS.push_back(_time_steps[iii]);
7482   _time_steps=newTS;
7483 }
7484
7485 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7486 {
7487   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7488   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7489   if(nbOfEntriesToKill==0)
7490     return ;
7491   std::size_t sz=_time_steps.size();
7492   std::vector<bool> b(sz,true);
7493   int j=bg;
7494   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7495     b[j]=false;
7496   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7497   for(std::size_t i=0;i<sz;i++)
7498     if(b[i])
7499       newTS.push_back(_time_steps[i]);
7500   _time_steps=newTS;
7501 }
7502
7503 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7504 {
7505   int ret=0;
7506   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7507   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7508     {
7509       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7510       if(tmp)
7511         {
7512           int it2,ord;
7513           tmp->getTime(it2,ord);
7514           if(it2==iteration && order==ord)
7515             return ret;
7516           else
7517             oss << "(" << it2 << ","  << ord << "), ";
7518         }
7519     }
7520   throw INTERP_KERNEL::Exception(oss.str().c_str());
7521 }
7522
7523 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7524 {
7525   int ret=0;
7526   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7527   oss.precision(15);
7528   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7529     {
7530       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7531       if(tmp)
7532         {
7533           int it2,ord;
7534           double ti=tmp->getTime(it2,ord);
7535           if(fabs(time-ti)<eps)
7536             return ret;
7537           else
7538             oss << ti << ", ";
7539         }
7540     }
7541   throw INTERP_KERNEL::Exception(oss.str().c_str());
7542 }
7543
7544 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7545 {
7546   int lgth=_time_steps.size();
7547   std::vector< std::pair<int,int> > ret(lgth);
7548   for(int i=0;i<lgth;i++)
7549     _time_steps[i]->fillIteration(ret[i]);
7550   return ret;
7551 }
7552
7553 /*!
7554  * 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'
7555  * This method returns two things.
7556  * - The absolute dimension of 'this' in first parameter. 
7557  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7558  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7559  *
7560  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7561  * Only these 3 discretizations will be taken into account here.
7562  *
7563  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7564  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7565  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7566  *
7567  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7568  * 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'.
7569  * 
7570  * Let's consider the typical following case :
7571  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7572  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7573  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7574  *   TETRA4 and SEG2
7575  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7576  *
7577  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7578  * 
7579  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7580  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7581  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7582  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7583  */
7584 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7585 {
7586   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7587 }
7588
7589 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7590 {
7591   if(pos<0 || pos>=(int)_time_steps.size())
7592     {
7593       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7594       throw INTERP_KERNEL::Exception(oss.str().c_str());
7595     }
7596   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7597   if(item==0)
7598     {
7599       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7600       oss << "\nTry to use following method eraseEmptyTS !";
7601       throw INTERP_KERNEL::Exception(oss.str().c_str());
7602     }
7603   return item;
7604 }
7605
7606 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7607 {
7608   if(pos<0 || pos>=(int)_time_steps.size())
7609     {
7610       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7611       throw INTERP_KERNEL::Exception(oss.str().c_str());
7612     }
7613   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7614   if(item==0)
7615     {
7616       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7617       oss << "\nTry to use following method eraseEmptyTS !";
7618       throw INTERP_KERNEL::Exception(oss.str().c_str());
7619     }
7620   return item;
7621 }
7622
7623 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7624 {
7625   std::vector<std::string> ret;
7626   std::set<std::string> ret2;
7627   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7628     {
7629       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7630       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7631         if(ret2.find(*it2)==ret2.end())
7632           {
7633             ret.push_back(*it2);
7634             ret2.insert(*it2);
7635           }
7636     }
7637   return ret;
7638 }
7639
7640 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7641 {
7642   std::vector<std::string> ret;
7643   std::set<std::string> ret2;
7644   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7645     {
7646       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7647       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7648         if(ret2.find(*it2)==ret2.end())
7649           {
7650             ret.push_back(*it2);
7651             ret2.insert(*it2);
7652           }
7653     }
7654   return ret;
7655 }
7656
7657 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7658 {
7659   std::vector<std::string> ret;
7660   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7661     {
7662       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7663       ret.insert(ret.end(),tmp.begin(),tmp.end());
7664     }
7665   return ret;
7666 }
7667
7668 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7669 {
7670   std::vector<std::string> ret;
7671   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7672     {
7673       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7674       ret.insert(ret.end(),tmp.begin(),tmp.end());
7675     }
7676   return ret;
7677 }
7678
7679 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7680 {
7681   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7682     (*it)->changePflsRefsNamesGen2(mapOfModif);
7683 }
7684
7685 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7686 {
7687   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7688     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7689 }
7690
7691 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7692 {
7693   int lgth=_time_steps.size();
7694   std::vector< std::vector<TypeOfField> > ret(lgth);
7695   for(int i=0;i<lgth;i++)
7696     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7697   return ret;
7698 }
7699
7700 /*!
7701  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7702  */
7703 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
7704 {
7705   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7706 }
7707
7708 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7709 {
7710   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7711   std::size_t i=0;
7712   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7713     {
7714       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7715         ret->_time_steps[i]=(*it)->deepCpy();
7716     }
7717   return ret.retn();
7718 }
7719
7720 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7721 {
7722   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7723   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7724   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7725   for(std::size_t i=0;i<sz;i++)
7726     {
7727       ret[i]=shallowCpy();
7728       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7729     }
7730   for(std::size_t i=0;i<sz2;i++)
7731     {
7732       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7733       if(ret1.size()!=sz)
7734         {
7735           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7736           throw INTERP_KERNEL::Exception(oss.str().c_str());
7737         }
7738       ts[i]=ret1;
7739     }
7740   for(std::size_t i=0;i<sz;i++)
7741     for(std::size_t j=0;j<sz2;j++)
7742       ret[i]->_time_steps[j]=ts[j][i];
7743   return ret;
7744 }
7745
7746 /*!
7747  * This method splits into discretization each time steps in \a this.
7748  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7749  */
7750 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7751 {
7752   std::size_t sz(_time_steps.size());
7753   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7754   for(std::size_t i=0;i<sz;i++)
7755     {
7756       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7757       if(!timeStep)
7758         {
7759           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7760           throw INTERP_KERNEL::Exception(oss.str().c_str());
7761         }
7762       items[i]=timeStep->splitDiscretizations();  
7763     }
7764   //
7765   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7766   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7767   std::vector< TypeOfField > types;
7768   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7769     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7770       {
7771         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7772         if(ts.size()!=1)
7773           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7774         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7775         if(it2==types.end())
7776           types.push_back(ts[0]);
7777       }
7778   ret.resize(types.size()); ret2.resize(types.size());
7779   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7780     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7781       {
7782         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7783         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7784         ret2[pos].push_back(*it1);
7785       }
7786   for(std::size_t i=0;i<types.size();i++)
7787     {
7788       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7789       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7790         elt->pushBackTimeStep(*it1);//also updates infos in elt
7791       ret[i]=elt;
7792       elt->MEDFileFieldNameScope::operator=(*this);
7793     }
7794   return ret;
7795 }
7796
7797 /*!
7798  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7799  */
7800 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7801 {
7802   std::size_t sz(_time_steps.size());
7803   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7804   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7805   for(std::size_t i=0;i<sz;i++)
7806     {
7807       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7808       if(!timeStep)
7809         {
7810           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7811           throw INTERP_KERNEL::Exception(oss.str().c_str());
7812         }
7813       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7814       if(szOut==std::numeric_limits<std::size_t>::max())
7815         szOut=items[i].size();
7816       else
7817         if(items[i].size()!=szOut)
7818           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7819     }
7820   if(szOut==std::numeric_limits<std::size_t>::max())
7821     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7822   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7823   for(std::size_t i=0;i<szOut;i++)
7824     {
7825       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7826       for(std::size_t j=0;j<sz;j++)
7827         elt->pushBackTimeStep(items[j][i]);
7828       ret[i]=elt;
7829       elt->MEDFileFieldNameScope::operator=(*this);
7830     }
7831   return ret;
7832 }
7833
7834 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7835 {
7836   _name=field->getName();
7837   if(_name.empty())
7838     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7839   if(!arr)
7840     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7841   _infos=arr->getInfoOnComponents();
7842 }
7843
7844 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7845 {
7846   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7847   if(_name!=field->getName())
7848     {
7849       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7850       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7851       throw INTERP_KERNEL::Exception(oss.str().c_str());
7852     }
7853   if(!arr)
7854     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7855   checkThatComponentsMatch(arr->getInfoOnComponents());
7856 }
7857
7858 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7859 {
7860   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7861   if(getInfo().size()!=compos.size())
7862     {
7863       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7864       oss << " number of components of element to append (" << compos.size() << ") !";
7865       throw INTERP_KERNEL::Exception(oss.str().c_str());
7866     }
7867   if(_infos!=compos)
7868     {
7869       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7870       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7871       oss << " But compo in input fields are : ";
7872       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7873       oss << " !";
7874       throw INTERP_KERNEL::Exception(oss.str().c_str());
7875     }
7876 }
7877
7878 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7879 {
7880   std::size_t sz=_infos.size();
7881   int j=0;
7882   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7883     {
7884       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7885       if(elt)
7886         if(elt->getInfo().size()!=sz)
7887           {
7888             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7889             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7890             throw INTERP_KERNEL::Exception(oss.str().c_str());
7891           }
7892     }
7893 }
7894
7895 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7896 {
7897   if(!field)
7898     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7899   if(!_time_steps.empty())
7900     checkCoherencyOfTinyInfo(field,arr);
7901   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7902   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7903   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7904   copyTinyInfoFrom(field,arr);
7905   _time_steps.push_back(obj);
7906 }
7907
7908 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7909 {
7910   if(!field)
7911     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7912   if(!_time_steps.empty())
7913     checkCoherencyOfTinyInfo(field,arr);
7914   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7915   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7916   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7917   copyTinyInfoFrom(field,arr);
7918   _time_steps.push_back(obj);
7919 }
7920
7921 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7922 {
7923   int sz=(int)_time_steps.size();
7924   if(i<0 || i>=sz)
7925     {
7926       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7927       throw INTERP_KERNEL::Exception(oss.str().c_str());
7928     }
7929   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7930   if(tsPtr)
7931     {
7932       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7933         {
7934           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7935           throw INTERP_KERNEL::Exception(oss.str().c_str());
7936         }
7937     }
7938   _time_steps[i]=ts;
7939 }
7940
7941 //= MEDFileFieldMultiTSWithoutSDA
7942
7943 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7944 {
7945   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
7946 }
7947
7948 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7949 {
7950 }
7951
7952 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7953 {
7954 }
7955
7956 /*!
7957  * \param [in] fieldId field id in C mode
7958  */
7959 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7960 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
7961 {
7962 }
7963 catch(INTERP_KERNEL::Exception& e)
7964 { throw e; }
7965
7966 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
7967 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
7968 {
7969 }
7970 catch(INTERP_KERNEL::Exception& e)
7971 { throw e; }
7972
7973 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7974 {
7975   return new MEDFileField1TSWithoutSDA;
7976 }
7977
7978 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7979 {
7980   if(!f1ts)
7981     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7982   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7983   if(!f1tsC)
7984     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7985 }
7986
7987 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7988 {
7989   return MEDFileField1TSWithoutSDA::TYPE_STR;
7990 }
7991
7992 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7993 {
7994   return new MEDFileFieldMultiTSWithoutSDA(*this);
7995 }
7996
7997 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7998 {
7999   return new MEDFileFieldMultiTSWithoutSDA;
8000 }
8001
8002 /*!
8003  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8004  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8005  */
8006 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
8007 {
8008   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8009   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8010   if(!myF1TSC)
8011     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8012   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8013 }
8014
8015 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8016 {
8017   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8018   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8019   int i=0;
8020   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8021     {
8022       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8023       if(eltToConv)
8024         {
8025           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8026           if(!eltToConvC)
8027             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8028           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8029           ret->setIteration(i,elt);
8030         }
8031     }
8032   return ret.retn();
8033 }
8034
8035 //= MEDFileAnyTypeFieldMultiTS
8036
8037 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8038 {
8039 }
8040
8041 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8042 try:MEDFileFieldGlobsReal(fileName)
8043 {
8044   MEDFileUtilities::CheckFileForRead(fileName);
8045   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8046   _content=BuildContentFrom(fid,fileName,loadAll,ms);
8047   loadGlobals(fid);
8048 }
8049 catch(INTERP_KERNEL::Exception& e)
8050 {
8051     throw e;
8052 }
8053
8054 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8055 {
8056   med_field_type typcha;
8057   std::vector<std::string> infos;
8058   std::string dtunit;
8059   int i=-1;
8060   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
8061   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8062   switch(typcha)
8063   {
8064     case MED_FLOAT64:
8065       {
8066         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8067         break;
8068       }
8069     case MED_INT32:
8070       {
8071         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8072         break;
8073       }
8074     default:
8075       {
8076         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] !";
8077         throw INTERP_KERNEL::Exception(oss.str().c_str());
8078       }
8079   }
8080   ret->setDtUnit(dtunit.c_str());
8081   return ret.retn();
8082 }
8083
8084 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
8085 {
8086   med_field_type typcha;
8087   //
8088   std::vector<std::string> infos;
8089   std::string dtunit,fieldName;
8090   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
8091   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8092   switch(typcha)
8093   {
8094     case MED_FLOAT64:
8095       {
8096         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8097         break;
8098       }
8099     case MED_INT32:
8100       {
8101         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8102         break;
8103       }
8104     default:
8105       {
8106         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] !";
8107         throw INTERP_KERNEL::Exception(oss.str().c_str());
8108       }
8109   }
8110   ret->setDtUnit(dtunit.c_str());
8111   return ret.retn();
8112 }
8113
8114 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
8115 {
8116   if(!c)
8117     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8118   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8119     {
8120       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
8121       ret->setFileName(fileName);
8122       ret->_content=c;  c->incrRef();
8123       return ret.retn();
8124     }
8125   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8126     {
8127       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
8128       ret->setFileName(fileName);
8129       ret->_content=c;  c->incrRef();
8130       return ret.retn();
8131     }
8132   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8133 }
8134
8135 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8136 try:MEDFileFieldGlobsReal(fileName)
8137 {
8138   MEDFileUtilities::CheckFileForRead(fileName);
8139   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8140   _content=BuildContentFrom(fid,fileName,fieldName,loadAll,ms,entities);
8141   loadGlobals(fid);
8142 }
8143 catch(INTERP_KERNEL::Exception& e)
8144 {
8145     throw e;
8146 }
8147
8148 //= MEDFileIntFieldMultiTSWithoutSDA
8149
8150 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8151 {
8152   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8153 }
8154
8155 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8156 {
8157 }
8158
8159 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8160 {
8161 }
8162
8163 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8164 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8165 {
8166 }
8167 catch(INTERP_KERNEL::Exception& e)
8168 { throw e; }
8169
8170 /*!
8171  * \param [in] fieldId field id in C mode
8172  */
8173 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
8174 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8175 {
8176 }
8177 catch(INTERP_KERNEL::Exception& e)
8178 { throw e; }
8179
8180 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8181 {
8182   return new MEDFileIntField1TSWithoutSDA;
8183 }
8184
8185 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8186 {
8187   if(!f1ts)
8188     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8189   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8190   if(!f1tsC)
8191     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8192 }
8193
8194 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8195 {
8196   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8197 }
8198
8199 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8200 {
8201   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8202 }
8203
8204 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8205 {
8206   return new MEDFileIntFieldMultiTSWithoutSDA;
8207 }
8208
8209 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8210 {
8211   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8212   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8213   int i=0;
8214   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8215     {
8216       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8217       if(eltToConv)
8218         {
8219           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8220           if(!eltToConvC)
8221             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8222           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8223           ret->setIteration(i,elt);
8224         }
8225     }
8226   return ret.retn();
8227 }
8228
8229 //= MEDFileAnyTypeFieldMultiTS
8230
8231 /*!
8232  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8233  * that has been read from a specified MED file.
8234  *  \param [in] fileName - the name of the MED file to read.
8235  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8236  *          is to delete this field using decrRef() as it is no more needed.
8237  *  \throw If reading the file fails.
8238  */
8239 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8240 {
8241   MEDFileUtilities::CheckFileForRead(fileName);
8242   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8243   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll,0);
8244   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8245   ret->loadGlobals(fid);
8246   return ret.retn();
8247 }
8248
8249 /*!
8250  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8251  * that has been read from a specified MED file.
8252  *  \param [in] fileName - the name of the MED file to read.
8253  *  \param [in] fieldName - the name of the field to read.
8254  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8255  *          is to delete this field using decrRef() as it is no more needed.
8256  *  \throw If reading the file fails.
8257  *  \throw If there is no field named \a fieldName in the file.
8258  */
8259 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8260 {
8261   MEDFileUtilities::CheckFileForRead(fileName);
8262   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
8263   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fileName,fieldName,loadAll,0,0));
8264   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
8265   ret->loadGlobals(fid);
8266   return ret.retn();
8267 }
8268
8269 /*!
8270  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8271  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8272  *
8273  * \warning this is a shallow copy constructor
8274  */
8275 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8276 {
8277   if(!shallowCopyOfContent)
8278     {
8279       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8280       otherPtr->incrRef();
8281       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8282     }
8283   else
8284     {
8285       _content=other.shallowCpy();
8286     }
8287 }
8288
8289 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8290 {
8291   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8292   if(!ret)
8293     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8294   return ret;
8295 }
8296
8297 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8298 {
8299   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8300   if(!ret)
8301     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8302   return ret;
8303 }
8304
8305 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8306 {
8307   return contentNotNullBase()->getPflsReallyUsed2();
8308 }
8309
8310 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8311 {
8312   return contentNotNullBase()->getLocsReallyUsed2();
8313 }
8314
8315 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8316 {
8317   return contentNotNullBase()->getPflsReallyUsedMulti2();
8318 }
8319
8320 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8321 {
8322   return contentNotNullBase()->getLocsReallyUsedMulti2();
8323 }
8324
8325 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8326 {
8327   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8328 }
8329
8330 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8331 {
8332   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8333 }
8334
8335 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8336 {
8337   return contentNotNullBase()->getNumberOfTS();
8338 }
8339
8340 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8341 {
8342   contentNotNullBase()->eraseEmptyTS();
8343 }
8344
8345 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8346 {
8347   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8348 }
8349
8350 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8351 {
8352   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8353 }
8354
8355 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8356 {
8357   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8358   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8359   ret->_content=c;
8360   return ret.retn();
8361 }
8362
8363 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8364 {
8365   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8366   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8367   ret->_content=c;
8368   return ret.retn();
8369 }
8370
8371 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8372 {
8373   return contentNotNullBase()->getIterations();
8374 }
8375
8376 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8377 {
8378   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8379     pushBackTimeStep(*it);
8380 }
8381
8382 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8383 {
8384   if(!f1ts)
8385     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8386   checkCoherencyOfType(f1ts);
8387   f1ts->incrRef();
8388   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8389   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8390   c->incrRef();
8391   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8392   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8393     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8394   _content->pushBackTimeStep(cSafe);
8395   appendGlobs(*f1ts,1e-12);
8396 }
8397
8398 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8399 {
8400   contentNotNullBase()->synchronizeNameScope();
8401 }
8402
8403 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8404 {
8405   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8406 }
8407
8408 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8409 {
8410   return contentNotNullBase()->getPosGivenTime(time,eps);
8411 }
8412
8413 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8414 {
8415   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8416 }
8417
8418 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8419 {
8420   return contentNotNullBase()->getTypesOfFieldAvailable();
8421 }
8422
8423 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
8424 {
8425   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8426 }
8427
8428 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8429 {
8430   return contentNotNullBase()->getName();
8431 }
8432
8433 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8434 {
8435   contentNotNullBase()->setName(name);
8436 }
8437
8438 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8439 {
8440   return contentNotNullBase()->getDtUnit();
8441 }
8442
8443 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8444 {
8445   contentNotNullBase()->setDtUnit(dtUnit);
8446 }
8447
8448 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8449 {
8450   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8451 }
8452
8453 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8454 {
8455   return contentNotNullBase()->getTimeSteps(ret1);
8456 }
8457
8458 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8459 {
8460   return contentNotNullBase()->getMeshName();
8461 }
8462
8463 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8464 {
8465   contentNotNullBase()->setMeshName(newMeshName);
8466 }
8467
8468 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8469 {
8470   return contentNotNullBase()->changeMeshNames(modifTab);
8471 }
8472
8473 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8474 {
8475   return contentNotNullBase()->getInfo();
8476 }
8477
8478 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8479 {
8480   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8481 }
8482
8483 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8484 {
8485   return contentNotNullBase()->setInfo(info);
8486 }
8487
8488 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8489 {
8490   const std::vector<std::string> ret=getInfo();
8491   return (int)ret.size();
8492 }
8493
8494 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8495 {
8496   writeGlobals(fid,*this);
8497   contentNotNullBase()->writeLL(fid,*this);
8498 }
8499
8500 /*!
8501  * Writes \a this field into a MED file specified by its name.
8502  *  \param [in] fileName - the MED file name.
8503  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8504  * - 2 - erase; an existing file is removed.
8505  * - 1 - append; same data should not be present in an existing file.
8506  * - 0 - overwrite; same data present in an existing file is overwritten.
8507  *  \throw If the field name is not set.
8508  *  \throw If no field data is set.
8509  *  \throw If \a mode == 1 and the same data is present in an existing file.
8510  */
8511 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8512 {
8513   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8514   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8515   writeLL(fid);
8516 }
8517
8518 /*!
8519  * This method alloc the arrays and load potentially huge arrays contained in this field.
8520  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8521  * This method can be also called to refresh or reinit values from a file.
8522  * 
8523  * \throw If the fileName is not set or points to a non readable MED file.
8524  */
8525 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8526 {
8527   if(getFileName().empty())
8528     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8529   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8530   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8531 }
8532
8533 /*!
8534  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8535  * But once data loaded once, this method does nothing.
8536  * 
8537  * \throw If the fileName is not set or points to a non readable MED file.
8538  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8539  */
8540 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8541 {
8542   if(!getFileName().empty())
8543     {
8544       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8545       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8546     }
8547 }
8548
8549 /*!
8550  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8551  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8552  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8553  * 
8554  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8555  */
8556 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8557 {
8558   contentNotNullBase()->unloadArrays();
8559 }
8560
8561 /*!
8562  * 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.
8563  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8564  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8565  * 
8566  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8567  */
8568 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8569 {
8570   if(!getFileName().empty())
8571     contentNotNullBase()->unloadArrays();
8572 }
8573
8574 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8575 {
8576   std::ostringstream oss;
8577   contentNotNullBase()->simpleRepr(0,oss,-1);
8578   simpleReprGlobs(oss);
8579   return oss.str();
8580 }
8581
8582 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8583 {
8584   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8585 }
8586
8587 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8588 {
8589   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8590   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8591   return ret;
8592 }
8593
8594 /*!
8595  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8596  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8597  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8598  */
8599 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8600 {
8601   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8602   if(!content)
8603     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8604   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8605   std::size_t sz(contentsSplit.size());
8606   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8607   for(std::size_t i=0;i<sz;i++)
8608     {
8609       ret[i]=shallowCpy();
8610       ret[i]->_content=contentsSplit[i];
8611     }
8612   return ret;
8613 }
8614
8615 /*!
8616  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8617  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8618  */
8619 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8620 {
8621   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8622   if(!content)
8623     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8624   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8625   std::size_t sz(contentsSplit.size());
8626   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8627   for(std::size_t i=0;i<sz;i++)
8628     {
8629       ret[i]=shallowCpy();
8630       ret[i]->_content=contentsSplit[i];
8631     }
8632   return ret;
8633 }
8634
8635 /*!
8636  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8637  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8638  */
8639 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8640 {
8641   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8642   if(!content)
8643     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8644   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8645   std::size_t sz(contentsSplit.size());
8646   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8647   for(std::size_t i=0;i<sz;i++)
8648     {
8649       ret[i]=shallowCpy();
8650       ret[i]->_content=contentsSplit[i];
8651     }
8652   return ret;
8653 }
8654
8655 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8656 {
8657   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8658   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8659     ret->_content=_content->deepCpy();
8660   ret->deepCpyGlobs(*this);
8661   return ret.retn();
8662 }
8663
8664 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8665 {
8666   return _content;
8667 }
8668
8669 /*!
8670  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8671  *  \param [in] iteration - the iteration number of a required time step.
8672  *  \param [in] order - the iteration order number of required time step.
8673  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8674  *          delete this field using decrRef() as it is no more needed.
8675  *  \throw If there is no required time step in \a this field.
8676  */
8677 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8678 {
8679   int pos=getPosOfTimeStep(iteration,order);
8680   return getTimeStepAtPos(pos);
8681 }
8682
8683 /*!
8684  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8685  *  \param [in] time - the time of the time step of interest.
8686  *  \param [in] eps - a precision used to compare time values.
8687  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8688  *          delete this field using decrRef() as it is no more needed.
8689  *  \throw If there is no required time step in \a this field.
8690  */
8691 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8692 {
8693   int pos=getPosGivenTime(time,eps);
8694   return getTimeStepAtPos(pos);
8695 }
8696
8697 /*!
8698  * 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.
8699  * The float64 value of time attached to the pair of integers are not considered here.
8700  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8701  *
8702  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8703  * \throw If there is a null pointer in \a vectFMTS.
8704  */
8705 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8706 {
8707   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8708   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8709   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8710   while(!lstFMTS.empty())
8711     {
8712       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8713       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8714       if(!curIt)
8715         throw INTERP_KERNEL::Exception(msg);
8716       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8717       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8718       elt.push_back(curIt); it=lstFMTS.erase(it);
8719       while(it!=lstFMTS.end())
8720         {
8721           curIt=*it;
8722           if(!curIt)
8723             throw INTERP_KERNEL::Exception(msg);
8724           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8725           if(refIts==curIts)
8726             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8727           else
8728             it++;
8729         }
8730       ret.push_back(elt);
8731     }
8732   return ret;
8733 }
8734
8735 /*!
8736  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8737  * All returned instances in a subvector can be safely loaded, rendered along time
8738  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8739  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8740  * 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).
8741  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8742  * 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.
8743  *
8744  * \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().
8745  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8746  * \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.
8747  * \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.
8748  *
8749  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8750  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8751  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8752  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8753  * \throw If mesh is null.
8754  * \throw If an element in \a vectFMTS is null.
8755  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8756  */
8757 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8758 {
8759   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8760   if(!mesh)
8761     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8762   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8763   if(vectFMTS.empty())
8764     return ret;
8765   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8766   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8767   if(!frstElt)
8768     throw INTERP_KERNEL::Exception(msg);
8769   std::size_t i=0;
8770   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8771   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8772   for(;it!=vectFMTS.end();it++,i++)
8773     {
8774       if(!(*it))
8775         throw INTERP_KERNEL::Exception(msg);
8776       TypeOfField tof0,tof1;
8777       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8778         {
8779           if(tof1!=ON_NODES)
8780             vectFMTSNotNodes.push_back(*it);
8781           else
8782             vectFMTSNodes.push_back(*it);
8783         }
8784       else
8785         vectFMTSNotNodes.push_back(*it);
8786     }
8787   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8788   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8789   ret=retCell;
8790   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8791     {
8792       i=0;
8793       bool isFetched(false);
8794       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8795         {
8796           if((*it0).empty())
8797             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8798           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8799             { ret[i].push_back(*it2); isFetched=true; }
8800         }
8801       if(!isFetched)
8802         {
8803           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8804           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8805           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8806         }
8807     }
8808   fsc=cmps;
8809   return ret;
8810 }
8811
8812 /*!
8813  * 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.
8814  * \param [out] cmps - same size than the returned vector.
8815  */
8816 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8817 {
8818   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8819   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8820   while(!lstFMTS.empty())
8821     {
8822       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8823       MEDFileAnyTypeFieldMultiTS *ref(*it);
8824       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8825       elt.push_back(ref); it=lstFMTS.erase(it);
8826       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8827       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8828       while(it!=lstFMTS.end())
8829         {
8830           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8831           if(cmp->isEqual(curIt))
8832             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8833           else
8834             it++;
8835         }
8836       ret.push_back(elt); cmps.push_back(cmp);
8837     }
8838   return ret;
8839 }
8840
8841 /*!
8842  * 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.
8843  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8844  *
8845  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8846  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8847  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8848  * \thorw If \a f0 and \a f1 do not have the same times steps.
8849  * \throw If mesh is null.
8850  * \throw If \a f0 or \a f1 is null.
8851  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8852  */
8853 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8854 {
8855   if(!mesh)
8856     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8857   if(!f0 || !f1)
8858     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8859   if(f0->getMeshName()!=mesh->getName())
8860     {
8861       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8862       throw INTERP_KERNEL::Exception(oss.str().c_str());
8863     }
8864   if(f1->getMeshName()!=mesh->getName())
8865     {
8866       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8867       throw INTERP_KERNEL::Exception(oss.str().c_str());
8868     }
8869   int nts=f0->getNumberOfTS();
8870   if(nts!=f1->getNumberOfTS())
8871     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8872   if(nts==0)
8873     return nts;
8874   for(int i=0;i<nts;i++)
8875     {
8876       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8877       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8878       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8879       if(tofs0.size()!=1 || tofs1.size()!=1)
8880         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8881       if(i!=0)
8882         {
8883           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8884             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8885         }
8886       else
8887         { tof0=tofs0[0]; tof1=tofs1[0]; }
8888       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8889         {
8890           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() << ") !";
8891           throw INTERP_KERNEL::Exception(oss.str().c_str());
8892         }
8893       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8894         {
8895           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() << ") !";
8896           throw INTERP_KERNEL::Exception(oss.str().c_str());
8897         }
8898       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8899         {
8900           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() << ") !";
8901           throw INTERP_KERNEL::Exception(oss.str().c_str());
8902         }
8903     }
8904   return nts;
8905 }
8906
8907 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8908 {
8909   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8910 }
8911
8912 //= MEDFileFieldMultiTS
8913
8914 /*!
8915  * Returns a new empty instance of MEDFileFieldMultiTS.
8916  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8917  *          is to delete this field using decrRef() as it is no more needed.
8918  */
8919 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8920 {
8921   return new MEDFileFieldMultiTS;
8922 }
8923
8924 /*!
8925  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8926  * that has been read from a specified MED file.
8927  *  \param [in] fileName - the name of the MED file to read.
8928  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8929  *          is to delete this field using decrRef() as it is no more needed.
8930  *  \throw If reading the file fails.
8931  */
8932 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8933 {
8934   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll,0);
8935   ret->contentNotNull();//to check that content type matches with \a this type.
8936   return ret.retn();
8937 }
8938
8939 /*!
8940  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8941  * that has been read from a specified MED file.
8942  *  \param [in] fileName - the name of the MED file to read.
8943  *  \param [in] fieldName - the name of the field to read.
8944  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8945  *          is to delete this field using decrRef() as it is no more needed.
8946  *  \throw If reading the file fails.
8947  *  \throw If there is no field named \a fieldName in the file.
8948  */
8949 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8950 {
8951   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0);
8952   ret->contentNotNull();//to check that content type matches with \a this type.
8953   return ret.retn();
8954 }
8955
8956 /*!
8957  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8958  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8959  *
8960  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8961  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8962  * \warning this is a shallow copy constructor
8963  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8964  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8965  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8966  *          is to delete this field using decrRef() as it is no more needed.
8967  */
8968 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8969 {
8970   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8971 }
8972
8973 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
8974 {
8975   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fileName,fieldName,loadAll,0,&entities));
8976   ret->contentNotNull();//to check that content type matches with \a this type.
8977   return ret.retn();
8978 }
8979
8980 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8981 {
8982   return new MEDFileFieldMultiTS(*this);
8983 }
8984
8985 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8986 {
8987   if(!f1ts)
8988     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8989   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8990   if(!f1tsC)
8991     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8992 }
8993
8994 /*!
8995  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8996  * following the given input policy.
8997  *
8998  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8999  *                            By default (true) the globals are deeply copied.
9000  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9001  */
9002 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9003 {
9004   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
9005   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9006   if(content)
9007     {
9008       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9009       if(!contc)
9010         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9011       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9012       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
9013     }
9014   else
9015     ret=MEDFileIntFieldMultiTS::New();
9016   if(isDeepCpyGlobs)
9017     ret->deepCpyGlobs(*this);
9018   else
9019     ret->shallowCpyGlobs(*this);
9020   return ret.retn();
9021 }
9022
9023 /*!
9024  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9025  *  \param [in] pos - a time step id.
9026  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9027  *          delete this field using decrRef() as it is no more needed.
9028  *  \throw If \a pos is not a valid time step id.
9029  */
9030 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9031 {
9032   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9033   if(!item)
9034     {
9035       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9036       throw INTERP_KERNEL::Exception(oss.str().c_str());
9037     }
9038   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9039   if(itemC)
9040     {
9041       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9042       ret->shallowCpyGlobs(*this);
9043       return ret.retn();
9044     }
9045   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9046   throw INTERP_KERNEL::Exception(oss.str().c_str());
9047 }
9048
9049 /*!
9050  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9051  * mesh entities of a given dimension of the first mesh in MED file.
9052  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9053  *  \param [in] type - a spatial discretization of interest.
9054  *  \param [in] iteration - the iteration number of a required time step.
9055  *  \param [in] order - the iteration order number of required time step.
9056  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9057  *  \param [in] renumPol - specifies how to permute values of the result field according to
9058  *          the optional numbers of cells and nodes, if any. The valid values are
9059  *          - 0 - do not permute.
9060  *          - 1 - permute cells.
9061  *          - 2 - permute nodes.
9062  *          - 3 - permute cells and nodes.
9063  *
9064  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9065  *          caller is to delete this field using decrRef() as it is no more needed. 
9066  *  \throw If the MED file is not readable.
9067  *  \throw If there is no mesh in the MED file.
9068  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9069  *  \throw If no field values of the required parameters are available.
9070  */
9071 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9072 {
9073   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9074   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9075   if(!myF1TSC)
9076     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9077   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9078   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9079   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9080   return ret.retn();
9081 }
9082
9083 /*!
9084  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9085  * the top level cells of the first mesh in MED file.
9086  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9087  *  \param [in] type - a spatial discretization of interest.
9088  *  \param [in] iteration - the iteration number of a required time step.
9089  *  \param [in] order - the iteration order number of required time step.
9090  *  \param [in] renumPol - specifies how to permute values of the result field according to
9091  *          the optional numbers of cells and nodes, if any. The valid values are
9092  *          - 0 - do not permute.
9093  *          - 1 - permute cells.
9094  *          - 2 - permute nodes.
9095  *          - 3 - permute cells and nodes.
9096  *
9097  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9098  *          caller is to delete this field using decrRef() as it is no more needed. 
9099  *  \throw If the MED file is not readable.
9100  *  \throw If there is no mesh in the MED file.
9101  *  \throw If no field values of the required parameters are available.
9102  */
9103 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9104 {
9105   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9106   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9107   if(!myF1TSC)
9108     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9109   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9110   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9111   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9112   return ret.retn();
9113 }
9114
9115 /*!
9116  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9117  * a given support.
9118  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9119  *  \param [in] type - a spatial discretization of interest.
9120  *  \param [in] iteration - the iteration number of a required time step.
9121  *  \param [in] order - the iteration order number of required time step.
9122  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9123  *  \param [in] mesh - the supporting mesh.
9124  *  \param [in] renumPol - specifies how to permute values of the result field according to
9125  *          the optional numbers of cells and nodes, if any. The valid values are
9126  *          - 0 - do not permute.
9127  *          - 1 - permute cells.
9128  *          - 2 - permute nodes.
9129  *          - 3 - permute cells and nodes.
9130  *
9131  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9132  *          caller is to delete this field using decrRef() as it is no more needed. 
9133  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9134  *  \throw If no field of \a this is lying on \a mesh.
9135  *  \throw If no field values of the required parameters are available.
9136  */
9137 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9138 {
9139   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9140   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9141   if(!myF1TSC)
9142     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9143   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9144   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9145   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9146   return ret.retn();
9147 }
9148
9149 /*!
9150  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9151  * given support. 
9152  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9153  *  \param [in] type - a spatial discretization of the new field.
9154  *  \param [in] iteration - the iteration number of a required time step.
9155  *  \param [in] order - the iteration order number of required time step.
9156  *  \param [in] mesh - the supporting mesh.
9157  *  \param [in] renumPol - specifies how to permute values of the result field according to
9158  *          the optional numbers of cells and nodes, if any. The valid values are
9159  *          - 0 - do not permute.
9160  *          - 1 - permute cells.
9161  *          - 2 - permute nodes.
9162  *          - 3 - permute cells and nodes.
9163  *
9164  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9165  *          caller is to delete this field using decrRef() as it is no more needed. 
9166  *  \throw If no field of \a this is lying on \a mesh.
9167  *  \throw If no field values of the required parameters are available.
9168  */
9169 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9170 {
9171   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9172   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9173   if(!myF1TSC)
9174     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9175   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9176   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9177   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9178   return ret.retn();
9179 }
9180
9181 /*!
9182  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9183  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9184  * This method is useful for MED2 file format when field on different mesh was autorized.
9185  */
9186 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9187 {
9188   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9189   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9190   if(!myF1TSC)
9191     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9192   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
9193   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9194   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9195   return ret.retn();
9196 }
9197
9198 /*!
9199  * Returns values and a profile of the field of a given type, of a given time step,
9200  * lying on a given support.
9201  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9202  *  \param [in] type - a spatial discretization of the field.
9203  *  \param [in] iteration - the iteration number of a required time step.
9204  *  \param [in] order - the iteration order number of required time step.
9205  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9206  *  \param [in] mesh - the supporting mesh.
9207  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9208  *          field of interest lies on. If the field lies on all entities of the given
9209  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9210  *          using decrRef() as it is no more needed.  
9211  *  \param [in] glob - the global data storing profiles and localization.
9212  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9213  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9214  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9215  *  \throw If no field of \a this is lying on \a mesh.
9216  *  \throw If no field values of the required parameters are available.
9217  */
9218 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9219 {
9220   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9221   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9222   if(!myF1TSC)
9223     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9224   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9225   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9226 }
9227
9228 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9229 {
9230   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9231   if(!pt)
9232     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9233   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9234   if(!ret)
9235     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 !");
9236   return ret;
9237 }
9238
9239 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9240 {
9241   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9242   if(!pt)
9243     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9244   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9245   if(!ret)
9246     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 !");
9247   return ret;
9248 }
9249
9250 /*!
9251  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9252  * the given field is checked if its elements are sorted suitable for writing to MED file
9253  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9254  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9255  *  \param [in] field - the field to add to \a this.
9256  *  \throw If the name of \a field is empty.
9257  *  \throw If the data array of \a field is not set.
9258  *  \throw If existing time steps have different name or number of components than \a field.
9259  *  \throw If the underlying mesh of \a field has no name.
9260  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9261  */
9262 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9263 {
9264   const DataArrayDouble *arr=0;
9265   if(field)
9266     arr=field->getArray();
9267   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9268 }
9269
9270 /*!
9271  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9272  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9273  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9274  * and \a profile.
9275  *
9276  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9277  * A new profile is added only if no equal profile is missing.
9278  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9279  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9280  *  \param [in] mesh - the supporting mesh of \a field.
9281  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9282  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9283  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9284  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9285  *  \throw If the data array of \a field is not set.
9286  *  \throw If the data array of \a this is already allocated but has different number of
9287  *         components than \a field.
9288  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9289  *  \sa setFieldNoProfileSBT()
9290  */
9291 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9292 {
9293   const DataArrayDouble *arr=0;
9294   if(field)
9295     arr=field->getArray();
9296   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9297 }
9298
9299 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9300 {
9301   _content=new MEDFileFieldMultiTSWithoutSDA;
9302 }
9303
9304 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9305 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9306 {
9307 }
9308 catch(INTERP_KERNEL::Exception& e)
9309 { throw e; }
9310
9311 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9312 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9313 {
9314 }
9315 catch(INTERP_KERNEL::Exception& e)
9316 { throw e; }
9317
9318 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9319 {
9320 }
9321
9322 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
9323 {
9324   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9325 }
9326
9327 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9328 {
9329   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9330 }
9331
9332 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9333 {
9334   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9335 }
9336
9337 //= MEDFileAnyTypeFieldMultiTSIterator
9338
9339 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9340 {
9341   if(fmts)
9342     {
9343       fmts->incrRef();
9344       _nb_iter=fmts->getNumberOfTS();
9345     }
9346 }
9347
9348 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9349 {
9350 }
9351
9352 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9353 {
9354   if(_iter_id<_nb_iter)
9355     {
9356       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9357       if(fmts)
9358         return fmts->getTimeStepAtPos(_iter_id++);
9359       else
9360         return 0;
9361     }
9362   else
9363     return 0;
9364 }
9365
9366 //= MEDFileIntFieldMultiTS
9367
9368 /*!
9369  * Returns a new empty instance of MEDFileFieldMultiTS.
9370  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9371  *          is to delete this field using decrRef() as it is no more needed.
9372  */
9373 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9374 {
9375   return new MEDFileIntFieldMultiTS;
9376 }
9377
9378 /*!
9379  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9380  * that has been read from a specified MED file.
9381  *  \param [in] fileName - the name of the MED file to read.
9382  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9383  *          is to delete this field using decrRef() as it is no more needed.
9384  *  \throw If reading the file fails.
9385  */
9386 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9387 {
9388   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll,0);
9389   ret->contentNotNull();//to check that content type matches with \a this type.
9390   return ret.retn();
9391 }
9392
9393 /*!
9394  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9395  * that has been read from a specified MED file.
9396  *  \param [in] fileName - the name of the MED file to read.
9397  *  \param [in] fieldName - the name of the field to read.
9398  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9399  *          is to delete this field using decrRef() as it is no more needed.
9400  *  \throw If reading the file fails.
9401  *  \throw If there is no field named \a fieldName in the file.
9402  */
9403 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9404 {
9405   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0);
9406   ret->contentNotNull();//to check that content type matches with \a this type.
9407   return ret.retn();
9408 }
9409
9410 /*!
9411  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9412  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9413  *
9414  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9415  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9416  * \warning this is a shallow copy constructor
9417  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9418  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9419  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9420  *          is to delete this field using decrRef() as it is no more needed.
9421  */
9422 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9423 {
9424   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9425 }
9426
9427 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9428 {
9429   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll,0,&entities);
9430   ret->contentNotNull();//to check that content type matches with \a this type.
9431   return ret.retn();
9432 }
9433
9434 /*!
9435  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9436  * following the given input policy.
9437  *
9438  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9439  *                            By default (true) the globals are deeply copied.
9440  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9441  */
9442 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9443 {
9444   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9445   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9446   if(content)
9447     {
9448       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9449       if(!contc)
9450         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9451       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9452       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9453     }
9454   else
9455     ret=MEDFileFieldMultiTS::New();
9456   if(isDeepCpyGlobs)
9457     ret->deepCpyGlobs(*this);
9458   else
9459     ret->shallowCpyGlobs(*this);
9460   return ret.retn();
9461 }
9462
9463 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9464 {
9465   return new MEDFileIntFieldMultiTS(*this);
9466 }
9467
9468 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9469 {
9470   if(!f1ts)
9471     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9472   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9473   if(!f1tsC)
9474     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9475 }
9476
9477 /*!
9478  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9479  * mesh entities of a given dimension of the first mesh in MED file.
9480  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9481  *  \param [in] type - a spatial discretization of interest.
9482  *  \param [in] iteration - the iteration number of a required time step.
9483  *  \param [in] order - the iteration order number of required time step.
9484  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9485  *  \param [out] arrOut - the DataArrayInt containing values of field.
9486  *  \param [in] renumPol - specifies how to permute values of the result field according to
9487  *          the optional numbers of cells and nodes, if any. The valid values are
9488  *          - 0 - do not permute.
9489  *          - 1 - permute cells.
9490  *          - 2 - permute nodes.
9491  *          - 3 - permute cells and nodes.
9492  *
9493  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9494  *          caller is to delete this field using decrRef() as it is no more needed. 
9495  *  \throw If the MED file is not readable.
9496  *  \throw If there is no mesh in the MED file.
9497  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9498  *  \throw If no field values of the required parameters are available.
9499  */
9500 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9501 {
9502   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9503   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9504   if(!myF1TSC)
9505     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9506   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9507   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9508   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9509   return ret.retn();
9510 }
9511
9512 /*!
9513  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9514  * the top level cells of the first mesh in MED file.
9515  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9516  *  \param [in] type - a spatial discretization of interest.
9517  *  \param [in] iteration - the iteration number of a required time step.
9518  *  \param [in] order - the iteration order number of required time step.
9519  *  \param [out] arrOut - the DataArrayInt containing values of field.
9520  *  \param [in] renumPol - specifies how to permute values of the result field according to
9521  *          the optional numbers of cells and nodes, if any. The valid values are
9522  *          - 0 - do not permute.
9523  *          - 1 - permute cells.
9524  *          - 2 - permute nodes.
9525  *          - 3 - permute cells and nodes.
9526  *
9527  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9528  *          caller is to delete this field using decrRef() as it is no more needed. 
9529  *  \throw If the MED file is not readable.
9530  *  \throw If there is no mesh in the MED file.
9531  *  \throw If no field values of the required parameters are available.
9532  */
9533 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9534 {
9535   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9536   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9537   if(!myF1TSC)
9538     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9539   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9540   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9541   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9542   return ret.retn();
9543 }
9544
9545 /*!
9546  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9547  * a given support.
9548  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9549  *  \param [in] type - a spatial discretization of interest.
9550  *  \param [in] iteration - the iteration number of a required time step.
9551  *  \param [in] order - the iteration order number of required time step.
9552  *  \param [out] arrOut - the DataArrayInt containing values of field.
9553  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9554  *  \param [in] mesh - the supporting mesh.
9555  *  \param [in] renumPol - specifies how to permute values of the result field according to
9556  *          the optional numbers of cells and nodes, if any. The valid values are
9557  *          - 0 - do not permute.
9558  *          - 1 - permute cells.
9559  *          - 2 - permute nodes.
9560  *          - 3 - permute cells and nodes.
9561  *
9562  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9563  *          caller is to delete this field using decrRef() as it is no more needed. 
9564  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9565  *  \throw If no field of \a this is lying on \a mesh.
9566  *  \throw If no field values of the required parameters are available.
9567  */
9568 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9569 {
9570   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9571   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9572   if(!myF1TSC)
9573     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9574   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9575   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9576   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9577   return ret.retn();
9578 }
9579
9580 /*!
9581  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9582  * given support. 
9583  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9584  *  \param [in] type - a spatial discretization of the new field.
9585  *  \param [in] iteration - the iteration number of a required time step.
9586  *  \param [in] order - the iteration order number of required time step.
9587  *  \param [in] mesh - the supporting mesh.
9588  *  \param [out] arrOut - the DataArrayInt containing values of field.
9589  *  \param [in] renumPol - specifies how to permute values of the result field according to
9590  *          the optional numbers of cells and nodes, if any. The valid values are
9591  *          - 0 - do not permute.
9592  *          - 1 - permute cells.
9593  *          - 2 - permute nodes.
9594  *          - 3 - permute cells and nodes.
9595  *
9596  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9597  *          caller is to delete this field using decrRef() as it is no more needed. 
9598  *  \throw If no field of \a this is lying on \a mesh.
9599  *  \throw If no field values of the required parameters are available.
9600  */
9601 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9602 {
9603   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9604   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9605   if(!myF1TSC)
9606     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9607   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9608   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9609   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9610   return ret.retn();
9611 }
9612
9613 /*!
9614  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9615  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9616  * This method is useful for MED2 file format when field on different mesh was autorized.
9617  */
9618 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9619 {
9620   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9621   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9622   if(!myF1TSC)
9623     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9624   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9625   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9626   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9627   return ret.retn();
9628 }
9629
9630 /*!
9631  * Returns values and a profile of the field of a given type, of a given time step,
9632  * lying on a given support.
9633  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9634  *  \param [in] type - a spatial discretization of the field.
9635  *  \param [in] iteration - the iteration number of a required time step.
9636  *  \param [in] order - the iteration order number of required time step.
9637  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9638  *  \param [in] mesh - the supporting mesh.
9639  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9640  *          field of interest lies on. If the field lies on all entities of the given
9641  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9642  *          using decrRef() as it is no more needed.  
9643  *  \param [in] glob - the global data storing profiles and localization.
9644  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9645  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9646  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9647  *  \throw If no field of \a this is lying on \a mesh.
9648  *  \throw If no field values of the required parameters are available.
9649  */
9650 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9651 {
9652   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9653   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9654   if(!myF1TSC)
9655     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9656   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9657   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9658 }
9659
9660 /*!
9661  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9662  *  \param [in] pos - a time step id.
9663  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9664  *          delete this field using decrRef() as it is no more needed.
9665  *  \throw If \a pos is not a valid time step id.
9666  */
9667 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9668 {
9669   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9670   if(!item)
9671     {
9672       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9673       throw INTERP_KERNEL::Exception(oss.str().c_str());
9674     }
9675   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9676   if(itemC)
9677     {
9678       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9679       ret->shallowCpyGlobs(*this);
9680       return ret.retn();
9681     }
9682   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9683   throw INTERP_KERNEL::Exception(oss.str().c_str());
9684 }
9685
9686 /*!
9687  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9688  * the given field is checked if its elements are sorted suitable for writing to MED file
9689  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9690  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9691  *  \param [in] field - the field to add to \a this.
9692  *  \throw If the name of \a field is empty.
9693  *  \throw If the data array of \a field is not set.
9694  *  \throw If existing time steps have different name or number of components than \a field.
9695  *  \throw If the underlying mesh of \a field has no name.
9696  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9697  */
9698 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9699 {
9700   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9701 }
9702
9703 /*!
9704  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9705  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9706  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9707  * and \a profile.
9708  *
9709  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9710  * A new profile is added only if no equal profile is missing.
9711  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9712  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9713  *  \param [in] arrOfVals - the values of the field \a field used.
9714  *  \param [in] mesh - the supporting mesh of \a field.
9715  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9716  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9717  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9718  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9719  *  \throw If the data array of \a field is not set.
9720  *  \throw If the data array of \a this is already allocated but has different number of
9721  *         components than \a field.
9722  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9723  *  \sa setFieldNoProfileSBT()
9724  */
9725 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9726 {
9727   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9728 }
9729
9730 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9731 {
9732   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9733   if(!pt)
9734     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9735   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9736   if(!ret)
9737     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 !");
9738   return ret;
9739 }
9740
9741 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9742 {
9743   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9744   if(!pt)
9745     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9746   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9747   if(!ret)
9748     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 !");
9749   return ret;
9750 }
9751
9752 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9753 {
9754   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9755 }
9756
9757 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9758 {
9759 }
9760
9761 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9762 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll,ms)
9763 {
9764 }
9765 catch(INTERP_KERNEL::Exception& e)
9766 { throw e; }
9767
9768 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9769 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll,ms,entities)
9770 {
9771 }
9772 catch(INTERP_KERNEL::Exception& e)
9773 { throw e; }
9774
9775 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9776 {
9777   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9778 }
9779
9780 //= MEDFileFields
9781
9782 MEDFileFields *MEDFileFields::New()
9783 {
9784   return new MEDFileFields;
9785 }
9786
9787 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9788 {
9789   return new MEDFileFields(fileName,loadAll,0,0);
9790 }
9791
9792 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
9793 {
9794   return new MEDFileFields(fileName,loadAll,ms,0);
9795 }
9796
9797 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9798 {
9799   return new MEDFileFields(fileName,loadAll,0,&entities);
9800 }
9801
9802 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9803 {
9804   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9805   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9806   return ret;
9807 }
9808
9809 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
9810 {
9811   std::vector<const BigMemoryObject *> ret;
9812   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9813     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
9814   return ret;
9815 }
9816
9817 MEDFileFields *MEDFileFields::deepCpy() const
9818 {
9819   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9820   std::size_t i=0;
9821   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9822     {
9823       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9824         ret->_fields[i]=(*it)->deepCpy();
9825     }
9826   ret->deepCpyGlobs(*this);
9827   return ret.retn();
9828 }
9829
9830 MEDFileFields *MEDFileFields::shallowCpy() const
9831 {
9832   return new MEDFileFields(*this);
9833 }
9834
9835 /*!
9836  * 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
9837  * 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.
9838  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9839  *
9840  * \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.
9841  * \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.
9842  * 
9843  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9844  */
9845 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9846 {
9847   std::set< std::pair<int,int> > s;
9848   bool firstShot=true;
9849   areThereSomeForgottenTS=false;
9850   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9851     {
9852       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9853         continue;
9854       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9855       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9856       if(firstShot)
9857         { s=s1; firstShot=false; }
9858       else
9859         {
9860           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9861           if(s!=s2)
9862             areThereSomeForgottenTS=true;
9863           s=s2;
9864         }
9865     }
9866   std::vector< std::pair<int,int> > ret;
9867   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9868   return ret;
9869 }
9870
9871 int MEDFileFields::getNumberOfFields() const
9872 {
9873   return _fields.size();
9874 }
9875
9876 std::vector<std::string> MEDFileFields::getFieldsNames() const
9877 {
9878   std::vector<std::string> ret(_fields.size());
9879   int i=0;
9880   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9881     {
9882       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9883       if(f)
9884         {
9885           ret[i]=f->getName();
9886         }
9887       else
9888         {
9889           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9890           throw INTERP_KERNEL::Exception(oss.str().c_str());
9891         }
9892     }
9893   return ret;
9894 }
9895
9896 std::vector<std::string> MEDFileFields::getMeshesNames() const
9897 {
9898   std::vector<std::string> ret;
9899   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9900     {
9901       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9902       if(cur)
9903         ret.push_back(cur->getMeshName());
9904     }
9905   return ret;
9906 }
9907
9908 std::string MEDFileFields::simpleRepr() const
9909 {
9910   std::ostringstream oss;
9911   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9912   simpleRepr(0,oss);
9913   return oss.str();
9914 }
9915
9916 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9917 {
9918   int nbOfFields=getNumberOfFields();
9919   std::string startLine(bkOffset,' ');
9920   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9921   int i=0;
9922   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9923     {
9924       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9925       if(cur)
9926         {
9927           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9928         }
9929       else
9930         {
9931           oss << startLine << "  - not defined !" << std::endl;
9932         }
9933     }
9934   i=0;
9935   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9936     {
9937       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9938       std::string chapter(17,'0'+i);
9939       oss << startLine << chapter << std::endl;
9940       if(cur)
9941         {
9942           cur->simpleRepr(bkOffset+2,oss,i);
9943         }
9944       else
9945         {
9946           oss << startLine << "  - not defined !" << std::endl;
9947         }
9948       oss << startLine << chapter << std::endl;
9949     }
9950   simpleReprGlobs(oss);
9951 }
9952
9953 MEDFileFields::MEDFileFields()
9954 {
9955 }
9956
9957 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> > *entities)
9958 try:MEDFileFieldGlobsReal(fileName)
9959 {
9960   MEDFileUtilities::CheckFileForRead(fileName);
9961   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
9962   int nbFields(MEDnField(fid));
9963   _fields.resize(nbFields);
9964   med_field_type typcha;
9965   for(int i=0;i<nbFields;i++)
9966     {
9967       std::vector<std::string> infos;
9968       std::string fieldName,dtunit;
9969       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit));
9970       switch(typcha)
9971       {
9972         case MED_FLOAT64:
9973           {
9974             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9975             break;
9976           }
9977         case MED_INT32:
9978           {
9979             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
9980             break;
9981           }
9982         default:
9983           {
9984             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] !";
9985             throw INTERP_KERNEL::Exception(oss.str().c_str());
9986           }
9987       }
9988     }
9989   loadAllGlobals(fid);
9990 }
9991 catch(INTERP_KERNEL::Exception& e)
9992 {
9993     throw e;
9994 }
9995
9996 void MEDFileFields::writeLL(med_idt fid) const
9997 {
9998   int i=0;
9999   writeGlobals(fid,*this);
10000   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10001     {
10002       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10003       if(!elt)
10004         {
10005           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10006           throw INTERP_KERNEL::Exception(oss.str().c_str());
10007         }
10008       elt->writeLL(fid,*this);
10009     }
10010 }
10011
10012 void MEDFileFields::write(const std::string& fileName, int mode) const
10013 {
10014   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
10015   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
10016   writeLL(fid);
10017 }
10018
10019 /*!
10020  * This method alloc the arrays and load potentially huge arrays contained in this field.
10021  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10022  * This method can be also called to refresh or reinit values from a file.
10023  * 
10024  * \throw If the fileName is not set or points to a non readable MED file.
10025  */
10026 void MEDFileFields::loadArrays()
10027 {
10028   if(getFileName().empty())
10029     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10030   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10031   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10032     {
10033       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10034       if(elt)
10035         elt->loadBigArraysRecursively(fid,*elt);
10036     }
10037 }
10038
10039 /*!
10040  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10041  * But once data loaded once, this method does nothing.
10042  * 
10043  * \throw If the fileName is not set or points to a non readable MED file.
10044  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10045  */
10046 void MEDFileFields::loadArraysIfNecessary()
10047 {
10048   if(!getFileName().empty())
10049     {
10050       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
10051       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10052         {
10053           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10054           if(elt)
10055             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10056         }
10057     }
10058 }
10059
10060 /*!
10061  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10062  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10063  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10064  * 
10065  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10066  */
10067 void MEDFileFields::unloadArrays()
10068 {
10069   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10070     {
10071       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10072       if(elt)
10073         elt->unloadArrays();
10074     }
10075 }
10076
10077 /*!
10078  * 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.
10079  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10080  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10081  * 
10082  * \sa MEDFileFields::loadArraysIfNecessary
10083  */
10084 void MEDFileFields::unloadArraysWithoutDataLoss()
10085 {
10086   if(!getFileName().empty())
10087     unloadArrays();
10088 }
10089
10090 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10091 {
10092   std::vector<std::string> ret;
10093   std::set<std::string> ret2;
10094   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10095     {
10096       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10097       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10098         if(ret2.find(*it2)==ret2.end())
10099           {
10100             ret.push_back(*it2);
10101             ret2.insert(*it2);
10102           }
10103     }
10104   return ret;
10105 }
10106
10107 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10108 {
10109   std::vector<std::string> ret;
10110   std::set<std::string> ret2;
10111   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10112     {
10113       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10114       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10115         if(ret2.find(*it2)==ret2.end())
10116           {
10117             ret.push_back(*it2);
10118             ret2.insert(*it2);
10119           }
10120     }
10121   return ret;
10122 }
10123
10124 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10125 {
10126   std::vector<std::string> ret;
10127   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10128     {
10129       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
10130       ret.insert(ret.end(),tmp.begin(),tmp.end());
10131     }
10132   return ret;
10133 }
10134
10135 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10136 {
10137   std::vector<std::string> ret;
10138   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10139     {
10140       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
10141       ret.insert(ret.end(),tmp.begin(),tmp.end());
10142     }
10143   return ret;
10144 }
10145
10146 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10147 {
10148   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10149     (*it)->changePflsRefsNamesGen2(mapOfModif);
10150 }
10151
10152 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10153 {
10154   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10155     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10156 }
10157
10158 void MEDFileFields::resize(int newSize)
10159 {
10160   _fields.resize(newSize);
10161 }
10162
10163 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10164 {
10165   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10166     pushField(*it);
10167 }
10168
10169 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10170 {
10171   if(!field)
10172     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10173   _fields.push_back(field->getContent());
10174   appendGlobs(*field,1e-12);
10175 }
10176
10177 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10178 {
10179   if(!field)
10180     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10181   if(i>=(int)_fields.size())
10182     _fields.resize(i+1);
10183   _fields[i]=field->getContent();
10184   appendGlobs(*field,1e-12);
10185 }
10186
10187 void MEDFileFields::destroyFieldAtPos(int i)
10188 {
10189   destroyFieldsAtPos(&i,&i+1);
10190 }
10191
10192 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10193 {
10194   std::vector<bool> b(_fields.size(),true);
10195   for(const int *i=startIds;i!=endIds;i++)
10196     {
10197       if(*i<0 || *i>=(int)_fields.size())
10198         {
10199           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10200           throw INTERP_KERNEL::Exception(oss.str().c_str());
10201         }
10202       b[*i]=false;
10203     }
10204   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10205   std::size_t j=0;
10206   for(std::size_t i=0;i<_fields.size();i++)
10207     if(b[i])
10208       fields[j++]=_fields[i];
10209   _fields=fields;
10210 }
10211
10212 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10213 {
10214   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10215   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
10216   std::vector<bool> b(_fields.size(),true);
10217   int k=bg;
10218   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10219     {
10220       if(k<0 || k>=(int)_fields.size())
10221         {
10222           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10223           throw INTERP_KERNEL::Exception(oss.str().c_str());
10224         }
10225       b[k]=false;
10226     }
10227   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10228   std::size_t j=0;
10229   for(std::size_t i=0;i<_fields.size();i++)
10230     if(b[i])
10231       fields[j++]=_fields[i];
10232   _fields=fields;
10233 }
10234
10235 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10236 {
10237   bool ret=false;
10238   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10239     {
10240       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10241       if(cur)
10242         ret=cur->changeMeshNames(modifTab) || ret;
10243     }
10244   return ret;
10245 }
10246
10247 /*!
10248  * \param [in] meshName the name of the mesh that will be renumbered.
10249  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10250  *             This code corresponds to the distribution of types in the corresponding mesh.
10251  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10252  * \param [in] renumO2N the old to new renumber array.
10253  * \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 
10254  *         field in \a this.
10255  */
10256 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10257 {
10258   bool ret=false;
10259   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10260     {
10261       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10262       if(fmts)
10263         {
10264           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10265         }
10266     }
10267   return ret;
10268 }
10269
10270 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10271 {
10272   if(i<0 || i>=(int)_fields.size())
10273     {
10274       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10275       throw INTERP_KERNEL::Exception(oss.str().c_str());
10276     }
10277   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10278   if(!fmts)
10279     return 0;
10280   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
10281   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
10282   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
10283   if(fmtsC)
10284     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10285   else if(fmtsC2)
10286     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10287   else
10288     {
10289       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10290       throw INTERP_KERNEL::Exception(oss.str().c_str());
10291     }
10292   ret->shallowCpyGlobs(*this);
10293   return ret.retn();
10294 }
10295
10296 /*!
10297  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10298  * This method is accessible in python using __getitem__ with a list in input.
10299  * \return a new object that the caller should deal with.
10300  */
10301 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10302 {
10303   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
10304   std::size_t sz=std::distance(startIds,endIds);
10305   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10306   int j=0;
10307   for(const int *i=startIds;i!=endIds;i++,j++)
10308     {
10309       if(*i<0 || *i>=(int)_fields.size())
10310         {
10311           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10312           throw INTERP_KERNEL::Exception(oss.str().c_str());
10313         }
10314       fields[j]=_fields[*i];
10315     }
10316   ret->_fields=fields;
10317   return ret.retn();
10318 }
10319
10320 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10321 {
10322   return getFieldAtPos(getPosFromFieldName(fieldName));
10323 }
10324
10325 /*!
10326  * This method removes, if any, fields in \a this having no time steps.
10327  * 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.
10328  * 
10329  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10330  */
10331 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10332 {
10333   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10334   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10335     {
10336       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10337       if(elt)
10338         {
10339           if(elt->getNumberOfTS()>0)
10340             newFields.push_back(*it);
10341         }
10342     }
10343   if(_fields.size()==newFields.size())
10344     return false;
10345   _fields=newFields;
10346   return true;
10347 }
10348
10349 /*!
10350  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10351  * This method can be seen as a filter applied on \a this, that returns an object containing
10352  * 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
10353  * shallow copied from \a this.
10354  * 
10355  * \param [in] meshName - the name of the mesh on w
10356  * \return a new object that the caller should deal with.
10357  */
10358 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10359 {
10360   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10361   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10362     {
10363       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10364       if(!cur)
10365         continue;
10366       if(cur->getMeshName()==meshName)
10367         {
10368           cur->incrRef();
10369           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10370           ret->_fields.push_back(cur2);
10371         }
10372     }
10373   ret->shallowCpyOnlyUsedGlobs(*this);
10374   return ret.retn();
10375 }
10376
10377 /*!
10378  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10379  * Input time steps are specified using a pair of integer (iteration, order).
10380  * 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,
10381  * but for each multitimestep only the time steps in \a timeSteps are kept.
10382  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10383  * 
10384  * The returned object points to shallow copy of elements in \a this.
10385  * 
10386  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10387  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10388  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10389  */
10390 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10391 {
10392   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10393   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10394     {
10395       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10396       if(!cur)
10397         continue;
10398       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10399       ret->_fields.push_back(elt);
10400     }
10401   ret->shallowCpyOnlyUsedGlobs(*this);
10402   return ret.retn();
10403 }
10404
10405 /*!
10406  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10407  */
10408 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10409 {
10410   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10411   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10412     {
10413       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10414       if(!cur)
10415         continue;
10416       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10417       if(elt->getNumberOfTS()!=0)
10418         ret->_fields.push_back(elt);
10419     }
10420   ret->shallowCpyOnlyUsedGlobs(*this);
10421   return ret.retn();
10422 }
10423
10424 MEDFileFieldsIterator *MEDFileFields::iterator()
10425 {
10426   return new MEDFileFieldsIterator(this);
10427 }
10428
10429 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10430 {
10431   std::string tmp(fieldName);
10432   std::vector<std::string> poss;
10433   for(std::size_t i=0;i<_fields.size();i++)
10434     {
10435       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10436       if(f)
10437         {
10438           std::string fname(f->getName());
10439           if(tmp==fname)
10440             return i;
10441           else
10442             poss.push_back(fname);
10443         }
10444     }
10445   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10446   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10447   oss << " !";
10448   throw INTERP_KERNEL::Exception(oss.str().c_str());
10449 }
10450
10451 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10452 {
10453   if(fs)
10454     {
10455       fs->incrRef();
10456       _nb_iter=fs->getNumberOfFields();
10457     }
10458 }
10459
10460 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10461 {
10462 }
10463
10464 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10465 {
10466   if(_iter_id<_nb_iter)
10467     {
10468       MEDFileFields *fs(_fs);
10469       if(fs)
10470         return fs->getFieldAtPos(_iter_id++);
10471       else
10472         return 0;
10473     }
10474   else
10475     return 0;
10476 }