Salome HOME
a test.
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25 #include "MEDFileFieldOverView.hxx"
26
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "MEDCouplingFieldDiscretization.hxx"
29
30 #include "InterpKernelAutoPtr.hxx"
31 #include "CellModel.hxx"
32
33 #include <algorithm>
34 #include <iterator>
35
36 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
37 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
38 extern med_geometry_type typmainoeud[1];
39 extern med_geometry_type typmai3[34];
40
41 using namespace ParaMEDMEM;
42
43 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
44 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
45
46 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
47 {
48   return new MEDFileFieldLoc(fid,locName);
49 }
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
52 {
53   return new MEDFileFieldLoc(fid,id);
54 }
55
56 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
57 {
58   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
59 }
60
61 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
62 {
63   med_geometry_type geotype;
64   med_geometry_type sectiongeotype;
65   int nsectionmeshcell;
66   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
67   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
68   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
69   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
70   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
71   _nb_node_per_cell=cm.getNumberOfNodes();
72   _ref_coo.resize(_dim*_nb_node_per_cell);
73   _gs_coo.resize(_dim*_nb_gauss_pt);
74   _w.resize(_nb_gauss_pt);
75   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
76 }
77
78 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
79 {
80   med_geometry_type geotype;
81   med_geometry_type sectiongeotype;
82   int nsectionmeshcell;
83   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
84   INTERP_KERNEL::AutoPtr<char> geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
85   INTERP_KERNEL::AutoPtr<char> sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
86   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
87   _name=locName;
88   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
89   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
90   _nb_node_per_cell=cm.getNumberOfNodes();
91   _ref_coo.resize(_dim*_nb_node_per_cell);
92   _gs_coo.resize(_dim*_nb_gauss_pt);
93   _w.resize(_nb_gauss_pt);
94   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
95 }
96
97 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
98                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
99                                      _w(w)
100 {
101   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
102   _dim=cm.getDimension();
103   _nb_node_per_cell=cm.getNumberOfNodes();
104   _nb_gauss_pt=_w.size();
105 }
106
107 MEDFileFieldLoc *MEDFileFieldLoc::deepCpy() const
108 {
109   return new MEDFileFieldLoc(*this);
110 }
111
112 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
113 {
114   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
115 }
116
117 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildren() const
118 {
119   return std::vector<const BigMemoryObject *>();
120 }
121
122 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
123 {
124   static const char OFF7[]="\n    ";
125   oss << "\"" << _name << "\"" << OFF7;
126   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
127   oss << "Dimension=" << _dim << OFF7;
128   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
129   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
130   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
131   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
132   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
133 }
134
135 void MEDFileFieldLoc::setName(const std::string& name)
136 {
137   _name=name;
138 }
139
140 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
141 {
142   if(_name!=other._name)
143     return false;
144   if(_dim!=other._dim)
145     return false;
146   if(_nb_gauss_pt!=other._nb_gauss_pt)
147     return false;
148   if(_nb_node_per_cell!=other._nb_node_per_cell)
149     return false;
150   if(_geo_type!=other._geo_type)
151     return false;
152   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
153     return false;
154   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
155     return false;
156   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
157     return false;
158
159   return true;
160 }
161
162 void MEDFileFieldLoc::writeLL(med_idt fid) const
163 {
164   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
165 }
166
167 std::string MEDFileFieldLoc::repr() const
168 {
169   std::ostringstream oss; oss.precision(15);
170   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
171   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
172   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
173   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
174   oss << "\n  - Ref coords are : ";
175   int sz=_ref_coo.size();
176   if(sz%_dim==0)
177     {
178       int nbOfTuples=sz/_dim;
179       for(int i=0;i<nbOfTuples;i++)
180         {
181           oss << "(";
182           for(int j=0;j<_dim;j++)
183             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
184           oss << ") ";
185         }
186     }
187   else
188     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
189   oss << "\n  - Gauss coords in reference element : ";
190   sz=_gs_coo.size();
191   if(sz%_dim==0)
192     {
193       int nbOfTuples=sz/_dim;
194       for(int i=0;i<nbOfTuples;i++)
195         {
196           oss << "(";
197           for(int j=0;j<_dim;j++)
198             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
199           oss << ") ";
200         }
201     }
202   else
203     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
204   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
205   return oss.str();
206 }
207
208 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
209 {
210   _type=field->getTypeOfField();
211   _start=start;
212   switch(_type)
213   {
214     case ON_CELLS:
215       {
216         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,offset,offset+nbOfCells,1);
217         _end=_start+nbOfCells;
218         _nval=nbOfCells;
219         break;
220       }
221     case ON_GAUSS_NE:
222       {
223         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
224         const int *arrPtr=arr->getConstPointer();
225         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
226         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
227         _nval=nbOfCells;
228         break;
229       }
230     case ON_GAUSS_PT:
231       {
232         const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
233         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
234         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
235         if(!disc2)
236           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
237         const DataArrayInt *dai=disc2->getArrayOfDiscIds();
238         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dai2=disc2->getOffsetArr(field->getMesh());
239         const int *dai2Ptr=dai2->getConstPointer();
240         int nbi=gsLoc.getWeights().size();
241         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=dai->selectByTupleId2(offset,offset+nbOfCells,1);
242         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
243         const int *da3Ptr=da3->getConstPointer();
244         if(da3->getNumberOfTuples()!=nbOfCells)
245           {//profile : for gauss even in NoProfile !!!
246             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
247             _profile=oss.str();
248             da3->setName(_profile.c_str());
249             glob.appendProfile(da3);
250           }
251         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=DataArrayInt::New();
252         _nval=da3->getNbOfElems();
253         da4->alloc(_nval*nbi,1);
254         int *da4Ptr=da4->getPointer();
255         for(int i=0;i<_nval;i++)
256           {
257             int ref=dai2Ptr[offset+da3Ptr[i]];
258             for(int j=0;j<nbi;j++)
259               *da4Ptr++=ref+j;
260           }
261         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
262         _localization=oss2.str();
263         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
264         _end=_start+_nval*nbi;
265         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
266         break;
267       }
268     default:
269       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
270   }
271   start=_end;
272 }
273
274 /*!
275  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
276  * \param [in] pflName input containing name of profile if any. 0 if no profile (except for GAUSS_PT where a no profile can hide a profile when splitted by loc_id).
277  * \param [in] multiTypePfl is the end user profile specified in high level API
278  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
279  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
280  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
281  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
282  */
283 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
284 {
285   _profile.clear();
286   _type=field->getTypeOfField();
287   std::string pflName(multiTypePfl->getName());
288   std::ostringstream oss; oss << pflName;
289   if(_type!=ON_NODES)
290     {
291       if(!isPflAlone)
292         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
293     }
294   else
295     { oss << "_NODE"; }
296   if(locIds)
297     {
298       if(pflName.empty())
299         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
300       if(_type!=ON_GAUSS_PT)
301         {
302           locIds->setName(oss.str().c_str());
303           glob.appendProfile(locIds);
304           _profile=oss.str();
305         }
306     }
307   _start=start;
308   switch(_type)
309   {
310     case ON_NODES:
311       {
312         _nval=idsInPfl->getNumberOfTuples();
313         getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,arrr->getNumberOfTuples(),1);
314         _end=_start+_nval;
315         break;
316       }
317     case ON_CELLS:
318       {
319         _nval=idsInPfl->getNumberOfTuples();
320         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
321         _end=_start+_nval;
322         break;
323       }
324     case ON_GAUSS_NE:
325       {
326         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
327         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr->deltaShiftIndex();
328         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
329         arr3->computeOffsets2();
330         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
331         int trueNval=tmp->getNumberOfTuples();
332         _nval=idsInPfl->getNumberOfTuples();
333         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
334         _end=_start+trueNval;
335         break;
336       }
337     case ON_GAUSS_PT:
338       {
339         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
340         if(!disc2)
341           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
342         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
343         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
344         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
345         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da2->getIdsEqual(_loc_id);
346         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
347         //
348         MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
349         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
350         //
351         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=DataArrayInt::New();
352         int trueNval=0;
353         for(const int *pt=da4->begin();pt!=da4->end();pt++)
354           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
355         tmp->alloc(trueNval,1);
356         int *tmpPtr=tmp->getPointer();
357         for(const int *pt=da4->begin();pt!=da4->end();pt++)
358           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
359             *tmpPtr++=j;
360         //
361         _nval=da4->getNumberOfTuples();
362         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
363         _end=_start+trueNval;
364         oss << "_loc_" << _loc_id;
365         if(locIds)
366           {
367             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
368             da5->setName(oss.str().c_str());
369             glob.appendProfile(da5);
370             _profile=oss.str();
371           }
372         else
373           {
374             if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity())
375               {
376                 da3->setName(oss.str().c_str());
377                 glob.appendProfile(da3);
378                 _profile=oss.str();
379               }
380           }
381         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
382         _localization=oss2.str();
383         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
384         break;
385       }
386     default:
387       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
388   }
389   start=_end;
390 }
391
392 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
393 {
394   _start=start;
395   _nval=arrr->getNumberOfTuples();
396   getOrCreateAndGetArray()->setContigPartOfSelectedValues2(_start,arrr,0,_nval,1);
397   _end=_start+_nval;
398   start=_end;
399 }
400
401 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt)
402 {
403   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt);
404 }
405
406 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId)
407 {
408   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
409 }
410
411 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
412 {
413   return new MEDFileFieldPerMeshPerTypePerDisc(other);
414 }
415
416 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
417 {
418   return _profile.capacity()+_localization.capacity()+5*sizeof(int);
419 }
420
421 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildren() const
422 {
423   return std::vector<const BigMemoryObject *>();
424 }
425
426 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCpy(MEDFileFieldPerMeshPerType *father) const
427 {
428   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
429   ret->_father=father;
430   return ret.retn();
431 }
432
433 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField atype, int profileIt)
434 try:_type(atype),_father(fath),_profile_it(profileIt)
435 {
436 }
437 catch(INTERP_KERNEL::Exception& e)
438 {
439     throw e;
440 }
441
442 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
443 {
444 }
445
446 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_tmp_work1(other._tmp_work1)
447 {
448 }
449
450 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
451     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
452 {
453 }
454
455 const MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
456 {
457   return _father;
458 }
459
460 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
461 {
462   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
463   INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
464   std::string fieldName=nasc.getName();
465   std::string meshName=getMeshName();
466   int iteration=getIteration();
467   int order=getOrder();
468   TypeOfField type=getType();
469   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
470   int profilesize,nbi;
471   med_geometry_type mgeoti;
472   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
473   _nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it,MED_COMPACT_PFLMODE,
474       pflname,&profilesize,locname,&nbi);
475   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
476   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
477   _start=start;
478   _end=start+_nval*nbi;
479   start=_end;
480   if(type==ON_CELLS && !_localization.empty())
481     {
482       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
483         setType(ON_GAUSS_PT);
484       else
485         {
486           setType(ON_GAUSS_NE);
487           _localization.clear();
488         }
489     }
490 }
491
492 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
493 {
494   std::string fieldName=nasc.getName();
495   std::string meshName=getMeshName();
496   int iteration=getIteration();
497   int order=getOrder();
498   TypeOfField type=getType();
499   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
500   med_geometry_type mgeoti;
501   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
502   if(_start>_end)
503     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
504   if(_start==_end)
505     return ;
506   DataArray *arr=getOrCreateAndGetArray();//arr is not null due to the spec of getOrCreateAndGetArray
507   if(_start<0 || _start>=arr->getNumberOfTuples())
508     {
509       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
510       throw INTERP_KERNEL::Exception(oss.str().c_str());
511     }
512   if(_end<0 || _end>arr->getNumberOfTuples())
513     {
514       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
515       throw INTERP_KERNEL::Exception(oss.str().c_str());
516     }
517   med_int tmp1,nbi;
518   INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
519   med_int nbValsInFile=MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi);
520   int nbOfCompo=arr->getNumberOfComponents();
521   if(_end-_start!=nbValsInFile*nbi)
522     {
523       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
524       throw INTERP_KERNEL::Exception(oss.str().c_str());
525     }
526   DataArrayDouble *arrD=dynamic_cast<DataArrayDouble *>(arr);
527   if(arrD)
528     {
529       double *startFeeding=arrD->getPointer()+_start*nbOfCompo;
530       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
531                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
532       return ;
533     }
534   DataArrayInt *arrI=dynamic_cast<DataArrayInt *>(arr);
535   if(arrI)
536     {
537       int *startFeeding=arrI->getPointer()+_start*nbOfCompo;
538       MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,
539                                  _profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(startFeeding));
540       return ;
541     }
542   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
543 }
544
545 /*!
546  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
547  */
548 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
549 {
550   int delta=_end-_start;
551   _start=newValueOfStart;
552   _end=_start+delta;
553 }
554
555 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
556 {
557   return _father->getIteration();
558 }
559
560 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
561 {
562   return _father->getOrder();
563 }
564
565 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
566 {
567   return _father->getTime();
568 }
569
570 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
571 {
572   return _father->getMeshName();
573 }
574
575 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
576 {
577   const char startLine[]="    ## ";
578   std::string startLine2(bkOffset,' ');
579   startLine2+=startLine;
580   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
581   oss << startLine2 << "Localization #" << id << "." << std::endl;
582   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
583   delete tmp;
584   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
585   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
586   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
587 }
588
589 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
590 {
591   return _type;
592 }
593
594 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
595 {
596   types.insert(_type);
597 }
598
599 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
600 {
601   _type=newType;
602 }
603
604 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
605 {
606   return _father->getGeoType();
607 }
608
609 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
610 {
611   return _father->getNumberOfComponents();
612 }
613
614 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
615 {
616   return _end-_start;
617 }
618
619 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
620 {
621   return _father->getOrCreateAndGetArray();
622 }
623
624 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
625 {
626   const MEDFileFieldPerMeshPerType *fath=_father;
627   return fath->getOrCreateAndGetArray();
628 }
629
630 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
631 {
632   return _father->getInfo();
633 }
634
635 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
636 {
637   return _profile;
638 }
639
640 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
641 {
642   _profile=newPflName;
643 }
644
645 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
646 {
647   return _localization;
648 }
649
650 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
651 {
652   _localization=newLocName;
653 }
654
655 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
656 {
657   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
658     {
659       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
660         {
661           _profile=(*it2).second;
662           return;
663         }
664     }
665 }
666
667 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
668 {
669   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
670     {
671       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
672         {
673           _localization=(*it2).second;
674           return;
675         }
676     }
677 }
678
679 void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
680 {
681   if(type!=_type)
682     return ;
683   dads.push_back(std::pair<int,int>(_start,_end));
684   geoTypes.push_back(getGeoType());
685   if(_profile.empty())
686     pfls.push_back(0);
687   else
688     {
689       pfls.push_back(glob->getProfile(_profile.c_str()));
690     }
691   if(_localization.empty())
692     locs.push_back(-1);
693   else
694     {
695       locs.push_back(glob->getLocalizationId(_localization.c_str()));
696     }
697 }
698
699 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
700 {
701   entries[startEntryId]=std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int> ,std::pair<int,int> >(std::pair<INTERP_KERNEL::NormalizedCellType,int>(getGeoType(),discId),std::pair<int,int>(_start,_end));
702   startEntryId++;
703 }
704
705 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
706 {
707   TypeOfField type=getType();
708   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
709   med_geometry_type mgeoti;
710   med_entity_type menti=MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(type,geoType,mgeoti);
711   const DataArray *arr=getOrCreateAndGetArray();
712   if(!arr)
713     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
714   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
715   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
716   const unsigned char *locToWrite=0;
717   if(arrD)
718     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
719   else if(arrI)
720     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
721   else
722     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
723   MEDfieldValueWithProfileWr(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
724                              MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
725                              locToWrite);
726 }
727
728 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
729 {
730   type=_type;
731   pfl=_profile;
732   loc=_localization;
733   dad.first=_start; dad.second=_end;
734 }
735
736 /*!
737  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
738  *             This code corresponds to the distribution of types in the corresponding mesh.
739  * \param [out] ptToFill memory zone where the output will be stored.
740  * \return the size of data pushed into output param \a ptToFill
741  */
742 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
743 {
744   _loc_id=offset;
745   std::ostringstream oss;
746   std::size_t nbOfType=codeOfMesh.size()/3;
747   int found=-1;
748   for(std::size_t i=0;i<nbOfType && found==-1;i++)
749     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
750       found=(int)i;
751   if(found==-1)
752     {
753       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
754       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
755       throw INTERP_KERNEL::Exception(oss.str().c_str());
756     }
757   int *work=ptToFill;
758   if(_profile.empty())
759     {
760       if(_nval!=codeOfMesh[3*found+1])
761         {
762           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
763           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
764           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
765           throw INTERP_KERNEL::Exception(oss.str().c_str());
766         }
767       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
768         *work++=ii;
769     }
770   else
771     {
772       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
773       if(pfl->getNumberOfTuples()!=_nval)
774         {
775           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
776           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
777           oss << _nval;
778           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
779           throw INTERP_KERNEL::Exception(oss.str().c_str());
780         }
781       int offset2=codeOfMesh[3*found+2];
782       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
783         {
784           if(*pflId<codeOfMesh[3*found+1])
785             *work++=offset2+*pflId;
786         }
787     }
788   return _nval;
789 }
790
791 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
792 {
793   for(int i=_start;i<_end;i++)
794     *ptToFill++=i;
795   return _end-_start;
796 }
797
798 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
799 {
800   switch(type)
801   {
802     case ON_CELLS:
803       return -2;
804     case ON_GAUSS_NE:
805       return -1;
806     case ON_GAUSS_PT:
807       return locId;
808     default:
809       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
810   }
811 }
812
813 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
814 {
815   int id=0;
816   std::map<std::pair<std::string,TypeOfField>,int> m;
817   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
818   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
819     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
820       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
821   ret.resize(id);
822   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
823     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
824   return ret;
825 }
826
827 /*!
828  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
829  * 
830  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
831  * \param [in] entriesOnSameDisc some entries **on same localization** if not the result can be invalid. The _start and _end on them are relative to \a arr parameter.
832  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
833  * \param [in] newCode one of the input parameter to explicit the new geo type dispatch (in classical format same than those asked by MEDFileFields::renumberEntitiesLyingOnMesh)
834  * \param [in,out] glob if necessary by the method, new profiles can be added to it
835  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
836  * \param [out] result All new entries will be appended on it.
837  * \return false if the configuration of renumbering leads to an unnecessary resplit of input \a entriesOnSameDisc. If not true is returned (the most general case !)
838  */
839 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
840                                                        const DataArrayInt *explicitIdsInMesh,
841                                                        const std::vector<int>& newCode,
842                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
843                                                        std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >& result)
844 {
845   if(entriesOnSameDisc.empty())
846     return false;
847   TypeOfField type=entriesOnSameDisc[0]->getType();
848   int szEntities=0,szTuples=0;
849   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
850     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
851   int nbi=szTuples/szEntities;
852   if(szTuples%szEntities!=0)
853     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
854   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
855   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
856   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
857   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
858   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
859   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
860   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
861   int id=0;
862   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
863     {
864       int startOfEltIdOfChunk=(*it)->_start;
865       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newEltIds=explicitIdsInMesh->substr(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
866       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
867       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
868       //
869       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
870       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
871       //
872       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
873       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
874     }
875   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
876   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
877   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
878   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
879   //
880   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
881   //
882   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arrPart=arr->substr(offset,offset+szTuples);
883   arrPart->renumberInPlace(renumTupleIds->begin());
884   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
885   bool ret=false;
886   const int *idIt=diffVals->begin();
887   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
888   int offset2=0;
889   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
890     {
891       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=newGeoTypesEltIdsAllGather->getIdsEqual(*idIt);
892       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
893       int nbEntityElts=subIds->getNumberOfTuples();
894       bool ret2;
895       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
896           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIdentity() || nbEntityElts!=newCode[3*(*idIt)+1],nbi,
897                                       offset+offset2,
898                                       li,glob,ret2);
899       ret=ret || ret2;
900       result.push_back(eltToAdd);
901       offset2+=nbEntityElts*nbi;
902     }
903   ret=ret || li.empty();
904   return ret;
905 }
906
907 /*!
908  * \param [in] typeF type of field of new chunk
909  * \param [in] geoType the geometric type of the chunk
910  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
911  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
912  * \param [in] nbi number of integration points
913  * \param [in] offset The offset in the **global array of data**.
914  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
915  *                 to the new chunk to create.
916  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
917  * \param [out] notInExisting If false the return newly allocated entry is not coming from \a entriesOnSameDisc. If true the output comes from copy of \a entriesOnSameDisc
918  *              and corresponding entry erased from \a entriesOnSameDisc.
919  * \return a newly allocated chunk
920  */
921 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
922                                                                                                   bool isPfl, int nbi, int offset,
923                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
924                                                                                                   MEDFileFieldGlobsReal& glob,
925                                                                                                   bool &notInExisting)
926 {
927   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
928   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
929   for(;it!=entriesOnSameDisc.end();it++)
930     {
931       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
932         {
933           if(!isPfl)
934             {
935               if((*it)->_profile.empty())
936                 break;
937               else
938                 if(!(*it)->_profile.empty())
939                   {
940                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
941                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
942                       break;
943                   }
944             }
945         }
946     }
947   if(it==entriesOnSameDisc.end())
948     {
949       notInExisting=true;
950       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
951       ret->_type=typeF;
952       ret->_loc_id=(int)geoType;
953       ret->_nval=nbMeshEntities;
954       ret->_start=offset;
955       ret->_end=ret->_start+ret->_nval*nbi;
956       if(isPfl)
957         {
958           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
959           glob.appendProfile(idsOfMeshElt);
960           ret->_profile=idsOfMeshElt->getName();
961         }
962       //tony treatment of localization
963       return ret;
964     }
965   else
966     {
967       notInExisting=false;
968       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
969       ret->_loc_id=(int)geoType;
970       ret->setNewStart(offset);
971       entriesOnSameDisc.erase(it);
972       return ret;
973     }
974
975 }
976
977 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc)
978 {
979   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc);
980 }
981
982 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
983 {
984   return new MEDFileFieldPerMeshPerType(fath,geoType);
985 }
986
987 std::size_t MEDFileFieldPerMeshPerType::getHeapMemorySizeWithoutChildren() const
988 {
989   return _field_pm_pt_pd.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc>);
990 }
991
992 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerType::getDirectChildren() const
993 {
994   std::vector<const BigMemoryObject *> ret;
995   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
996     {
997       const MEDFileFieldPerMeshPerTypePerDisc *cur(*it);
998       if(cur)
999         ret.push_back(cur);
1000     }
1001   return ret;
1002 }
1003
1004 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCpy(MEDFileFieldPerMesh *father) const
1005 {
1006   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1007   ret->_father=father;
1008   std::size_t i=0;
1009   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1010     {
1011       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1012         ret->_field_pm_pt_pd[i]=(*it)->deepCpy((MEDFileFieldPerMeshPerType *)ret);
1013     }
1014   return ret.retn();
1015 }
1016
1017 void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1018 {
1019   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1020   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1021     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1022 }
1023
1024 /*!
1025  * This method is the most general one. No optimization is done here.
1026  * \param [in] multiTypePfl is the end user profile specified in high level API
1027  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1028  * \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.
1029  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1030  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1031  * \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.
1032  */
1033 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)
1034 {
1035   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1036   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1037     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1038 }
1039
1040 void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1041 {
1042   _field_pm_pt_pd.resize(1);
1043   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1044   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1045 }
1046
1047 void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1048 {
1049   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2=pfl->deepCpy();
1050   if(!arr || !arr->isAllocated())
1051     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : input array is null, or not allocated !");
1052   _field_pm_pt_pd.resize(1);
1053   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1054   _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.
1055 }
1056
1057 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1058 {
1059   TypeOfField type=field->getTypeOfField();
1060   if(type!=ON_GAUSS_PT)
1061     {
1062       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1063       int sz=_field_pm_pt_pd.size();
1064       bool found=false;
1065       for(int j=0;j<sz && !found;j++)
1066         {
1067           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1068             {
1069               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1070               found=true;
1071             }
1072         }
1073       if(!found)
1074         {
1075           _field_pm_pt_pd.resize(sz+1);
1076           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1077         }
1078       std::vector<int> ret(1,(int)sz);
1079       return ret;
1080     }
1081   else
1082     {
1083       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1084       int sz2=ret2.size();
1085       std::vector<int> ret3(sz2);
1086       int k=0;
1087       for(int i=0;i<sz2;i++)
1088         {
1089           int sz=_field_pm_pt_pd.size();
1090           int locIdToFind=ret2[i];
1091           bool found=false;
1092           for(int j=0;j<sz && !found;j++)
1093             {
1094               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1095                 {
1096                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1097                   ret3[k++]=j;
1098                   found=true;
1099                 }
1100             }
1101           if(!found)
1102             {
1103               _field_pm_pt_pd.resize(sz+1);
1104               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1105               ret3[k++]=sz;
1106             }
1107         }
1108       return ret3;
1109     }
1110 }
1111
1112 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1113 {
1114   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1115   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1116   if(!disc2)
1117     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1118   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1119   if(!da)
1120     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1121   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleId2(offset,offset+nbOfCells,1);
1122   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1123   if(retTmp->presenceOfValue(-1))
1124     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1125   std::vector<int> ret(retTmp->begin(),retTmp->end());
1126   return ret;
1127 }
1128
1129 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1130 {
1131   TypeOfField type=field->getTypeOfField();
1132   if(type!=ON_GAUSS_PT)
1133     {
1134       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1135       int sz=_field_pm_pt_pd.size();
1136       bool found=false;
1137       for(int j=0;j<sz && !found;j++)
1138         {
1139           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1140             {
1141               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1142               found=true;
1143             }
1144         }
1145       if(!found)
1146         {
1147           _field_pm_pt_pd.resize(sz+1);
1148           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1149         }
1150       std::vector<int> ret(1,0);
1151       return ret;
1152     }
1153   else
1154     {
1155       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1156       int sz2=ret2.size();
1157       std::vector<int> ret3(sz2);
1158       int k=0;
1159       for(int i=0;i<sz2;i++)
1160         {
1161           int sz=_field_pm_pt_pd.size();
1162           int locIdToFind=ret2[i];
1163           bool found=false;
1164           for(int j=0;j<sz && !found;j++)
1165             {
1166               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1167                 {
1168                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1169                   ret3[k++]=j;
1170                   found=true;
1171                 }
1172             }
1173           if(!found)
1174             {
1175               _field_pm_pt_pd.resize(sz+1);
1176               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1177               ret3[k++]=sz;
1178             }
1179         }
1180       return ret3;
1181     }
1182 }
1183
1184 std::vector<int> MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1185 {
1186   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1187   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1188   if(!disc2)
1189     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1190   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1191   if(!da)
1192     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1193   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1194   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retTmp=da2->getDifferentValues();
1195   if(retTmp->presenceOfValue(-1))
1196     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1197   std::vector<int> ret(retTmp->begin(),retTmp->end());
1198   return ret;
1199 }
1200
1201 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const
1202 {
1203   return _father;
1204 }
1205
1206 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1207 {
1208   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1209   int curDim=(int)cm.getDimension();
1210   dim=std::max(dim,curDim);
1211 }
1212
1213 void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1214 {
1215   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1216     {
1217       (*it)->fillTypesOfFieldAvailable(types);
1218     }
1219 }
1220
1221 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
1222 {
1223   int sz=_field_pm_pt_pd.size();
1224   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1225   for(int i=0;i<sz;i++)
1226     {
1227       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1228     }
1229 }
1230
1231 int MEDFileFieldPerMeshPerType::getIteration() const
1232 {
1233   return _father->getIteration();
1234 }
1235
1236 int MEDFileFieldPerMeshPerType::getOrder() const
1237 {
1238   return _father->getOrder();
1239 }
1240
1241 double MEDFileFieldPerMeshPerType::getTime() const
1242 {
1243   return _father->getTime();
1244 }
1245
1246 std::string MEDFileFieldPerMeshPerType::getMeshName() const
1247 {
1248   return _father->getMeshName();
1249 }
1250
1251 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1252 {
1253   const char startLine[]="  ## ";
1254   std::string startLine2(bkOffset,' ');
1255   std::string startLine3(startLine2);
1256   startLine3+=startLine;
1257   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1258     {
1259       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1260       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1261     }
1262   else
1263     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1264   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1265   int i=0;
1266   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1267     {
1268       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1269       if(cur)
1270         cur->simpleRepr(bkOffset,oss,i);
1271       else
1272         {
1273           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1274         }
1275     }
1276 }
1277
1278 void MEDFileFieldPerMeshPerType::getSizes(int& globalSz, int& nbOfEntries) const
1279 {
1280   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1281     {
1282       globalSz+=(*it)->getNumberOfTuples();
1283     }
1284   nbOfEntries+=(int)_field_pm_pt_pd.size();
1285 }
1286
1287 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1288 {
1289   return _geo_type;
1290 }
1291
1292
1293 int MEDFileFieldPerMeshPerType::getNumberOfComponents() const
1294 {
1295   return _father->getNumberOfComponents();
1296 }
1297
1298 DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray()
1299 {
1300   return _father->getOrCreateAndGetArray();
1301 }
1302
1303 const DataArray *MEDFileFieldPerMeshPerType::getOrCreateAndGetArray() const
1304 {
1305   const MEDFileFieldPerMesh *fath=_father;
1306   return fath->getOrCreateAndGetArray();
1307 }
1308
1309 const std::vector<std::string>& MEDFileFieldPerMeshPerType::getInfo() const
1310 {
1311   return _father->getInfo();
1312 }
1313
1314 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsed() const
1315 {
1316   std::vector<std::string> ret;
1317   std::set<std::string> ret2;
1318   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1319     {
1320       std::string tmp=(*it1)->getProfile();
1321       if(!tmp.empty())
1322         if(ret2.find(tmp)==ret2.end())
1323           {
1324             ret.push_back(tmp);
1325             ret2.insert(tmp);
1326           }
1327     }
1328   return ret;
1329 }
1330
1331 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsed() const
1332 {
1333   std::vector<std::string> ret;
1334   std::set<std::string> ret2;
1335   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1336     {
1337       std::string tmp=(*it1)->getLocalization();
1338       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1339         if(ret2.find(tmp)==ret2.end())
1340           {
1341             ret.push_back(tmp);
1342             ret2.insert(tmp);
1343           }
1344     }
1345   return ret;
1346 }
1347
1348 std::vector<std::string> MEDFileFieldPerMeshPerType::getPflsReallyUsedMulti() const
1349 {
1350   std::vector<std::string> ret;
1351   std::set<std::string> ret2;
1352   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1353     {
1354       std::string tmp=(*it1)->getProfile();
1355       if(!tmp.empty())
1356         ret.push_back(tmp);
1357     }
1358   return ret;
1359 }
1360
1361 std::vector<std::string> MEDFileFieldPerMeshPerType::getLocsReallyUsedMulti() const
1362 {
1363   std::vector<std::string> ret;
1364   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1365     {
1366       std::string tmp=(*it1)->getLocalization();
1367       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1368         ret.push_back(tmp);
1369     }
1370   return ret;
1371 }
1372
1373 void MEDFileFieldPerMeshPerType::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1374 {
1375   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1376     (*it1)->changePflsRefsNamesGen(mapOfModif);
1377 }
1378
1379 void MEDFileFieldPerMeshPerType::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1380 {
1381   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1382     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1383 }
1384
1385 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId)
1386 {
1387   if(_field_pm_pt_pd.empty())
1388     {
1389       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1390       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1391       throw INTERP_KERNEL::Exception(oss.str().c_str());
1392     }
1393   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1394     return _field_pm_pt_pd[locId];
1395   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1396   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1397   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1398   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1399   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1400 }
1401
1402 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerType::getLeafGivenLocId(int locId) const
1403 {
1404   if(_field_pm_pt_pd.empty())
1405     {
1406       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1407       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no localizations for geotype \"" << cm.getRepr() << "\" !";
1408       throw INTERP_KERNEL::Exception(oss.str().c_str());
1409     }
1410   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1411     return _field_pm_pt_pd[locId];
1412   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1413   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerType::getLeafGivenLocId : no such locId available (" << locId;
1414   oss2 << ") for geometric type \"" << cm.getRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1415   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1416   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1417 }
1418
1419 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
1420 {
1421   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1422     {
1423       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1424       if(meshDim!=(int)cm.getDimension())
1425         return ;
1426     }
1427   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1428     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1429 }
1430
1431 void MEDFileFieldPerMeshPerType::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1432 {
1433   int i=0;
1434   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1435     {
1436       (*it)->fillValues(i,startEntryId,entries);
1437     }
1438 }
1439
1440 void MEDFileFieldPerMeshPerType::setLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1441 {
1442   _field_pm_pt_pd=leaves;
1443   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1444     (*it)->setFather(this);
1445 }
1446
1447 /*!
1448  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1449  *  \param [out] its - list of pair (start,stop) kept
1450  *  \return bool - false if the type of field \a tof is not contained in \a this.
1451  */
1452 bool MEDFileFieldPerMeshPerType::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1453 {
1454   bool ret=false;
1455   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1456   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1457     if((*it)->getType()==tof)
1458       {
1459         newPmPtPd.push_back(*it);
1460         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1461         (*it)->setNewStart(globalNum);
1462         globalNum=(*it)->getEnd();
1463         its.push_back(bgEnd);
1464         ret=true;
1465       }
1466   if(ret)
1467     _field_pm_pt_pd=newPmPtPd;
1468   return ret;
1469 }
1470
1471 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType):_father(fath),_geo_type(geoType)
1472 {
1473 }
1474
1475 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc):_father(fath),_geo_type(geoType)
1476 {
1477   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1478   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1479   med_geometry_type mgeoti;
1480   med_entity_type menti;
1481   menti=ConvertIntoMEDFileType(type,geoType,mgeoti);
1482   int nbProfiles=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName);
1483   _field_pm_pt_pd.resize(nbProfiles);
1484   for(int i=0;i<nbProfiles;i++)
1485     {
1486       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i+1);
1487     }
1488   if(type==ON_CELLS)
1489     {
1490       int nbProfiles2=MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName);
1491       for(int i=0;i<nbProfiles2;i++)
1492         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i+1));
1493     }
1494 }
1495
1496 void MEDFileFieldPerMeshPerType::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1497 {
1498   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1499     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1500 }
1501
1502 void MEDFileFieldPerMeshPerType::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1503 {
1504   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1505     (*it)->loadBigArray(fid,nasc);
1506 }
1507
1508 void MEDFileFieldPerMeshPerType::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1509 {
1510   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1511     {
1512       (*it)->copyOptionsFrom(*this);
1513       (*it)->writeLL(fid,nasc);
1514     }
1515 }
1516
1517 med_entity_type MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1518 {
1519   switch(ikType)
1520   {
1521     case ON_CELLS:
1522       medfGeoType=typmai3[(int)ikGeoType];
1523       return MED_CELL;
1524     case ON_NODES:
1525       medfGeoType=MED_NONE;
1526       return MED_NODE;
1527     case ON_GAUSS_NE:
1528       medfGeoType=typmai3[(int)ikGeoType];
1529       return MED_NODE_ELEMENT;
1530     case ON_GAUSS_PT:
1531       medfGeoType=typmai3[(int)ikGeoType];
1532       return MED_CELL;
1533     default:
1534       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1535   }
1536   return MED_UNDEF_ENTITY_TYPE;
1537 }
1538
1539 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc)
1540 {
1541   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc);
1542 }
1543
1544 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1545 {
1546   return new MEDFileFieldPerMesh(fath,mesh);
1547 }
1548
1549 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1550 {
1551   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType >);
1552 }
1553
1554 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildren() const
1555 {
1556   std::vector<const BigMemoryObject *> ret;
1557   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1558     {
1559       const MEDFileFieldPerMeshPerType *cur(*it);
1560       if(cur)
1561         ret.push_back(cur);
1562     }
1563   return ret;
1564 }
1565
1566 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCpy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1567 {
1568   MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1569   ret->_father=father;
1570   std::size_t i=0;
1571   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1572     {
1573       if((const MEDFileFieldPerMeshPerType *)*it)
1574         ret->_field_pm_pt[i]=(*it)->deepCpy((MEDFileFieldPerMesh *)(ret));
1575     }
1576   return ret.retn();
1577 }
1578
1579 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1580 {
1581   std::string startLine(bkOffset,' ');
1582   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1583   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1584   int i=0;
1585   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1586     {
1587       const MEDFileFieldPerMeshPerType *cur=*it;
1588       if(cur)
1589         cur->simpleRepr(bkOffset,oss,i);
1590       else
1591         {
1592           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1593         }
1594     }
1595 }
1596
1597 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1598 {
1599   _mesh_name=mesh->getName();
1600   mesh->getTime(_mesh_iteration,_mesh_order);
1601 }
1602
1603 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1604 {
1605   int nbOfTypes=code.size()/3;
1606   int offset=0;
1607   for(int i=0;i<nbOfTypes;i++)
1608     {
1609       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1610       int nbOfCells=code[3*i+1];
1611       int pos=addNewEntryIfNecessary(type);
1612       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1613       offset+=nbOfCells;
1614     }
1615 }
1616
1617 /*!
1618  * This method is the most general one. No optimization is done here.
1619  * \param [in] multiTypePfl is the end user profile specified in high level API
1620  * \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].
1621  * \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.
1622  * \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.
1623  * \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.
1624  * \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.
1625  */
1626 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)
1627 {
1628   int nbOfTypes(code.size()/3);
1629   for(int i=0;i<nbOfTypes;i++)
1630     {
1631       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1632       int pos=addNewEntryIfNecessary(type);
1633       DataArrayInt *pfl=0;
1634       if(code[3*i+2]!=-1)
1635         pfl=idsPerType[code[3*i+2]];
1636       int nbOfTupes2=code2.size()/3;
1637       int found=0;
1638       for(;found<nbOfTupes2;found++)
1639         if(code[3*i]==code2[3*found])
1640           break;
1641       if(found==nbOfTupes2)
1642         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1643       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1644     }
1645 }
1646
1647 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1648 {
1649   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1650   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1651 }
1652
1653 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1654 {
1655   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1656   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1657 }
1658
1659 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1660 {
1661   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1662     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1663 }
1664
1665 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1666 {
1667   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1668     (*it)->loadBigArraysRecursively(fid,nasc);
1669 }
1670
1671 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1672 {
1673   int nbOfTypes=_field_pm_pt.size();
1674   for(int i=0;i<nbOfTypes;i++)
1675     {
1676       _field_pm_pt[i]->copyOptionsFrom(*this);
1677       _field_pm_pt[i]->writeLL(fid,nasc);
1678     }
1679 }
1680
1681 void MEDFileFieldPerMesh::getDimension(int& dim) const
1682 {
1683   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1684     (*it)->getDimension(dim);
1685 }
1686
1687 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1688 {
1689   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1690     (*it)->fillTypesOfFieldAvailable(types);
1691 }
1692
1693 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
1694 {
1695   int sz=_field_pm_pt.size();
1696   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1697   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1698   for(int i=0;i<sz;i++)
1699     {
1700       types[i]=_field_pm_pt[i]->getGeoType();
1701       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1702     }
1703   return ret;
1704 }
1705
1706 double MEDFileFieldPerMesh::getTime() const
1707 {
1708   int tmp1,tmp2;
1709   return _father->getTime(tmp1,tmp2);
1710 }
1711
1712 int MEDFileFieldPerMesh::getIteration() const
1713 {
1714   return _father->getIteration();
1715 }
1716
1717 int MEDFileFieldPerMesh::getOrder() const
1718 {
1719   return _father->getOrder();
1720 }
1721
1722 int MEDFileFieldPerMesh::getNumberOfComponents() const
1723 {
1724   return _father->getNumberOfComponents();
1725 }
1726
1727 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1728 {
1729   if(!_father)
1730     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1731   return _father->getOrCreateAndGetArray();
1732 }
1733
1734 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1735 {
1736   if(!_father)
1737     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1738   return _father->getOrCreateAndGetArray();
1739 }
1740
1741 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1742 {
1743   return _father->getInfo();
1744 }
1745
1746 /*!
1747  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1748  * 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.
1749  * It returns 2 output vectors :
1750  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1751  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1752  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1753  */
1754 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)
1755 {
1756   int notNullPflsSz=0;
1757   int nbOfArrs=geoTypes.size();
1758   for(int i=0;i<nbOfArrs;i++)
1759     if(pfls[i])
1760       notNullPflsSz++;
1761   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1762   int nbOfDiffGeoTypes=geoTypes3.size();
1763   code.resize(3*nbOfDiffGeoTypes);
1764   notNullPfls.resize(notNullPflsSz);
1765   notNullPflsSz=0;
1766   int j=0;
1767   for(int i=0;i<nbOfDiffGeoTypes;i++)
1768     {
1769       int startZone=j;
1770       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1771       std::vector<const DataArrayInt *> notNullTmp;
1772       if(pfls[j])
1773         notNullTmp.push_back(pfls[j]);
1774       j++;
1775       for(;j<nbOfArrs;j++)
1776         if(geoTypes[j]==refType)
1777           {
1778             if(pfls[j])
1779               notNullTmp.push_back(pfls[j]);
1780           }
1781         else
1782           break;
1783       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1784       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1785       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1786       code[3*i]=(int)refType;
1787       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1788       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1789       if(notNullTmp.empty())
1790         code[3*i+2]=-1;
1791       else
1792         {
1793           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1794           code[3*i+2]=notNullPflsSz++;
1795         }
1796     }
1797 }
1798
1799 /*!
1800  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1801  */
1802 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)
1803 {
1804   int sz=dads.size();
1805   int ret=0;
1806   for(int i=0;i<sz;i++)
1807     {
1808       if(locs[i]==-1)
1809         {
1810           if(type!=ON_GAUSS_NE)
1811             ret+=dads[i].second-dads[i].first;
1812           else
1813             {
1814               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1815               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1816             }
1817         }
1818       else
1819         {
1820           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1821           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1822         }
1823     }
1824   return ret;
1825 }
1826
1827 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1828 {
1829   std::vector<std::string> ret;
1830   std::set<std::string> ret2;
1831   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1832     {
1833       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
1834       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1835         if(ret2.find(*it2)==ret2.end())
1836           {
1837             ret.push_back(*it2);
1838             ret2.insert(*it2);
1839           }
1840     }
1841   return ret;
1842 }
1843
1844 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
1845 {
1846   std::vector<std::string> ret;
1847   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1848     {
1849       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
1850       ret.insert(ret.end(),tmp.begin(),tmp.end());
1851     }
1852   return ret;
1853 }
1854
1855 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
1856 {
1857   std::vector<std::string> ret;
1858   std::set<std::string> ret2;
1859   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1860     {
1861       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
1862       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1863         if(ret2.find(*it2)==ret2.end())
1864           {
1865             ret.push_back(*it2);
1866             ret2.insert(*it2);
1867           }
1868     }
1869   return ret;
1870 }
1871
1872 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
1873 {
1874   std::vector<std::string> ret;
1875   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1876     {
1877       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
1878       ret.insert(ret.end(),tmp.begin(),tmp.end());
1879     }
1880   return ret;
1881 }
1882
1883 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
1884 {
1885   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
1886     {
1887       if((*it).first==_mesh_name)
1888         {
1889           _mesh_name=(*it).second;
1890           return true;
1891         }
1892     }
1893   return false;
1894 }
1895
1896 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
1897                                                       MEDFileFieldGlobsReal& glob)
1898 {
1899   if(_mesh_name!=meshName)
1900     return false;
1901   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1902   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
1903   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
1904   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
1905   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
1906   getUndergroundDataArrayExt(entries);
1907   DataArray *arr0=getOrCreateAndGetArray();//tony
1908   if(!arr0)
1909     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
1910   DataArrayDouble *arr=dynamic_cast<DataArrayDouble *>(arr0);//tony
1911   if(!arr0)
1912     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
1913   int sz=0;
1914   if(!arr)
1915     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
1916   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
1917     {
1918       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
1919         {
1920           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1921           sz+=(*it).second.second-(*it).second.first;
1922         }
1923       else
1924         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
1925     }
1926   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
1927   ////////////////////
1928   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
1929   int *workI2=explicitIdsOldInMesh->getPointer();
1930   int sz1=0,sz2=0,sid=1;
1931   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
1932   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
1933   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
1934     {
1935       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
1936       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
1937       int *workI=explicitIdsOldInArr->getPointer();
1938       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
1939         {
1940           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
1941           (*itL2)->setLocId(sz2);
1942           (*itL2)->_tmp_work1=(*itL2)->getStart();
1943           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
1944         }
1945       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
1946     }
1947   explicitIdsOldInMesh->reAlloc(sz2);
1948   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
1949   ////////////////////
1950   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
1951   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
1952   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
1953   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
1954     {
1955       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
1956       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
1957       otherEntriesNew.back()->setLocId((*it)->getGeoType());
1958     }
1959   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
1960   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
1961   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
1962     {
1963       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1964       int newStart=elt->getLocId();
1965       elt->setLocId((*it)->getGeoType());
1966       elt->setNewStart(newStart);
1967       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
1968       entriesKeptNew.push_back(elt);
1969       entriesKeptNew2.push_back(elt);
1970     }
1971   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
1972   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
1973   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
1974   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
1975   bool ret=false;
1976   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
1977     {
1978       sid=0;
1979       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
1980         {
1981           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
1982           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
1983           }*/
1984       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
1985                                                             glob,arr2,otherEntriesNew) || ret;
1986     }
1987   if(!ret)
1988     return false;
1989   // Assign new dispatching
1990   assignNewLeaves(otherEntriesNew);
1991   arr->cpyFrom(*arr2);
1992   return true;
1993 }
1994
1995 /*!
1996  * \param [in,out] globalNum a global numbering counter for the renumbering.
1997  * \param [out] its - list of pair (start,stop) kept
1998  */
1999 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2000 {
2001   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > ret;
2002   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2003     {
2004       std::vector< std::pair<int,int> > its2;
2005       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2006         {
2007           ret.push_back(*it);
2008           its.insert(its.end(),its2.begin(),its2.end());
2009         }
2010     }
2011   _field_pm_pt=ret;
2012 }
2013
2014 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2015 {
2016   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2017   for( std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2018     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2019   //
2020   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > fieldPmPt(types.size());
2021   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2022   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=fieldPmPt.begin();
2023   for(;it1!=types.end();it1++,it2++)
2024     {
2025       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2026       elt->setLeaves((*it1).second);
2027       *it2=elt;
2028     }
2029   _field_pm_pt=fieldPmPt;
2030 }
2031
2032 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2033 {
2034   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2035     (*it)->changePflsRefsNamesGen(mapOfModif);
2036 }
2037
2038 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2039 {
2040   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2041     (*it)->changeLocsRefsNamesGen(mapOfModif);
2042 }
2043
2044 /*!
2045  * \param [in] mesh is the whole mesh
2046  */
2047 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2048 {
2049   if(_field_pm_pt.empty())
2050     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2051   //
2052   std::vector< std::pair<int,int> > dads;
2053   std::vector<const DataArrayInt *> pfls;
2054   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2055   std::vector<int> locs,code;
2056   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2057   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2058     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2059   // Sort by types
2060   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2061   if(code.empty())
2062     {
2063       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2064       throw INTERP_KERNEL::Exception(oss.str().c_str());
2065     }
2066   //
2067   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2068   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2069   if(type!=ON_NODES)
2070     {
2071       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2072       if(!arr)
2073         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2074       else
2075         {
2076           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr);
2077           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2078         }
2079     }
2080   else
2081     {
2082       if(code.size()!=3)
2083         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2084       int nb=code[1];
2085       if(code[2]==-1)
2086         {
2087           if(nb!=mesh->getNumberOfNodes())
2088             {
2089               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2090               oss << " nodes in mesh !";
2091               throw INTERP_KERNEL::Exception(oss.str().c_str());
2092             }
2093           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2094         }
2095       else
2096         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2097     }
2098 }
2099
2100 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2101 {
2102   if(_field_pm_pt.empty())
2103     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2104   //
2105   std::vector<std::pair<int,int> > dads;
2106   std::vector<const DataArrayInt *> pfls;
2107   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2108   std::vector<int> locs,code;
2109   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2110   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2111     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2112   // Sort by types
2113   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2114   if(code.empty())
2115     {
2116       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2117       throw INTERP_KERNEL::Exception(oss.str().c_str());
2118     }
2119   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2120   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2121   if(type!=ON_NODES)
2122     {
2123       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2124       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2125     }
2126   else
2127     {
2128       if(code.size()!=3)
2129         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2130       int nb=code[1];
2131       if(code[2]==-1)
2132         {
2133           if(nb!=mesh->getNumberOfNodes())
2134             {
2135               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2136               oss << " nodes in mesh !";
2137               throw INTERP_KERNEL::Exception(oss.str().c_str());
2138             }
2139         }
2140       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2141     }
2142   //
2143   return 0;
2144 }
2145
2146 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2147 {
2148   int globalSz=0;
2149   int nbOfEntries=0;
2150   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2151     {
2152       (*it)->getSizes(globalSz,nbOfEntries);
2153     }
2154   entries.resize(nbOfEntries);
2155   nbOfEntries=0;
2156   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2157     {
2158       (*it)->fillValues(nbOfEntries,entries);
2159     }
2160 }
2161
2162 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2163 {
2164   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2165     {
2166       if((*it)->getGeoType()==typ)
2167         return (*it)->getLeafGivenLocId(locId);
2168     }
2169   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2170   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2171   oss << "Possiblities are : ";
2172   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2173     {
2174       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2175       oss << "\"" << cm2.getRepr() << "\", ";
2176     }
2177   throw INTERP_KERNEL::Exception(oss.str().c_str());
2178 }
2179
2180 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2181 {
2182   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2183     {
2184       if((*it)->getGeoType()==typ)
2185         return (*it)->getLeafGivenLocId(locId);
2186     }
2187   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2188   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2189   oss << "Possiblities are : ";
2190   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2191     {
2192       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2193       oss << "\"" << cm2.getRepr() << "\", ";
2194     }
2195   throw INTERP_KERNEL::Exception(oss.str().c_str());
2196 }
2197
2198 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2199 {
2200   int i=0;
2201   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2202   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it2=_field_pm_pt.begin();
2203   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2204     {
2205       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2206       if(type==curType)
2207         return i;
2208       else
2209         {
2210           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2211           if(pos>pos2)
2212             it2=it+1;
2213         }
2214     }
2215   int ret=std::distance(_field_pm_pt.begin(),it2);
2216   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2217   return ret;
2218 }
2219
2220 /*!
2221  * 'dads' and 'locs' input parameters have the same number of elements
2222  * \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
2223  */
2224 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2225                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2226                                                          const MEDCouplingMesh *mesh, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2227 {
2228   isPfl=false;
2229   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2230   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2231   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2232   const std::vector<std::string>& infos=getInfo();
2233   da->setInfoOnComponents(infos);
2234   da->setName("");
2235   if(type==ON_GAUSS_PT)
2236     {
2237       int offset=0;
2238       int nbOfArrs=dads.size();
2239       for(int i=0;i<nbOfArrs;i++)
2240         {
2241           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2242           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2243           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2244           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> di=DataArrayInt::New();
2245           di->alloc(nbOfElems,1);
2246           di->iota(offset);
2247           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2248           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2249           offset+=nbOfElems;
2250         }
2251     }
2252   arrOut=da;
2253   return ret.retn();
2254 }
2255
2256 /*!
2257  * 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.
2258  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2259  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2260  * The order of cells in the returned field is those imposed by the profile.
2261  * \param [in] mesh is the global mesh.
2262  */
2263 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2264                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2265                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2266                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2267 {
2268   if(da->isIdentity())
2269     {
2270       int nbOfTuples=da->getNumberOfTuples();
2271       if(nbOfTuples==mesh->getNumberOfCells())
2272         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2273     }
2274   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2275   m2->setName(mesh->getName().c_str());
2276   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2277   isPfl=true;
2278   return ret.retn();
2279 }
2280
2281 /*!
2282  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2283  */
2284 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2285                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2286                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2287 {
2288   if(da->isIdentity())
2289     {
2290       int nbOfTuples=da->getNumberOfTuples();
2291       if(nbOfTuples==mesh->getNumberOfNodes())//No problem for NORM_ERROR because it is in context of node
2292         return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2293     }
2294   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2295   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2296   if(meshu)
2297     {
2298       if(meshu->getNodalConnectivity()==0)
2299         {
2300           MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2301           int nb=da->getNbOfElems();
2302           const int *ptr=da->getConstPointer();
2303           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2304           meshuc->allocateCells(nb);
2305           for(int i=0;i<nb;i++)
2306             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2307           meshuc->finishInsertingCells();
2308           ret->setMesh(meshuc);
2309           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2310           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2311           disc->checkCoherencyBetween(meshuc,arrOut);
2312           return ret.retn();
2313         }
2314     }
2315   //
2316   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2317   isPfl=true;
2318   DataArrayInt *arr2=0;
2319   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2320   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2321   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3(arr2);
2322   int nnodes=mesh2->getNumberOfNodes();
2323   if(nnodes==(int)da->getNbOfElems())
2324     {
2325       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2326       arrOut->renumberInPlace(da3->getConstPointer());
2327       mesh2->setName(mesh->getName().c_str());
2328       ret->setMesh(mesh2);
2329       return ret.retn();
2330     }
2331   else
2332     {
2333       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 !!!";
2334       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2335       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2336       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2337       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2338       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2339       throw INTERP_KERNEL::Exception(oss.str().c_str());
2340     }
2341   return 0;
2342 }
2343
2344 /*!
2345  * This method is the most light method of field retrieving.
2346  */
2347 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2348 {
2349   if(!pflIn)
2350     {
2351       pflOut=DataArrayInt::New();
2352       pflOut->alloc(nbOfElems,1);
2353       pflOut->iota(0);
2354     }
2355   else
2356     {
2357       pflOut=const_cast<DataArrayInt*>(pflIn);
2358       pflOut->incrRef();
2359     }
2360   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> safePfl(pflOut);
2361   MEDCouplingAutoRefCountObjectPtr<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2362   const std::vector<std::string>& infos=getInfo();
2363   int nbOfComp=infos.size();
2364   for(int i=0;i<nbOfComp;i++)
2365     da->setInfoOnComponent(i,infos[i].c_str());
2366   safePfl->incrRef();
2367   return da.retn();
2368 }
2369
2370 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2371     _mesh_csit(meshCsit),_father(fath)
2372 {
2373   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2374   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2375   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2376   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2377     {
2378       int nbProfile =MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[i],_mesh_csit,meshName,pflName,locName);
2379       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2380       int nbProfile2=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName);
2381       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2382       if(nbProfile>0 || nbProfile2>0)
2383         {
2384           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[i],nasc));
2385           if(nbProfile>0)
2386             _mesh_name=name0;
2387           else
2388             _mesh_name=name1;
2389         }
2390     }
2391   int nbProfile=MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName);
2392   if(nbProfile>0)
2393     {
2394       _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc));
2395       _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2396     }
2397 }
2398
2399 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2400 {
2401   copyTinyInfoFrom(mesh);
2402 }
2403
2404 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2405 {
2406   if(id>=(int)_pfls.size())
2407     _pfls.resize(id+1);
2408   _pfls[id]=DataArrayInt::New();
2409   int lgth=MEDprofileSizeByName(fid,pflName.c_str());
2410   _pfls[id]->setName(pflName);
2411   _pfls[id]->alloc(lgth,1);
2412   MEDprofileRd(fid,pflName.c_str(),_pfls[id]->getPointer());
2413   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2414 }
2415
2416 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2417 {
2418   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2419   int sz;
2420   MEDprofileInfo(fid,i+1,pflName,&sz);
2421   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2422   if(i>=(int)_pfls.size())
2423     _pfls.resize(i+1);
2424   _pfls[i]=DataArrayInt::New();
2425   _pfls[i]->alloc(sz,1);
2426   _pfls[i]->setName(pflCpp.c_str());
2427   MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
2428   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2429 }
2430
2431 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2432 {
2433   int nbOfPfls=_pfls.size();
2434   for(int i=0;i<nbOfPfls;i++)
2435     {
2436       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpy=_pfls[i]->deepCpy();
2437       cpy->applyLin(1,1,0);
2438       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2439       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2440       MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer());
2441     }
2442   //
2443   int nbOfLocs=_locs.size();
2444   for(int i=0;i<nbOfLocs;i++)
2445     _locs[i]->writeLL(fid);
2446 }
2447
2448 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2449 {
2450   std::vector<std::string> pfls=getPfls();
2451   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2452     {
2453       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2454       if(it2==pfls.end())
2455         {
2456           _pfls.push_back(*it);
2457         }
2458       else
2459         {
2460           int id=std::distance(pfls.begin(),it2);
2461           if(!(*it)->isEqual(*_pfls[id]))
2462             {
2463               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2464               throw INTERP_KERNEL::Exception(oss.str().c_str());
2465             }
2466         }
2467     }
2468   std::vector<std::string> locs=getLocs();
2469   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2470     {
2471       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2472       if(it2==locs.end())
2473         {
2474           _locs.push_back(*it);
2475         }
2476       else
2477         {
2478           int id=std::distance(locs.begin(),it2);
2479           if(!(*it)->isEqual(*_locs[id],eps))
2480             {
2481               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2482               throw INTERP_KERNEL::Exception(oss.str().c_str());
2483             }
2484         }
2485     }
2486 }
2487
2488 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2489 {
2490   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2491     getProfile((*it).c_str());
2492 }
2493
2494 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2495 {
2496   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2497     getLocalization((*it).c_str());
2498 }
2499
2500 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2501 {
2502   std::vector<std::string> profiles=real.getPflsReallyUsed();
2503   int sz=profiles.size();
2504   _pfls.resize(sz);
2505   for(int i=0;i<sz;i++)
2506     loadProfileInFile(fid,i,profiles[i].c_str());
2507   //
2508   std::vector<std::string> locs=real.getLocsReallyUsed();
2509   sz=locs.size();
2510   _locs.resize(sz);
2511   for(int i=0;i<sz;i++)
2512     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2513 }
2514
2515 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2516 {
2517   int nProfil=MEDnProfile(fid);
2518   for(int i=0;i<nProfil;i++)
2519     loadProfileInFile(fid,i);
2520   int sz=MEDnLocalization(fid);
2521   _locs.resize(sz);
2522   for(int i=0;i<sz;i++)
2523     {
2524       _locs[i]=MEDFileFieldLoc::New(fid,i);
2525     }
2526 }
2527
2528 MEDFileFieldGlobs *MEDFileFieldGlobs::New(const std::string& fname)
2529 {
2530   return new MEDFileFieldGlobs(fname);
2531 }
2532
2533 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2534 {
2535   return new MEDFileFieldGlobs;
2536 }
2537
2538 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2539 {
2540   return _file_name.capacity()+_pfls.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>)+_locs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>);
2541 }
2542
2543 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildren() const
2544 {
2545   std::vector<const BigMemoryObject *> ret;
2546   for(std::vector< MEDCouplingAutoRefCountObjectPtr< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2547     {
2548       const DataArrayInt *cur(*it);
2549       if(cur)
2550         ret.push_back(cur);
2551     }
2552   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2553     {
2554       const MEDFileFieldLoc *cur(*it);
2555       if(cur)
2556         ret.push_back(cur);
2557     }
2558   return ret;
2559 }
2560
2561 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpy() const
2562 {
2563   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2564   std::size_t i=0;
2565   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2566     {
2567       if((const DataArrayInt *)*it)
2568         ret->_pfls[i]=(*it)->deepCpy();
2569     }
2570   i=0;
2571   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2572     {
2573       if((const MEDFileFieldLoc*)*it)
2574         ret->_locs[i]=(*it)->deepCpy();
2575     }
2576   return ret.retn();
2577 }
2578
2579 /*!
2580  * \throw if a profile in \a pfls in not in \a this.
2581  * \throw if a localization in \a locs in not in \a this.
2582  * \sa MEDFileFieldGlobs::deepCpyPart
2583  */
2584 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2585 {
2586   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2587   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2588     {
2589       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2590       if(!pfl)
2591         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2592       pfl->incrRef();
2593       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pfl2(pfl);
2594       ret->_pfls.push_back(pfl2);
2595     }
2596   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2597     {
2598       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2599       if(!loc)
2600         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2601       loc->incrRef();
2602       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> loc2(loc);
2603       ret->_locs.push_back(loc2);
2604     }
2605   ret->setFileName(getFileName());
2606   return ret.retn();
2607 }
2608
2609 /*!
2610  * \throw if a profile in \a pfls in not in \a this.
2611  * \throw if a localization in \a locs in not in \a this.
2612  * \sa MEDFileFieldGlobs::shallowCpyPart
2613  */
2614 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2615 {
2616   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2617   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2618     {
2619       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2620       if(!pfl)
2621         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2622       ret->_pfls.push_back(pfl->deepCpy());
2623     }
2624   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2625     {
2626       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2627       if(!loc)
2628         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2629       ret->_locs.push_back(loc->deepCpy());
2630     }
2631   ret->setFileName(getFileName());
2632   return ret.retn();
2633 }
2634
2635 MEDFileFieldGlobs::MEDFileFieldGlobs(const std::string& fname):_file_name(fname)
2636 {
2637 }
2638
2639 MEDFileFieldGlobs::MEDFileFieldGlobs()
2640 {
2641 }
2642
2643 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2644 {
2645 }
2646
2647 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2648 {
2649   oss << "Profiles :\n";
2650   std::size_t n=_pfls.size();
2651   for(std::size_t i=0;i<n;i++)
2652     {
2653       oss << "  - #" << i << " ";
2654       const DataArrayInt *pfl=_pfls[i];
2655       if(pfl)
2656         oss << "\"" << pfl->getName() << "\"\n";
2657       else
2658         oss << "EMPTY !\n";
2659     }
2660   n=_locs.size();
2661   oss << "Localizations :\n";
2662   for(std::size_t i=0;i<n;i++)
2663     {
2664       oss << "  - #" << i << " ";
2665       const MEDFileFieldLoc *loc=_locs[i];
2666       if(loc)
2667         loc->simpleRepr(oss);
2668       else
2669         oss<< "EMPTY !\n";
2670     }
2671 }
2672
2673 void MEDFileFieldGlobs::setFileName(const std::string& fileName)
2674 {
2675   _file_name=fileName;
2676 }
2677
2678 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2679 {
2680   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
2681     {
2682       DataArrayInt *elt(*it);
2683       if(elt)
2684         {
2685           std::string name(elt->getName());
2686           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2687             {
2688               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2689                 {
2690                   elt->setName((*it2).second.c_str());
2691                   return;
2692                 }
2693             }
2694         }
2695     }
2696 }
2697
2698 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2699 {
2700   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
2701     {
2702       MEDFileFieldLoc *elt(*it);
2703       if(elt)
2704         {
2705           std::string name(elt->getName());
2706           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
2707             {
2708               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
2709                 {
2710                   elt->setName((*it2).second.c_str());
2711                   return;
2712                 }
2713             }
2714         }
2715     }
2716 }
2717
2718 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
2719 {
2720   if(locId<0 || locId>=(int)_locs.size())
2721     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
2722   return _locs[locId]->getNbOfGaussPtPerCell();
2723 }
2724
2725 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
2726 {
2727   return getLocalizationFromId(getLocalizationId(locName));
2728 }
2729
2730 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
2731 {
2732   if(locId<0 || locId>=(int)_locs.size())
2733     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2734   return *_locs[locId];
2735 }
2736
2737 namespace ParaMEDMEMImpl
2738 {
2739   class LocFinder
2740   {
2741   public:
2742     LocFinder(const std::string& loc):_loc(loc) { }
2743     bool operator() (const MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
2744   private:
2745     const std::string &_loc;
2746   };
2747
2748   class PflFinder
2749   {
2750   public:
2751     PflFinder(const std::string& pfl):_pfl(pfl) { }
2752     bool operator() (const MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
2753   private:
2754     const std::string& _pfl;
2755   };
2756 }
2757
2758 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
2759 {
2760   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),ParaMEDMEMImpl::LocFinder(loc));
2761   if(it==_locs.end())
2762     {
2763       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
2764       for(it=_locs.begin();it!=_locs.end();it++)
2765         oss << "\"" << (*it)->getName() << "\", ";
2766       throw INTERP_KERNEL::Exception(oss.str().c_str());
2767     }
2768   return std::distance(_locs.begin(),it);
2769 }
2770
2771 /*!
2772  * The returned value is never null.
2773  */
2774 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
2775 {
2776   std::string pflNameCpp(pflName);
2777   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2778   if(it==_pfls.end())
2779     {
2780       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2781       for(it=_pfls.begin();it!=_pfls.end();it++)
2782         oss << "\"" << (*it)->getName() << "\", ";
2783       throw INTERP_KERNEL::Exception(oss.str().c_str());
2784     }
2785   return *it;
2786 }
2787
2788 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
2789 {
2790   if(pflId<0 || pflId>=(int)_pfls.size())
2791     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2792   return _pfls[pflId];
2793 }
2794
2795 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
2796 {
2797   if(locId<0 || locId>=(int)_locs.size())
2798     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
2799   return *_locs[locId];
2800 }
2801
2802 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
2803 {
2804   return getLocalizationFromId(getLocalizationId(locName));
2805 }
2806
2807 /*!
2808  * The returned value is never null.
2809  */
2810 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
2811 {
2812   std::string pflNameCpp(pflName);
2813   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),ParaMEDMEMImpl::PflFinder(pflNameCpp));
2814   if(it==_pfls.end())
2815     {
2816       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
2817       for(it=_pfls.begin();it!=_pfls.end();it++)
2818         oss << "\"" << (*it)->getName() << "\", ";
2819       throw INTERP_KERNEL::Exception(oss.str().c_str());
2820     }
2821   return *it;
2822 }
2823
2824 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
2825 {
2826   if(pflId<0 || pflId>=(int)_pfls.size())
2827     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
2828   return _pfls[pflId];
2829 }
2830
2831 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
2832 {
2833   std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > newPfls;
2834   int i=0;
2835   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2836     {
2837       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
2838         newPfls.push_back(*it);
2839     }
2840   _pfls=newPfls;
2841 }
2842
2843 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
2844 {
2845   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > newLocs;
2846   int i=0;
2847   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2848     {
2849       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
2850         newLocs.push_back(*it);
2851     }
2852   _locs=newLocs;
2853 }
2854
2855 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
2856 {
2857   int sz=_pfls.size();
2858   std::vector<std::string> ret(sz);
2859   for(int i=0;i<sz;i++)
2860     ret[i]=_pfls[i]->getName();
2861   return ret;
2862 }
2863
2864 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
2865 {
2866   int sz=_locs.size();
2867   std::vector<std::string> ret(sz);
2868   for(int i=0;i<sz;i++)
2869     ret[i]=_locs[i]->getName();
2870   return ret;
2871 }
2872
2873 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
2874 {
2875   std::vector<std::string> v=getPfls();
2876   std::string s(pflName);
2877   return std::find(v.begin(),v.end(),s)!=v.end();
2878 }
2879
2880 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
2881 {
2882   std::vector<std::string> v=getLocs();
2883   std::string s(locName);
2884   return std::find(v.begin(),v.end(),s)!=v.end();
2885 }
2886
2887 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
2888 {
2889   std::map<int,std::vector<int> > m;
2890   int i=0;
2891   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2892     {
2893       const DataArrayInt *tmp=(*it);
2894       if(tmp)
2895         {
2896           m[tmp->getHashCode()].push_back(i);
2897         }
2898     }
2899   std::vector< std::vector<int> > ret;
2900   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
2901     {
2902       if((*it2).second.size()>1)
2903         {
2904           std::vector<int> ret0;
2905           bool equalityOrNot=false;
2906           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
2907             {
2908               std::vector<int>::const_iterator it4=it3; it4++;
2909               for(;it4!=(*it2).second.end();it4++)
2910                 {
2911                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
2912                     {
2913                       if(!equalityOrNot)
2914                         ret0.push_back(*it3);
2915                       ret0.push_back(*it4);
2916                       equalityOrNot=true;
2917                     }
2918                 }
2919             }
2920           if(!ret0.empty())
2921             ret.push_back(ret0);
2922         }
2923     }
2924   return ret;
2925 }
2926
2927 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
2928 {
2929   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
2930 }
2931
2932 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
2933 {
2934   std::string name(pfl->getName());
2935   if(name.empty())
2936     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
2937   for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2938     if(name==(*it)->getName())
2939       {
2940         if(!pfl->isEqual(*(*it)))
2941           {
2942             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
2943             throw INTERP_KERNEL::Exception(oss.str().c_str());
2944           }
2945       }
2946   pfl->incrRef();
2947   _pfls.push_back(pfl);
2948 }
2949
2950 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)
2951 {
2952   std::string name(locName);
2953   if(name.empty())
2954     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
2955   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
2956   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2957     if((*it)->isName(locName))
2958       {
2959         if(!(*it)->isEqual(*obj,1e-12))
2960           {
2961             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
2962             throw INTERP_KERNEL::Exception(oss.str().c_str());
2963           }
2964       }
2965   _locs.push_back(obj);
2966 }
2967
2968 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
2969 {
2970   std::vector<std::string> names=getPfls();
2971   return CreateNewNameNotIn("NewPfl_",names);
2972 }
2973
2974 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
2975 {
2976   std::vector<std::string> names=getLocs();
2977   return CreateNewNameNotIn("NewLoc_",names);
2978 }
2979
2980 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
2981 {
2982   for(std::size_t sz=0;sz<100000;sz++)
2983     {
2984       std::ostringstream tryName;
2985       tryName << prefix << sz;
2986       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
2987         return tryName.str();
2988     }
2989   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
2990 }
2991
2992 /*!
2993  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
2994  *  \param [in] fname - the file name.
2995  */
2996 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(const std::string& fname):_globals(MEDFileFieldGlobs::New(fname))
2997 {
2998 }
2999
3000 /*!
3001  * Creates an empty MEDFileFieldGlobsReal.
3002  */
3003 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3004 {
3005 }
3006
3007 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3008 {
3009   return 0;
3010 }
3011
3012 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildren() const
3013 {
3014   std::vector<const BigMemoryObject *> ret;
3015   if((const MEDFileFieldGlobs *)_globals)
3016     ret.push_back((const MEDFileFieldGlobs *)_globals);
3017   return ret;
3018 }
3019
3020 /*!
3021  * Returns a string describing profiles and Gauss points held in \a this.
3022  *  \return std::string - the description string.
3023  */
3024 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3025 {
3026   const MEDFileFieldGlobs *glob=_globals;
3027   std::ostringstream oss2; oss2 << glob;
3028   std::string stars(oss2.str().length(),'*');
3029   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3030   if(glob)
3031     glob->simpleRepr(oss);
3032   else
3033     oss << "NO GLOBAL INFORMATION !\n";
3034 }
3035
3036 void MEDFileFieldGlobsReal::resetContent()
3037 {
3038   _globals=MEDFileFieldGlobs::New();
3039 }
3040
3041 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3042 {
3043 }
3044
3045 /*!
3046  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3047  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3048  */
3049 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3050 {
3051   _globals=other._globals;
3052 }
3053
3054 /*!
3055  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3056  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3057  */
3058 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3059 {
3060   const MEDFileFieldGlobs *otherg(other._globals);
3061   if(!otherg)
3062     return ;
3063   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3064 }
3065
3066 /*!
3067  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3068  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3069  */
3070 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3071 {
3072   const MEDFileFieldGlobs *otherg(other._globals);
3073   if(!otherg)
3074     return ;
3075   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3076 }
3077
3078 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3079 {
3080   _globals=other._globals;
3081   if((const MEDFileFieldGlobs *)_globals)
3082     _globals=other._globals->deepCpy();
3083 }
3084
3085 /*!
3086  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3087  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3088  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3089  *         \a this and \a other MEDFileFieldGlobsReal.
3090  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3091  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3092  */
3093 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3094 {
3095   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3096   if(thisGlobals==otherGlobals)
3097     return ;
3098   if(!thisGlobals)
3099     {
3100       _globals=other._globals;
3101       return ;
3102     }
3103   _globals->appendGlobs(*other._globals,eps);
3104 }
3105
3106 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3107 {
3108   checkGlobsPflsPartCoherency();
3109   checkGlobsLocsPartCoherency();
3110 }
3111
3112 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3113 {
3114   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3115 }
3116
3117 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3118 {
3119   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3120 }
3121
3122 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3123 {
3124   contentNotNull()->loadProfileInFile(fid,id,pflName);
3125 }
3126
3127 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3128 {
3129   contentNotNull()->loadProfileInFile(fid,id);
3130 }
3131
3132 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3133 {
3134   contentNotNull()->loadGlobals(fid,*this);
3135 }
3136
3137 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3138 {
3139   contentNotNull()->loadAllGlobals(fid);
3140 }
3141
3142 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3143 {
3144   contentNotNull()->writeGlobals(fid,opt);
3145 }
3146
3147 /*!
3148  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3149  * or getPflsReallyUsedMulti().
3150  *  \return std::vector<std::string> - a sequence of names of all profiles.
3151  */
3152 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3153 {
3154   return contentNotNull()->getPfls();
3155 }
3156
3157 /*!
3158  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3159  * or getLocsReallyUsedMulti().
3160  *  \return std::vector<std::string> - a sequence of names of all localizations.
3161  */
3162 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3163 {
3164   return contentNotNull()->getLocs();
3165 }
3166
3167 /*!
3168  * Checks if the profile with a given name exists.
3169  *  \param [in] pflName - the profile name of interest.
3170  *  \return bool - \c true if the profile named \a pflName exists.
3171  */
3172 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3173 {
3174   return contentNotNull()->existsPfl(pflName);
3175 }
3176
3177 /*!
3178  * Checks if the localization with a given name exists.
3179  *  \param [in] locName - the localization name of interest.
3180  *  \return bool - \c true if the localization named \a locName exists.
3181  */
3182 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3183 {
3184   return contentNotNull()->existsLoc(locName);
3185 }
3186
3187 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3188 {
3189   return contentNotNull()->createNewNameOfPfl();
3190 }
3191
3192 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3193 {
3194   return contentNotNull()->createNewNameOfLoc();
3195 }
3196
3197 /*!
3198  * Sets the name of a MED file.
3199  *  \param [inout] fileName - the file name.
3200  */
3201 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3202 {
3203   contentNotNull()->setFileName(fileName);
3204 }
3205
3206 /*!
3207  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3208  * in the same order.
3209  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3210  *          Each item of this sequence is a vector containing ids of equal profiles.
3211  */
3212 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3213 {
3214   return contentNotNull()->whichAreEqualProfiles();
3215 }
3216
3217 /*!
3218  * Finds equal localizations.
3219  *  \param [in] eps - a precision used to compare real values of the localizations.
3220  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3221  *          Each item of this sequence is a vector containing ids of equal localizations.
3222  */
3223 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3224 {
3225   return contentNotNull()->whichAreEqualLocs(eps);
3226 }
3227
3228 /*!
3229  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3230  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3231  *        this sequence is a pair whose 
3232  *        - the first item is a vector of profile names to replace by the second item,
3233  *        - the second item is a profile name to replace every profile name of the first item.
3234  */
3235 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3236 {
3237   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3238 }
3239
3240 /*!
3241  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3242  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3243  *        this sequence is a pair whose 
3244  *        - the first item is a vector of localization names to replace by the second item,
3245  *        - the second item is a localization name to replace every localization name of the first item.
3246  */
3247 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3248 {
3249   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3250 }
3251
3252 /*!
3253  * Replaces references to some profiles (a reference is a profile name) by references
3254  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3255  * them-selves accordingly. <br>
3256  * This method is a generalization of changePflName().
3257  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3258  *        this sequence is a pair whose 
3259  *        - the first item is a vector of profile names to replace by the second item,
3260  *        - the second item is a profile name to replace every profile of the first item.
3261  * \sa changePflsRefsNamesGen()
3262  * \sa changePflName()
3263  */
3264 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3265 {
3266   changePflsRefsNamesGen(mapOfModif);
3267   changePflsNamesInStruct(mapOfModif);
3268 }
3269
3270 /*!
3271  * Replaces references to some localizations (a reference is a localization name) by references
3272  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3273  * them-selves accordingly. <br>
3274  * This method is a generalization of changeLocName().
3275  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3276  *        this sequence is a pair whose 
3277  *        - the first item is a vector of localization names to replace by the second item,
3278  *        - the second item is a localization name to replace every localization of the first item.
3279  * \sa changeLocsRefsNamesGen()
3280  * \sa changeLocName()
3281  */
3282 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3283 {
3284   changeLocsRefsNamesGen(mapOfModif);
3285   changeLocsNamesInStruct(mapOfModif);
3286 }
3287
3288 /*!
3289  * Renames the profile having a given name and updates references to this profile.
3290  *  \param [in] oldName - the name of the profile to rename.
3291  *  \param [in] newName - a new name of the profile.
3292  * \sa changePflsNames().
3293  */
3294 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3295 {
3296   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3297   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3298   mapOfModif[0]=p;
3299   changePflsNames(mapOfModif);
3300 }
3301
3302 /*!
3303  * Renames the localization having a given name and updates references to this localization.
3304  *  \param [in] oldName - the name of the localization to rename.
3305  *  \param [in] newName - a new name of the localization.
3306  * \sa changeLocsNames().
3307  */
3308 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3309 {
3310   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3311   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3312   mapOfModif[0]=p;
3313   changeLocsNames(mapOfModif);
3314 }
3315
3316 /*!
3317  * Removes duplicated profiles. Returns a map used to update references to removed 
3318  * profiles via changePflsRefsNamesGen().
3319  * Equal profiles are found using whichAreEqualProfiles().
3320  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3321  *          a sequence describing the performed replacements of profiles. Each element of
3322  *          this sequence is a pair whose
3323  *          - the first item is a vector of profile names replaced by the second item,
3324  *          - the second item is a profile name replacing every profile of the first item.
3325  */
3326 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3327 {
3328   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3329   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3330   int i=0;
3331   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3332     {
3333       std::vector< std::string > tmp((*it).size());
3334       int j=0;
3335       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3336         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3337       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3338       ret[i]=p;
3339       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3340       killProfileIds(tmp2);
3341     }
3342   changePflsRefsNamesGen(ret);
3343   return ret;
3344 }
3345
3346 /*!
3347  * Removes duplicated localizations. Returns a map used to update references to removed 
3348  * localizations via changeLocsRefsNamesGen().
3349  * Equal localizations are found using whichAreEqualLocs().
3350  *  \param [in] eps - a precision used to compare real values of the localizations.
3351  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3352  *          a sequence describing the performed replacements of localizations. Each element of
3353  *          this sequence is a pair whose
3354  *          - the first item is a vector of localization names replaced by the second item,
3355  *          - the second item is a localization name replacing every localization of the first item.
3356  */
3357 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3358 {
3359   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3360   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3361   int i=0;
3362   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3363     {
3364       std::vector< std::string > tmp((*it).size());
3365       int j=0;
3366       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3367         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3368       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3369       ret[i]=p;
3370       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3371       killLocalizationIds(tmp2);
3372     }
3373   changeLocsRefsNamesGen(ret);
3374   return ret;
3375 }
3376
3377 /*!
3378  * Returns number of Gauss points per cell in a given localization.
3379  *  \param [in] locId - an id of the localization of interest.
3380  *  \return int - the number of the Gauss points per cell.
3381  */
3382 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3383 {
3384   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3385 }
3386
3387 /*!
3388  * Returns an id of a localization by its name.
3389  *  \param [in] loc - the localization name of interest.
3390  *  \return int - the id of the localization.
3391  *  \throw If there is no a localization named \a loc.
3392  */
3393 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3394 {
3395   return contentNotNull()->getLocalizationId(loc);
3396 }
3397
3398 /*!
3399  * Returns the name of the MED file.
3400  *  \return const std::string&  - the MED file name.
3401  */
3402 std::string MEDFileFieldGlobsReal::getFileName() const
3403 {
3404   return contentNotNull()->getFileName();
3405 }
3406
3407 /*!
3408  * Returns a localization object by its name.
3409  *  \param [in] locName - the name of the localization of interest.
3410  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3411  *  \throw If there is no a localization named \a locName.
3412  */
3413 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3414 {
3415   return contentNotNull()->getLocalization(locName);
3416 }
3417
3418 /*!
3419  * Returns a localization object by its id.
3420  *  \param [in] locId - the id of the localization of interest.
3421  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3422  *  \throw If there is no a localization with id \a locId.
3423  */
3424 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3425 {
3426   return contentNotNull()->getLocalizationFromId(locId);
3427 }
3428
3429 /*!
3430  * Returns a profile array by its name.
3431  *  \param [in] pflName - the name of the profile of interest.
3432  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3433  *  \throw If there is no a profile named \a pflName.
3434  */
3435 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3436 {
3437   return contentNotNull()->getProfile(pflName);
3438 }
3439
3440 /*!
3441  * Returns a profile array by its id.
3442  *  \param [in] pflId - the id of the profile of interest.
3443  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3444  *  \throw If there is no a profile with id \a pflId.
3445  */
3446 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3447 {
3448   return contentNotNull()->getProfileFromId(pflId);
3449 }
3450
3451 /*!
3452  * Returns a localization object, apt for modification, by its id.
3453  *  \param [in] locId - the id of the localization of interest.
3454  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3455  *          having the id \a locId.
3456  *  \throw If there is no a localization with id \a locId.
3457  */
3458 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3459 {
3460   return contentNotNull()->getLocalizationFromId(locId);
3461 }
3462
3463 /*!
3464  * Returns a localization object, apt for modification, by its name.
3465  *  \param [in] locName - the name of the localization of interest.
3466  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3467  *          having the name \a locName.
3468  *  \throw If there is no a localization named \a locName.
3469  */
3470 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3471 {
3472   return contentNotNull()->getLocalization(locName);
3473 }
3474
3475 /*!
3476  * Returns a profile array, apt for modification, by its name.
3477  *  \param [in] pflName - the name of the profile of interest.
3478  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3479  *  \throw If there is no a profile named \a pflName.
3480  */
3481 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3482 {
3483   return contentNotNull()->getProfile(pflName);
3484 }
3485
3486 /*!
3487  * Returns a profile array, apt for modification, by its id.
3488  *  \param [in] pflId - the id of the profile of interest.
3489  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3490  *  \throw If there is no a profile with id \a pflId.
3491  */
3492 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3493 {
3494   return contentNotNull()->getProfileFromId(pflId);
3495 }
3496
3497 /*!
3498  * Removes profiles given by their ids. No data is updated to track this removal.
3499  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3500  */
3501 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3502 {
3503   contentNotNull()->killProfileIds(pflIds);
3504 }
3505
3506 /*!
3507  * Removes localizations given by their ids. No data is updated to track this removal.
3508  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3509  */
3510 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3511 {
3512   contentNotNull()->killLocalizationIds(locIds);
3513 }
3514
3515 /*!
3516  * Stores a profile array.
3517  *  \param [in] pfl - the profile array to store.
3518  *  \throw If the name of \a pfl is empty.
3519  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3520  *         different ids.
3521  */
3522 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3523 {
3524   contentNotNull()->appendProfile(pfl);
3525 }
3526
3527 /*!
3528  * Adds a new localization of Gauss points.
3529  *  \param [in] locName - the name of the new localization.
3530  *  \param [in] geoType - a geometrical type of the reference cell.
3531  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3532  *         must be \c nbOfNodesPerCell * \c dimOfType.
3533  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3534  *         must be  _wg_.size() * \c dimOfType.
3535  *  \param [in] w - the weights of Gauss points.
3536  *  \throw If \a locName is empty.
3537  *  \throw If a localization with the name \a locName already exists but is
3538  *         different form the new one.
3539  */
3540 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)
3541 {
3542   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3543 }
3544
3545 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3546 {
3547   MEDFileFieldGlobs *g(_globals);
3548   if(!g)
3549     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3550   return g;
3551 }
3552
3553 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3554 {
3555   const MEDFileFieldGlobs *g(_globals);
3556   if(!g)
3557     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3558   return g;
3559 }
3560
3561 //= MEDFileFieldNameScope
3562
3563 MEDFileFieldNameScope::MEDFileFieldNameScope()
3564 {
3565 }
3566
3567 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3568 {
3569 }
3570
3571 /*!
3572  * Returns the name of \a this field.
3573  *  \return std::string - a string containing the field name.
3574  */
3575 std::string MEDFileFieldNameScope::getName() const
3576 {
3577   return _name;
3578 }
3579
3580 /*!
3581  * Sets name of \a this field
3582  *  \param [in] name - the new field name.
3583  */
3584 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3585 {
3586   _name=fieldName;
3587 }
3588
3589 std::string MEDFileFieldNameScope::getDtUnit() const
3590 {
3591   return _dt_unit;
3592 }
3593
3594 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3595 {
3596   _dt_unit=dtUnit;
3597 }
3598
3599 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3600 {
3601   _name=other._name;
3602   _dt_unit=other._dt_unit;
3603 }
3604
3605 //= MEDFileAnyTypeField1TSWithoutSDA
3606
3607 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3608 {
3609   _field_per_mesh.resize(other._field_per_mesh.size());
3610   std::size_t i=0;
3611   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3612     {
3613       if((const MEDFileFieldPerMesh *)*it)
3614         _field_per_mesh[i]=(*it)->deepCpy(this);
3615     }
3616 }
3617
3618 /*!
3619  * Prints a string describing \a this field into a stream. This string is outputted 
3620  * by \c print Python command.
3621  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3622  *  \param [in,out] oss - the out stream.
3623  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3624  *          info id printed, else, not.
3625  */
3626 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3627 {
3628   std::string startOfLine(bkOffset,' ');
3629   oss << startOfLine << "Field ";
3630   if(bkOffset==0)
3631     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3632   oss << "on one time Step ";
3633   if(f1tsId>=0)
3634     oss << "(" << f1tsId << ") ";
3635   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3636   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3637   const DataArray *arr=getUndergroundDataArray();
3638   if(arr)
3639     {
3640       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3641       if(f1tsId<0)
3642         {
3643           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3644           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3645             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3646         }
3647       if(arr->isAllocated())
3648         {
3649           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3650         }
3651       else
3652         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3653     }
3654   else
3655     {
3656       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
3657     }
3658   oss << startOfLine << "----------------------" << std::endl;
3659   if(!_field_per_mesh.empty())
3660     {
3661       int i=0;
3662       for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
3663         {
3664           const MEDFileFieldPerMesh *cur=(*it2);
3665           if(cur)
3666             cur->simpleRepr(bkOffset,oss,i);
3667           else
3668             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
3669         }
3670     }
3671   else
3672     {
3673       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
3674     }
3675   oss << startOfLine << "----------------------" << std::endl;
3676 }
3677
3678 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
3679 {
3680   const DataArray *arr(getUndergroundDataArray());
3681   if(!arr)
3682     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
3683   int nbOfCompo=arr->getNumberOfComponents();
3684   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
3685   for(int i=0;i<nbOfCompo;i++)
3686     {
3687       ret[i]=deepCpy();
3688       std::vector<int> v(1,i);
3689       MEDCouplingAutoRefCountObjectPtr<DataArray> arr2=arr->keepSelectedComponents(v);
3690       ret[i]->setArray(arr2);
3691     }
3692   return ret;
3693 }
3694
3695 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)
3696 {
3697 }
3698
3699 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
3700 {
3701 }
3702
3703 /*!
3704  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
3705  * empty. Returns -1 if this in on nodes.
3706  *  \return int - the dimension of \a this.
3707  */
3708 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
3709 {
3710   int ret=-2;
3711   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3712     (*it)->getDimension(ret);
3713   return ret;
3714 }
3715
3716 /*!
3717  * Returns the mesh name.
3718  *  \return std::string - a string holding the mesh name.
3719  *  \throw If \c _field_per_mesh.empty()
3720  */
3721 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
3722 {
3723   if(_field_per_mesh.empty())
3724     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
3725   return _field_per_mesh[0]->getMeshName();
3726 }
3727
3728 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
3729 {
3730   std::string oldName(getMeshName());
3731   std::vector< std::pair<std::string,std::string> > v(1);
3732   v[0].first=oldName; v[0].second=newMeshName;
3733   changeMeshNames(v);
3734 }
3735
3736 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
3737 {
3738   bool ret=false;
3739   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3740     {
3741       MEDFileFieldPerMesh *cur(*it);
3742       if(cur)
3743         ret=cur->changeMeshNames(modifTab) || ret;
3744     }
3745   return ret;
3746 }
3747
3748 /*!
3749  * Returns the number of iteration of the state of underlying mesh.
3750  *  \return int - the iteration number.
3751  *  \throw If \c _field_per_mesh.empty()
3752  */
3753 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
3754 {
3755   if(_field_per_mesh.empty())
3756     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
3757   return _field_per_mesh[0]->getMeshIteration();
3758 }
3759
3760 /*!
3761  * Returns the order number of iteration of the state of underlying mesh.
3762  *  \return int - the order number.
3763  *  \throw If \c _field_per_mesh.empty()
3764  */
3765 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
3766 {
3767   if(_field_per_mesh.empty())
3768     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
3769   return _field_per_mesh[0]->getMeshOrder();
3770 }
3771
3772 /*!
3773  * Checks if \a this field is tagged by a given iteration number and a given
3774  * iteration order number.
3775  *  \param [in] iteration - the iteration number of interest.
3776  *  \param [in] order - the iteration order number of interest.
3777  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
3778  *          \a this->getOrder() == \a order.
3779  */
3780 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
3781 {
3782   return iteration==_iteration && order==_order;
3783 }
3784
3785 /*!
3786  * Returns number of iteration and order number of iteration when
3787  * \a this field has been calculated.
3788  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
3789  *          order number.
3790  */
3791 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
3792 {
3793   std::pair<int,int> p;
3794   fillIteration(p);
3795   return p;
3796 }
3797
3798 /*!
3799  * Returns number of iteration and order number of iteration when
3800  * \a this field has been calculated.
3801  *  \param [in,out] p - a pair returning the iteration number and the iteration
3802  *          order number.
3803  */
3804 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
3805 {
3806   p.first=_iteration;
3807   p.second=_order;
3808 }
3809
3810 /*!
3811  * Returns all types of spatial discretization of \a this field.
3812  *  \param [in,out] types - a sequence of types of \a this field.
3813  */
3814 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
3815 {
3816   std::set<TypeOfField> types2;
3817   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3818     {
3819       (*it)->fillTypesOfFieldAvailable(types2);
3820     }
3821   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
3822   std::copy(types2.begin(),types2.end(),bi);
3823 }
3824
3825 /*!
3826  * Returns all types of spatial discretization of \a this field.
3827  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
3828  *          of \a this field.
3829  */
3830 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
3831 {
3832   std::vector<TypeOfField> ret;
3833   fillTypesOfFieldAvailable(ret);
3834   return ret;
3835 }
3836
3837 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
3838 {
3839   std::vector<std::string> ret;
3840   std::set<std::string> ret2;
3841   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3842     {
3843       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
3844       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3845         if(ret2.find(*it2)==ret2.end())
3846           {
3847             ret.push_back(*it2);
3848             ret2.insert(*it2);
3849           }
3850     }
3851   return ret;
3852 }
3853
3854 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
3855 {
3856   std::vector<std::string> ret;
3857   std::set<std::string> ret2;
3858   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3859     {
3860       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
3861       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
3862         if(ret2.find(*it2)==ret2.end())
3863           {
3864             ret.push_back(*it2);
3865             ret2.insert(*it2);
3866           }
3867     }
3868   return ret;
3869 }
3870
3871 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
3872 {
3873   std::vector<std::string> ret;
3874   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3875     {
3876       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
3877       ret.insert(ret.end(),tmp.begin(),tmp.end());
3878     }
3879   return ret;
3880 }
3881
3882 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
3883 {
3884   std::vector<std::string> ret;
3885   std::set<std::string> ret2;
3886   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3887     {
3888       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
3889       ret.insert(ret.end(),tmp.begin(),tmp.end());
3890     }
3891   return ret;
3892 }
3893
3894 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3895 {
3896   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3897     (*it)->changePflsRefsNamesGen(mapOfModif);
3898 }
3899
3900 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3901 {
3902   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
3903     (*it)->changeLocsRefsNamesGen(mapOfModif);
3904 }
3905
3906 /*!
3907  * Returns all attributes of parts of \a this field lying on a given mesh.
3908  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
3909  * item of every of returned sequences refers to the _i_-th part of \a this field.
3910  * Thus all sequences returned by this method are of the same length equal to number
3911  * of different types of supporting entities.<br>
3912  * A field part can include sub-parts with several different spatial discretizations,
3913  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
3914  * for example. Hence, some of the returned sequences contains nested sequences, and an item
3915  * of a nested sequence corresponds to a type of spatial discretization.<br>
3916  * This method allows for iteration over MEDFile DataStructure without any overhead.
3917  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3918  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3919  *          not checked if \a mname == \c NULL).
3920  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
3921  *          a field part is returned. 
3922  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
3923  *          This sequence is of the same length as \a types. 
3924  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
3925  *          discretization. A profile name can be empty.
3926  *          Length of this and of nested sequences is the same as that of \a typesF.
3927  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
3928  *          discretization. A localization name can be empty.
3929  *          Length of this and of nested sequences is the same as that of \a typesF.
3930  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
3931  *          of ids of tuples within the data array, per each type of spatial
3932  *          discretization within one mesh entity type. 
3933  *          Length of this and of nested sequences is the same as that of \a typesF.
3934  *  \throw If no field is lying on \a mname.
3935  */
3936 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
3937 {
3938   int meshId=0;
3939   if(!mname.empty())
3940     meshId=getMeshIdFromMeshName(mname);
3941   else
3942     if(_field_per_mesh.empty())
3943       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
3944   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3945 }
3946
3947 /*!
3948  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
3949  * maximal absolute dimension and values returned via the out parameter \a levs are 
3950  * dimensions relative to the maximal absolute dimension. <br>
3951  * This method is designed for MEDFileField1TS instances that have a discretization
3952  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS", 
3953  * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT", 
3954  * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
3955  * Only these 3 discretizations will be taken into account here. If \a this is
3956  * \ref ParaMEDMEM::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
3957  * This method is useful to make the link between the dimension of the underlying mesh
3958  * and the levels of \a this, because it is possible that the highest dimension of \a this
3959  * field is not equal to the dimension of the underlying mesh.
3960  * 
3961  * Let's consider the following case:
3962  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
3963  * TETRA4, HEXA8, TRI3 and SEG2.
3964  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
3965  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
3966  *
3967  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
3968  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
3969  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
3970  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
3971  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
3972  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
3973  * For example<br>
3974  * to retrieve the highest level of
3975  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
3976  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
3977  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
3978  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
3979  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
3980  *          for the case with only one underlying mesh. (Actually, the number of meshes is
3981  *          not checked if \a mname == \c NULL).
3982  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
3983  *          absolute one. They are in decreasing order. This sequence is cleared before
3984  *          filling it in.
3985  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
3986  *  \throw If no field is lying on \a mname.
3987  */
3988 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
3989 {
3990   levs.clear();
3991   int meshId=getMeshIdFromMeshName(mname);
3992   std::vector<INTERP_KERNEL::NormalizedCellType> types;
3993   std::vector< std::vector<TypeOfField> > typesF;
3994   std::vector< std::vector<std::string> > pfls, locs;
3995   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
3996   if(types.empty())
3997     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
3998   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
3999   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4000     return -1;
4001   st.erase(INTERP_KERNEL::NORM_ERROR);
4002   std::set<int> ret1;
4003   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4004     {
4005       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4006       ret1.insert((int)cm.getDimension());
4007     }
4008   int ret=*std::max_element(ret1.begin(),ret1.end());
4009   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4010   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4011   return ret;
4012 }
4013
4014 /*!
4015  * \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.
4016  * \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.
4017  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4018  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4019  */
4020 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4021 {
4022   int mid=getMeshIdFromMeshName(mName);
4023   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4024 }
4025
4026 /*!
4027  * \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.
4028  * \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.
4029  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4030  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4031  */
4032 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4033 {
4034   int mid=getMeshIdFromMeshName(mName);
4035   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4036 }
4037
4038 /*!
4039  * \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.
4040  */
4041 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4042 {
4043   if(_field_per_mesh.empty())
4044     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4045   if(mName.empty())
4046     return 0;
4047   std::string mName2(mName);
4048   int ret=0;
4049   std::vector<std::string> msg;
4050   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4051     if(mName2==(*it)->getMeshName())
4052       return ret;
4053     else
4054       msg.push_back((*it)->getMeshName());
4055   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4056   oss << "Possible meshes are : ";
4057   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4058     oss << "\"" << (*it2) << "\" ";
4059   throw INTERP_KERNEL::Exception(oss.str().c_str());
4060 }
4061
4062 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4063 {
4064   if(!mesh)
4065     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4066   std::string tmp(mesh->getName());
4067   if(tmp.empty())
4068     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4069   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4070   int i=0;
4071   for(;it!=_field_per_mesh.end();it++,i++)
4072     {
4073       if((*it)->getMeshName()==tmp)
4074         return i;
4075     }
4076   int sz=_field_per_mesh.size();
4077   _field_per_mesh.resize(sz+1);
4078   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4079   return sz;
4080 }
4081
4082 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4083                                                                    MEDFileFieldGlobsReal& glob)
4084 {
4085   bool ret=false;
4086   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4087     {
4088       MEDFileFieldPerMesh *fpm(*it);
4089       if(fpm)
4090         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4091     }
4092   return ret;
4093 }
4094
4095 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4096 {
4097   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4098   std::vector< std::vector<TypeOfField> > typesF;
4099   std::vector< std::vector<std::string> > pfls,locs;
4100   std::vector< std::vector<std::pair<int,int> > > bgEnd=getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs);
4101   std::set<TypeOfField> allEnt;
4102   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4103     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4104       allEnt.insert(*it2);
4105   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4106   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4107   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4108     {
4109       std::vector< std::pair<int,int> > its;
4110       ret[i]=shallowCpy();
4111       int newLgth=ret[i]->keepOnlySpatialDiscretization(*it3,its);
4112       ret[i]->updateData(newLgth,its);
4113     }
4114   return ret;
4115 }
4116
4117 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4118 {
4119   int globalCounter=0;
4120   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4121     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4122   return globalCounter;
4123 }
4124
4125 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4126 {
4127   if(_nb_of_tuples_to_be_allocated>=0)
4128     {
4129       _nb_of_tuples_to_be_allocated=newLgth;
4130       const DataArray *oldArr(getUndergroundDataArray());
4131       if(oldArr)
4132         {
4133           MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4134           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4135           setArray(newArr);
4136           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4137         }
4138       return ;
4139     }
4140   if(_nb_of_tuples_to_be_allocated==-1)
4141     return ;
4142   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4143     {
4144       const DataArray *oldArr(getUndergroundDataArray());
4145       if(!oldArr || !oldArr->isAllocated())
4146         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4147       MEDCouplingAutoRefCountObjectPtr<DataArray> newArr(createNewEmptyDataArrayInstance());
4148       newArr->alloc(newLgth,getNumberOfComponents());
4149       if(oldArr)
4150         newArr->copyStringInfoFrom(*oldArr);
4151       int pos=0;
4152       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4153         {
4154           if((*it).second<(*it).first)
4155             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4156           newArr->setContigPartOfSelectedValues2(pos,oldArr,(*it).first,(*it).second,1);
4157           pos+=(*it).second-(*it).first;
4158         }
4159       setArray(newArr);
4160       return ;
4161     }
4162   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4163 }
4164
4165 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4166 {
4167   if(_field_per_mesh.empty())
4168     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4169   if(_field_per_mesh.size()>1)
4170     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4171   _field_per_mesh[0]->copyOptionsFrom(opts);
4172   _field_per_mesh[0]->writeLL(fid,nasc);
4173 }
4174
4175 /*!
4176  * 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.
4177  * If false is returned the memory allocation is not required.
4178  */
4179 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4180 {
4181   if(_nb_of_tuples_to_be_allocated>=0)
4182     {
4183       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4184       _nb_of_tuples_to_be_allocated=-2;
4185       return true;
4186     }
4187   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4188     return false;
4189   if(_nb_of_tuples_to_be_allocated==-1)
4190     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4191   if(_nb_of_tuples_to_be_allocated<-3)
4192     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4193   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4194 }
4195
4196 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4197 {
4198   med_int numdt,numit;
4199   med_float dt;
4200   med_int nmesh;
4201   med_bool localMesh;
4202   med_int meshnumdt,meshnumit;
4203   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4204   MEDfieldComputingStepInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt);
4205   MEDfield23ComputingStepMeshInfo(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit);
4206   if(_iteration!=numdt || _order!=numit)
4207     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4208   _field_per_mesh.resize(nmesh);
4209   for(int i=0;i<nmesh;i++)
4210     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i+1,meshnumdt,meshnumit,nasc);//tony
4211   _nb_of_tuples_to_be_allocated=0;
4212   for(int i=0;i<nmesh;i++)
4213     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4214 }
4215
4216 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4217 {
4218   allocIfNecessaryTheArrayToReceiveDataFromFile();
4219   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4220     (*it)->loadBigArraysRecursively(fid,nasc);
4221 }
4222
4223 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4224 {
4225   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4226     for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4227       (*it)->loadBigArraysRecursively(fid,nasc);
4228 }
4229
4230 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4231 {
4232   loadOnlyStructureOfDataRecursively(fid,nasc);
4233   loadBigArraysRecursively(fid,nasc);
4234 }
4235
4236 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4237 {
4238   DataArray *thisArr(getUndergroundDataArray());
4239   if(thisArr && thisArr->isAllocated())
4240     {
4241       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4242       thisArr->desallocate();
4243     }
4244 }
4245
4246 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4247 {
4248   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh >);
4249 }
4250
4251 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildren() const
4252 {
4253   std::vector<const BigMemoryObject *> ret;
4254   if(getUndergroundDataArray())
4255     ret.push_back(getUndergroundDataArray());
4256   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4257     {
4258       const MEDFileFieldPerMesh *cur(*it);
4259       if(cur)
4260         ret.push_back(cur);
4261     }
4262   return ret;
4263 }
4264
4265 /*!
4266  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4267  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4268  * "Sort By Type"), if not, an exception is thrown. 
4269  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4270  *  \param [in] arr - the array of values.
4271  *  \param [in,out] glob - the global data where profiles and localization present in
4272  *          \a field, if any, are added.
4273  *  \throw If the name of \a field is empty.
4274  *  \throw If the data array of \a field is not set.
4275  *  \throw If \a this->_arr is already allocated but has different number of components
4276  *         than \a field.
4277  *  \throw If the underlying mesh of \a field has no name.
4278  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4279  */
4280 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4281 {
4282   const MEDCouplingMesh *mesh=field->getMesh();
4283   //
4284   TypeOfField type=field->getTypeOfField();
4285   std::vector<DataArrayInt *> dummy;
4286   int start=copyTinyInfoFrom(field,arr);
4287   int pos=addNewEntryIfNecessary(mesh);
4288   if(type!=ON_NODES)
4289     {
4290       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4291       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4292     }
4293   else
4294     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4295 }
4296
4297 /*!
4298  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4299  * of a given mesh are used as the support of the given field (a real support is not used). 
4300  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4301  * Order of underlying mesh entities of the given field specified by \a profile parameter
4302  * is not prescribed; this method permutes field values to have them sorted by element
4303  * type as required for writing to MED file. A new profile is added only if no equal
4304  * profile is missing. 
4305  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4306  *  \param [in] arrOfVals - the values of the field \a field used.
4307  *  \param [in] mesh - the supporting mesh of \a field.
4308  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4309  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4310  *  \param [in,out] glob - the global data where profiles and localization present in
4311  *          \a field, if any, are added.
4312  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4313  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4314  *  \throw If the data array of \a field is not set.
4315  *  \throw If \a this->_arr is already allocated but has different number of components
4316  *         than \a field.
4317  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4318  *  \sa setFieldNoProfileSBT()
4319  */
4320 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4321 {
4322   if(!field)
4323     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4324   if(!arrOfVals || !arrOfVals->isAllocated())
4325     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4326   TypeOfField type=field->getTypeOfField();
4327   std::vector<DataArrayInt *> idsInPflPerType;
4328   std::vector<DataArrayInt *> idsPerType;
4329   std::vector<int> code,code2;
4330   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4331   if(type!=ON_NODES)
4332     {
4333       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4334       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4335       std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4336       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4337       // start of check
4338       MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> field2=field->clone(false);
4339       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4340       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4341         {
4342           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4343           throw INTERP_KERNEL::Exception(oss.str().c_str());
4344         }
4345       // end of check
4346       int start=copyTinyInfoFrom(field,arrOfVals);
4347       code2=m->getDistributionOfTypes();
4348       //
4349       int pos=addNewEntryIfNecessary(m);
4350       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4351     }
4352   else
4353     {
4354       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4355         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4356       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4357       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4358       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4359       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4360         {
4361           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4362           throw INTERP_KERNEL::Exception(oss.str().c_str());
4363         }
4364       int start=copyTinyInfoFrom(field,arrOfVals);
4365       int pos=addNewEntryIfNecessary(m);
4366       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4367     }
4368 }
4369
4370 /*!
4371  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4372  */
4373 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4374 {
4375   if(_nb_of_tuples_to_be_allocated>=0)
4376     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 !");
4377   DataArray *arr(getOrCreateAndGetArray());
4378   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4379   _nb_of_tuples_to_be_allocated=-3;
4380 }
4381
4382 /*!
4383  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4384  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4385  * larger by the size of \a field. Returns an id of the first not filled
4386  * tuple of \a this->_arr.
4387  *  \param [in] field - the field to copy the info on components and the name from.
4388  *  \return int - the id of first not initialized tuple of \a this->_arr.
4389  *  \throw If the name of \a field is empty.
4390  *  \throw If the data array of \a field is not set.
4391  *  \throw If \a this->_arr is already allocated but has different number of components
4392  *         than \a field.
4393  */
4394 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4395 {
4396   if(!field)
4397     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4398   std::string name(field->getName());
4399   setName(name.c_str());
4400   setDtUnit(field->getTimeUnit());
4401   if(name.empty())
4402     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4403   if(!arr)
4404     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4405   if(!arr->isAllocated())
4406     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4407   _dt=field->getTime(_iteration,_order);
4408   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4409   if(!getOrCreateAndGetArray()->isAllocated())
4410     {
4411       allocNotFromFile(arr->getNumberOfTuples());
4412       return 0;
4413     }
4414   else
4415     {
4416       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4417       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4418       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4419       _nb_of_tuples_to_be_allocated=-3;
4420       return oldNbOfTuples;
4421     }
4422 }
4423
4424 /*!
4425  * Returns number of components in \a this field
4426  *  \return int - the number of components.
4427  */
4428 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4429 {
4430   return getOrCreateAndGetArray()->getNumberOfComponents();
4431 }
4432
4433 /*!
4434  * Change info on components in \a this.
4435  * \throw If size of \a infos is not equal to the number of components already in \a this.
4436  */
4437 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4438 {
4439   DataArray *arr=getOrCreateAndGetArray();
4440   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4441 }
4442
4443 /*!
4444  * Returns info on components of \a this field.
4445  *  \return const std::vector<std::string>& - a sequence of strings each being an
4446  *          information on _i_-th component.
4447  */
4448 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4449 {
4450   const DataArray *arr=getOrCreateAndGetArray();
4451   return arr->getInfoOnComponents();
4452 }
4453
4454 /*!
4455  * Returns a mutable info on components of \a this field.
4456  *  \return std::vector<std::string>& - a sequence of strings each being an
4457  *          information on _i_-th component.
4458  */
4459 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4460 {
4461   DataArray *arr=getOrCreateAndGetArray();
4462   return arr->getInfoOnComponents();
4463 }
4464
4465 /*!
4466  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4467  *  \param [in] type - a spatial discretization of the new field.
4468  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4469  *  \param [in] mName - a name of the supporting mesh.
4470  *  \param [in] renumPol - specifies how to permute values of the result field according to
4471  *          the optional numbers of cells and nodes, if any. The valid values are
4472  *          - 0 - do not permute.
4473  *          - 1 - permute cells.
4474  *          - 2 - permute nodes.
4475  *          - 3 - permute cells and nodes.
4476  *
4477  *  \param [in] glob - the global data storing profiles and localization.
4478  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4479  *          caller is to delete this field using decrRef() as it is no more needed. 
4480  *  \throw If the MED file is not readable.
4481  *  \throw If there is no mesh named \a mName in the MED file.
4482  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4483  *  \throw If no field of \a this is lying on the mesh \a mName.
4484  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4485  */
4486 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4487 {
4488   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4489   if(mName.empty())
4490     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4491   else
4492     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4493   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4494 }
4495
4496 /*!
4497  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4498  *  \param [in] type - a spatial discretization of the new field.
4499  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4500  *  \param [in] renumPol - specifies how to permute values of the result field according to
4501  *          the optional numbers of cells and nodes, if any. The valid values are
4502  *          - 0 - do not permute.
4503  *          - 1 - permute cells.
4504  *          - 2 - permute nodes.
4505  *          - 3 - permute cells and nodes.
4506  *
4507  *  \param [in] glob - the global data storing profiles and localization.
4508  *  \param [in] mesh - the supporting mesh.
4509  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4510  *          caller is to delete this field using decrRef() as it is no more needed. 
4511  *  \throw If the MED file is not readable.
4512  *  \throw If no field of \a this is lying on \a mesh.
4513  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4514  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4515  */
4516 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4517 {
4518   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax,false);
4519   const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax);
4520   const DataArrayInt *e=mesh->getNumberFieldAtLevel(1);
4521   if(meshDimRelToMax==1)
4522     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4523   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4524 }
4525
4526 /*!
4527  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4528  * given mesh. 
4529  *  \param [in] type - a spatial discretization of the new field.
4530  *  \param [in] mName - a name of the supporting mesh.
4531  *  \param [in] renumPol - specifies how to permute values of the result field according to
4532  *          the optional numbers of cells and nodes, if any. The valid values are
4533  *          - 0 - do not permute.
4534  *          - 1 - permute cells.
4535  *          - 2 - permute nodes.
4536  *          - 3 - permute cells and nodes.
4537  *
4538  *  \param [in] glob - the global data storing profiles and localization.
4539  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4540  *          caller is to delete this field using decrRef() as it is no more needed. 
4541  *  \throw If the MED file is not readable.
4542  *  \throw If there is no mesh named \a mName in the MED file.
4543  *  \throw If there are no mesh entities in the mesh.
4544  *  \throw If no field values of the given \a type are available.
4545  */
4546 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MEDCouplingAutoRefCountObjectPtr<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4547 {
4548   MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
4549   if(mName.empty())
4550     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4551   else
4552     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4553   int absDim=getDimension();
4554   int meshDimRelToMax=absDim-mm->getMeshDimension();
4555   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4556 }
4557
4558 /*!
4559  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4560  *  \param [in] type - a spatial discretization of the new field.
4561  *  \param [in] renumPol - specifies how to permute values of the result field according to
4562  *          the optional numbers of cells and nodes, if any. The valid values are
4563  *          - 0 - do not permute.
4564  *          - 1 - permute cells.
4565  *          - 2 - permute nodes.
4566  *          - 3 - permute cells and nodes.
4567  *
4568  *  \param [in] glob - the global data storing profiles and localization.
4569  *  \param [in] mesh - the supporting mesh.
4570  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
4571  *         field according to \a renumPol.
4572  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
4573  *         field according to \a renumPol.
4574  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4575  *          caller is to delete this field using decrRef() as it is no more needed. 
4576  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4577  *  \throw If no field of \a this is lying on \a mesh.
4578  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4579  */
4580 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
4581 {
4582   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
4583   int meshId=getMeshIdFromMeshName(mesh->getName());
4584   bool isPfl=false;
4585   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
4586   switch(renumPol)
4587   {
4588     case 0:
4589       {
4590         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4591         return ret.retn();
4592       }
4593     case 3:
4594     case 1:
4595       {
4596         if(isPfl)
4597           throw INTERP_KERNEL::Exception(msg1);
4598         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4599         if(cellRenum)
4600           {
4601             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
4602               {
4603                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4604                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
4605                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4606               }
4607             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
4608             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
4609             std::vector<DataArray *> arrOut2(1,arrOut);
4610             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
4611             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
4612             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
4613           }
4614         if(renumPol==1)
4615           return ret.retn();
4616       }
4617     case 2:
4618       {
4619         //no need to test _field_per_mesh.empty() because geMeshName has already done it
4620         if(isPfl)
4621           throw INTERP_KERNEL::Exception(msg1);
4622         if(nodeRenum)
4623           {
4624             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
4625               {
4626                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
4627                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
4628                 throw INTERP_KERNEL::Exception(oss.str().c_str());
4629               }
4630             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
4631             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
4632               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
4633             ret->renumberNodes(nodeRenumSafe->getConstPointer());
4634           }
4635         return ret.retn();
4636       }
4637     default:
4638       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
4639   }
4640 }
4641
4642 /*!
4643  * Returns values and a profile of the field of a given type lying on a given support.
4644  *  \param [in] type - a spatial discretization of the field.
4645  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4646  *  \param [in] mesh - the supporting mesh.
4647  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
4648  *          field of interest lies on. If the field lies on all entities of the given
4649  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
4650  *          using decrRef() as it is no more needed.  
4651  *  \param [in] glob - the global data storing profiles and localization.
4652  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
4653  *          field. The caller is to delete this array using decrRef() as it is no more needed.
4654  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4655  *  \throw If no field of \a this is lying on \a mesh.
4656  *  \throw If no field values of the given \a type are available.
4657  */
4658 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
4659 {
4660   MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mesh->getGenMeshAtLevel(meshDimRelToMax);
4661   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
4662   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
4663   ret->setName(nasc.getName().c_str());
4664   return ret.retn();
4665 }
4666
4667 //= MEDFileField1TSWithoutSDA
4668
4669 /*!
4670  * Throws if a given value is not a valid (non-extended) relative dimension.
4671  *  \param [in] meshDimRelToMax - the relative dimension value.
4672  *  \throw If \a meshDimRelToMax > 0.
4673  */
4674 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
4675 {
4676   if(meshDimRelToMax>0)
4677     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
4678 }
4679
4680 /*!
4681  * Checks if elements of a given mesh are in the order suitable for writing 
4682  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
4683  * vector describing types of elements and their number.
4684  *  \param [in] mesh - the mesh to check.
4685  *  \return std::vector<int> - a vector holding for each element type (1) item of
4686  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
4687  *          These values are in full-interlace mode.
4688  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4689  */
4690 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
4691 {
4692   if(!mesh)
4693     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
4694   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
4695   int nbOfTypes=geoTypes.size();
4696   std::vector<int> code(3*nbOfTypes);
4697   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1=DataArrayInt::New();
4698   arr1->alloc(nbOfTypes,1);
4699   int *arrPtr=arr1->getPointer();
4700   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
4701   for(int i=0;i<nbOfTypes;i++,it++)
4702     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
4703   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
4704   const int *arrPtr2=arr2->getConstPointer();
4705   int i=0;
4706   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
4707     {
4708       int pos=arrPtr2[i];
4709       int nbCells=mesh->getNumberOfCellsWithType(*it);
4710       code[3*pos]=(int)(*it);
4711       code[3*pos+1]=nbCells;
4712       code[3*pos+2]=-1;//no profiles
4713     }
4714   std::vector<const DataArrayInt *> idsPerType;//no profiles
4715   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
4716   if(da)
4717     {
4718       da->decrRef();
4719       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
4720     }
4721   return code;
4722 }
4723
4724 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
4725 {
4726   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4727 }
4728
4729 /*!
4730  * Returns all attributes and values of parts of \a this field lying on a given mesh.
4731  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4732  * item of every of returned sequences refers to the _i_-th part of \a this field.
4733  * Thus all sequences returned by this method are of the same length equal to number
4734  * of different types of supporting entities.<br>
4735  * A field part can include sub-parts with several different spatial discretizations,
4736  * \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"
4737  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4738  * of a nested sequence corresponds to a type of spatial discretization.<br>
4739  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
4740  * The overhead is due to selecting values into new instances of DataArrayDouble.
4741  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4742  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4743  *          not checked if \a mname == \c NULL).
4744  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4745  *          a field part is returned. 
4746  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4747  *          A field part can include sub-parts with several different spatial discretizations,
4748  *          \ref ParaMEDMEM::ON_CELLS "ON_CELLS" and 
4749  *          \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" for example.
4750  *          This sequence is of the same length as \a types. 
4751  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4752  *          discretization. A profile name can be empty.
4753  *          Length of this and of nested sequences is the same as that of \a typesF.
4754  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4755  *          discretization. A localization name can be empty.
4756  *          Length of this and of nested sequences is the same as that of \a typesF.
4757  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
4758  *          per each type of spatial discretization within one mesh entity type.
4759  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
4760  *          Length of this and of nested sequences is the same as that of \a typesF.
4761  *  \throw If no field is lying on \a mname.
4762  */
4763 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
4764 {
4765   int meshId=0;
4766   if(!mname.empty())
4767     meshId=getMeshIdFromMeshName(mname);
4768   else
4769     if(_field_per_mesh.empty())
4770       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4771   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4772   int nbOfRet=ret0.size();
4773   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
4774   for(int i=0;i<nbOfRet;i++)
4775     {
4776       const std::vector< std::pair<int,int> >& p=ret0[i];
4777       int nbOfRet1=p.size();
4778       ret[i].resize(nbOfRet1);
4779       for(int j=0;j<nbOfRet1;j++)
4780         {
4781           DataArrayDouble *tmp=_arr->selectByTupleId2(p[j].first,p[j].second,1);
4782           ret[i][j]=tmp;
4783         }
4784     }
4785   return ret;
4786 }
4787
4788 /*!
4789  * Returns a pointer to the underground DataArrayDouble instance. So the
4790  * caller should not decrRef() it. This method allows for a direct access to the field
4791  * values. This method is quite unusable if there is more than a nodal field or a cell
4792  * field on single geometric cell type. 
4793  *  \return DataArrayDouble * - the pointer to the field values array.
4794  */
4795 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDouble() const
4796 {
4797   const DataArrayDouble *ret=_arr;
4798   if(ret)
4799     return const_cast<DataArrayDouble *>(ret);
4800   else
4801     return 0;
4802 }
4803
4804 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
4805 {
4806   return TYPE_STR;
4807 }
4808
4809 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
4810 {
4811   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
4812   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4813   ret->deepCpyLeavesFrom(*this);
4814   const DataArrayDouble *arr(_arr);
4815   if(arr)
4816     {
4817       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr->convertToIntArr());
4818       ret->setArray(arr2);
4819     }
4820   return ret.retn();
4821 }
4822
4823 /*!
4824  * Returns a pointer to the underground DataArrayDouble instance. So the
4825  * caller should not decrRef() it. This method allows for a direct access to the field
4826  * values. This method is quite unusable if there is more than a nodal field or a cell
4827  * field on single geometric cell type. 
4828  *  \return DataArrayDouble * - the pointer to the field values array.
4829  */
4830 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArray() const
4831 {
4832   return getUndergroundDataArrayDouble();
4833 }
4834
4835 /*!
4836  * Returns a pointer to the underground DataArrayDouble instance and a
4837  * sequence describing parameters of a support of each part of \a this field. The
4838  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4839  * direct access to the field values. This method is intended for the field lying on one
4840  * mesh only.
4841  *  \param [in,out] entries - the sequence describing parameters of a support of each
4842  *         part of \a this field. Each item of this sequence consists of two parts. The
4843  *         first part describes a type of mesh entity and an id of discretization of a
4844  *         current field part. The second part describes a range of values [begin,end)
4845  *         within the returned array relating to the current field part.
4846  *  \return DataArrayDouble * - the pointer to the field values array.
4847  *  \throw If the number of underlying meshes is not equal to 1.
4848  *  \throw If no field values are available.
4849  *  \sa getUndergroundDataArray()
4850  */
4851 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4852 {
4853   if(_field_per_mesh.size()!=1)
4854     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
4855   if(_field_per_mesh[0]==0)
4856     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
4857   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
4858   return getUndergroundDataArrayDouble();
4859 }
4860
4861 /*!
4862  * Returns a pointer to the underground DataArrayDouble instance and a
4863  * sequence describing parameters of a support of each part of \a this field. The
4864  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
4865  * direct access to the field values. This method is intended for the field lying on one
4866  * mesh only.
4867  *  \param [in,out] entries - the sequence describing parameters of a support of each
4868  *         part of \a this field. Each item of this sequence consists of two parts. The
4869  *         first part describes a type of mesh entity and an id of discretization of a
4870  *         current field part. The second part describes a range of values [begin,end)
4871  *         within the returned array relating to the current field part.
4872  *  \return DataArrayDouble * - the pointer to the field values array.
4873  *  \throw If the number of underlying meshes is not equal to 1.
4874  *  \throw If no field values are available.
4875  *  \sa getUndergroundDataArray()
4876  */
4877 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
4878 {
4879   return getUndergroundDataArrayDoubleExt(entries);
4880 }
4881
4882 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
4883                                                      const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4884 {
4885   DataArrayDouble *arr=getOrCreateAndGetArrayDouble();
4886   arr->setInfoAndChangeNbOfCompo(infos);
4887 }
4888
4889 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4890 {
4891 }
4892
4893 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
4894 {
4895   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
4896   ret->deepCpyLeavesFrom(*this);
4897   return ret.retn();
4898 }
4899
4900 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const
4901 {
4902   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
4903   if((const DataArrayDouble *)_arr)
4904     ret->_arr=_arr->deepCpy();
4905   return ret.retn();
4906 }
4907
4908 void MEDFileField1TSWithoutSDA::setArray(DataArray *arr)
4909 {
4910   if(!arr)
4911     {
4912       _nb_of_tuples_to_be_allocated=-1;
4913       _arr=0;
4914       return ;
4915     }
4916   DataArrayDouble *arrC=dynamic_cast<DataArrayDouble *>(arr);
4917   if(!arrC)
4918     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayDouble !");
4919   else
4920     _nb_of_tuples_to_be_allocated=-3;
4921   arrC->incrRef();
4922   _arr=arrC;
4923 }
4924
4925 DataArray *MEDFileField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
4926 {
4927   return DataArrayDouble::New();
4928 }
4929
4930 DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble()
4931 {
4932   DataArrayDouble *ret=_arr;
4933   if(ret)
4934     return ret;
4935   _arr=DataArrayDouble::New();
4936   return _arr;
4937 }
4938
4939 DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray()
4940 {
4941   return getOrCreateAndGetArrayDouble();
4942 }
4943
4944 const DataArrayDouble *MEDFileField1TSWithoutSDA::getOrCreateAndGetArrayDouble() const
4945 {
4946   const DataArrayDouble *ret=_arr;
4947   if(ret)
4948     return ret;
4949   DataArrayDouble *ret2=DataArrayDouble::New();
4950   const_cast<MEDFileField1TSWithoutSDA *>(this)->_arr=DataArrayDouble::New();
4951   return ret2;
4952 }
4953
4954 const DataArray *MEDFileField1TSWithoutSDA::getOrCreateAndGetArray() const
4955 {
4956   return getOrCreateAndGetArrayDouble();
4957 }
4958
4959 //= MEDFileIntField1TSWithoutSDA
4960
4961 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order,
4962                                                                 const std::vector<std::string>& infos)
4963 {
4964   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
4965 }
4966
4967 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileAnyTypeField1TSWithoutSDA()
4968 {
4969 }
4970
4971 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
4972                                                            const std::vector<std::string>& infos):MEDFileAnyTypeField1TSWithoutSDA(fieldName,csit,iteration,order)
4973 {
4974   DataArrayInt *arr=getOrCreateAndGetArrayInt();
4975   arr->setInfoAndChangeNbOfCompo(infos);
4976 }
4977
4978 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
4979 {
4980   return TYPE_STR;
4981 }
4982
4983 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
4984 {
4985   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
4986   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
4987   ret->deepCpyLeavesFrom(*this);
4988   const DataArrayInt *arr(_arr);
4989   if(arr)
4990     {
4991       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(arr->convertToDblArr());
4992       ret->setArray(arr2);
4993     }
4994   return ret.retn();
4995 }
4996
4997 /*!
4998  * Returns a pointer to the underground DataArrayInt instance. So the
4999  * caller should not decrRef() it. This method allows for a direct access to the field
5000  * values. This method is quite unusable if there is more than a nodal field or a cell
5001  * field on single geometric cell type. 
5002  *  \return DataArrayInt * - the pointer to the field values array.
5003  */
5004 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArray() const
5005 {
5006   return getUndergroundDataArrayInt();
5007 }
5008
5009 /*!
5010  * Returns a pointer to the underground DataArrayInt instance. So the
5011  * caller should not decrRef() it. This method allows for a direct access to the field
5012  * values. This method is quite unusable if there is more than a nodal field or a cell
5013  * field on single geometric cell type. 
5014  *  \return DataArrayInt * - the pointer to the field values array.
5015  */
5016 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayInt() const
5017 {
5018   const DataArrayInt *ret=_arr;
5019   if(ret)
5020     return const_cast<DataArrayInt *>(ret);
5021   else
5022     return 0;
5023 }
5024
5025 /*!
5026  * Returns a pointer to the underground DataArrayInt instance and a
5027  * sequence describing parameters of a support of each part of \a this field. The
5028  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5029  * direct access to the field values. This method is intended for the field lying on one
5030  * mesh only.
5031  *  \param [in,out] entries - the sequence describing parameters of a support of each
5032  *         part of \a this field. Each item of this sequence consists of two parts. The
5033  *         first part describes a type of mesh entity and an id of discretization of a
5034  *         current field part. The second part describes a range of values [begin,end)
5035  *         within the returned array relating to the current field part.
5036  *  \return DataArrayInt * - the pointer to the field values array.
5037  *  \throw If the number of underlying meshes is not equal to 1.
5038  *  \throw If no field values are available.
5039  *  \sa getUndergroundDataArray()
5040  */
5041 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5042 {
5043   return getUndergroundDataArrayIntExt(entries);
5044 }
5045
5046 /*!
5047  * Returns a pointer to the underground DataArrayInt instance and a
5048  * sequence describing parameters of a support of each part of \a this field. The
5049  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5050  * direct access to the field values. This method is intended for the field lying on one
5051  * mesh only.
5052  *  \param [in,out] entries - the sequence describing parameters of a support of each
5053  *         part of \a this field. Each item of this sequence consists of two parts. The
5054  *         first part describes a type of mesh entity and an id of discretization of a
5055  *         current field part. The second part describes a range of values [begin,end)
5056  *         within the returned array relating to the current field part.
5057  *  \return DataArrayInt * - the pointer to the field values array.
5058  *  \throw If the number of underlying meshes is not equal to 1.
5059  *  \throw If no field values are available.
5060  *  \sa getUndergroundDataArray()
5061  */
5062 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5063 {
5064   if(_field_per_mesh.size()!=1)
5065     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5066   if(_field_per_mesh[0]==0)
5067     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5068   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5069   return getUndergroundDataArrayInt();
5070 }
5071
5072 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5073 {
5074   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5075   ret->deepCpyLeavesFrom(*this);
5076   return ret.retn();
5077 }
5078
5079 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const
5080 {
5081   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5082   if((const DataArrayInt *)_arr)
5083     ret->_arr=_arr->deepCpy();
5084   return ret.retn();
5085 }
5086
5087 void MEDFileIntField1TSWithoutSDA::setArray(DataArray *arr)
5088 {
5089   if(!arr)
5090     {
5091       _nb_of_tuples_to_be_allocated=-1;
5092       _arr=0;
5093       return ;
5094     }
5095   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>(arr);
5096   if(!arrC)
5097     throw INTERP_KERNEL::Exception("MEDFileIntField1TSWithoutSDA::setArray : the input not null array is not of type DataArrayInt !");
5098   else
5099     _nb_of_tuples_to_be_allocated=-3;
5100   arrC->incrRef();
5101   _arr=arrC;
5102 }
5103
5104 DataArray *MEDFileIntField1TSWithoutSDA::createNewEmptyDataArrayInstance() const
5105 {
5106   return DataArrayInt::New();
5107 }
5108
5109 DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt()
5110 {
5111   DataArrayInt *ret=_arr;
5112   if(ret)
5113     return ret;
5114   _arr=DataArrayInt::New();
5115   return _arr;
5116 }
5117
5118 DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray()
5119 {
5120   return getOrCreateAndGetArrayInt();
5121 }
5122
5123 const DataArrayInt *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArrayInt() const
5124 {
5125   const DataArrayInt *ret=_arr;
5126   if(ret)
5127     return ret;
5128   DataArrayInt *ret2=DataArrayInt::New();
5129   const_cast<MEDFileIntField1TSWithoutSDA *>(this)->_arr=DataArrayInt::New();
5130   return ret2;
5131 }
5132
5133 const DataArray *MEDFileIntField1TSWithoutSDA::getOrCreateAndGetArray() const
5134 {
5135   return getOrCreateAndGetArrayInt();
5136 }
5137
5138 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5139 {
5140 }
5141
5142 //= MEDFileAnyTypeField1TS
5143
5144 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll)
5145 {
5146   med_field_type typcha;
5147   //
5148   std::vector<std::string> infos;
5149   std::string dtunit,fieldName;
5150   LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
5151   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5152   switch(typcha)
5153   {
5154     case MED_FLOAT64:
5155       {
5156         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5157         break;
5158       }
5159     case MED_INT32:
5160       {
5161         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5162         break;
5163       }
5164     default:
5165       {
5166         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] !";
5167         throw INTERP_KERNEL::Exception(oss.str().c_str());
5168       }
5169   }
5170   ret->setDtUnit(dtunit.c_str());
5171   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5172   //
5173   med_int numdt,numit;
5174   med_float dt;
5175   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5176   ret->setTime(numdt,numit,dt);
5177   ret->_csit=1;
5178   if(loadAll)
5179     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5180   else
5181     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5182   return ret.retn();
5183 }
5184
5185 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, bool loadAll)
5186 try:MEDFileFieldGlobsReal(fileName)
5187 {
5188   MEDFileUtilities::CheckFileForRead(fileName);
5189   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5190   _content=BuildContentFrom(fid,fileName,loadAll);
5191   loadGlobals(fid);
5192 }
5193 catch(INTERP_KERNEL::Exception& e)
5194 {
5195     throw e;
5196 }
5197
5198 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll)
5199 {
5200   med_field_type typcha;
5201   std::vector<std::string> infos;
5202   std::string dtunit;
5203   int iii=-1;
5204   int nbSteps=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5205   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5206   switch(typcha)
5207   {
5208     case MED_FLOAT64:
5209       {
5210         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5211         break;
5212       }
5213     case MED_INT32:
5214       {
5215         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5216         break;
5217       }
5218     default:
5219       {
5220         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] !";
5221         throw INTERP_KERNEL::Exception(oss.str().c_str());
5222       }
5223   }
5224   ret->setDtUnit(dtunit.c_str());
5225   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5226   //
5227   if(nbSteps<1)
5228     {
5229       std::ostringstream oss; oss << "MEDFileField1TS(fileName,fieldName) : file \'" << fileName << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5230       throw INTERP_KERNEL::Exception(oss.str().c_str());
5231     }
5232   //
5233   med_int numdt,numit;
5234   med_float dt;
5235   MEDfieldComputingStepInfo(fid,fieldName.c_str(),1,&numdt,&numit,&dt);
5236   ret->setTime(numdt,numit,dt);
5237   ret->_csit=1;
5238   if(loadAll)
5239     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5240   else
5241     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5242   return ret.retn();
5243 }
5244
5245 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll)
5246 try:MEDFileFieldGlobsReal(fileName)
5247 {
5248   MEDFileUtilities::CheckFileForRead(fileName);
5249   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5250   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
5251   loadGlobals(fid);
5252 }
5253 catch(INTERP_KERNEL::Exception& e)
5254 {
5255     throw e;
5256 }
5257
5258 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, const std::string& fileName)
5259 {
5260   if(!c)
5261     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5262   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5263     {
5264       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New();
5265       ret->setFileName(fileName);
5266       ret->_content=c; c->incrRef();
5267       return ret.retn();
5268     }
5269   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5270     {
5271       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New();
5272       ret->setFileName(fileName);
5273       ret->_content=c; c->incrRef();
5274       return ret.retn();
5275     }
5276   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5277 }
5278
5279 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5280 {
5281   MEDFileUtilities::CheckFileForRead(fileName);
5282   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5283   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
5284   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5285   ret->loadGlobals(fid);
5286   return ret.retn();
5287 }
5288
5289 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5290 {
5291   MEDFileUtilities::CheckFileForRead(fileName);
5292   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5293   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
5294   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5295   ret->loadGlobals(fid);
5296   return ret.retn();
5297 }
5298
5299 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5300 {
5301   MEDFileUtilities::CheckFileForRead(fileName);
5302   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5303   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,iteration,order,loadAll);
5304   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=BuildNewInstanceFromContent(c,fileName);
5305   ret->loadGlobals(fid);
5306   return ret.retn();
5307 }
5308
5309 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5310 {
5311   med_field_type typcha;
5312   std::vector<std::string> infos;
5313   std::string dtunit;
5314   int iii=-1;
5315   int nbOfStep2=LocateField(fid,fileName,fieldName,iii,typcha,infos,dtunit);
5316   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ret;
5317   switch(typcha)
5318   {
5319     case MED_FLOAT64:
5320       {
5321         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5322         break;
5323       }
5324     case MED_INT32:
5325       {
5326         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5327         break;
5328       }
5329     default:
5330       {
5331         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] !";
5332         throw INTERP_KERNEL::Exception(oss.str().c_str());
5333       }
5334   }
5335   ret->setDtUnit(dtunit.c_str());
5336   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5337   //
5338   bool found=false;
5339   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5340   for(int i=0;i<nbOfStep2 && !found;i++)
5341     {
5342       med_int numdt,numit;
5343       med_float dt;
5344       MEDfieldComputingStepInfo(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt);
5345       if(numdt==iteration && numit==order)
5346         {
5347           found=true;
5348           ret->_csit=i+1;
5349         }
5350       else
5351         dtits[i]=std::pair<int,int>(numdt,numit);
5352     }
5353   if(!found)
5354     {
5355       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << fileName << "' ! Available iterations are : ";
5356       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5357         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5358       throw INTERP_KERNEL::Exception(oss.str().c_str());
5359     }
5360   if(loadAll)
5361     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5362   else
5363     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret));
5364   return ret.retn();
5365 }
5366
5367 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5368 try:MEDFileFieldGlobsReal(fileName)
5369 {
5370   MEDFileUtilities::CheckFileForRead(fileName);
5371   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5372   _content=BuildContentFrom(fid,fileName.c_str(),fieldName.c_str(),iteration,order,loadAll);
5373   loadGlobals(fid);
5374 }
5375 catch(INTERP_KERNEL::Exception& e)
5376 {
5377     throw e;
5378 }
5379
5380 /*!
5381  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5382  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5383  *
5384  * \warning this is a shallow copy constructor
5385  */
5386 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5387 {
5388   if(!shallowCopyOfContent)
5389     {
5390       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5391       otherPtr->incrRef();
5392       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5393     }
5394   else
5395     {
5396       _content=other.shallowCpy();
5397     }
5398 }
5399
5400 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)
5401 {
5402   if(checkFieldId)
5403     {
5404       int nbFields=MEDnField(fid);
5405       if(fieldIdCFormat>=nbFields)
5406         {
5407           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << fileName << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5408           throw INTERP_KERNEL::Exception(oss.str().c_str());
5409         }
5410     }
5411   int ncomp=MEDfieldnComponent(fid,fieldIdCFormat+1);
5412   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5413   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5414   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5415   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5416   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5417   med_bool localMesh;
5418   int nbOfStep;
5419   MEDfieldInfo(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
5420   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5421   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5422   infos.clear(); infos.resize(ncomp);
5423   for(int j=0;j<ncomp;j++)
5424     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5425   return nbOfStep;
5426 }
5427
5428 /*!
5429  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5430  * 
5431  * \param [out]
5432  * \return in case of success the number of time steps available for the field with name \a fieldName.
5433  */
5434 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)
5435 {
5436   int nbFields=MEDnField(fid);
5437   bool found=false;
5438   std::vector<std::string> fns(nbFields);
5439   int nbOfStep2=-1;
5440   for(int i=0;i<nbFields && !found;i++)
5441     {
5442       std::string tmp;
5443       nbOfStep2=LocateField2(fid,fileName,i,false,tmp,typcha,infos,dtunitOut);
5444       fns[i]=tmp;
5445       found=(tmp==fieldName);
5446       if(found)
5447         posCFormat=i;
5448     }
5449   if(!found)
5450     {
5451       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << fileName << "' ! Available fields are : ";
5452       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5453         oss << "\"" << *it << "\" ";
5454       throw INTERP_KERNEL::Exception(oss.str().c_str());
5455     }
5456   return nbOfStep2;
5457 }
5458
5459 /*!
5460  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5461  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5462  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5463  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5464  * to keep a valid instance.
5465  * 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.
5466  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5467  * 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.
5468  *
5469  * \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.
5470  * \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.
5471  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5472  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5473  * \param [in] newLocName is the new localization name.
5474  * \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.
5475  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5476  */
5477 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5478 {
5479   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5480   std::string oldPflName=disc->getProfile();
5481   std::vector<std::string> vv=getPflsReallyUsedMulti();
5482   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5483   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5484     {
5485       disc->setProfile(newPflName);
5486       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5487       pfl->setName(newPflName);
5488     }
5489   else
5490     {
5491       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5492       throw INTERP_KERNEL::Exception(oss.str().c_str());
5493     }
5494 }
5495
5496 /*!
5497  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5498  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5499  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5500  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5501  * to keep a valid instance.
5502  * 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.
5503  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5504  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5505  * 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.
5506  *
5507  * \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.
5508  * \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.
5509  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5510  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5511  * \param [in] newLocName is the new localization name.
5512  * \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.
5513  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5514  */
5515 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5516 {
5517   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5518   std::string oldLocName=disc->getLocalization();
5519   std::vector<std::string> vv=getLocsReallyUsedMulti();
5520   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5521   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5522     {
5523       disc->setLocalization(newLocName);
5524       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5525       loc.setName(newLocName);
5526     }
5527   else
5528     {
5529       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5530       throw INTERP_KERNEL::Exception(oss.str().c_str());
5531     }
5532 }
5533
5534 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5535 {
5536   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5537   if(!ret)
5538     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5539   return ret;
5540 }
5541
5542 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5543 {
5544   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5545   if(!ret)
5546     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5547   return ret;
5548 }
5549
5550 /*!
5551  * Writes \a this field into a MED file specified by its name.
5552  *  \param [in] fileName - the MED file name.
5553  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
5554  * - 2 - erase; an existing file is removed.
5555  * - 1 - append; same data should not be present in an existing file.
5556  * - 0 - overwrite; same data present in an existing file is overwritten.
5557  *  \throw If the field name is not set.
5558  *  \throw If no field data is set.
5559  *  \throw If \a mode == 1 and the same data is present in an existing file.
5560  */
5561 void MEDFileAnyTypeField1TS::write(const std::string& fileName, int mode) const
5562 {
5563   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
5564   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
5565   writeLL(fid);
5566 }
5567
5568 /*!
5569  * This method alloc the arrays and load potentially huge arrays contained in this field.
5570  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5571  * This method can be also called to refresh or reinit values from a file.
5572  * 
5573  * \throw If the fileName is not set or points to a non readable MED file.
5574  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5575  */
5576 void MEDFileAnyTypeField1TS::loadArrays()
5577 {
5578   if(getFileName().empty())
5579     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5580   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5581   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5582 }
5583
5584 /*!
5585  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5586  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5587  * this method does not throw if \a this does not come from file read.
5588  * 
5589  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5590  */
5591 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5592 {
5593   if(!getFileName().empty())
5594     {
5595       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
5596       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5597     }
5598 }
5599
5600 /*!
5601  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5602  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5603  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5604  * 
5605  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5606  */
5607 void MEDFileAnyTypeField1TS::unloadArrays()
5608 {
5609   contentNotNullBase()->unloadArrays();
5610 }
5611
5612 /*!
5613  * 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.
5614  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5615  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5616  * 
5617  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5618  */
5619 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5620 {
5621   if(!getFileName().empty())
5622     contentNotNullBase()->unloadArrays();
5623 }
5624
5625 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5626 {
5627   int nbComp=getNumberOfComponents();
5628   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5629   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
5630   for(int i=0;i<nbComp;i++)
5631     {
5632       std::string info=getInfo()[i];
5633       std::string c,u;
5634       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5635       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5636       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5637     }
5638   if(getName().empty())
5639     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5640   MEDfieldCr(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
5641   writeGlobals(fid,*this);
5642   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5643 }
5644
5645 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5646 {
5647   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5648 }
5649
5650 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildren() const
5651 {
5652   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildren());
5653   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5654     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5655   return ret;
5656 }
5657
5658 /*!
5659  * Returns a string describing \a this field. This string is outputted 
5660  * by \c print Python command.
5661  */
5662 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5663 {
5664   std::ostringstream oss;
5665   contentNotNullBase()->simpleRepr(0,oss,-1);
5666   simpleReprGlobs(oss);
5667   return oss.str();
5668 }
5669
5670 /*!
5671  * This method returns all profiles whose name is non empty used.
5672  * \b WARNING If profile is used several times it will be reported \b only \b once.
5673  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5674  */
5675 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5676 {
5677   return contentNotNullBase()->getPflsReallyUsed2();
5678 }
5679
5680 /*!
5681  * This method returns all localizations whose name is non empty used.
5682  * \b WARNING If localization is used several times it will be reported \b only \b once.
5683  */
5684 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5685 {
5686   return contentNotNullBase()->getLocsReallyUsed2();
5687 }
5688
5689 /*!
5690  * This method returns all profiles whose name is non empty used.
5691  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5692  */
5693 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5694 {
5695   return contentNotNullBase()->getPflsReallyUsedMulti2();
5696 }
5697
5698 /*!
5699  * This method returns all localizations whose name is non empty used.
5700  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5701  */
5702 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5703 {
5704   return contentNotNullBase()->getLocsReallyUsedMulti2();
5705 }
5706
5707 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5708 {
5709   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5710 }
5711
5712 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5713 {
5714   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5715 }
5716
5717 int MEDFileAnyTypeField1TS::getDimension() const
5718 {
5719   return contentNotNullBase()->getDimension();
5720 }
5721
5722 int MEDFileAnyTypeField1TS::getIteration() const
5723 {
5724   return contentNotNullBase()->getIteration();
5725 }
5726
5727 int MEDFileAnyTypeField1TS::getOrder() const
5728 {
5729   return contentNotNullBase()->getOrder();
5730 }
5731
5732 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
5733 {
5734   return contentNotNullBase()->getTime(iteration,order);
5735 }
5736
5737 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
5738 {
5739   contentNotNullBase()->setTime(iteration,order,val);
5740 }
5741
5742 std::string MEDFileAnyTypeField1TS::getName() const
5743 {
5744   return contentNotNullBase()->getName();
5745 }
5746
5747 void MEDFileAnyTypeField1TS::setName(const std::string& name)
5748 {
5749   contentNotNullBase()->setName(name);
5750 }
5751
5752 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
5753 {
5754   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
5755 }
5756
5757 std::string MEDFileAnyTypeField1TS::getDtUnit() const
5758 {
5759   return contentNotNullBase()->getDtUnit();
5760 }
5761
5762 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
5763 {
5764   contentNotNullBase()->setDtUnit(dtUnit);
5765 }
5766
5767 std::string MEDFileAnyTypeField1TS::getMeshName() const
5768 {
5769   return contentNotNullBase()->getMeshName();
5770 }
5771
5772 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
5773 {
5774   contentNotNullBase()->setMeshName(newMeshName);
5775 }
5776
5777 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
5778 {
5779   return contentNotNullBase()->changeMeshNames(modifTab);
5780 }
5781
5782 int MEDFileAnyTypeField1TS::getMeshIteration() const
5783 {
5784   return contentNotNullBase()->getMeshIteration();
5785 }
5786
5787 int MEDFileAnyTypeField1TS::getMeshOrder() const
5788 {
5789   return contentNotNullBase()->getMeshOrder();
5790 }
5791
5792 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
5793 {
5794   return contentNotNullBase()->getNumberOfComponents();
5795 }
5796
5797 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
5798 {
5799   return contentNotNullBase()->isDealingTS(iteration,order);
5800 }
5801
5802 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
5803 {
5804   return contentNotNullBase()->getDtIt();
5805 }
5806
5807 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
5808 {
5809   contentNotNullBase()->fillIteration(p);
5810 }
5811
5812 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
5813 {
5814   contentNotNullBase()->fillTypesOfFieldAvailable(types);
5815 }
5816
5817 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
5818 {
5819   contentNotNullBase()->setInfo(infos);
5820 }
5821
5822 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
5823 {
5824   return contentNotNullBase()->getInfo();
5825 }
5826 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
5827 {
5828   return contentNotNullBase()->getInfo();
5829 }
5830
5831 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
5832 {
5833   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5834 }
5835
5836 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
5837 {
5838   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5839 }
5840
5841 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
5842 {
5843   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
5844 }
5845
5846 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
5847 {
5848   return contentNotNullBase()->getTypesOfFieldAvailable();
5849 }
5850
5851 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,
5852                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
5853 {
5854   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
5855 }
5856
5857 /*!
5858  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
5859  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5860  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
5861  */
5862 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
5863 {
5864   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5865   if(!content)
5866     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
5867   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
5868   std::size_t sz(contentsSplit.size());
5869   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5870   for(std::size_t i=0;i<sz;i++)
5871     {
5872       ret[i]=shallowCpy();
5873       ret[i]->_content=contentsSplit[i];
5874     }
5875   return ret;
5876 }
5877
5878 /*!
5879  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
5880  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
5881  */
5882 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
5883 {
5884   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
5885   if(!content)
5886     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
5887   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitDiscretizations();
5888   std::size_t sz(contentsSplit.size());
5889   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret(sz);
5890   for(std::size_t i=0;i<sz;i++)
5891     {
5892       ret[i]=shallowCpy();
5893       ret[i]->_content=contentsSplit[i];
5894     }
5895   return ret;
5896 }
5897
5898 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCpy() const
5899 {
5900   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> ret=shallowCpy();
5901   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
5902     ret->_content=_content->deepCpy();
5903   ret->deepCpyGlobs(*this);
5904   return ret.retn();
5905 }
5906
5907 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5908 {
5909   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
5910 }
5911
5912 //= MEDFileField1TS
5913
5914 /*!
5915  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5916  * the first field that has been read from a specified MED file.
5917  *  \param [in] fileName - the name of the MED file to read.
5918  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5919  *          is to delete this field using decrRef() as it is no more needed.
5920  *  \throw If reading the file fails.
5921  */
5922 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
5923 {
5924   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,loadAll);
5925   ret->contentNotNull();
5926   return ret.retn();
5927 }
5928
5929 /*!
5930  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
5931  * a given field that has been read from a specified MED file.
5932  *  \param [in] fileName - the name of the MED file to read.
5933  *  \param [in] fieldName - the name of the field to read.
5934  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5935  *          is to delete this field using decrRef() as it is no more needed.
5936  *  \throw If reading the file fails.
5937  *  \throw If there is no field named \a fieldName in the file.
5938  */
5939 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5940 {
5941   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,loadAll);
5942   ret->contentNotNull();
5943   return ret.retn();
5944 }
5945
5946 /*!
5947  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
5948  * a given field that has been read from a specified MED file.
5949  *  \param [in] fileName - the name of the MED file to read.
5950  *  \param [in] fieldName - the name of the field to read.
5951  *  \param [in] iteration - the iteration number of a required time step.
5952  *  \param [in] order - the iteration order number of required time step.
5953  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
5954  *          is to delete this field using decrRef() as it is no more needed.
5955  *  \throw If reading the file fails.
5956  *  \throw If there is no field named \a fieldName in the file.
5957  *  \throw If the required time step is missing from the file.
5958  */
5959 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5960 {
5961   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(fileName,fieldName,iteration,order,loadAll);
5962   ret->contentNotNull();
5963   return ret.retn();
5964 }
5965
5966 /*!
5967  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5968  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5969  *
5970  * Returns a new instance of MEDFileField1TS holding either a shallow copy
5971  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
5972  * \warning this is a shallow copy constructor
5973  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
5974  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
5975  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5976  *          is to delete this field using decrRef() as it is no more needed.
5977  */
5978 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
5979 {
5980   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS(other,shallowCopyOfContent);
5981   ret->contentNotNull();
5982   return ret.retn();
5983 }
5984
5985 /*!
5986  * Returns a new empty instance of MEDFileField1TS.
5987  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
5988  *          is to delete this field using decrRef() as it is no more needed.
5989  */
5990 MEDFileField1TS *MEDFileField1TS::New()
5991 {
5992   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=new MEDFileField1TS;
5993   ret->contentNotNull();
5994   return ret.retn();
5995 }
5996
5997 /*!
5998  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
5999  * following the given input policy.
6000  *
6001  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6002  *                            By default (true) the globals are deeply copied.
6003  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6004  */
6005 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6006 {
6007   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret;
6008   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6009   if(content)
6010     {
6011       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6012       if(!contc)
6013         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6014       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6015       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName()));
6016     }
6017   else
6018     ret=MEDFileIntField1TS::New();
6019   if(isDeepCpyGlobs)
6020     ret->deepCpyGlobs(*this);
6021   else
6022     ret->shallowCpyGlobs(*this);
6023   return ret.retn();
6024 }
6025
6026 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6027 {
6028   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6029   if(!pt)
6030     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6031   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6032   if(!ret)
6033     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 !");
6034   return ret;
6035 }
6036
6037 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6038 {
6039   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6040   if(!pt)
6041     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6042   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6043   if(!ret)
6044     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 !");
6045   return ret;
6046 }
6047
6048 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6049 {
6050   if(!f)
6051     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6052   if(!((DataArray*)arr))
6053     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6054   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6055   if(!arrOutC)
6056     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6057   f->setArray(arrOutC);
6058 }
6059
6060 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6061 {
6062   if(!((DataArray*)arr))
6063     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6064   DataArrayDouble *arrOutC=dynamic_cast<DataArrayDouble *>((DataArray*)arr);
6065   if(!arrOutC)
6066     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6067   arrOutC->incrRef();
6068   return arrOutC;
6069 }
6070
6071 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, bool loadAll)
6072 try:MEDFileAnyTypeField1TS(fileName,loadAll)
6073 {
6074 }
6075 catch(INTERP_KERNEL::Exception& e)
6076 { throw e; }
6077
6078 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll)
6079 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
6080 {
6081 }
6082 catch(INTERP_KERNEL::Exception& e)
6083 { throw e; }
6084
6085 MEDFileField1TS::MEDFileField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6086 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
6087 {
6088 }
6089 catch(INTERP_KERNEL::Exception& e)
6090 { throw e; }
6091
6092 /*!
6093  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6094  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6095  *
6096  * \warning this is a shallow copy constructor
6097  */
6098 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6099 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6100 {
6101 }
6102 catch(INTERP_KERNEL::Exception& e)
6103 { throw e; }
6104
6105 MEDFileField1TS::MEDFileField1TS()
6106 {
6107   _content=new MEDFileField1TSWithoutSDA;
6108 }
6109
6110 /*!
6111  * Returns a new MEDCouplingFieldDouble of a given type lying on
6112  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6113  * has not been constructed via file reading, an exception is thrown.
6114  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6115  *  \param [in] type - a spatial discretization of interest.
6116  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6117  *  \param [in] renumPol - specifies how to permute values of the result field according to
6118  *          the optional numbers of cells and nodes, if any. The valid values are
6119  *          - 0 - do not permute.
6120  *          - 1 - permute cells.
6121  *          - 2 - permute nodes.
6122  *          - 3 - permute cells and nodes.
6123  *
6124  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6125  *          caller is to delete this field using decrRef() as it is no more needed. 
6126  *  \throw If \a this field has not been constructed via file reading.
6127  *  \throw If the MED file is not readable.
6128  *  \throw If there is no mesh in the MED file.
6129  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6130  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6131  *  \sa getFieldOnMeshAtLevel()
6132  */
6133 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6134 {
6135   if(getFileName().empty())
6136     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6137   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6138   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull());
6139   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6140   return ret.retn();
6141 }
6142
6143 /*!
6144  * Returns a new MEDCouplingFieldDouble of a given type lying on
6145  * the top level cells of the first mesh in MED file. If \a this field 
6146  * has not been constructed via file reading, an exception is thrown.
6147  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6148  *  \param [in] type - a spatial discretization of interest.
6149  *  \param [in] renumPol - specifies how to permute values of the result field according to
6150  *          the optional numbers of cells and nodes, if any. The valid values are
6151  *          - 0 - do not permute.
6152  *          - 1 - permute cells.
6153  *          - 2 - permute nodes.
6154  *          - 3 - permute cells and nodes.
6155  *
6156  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6157  *          caller is to delete this field using decrRef() as it is no more needed. 
6158  *  \throw If \a this field has not been constructed via file reading.
6159  *  \throw If the MED file is not readable.
6160  *  \throw If there is no mesh in the MED file.
6161  *  \throw If no field values of the given \a type.
6162  *  \throw If no field values lying on the top level support.
6163  *  \sa getFieldAtLevel()
6164  */
6165 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6166 {
6167   if(getFileName().empty())
6168     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6169   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6170   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull());
6171   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6172   return ret.retn();
6173 }
6174
6175 /*!
6176  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6177  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6178  *  \param [in] type - a spatial discretization of the new field.
6179  *  \param [in] mesh - the supporting mesh.
6180  *  \param [in] renumPol - specifies how to permute values of the result field according to
6181  *          the optional numbers of cells and nodes, if any. The valid values are
6182  *          - 0 - do not permute.
6183  *          - 1 - permute cells.
6184  *          - 2 - permute nodes.
6185  *          - 3 - permute cells and nodes.
6186  *
6187  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6188  *          caller is to delete this field using decrRef() as it is no more needed. 
6189  *  \throw If no field of \a this is lying on \a mesh.
6190  *  \throw If the mesh is empty.
6191  *  \throw If no field values of the given \a type are available.
6192  *  \sa getFieldAtLevel()
6193  *  \sa getFieldOnMeshAtLevel() 
6194  */
6195 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6196 {
6197   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6198   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull());
6199   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6200   return ret.retn();
6201 }
6202
6203 /*!
6204  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6205  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6206  *  \param [in] type - a spatial discretization of interest.
6207  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6208  *  \param [in] mesh - the supporting mesh.
6209  *  \param [in] renumPol - specifies how to permute values of the result field according to
6210  *          the optional numbers of cells and nodes, if any. The valid values are
6211  *          - 0 - do not permute.
6212  *          - 1 - permute cells.
6213  *          - 2 - permute nodes.
6214  *          - 3 - permute cells and nodes.
6215  *
6216  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6217  *          caller is to delete this field using decrRef() as it is no more needed. 
6218  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6219  *  \throw If no field of \a this is lying on \a mesh.
6220  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6221  *  \sa getFieldAtLevel()
6222  *  \sa getFieldOnMeshAtLevel() 
6223  */
6224 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6225 {
6226   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6227   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull());
6228   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6229   return ret.retn();
6230 }
6231
6232 /*!
6233  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6234  * This method is called "Old" because in MED3 norm a field has only one meshName
6235  * attached, so this method is for readers of MED2 files. If \a this field 
6236  * has not been constructed via file reading, an exception is thrown.
6237  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6238  *  \param [in] type - a spatial discretization of interest.
6239  *  \param [in] mName - a name of the supporting mesh.
6240  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6241  *  \param [in] renumPol - specifies how to permute values of the result field according to
6242  *          the optional numbers of cells and nodes, if any. The valid values are
6243  *          - 0 - do not permute.
6244  *          - 1 - permute cells.
6245  *          - 2 - permute nodes.
6246  *          - 3 - permute cells and nodes.
6247  *
6248  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6249  *          caller is to delete this field using decrRef() as it is no more needed. 
6250  *  \throw If the MED file is not readable.
6251  *  \throw If there is no mesh named \a mName in the MED file.
6252  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6253  *  \throw If \a this field has not been constructed via file reading.
6254  *  \throw If no field of \a this is lying on the mesh named \a mName.
6255  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6256  *  \sa getFieldAtLevel()
6257  */
6258 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6259 {
6260   if(getFileName().empty())
6261     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6262   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
6263   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
6264   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6265   return ret.retn();
6266 }
6267
6268 /*!
6269  * Returns values and a profile of the field of a given type lying on a given support.
6270  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6271  *  \param [in] type - a spatial discretization of the field.
6272  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6273  *  \param [in] mesh - the supporting mesh.
6274  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6275  *          field of interest lies on. If the field lies on all entities of the given
6276  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6277  *          using decrRef() as it is no more needed.  
6278  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6279  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6280  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6281  *  \throw If no field of \a this is lying on \a mesh.
6282  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6283  */
6284 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6285 {
6286   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6287   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6288 }
6289
6290 /*!
6291  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6292  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6293  * "Sort By Type"), if not, an exception is thrown. 
6294  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6295  *  \param [in] field - the field to add to \a this.
6296  *  \throw If the name of \a field is empty.
6297  *  \throw If the data array of \a field is not set.
6298  *  \throw If the data array is already allocated but has different number of components
6299  *         than \a field.
6300  *  \throw If the underlying mesh of \a field has no name.
6301  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6302  */
6303 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6304 {
6305   setFileName("");
6306   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6307 }
6308
6309 /*!
6310  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6311  * can be an aggregation of several MEDCouplingFieldDouble instances.
6312  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6313  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6314  * and \a profile.
6315  *
6316  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6317  * A new profile is added only if no equal profile is missing.
6318  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6319  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6320  *  \param [in] mesh - the supporting mesh of \a field.
6321  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6322  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6323  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6324  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6325  *  \throw If the data array of \a field is not set.
6326  *  \throw If the data array of \a this is already allocated but has different number of
6327  *         components than \a field.
6328  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6329  *  \sa setFieldNoProfileSBT()
6330  */
6331 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6332 {
6333   setFileName("");
6334   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6335 }
6336
6337 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6338 {
6339   return new MEDFileField1TS(*this);
6340 }
6341
6342 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6343 {
6344   return contentNotNull()->getUndergroundDataArrayDouble();
6345 }
6346
6347 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6348 {
6349   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6350 }
6351
6352 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6353                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6354 {
6355   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6356 }
6357
6358 //= MEDFileIntField1TS
6359
6360 MEDFileIntField1TS *MEDFileIntField1TS::New()
6361 {
6362   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS;
6363   ret->contentNotNull();
6364   return ret.retn();
6365 }
6366
6367 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6368 {
6369   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,loadAll);
6370   ret->contentNotNull();
6371   return ret.retn();
6372 }
6373
6374 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6375 {
6376   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,loadAll);
6377   ret->contentNotNull();
6378   return ret.retn();
6379 }
6380
6381 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6382 {
6383   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(fileName,fieldName,iteration,order,loadAll);
6384   ret->contentNotNull();
6385   return ret.retn();
6386 }
6387
6388 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6389 {
6390   MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6391   ret->contentNotNull();
6392   return ret.retn();
6393 }
6394
6395 MEDFileIntField1TS::MEDFileIntField1TS()
6396 {
6397   _content=new MEDFileIntField1TSWithoutSDA;
6398 }
6399
6400 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, bool loadAll)
6401 try:MEDFileAnyTypeField1TS(fileName,loadAll)
6402 {
6403 }
6404 catch(INTERP_KERNEL::Exception& e)
6405 { throw e; }
6406
6407 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, bool loadAll)
6408 try:MEDFileAnyTypeField1TS(fileName,fieldName,loadAll)
6409 {
6410 }
6411 catch(INTERP_KERNEL::Exception& e)
6412 { throw e; }
6413
6414 MEDFileIntField1TS::MEDFileIntField1TS(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6415 try:MEDFileAnyTypeField1TS(fileName,fieldName,iteration,order,loadAll)
6416 {
6417 }
6418 catch(INTERP_KERNEL::Exception& e)
6419 { throw e; }
6420
6421 /*!
6422  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6423  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6424  *
6425  * \warning this is a shallow copy constructor
6426  */
6427 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6428 {
6429 }
6430
6431 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6432 {
6433   return new MEDFileIntField1TS(*this);
6434 }
6435
6436 /*!
6437  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6438  * following the given input policy.
6439  *
6440  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6441  *                            By default (true) the globals are deeply copied.
6442  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6443  */
6444 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6445 {
6446   MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret;
6447   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6448   if(content)
6449     {
6450       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6451       if(!contc)
6452         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6453       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6454       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName()));
6455     }
6456   else
6457     ret=MEDFileField1TS::New();
6458   if(isDeepCpyGlobs)
6459     ret->deepCpyGlobs(*this);
6460   else
6461     ret->shallowCpyGlobs(*this);
6462   return ret.retn();
6463 }
6464
6465 /*!
6466  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6467  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6468  * "Sort By Type"), if not, an exception is thrown. 
6469  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6470  *  \param [in] field - the field to add to \a this. The field double values are ignored.
6471  *  \param [in] arrOfVals - the values of the field \a field used.
6472  *  \throw If the name of \a field is empty.
6473  *  \throw If the data array of \a field is not set.
6474  *  \throw If the data array is already allocated but has different number of components
6475  *         than \a field.
6476  *  \throw If the underlying mesh of \a field has no name.
6477  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6478  */
6479 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
6480 {
6481   setFileName("");
6482   contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull());
6483 }
6484
6485 /*!
6486  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6487  * can be an aggregation of several MEDCouplingFieldDouble instances.
6488  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6489  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6490  * and \a profile.
6491  *
6492  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6493  * A new profile is added only if no equal profile is missing.
6494  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6495  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
6496  *  \param [in] arrOfVals - the values of the field \a field used.
6497  *  \param [in] mesh - the supporting mesh of \a field.
6498  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6499  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6500  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6501  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6502  *  \throw If the data array of \a field is not set.
6503  *  \throw If the data array of \a this is already allocated but has different number of
6504  *         components than \a field.
6505  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6506  *  \sa setFieldNoProfileSBT()
6507  */
6508 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6509 {
6510   setFileName("");
6511   contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6512 }
6513
6514 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6515 {
6516   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6517   if(!pt)
6518     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6519   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6520   if(!ret)
6521     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 !");
6522   return ret;
6523 }
6524
6525 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6526 {
6527   if(getFileName().empty())
6528     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6529   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut2;
6530   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut2,*contentNotNull());
6531   DataArrayInt *arrOutC=dynamic_cast<DataArrayInt *>((DataArray *)arrOut2);
6532   if(!arrOutC)
6533     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : mismatch between dataArrays type and MEDFileIntField1TS ! Expected int32 !");
6534   arrOut=arrOutC;
6535   return ret.retn();
6536 }
6537
6538 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MEDCouplingAutoRefCountObjectPtr<DataArray>& arr)
6539 {
6540   if(!((DataArray *)arr))
6541     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6542   DataArrayInt *arrC=dynamic_cast<DataArrayInt *>((DataArray *)arr);
6543   if(!arrC)
6544     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6545   arrC->incrRef();
6546   return arrC;
6547 }
6548
6549 /*!
6550  * Returns a new MEDCouplingFieldDouble of a given type lying on
6551  * the top level cells of the first mesh in MED file. If \a this field 
6552  * has not been constructed via file reading, an exception is thrown.
6553  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6554  *  \param [in] type - a spatial discretization of interest.
6555  *  \param [out] arrOut - the DataArrayInt containing values of field.
6556  *  \param [in] renumPol - specifies how to permute values of the result field according to
6557  *          the optional numbers of cells and nodes, if any. The valid values are
6558  *          - 0 - do not permute.
6559  *          - 1 - permute cells.
6560  *          - 2 - permute nodes.
6561  *          - 3 - permute cells and nodes.
6562  *
6563  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6564  *          caller is to delete this field using decrRef() as it is no more needed. 
6565  *  \throw If \a this field has not been constructed via file reading.
6566  *  \throw If the MED file is not readable.
6567  *  \throw If there is no mesh in the MED file.
6568  *  \throw If no field values of the given \a type.
6569  *  \throw If no field values lying on the top level support.
6570  *  \sa getFieldAtLevel()
6571  */
6572 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol) const
6573 {
6574   if(getFileName().empty())
6575     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6576   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6577   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNull());
6578   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6579   return ret.retn();
6580 }
6581
6582 /*!
6583  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6584  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6585  *  \param [in] type - a spatial discretization of the new field.
6586  *  \param [in] mesh - the supporting mesh.
6587  *  \param [out] arrOut - the DataArrayInt containing values of field.
6588  *  \param [in] renumPol - specifies how to permute values of the result field according to
6589  *          the optional numbers of cells and nodes, if any. The valid values are
6590  *          - 0 - do not permute.
6591  *          - 1 - permute cells.
6592  *          - 2 - permute nodes.
6593  *          - 3 - permute cells and nodes.
6594  *
6595  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6596  *          caller is to delete this field using decrRef() as it is no more needed. 
6597  *  \throw If no field of \a this is lying on \a mesh.
6598  *  \throw If the mesh is empty.
6599  *  \throw If no field values of the given \a type are available.
6600  *  \sa getFieldAtLevel()
6601  *  \sa getFieldOnMeshAtLevel() 
6602  */
6603 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6604 {
6605   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6606   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNull());
6607   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6608   return ret.retn();
6609 }
6610
6611 /*!
6612  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6613  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6614  *  \param [in] type - a spatial discretization of interest.
6615  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6616  *  \param [out] arrOut - the DataArrayInt containing values of field.
6617  *  \param [in] mesh - the supporting mesh.
6618  *  \param [in] renumPol - specifies how to permute values of the result field according to
6619  *          the optional numbers of cells and nodes, if any. The valid values are
6620  *          - 0 - do not permute.
6621  *          - 1 - permute cells.
6622  *          - 2 - permute nodes.
6623  *          - 3 - permute cells and nodes.
6624  *
6625  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6626  *          caller is to delete this field using decrRef() as it is no more needed. 
6627  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6628  *  \throw If no field of \a this is lying on \a mesh.
6629  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6630  *  \sa getFieldAtLevel()
6631  *  \sa getFieldOnMeshAtLevel() 
6632  */
6633 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
6634 {
6635   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6636   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNull());
6637   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6638   return ret.retn();
6639 }
6640
6641 /*!
6642  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6643  * This method is called "Old" because in MED3 norm a field has only one meshName
6644  * attached, so this method is for readers of MED2 files. If \a this field 
6645  * has not been constructed via file reading, an exception is thrown.
6646  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6647  *  \param [in] type - a spatial discretization of interest.
6648  *  \param [in] mName - a name of the supporting mesh.
6649  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6650  *  \param [out] arrOut - the DataArrayInt containing values of field.
6651  *  \param [in] renumPol - specifies how to permute values of the result field according to
6652  *          the optional numbers of cells and nodes, if any. The valid values are
6653  *          - 0 - do not permute.
6654  *          - 1 - permute cells.
6655  *          - 2 - permute nodes.
6656  *          - 3 - permute cells and nodes.
6657  *
6658  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6659  *          caller is to delete this field using decrRef() as it is no more needed. 
6660  *  \throw If the MED file is not readable.
6661  *  \throw If there is no mesh named \a mName in the MED file.
6662  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6663  *  \throw If \a this field has not been constructed via file reading.
6664  *  \throw If no field of \a this is lying on the mesh named \a mName.
6665  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6666  *  \sa getFieldAtLevel()
6667  */
6668 MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
6669 {
6670   if(getFileName().empty())
6671     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6672   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
6673   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNull());
6674   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6675   return ret.retn();
6676 }
6677
6678 /*!
6679  * Returns values and a profile of the field of a given type lying on a given support.
6680  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6681  *  \param [in] type - a spatial discretization of the field.
6682  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6683  *  \param [in] mesh - the supporting mesh.
6684  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6685  *          field of interest lies on. If the field lies on all entities of the given
6686  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6687  *          using decrRef() as it is no more needed.  
6688  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
6689  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6690  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6691  *  \throw If no field of \a this is lying on \a mesh.
6692  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6693  */
6694 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6695 {
6696   MEDCouplingAutoRefCountObjectPtr<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6697   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
6698 }
6699
6700 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
6701 {
6702   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6703   if(!pt)
6704     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
6705   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
6706   if(!ret)
6707     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 !");
6708   return ret;
6709 }
6710
6711 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
6712 {
6713   return contentNotNull()->getUndergroundDataArrayInt();
6714 }
6715
6716 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
6717
6718 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
6719 {
6720 }
6721
6722 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
6723 {
6724 }
6725
6726 /*!
6727  * \param [in] fieldId field id in C mode
6728  */
6729 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll)
6730 {
6731   med_field_type typcha;
6732   std::string dtunitOut;
6733   int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,"",fieldId,false,_name,typcha,_infos,dtunitOut);
6734   setDtUnit(dtunitOut.c_str());
6735   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll);
6736 }
6737
6738 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)
6739 try:MEDFileFieldNameScope(fieldName),_infos(infos)
6740 {
6741   setDtUnit(dtunit.c_str());
6742   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll);
6743 }
6744 catch(INTERP_KERNEL::Exception& e)
6745 {
6746     throw e;
6747 }
6748
6749 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
6750 {
6751   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutSDA>));
6752   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6753     ret+=(*it).capacity();
6754   return ret;
6755 }
6756
6757 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildren() const
6758 {
6759   std::vector<const BigMemoryObject *> ret;
6760   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6761     {
6762       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6763       if(cur)
6764         ret.push_back(cur);
6765     }
6766   return ret;
6767 }
6768
6769 /*!
6770  * 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
6771  * NULL.
6772  */
6773 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
6774 {
6775   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6776   ret->setInfo(_infos);
6777   int sz=(int)_time_steps.size();
6778   for(const int *id=startIds;id!=endIds;id++)
6779     {
6780       if(*id>=0 && *id<sz)
6781         {
6782           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
6783           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6784           if(tse)
6785             {
6786               tse->incrRef();
6787               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6788             }
6789           ret->pushBackTimeStep(tse2);
6790         }
6791       else
6792         {
6793           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
6794           oss << " ! Should be in [0," << sz << ") !";
6795           throw INTERP_KERNEL::Exception(oss.str().c_str());
6796         }
6797     }
6798   if(ret->getNumberOfTS()>0)
6799     ret->synchronizeNameScope();
6800   ret->copyNameScope(*this);
6801   return ret.retn();
6802 }
6803
6804 /*!
6805  * 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
6806  * NULL.
6807  */
6808 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
6809 {
6810   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
6811   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
6812   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
6813   ret->setInfo(_infos);
6814   int sz=(int)_time_steps.size();
6815   int j=bg;
6816   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
6817     {
6818       if(j>=0 && j<sz)
6819         {
6820           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
6821           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> tse2;
6822           if(tse)
6823             {
6824               tse->incrRef();
6825               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
6826             }
6827           ret->pushBackTimeStep(tse2);
6828         }
6829       else
6830         {
6831           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
6832           oss << " ! Should be in [0," << sz << ") !";
6833           throw INTERP_KERNEL::Exception(oss.str().c_str());
6834         }
6835     }
6836   if(ret->getNumberOfTS()>0)
6837     ret->synchronizeNameScope();
6838   ret->copyNameScope(*this);
6839   return ret.retn();
6840 }
6841
6842 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6843 {
6844   int id=0;
6845   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6846   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6847     {
6848       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6849       if(!cur)
6850         continue;
6851       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6852       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
6853         ids->pushBackSilent(id);
6854     }
6855   return buildFromTimeStepIds(ids->begin(),ids->end());
6856 }
6857
6858 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
6859 {
6860   int id=0;
6861   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
6862   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
6863     {
6864       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6865       if(!cur)
6866         continue;
6867       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
6868       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
6869         ids->pushBackSilent(id);
6870     }
6871   return buildFromTimeStepIds(ids->begin(),ids->end());
6872 }
6873
6874 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
6875 {
6876   return _infos;
6877 }
6878
6879 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
6880 {
6881   _infos=info;
6882 }
6883
6884 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
6885 {
6886   int ret=0;
6887   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
6888     {
6889       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
6890       if(pt->isDealingTS(iteration,order))
6891         return ret;
6892     }
6893   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
6894   std::vector< std::pair<int,int> > vp=getIterations();
6895   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
6896     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
6897   throw INTERP_KERNEL::Exception(oss.str().c_str());
6898 }
6899
6900 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
6901 {
6902   return *_time_steps[getTimeStepPos(iteration,order)];
6903 }
6904
6905 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
6906 {
6907   return *_time_steps[getTimeStepPos(iteration,order)];
6908 }
6909
6910 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
6911 {
6912   if(_time_steps.empty())
6913     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
6914   return _time_steps[0]->getMeshName();
6915 }
6916
6917 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
6918 {
6919   std::string oldName(getMeshName());
6920   std::vector< std::pair<std::string,std::string> > v(1);
6921   v[0].first=oldName; v[0].second=newMeshName;
6922   changeMeshNames(v);
6923 }
6924
6925 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6926 {
6927   bool ret=false;
6928   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6929     {
6930       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
6931       if(cur)
6932         ret=cur->changeMeshNames(modifTab) || ret;
6933     }
6934   return ret;
6935 }
6936
6937 /*!
6938  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
6939  */
6940 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
6941 {
6942   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
6943 }
6944
6945 /*!
6946  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
6947  */
6948 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6949 {
6950   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
6951 }
6952
6953 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
6954                                                                        MEDFileFieldGlobsReal& glob)
6955 {
6956   bool ret=false;
6957   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
6958     {
6959       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
6960       if(f1ts)
6961         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
6962     }
6963   return ret;
6964 }
6965
6966 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
6967 {
6968   std::string startLine(bkOffset,' ');
6969   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
6970   if(fmtsId>=0)
6971     oss << " (" << fmtsId << ")";
6972   oss << " has the following name: \"" << _name << "\"." << std::endl;
6973   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
6974   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
6975     {
6976       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
6977     }
6978   int i=0;
6979   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
6980     {
6981       std::string chapter(17,'0'+i);
6982       oss << startLine << chapter << std::endl;
6983       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
6984       if(cur)
6985         cur->simpleRepr(bkOffset+2,oss,i);
6986       else
6987         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
6988       oss << startLine << chapter << std::endl;
6989     }
6990 }
6991
6992 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
6993 {
6994   std::size_t sz=_time_steps.size();
6995   std::vector< std::pair<int,int> > ret(sz);
6996   ret1.resize(sz);
6997   for(std::size_t i=0;i<sz;i++)
6998     {
6999       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7000       if(f1ts)
7001         {
7002           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7003         }
7004       else
7005         {
7006           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7007           throw INTERP_KERNEL::Exception(oss.str().c_str());
7008         }
7009     }
7010   return ret;
7011 }
7012
7013 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7014 {
7015   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7016   if(!tse2)
7017     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7018   checkCoherencyOfType(tse2);
7019   if(_time_steps.empty())
7020     {
7021       setName(tse2->getName().c_str());
7022       setInfo(tse2->getInfo());
7023     }
7024   checkThatComponentsMatch(tse2->getInfo());
7025   _time_steps.push_back(tse);
7026 }
7027
7028 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7029 {
7030   std::size_t nbOfCompo=_infos.size();
7031   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7032     {
7033       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7034       if(cur)
7035         {
7036           if((cur->getInfo()).size()!=nbOfCompo)
7037             {
7038               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7039               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7040               throw INTERP_KERNEL::Exception(oss.str().c_str());
7041             }
7042           cur->copyNameScope(*this);
7043         }
7044     }
7045 }
7046
7047 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll)
7048 {
7049   _time_steps.resize(nbPdt);
7050   for(int i=0;i<nbPdt;i++)
7051     {
7052       std::vector< std::pair<int,int> > ts;
7053       med_int numdt=0,numo=0;
7054       med_int meshIt=0,meshOrder=0;
7055       med_float dt=0.0;
7056       MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
7057       switch(fieldTyp)
7058       {
7059         case MED_FLOAT64:
7060           {
7061             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7062             break;
7063           }
7064         case MED_INT32:
7065           {
7066             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7067             break;
7068           }
7069         default:
7070           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7071       }
7072       if(loadAll)
7073         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this);
7074       else
7075         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this);
7076     }
7077 }
7078
7079 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7080 {
7081   if(_time_steps.empty())
7082     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7083   checkThatNbOfCompoOfTSMatchThis();
7084   std::vector<std::string> infos(getInfo());
7085   int nbComp=infos.size();
7086   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7087   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7088   for(int i=0;i<nbComp;i++)
7089     {
7090       std::string info=infos[i];
7091       std::string c,u;
7092       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7093       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7094       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7095     }
7096   if(_name.empty())
7097     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7098   MEDfieldCr(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str());
7099   int nbOfTS=_time_steps.size();
7100   for(int i=0;i<nbOfTS;i++)
7101     _time_steps[i]->writeLL(fid,opts,*this);
7102 }
7103
7104 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7105 {
7106   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7107     {
7108       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7109       if(elt)
7110         elt->loadBigArraysRecursively(fid,nasc);
7111     }
7112 }
7113
7114 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7115 {
7116   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7117     {
7118       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7119       if(elt)
7120         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7121     }
7122 }
7123
7124 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7125 {
7126   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7127     {
7128       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7129       if(elt)
7130         elt->unloadArrays();
7131     }
7132 }
7133
7134 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7135 {
7136   return _time_steps.size();
7137 }
7138
7139 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7140 {
7141   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7142   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7143     {
7144       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7145       if(tmp)
7146         newTS.push_back(*it);
7147     }
7148   _time_steps=newTS;
7149 }
7150
7151 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7152 {
7153   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7154   int maxId=(int)_time_steps.size();
7155   int ii=0;
7156   std::set<int> idsToDel;
7157   for(const int *id=startIds;id!=endIds;id++,ii++)
7158     {
7159       if(*id>=0 && *id<maxId)
7160         {
7161           idsToDel.insert(*id);
7162         }
7163       else
7164         {
7165           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7166           throw INTERP_KERNEL::Exception(oss.str().c_str());
7167         }
7168     }
7169   for(int iii=0;iii<maxId;iii++)
7170     if(idsToDel.find(iii)==idsToDel.end())
7171       newTS.push_back(_time_steps[iii]);
7172   _time_steps=newTS;
7173 }
7174
7175 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7176 {
7177   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7178   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7179   if(nbOfEntriesToKill==0)
7180     return ;
7181   std::size_t sz=_time_steps.size();
7182   std::vector<bool> b(sz,true);
7183   int j=bg;
7184   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7185     b[j]=false;
7186   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7187   for(std::size_t i=0;i<sz;i++)
7188     if(b[i])
7189       newTS.push_back(_time_steps[i]);
7190   _time_steps=newTS;
7191 }
7192
7193 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7194 {
7195   int ret=0;
7196   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7197   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7198     {
7199       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7200       if(tmp)
7201         {
7202           int it2,ord;
7203           tmp->getTime(it2,ord);
7204           if(it2==iteration && order==ord)
7205             return ret;
7206           else
7207             oss << "(" << it2 << ","  << ord << "), ";
7208         }
7209     }
7210   throw INTERP_KERNEL::Exception(oss.str().c_str());
7211 }
7212
7213 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7214 {
7215   int ret=0;
7216   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7217   oss.precision(15);
7218   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7219     {
7220       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7221       if(tmp)
7222         {
7223           int it2,ord;
7224           double ti=tmp->getTime(it2,ord);
7225           if(fabs(time-ti)<eps)
7226             return ret;
7227           else
7228             oss << ti << ", ";
7229         }
7230     }
7231   throw INTERP_KERNEL::Exception(oss.str().c_str());
7232 }
7233
7234 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7235 {
7236   int lgth=_time_steps.size();
7237   std::vector< std::pair<int,int> > ret(lgth);
7238   for(int i=0;i<lgth;i++)
7239     _time_steps[i]->fillIteration(ret[i]);
7240   return ret;
7241 }
7242
7243 /*!
7244  * 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'
7245  * This method returns two things.
7246  * - The absolute dimension of 'this' in first parameter. 
7247  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7248  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7249  *
7250  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7251  * Only these 3 discretizations will be taken into account here.
7252  *
7253  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7254  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7255  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7256  *
7257  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7258  * 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'.
7259  * 
7260  * Let's consider the typical following case :
7261  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7262  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7263  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7264  *   TETRA4 and SEG2
7265  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7266  *
7267  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7268  * 
7269  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7270  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7271  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7272  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7273  */
7274 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7275 {
7276   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7277 }
7278
7279 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7280 {
7281   if(pos<0 || pos>=(int)_time_steps.size())
7282     {
7283       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7284       throw INTERP_KERNEL::Exception(oss.str().c_str());
7285     }
7286   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7287   if(item==0)
7288     {
7289       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7290       oss << "\nTry to use following method eraseEmptyTS !";
7291       throw INTERP_KERNEL::Exception(oss.str().c_str());
7292     }
7293   return item;
7294 }
7295
7296 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7297 {
7298   if(pos<0 || pos>=(int)_time_steps.size())
7299     {
7300       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7301       throw INTERP_KERNEL::Exception(oss.str().c_str());
7302     }
7303   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7304   if(item==0)
7305     {
7306       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7307       oss << "\nTry to use following method eraseEmptyTS !";
7308       throw INTERP_KERNEL::Exception(oss.str().c_str());
7309     }
7310   return item;
7311 }
7312
7313 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7314 {
7315   std::vector<std::string> ret;
7316   std::set<std::string> ret2;
7317   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7318     {
7319       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7320       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7321         if(ret2.find(*it2)==ret2.end())
7322           {
7323             ret.push_back(*it2);
7324             ret2.insert(*it2);
7325           }
7326     }
7327   return ret;
7328 }
7329
7330 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7331 {
7332   std::vector<std::string> ret;
7333   std::set<std::string> ret2;
7334   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7335     {
7336       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7337       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7338         if(ret2.find(*it2)==ret2.end())
7339           {
7340             ret.push_back(*it2);
7341             ret2.insert(*it2);
7342           }
7343     }
7344   return ret;
7345 }
7346
7347 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7348 {
7349   std::vector<std::string> ret;
7350   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7351     {
7352       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7353       ret.insert(ret.end(),tmp.begin(),tmp.end());
7354     }
7355   return ret;
7356 }
7357
7358 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7359 {
7360   std::vector<std::string> ret;
7361   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7362     {
7363       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7364       ret.insert(ret.end(),tmp.begin(),tmp.end());
7365     }
7366   return ret;
7367 }
7368
7369 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7370 {
7371   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7372     (*it)->changePflsRefsNamesGen2(mapOfModif);
7373 }
7374
7375 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7376 {
7377   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7378     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7379 }
7380
7381 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7382 {
7383   int lgth=_time_steps.size();
7384   std::vector< std::vector<TypeOfField> > ret(lgth);
7385   for(int i=0;i<lgth;i++)
7386     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7387   return ret;
7388 }
7389
7390 /*!
7391  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7392  */
7393 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
7394 {
7395   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7396 }
7397
7398 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCpy() const
7399 {
7400   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7401   std::size_t i=0;
7402   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7403     {
7404       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7405         ret->_time_steps[i]=(*it)->deepCpy();
7406     }
7407   return ret.retn();
7408 }
7409
7410 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7411 {
7412   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7413   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7414   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7415   for(std::size_t i=0;i<sz;i++)
7416     {
7417       ret[i]=shallowCpy();
7418       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7419     }
7420   for(std::size_t i=0;i<sz2;i++)
7421     {
7422       std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7423       if(ret1.size()!=sz)
7424         {
7425           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7426           throw INTERP_KERNEL::Exception(oss.str().c_str());
7427         }
7428       ts[i]=ret1;
7429     }
7430   for(std::size_t i=0;i<sz;i++)
7431     for(std::size_t j=0;j<sz2;j++)
7432       ret[i]->_time_steps[j]=ts[j][i];
7433   return ret;
7434 }
7435
7436 /*!
7437  * This method splits into discretization each time steps in \a this.
7438  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7439  */
7440 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7441 {
7442   std::size_t sz(_time_steps.size());
7443   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7444   for(std::size_t i=0;i<sz;i++)
7445     {
7446       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7447       if(!timeStep)
7448         {
7449           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7450           throw INTERP_KERNEL::Exception(oss.str().c_str());
7451         }
7452       items[i]=timeStep->splitDiscretizations();  
7453     }
7454   //
7455   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7456   std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7457   std::vector< TypeOfField > types;
7458   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7459     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7460       {
7461         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7462         if(ts.size()!=1)
7463           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7464         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7465         if(it2==types.end())
7466           types.push_back(ts[0]);
7467       }
7468   ret.resize(types.size()); ret2.resize(types.size());
7469   for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7470     for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7471       {
7472         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7473         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7474         ret2[pos].push_back(*it1);
7475       }
7476   for(std::size_t i=0;i<types.size();i++)
7477     {
7478       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=createNew();
7479       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7480         elt->pushBackTimeStep(*it1);//also updates infos in elt
7481       ret[i]=elt;
7482       elt->MEDFileFieldNameScope::operator=(*this);
7483     }
7484   return ret;
7485 }
7486
7487 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7488 {
7489   _name=field->getName();
7490   if(_name.empty())
7491     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7492   if(!arr)
7493     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7494   _infos=arr->getInfoOnComponents();
7495 }
7496
7497 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7498 {
7499   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7500   if(_name!=field->getName())
7501     {
7502       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7503       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7504       throw INTERP_KERNEL::Exception(oss.str().c_str());
7505     }
7506   if(!arr)
7507     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
7508   checkThatComponentsMatch(arr->getInfoOnComponents());
7509 }
7510
7511 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
7512 {
7513   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
7514   if(getInfo().size()!=compos.size())
7515     {
7516       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
7517       oss << " number of components of element to append (" << compos.size() << ") !";
7518       throw INTERP_KERNEL::Exception(oss.str().c_str());
7519     }
7520   if(_infos!=compos)
7521     {
7522       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
7523       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
7524       oss << " But compo in input fields are : ";
7525       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
7526       oss << " !";
7527       throw INTERP_KERNEL::Exception(oss.str().c_str());
7528     }
7529 }
7530
7531 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
7532 {
7533   std::size_t sz=_infos.size();
7534   int j=0;
7535   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
7536     {
7537       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7538       if(elt)
7539         if(elt->getInfo().size()!=sz)
7540           {
7541             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
7542             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
7543             throw INTERP_KERNEL::Exception(oss.str().c_str());
7544           }
7545     }
7546 }
7547
7548 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
7549 {
7550   if(!field)
7551     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7552   if(!_time_steps.empty())
7553     checkCoherencyOfTinyInfo(field,arr);
7554   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
7555   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7556   objC->setFieldNoProfileSBT(field,arr,glob,*this);
7557   copyTinyInfoFrom(field,arr);
7558   _time_steps.push_back(obj);
7559 }
7560
7561 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
7562 {
7563   if(!field)
7564     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
7565   if(!_time_steps.empty())
7566     checkCoherencyOfTinyInfo(field,arr);
7567   MEDFileField1TSWithoutSDA *objC=new MEDFileField1TSWithoutSDA;
7568   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
7569   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
7570   copyTinyInfoFrom(field,arr);
7571   _time_steps.push_back(obj);
7572 }
7573
7574 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> ts)
7575 {
7576   int sz=(int)_time_steps.size();
7577   if(i<0 || i>=sz)
7578     {
7579       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
7580       throw INTERP_KERNEL::Exception(oss.str().c_str());
7581     }
7582   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
7583   if(tsPtr)
7584     {
7585       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
7586         {
7587           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
7588           throw INTERP_KERNEL::Exception(oss.str().c_str());
7589         }
7590     }
7591   _time_steps[i]=ts;
7592 }
7593
7594 //= MEDFileFieldMultiTSWithoutSDA
7595
7596 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)
7597 {
7598   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7599 }
7600
7601 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
7602 {
7603 }
7604
7605 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7606 {
7607 }
7608
7609 /*!
7610  * \param [in] fieldId field id in C mode
7611  */
7612 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll)
7613 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7614 {
7615 }
7616 catch(INTERP_KERNEL::Exception& e)
7617 { throw e; }
7618
7619 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)
7620 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7621 {
7622 }
7623 catch(INTERP_KERNEL::Exception& e)
7624 { throw e; }
7625
7626 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7627 {
7628   return new MEDFileField1TSWithoutSDA;
7629 }
7630
7631 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7632 {
7633   if(!f1ts)
7634     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7635   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
7636   if(!f1tsC)
7637     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
7638 }
7639
7640 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
7641 {
7642   return MEDFileField1TSWithoutSDA::TYPE_STR;
7643 }
7644
7645 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
7646 {
7647   return new MEDFileFieldMultiTSWithoutSDA(*this);
7648 }
7649
7650 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
7651 {
7652   return new MEDFileFieldMultiTSWithoutSDA;
7653 }
7654
7655 /*!
7656  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
7657  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
7658  */
7659 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
7660 {
7661   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
7662   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
7663   if(!myF1TSC)
7664     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
7665   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7666 }
7667
7668 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
7669 {
7670   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
7671   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7672   int i=0;
7673   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7674     {
7675       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7676       if(eltToConv)
7677         {
7678           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
7679           if(!eltToConvC)
7680             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
7681           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
7682           ret->setIteration(i,elt);
7683         }
7684     }
7685   return ret.retn();
7686 }
7687
7688 //= MEDFileAnyTypeFieldMultiTS
7689
7690 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
7691 {
7692 }
7693
7694 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, bool loadAll)
7695 try:MEDFileFieldGlobsReal(fileName)
7696 {
7697   MEDFileUtilities::CheckFileForRead(fileName);
7698   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7699   _content=BuildContentFrom(fid,fileName,loadAll);
7700   loadGlobals(fid);
7701 }
7702 catch(INTERP_KERNEL::Exception& e)
7703 {
7704     throw e;
7705 }
7706
7707 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, const std::string& fieldName, bool loadAll)
7708 {
7709   med_field_type typcha;
7710   std::vector<std::string> infos;
7711   std::string dtunit;
7712   int i=-1;
7713   MEDFileAnyTypeField1TS::LocateField(fid,fileName,fieldName,i,typcha,infos,dtunit);
7714   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7715   switch(typcha)
7716   {
7717     case MED_FLOAT64:
7718       {
7719         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll);
7720         break;
7721       }
7722     case MED_INT32:
7723       {
7724         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll);
7725         break;
7726       }
7727     default:
7728       {
7729         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] !";
7730         throw INTERP_KERNEL::Exception(oss.str().c_str());
7731       }
7732   }
7733   ret->setDtUnit(dtunit.c_str());
7734   return ret.retn();
7735 }
7736
7737 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fileName, bool loadAll)
7738 {
7739   med_field_type typcha;
7740   //
7741   std::vector<std::string> infos;
7742   std::string dtunit,fieldName;
7743   MEDFileAnyTypeField1TS::LocateField2(fid,fileName,0,true,fieldName,typcha,infos,dtunit);
7744   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
7745   switch(typcha)
7746   {
7747     case MED_FLOAT64:
7748       {
7749         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll);
7750         break;
7751       }
7752     case MED_INT32:
7753       {
7754         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll);
7755         break;
7756       }
7757     default:
7758       {
7759         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] !";
7760         throw INTERP_KERNEL::Exception(oss.str().c_str());
7761       }
7762   }
7763   ret->setDtUnit(dtunit.c_str());
7764   return ret.retn();
7765 }
7766
7767 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, const std::string& fileName)
7768 {
7769   if(!c)
7770     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
7771   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
7772     {
7773       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=MEDFileFieldMultiTS::New();
7774       ret->setFileName(fileName);
7775       ret->_content=c;  c->incrRef();
7776       return ret.retn();
7777     }
7778   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
7779     {
7780       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=MEDFileIntFieldMultiTS::New();
7781       ret->setFileName(fileName);
7782       ret->_content=c;  c->incrRef();
7783       return ret.retn();
7784     }
7785   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
7786 }
7787
7788 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll)
7789 try:MEDFileFieldGlobsReal(fileName)
7790 {
7791   MEDFileUtilities::CheckFileForRead(fileName);
7792   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7793   _content=BuildContentFrom(fid,fileName,fieldName,loadAll);
7794   loadGlobals(fid);
7795 }
7796 catch(INTERP_KERNEL::Exception& e)
7797 {
7798     throw e;
7799 }
7800
7801 //= MEDFileIntFieldMultiTSWithoutSDA
7802
7803 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)
7804 {
7805   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll);
7806 }
7807
7808 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
7809 {
7810 }
7811
7812 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
7813 {
7814 }
7815
7816 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)
7817 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll)
7818 {
7819 }
7820 catch(INTERP_KERNEL::Exception& e)
7821 { throw e; }
7822
7823 /*!
7824  * \param [in] fieldId field id in C mode
7825  */
7826 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll)
7827 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll)
7828 {
7829 }
7830 catch(INTERP_KERNEL::Exception& e)
7831 { throw e; }
7832
7833 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
7834 {
7835   return new MEDFileIntField1TSWithoutSDA;
7836 }
7837
7838 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
7839 {
7840   if(!f1ts)
7841     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
7842   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
7843   if(!f1tsC)
7844     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
7845 }
7846
7847 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
7848 {
7849   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
7850 }
7851
7852 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
7853 {
7854   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
7855 }
7856
7857 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
7858 {
7859   return new MEDFileIntFieldMultiTSWithoutSDA;
7860 }
7861
7862 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
7863 {
7864   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
7865   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
7866   int i=0;
7867   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7868     {
7869       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
7870       if(eltToConv)
7871         {
7872           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
7873           if(!eltToConvC)
7874             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
7875           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
7876           ret->setIteration(i,elt);
7877         }
7878     }
7879   return ret.retn();
7880 }
7881
7882 //= MEDFileAnyTypeFieldMultiTS
7883
7884 /*!
7885  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
7886  * that has been read from a specified MED file.
7887  *  \param [in] fileName - the name of the MED file to read.
7888  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7889  *          is to delete this field using decrRef() as it is no more needed.
7890  *  \throw If reading the file fails.
7891  */
7892 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
7893 {
7894   MEDFileUtilities::CheckFileForRead(fileName);
7895   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7896   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,loadAll);
7897   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7898   ret->loadGlobals(fid);
7899   return ret.retn();
7900 }
7901
7902 /*!
7903  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
7904  * that has been read from a specified MED file.
7905  *  \param [in] fileName - the name of the MED file to read.
7906  *  \param [in] fieldName - the name of the field to read.
7907  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
7908  *          is to delete this field using decrRef() as it is no more needed.
7909  *  \throw If reading the file fails.
7910  *  \throw If there is no field named \a fieldName in the file.
7911  */
7912 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
7913 {
7914   MEDFileUtilities::CheckFileForRead(fileName);
7915   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
7916   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=BuildContentFrom(fid,fileName,fieldName,loadAll);
7917   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=BuildNewInstanceFromContent(c,fileName);
7918   ret->loadGlobals(fid);
7919   return ret.retn();
7920 }
7921
7922 /*!
7923  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7924  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7925  *
7926  * \warning this is a shallow copy constructor
7927  */
7928 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
7929 {
7930   if(!shallowCopyOfContent)
7931     {
7932       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
7933       otherPtr->incrRef();
7934       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
7935     }
7936   else
7937     {
7938       _content=other.shallowCpy();
7939     }
7940 }
7941
7942 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
7943 {
7944   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7945   if(!ret)
7946     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
7947   return ret;
7948 }
7949
7950 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
7951 {
7952   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
7953   if(!ret)
7954     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
7955   return ret;
7956 }
7957
7958 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
7959 {
7960   return contentNotNullBase()->getPflsReallyUsed2();
7961 }
7962
7963 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
7964 {
7965   return contentNotNullBase()->getLocsReallyUsed2();
7966 }
7967
7968 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
7969 {
7970   return contentNotNullBase()->getPflsReallyUsedMulti2();
7971 }
7972
7973 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
7974 {
7975   return contentNotNullBase()->getLocsReallyUsedMulti2();
7976 }
7977
7978 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7979 {
7980   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
7981 }
7982
7983 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7984 {
7985   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
7986 }
7987
7988 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
7989 {
7990   return contentNotNullBase()->getNumberOfTS();
7991 }
7992
7993 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
7994 {
7995   contentNotNullBase()->eraseEmptyTS();
7996 }
7997
7998 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
7999 {
8000   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8001 }
8002
8003 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8004 {
8005   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8006 }
8007
8008 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8009 {
8010   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8011   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8012   ret->_content=c;
8013   return ret.retn();
8014 }
8015
8016 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8017 {
8018   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8019   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8020   ret->_content=c;
8021   return ret.retn();
8022 }
8023
8024 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8025 {
8026   return contentNotNullBase()->getIterations();
8027 }
8028
8029 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8030 {
8031   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8032     pushBackTimeStep(*it);
8033 }
8034
8035 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8036 {
8037   if(!f1ts)
8038     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8039   checkCoherencyOfType(f1ts);
8040   f1ts->incrRef();
8041   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8042   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8043   c->incrRef();
8044   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8045   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8046     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8047   _content->pushBackTimeStep(cSafe);
8048   appendGlobs(*f1ts,1e-12);
8049 }
8050
8051 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8052 {
8053   contentNotNullBase()->synchronizeNameScope();
8054 }
8055
8056 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8057 {
8058   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8059 }
8060
8061 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8062 {
8063   return contentNotNullBase()->getPosGivenTime(time,eps);
8064 }
8065
8066 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8067 {
8068   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8069 }
8070
8071 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8072 {
8073   return contentNotNullBase()->getTypesOfFieldAvailable();
8074 }
8075
8076 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
8077 {
8078   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8079 }
8080
8081 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8082 {
8083   return contentNotNullBase()->getName();
8084 }
8085
8086 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8087 {
8088   contentNotNullBase()->setName(name);
8089 }
8090
8091 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8092 {
8093   return contentNotNullBase()->getDtUnit();
8094 }
8095
8096 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8097 {
8098   contentNotNullBase()->setDtUnit(dtUnit);
8099 }
8100
8101 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8102 {
8103   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8104 }
8105
8106 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8107 {
8108   return contentNotNullBase()->getTimeSteps(ret1);
8109 }
8110
8111 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8112 {
8113   return contentNotNullBase()->getMeshName();
8114 }
8115
8116 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8117 {
8118   contentNotNullBase()->setMeshName(newMeshName);
8119 }
8120
8121 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8122 {
8123   return contentNotNullBase()->changeMeshNames(modifTab);
8124 }
8125
8126 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8127 {
8128   return contentNotNullBase()->getInfo();
8129 }
8130
8131 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8132 {
8133   return contentNotNullBase()->setInfo(info);
8134 }
8135
8136 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8137 {
8138   const std::vector<std::string> ret=getInfo();
8139   return (int)ret.size();
8140 }
8141
8142 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8143 {
8144   writeGlobals(fid,*this);
8145   contentNotNullBase()->writeLL(fid,*this);
8146 }
8147
8148 /*!
8149  * Writes \a this field into a MED file specified by its name.
8150  *  \param [in] fileName - the MED file name.
8151  *  \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
8152  * - 2 - erase; an existing file is removed.
8153  * - 1 - append; same data should not be present in an existing file.
8154  * - 0 - overwrite; same data present in an existing file is overwritten.
8155  *  \throw If the field name is not set.
8156  *  \throw If no field data is set.
8157  *  \throw If \a mode == 1 and the same data is present in an existing file.
8158  */
8159 void MEDFileAnyTypeFieldMultiTS::write(const std::string& fileName, int mode) const
8160 {
8161   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
8162   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
8163   writeLL(fid);
8164 }
8165
8166 /*!
8167  * This method alloc the arrays and load potentially huge arrays contained in this field.
8168  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8169  * This method can be also called to refresh or reinit values from a file.
8170  * 
8171  * \throw If the fileName is not set or points to a non readable MED file.
8172  */
8173 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8174 {
8175   if(getFileName().empty())
8176     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8177   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8178   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8179 }
8180
8181 /*!
8182  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8183  * But once data loaded once, this method does nothing.
8184  * 
8185  * \throw If the fileName is not set or points to a non readable MED file.
8186  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8187  */
8188 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8189 {
8190   if(!getFileName().empty())
8191     {
8192       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
8193       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8194     }
8195 }
8196
8197 /*!
8198  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8199  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8200  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8201  * 
8202  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8203  */
8204 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8205 {
8206   contentNotNullBase()->unloadArrays();
8207 }
8208
8209 /*!
8210  * 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.
8211  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8212  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8213  * 
8214  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8215  */
8216 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8217 {
8218   if(!getFileName().empty())
8219     contentNotNullBase()->unloadArrays();
8220 }
8221
8222 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8223 {
8224   std::ostringstream oss;
8225   contentNotNullBase()->simpleRepr(0,oss,-1);
8226   simpleReprGlobs(oss);
8227   return oss.str();
8228 }
8229
8230 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8231 {
8232   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8233 }
8234
8235 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildren() const
8236 {
8237   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildren());
8238   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8239     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8240   return ret;
8241 }
8242
8243 /*!
8244  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8245  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8246  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8247  */
8248 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8249 {
8250   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8251   if(!content)
8252     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8253   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8254   std::size_t sz(contentsSplit.size());
8255   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8256   for(std::size_t i=0;i<sz;i++)
8257     {
8258       ret[i]=shallowCpy();
8259       ret[i]->_content=contentsSplit[i];
8260     }
8261   return ret;
8262 }
8263
8264 /*!
8265  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8266  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8267  */
8268 std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8269 {
8270   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8271   if(!content)
8272     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8273   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitDiscretizations();
8274   std::size_t sz(contentsSplit.size());
8275   std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8276   for(std::size_t i=0;i<sz;i++)
8277     {
8278       ret[i]=shallowCpy();
8279       ret[i]->_content=contentsSplit[i];
8280     }
8281   return ret;
8282 }
8283
8284 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCpy() const
8285 {
8286   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8287   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8288     ret->_content=_content->deepCpy();
8289   ret->deepCpyGlobs(*this);
8290   return ret.retn();
8291 }
8292
8293 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8294 {
8295   return _content;
8296 }
8297
8298 /*!
8299  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8300  *  \param [in] iteration - the iteration number of a required time step.
8301  *  \param [in] order - the iteration order number of required time step.
8302  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8303  *          delete this field using decrRef() as it is no more needed.
8304  *  \throw If there is no required time step in \a this field.
8305  */
8306 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8307 {
8308   int pos=getPosOfTimeStep(iteration,order);
8309   return getTimeStepAtPos(pos);
8310 }
8311
8312 /*!
8313  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8314  *  \param [in] time - the time of the time step of interest.
8315  *  \param [in] eps - a precision used to compare time values.
8316  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8317  *          delete this field using decrRef() as it is no more needed.
8318  *  \throw If there is no required time step in \a this field.
8319  */
8320 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8321 {
8322   int pos=getPosGivenTime(time,eps);
8323   return getTimeStepAtPos(pos);
8324 }
8325
8326 /*!
8327  * 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.
8328  * The float64 value of time attached to the pair of integers are not considered here.
8329  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8330  *
8331  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8332  * \throw If there is a null pointer in \a vectFMTS.
8333  */
8334 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8335 {
8336   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8337   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8338   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8339   while(!lstFMTS.empty())
8340     {
8341       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8342       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8343       if(!curIt)
8344         throw INTERP_KERNEL::Exception(msg);
8345       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8346       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8347       elt.push_back(curIt); it=lstFMTS.erase(it);
8348       while(it!=lstFMTS.end())
8349         {
8350           curIt=*it;
8351           if(!curIt)
8352             throw INTERP_KERNEL::Exception(msg);
8353           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8354           if(refIts==curIts)
8355             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8356           else
8357             it++;
8358         }
8359       ret.push_back(elt);
8360     }
8361   return ret;
8362 }
8363
8364 /*!
8365  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8366  * All returned instances in a subvector can be safely loaded, rendered along time
8367  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8368  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8369  * 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).
8370  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8371  * 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.
8372  *
8373  * \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().
8374  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8375  * \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.
8376  * \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.
8377  *
8378  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8379  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8380  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8381  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8382  * \throw If mesh is null.
8383  * \throw If an element in \a vectFMTS is null.
8384  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8385  */
8386 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& fsc)
8387 {
8388   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8389   if(!mesh)
8390     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8391   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8392   if(vectFMTS.empty())
8393     return ret;
8394   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8395   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8396   if(!frstElt)
8397     throw INTERP_KERNEL::Exception(msg);
8398   std::size_t i=0;
8399   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8400   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8401   for(;it!=vectFMTS.end();it++,i++)
8402     {
8403       if(!(*it))
8404         throw INTERP_KERNEL::Exception(msg);
8405       TypeOfField tof0,tof1;
8406       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8407         {
8408           if(tof1!=ON_NODES)
8409             vectFMTSNotNodes.push_back(*it);
8410           else
8411             vectFMTSNodes.push_back(*it);
8412         }
8413       else
8414         vectFMTSNotNodes.push_back(*it);
8415     }
8416   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> > cmps;
8417   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8418   ret=retCell;
8419   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8420     {
8421       i=0;
8422       bool isFetched(false);
8423       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8424         {
8425           if((*it0).empty())
8426             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8427           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8428             { ret[i].push_back(*it2); isFetched=true; }
8429         }
8430       if(!isFetched)
8431         {
8432           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8433           MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8434           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8435         }
8436     }
8437   fsc=cmps;
8438   return ret;
8439 }
8440
8441 /*!
8442  * 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.
8443  * \param [out] cmps - same size than the returned vector.
8444  */
8445 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> >& cmps)
8446 {
8447   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8448   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8449   while(!lstFMTS.empty())
8450     {
8451       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8452       MEDFileAnyTypeFieldMultiTS *ref(*it);
8453       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8454       elt.push_back(ref); it=lstFMTS.erase(it);
8455       MEDCouplingAutoRefCountObjectPtr<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8456       MEDCouplingAutoRefCountObjectPtr<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8457       while(it!=lstFMTS.end())
8458         {
8459           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8460           if(cmp->isEqual(curIt))
8461             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8462           else
8463             it++;
8464         }
8465       ret.push_back(elt); cmps.push_back(cmp);
8466     }
8467   return ret;
8468 }
8469
8470 /*!
8471  * 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.
8472  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8473  *
8474  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8475  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8476  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
8477  * \thorw If \a f0 and \a f1 do not have the same times steps.
8478  * \throw If mesh is null.
8479  * \throw If \a f0 or \a f1 is null.
8480  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
8481  */
8482 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
8483 {
8484   if(!mesh)
8485     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
8486   if(!f0 || !f1)
8487     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
8488   if(f0->getMeshName()!=mesh->getName())
8489     {
8490       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8491       throw INTERP_KERNEL::Exception(oss.str().c_str());
8492     }
8493   if(f1->getMeshName()!=mesh->getName())
8494     {
8495       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
8496       throw INTERP_KERNEL::Exception(oss.str().c_str());
8497     }
8498   int nts=f0->getNumberOfTS();
8499   if(nts!=f1->getNumberOfTS())
8500     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
8501   if(nts==0)
8502     return nts;
8503   for(int i=0;i<nts;i++)
8504     {
8505       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
8506       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
8507       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
8508       if(tofs0.size()!=1 || tofs1.size()!=1)
8509         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
8510       if(i!=0)
8511         {
8512           if(tof0!=tofs0[0] || tof1!=tofs1[0])
8513             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
8514         }
8515       else
8516         { tof0=tofs0[0]; tof1=tofs1[0]; }
8517       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
8518         {
8519           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() << ") !";
8520           throw INTERP_KERNEL::Exception(oss.str().c_str());
8521         }
8522       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
8523         {
8524           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() << ") !";
8525           throw INTERP_KERNEL::Exception(oss.str().c_str());
8526         }
8527       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
8528         {
8529           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() << ") !";
8530           throw INTERP_KERNEL::Exception(oss.str().c_str());
8531         }
8532     }
8533   return nts;
8534 }
8535
8536 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
8537 {
8538   return new MEDFileAnyTypeFieldMultiTSIterator(this);
8539 }
8540
8541 //= MEDFileFieldMultiTS
8542
8543 /*!
8544  * Returns a new empty instance of MEDFileFieldMultiTS.
8545  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8546  *          is to delete this field using decrRef() as it is no more needed.
8547  */
8548 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
8549 {
8550   return new MEDFileFieldMultiTS;
8551 }
8552
8553 /*!
8554  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
8555  * that has been read from a specified MED file.
8556  *  \param [in] fileName - the name of the MED file to read.
8557  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8558  *          is to delete this field using decrRef() as it is no more needed.
8559  *  \throw If reading the file fails.
8560  */
8561 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
8562 {
8563   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,loadAll);
8564   ret->contentNotNull();//to check that content type matches with \a this type.
8565   return ret.retn();
8566 }
8567
8568 /*!
8569  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
8570  * that has been read from a specified MED file.
8571  *  \param [in] fileName - the name of the MED file to read.
8572  *  \param [in] fieldName - the name of the field to read.
8573  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8574  *          is to delete this field using decrRef() as it is no more needed.
8575  *  \throw If reading the file fails.
8576  *  \throw If there is no field named \a fieldName in the file.
8577  */
8578 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8579 {
8580   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret=new MEDFileFieldMultiTS(fileName,fieldName,loadAll);
8581   ret->contentNotNull();//to check that content type matches with \a this type.
8582   return ret.retn();
8583 }
8584
8585 /*!
8586  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8587  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8588  *
8589  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
8590  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
8591  * \warning this is a shallow copy constructor
8592  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
8593  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
8594  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
8595  *          is to delete this field using decrRef() as it is no more needed.
8596  */
8597 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8598 {
8599   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
8600 }
8601
8602 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
8603 {
8604   return new MEDFileFieldMultiTS(*this);
8605 }
8606
8607 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
8608 {
8609   if(!f1ts)
8610     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8611   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
8612   if(!f1tsC)
8613     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8614 }
8615
8616 /*!
8617  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
8618  * following the given input policy.
8619  *
8620  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
8621  *                            By default (true) the globals are deeply copied.
8622  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
8623  */
8624 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
8625 {
8626   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret;
8627   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8628   if(content)
8629     {
8630       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
8631       if(!contc)
8632         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
8633       MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
8634       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName()));
8635     }
8636   else
8637     ret=MEDFileIntFieldMultiTS::New();
8638   if(isDeepCpyGlobs)
8639     ret->deepCpyGlobs(*this);
8640   else
8641     ret->shallowCpyGlobs(*this);
8642   return ret.retn();
8643 }
8644
8645 /*!
8646  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
8647  *  \param [in] pos - a time step id.
8648  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8649  *          delete this field using decrRef() as it is no more needed.
8650  *  \throw If \a pos is not a valid time step id.
8651  */
8652 MEDFileAnyTypeField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
8653 {
8654   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
8655   if(!item)
8656     {
8657       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
8658       throw INTERP_KERNEL::Exception(oss.str().c_str());
8659     }
8660   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
8661   if(itemC)
8662     {
8663       MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
8664       ret->shallowCpyGlobs(*this);
8665       return ret.retn();
8666     }
8667   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
8668   throw INTERP_KERNEL::Exception(oss.str().c_str());
8669 }
8670
8671 /*!
8672  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8673  * mesh entities of a given dimension of the first mesh in MED file.
8674  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8675  *  \param [in] type - a spatial discretization of interest.
8676  *  \param [in] iteration - the iteration number of a required time step.
8677  *  \param [in] order - the iteration order number of required time step.
8678  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8679  *  \param [in] renumPol - specifies how to permute values of the result field according to
8680  *          the optional numbers of cells and nodes, if any. The valid values are
8681  *          - 0 - do not permute.
8682  *          - 1 - permute cells.
8683  *          - 2 - permute nodes.
8684  *          - 3 - permute cells and nodes.
8685  *
8686  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8687  *          caller is to delete this field using decrRef() as it is no more needed. 
8688  *  \throw If the MED file is not readable.
8689  *  \throw If there is no mesh in the MED file.
8690  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8691  *  \throw If no field values of the required parameters are available.
8692  */
8693 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
8694 {
8695   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8696   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8697   if(!myF1TSC)
8698     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
8699   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8700   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8701   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8702   return ret.retn();
8703 }
8704
8705 /*!
8706  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8707  * the top level cells of the first mesh in MED file.
8708  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8709  *  \param [in] type - a spatial discretization of interest.
8710  *  \param [in] iteration - the iteration number of a required time step.
8711  *  \param [in] order - the iteration order number of required time step.
8712  *  \param [in] renumPol - specifies how to permute values of the result field according to
8713  *          the optional numbers of cells and nodes, if any. The valid values are
8714  *          - 0 - do not permute.
8715  *          - 1 - permute cells.
8716  *          - 2 - permute nodes.
8717  *          - 3 - permute cells and nodes.
8718  *
8719  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8720  *          caller is to delete this field using decrRef() as it is no more needed. 
8721  *  \throw If the MED file is not readable.
8722  *  \throw If there is no mesh in the MED file.
8723  *  \throw If no field values of the required parameters are available.
8724  */
8725 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
8726 {
8727   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8728   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8729   if(!myF1TSC)
8730     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
8731   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8732   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
8733   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8734   return ret.retn();
8735 }
8736
8737 /*!
8738  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
8739  * a given support.
8740  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8741  *  \param [in] type - a spatial discretization of interest.
8742  *  \param [in] iteration - the iteration number of a required time step.
8743  *  \param [in] order - the iteration order number of required time step.
8744  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8745  *  \param [in] mesh - the supporting mesh.
8746  *  \param [in] renumPol - specifies how to permute values of the result field according to
8747  *          the optional numbers of cells and nodes, if any. The valid values are
8748  *          - 0 - do not permute.
8749  *          - 1 - permute cells.
8750  *          - 2 - permute nodes.
8751  *          - 3 - permute cells and nodes.
8752  *
8753  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8754  *          caller is to delete this field using decrRef() as it is no more needed. 
8755  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
8756  *  \throw If no field of \a this is lying on \a mesh.
8757  *  \throw If no field values of the required parameters are available.
8758  */
8759 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
8760 {
8761   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8762   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8763   if(!myF1TSC)
8764     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8765   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8766   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
8767   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8768   return ret.retn();
8769 }
8770
8771 /*!
8772  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
8773  * given support. 
8774  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8775  *  \param [in] type - a spatial discretization of the new field.
8776  *  \param [in] iteration - the iteration number of a required time step.
8777  *  \param [in] order - the iteration order number of required time step.
8778  *  \param [in] mesh - the supporting mesh.
8779  *  \param [in] renumPol - specifies how to permute values of the result field according to
8780  *          the optional numbers of cells and nodes, if any. The valid values are
8781  *          - 0 - do not permute.
8782  *          - 1 - permute cells.
8783  *          - 2 - permute nodes.
8784  *          - 3 - permute cells and nodes.
8785  *
8786  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
8787  *          caller is to delete this field using decrRef() as it is no more needed. 
8788  *  \throw If no field of \a this is lying on \a mesh.
8789  *  \throw If no field values of the required parameters are available.
8790  */
8791 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
8792 {
8793   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8794   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8795   if(!myF1TSC)
8796     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
8797   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8798   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
8799   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8800   return ret.retn();
8801 }
8802
8803 /*!
8804  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
8805  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
8806  * This method is useful for MED2 file format when field on different mesh was autorized.
8807  */
8808 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
8809 {
8810   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8811   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8812   if(!myF1TSC)
8813     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
8814   MEDCouplingAutoRefCountObjectPtr<DataArray> arrOut;
8815   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
8816   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
8817   return ret.retn();
8818 }
8819
8820 /*!
8821  * Returns values and a profile of the field of a given type, of a given time step,
8822  * lying on a given support.
8823  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8824  *  \param [in] type - a spatial discretization of the field.
8825  *  \param [in] iteration - the iteration number of a required time step.
8826  *  \param [in] order - the iteration order number of required time step.
8827  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
8828  *  \param [in] mesh - the supporting mesh.
8829  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
8830  *          field of interest lies on. If the field lies on all entities of the given
8831  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
8832  *          using decrRef() as it is no more needed.  
8833  *  \param [in] glob - the global data storing profiles and localization.
8834  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
8835  *          field. The caller is to delete this array using decrRef() as it is no more needed.
8836  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8837  *  \throw If no field of \a this is lying on \a mesh.
8838  *  \throw If no field values of the required parameters are available.
8839  */
8840 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
8841 {
8842   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
8843   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8844   if(!myF1TSC)
8845     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
8846   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
8847   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
8848 }
8849
8850 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
8851 {
8852   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8853   if(!pt)
8854     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
8855   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
8856   if(!ret)
8857     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 !");
8858   return ret;
8859 }
8860
8861 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
8862 {
8863   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
8864   if(!pt)
8865     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
8866   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
8867   if(!ret)
8868     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 !");
8869   return ret;
8870 }
8871
8872 /*!
8873  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
8874  * the given field is checked if its elements are sorted suitable for writing to MED file
8875  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
8876  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8877  *  \param [in] field - the field to add to \a this.
8878  *  \throw If the name of \a field is empty.
8879  *  \throw If the data array of \a field is not set.
8880  *  \throw If existing time steps have different name or number of components than \a field.
8881  *  \throw If the underlying mesh of \a field has no name.
8882  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
8883  */
8884 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
8885 {
8886   const DataArrayDouble *arr=0;
8887   if(field)
8888     arr=field->getArray();
8889   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
8890 }
8891
8892 /*!
8893  * Adds a MEDCouplingFieldDouble to \a this as another time step.
8894  * The mesh support of input parameter \a field is ignored here, it can be NULL.
8895  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
8896  * and \a profile.
8897  *
8898  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
8899  * A new profile is added only if no equal profile is missing.
8900  * For more info, see \ref AdvMEDLoaderAPIFieldRW
8901  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
8902  *  \param [in] mesh - the supporting mesh of \a field.
8903  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
8904  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
8905  *  \throw If either \a field or \a mesh or \a profile has an empty name.
8906  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
8907  *  \throw If the data array of \a field is not set.
8908  *  \throw If the data array of \a this is already allocated but has different number of
8909  *         components than \a field.
8910  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
8911  *  \sa setFieldNoProfileSBT()
8912  */
8913 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
8914 {
8915   const DataArrayDouble *arr=0;
8916   if(field)
8917     arr=field->getArray();
8918   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
8919 }
8920
8921 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
8922 {
8923   _content=new MEDFileFieldMultiTSWithoutSDA;
8924 }
8925
8926 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, bool loadAll)
8927 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
8928 {
8929 }
8930 catch(INTERP_KERNEL::Exception& e)
8931 { throw e; }
8932
8933 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll)
8934 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
8935 {
8936 }
8937 catch(INTERP_KERNEL::Exception& e)
8938 { throw e; }
8939
8940 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
8941 {
8942 }
8943
8944 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
8945 {
8946   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
8947 }
8948
8949 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
8950 {
8951   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
8952 }
8953
8954 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
8955 {
8956   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
8957 }
8958
8959 //= MEDFileAnyTypeFieldMultiTSIterator
8960
8961 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
8962 {
8963   if(fmts)
8964     {
8965       fmts->incrRef();
8966       _nb_iter=fmts->getNumberOfTS();
8967     }
8968 }
8969
8970 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
8971 {
8972 }
8973
8974 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
8975 {
8976   if(_iter_id<_nb_iter)
8977     {
8978       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
8979       if(fmts)
8980         return fmts->getTimeStepAtPos(_iter_id++);
8981       else
8982         return 0;
8983     }
8984   else
8985     return 0;
8986 }
8987
8988 //= MEDFileIntFieldMultiTS
8989
8990 /*!
8991  * Returns a new empty instance of MEDFileFieldMultiTS.
8992  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
8993  *          is to delete this field using decrRef() as it is no more needed.
8994  */
8995 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
8996 {
8997   return new MEDFileIntFieldMultiTS;
8998 }
8999
9000 /*!
9001  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9002  * that has been read from a specified MED file.
9003  *  \param [in] fileName - the name of the MED file to read.
9004  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9005  *          is to delete this field using decrRef() as it is no more needed.
9006  *  \throw If reading the file fails.
9007  */
9008 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9009 {
9010   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,loadAll);
9011   ret->contentNotNull();//to check that content type matches with \a this type.
9012   return ret.retn();
9013 }
9014
9015 /*!
9016  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9017  * that has been read from a specified MED file.
9018  *  \param [in] fileName - the name of the MED file to read.
9019  *  \param [in] fieldName - the name of the field to read.
9020  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9021  *          is to delete this field using decrRef() as it is no more needed.
9022  *  \throw If reading the file fails.
9023  *  \throw If there is no field named \a fieldName in the file.
9024  */
9025 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9026 {
9027   MEDCouplingAutoRefCountObjectPtr<MEDFileIntFieldMultiTS> ret=new MEDFileIntFieldMultiTS(fileName,fieldName,loadAll);
9028   ret->contentNotNull();//to check that content type matches with \a this type.
9029   return ret.retn();
9030 }
9031
9032 /*!
9033  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9034  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9035  *
9036  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9037  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9038  * \warning this is a shallow copy constructor
9039  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9040  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9041  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9042  *          is to delete this field using decrRef() as it is no more needed.
9043  */
9044 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9045 {
9046   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9047 }
9048
9049 /*!
9050  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9051  * following the given input policy.
9052  *
9053  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9054  *                            By default (true) the globals are deeply copied.
9055  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9056  */
9057 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9058 {
9059   MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTS> ret;
9060   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9061   if(content)
9062     {
9063       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9064       if(!contc)
9065         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9066       MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9067       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName()));
9068     }
9069   else
9070     ret=MEDFileFieldMultiTS::New();
9071   if(isDeepCpyGlobs)
9072     ret->deepCpyGlobs(*this);
9073   else
9074     ret->shallowCpyGlobs(*this);
9075   return ret.retn();
9076 }
9077
9078 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9079 {
9080   return new MEDFileIntFieldMultiTS(*this);
9081 }
9082
9083 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9084 {
9085   if(!f1ts)
9086     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9087   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9088   if(!f1tsC)
9089     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9090 }
9091
9092 /*!
9093  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9094  * mesh entities of a given dimension of the first mesh in MED file.
9095  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9096  *  \param [in] type - a spatial discretization of interest.
9097  *  \param [in] iteration - the iteration number of a required time step.
9098  *  \param [in] order - the iteration order number of required time step.
9099  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9100  *  \param [out] arrOut - the DataArrayInt containing values of field.
9101  *  \param [in] renumPol - specifies how to permute values of the result field according to
9102  *          the optional numbers of cells and nodes, if any. The valid values are
9103  *          - 0 - do not permute.
9104  *          - 1 - permute cells.
9105  *          - 2 - permute nodes.
9106  *          - 3 - permute cells and nodes.
9107  *
9108  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9109  *          caller is to delete this field using decrRef() as it is no more needed. 
9110  *  \throw If the MED file is not readable.
9111  *  \throw If there is no mesh in the MED file.
9112  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9113  *  \throw If no field values of the required parameters are available.
9114  */
9115 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9116 {
9117   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9118   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9119   if(!myF1TSC)
9120     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9121   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9122   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase());
9123   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9124   return ret.retn();
9125 }
9126
9127 /*!
9128  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9129  * the top level cells of the first mesh in MED file.
9130  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9131  *  \param [in] type - a spatial discretization of interest.
9132  *  \param [in] iteration - the iteration number of a required time step.
9133  *  \param [in] order - the iteration order number of required time step.
9134  *  \param [out] arrOut - the DataArrayInt containing values of field.
9135  *  \param [in] renumPol - specifies how to permute values of the result field according to
9136  *          the optional numbers of cells and nodes, if any. The valid values are
9137  *          - 0 - do not permute.
9138  *          - 1 - permute cells.
9139  *          - 2 - permute nodes.
9140  *          - 3 - permute cells and nodes.
9141  *
9142  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9143  *          caller is to delete this field using decrRef() as it is no more needed. 
9144  *  \throw If the MED file is not readable.
9145  *  \throw If there is no mesh in the MED file.
9146  *  \throw If no field values of the required parameters are available.
9147  */
9148 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol) const
9149 {
9150   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9151   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9152   if(!myF1TSC)
9153     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9154   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9155   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase());
9156   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9157   return ret.retn();
9158 }
9159
9160 /*!
9161  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9162  * a given support.
9163  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9164  *  \param [in] type - a spatial discretization of interest.
9165  *  \param [in] iteration - the iteration number of a required time step.
9166  *  \param [in] order - the iteration order number of required time step.
9167  *  \param [out] arrOut - the DataArrayInt containing values of field.
9168  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9169  *  \param [in] mesh - the supporting mesh.
9170  *  \param [in] renumPol - specifies how to permute values of the result field according to
9171  *          the optional numbers of cells and nodes, if any. The valid values are
9172  *          - 0 - do not permute.
9173  *          - 1 - permute cells.
9174  *          - 2 - permute nodes.
9175  *          - 3 - permute cells and nodes.
9176  *
9177  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9178  *          caller is to delete this field using decrRef() as it is no more needed. 
9179  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9180  *  \throw If no field of \a this is lying on \a mesh.
9181  *  \throw If no field values of the required parameters are available.
9182  */
9183 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9184 {
9185   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9186   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9187   if(!myF1TSC)
9188     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9189   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9190   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase());
9191   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9192   return ret.retn();
9193 }
9194
9195 /*!
9196  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9197  * given support. 
9198  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9199  *  \param [in] type - a spatial discretization of the new field.
9200  *  \param [in] iteration - the iteration number of a required time step.
9201  *  \param [in] order - the iteration order number of required time step.
9202  *  \param [in] mesh - the supporting mesh.
9203  *  \param [out] arrOut - the DataArrayInt containing values of field.
9204  *  \param [in] renumPol - specifies how to permute values of the result field according to
9205  *          the optional numbers of cells and nodes, if any. The valid values are
9206  *          - 0 - do not permute.
9207  *          - 1 - permute cells.
9208  *          - 2 - permute nodes.
9209  *          - 3 - permute cells and nodes.
9210  *
9211  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9212  *          caller is to delete this field using decrRef() as it is no more needed. 
9213  *  \throw If no field of \a this is lying on \a mesh.
9214  *  \throw If no field values of the required parameters are available.
9215  */
9216 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, DataArrayInt* &arrOut, int renumPol) const
9217 {
9218   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9219   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9220   if(!myF1TSC)
9221     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9222   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9223   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase());
9224   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9225   return ret.retn();
9226 }
9227
9228 /*!
9229  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9230  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9231  * This method is useful for MED2 file format when field on different mesh was autorized.
9232  */
9233 MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const
9234 {
9235   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9236   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9237   if(!myF1TSC)
9238     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9239   MEDCouplingAutoRefCountObjectPtr<DataArray> arr;
9240   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase());
9241   arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
9242   return ret.retn();
9243 }
9244
9245 /*!
9246  * Returns values and a profile of the field of a given type, of a given time step,
9247  * lying on a given support.
9248  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9249  *  \param [in] type - a spatial discretization of the field.
9250  *  \param [in] iteration - the iteration number of a required time step.
9251  *  \param [in] order - the iteration order number of required time step.
9252  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9253  *  \param [in] mesh - the supporting mesh.
9254  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9255  *          field of interest lies on. If the field lies on all entities of the given
9256  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9257  *          using decrRef() as it is no more needed.  
9258  *  \param [in] glob - the global data storing profiles and localization.
9259  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9260  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9261  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9262  *  \throw If no field of \a this is lying on \a mesh.
9263  *  \throw If no field values of the required parameters are available.
9264  */
9265 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9266 {
9267   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9268   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9269   if(!myF1TSC)
9270     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9271   MEDCouplingAutoRefCountObjectPtr<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9272   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9273 }
9274
9275 /*!
9276  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9277  *  \param [in] pos - a time step id.
9278  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
9279  *          delete this field using decrRef() as it is no more needed.
9280  *  \throw If \a pos is not a valid time step id.
9281  */
9282 MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
9283 {
9284   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9285   if(!item)
9286     {
9287       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9288       throw INTERP_KERNEL::Exception(oss.str().c_str());
9289     }
9290   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
9291   if(itemC)
9292     {
9293       MEDCouplingAutoRefCountObjectPtr<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
9294       ret->shallowCpyGlobs(*this);
9295       return ret.retn();
9296     }
9297   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
9298   throw INTERP_KERNEL::Exception(oss.str().c_str());
9299 }
9300
9301 /*!
9302  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9303  * the given field is checked if its elements are sorted suitable for writing to MED file
9304  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9305  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9306  *  \param [in] field - the field to add to \a this.
9307  *  \throw If the name of \a field is empty.
9308  *  \throw If the data array of \a field is not set.
9309  *  \throw If existing time steps have different name or number of components than \a field.
9310  *  \throw If the underlying mesh of \a field has no name.
9311  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9312  */
9313 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals)
9314 {
9315   contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this);
9316 }
9317
9318 /*!
9319  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
9320  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9321  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9322  * and \a profile.
9323  *
9324  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9325  * A new profile is added only if no equal profile is missing.
9326  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9327  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
9328  *  \param [in] arrOfVals - the values of the field \a field used.
9329  *  \param [in] mesh - the supporting mesh of \a field.
9330  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9331  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9332  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9333  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9334  *  \throw If the data array of \a field is not set.
9335  *  \throw If the data array of \a this is already allocated but has different number of
9336  *         components than \a field.
9337  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9338  *  \sa setFieldNoProfileSBT()
9339  */
9340 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9341 {
9342   contentNotNull()->appendFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this);
9343 }
9344
9345 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
9346 {
9347   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9348   if(!pt)
9349     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
9350   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9351   if(!ret)
9352     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 !");
9353   return ret;
9354 }
9355
9356 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
9357 {
9358   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9359   if(!pt)
9360     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
9361   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
9362   if(!ret)
9363     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 !");
9364   return ret;
9365 }
9366
9367 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
9368 {
9369   _content=new MEDFileIntFieldMultiTSWithoutSDA;
9370 }
9371
9372 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9373 {
9374 }
9375
9376 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, bool loadAll)
9377 try:MEDFileAnyTypeFieldMultiTS(fileName,loadAll)
9378 {
9379 }
9380 catch(INTERP_KERNEL::Exception& e)
9381 { throw e; }
9382
9383 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const std::string& fileName, const std::string& fieldName, bool loadAll)
9384 try:MEDFileAnyTypeFieldMultiTS(fileName,fieldName,loadAll)
9385 {
9386 }
9387 catch(INTERP_KERNEL::Exception& e)
9388 { throw e; }
9389
9390 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9391 {
9392   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9393 }
9394
9395 //= MEDFileFields
9396
9397 MEDFileFields *MEDFileFields::New()
9398 {
9399   return new MEDFileFields;
9400 }
9401
9402 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
9403 {
9404   return new MEDFileFields(fileName,loadAll);
9405 }
9406
9407 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
9408 {
9409   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
9410   ret+=_fields.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
9411   return ret;
9412 }
9413
9414 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildren() const
9415 {
9416   std::vector<const BigMemoryObject *> ret;
9417   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9418     {
9419       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9420       if(cur)
9421         ret.push_back(cur);
9422     }
9423   return ret;
9424 }
9425
9426 MEDFileFields *MEDFileFields::deepCpy() const
9427 {
9428   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9429   std::size_t i=0;
9430   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9431     {
9432       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9433         ret->_fields[i]=(*it)->deepCpy();
9434     }
9435   ret->deepCpyGlobs(*this);
9436   return ret.retn();
9437 }
9438
9439 MEDFileFields *MEDFileFields::shallowCpy() const
9440 {
9441   return new MEDFileFields(*this);
9442 }
9443
9444 /*!
9445  * 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
9446  * 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.
9447  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
9448  *
9449  * \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.
9450  * \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.
9451  * 
9452  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9453  */
9454 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
9455 {
9456   std::set< std::pair<int,int> > s;
9457   bool firstShot=true;
9458   areThereSomeForgottenTS=false;
9459   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9460     {
9461       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
9462         continue;
9463       std::vector< std::pair<int,int> > v=(*it)->getIterations();
9464       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
9465       if(firstShot)
9466         { s=s1; firstShot=false; }
9467       else
9468         {
9469           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
9470           if(s!=s2)
9471             areThereSomeForgottenTS=true;
9472           s=s2;
9473         }
9474     }
9475   std::vector< std::pair<int,int> > ret;
9476   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
9477   return ret;
9478 }
9479
9480 int MEDFileFields::getNumberOfFields() const
9481 {
9482   return _fields.size();
9483 }
9484
9485 std::vector<std::string> MEDFileFields::getFieldsNames() const
9486 {
9487   std::vector<std::string> ret(_fields.size());
9488   int i=0;
9489   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9490     {
9491       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
9492       if(f)
9493         {
9494           ret[i]=f->getName();
9495         }
9496       else
9497         {
9498           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
9499           throw INTERP_KERNEL::Exception(oss.str().c_str());
9500         }
9501     }
9502   return ret;
9503 }
9504
9505 std::vector<std::string> MEDFileFields::getMeshesNames() const
9506 {
9507   std::vector<std::string> ret;
9508   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9509     {
9510       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9511       if(cur)
9512         ret.push_back(cur->getMeshName());
9513     }
9514   return ret;
9515 }
9516
9517 std::string MEDFileFields::simpleRepr() const
9518 {
9519   std::ostringstream oss;
9520   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
9521   simpleRepr(0,oss);
9522   return oss.str();
9523 }
9524
9525 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
9526 {
9527   int nbOfFields=getNumberOfFields();
9528   std::string startLine(bkOffset,' ');
9529   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
9530   int i=0;
9531   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9532     {
9533       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9534       if(cur)
9535         {
9536           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
9537         }
9538       else
9539         {
9540           oss << startLine << "  - not defined !" << std::endl;
9541         }
9542     }
9543   i=0;
9544   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9545     {
9546       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9547       std::string chapter(17,'0'+i);
9548       oss << startLine << chapter << std::endl;
9549       if(cur)
9550         {
9551           cur->simpleRepr(bkOffset+2,oss,i);
9552         }
9553       else
9554         {
9555           oss << startLine << "  - not defined !" << std::endl;
9556         }
9557       oss << startLine << chapter << std::endl;
9558     }
9559   simpleReprGlobs(oss);
9560 }
9561
9562 MEDFileFields::MEDFileFields()
9563 {
9564 }
9565
9566 MEDFileFields::MEDFileFields(const std::string& fileName, bool loadAll)
9567 try:MEDFileFieldGlobsReal(fileName)
9568 {
9569   MEDFileUtilities::CheckFileForRead(fileName);
9570   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
9571   int nbFields=MEDnField(fid);
9572   _fields.resize(nbFields);
9573   med_field_type typcha;
9574   for(int i=0;i<nbFields;i++)
9575     {
9576       std::vector<std::string> infos;
9577       std::string fieldName,dtunit;
9578       int nbOfStep=MEDFileAnyTypeField1TS::LocateField2(fid,fileName,i,false,fieldName,typcha,infos,dtunit);
9579       switch(typcha)
9580       {
9581         case MED_FLOAT64:
9582           {
9583             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9584             break;
9585           }
9586         case MED_INT32:
9587           {
9588             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll);
9589             break;
9590           }
9591         default:
9592           {
9593             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] !";
9594             throw INTERP_KERNEL::Exception(oss.str().c_str());
9595           }
9596       }
9597     }
9598   loadAllGlobals(fid);
9599 }
9600 catch(INTERP_KERNEL::Exception& e)
9601 {
9602     throw e;
9603 }
9604
9605 void MEDFileFields::writeLL(med_idt fid) const
9606 {
9607   int i=0;
9608   writeGlobals(fid,*this);
9609   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
9610     {
9611       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
9612       if(!elt)
9613         {
9614           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
9615           throw INTERP_KERNEL::Exception(oss.str().c_str());
9616         }
9617       elt->writeLL(fid,*this);
9618     }
9619 }
9620
9621 void MEDFileFields::write(const std::string& fileName, int mode) const
9622 {
9623   med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
9624   MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),medmod));
9625   writeLL(fid);
9626 }
9627
9628 /*!
9629  * This method alloc the arrays and load potentially huge arrays contained in this field.
9630  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9631  * This method can be also called to refresh or reinit values from a file.
9632  * 
9633  * \throw If the fileName is not set or points to a non readable MED file.
9634  */
9635 void MEDFileFields::loadArrays()
9636 {
9637   if(getFileName().empty())
9638     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
9639   MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9640   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9641     {
9642       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9643       if(elt)
9644         elt->loadBigArraysRecursively(fid,*elt);
9645     }
9646 }
9647
9648 /*!
9649  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9650  * But once data loaded once, this method does nothing.
9651  * 
9652  * \throw If the fileName is not set or points to a non readable MED file.
9653  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
9654  */
9655 void MEDFileFields::loadArraysIfNecessary()
9656 {
9657   if(!getFileName().empty())
9658     {
9659       MEDFileUtilities::AutoFid fid=MEDfileOpen(getFileName().c_str(),MED_ACC_RDONLY);
9660       for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9661         {
9662           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9663           if(elt)
9664             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
9665         }
9666     }
9667 }
9668
9669 /*!
9670  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9671  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9672  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
9673  * 
9674  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
9675  */
9676 void MEDFileFields::unloadArrays()
9677 {
9678   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9679     {
9680       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9681       if(elt)
9682         elt->unloadArrays();
9683     }
9684 }
9685
9686 /*!
9687  * 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.
9688  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
9689  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9690  * 
9691  * \sa MEDFileFields::loadArraysIfNecessary
9692  */
9693 void MEDFileFields::unloadArraysWithoutDataLoss()
9694 {
9695   if(!getFileName().empty())
9696     unloadArrays();
9697 }
9698
9699 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
9700 {
9701   std::vector<std::string> ret;
9702   std::set<std::string> ret2;
9703   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9704     {
9705       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
9706       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9707         if(ret2.find(*it2)==ret2.end())
9708           {
9709             ret.push_back(*it2);
9710             ret2.insert(*it2);
9711           }
9712     }
9713   return ret;
9714 }
9715
9716 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
9717 {
9718   std::vector<std::string> ret;
9719   std::set<std::string> ret2;
9720   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9721     {
9722       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9723       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
9724         if(ret2.find(*it2)==ret2.end())
9725           {
9726             ret.push_back(*it2);
9727             ret2.insert(*it2);
9728           }
9729     }
9730   return ret;
9731 }
9732
9733 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
9734 {
9735   std::vector<std::string> ret;
9736   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9737     {
9738       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
9739       ret.insert(ret.end(),tmp.begin(),tmp.end());
9740     }
9741   return ret;
9742 }
9743
9744 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
9745 {
9746   std::vector<std::string> ret;
9747   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9748     {
9749       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
9750       ret.insert(ret.end(),tmp.begin(),tmp.end());
9751     }
9752   return ret;
9753 }
9754
9755 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9756 {
9757   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9758     (*it)->changePflsRefsNamesGen2(mapOfModif);
9759 }
9760
9761 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
9762 {
9763   for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
9764     (*it)->changeLocsRefsNamesGen2(mapOfModif);
9765 }
9766
9767 void MEDFileFields::resize(int newSize)
9768 {
9769   _fields.resize(newSize);
9770 }
9771
9772 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
9773 {
9774   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
9775     pushField(*it);
9776 }
9777
9778 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
9779 {
9780   if(!field)
9781     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
9782   _fields.push_back(field->getContent());
9783   appendGlobs(*field,1e-12);
9784 }
9785
9786 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
9787 {
9788   if(!field)
9789     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
9790   if(i>=(int)_fields.size())
9791     _fields.resize(i+1);
9792   _fields[i]=field->getContent();
9793   appendGlobs(*field,1e-12);
9794 }
9795
9796 void MEDFileFields::destroyFieldAtPos(int i)
9797 {
9798   destroyFieldsAtPos(&i,&i+1);
9799 }
9800
9801 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
9802 {
9803   std::vector<bool> b(_fields.size(),true);
9804   for(const int *i=startIds;i!=endIds;i++)
9805     {
9806       if(*i<0 || *i>=(int)_fields.size())
9807         {
9808           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9809           throw INTERP_KERNEL::Exception(oss.str().c_str());
9810         }
9811       b[*i]=false;
9812     }
9813   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9814   std::size_t j=0;
9815   for(std::size_t i=0;i<_fields.size();i++)
9816     if(b[i])
9817       fields[j++]=_fields[i];
9818   _fields=fields;
9819 }
9820
9821 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
9822 {
9823   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
9824   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
9825   std::vector<bool> b(_fields.size(),true);
9826   int k=bg;
9827   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
9828     {
9829       if(k<0 || k>=(int)_fields.size())
9830         {
9831           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
9832           throw INTERP_KERNEL::Exception(oss.str().c_str());
9833         }
9834       b[k]=false;
9835     }
9836   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
9837   std::size_t j=0;
9838   for(std::size_t i=0;i<_fields.size();i++)
9839     if(b[i])
9840       fields[j++]=_fields[i];
9841   _fields=fields;
9842 }
9843
9844 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9845 {
9846   bool ret=false;
9847   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9848     {
9849       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
9850       if(cur)
9851         ret=cur->changeMeshNames(modifTab) || ret;
9852     }
9853   return ret;
9854 }
9855
9856 /*!
9857  * \param [in] meshName the name of the mesh that will be renumbered.
9858  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
9859  *             This code corresponds to the distribution of types in the corresponding mesh.
9860  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
9861  * \param [in] renumO2N the old to new renumber array.
9862  * \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 
9863  *         field in \a this.
9864  */
9865 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
9866 {
9867   bool ret=false;
9868   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
9869     {
9870       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
9871       if(fmts)
9872         {
9873           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
9874         }
9875     }
9876   return ret;
9877 }
9878
9879 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
9880 {
9881   if(i<0 || i>=(int)_fields.size())
9882     {
9883       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
9884       throw INTERP_KERNEL::Exception(oss.str().c_str());
9885     }
9886   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
9887   if(!fmts)
9888     return 0;
9889   MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> ret;
9890   const MEDFileFieldMultiTSWithoutSDA *fmtsC=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts);
9891   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts);
9892   if(fmtsC)
9893     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
9894   else if(fmtsC2)
9895     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
9896   else
9897     {
9898       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
9899       throw INTERP_KERNEL::Exception(oss.str().c_str());
9900     }
9901   ret->shallowCpyGlobs(*this);
9902   return ret.retn();
9903 }
9904
9905 /*!
9906  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
9907  * This method is accessible in python using __getitem__ with a list in input.
9908  * \return a new object that the caller should deal with.
9909  */
9910 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
9911 {
9912   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=shallowCpy();
9913   std::size_t sz=std::distance(startIds,endIds);
9914   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
9915   int j=0;
9916   for(const int *i=startIds;i!=endIds;i++,j++)
9917     {
9918       if(*i<0 || *i>=(int)_fields.size())
9919         {
9920           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
9921           throw INTERP_KERNEL::Exception(oss.str().c_str());
9922         }
9923       fields[j]=_fields[*i];
9924     }
9925   ret->_fields=fields;
9926   return ret.retn();
9927 }
9928
9929 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
9930 {
9931   return getFieldAtPos(getPosFromFieldName(fieldName));
9932 }
9933
9934 /*!
9935  * This method removes, if any, fields in \a this having no time steps.
9936  * 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.
9937  * 
9938  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
9939  */
9940 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
9941 {
9942   std::vector<MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
9943   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9944     {
9945       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
9946       if(elt)
9947         {
9948           if(elt->getNumberOfTS()>0)
9949             newFields.push_back(*it);
9950         }
9951     }
9952   if(_fields.size()==newFields.size())
9953     return false;
9954   _fields=newFields;
9955   return true;
9956 }
9957
9958 /*!
9959  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
9960  * This method can be seen as a filter applied on \a this, that returns an object containing
9961  * 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
9962  * shallow copied from \a this.
9963  * 
9964  * \param [in] meshName - the name of the mesh on w
9965  * \return a new object that the caller should deal with.
9966  */
9967 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
9968 {
9969   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
9970   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
9971     {
9972       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
9973       if(!cur)
9974         continue;
9975       if(cur->getMeshName()==meshName)
9976         {
9977           cur->incrRef();
9978           MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
9979           ret->_fields.push_back(cur2);
9980         }
9981     }
9982   ret->shallowCpyOnlyUsedGlobs(*this);
9983   return ret.retn();
9984 }
9985
9986 /*!
9987  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
9988  * Input time steps are specified using a pair of integer (iteration, order).
9989  * 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,
9990  * but for each multitimestep only the time steps in \a timeSteps are kept.
9991  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
9992  * 
9993  * The returned object points to shallow copy of elements in \a this.
9994  * 
9995  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
9996  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
9997  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
9998  */
9999 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10000 {
10001   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10002   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10003     {
10004       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10005       if(!cur)
10006         continue;
10007       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10008       ret->_fields.push_back(elt);
10009     }
10010   ret->shallowCpyOnlyUsedGlobs(*this);
10011   return ret.retn();
10012 }
10013
10014 /*!
10015  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10016  */
10017 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10018 {
10019   MEDCouplingAutoRefCountObjectPtr<MEDFileFields> ret=MEDFileFields::New();
10020   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10021     {
10022       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10023       if(!cur)
10024         continue;
10025       MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10026       if(elt->getNumberOfTS()!=0)
10027         ret->_fields.push_back(elt);
10028     }
10029   ret->shallowCpyOnlyUsedGlobs(*this);
10030   return ret.retn();
10031 }
10032
10033 MEDFileFieldsIterator *MEDFileFields::iterator()
10034 {
10035   return new MEDFileFieldsIterator(this);
10036 }
10037
10038 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10039 {
10040   std::string tmp(fieldName);
10041   std::vector<std::string> poss;
10042   for(std::size_t i=0;i<_fields.size();i++)
10043     {
10044       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=_fields[i];
10045       if(f)
10046         {
10047           std::string fname(f->getName());
10048           if(tmp==fname)
10049             return i;
10050           else
10051             poss.push_back(fname);
10052         }
10053     }
10054   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10055   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10056   oss << " !";
10057   throw INTERP_KERNEL::Exception(oss.str().c_str());
10058 }
10059
10060 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10061 {
10062   if(fs)
10063     {
10064       fs->incrRef();
10065       _nb_iter=fs->getNumberOfFields();
10066     }
10067 }
10068
10069 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10070 {
10071 }
10072
10073 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10074 {
10075   if(_iter_id<_nb_iter)
10076     {
10077       MEDFileFields *fs(_fs);
10078       if(fs)
10079         return fs->getFieldAtPos(_iter_id++);
10080       else
10081         return 0;
10082     }
10083   else
10084     return 0;
10085 }