]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileField.cxx
Salome HOME
3f8a7188e45ef1bf0b588af8092a1a53f364ebfb
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2016  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.txx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDLoaderTraits.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileFieldOverView.hxx"
27
28 #include "MEDCouplingFieldDouble.hxx"
29 #include "MEDCouplingFieldTemplate.hxx"
30 #include "MEDCouplingFieldDiscretization.hxx"
31
32 #include "InterpKernelAutoPtr.hxx"
33 #include "CellModel.hxx"
34
35 #include <algorithm>
36 #include <iterator>
37
38 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
39 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
40 extern med_geometry_type typmainoeud[1];
41 extern med_geometry_type typmai3[34];
42
43 using namespace MEDCoupling;
44
45 template class MEDFileField1TSTemplateWithoutSDA<int>;
46 template class MEDFileField1TSTemplateWithoutSDA<double>;
47
48 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
49 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
52 {
53   return new MEDFileFieldLoc(fid,locName);
54 }
55
56 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
57 {
58   return new MEDFileFieldLoc(fid,id);
59 }
60
61 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)
62 {
63   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
64 }
65
66 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
67 {
68   med_geometry_type geotype;
69   med_geometry_type sectiongeotype;
70   int nsectionmeshcell;
71   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
72   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
73   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
74   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
75   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
76   _nb_node_per_cell=cm.getNumberOfNodes();
77   _ref_coo.resize(_dim*_nb_node_per_cell);
78   _gs_coo.resize(_dim*_nb_gauss_pt);
79   _w.resize(_nb_gauss_pt);
80   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
81 }
82
83 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
84 {
85   med_geometry_type geotype;
86   med_geometry_type sectiongeotype;
87   int nsectionmeshcell;
88   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
89   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
90   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
91   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
92   _name=locName;
93   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
94   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
95   _nb_node_per_cell=cm.getNumberOfNodes();
96   _ref_coo.resize(_dim*_nb_node_per_cell);
97   _gs_coo.resize(_dim*_nb_gauss_pt);
98   _w.resize(_nb_gauss_pt);
99   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
100 }
101
102 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
103                                  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),
104                                      _w(w)
105 {
106   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
107   _dim=cm.getDimension();
108   _nb_node_per_cell=cm.getNumberOfNodes();
109   _nb_gauss_pt=_w.size();
110 }
111
112 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
113 {
114   return new MEDFileFieldLoc(*this);
115 }
116
117 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
118 {
119   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
120 }
121
122 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
123 {
124   return std::vector<const BigMemoryObject *>();
125 }
126
127 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
128 {
129   static const char OFF7[]="\n    ";
130   oss << "\"" << _name << "\"" << OFF7;
131   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
132   oss << "Dimension=" << _dim << OFF7;
133   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
134   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
135   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
136   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
137   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
138 }
139
140 void MEDFileFieldLoc::setName(const std::string& name)
141 {
142   _name=name;
143 }
144
145 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
146 {
147   if(_name!=other._name)
148     return false;
149   if(_dim!=other._dim)
150     return false;
151   if(_nb_gauss_pt!=other._nb_gauss_pt)
152     return false;
153   if(_nb_node_per_cell!=other._nb_node_per_cell)
154     return false;
155   if(_geo_type!=other._geo_type)
156     return false;
157   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
158     return false;
159   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
160     return false;
161   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
162     return false;
163
164   return true;
165 }
166
167 void MEDFileFieldLoc::writeLL(med_idt fid) const
168 {
169   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);
170 }
171
172 std::string MEDFileFieldLoc::repr() const
173 {
174   std::ostringstream oss; oss.precision(15);
175   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
176   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
177   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
178   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
179   oss << "\n  - Ref coords are : ";
180   int sz=_ref_coo.size();
181   if(sz%_dim==0)
182     {
183       int nbOfTuples=sz/_dim;
184       for(int i=0;i<nbOfTuples;i++)
185         {
186           oss << "(";
187           for(int j=0;j<_dim;j++)
188             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
189           oss << ") ";
190         }
191     }
192   else
193     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
194   oss << "\n  - Gauss coords in reference element : ";
195   sz=_gs_coo.size();
196   if(sz%_dim==0)
197     {
198       int nbOfTuples=sz/_dim;
199       for(int i=0;i<nbOfTuples;i++)
200         {
201           oss << "(";
202           for(int j=0;j<_dim;j++)
203             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
204           oss << ") ";
205         }
206     }
207   else
208     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
209   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
210   return oss.str();
211 }
212
213 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
214 {
215   _type=field->getTypeOfField();
216   _start=start;
217   switch(_type)
218   {
219     case ON_CELLS:
220       {
221         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
222         _end=_start+nbOfCells;
223         _nval=nbOfCells;
224         break;
225       }
226     case ON_GAUSS_NE:
227       {
228         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
229         const int *arrPtr=arr->getConstPointer();
230         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
231         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
232         _nval=nbOfCells;
233         break;
234       }
235     case ON_GAUSS_PT:
236       {
237         const MEDCouplingFieldDiscretization *disc(field->getDiscretization());
238         const MEDCouplingGaussLocalization& gsLoc(field->getGaussLocalization(_loc_id));
239         const MEDCouplingFieldDiscretizationGauss *disc2(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc));
240         if(!disc2)
241           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
242         const DataArrayInt *dai(disc2->getArrayOfDiscIds());
243         MCAuto<DataArrayInt> dai2(disc2->getOffsetArr(field->getMesh()));
244         const int *dai2Ptr(dai2->getConstPointer());
245         int nbi(gsLoc.getWeights().size());
246         MCAuto<DataArrayInt> da2(dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1));
247         MCAuto<DataArrayInt> da3(da2->findIdsEqual(_loc_id));
248         const int *da3Ptr(da3->getConstPointer());
249         if(da3->getNumberOfTuples()!=nbOfCells)
250           {//profile : for gauss even in NoProfile !!!
251             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
252             _profile=oss.str();
253             da3->setName(_profile.c_str());
254             glob.appendProfile(da3);
255           }
256         MCAuto<DataArrayInt> da4(DataArrayInt::New());
257         _nval=da3->getNbOfElems();
258         da4->alloc(_nval*nbi,1);
259         int *da4Ptr(da4->getPointer());
260         for(int i=0;i<_nval;i++)
261           {
262             int ref=dai2Ptr[offset+da3Ptr[i]];
263             for(int j=0;j<nbi;j++)
264               *da4Ptr++=ref+j;
265           }
266         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
267         _localization=oss2.str();
268         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
269         _end=_start+_nval*nbi;
270         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
271         break;
272       }
273     default:
274       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
275   }
276   start=_end;
277 }
278
279 /*!
280  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
281  * \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).
282  * \param [in] multiTypePfl is the end user profile specified in high level API
283  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
284  * \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.
285  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
286  * \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.
287  */
288 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)
289 {
290   _profile.clear();
291   _type=field->getTypeOfField();
292   std::string pflName(multiTypePfl->getName());
293   std::ostringstream oss; oss << pflName;
294   if(_type!=ON_NODES)
295     {
296       if(!isPflAlone)
297         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
298     }
299   else
300     { oss << "_NODE"; }
301   if(locIds)
302     {
303       if(pflName.empty())
304         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
305       if(_type!=ON_GAUSS_PT)
306         {
307           locIds->setName(oss.str());
308           glob.appendProfile(locIds);
309           _profile=oss.str();
310         }
311     }
312   _start=start;
313   switch(_type)
314   {
315     case ON_NODES:
316       {
317         _nval=idsInPfl->getNumberOfTuples();
318         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
319         _end=_start+_nval;
320         break;
321       }
322     case ON_CELLS:
323       {
324         _nval=idsInPfl->getNumberOfTuples();
325         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
326         _end=_start+_nval;
327         break;
328       }
329     case ON_GAUSS_NE:
330       {
331         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
332         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
333         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
334         arr3->computeOffsetsFull();
335         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
336         int trueNval=tmp->getNumberOfTuples();
337         _nval=idsInPfl->getNumberOfTuples();
338         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
339         _end=_start+trueNval;
340         break;
341       }
342     case ON_GAUSS_PT:
343       {
344         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
345         if(!disc2)
346           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
347         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
348         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
349         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
350         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
351         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
352         //
353         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
354         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
355         //
356         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
357         int trueNval=0;
358         for(const int *pt=da4->begin();pt!=da4->end();pt++)
359           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
360         tmp->alloc(trueNval,1);
361         int *tmpPtr=tmp->getPointer();
362         for(const int *pt=da4->begin();pt!=da4->end();pt++)
363           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
364             *tmpPtr++=j;
365         //
366         _nval=da4->getNumberOfTuples();
367         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
368         _end=_start+trueNval;
369         oss << "_loc_" << _loc_id;
370         if(locIds)
371           {
372             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
373             da5->setName(oss.str());
374             glob.appendProfile(da5);
375             _profile=oss.str();
376           }
377         else
378           {
379             if(!da3->isIota(nbOfEltsInWholeMesh))
380               {
381                 da3->setName(oss.str());
382                 glob.appendProfile(da3);
383                 _profile=oss.str();
384               }
385           }
386         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
387         _localization=oss2.str();
388         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
389         break;
390       }
391     default:
392       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
393   }
394   start=_end;
395 }
396
397 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
398 {
399   _start=start;
400   _nval=arrr->getNumberOfTuples();
401   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
402   _end=_start+_nval;
403   start=_end;
404 }
405
406 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
407 {
408   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
409 }
410
411 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId)
412 {
413   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
414 }
415
416 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
417 {
418   return new MEDFileFieldPerMeshPerTypePerDisc(other);
419 }
420
421 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
422 {
423   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
424 }
425
426 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
427 {
428   std::vector<const BigMemoryObject *> ret(1);
429   ret[0]=(const PartDefinition*)_pd;
430   return ret;
431 }
432
433 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const
434 {
435   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret=new MEDFileFieldPerMeshPerTypePerDisc(*this);
436   ret->_father=father;
437   return ret.retn();
438 }
439
440 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
441 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
442 {
443   if(pd)
444     pd->incrRef();
445 }
446 catch(INTERP_KERNEL::Exception& e)
447 {
448     throw e;
449 }
450
451 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
452 {
453 }
454
455 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_profile_it(other._profile_it),_pd(other._pd),_tmp_work1(other._tmp_work1)
456 {
457 }
458
459 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
460     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
461 {
462 }
463
464 void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const std::string& fieldName, int nbOfCompo, int iteration, int order, med_entity_type menti, med_geometry_type mgeoti, unsigned char *startFeedingPtr)
465 {
466   const PartDefinition *pd(_pd);
467   if(!pd)
468     {
469       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
470       int nbi,tmp1;
471       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
472       if(_end-_start!=nbValsInFile*nbi)
473         {
474           std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
475           throw INTERP_KERNEL::Exception(oss.str());
476         }
477       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
478     }
479   else
480     {
481       if(!_profile.empty())
482         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
483       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
484       int profilesize,nbi;
485       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
486       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
487       if(spd)
488         {
489           int start,stop,step;
490           spd->getSlice(start,stop,step);
491           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
492           med_filter filter=MED_FILTER_INIT;
493           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
494                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
495                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
496                                    /*lastblocksize=useless because count=1*/0,&filter);
497           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
498           MEDfilterClose(&filter);
499           return ;
500         }
501       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
502       if(dpd)
503         {
504           dpd->checkConsistencyLight();
505           MCAuto<DataArrayInt> myIds(dpd->toDAI());
506           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
507           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
508           myIds->applyLin(1,-a);
509           int nbOfEltsToLoad(b-a+1);
510           med_filter filter=MED_FILTER_INIT;
511           {//TODO : manage int32 !
512             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
513             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
514             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
515                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
516                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
517                                      /*lastblocksize=useless because count=1*/0,&filter);
518             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
519             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
520             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
521             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
522           }
523           MEDfilterClose(&filter);
524         }
525       else
526         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
527     }
528 }
529
530 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
531 {
532   return _father;
533 }
534
535 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
536 {
537   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
538   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
539   std::string fieldName(nasc.getName()),meshName(getMeshName());
540   int iteration(getIteration()),order(getOrder());
541   TypeOfField type(getType());
542   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
543   int profilesize,nbi;
544   med_geometry_type mgeoti;
545   med_entity_type menti(MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(type,geoType,mgeoti));
546   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
547   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
548   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
549   const PartDefinition *pd(_pd);
550   if(!pd)
551     {
552       _nval=zeNVal;
553     }
554   else
555     {
556       if(!_profile.empty())
557         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
558       _nval=pd->getNumberOfElems();
559     }
560   _start=start;
561   _end=start+_nval*nbi;
562   start=_end;
563   if(type==ON_CELLS && !_localization.empty())
564     {
565       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
566         setType(ON_GAUSS_PT);
567       else
568         {
569           setType(ON_GAUSS_NE);
570           _localization.clear();
571         }
572     }
573 }
574
575 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
576 {
577   std::string fieldName(nasc.getName()),meshName(getMeshName());
578   int iteration(getIteration()),order(getOrder());
579   TypeOfField type(getType());
580   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
581   med_geometry_type mgeoti;
582   med_entity_type menti(MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(type,geoType,mgeoti));
583   if(_start>_end)
584     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
585   if(_start==_end)
586     return ;
587   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
588   if(_start<0 || _start>=arr->getNumberOfTuples())
589     {
590       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
591       throw INTERP_KERNEL::Exception(oss.str());
592     }
593   if(_end<0 || _end>arr->getNumberOfTuples())
594     {
595       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
596       throw INTERP_KERNEL::Exception(oss.str());
597     }
598   int nbOfCompo(arr->getNumberOfComponents());
599   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
600   if(arrD)
601     {
602       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
603       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
604       return ;
605     }
606   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
607   if(arrI)
608     {
609       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
610       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
611       return ;
612     }
613   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
614 }
615
616 /*!
617  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
618  */
619 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
620 {
621   int delta=_end-_start;
622   _start=newValueOfStart;
623   _end=_start+delta;
624 }
625
626 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
627 {
628   return _father->getIteration();
629 }
630
631 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
632 {
633   return _father->getOrder();
634 }
635
636 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
637 {
638   return _father->getTime();
639 }
640
641 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
642 {
643   return _father->getMeshName();
644 }
645
646 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
647 {
648   const char startLine[]="    ## ";
649   std::string startLine2(bkOffset,' ');
650   startLine2+=startLine;
651   MEDCouplingFieldDiscretization *tmp=MEDCouplingFieldDiscretization::New(_type);
652   oss << startLine2 << "Localization #" << id << "." << std::endl;
653   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
654   delete tmp;
655   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
656   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
657   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
658 }
659
660 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
661 {
662   return _type;
663 }
664
665 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
666 {
667   return _father->getGeoType();
668 }
669
670 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
671 {
672   types.insert(_type);
673 }
674
675 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
676 {
677   _type=newType;
678 }
679
680 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
681 {
682   return _father->getNumberOfComponents();
683 }
684
685 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
686 {
687   return _end-_start;
688 }
689
690 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
691 {
692   return _father->getOrCreateAndGetArray();
693 }
694
695 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
696 {
697   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
698   return fath->getOrCreateAndGetArray();
699 }
700
701 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
702 {
703   return _father->getInfo();
704 }
705
706 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
707 {
708   return _profile;
709 }
710
711 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
712 {
713   _profile=newPflName;
714 }
715
716 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
717 {
718   return _localization;
719 }
720
721 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
722 {
723   _localization=newLocName;
724 }
725
726 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
727 {
728   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
729     {
730       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
731         {
732           _profile=(*it2).second;
733           return;
734         }
735     }
736 }
737
738 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
739 {
740   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
741     {
742       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
743         {
744           _localization=(*it2).second;
745           return;
746         }
747     }
748 }
749
750 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
751 {
752   if(type!=_type)
753     return ;
754   dads.push_back(std::pair<int,int>(_start,_end));
755   geoTypes.push_back(getGeoType());
756   if(_profile.empty())
757     pfls.push_back(0);
758   else
759     {
760       pfls.push_back(glob->getProfile(_profile.c_str()));
761     }
762   if(_localization.empty())
763     locs.push_back(-1);
764   else
765     {
766       locs.push_back(glob->getLocalizationId(_localization.c_str()));
767     }
768 }
769
770 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
771 {
772   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));
773   startEntryId++;
774 }
775
776 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
777 {
778   TypeOfField type=getType();
779   INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
780   med_geometry_type mgeoti;
781   med_entity_type menti=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(type,geoType,mgeoti);
782   const DataArray *arr=getOrCreateAndGetArray();
783   if(!arr)
784     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
785   if(!arr->isAllocated())
786     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
787   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
788   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
789   const unsigned char *locToWrite=0;
790   if(arrD)
791     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
792   else if(arrI)
793     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
794   else
795     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
796   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
797                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
798                                                    locToWrite));
799 }
800
801 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
802 {
803   type=_type;
804   pfl=_profile;
805   loc=_localization;
806   dad.first=_start; dad.second=_end;
807 }
808
809 /*!
810  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
811  *             This code corresponds to the distribution of types in the corresponding mesh.
812  * \param [out] ptToFill memory zone where the output will be stored.
813  * \return the size of data pushed into output param \a ptToFill
814  */
815 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
816 {
817   _loc_id=offset;
818   std::ostringstream oss;
819   std::size_t nbOfType=codeOfMesh.size()/3;
820   int found=-1;
821   for(std::size_t i=0;i<nbOfType && found==-1;i++)
822     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
823       found=(int)i;
824   if(found==-1)
825     {
826       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
827       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
828       throw INTERP_KERNEL::Exception(oss.str());
829     }
830   int *work=ptToFill;
831   if(_profile.empty())
832     {
833       if(_nval!=codeOfMesh[3*found+1])
834         {
835           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
836           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
837           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
838           throw INTERP_KERNEL::Exception(oss.str());
839         }
840       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
841         *work++=ii;
842     }
843   else
844     {
845       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
846       if(pfl->getNumberOfTuples()!=_nval)
847         {
848           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
849           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
850           oss << _nval;
851           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
852           throw INTERP_KERNEL::Exception(oss.str());
853         }
854       int offset2=codeOfMesh[3*found+2];
855       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
856         {
857           if(*pflId<codeOfMesh[3*found+1])
858             *work++=offset2+*pflId;
859         }
860     }
861   return _nval;
862 }
863
864 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
865 {
866   for(int i=_start;i<_end;i++)
867     *ptToFill++=i;
868   return _end-_start;
869 }
870
871 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
872 {
873   switch(type)
874   {
875     case ON_CELLS:
876       return -2;
877     case ON_GAUSS_NE:
878       return -1;
879     case ON_GAUSS_PT:
880       return locId;
881     default:
882       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
883   }
884 }
885
886 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
887 {
888   int id=0;
889   std::map<std::pair<std::string,TypeOfField>,int> m;
890   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
891   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
892     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
893       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
894   ret.resize(id);
895   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
896     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
897   return ret;
898 }
899
900 /*!
901  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
902  * 
903  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
904  * \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.
905  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
906  * \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)
907  * \param [in,out] glob if necessary by the method, new profiles can be added to it
908  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
909  * \param [out] result All new entries will be appended on it.
910  * \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 !)
911  */
912 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
913                                                        const DataArrayInt *explicitIdsInMesh,
914                                                        const std::vector<int>& newCode,
915                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
916                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
917 {
918   if(entriesOnSameDisc.empty())
919     return false;
920   TypeOfField type=entriesOnSameDisc[0]->getType();
921   int szEntities=0,szTuples=0;
922   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
923     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
924   int nbi=szTuples/szEntities;
925   if(szTuples%szEntities!=0)
926     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
927   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
928   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
929   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
930   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
931   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
932   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
933   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
934   int id=0;
935   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
936     {
937       int startOfEltIdOfChunk=(*it)->_start;
938       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
939       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
940       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
941       //
942       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
943       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
944       //
945       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
946       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
947     }
948   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
949   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
950   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
951   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
952   //
953   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
954   //
955   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
956   arrPart->renumberInPlace(renumTupleIds->begin());
957   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
958   bool ret=false;
959   const int *idIt=diffVals->begin();
960   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
961   int offset2=0;
962   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
963     {
964       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
965       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
966       int nbEntityElts=subIds->getNumberOfTuples();
967       bool ret2;
968       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
969           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
970                                       offset+offset2,
971                                       li,glob,ret2);
972       ret=ret || ret2;
973       result.push_back(eltToAdd);
974       offset2+=nbEntityElts*nbi;
975     }
976   ret=ret || li.empty();
977   return ret;
978 }
979
980 /*!
981  * \param [in] typeF type of field of new chunk
982  * \param [in] geoType the geometric type of the chunk
983  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
984  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
985  * \param [in] nbi number of integration points
986  * \param [in] offset The offset in the **global array of data**.
987  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
988  *                 to the new chunk to create.
989  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
990  * \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
991  *              and corresponding entry erased from \a entriesOnSameDisc.
992  * \return a newly allocated chunk
993  */
994 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
995                                                                                                   bool isPfl, int nbi, int offset,
996                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
997                                                                                                   MEDFileFieldGlobsReal& glob,
998                                                                                                   bool &notInExisting)
999 {
1000   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1001   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1002   for(;it!=entriesOnSameDisc.end();it++)
1003     {
1004       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1005         {
1006           if(!isPfl)
1007             {
1008               if((*it)->_profile.empty())
1009                 break;
1010               else
1011                 if(!(*it)->_profile.empty())
1012                   {
1013                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1014                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1015                       break;
1016                   }
1017             }
1018         }
1019     }
1020   if(it==entriesOnSameDisc.end())
1021     {
1022       notInExisting=true;
1023       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1024       ret->_type=typeF;
1025       ret->_loc_id=(int)geoType;
1026       ret->_nval=nbMeshEntities;
1027       ret->_start=offset;
1028       ret->_end=ret->_start+ret->_nval*nbi;
1029       if(isPfl)
1030         {
1031           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1032           glob.appendProfile(idsOfMeshElt);
1033           ret->_profile=idsOfMeshElt->getName();
1034         }
1035       //tony treatment of localization
1036       return ret;
1037     }
1038   else
1039     {
1040       notInExisting=false;
1041       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1042       ret->_loc_id=(int)geoType;
1043       ret->setNewStart(offset);
1044       entriesOnSameDisc.erase(it);
1045       return ret;
1046     }
1047
1048 }
1049
1050 ////////////////////////////////////
1051
1052 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1053  {
1054  }
1055
1056 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1057 {
1058   _father=father;
1059 }
1060
1061 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1062 {
1063   std::size_t i=0;
1064   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1065     {
1066       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1067         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1068     }
1069 }
1070
1071 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1072 {
1073   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1074 }
1075
1076 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1077 {
1078   std::vector<const BigMemoryObject *> ret;
1079   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1080     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1081   return ret;
1082 }
1083
1084 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1085 {
1086   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1087   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1088     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1089 }
1090
1091 /*!
1092  * This method is the most general one. No optimization is done here.
1093  * \param [in] multiTypePfl is the end user profile specified in high level API
1094  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1095  * \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.
1096  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1097  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1098  * \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.
1099  */
1100 void MEDFileFieldPerMeshPerTypeCommon::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)
1101 {
1102   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1103   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1104     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1105 }
1106
1107 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1108 {
1109   _field_pm_pt_pd.resize(1);
1110   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1111   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1112 }
1113
1114 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1115 {
1116   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1117   if(!arr || !arr->isAllocated())
1118     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1119   _field_pm_pt_pd.resize(1);
1120   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1121   _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.
1122 }
1123
1124 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1125 {
1126   TypeOfField type=field->getTypeOfField();
1127   if(type!=ON_GAUSS_PT)
1128     {
1129       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1130       int sz=_field_pm_pt_pd.size();
1131       bool found=false;
1132       for(int j=0;j<sz && !found;j++)
1133         {
1134           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1135             {
1136               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1137               found=true;
1138             }
1139         }
1140       if(!found)
1141         {
1142           _field_pm_pt_pd.resize(sz+1);
1143           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1144         }
1145       std::vector<int> ret(1,(int)sz);
1146       return ret;
1147     }
1148   else
1149     {
1150       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1151       int sz2=ret2.size();
1152       std::vector<int> ret3(sz2);
1153       int k=0;
1154       for(int i=0;i<sz2;i++)
1155         {
1156           int sz=_field_pm_pt_pd.size();
1157           int locIdToFind=ret2[i];
1158           bool found=false;
1159           for(int j=0;j<sz && !found;j++)
1160             {
1161               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1162                 {
1163                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1164                   ret3[k++]=j;
1165                   found=true;
1166                 }
1167             }
1168           if(!found)
1169             {
1170               _field_pm_pt_pd.resize(sz+1);
1171               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1172               ret3[k++]=sz;
1173             }
1174         }
1175       return ret3;
1176     }
1177 }
1178
1179 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1180 {
1181   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1182   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1183   if(!disc2)
1184     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1185   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1186   if(!da)
1187     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1188   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1189   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1190   if(retTmp->presenceOfValue(-1))
1191     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1192   std::vector<int> ret(retTmp->begin(),retTmp->end());
1193   return ret;
1194 }
1195
1196 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1197 {
1198   TypeOfField type=field->getTypeOfField();
1199   if(type!=ON_GAUSS_PT)
1200     {
1201       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1202       int sz=_field_pm_pt_pd.size();
1203       bool found=false;
1204       for(int j=0;j<sz && !found;j++)
1205         {
1206           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1207             {
1208               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1209               found=true;
1210             }
1211         }
1212       if(!found)
1213         {
1214           _field_pm_pt_pd.resize(sz+1);
1215           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1216         }
1217       std::vector<int> ret(1,0);
1218       return ret;
1219     }
1220   else
1221     {
1222       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1223       int sz2=ret2.size();
1224       std::vector<int> ret3(sz2);
1225       int k=0;
1226       for(int i=0;i<sz2;i++)
1227         {
1228           int sz=_field_pm_pt_pd.size();
1229           int locIdToFind=ret2[i];
1230           bool found=false;
1231           for(int j=0;j<sz && !found;j++)
1232             {
1233               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1234                 {
1235                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1236                   ret3[k++]=j;
1237                   found=true;
1238                 }
1239             }
1240           if(!found)
1241             {
1242               _field_pm_pt_pd.resize(sz+1);
1243               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1244               ret3[k++]=sz;
1245             }
1246         }
1247       return ret3;
1248     }
1249 }
1250
1251 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1252 {
1253   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1254   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1255   if(!disc2)
1256     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1257   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1258   if(!da)
1259     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1260   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1261   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1262   if(retTmp->presenceOfValue(-1))
1263     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1264   std::vector<int> ret(retTmp->begin(),retTmp->end());
1265   return ret;
1266 }
1267
1268 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1269 {
1270   return _father;
1271 }
1272
1273 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1274 {
1275   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1276   int curDim((int)cm.getDimension());
1277   if(dim!=std::numeric_limits<int>::max())
1278     {
1279       if(dim!=curDim)
1280         return false;
1281     }
1282   else
1283     dim=curDim;
1284   return true;
1285 }
1286
1287 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1288 {
1289   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1290     {
1291       (*it)->fillTypesOfFieldAvailable(types);
1292     }
1293 }
1294
1295 void MEDFileFieldPerMeshPerTypeCommon::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1296 {
1297   int sz=_field_pm_pt_pd.size();
1298   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1299   for(int i=0;i<sz;i++)
1300     {
1301       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1302     }
1303 }
1304
1305 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1306 {
1307   return _father->getIteration();
1308 }
1309
1310 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1311 {
1312   return _father->getOrder();
1313 }
1314
1315 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1316 {
1317   return _father->getTime();
1318 }
1319
1320 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1321 {
1322   return _father->getMeshName();
1323 }
1324
1325 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1326 {
1327   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1328     {
1329       globalSz+=(*it)->getNumberOfTuples();
1330     }
1331   nbOfEntries+=(int)_field_pm_pt_pd.size();
1332 }
1333
1334 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1335 {
1336   return _father->getNumberOfComponents();
1337 }
1338
1339 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1340 {
1341   std::size_t nb(0);
1342   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1343     {
1344       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1345       if(fmtd)
1346         nb++;
1347     }
1348   return nb>1;
1349 }
1350
1351 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1352 {
1353   return _father->getOrCreateAndGetArray();
1354 }
1355
1356 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1357 {
1358   const MEDFileFieldPerMesh *fath=_father;
1359   return fath->getOrCreateAndGetArray();
1360 }
1361
1362 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1363 {
1364   return _father->getInfo();
1365 }
1366
1367 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1368 {
1369   std::vector<std::string> ret;
1370   std::set<std::string> ret2;
1371   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1372     {
1373       std::string tmp=(*it1)->getProfile();
1374       if(!tmp.empty())
1375         if(ret2.find(tmp)==ret2.end())
1376           {
1377             ret.push_back(tmp);
1378             ret2.insert(tmp);
1379           }
1380     }
1381   return ret;
1382 }
1383
1384 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1385 {
1386   std::vector<std::string> ret;
1387   std::set<std::string> ret2;
1388   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1389     {
1390       std::string tmp=(*it1)->getLocalization();
1391       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1392         if(ret2.find(tmp)==ret2.end())
1393           {
1394             ret.push_back(tmp);
1395             ret2.insert(tmp);
1396           }
1397     }
1398   return ret;
1399 }
1400
1401 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1402 {
1403   std::vector<std::string> ret;
1404   std::set<std::string> ret2;
1405   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1406     {
1407       std::string tmp=(*it1)->getProfile();
1408       if(!tmp.empty())
1409         ret.push_back(tmp);
1410     }
1411   return ret;
1412 }
1413
1414 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1415 {
1416   std::vector<std::string> ret;
1417   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1418     {
1419       std::string tmp=(*it1)->getLocalization();
1420       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1421         ret.push_back(tmp);
1422     }
1423   return ret;
1424 }
1425
1426 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1427 {
1428   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1429     (*it1)->changePflsRefsNamesGen(mapOfModif);
1430 }
1431
1432 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1433 {
1434   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1435     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1436 }
1437
1438 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1439 {
1440   if(_field_pm_pt_pd.empty())
1441     {
1442       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1443       throw INTERP_KERNEL::Exception(oss.str());
1444     }
1445   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1446     return _field_pm_pt_pd[locId];
1447   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1448   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1449   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1450   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1451 }
1452
1453 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1454 {
1455   if(_field_pm_pt_pd.empty())
1456     {
1457       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1458       throw INTERP_KERNEL::Exception(oss.str());
1459     }
1460   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1461     return _field_pm_pt_pd[locId];
1462   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1463   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1464   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1465   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1466 }
1467
1468 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1469 {
1470   int i=0;
1471   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1472     {
1473       (*it)->fillValues(i,startEntryId,entries);
1474     }
1475 }
1476
1477 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1478 {
1479   _field_pm_pt_pd=leaves;
1480   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1481     (*it)->setFather(this);
1482 }
1483
1484 /*!
1485  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1486  *  \param [out] its - list of pair (start,stop) kept
1487  *  \return bool - false if the type of field \a tof is not contained in \a this.
1488  */
1489 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1490 {
1491   bool ret(false);
1492   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1493   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1494     if((*it)->getType()==tof)
1495       {
1496         newPmPtPd.push_back(*it);
1497         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1498         (*it)->setNewStart(globalNum);
1499         globalNum=(*it)->getEnd();
1500         its.push_back(bgEnd);
1501         ret=true;
1502       }
1503   if(ret)
1504     _field_pm_pt_pd=newPmPtPd;
1505   return ret;
1506 }
1507
1508 /*!
1509  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1510  *  \param [out] its - list of pair (start,stop) kept
1511  *  \return bool - false if the type of field \a tof is not contained in \a this.
1512  */
1513 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1514 {
1515   if(_field_pm_pt_pd.size()<=idOfDisc)
1516     return false;
1517   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1518   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1519   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1520   elt->setNewStart(globalNum);
1521   globalNum=elt->getEnd();
1522   its.push_back(bgEnd);
1523   _field_pm_pt_pd=newPmPtPd;
1524   return true;
1525 }
1526
1527 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1528 {
1529   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1530     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1531 }
1532
1533 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1534 {
1535   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1536     (*it)->loadBigArray(fid,nasc);
1537 }
1538
1539 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1540 {
1541   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1542     {
1543       (*it)->copyOptionsFrom(*this);
1544       (*it)->writeLL(fid,nasc);
1545     }
1546 }
1547
1548 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1549 {
1550   switch(ikType)
1551   {
1552     case ON_CELLS:
1553       medfGeoType=typmai3[(int)ikGeoType];
1554       return MED_CELL;
1555     case ON_NODES:
1556       medfGeoType=MED_NONE;
1557       return MED_NODE;
1558     case ON_GAUSS_NE:
1559       medfGeoType=typmai3[(int)ikGeoType];
1560       return MED_NODE_ELEMENT;
1561     case ON_GAUSS_PT:
1562       medfGeoType=typmai3[(int)ikGeoType];
1563       return MED_CELL;
1564     default:
1565       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1566   }
1567   return MED_UNDEF_ENTITY_TYPE;
1568 }
1569
1570 //////////////////////////////////////////////////
1571
1572 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1573 {
1574   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1575 }
1576
1577 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1578 {
1579   return new MEDFileFieldPerMeshPerType(fath,geoType);
1580 }
1581
1582 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1583 {
1584   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1585   ret->setFather(father);
1586   ret->deepCopyElements();
1587   return ret.retn();
1588 }
1589
1590 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
1591 {
1592   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1593     {
1594       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1595       if(meshDim!=(int)cm.getDimension())
1596         return ;
1597     }
1598   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1599     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1600 }
1601
1602 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1603 {
1604   return _geo_type;
1605 }
1606
1607 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1608 {
1609   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1610   int curDim((int)cm.getDimension());
1611   dim=std::max(dim,curDim);
1612 }
1613
1614 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1615 {
1616   const char startLine[]="  ## ";
1617   std::string startLine2(bkOffset,' ');
1618   std::string startLine3(startLine2);
1619   startLine3+=startLine;
1620   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1621     {
1622       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1623       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1624     }
1625   else
1626     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1627   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1628   int i=0;
1629   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1630     {
1631       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1632       if(cur)
1633         cur->simpleRepr(bkOffset,oss,i);
1634       else
1635         {
1636           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1637         }
1638     }
1639 }
1640
1641 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1642 {
1643   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1644   return std::string(cm.getRepr());
1645 }
1646
1647 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1648 {
1649 }
1650
1651 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1652 {
1653   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1654   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1655   med_geometry_type mgeoti;
1656   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1657   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1658   _field_pm_pt_pd.resize(nbProfiles);
1659   for(int i=0;i<nbProfiles;i++)
1660     {
1661       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1662     }
1663   if(type==ON_CELLS)
1664     {
1665       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1666       for(int i=0;i<nbProfiles2;i++)
1667         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1668     }
1669 }
1670
1671 MCAuto<MEDFileFieldPerMeshPerType> MEDFileFieldPerMeshPerType::Aggregate(int &start, const std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
1672 {
1673   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1674   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1675   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1676     {
1677       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1678         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1679     }
1680   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1681     {
1682       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1683       ret->_field_pm_pt_pd.push_back(agg);
1684     }
1685   return ret;
1686 }
1687
1688 //////////////////////////////////////////////////
1689
1690 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1691 {
1692   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1693 }
1694
1695 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1696 {
1697   return new MEDFileFieldPerMesh(fath,mesh);
1698 }
1699
1700 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1701 {
1702   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1703 }
1704
1705 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1706 {
1707   std::vector<const BigMemoryObject *> ret;
1708   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1709     ret.push_back(*it);
1710   return ret;
1711 }
1712
1713 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1714 {
1715   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1716   ret->_father=father;
1717   std::size_t i=0;
1718   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1719     {
1720       if((*it).isNotNull())
1721         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1722     }
1723   return ret.retn();
1724 }
1725
1726 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1727 {
1728   std::string startLine(bkOffset,' ');
1729   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1730   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1731   int i=0;
1732   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1733     {
1734       if((*it).isNotNull())
1735         (*it)->simpleRepr(bkOffset,oss,i);
1736       else
1737         {
1738           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1739         }
1740     }
1741 }
1742
1743 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1744 {
1745   _mesh_name=mesh->getName();
1746   mesh->getTime(_mesh_iteration,_mesh_order);
1747 }
1748
1749 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1750 {
1751   int nbOfTypes=code.size()/3;
1752   int offset=0;
1753   for(int i=0;i<nbOfTypes;i++)
1754     {
1755       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1756       int nbOfCells=code[3*i+1];
1757       int pos=addNewEntryIfNecessary(type);
1758       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1759       offset+=nbOfCells;
1760     }
1761 }
1762
1763 /*!
1764  * This method is the most general one. No optimization is done here.
1765  * \param [in] multiTypePfl is the end user profile specified in high level API
1766  * \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].
1767  * \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.
1768  * \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.
1769  * \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.
1770  * \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.
1771  */
1772 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)
1773 {
1774   int nbOfTypes(code.size()/3);
1775   for(int i=0;i<nbOfTypes;i++)
1776     {
1777       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1778       int pos=addNewEntryIfNecessary(type);
1779       DataArrayInt *pfl=0;
1780       if(code[3*i+2]!=-1)
1781         pfl=idsPerType[code[3*i+2]];
1782       int nbOfTupes2=code2.size()/3;
1783       int found=0;
1784       for(;found<nbOfTupes2;found++)
1785         if(code[3*i]==code2[3*found])
1786           break;
1787       if(found==nbOfTupes2)
1788         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1789       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1790     }
1791 }
1792
1793 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1794 {
1795   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1796   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1797 }
1798
1799 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1800 {
1801   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1802   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1803 }
1804
1805 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1806 {
1807   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1808     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1809 }
1810
1811 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1812 {
1813   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1814     (*it)->loadBigArraysRecursively(fid,nasc);
1815 }
1816
1817 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1818 {
1819   int nbOfTypes=_field_pm_pt.size();
1820   for(int i=0;i<nbOfTypes;i++)
1821     {
1822       _field_pm_pt[i]->copyOptionsFrom(*this);
1823       _field_pm_pt[i]->writeLL(fid,nasc);
1824     }
1825 }
1826
1827 void MEDFileFieldPerMesh::getDimension(int& dim) const
1828 {
1829   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1830     (*it)->getDimension(dim);
1831 }
1832
1833 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
1834 {
1835   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1836     if(!(*it)->isUniqueLevel(dim))
1837       return false;
1838   return true;
1839 }
1840
1841 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1842 {
1843   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1844     (*it)->fillTypesOfFieldAvailable(types);
1845 }
1846
1847 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
1848 {
1849   int sz=_field_pm_pt.size();
1850   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1851   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1852   for(int i=0;i<sz;i++)
1853     {
1854       types[i]=_field_pm_pt[i]->getGeoType();
1855       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1856     }
1857   return ret;
1858 }
1859
1860 double MEDFileFieldPerMesh::getTime() const
1861 {
1862   int tmp1,tmp2;
1863   return _father->getTime(tmp1,tmp2);
1864 }
1865
1866 int MEDFileFieldPerMesh::getIteration() const
1867 {
1868   return _father->getIteration();
1869 }
1870
1871 int MEDFileFieldPerMesh::getOrder() const
1872 {
1873   return _father->getOrder();
1874 }
1875
1876 int MEDFileFieldPerMesh::getNumberOfComponents() const
1877 {
1878   return _father->getNumberOfComponents();
1879 }
1880
1881 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1882 {
1883   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1884     {
1885       if((*it).isNull())
1886         continue;
1887       if((*it)->presenceOfMultiDiscPerGeoType())
1888         return true;
1889     }
1890   return false;
1891 }
1892
1893 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1894 {
1895   if(!_father)
1896     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1897   return _father->getOrCreateAndGetArray();
1898 }
1899
1900 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1901 {
1902   if(!_father)
1903     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1904   return _father->getOrCreateAndGetArray();
1905 }
1906
1907 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1908 {
1909   return _father->getInfo();
1910 }
1911
1912 /*!
1913  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
1914  * 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.
1915  * It returns 2 output vectors :
1916  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
1917  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
1918  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
1919  */
1920 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)
1921 {
1922   int notNullPflsSz=0;
1923   int nbOfArrs=geoTypes.size();
1924   for(int i=0;i<nbOfArrs;i++)
1925     if(pfls[i])
1926       notNullPflsSz++;
1927   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
1928   int nbOfDiffGeoTypes=geoTypes3.size();
1929   code.resize(3*nbOfDiffGeoTypes);
1930   notNullPfls.resize(notNullPflsSz);
1931   notNullPflsSz=0;
1932   int j=0;
1933   for(int i=0;i<nbOfDiffGeoTypes;i++)
1934     {
1935       int startZone=j;
1936       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
1937       std::vector<const DataArrayInt *> notNullTmp;
1938       if(pfls[j])
1939         notNullTmp.push_back(pfls[j]);
1940       j++;
1941       for(;j<nbOfArrs;j++)
1942         if(geoTypes[j]==refType)
1943           {
1944             if(pfls[j])
1945               notNullTmp.push_back(pfls[j]);
1946           }
1947         else
1948           break;
1949       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
1950       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
1951       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
1952       code[3*i]=(int)refType;
1953       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
1954       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
1955       if(notNullTmp.empty())
1956         code[3*i+2]=-1;
1957       else
1958         {
1959           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
1960           code[3*i+2]=notNullPflsSz++;
1961         }
1962     }
1963 }
1964
1965 /*!
1966  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
1967  */
1968 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)
1969 {
1970   int sz=dads.size();
1971   int ret=0;
1972   for(int i=0;i<sz;i++)
1973     {
1974       if(locs[i]==-1)
1975         {
1976           if(type!=ON_GAUSS_NE)
1977             ret+=dads[i].second-dads[i].first;
1978           else
1979             {
1980               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
1981               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
1982             }
1983         }
1984       else
1985         {
1986           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
1987           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
1988         }
1989     }
1990   return ret;
1991 }
1992
1993 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
1994 {
1995   std::vector<std::string> ret;
1996   std::set<std::string> ret2;
1997   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1998     {
1999       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2000       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2001         if(ret2.find(*it2)==ret2.end())
2002           {
2003             ret.push_back(*it2);
2004             ret2.insert(*it2);
2005           }
2006     }
2007   return ret;
2008 }
2009
2010 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2011 {
2012   std::vector<std::string> ret;
2013   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2014     {
2015       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2016       ret.insert(ret.end(),tmp.begin(),tmp.end());
2017     }
2018   return ret;
2019 }
2020
2021 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2022 {
2023   std::vector<std::string> ret;
2024   std::set<std::string> ret2;
2025   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2026     {
2027       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2028       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2029         if(ret2.find(*it2)==ret2.end())
2030           {
2031             ret.push_back(*it2);
2032             ret2.insert(*it2);
2033           }
2034     }
2035   return ret;
2036 }
2037
2038 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2039 {
2040   std::vector<std::string> ret;
2041   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2042     {
2043       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2044       ret.insert(ret.end(),tmp.begin(),tmp.end());
2045     }
2046   return ret;
2047 }
2048
2049 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2050 {
2051   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2052     {
2053       if((*it).first==_mesh_name)
2054         {
2055           _mesh_name=(*it).second;
2056           return true;
2057         }
2058     }
2059   return false;
2060 }
2061
2062 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2063                                                       MEDFileFieldGlobsReal& glob)
2064 {
2065   if(_mesh_name!=meshName)
2066     return false;
2067   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2068   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2069   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2070   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2071   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2072   getUndergroundDataArrayExt(entries);
2073   DataArray *arr0(getOrCreateAndGetArray());//tony
2074   if(!arr0)
2075     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2076   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2077   if(!arr0)
2078     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2079   int sz=0;
2080   if(!arr)
2081     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2082   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2083     {
2084       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2085         {
2086           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2087           sz+=(*it).second.second-(*it).second.first;
2088         }
2089       else
2090         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2091     }
2092   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2093   ////////////////////
2094   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2095   int *workI2=explicitIdsOldInMesh->getPointer();
2096   int sz1=0,sz2=0,sid=1;
2097   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2098   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2099   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2100     {
2101       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2102       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2103       int *workI=explicitIdsOldInArr->getPointer();
2104       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2105         {
2106           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2107           (*itL2)->setLocId(sz2);
2108           (*itL2)->_tmp_work1=(*itL2)->getStart();
2109           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2110         }
2111       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2112     }
2113   explicitIdsOldInMesh->reAlloc(sz2);
2114   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2115   ////////////////////
2116   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2117   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2118   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2119   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2120     {
2121       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2122       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2123       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2124     }
2125   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2126   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2127   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2128     {
2129       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2130       int newStart=elt->getLocId();
2131       elt->setLocId((*it)->getGeoType());
2132       elt->setNewStart(newStart);
2133       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2134       entriesKeptNew.push_back(elt);
2135       entriesKeptNew2.push_back(elt);
2136     }
2137   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2138   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2139   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2140   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2141   bool ret=false;
2142   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2143     {
2144       sid=0;
2145       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2146         {
2147           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2148           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2149           }*/
2150       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2151                                                             glob,arr2,otherEntriesNew) || ret;
2152     }
2153   if(!ret)
2154     return false;
2155   // Assign new dispatching
2156   assignNewLeaves(otherEntriesNew);
2157   arr->deepCopyFrom(*arr2);
2158   return true;
2159 }
2160
2161 /*!
2162  * \param [in,out] globalNum a global numbering counter for the renumbering.
2163  * \param [out] its - list of pair (start,stop) kept
2164  */
2165 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2166 {
2167   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2168   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2169     {
2170       std::vector< std::pair<int,int> > its2;
2171       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2172         {
2173           ret.push_back(*it);
2174           its.insert(its.end(),its2.begin(),its2.end());
2175         }
2176     }
2177   _field_pm_pt=ret;
2178 }
2179
2180 /*!
2181  * \param [in,out] globalNum a global numbering counter for the renumbering.
2182  * \param [out] its - list of pair (start,stop) kept
2183  */
2184 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2185 {
2186   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2187   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2188     {
2189       std::vector< std::pair<int,int> > its2;
2190       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2191         {
2192           ret.push_back(*it);
2193           its.insert(its.end(),its2.begin(),its2.end());
2194         }
2195     }
2196   _field_pm_pt=ret;
2197 }
2198
2199 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2200 {
2201   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2202   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2203     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2204   //
2205   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2206   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2207   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2208   for(;it1!=types.end();it1++,it2++)
2209     {
2210       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2211       elt->setLeaves((*it1).second);
2212       *it2=elt;
2213     }
2214   _field_pm_pt=fieldPmPt;
2215 }
2216
2217 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2218 {
2219   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2220     (*it)->changePflsRefsNamesGen(mapOfModif);
2221 }
2222
2223 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2224 {
2225   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2226     (*it)->changeLocsRefsNamesGen(mapOfModif);
2227 }
2228
2229 /*!
2230  * \param [in] mesh is the whole mesh
2231  */
2232 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2233 {
2234   if(_field_pm_pt.empty())
2235     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2236   //
2237   std::vector< std::pair<int,int> > dads;
2238   std::vector<const DataArrayInt *> pfls;
2239   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2240   std::vector<int> locs,code;
2241   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2242   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2243     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2244   // Sort by types
2245   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2246   if(code.empty())
2247     {
2248       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2249       throw INTERP_KERNEL::Exception(oss.str());
2250     }
2251   //
2252   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2253   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2254   if(type!=ON_NODES)
2255     {
2256       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2257       if(!arr)
2258         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2259       else
2260         {
2261           MCAuto<DataArrayInt> arr2(arr);
2262           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2263         }
2264     }
2265   else
2266     {
2267       if(code.size()!=3)
2268         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2269       int nb=code[1];
2270       if(code[2]==-1)
2271         {
2272           if(nb!=mesh->getNumberOfNodes())
2273             {
2274               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2275               oss << " nodes in mesh !";
2276               throw INTERP_KERNEL::Exception(oss.str());
2277             }
2278           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2279         }
2280       else
2281         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2282     }
2283 }
2284
2285 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2286 {
2287   if(_field_pm_pt.empty())
2288     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2289   //
2290   std::vector<std::pair<int,int> > dads;
2291   std::vector<const DataArrayInt *> pfls;
2292   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2293   std::vector<int> locs,code;
2294   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2295   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2296     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2297   // Sort by types
2298   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2299   if(code.empty())
2300     {
2301       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2302       throw INTERP_KERNEL::Exception(oss.str());
2303     }
2304   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2305   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2306   if(type!=ON_NODES)
2307     {
2308       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2309       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2310     }
2311   else
2312     {
2313       if(code.size()!=3)
2314         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2315       int nb=code[1];
2316       if(code[2]==-1)
2317         {
2318           if(nb!=mesh->getNumberOfNodes())
2319             {
2320               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2321               oss << " nodes in mesh !";
2322               throw INTERP_KERNEL::Exception(oss.str());
2323             }
2324         }
2325       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2326     }
2327   //
2328   return 0;
2329 }
2330
2331 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2332 {
2333   int globalSz=0;
2334   int nbOfEntries=0;
2335   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2336     {
2337       (*it)->getSizes(globalSz,nbOfEntries);
2338     }
2339   entries.resize(nbOfEntries);
2340   nbOfEntries=0;
2341   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2342     {
2343       (*it)->fillValues(nbOfEntries,entries);
2344     }
2345 }
2346
2347 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2348 {
2349   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2350     {
2351       if((*it)->getGeoType()==typ)
2352         return (*it)->getLeafGivenLocId(locId);
2353     }
2354   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2355   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2356   oss << "Possiblities are : ";
2357   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2358     {
2359       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2360       oss << "\"" << cm2.getRepr() << "\", ";
2361     }
2362   throw INTERP_KERNEL::Exception(oss.str());
2363 }
2364
2365 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2366 {
2367   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2368     {
2369       if((*it)->getGeoType()==typ)
2370         return (*it)->getLeafGivenLocId(locId);
2371     }
2372   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2373   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2374   oss << "Possiblities are : ";
2375   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2376     {
2377       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2378       oss << "\"" << cm2.getRepr() << "\", ";
2379     }
2380   throw INTERP_KERNEL::Exception(oss.str());
2381 }
2382
2383 /*!
2384  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2385  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2386  * \param [in] dts - (Distribution of types) = level 1 : meshes to aggregate. Level 2 : all geo type. Level 3 pair specifying geo type and number of elem in geotype.
2387  * \param [out] extractInfo - Gives information about the where the data comes from. It is a vector of triplet. First element in the triplet the mesh pos. The 2nd one the start pos. The 3rd the end pos.
2388  */
2389 MCAuto<MEDFileFieldPerMeshPerTypePerDisc> MEDFileFieldPerMeshPerTypePerDisc::Aggregate(int &start, const std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, TypeOfField tof, MEDFileFieldPerMeshPerType *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2390 {
2391   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2392   if(pms.empty())
2393     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2394   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2395     {
2396       if(!(*it).second)
2397         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2398       if(!(*it).second->getProfile().empty())
2399         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2400       if(!(*it).second->getLocalization().empty())
2401         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2402     }
2403   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2404   std::size_t i(0);
2405   std::vector< std::pair<int,int> > filteredDTS;
2406   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2407     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2408       if((*it2).first==gt)
2409         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2410   if(pms.size()!=filteredDTS.size())
2411     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2412   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2413   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2414   int zeStart(start),nval(0);
2415   for(;it1!=pms.end();it1++,it2++)
2416     {
2417       if((*it1).first!=(*it2).first)
2418         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2419       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2420       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2421       start+=e1-s1;
2422       nval+=((*it1).second)->getNumberOfVals();
2423     }
2424   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2425   return ret;
2426 }
2427
2428 MCAuto<MEDFileFieldPerMesh> MEDFileFieldPerMesh::Aggregate(int &start, const std::vector<const MEDFileFieldPerMesh *>& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, MEDFileAnyTypeField1TSWithoutSDA *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
2429 {
2430   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2431   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2432   std::size_t i(0);
2433   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2434     {
2435       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2436       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2437         {
2438           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2439           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2440           if(!elt)
2441             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2442           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2443         }
2444     }
2445   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2446     {
2447       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2448       ret->_field_pm_pt.push_back(agg);
2449     }
2450   return ret;
2451 }
2452
2453 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2454 {
2455   int i=0;
2456   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2457   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2458   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2459     {
2460       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2461       if(type==curType)
2462         return i;
2463       else
2464         {
2465           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2466           if(pos>pos2)
2467             it2=it+1;
2468         }
2469     }
2470   int ret=std::distance(_field_pm_pt.begin(),it2);
2471   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2472   return ret;
2473 }
2474
2475 /*!
2476  * 'dads' and 'locs' input parameters have the same number of elements
2477  * \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
2478  */
2479 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2480                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2481                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2482 {
2483   isPfl=false;
2484   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2485   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2486   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2487   const std::vector<std::string>& infos=getInfo();
2488   da->setInfoOnComponents(infos);
2489   da->setName("");
2490   if(type==ON_GAUSS_PT)
2491     {
2492       int offset=0;
2493       int nbOfArrs=dads.size();
2494       for(int i=0;i<nbOfArrs;i++)
2495         {
2496           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2497           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2498           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2499           MCAuto<DataArrayInt> di=DataArrayInt::New();
2500           di->alloc(nbOfElems,1);
2501           di->iota(offset);
2502           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2503           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2504           offset+=nbOfElems;
2505         }
2506     }
2507   arrOut=da;
2508   return ret.retn();
2509 }
2510
2511 /*!
2512  * 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.
2513  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2514  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2515  * The order of cells in the returned field is those imposed by the profile.
2516  * \param [in] mesh is the global mesh.
2517  */
2518 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2519                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2520                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2521                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2522 {
2523   if(da->isIota(mesh->getNumberOfCells()))
2524     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2525   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2526   m2->setName(mesh->getName().c_str());
2527   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2528   isPfl=true;
2529   return ret.retn();
2530 }
2531
2532 /*!
2533  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2534  */
2535 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2536                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2537                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2538 {
2539   if(da->isIota(mesh->getNumberOfNodes()))
2540     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2541   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2542   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2543   if(meshu)
2544     {
2545       if(meshu->getNodalConnectivity()==0)
2546         {
2547           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2548           int nb=da->getNbOfElems();
2549           const int *ptr=da->getConstPointer();
2550           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2551           meshuc->allocateCells(nb);
2552           for(int i=0;i<nb;i++)
2553             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2554           meshuc->finishInsertingCells();
2555           ret->setMesh(meshuc);
2556           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2557           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2558           disc->checkCoherencyBetween(meshuc,arrOut);
2559           return ret.retn();
2560         }
2561     }
2562   //
2563   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2564   isPfl=true;
2565   DataArrayInt *arr2=0;
2566   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2567   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2568   MCAuto<DataArrayInt> arr3(arr2);
2569   int nnodes=mesh2->getNumberOfNodes();
2570   if(nnodes==(int)da->getNbOfElems())
2571     {
2572       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2573       arrOut->renumberInPlace(da3->getConstPointer());
2574       mesh2->setName(mesh->getName().c_str());
2575       ret->setMesh(mesh2);
2576       return ret.retn();
2577     }
2578   else
2579     {
2580       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 !!!";
2581       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2582       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2583       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2584       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2585       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2586       throw INTERP_KERNEL::Exception(oss.str());
2587     }
2588   return 0;
2589 }
2590
2591 /*!
2592  * This method is the most light method of field retrieving.
2593  */
2594 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2595 {
2596   if(!pflIn)
2597     {
2598       pflOut=DataArrayInt::New();
2599       pflOut->alloc(nbOfElems,1);
2600       pflOut->iota(0);
2601     }
2602   else
2603     {
2604       pflOut=const_cast<DataArrayInt*>(pflIn);
2605       pflOut->incrRef();
2606     }
2607   MCAuto<DataArrayInt> safePfl(pflOut);
2608   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2609   const std::vector<std::string>& infos=getInfo();
2610   int nbOfComp=infos.size();
2611   for(int i=0;i<nbOfComp;i++)
2612     da->setInfoOnComponent(i,infos[i].c_str());
2613   safePfl->incrRef();
2614   return da.retn();
2615 }
2616
2617
2618 /// @cond INTERNAL
2619
2620 class MFFPMIter
2621 {
2622 public:
2623   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2624   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2625   virtual ~MFFPMIter() { }
2626   virtual void begin() = 0;
2627   virtual bool finished() const = 0;
2628   virtual void next() = 0;
2629   virtual int current() const = 0;
2630 };
2631
2632 class MFFPMIterSimple : public MFFPMIter
2633 {
2634 public:
2635   MFFPMIterSimple():_pos(0) { }
2636   void begin() { _pos=0; }
2637   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2638   void next() { _pos++; }
2639   int current() const { return _pos; }
2640 private:
2641   int _pos;
2642 };
2643
2644 class MFFPMIter2 : public MFFPMIter
2645 {
2646 public:
2647   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2648   void begin() { _it=_ids.begin(); }
2649   bool finished() const { return _it==_ids.end(); }
2650   void next() { _it++; }
2651   int current() const { return *_it; }
2652 private:
2653   std::vector<int> _ids;
2654   std::vector<int>::const_iterator _it;
2655 };
2656
2657 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
2658 {
2659   if(!entities)
2660     return new MFFPMIterSimple;
2661   else
2662     {
2663       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2664       if(entities2)
2665         {
2666           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2667           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2668           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2669             {
2670               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2671                 tmp.push_back((*it).second);
2672             }
2673           return new MFFPMIter2(tmp);
2674         }
2675       else
2676         throw INTERP_KERNEL::Exception("MFFPMIter::NewCell : not recognized type !");
2677     }
2678 }
2679
2680 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
2681 {
2682   if(!entities)
2683     return true;
2684   else
2685     {
2686       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2687       if(entities2)
2688         {
2689           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2690           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2691             if((*it).first==ON_NODES)
2692               return true;
2693           return false;
2694         }
2695       else
2696         throw INTERP_KERNEL::Exception("MFFPMIter::IsPresenceOfNode : not recognized type !");
2697     }
2698 }
2699
2700 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2701 {
2702   std::size_t sz(cts.size());
2703   _ids.resize(sz);
2704   for(std::size_t i=0;i<sz;i++)
2705     {
2706       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2707       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2708         _ids[i]=(int)std::distance(typmai2,loc);
2709       else
2710         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2711     }
2712 }
2713
2714 /// @endcond
2715
2716 MEDFileFieldPerMesh::MEDFileFieldPerMesh(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities):_mesh_iteration(meshIteration),_mesh_order(meshOrder),
2717     _father(fath)
2718 {
2719   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2720   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2721   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2722   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2723   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2724   for(iter0->begin();!iter0->finished();iter0->next())
2725     {
2726       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2727       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2728       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2729       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2730       if(nbProfile>0 || nbProfile2>0)
2731         {
2732           const PartDefinition *pd(0);
2733           if(mmu)
2734             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2735           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2736           if(nbProfile>0)
2737             _mesh_name=name0;
2738           else
2739             _mesh_name=name1;
2740         }
2741     }
2742   if(MFFPMIter::IsPresenceOfNode(entities))
2743     {
2744       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2745       if(nbProfile>0)
2746         {
2747           const PartDefinition *pd(0);
2748           if(mmu)
2749             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2750           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2751           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2752         }
2753     }
2754 }
2755
2756 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2757 {
2758   copyTinyInfoFrom(mesh);
2759 }
2760
2761 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2762 {
2763   if(id>=(int)_pfls.size())
2764     _pfls.resize(id+1);
2765   _pfls[id]=DataArrayInt::New();
2766   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2767   _pfls[id]->setName(pflName);
2768   _pfls[id]->alloc(lgth,1);
2769   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2770   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2771 }
2772
2773 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2774 {
2775   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2776   int sz;
2777   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2778   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2779   if(i>=(int)_pfls.size())
2780     _pfls.resize(i+1);
2781   _pfls[i]=DataArrayInt::New();
2782   _pfls[i]->alloc(sz,1);
2783   _pfls[i]->setName(pflCpp.c_str());
2784   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2785   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2786 }
2787
2788 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2789 {
2790   int nbOfPfls=_pfls.size();
2791   for(int i=0;i<nbOfPfls;i++)
2792     {
2793       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2794       cpy->applyLin(1,1,0);
2795       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2796       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2797       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2798     }
2799   //
2800   int nbOfLocs=_locs.size();
2801   for(int i=0;i<nbOfLocs;i++)
2802     _locs[i]->writeLL(fid);
2803 }
2804
2805 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2806 {
2807   std::vector<std::string> pfls=getPfls();
2808   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2809     {
2810       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2811       if(it2==pfls.end())
2812         {
2813           _pfls.push_back(*it);
2814         }
2815       else
2816         {
2817           int id=std::distance(pfls.begin(),it2);
2818           if(!(*it)->isEqual(*_pfls[id]))
2819             {
2820               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2821               throw INTERP_KERNEL::Exception(oss.str());
2822             }
2823         }
2824     }
2825   std::vector<std::string> locs=getLocs();
2826   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2827     {
2828       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2829       if(it2==locs.end())
2830         {
2831           _locs.push_back(*it);
2832         }
2833       else
2834         {
2835           int id=std::distance(locs.begin(),it2);
2836           if(!(*it)->isEqual(*_locs[id],eps))
2837             {
2838               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2839               throw INTERP_KERNEL::Exception(oss.str());
2840             }
2841         }
2842     }
2843 }
2844
2845 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2846 {
2847   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2848     getProfile((*it).c_str());
2849 }
2850
2851 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2852 {
2853   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2854     getLocalization((*it).c_str());
2855 }
2856
2857 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2858 {
2859   std::vector<std::string> profiles=real.getPflsReallyUsed();
2860   int sz=profiles.size();
2861   _pfls.resize(sz);
2862   for(int i=0;i<sz;i++)
2863     loadProfileInFile(fid,i,profiles[i].c_str());
2864   //
2865   std::vector<std::string> locs=real.getLocsReallyUsed();
2866   sz=locs.size();
2867   _locs.resize(sz);
2868   for(int i=0;i<sz;i++)
2869     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2870 }
2871
2872 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2873 {
2874   int nProfil=MEDnProfile(fid);
2875   for(int i=0;i<nProfil;i++)
2876     loadProfileInFile(fid,i);
2877   int sz=MEDnLocalization(fid);
2878   _locs.resize(sz);
2879   for(int i=0;i<sz;i++)
2880     {
2881       _locs[i]=MEDFileFieldLoc::New(fid,i);
2882     }
2883 }
2884
2885 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
2886 {
2887   return new MEDFileFieldGlobs(fid);
2888 }
2889
2890 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2891 {
2892   return new MEDFileFieldGlobs;
2893 }
2894
2895 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2896 {
2897   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
2898 }
2899
2900 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2901 {
2902   std::vector<const BigMemoryObject *> ret;
2903   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
2904     ret.push_back((const DataArrayInt *)*it);
2905   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
2906     ret.push_back((const MEDFileFieldLoc *)*it);
2907   return ret;
2908 }
2909
2910 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
2911 {
2912   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
2913   std::size_t i=0;
2914   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
2915     {
2916       if((const DataArrayInt *)*it)
2917         ret->_pfls[i]=(*it)->deepCopy();
2918     }
2919   i=0;
2920   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
2921     {
2922       if((const MEDFileFieldLoc*)*it)
2923         ret->_locs[i]=(*it)->deepCopy();
2924     }
2925   return ret.retn();
2926 }
2927
2928 /*!
2929  * \throw if a profile in \a pfls in not in \a this.
2930  * \throw if a localization in \a locs in not in \a this.
2931  * \sa MEDFileFieldGlobs::deepCpyPart
2932  */
2933 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2934 {
2935   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2936   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2937     {
2938       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2939       if(!pfl)
2940         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
2941       pfl->incrRef();
2942       MCAuto<DataArrayInt> pfl2(pfl);
2943       ret->_pfls.push_back(pfl2);
2944     }
2945   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2946     {
2947       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2948       if(!loc)
2949         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
2950       loc->incrRef();
2951       MCAuto<MEDFileFieldLoc> loc2(loc);
2952       ret->_locs.push_back(loc2);
2953     }
2954   ret->setFileName(getFileName());
2955   return ret.retn();
2956 }
2957
2958 /*!
2959  * \throw if a profile in \a pfls in not in \a this.
2960  * \throw if a localization in \a locs in not in \a this.
2961  * \sa MEDFileFieldGlobs::shallowCpyPart
2962  */
2963 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
2964 {
2965   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
2966   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
2967     {
2968       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
2969       if(!pfl)
2970         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
2971       ret->_pfls.push_back(pfl->deepCopy());
2972     }
2973   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
2974     {
2975       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
2976       if(!loc)
2977         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
2978       ret->_locs.push_back(loc->deepCopy());
2979     }
2980   ret->setFileName(getFileName());
2981   return ret.retn();
2982 }
2983
2984 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
2985 {
2986 }
2987
2988 MEDFileFieldGlobs::MEDFileFieldGlobs()
2989 {
2990 }
2991
2992 MEDFileFieldGlobs::~MEDFileFieldGlobs()
2993 {
2994 }
2995
2996 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
2997 {
2998   oss << "Profiles :\n";
2999   std::size_t n=_pfls.size();
3000   for(std::size_t i=0;i<n;i++)
3001     {
3002       oss << "  - #" << i << " ";
3003       const DataArrayInt *pfl=_pfls[i];
3004       if(pfl)
3005         oss << "\"" << pfl->getName() << "\"\n";
3006       else
3007         oss << "EMPTY !\n";
3008     }
3009   n=_locs.size();
3010   oss << "Localizations :\n";
3011   for(std::size_t i=0;i<n;i++)
3012     {
3013       oss << "  - #" << i << " ";
3014       const MEDFileFieldLoc *loc=_locs[i];
3015       if(loc)
3016         loc->simpleRepr(oss);
3017       else
3018         oss<< "EMPTY !\n";
3019     }
3020 }
3021
3022 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3023 {
3024   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3025     {
3026       DataArrayInt *elt(*it);
3027       if(elt)
3028         {
3029           std::string name(elt->getName());
3030           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3031             {
3032               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3033                 {
3034                   elt->setName((*it2).second.c_str());
3035                   return;
3036                 }
3037             }
3038         }
3039     }
3040 }
3041
3042 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3043 {
3044   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3045     {
3046       MEDFileFieldLoc *elt(*it);
3047       if(elt)
3048         {
3049           std::string name(elt->getName());
3050           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3051             {
3052               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3053                 {
3054                   elt->setName((*it2).second.c_str());
3055                   return;
3056                 }
3057             }
3058         }
3059     }
3060 }
3061
3062 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3063 {
3064   if(locId<0 || locId>=(int)_locs.size())
3065     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3066   return _locs[locId]->getNbOfGaussPtPerCell();
3067 }
3068
3069 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3070 {
3071   return getLocalizationFromId(getLocalizationId(locName));
3072 }
3073
3074 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3075 {
3076   if(locId<0 || locId>=(int)_locs.size())
3077     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3078   return *_locs[locId];
3079 }
3080
3081 /// @cond INTERNAL
3082 namespace MEDCouplingImpl
3083 {
3084   class LocFinder
3085   {
3086   public:
3087     LocFinder(const std::string& loc):_loc(loc) { }
3088     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3089   private:
3090     const std::string &_loc;
3091   };
3092
3093   class PflFinder
3094   {
3095   public:
3096     PflFinder(const std::string& pfl):_pfl(pfl) { }
3097     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3098   private:
3099     const std::string& _pfl;
3100   };
3101 }
3102 /// @endcond
3103
3104 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3105 {
3106   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3107   if(it==_locs.end())
3108     {
3109       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3110       for(it=_locs.begin();it!=_locs.end();it++)
3111         oss << "\"" << (*it)->getName() << "\", ";
3112       throw INTERP_KERNEL::Exception(oss.str());
3113     }
3114   return std::distance(_locs.begin(),it);
3115 }
3116
3117 /*!
3118  * The returned value is never null.
3119  */
3120 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3121 {
3122   std::string pflNameCpp(pflName);
3123   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3124   if(it==_pfls.end())
3125     {
3126       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3127       for(it=_pfls.begin();it!=_pfls.end();it++)
3128         oss << "\"" << (*it)->getName() << "\", ";
3129       throw INTERP_KERNEL::Exception(oss.str());
3130     }
3131   return *it;
3132 }
3133
3134 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3135 {
3136   if(pflId<0 || pflId>=(int)_pfls.size())
3137     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3138   return _pfls[pflId];
3139 }
3140
3141 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3142 {
3143   if(locId<0 || locId>=(int)_locs.size())
3144     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3145   return *_locs[locId];
3146 }
3147
3148 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3149 {
3150   return getLocalizationFromId(getLocalizationId(locName));
3151 }
3152
3153 /*!
3154  * The returned value is never null.
3155  */
3156 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3157 {
3158   std::string pflNameCpp(pflName);
3159   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3160   if(it==_pfls.end())
3161     {
3162       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3163       for(it=_pfls.begin();it!=_pfls.end();it++)
3164         oss << "\"" << (*it)->getName() << "\", ";
3165       throw INTERP_KERNEL::Exception(oss.str());
3166     }
3167   return *it;
3168 }
3169
3170 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3171 {
3172   if(pflId<0 || pflId>=(int)_pfls.size())
3173     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3174   return _pfls[pflId];
3175 }
3176
3177 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3178 {
3179   std::vector< MCAuto<DataArrayInt> > newPfls;
3180   int i=0;
3181   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3182     {
3183       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3184         newPfls.push_back(*it);
3185     }
3186   _pfls=newPfls;
3187 }
3188
3189 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3190 {
3191   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3192   int i=0;
3193   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3194     {
3195       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3196         newLocs.push_back(*it);
3197     }
3198   _locs=newLocs;
3199 }
3200
3201 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3202 {
3203   int sz=_pfls.size();
3204   std::vector<std::string> ret(sz);
3205   for(int i=0;i<sz;i++)
3206     ret[i]=_pfls[i]->getName();
3207   return ret;
3208 }
3209
3210 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3211 {
3212   int sz=_locs.size();
3213   std::vector<std::string> ret(sz);
3214   for(int i=0;i<sz;i++)
3215     ret[i]=_locs[i]->getName();
3216   return ret;
3217 }
3218
3219 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3220 {
3221   std::vector<std::string> v=getPfls();
3222   std::string s(pflName);
3223   return std::find(v.begin(),v.end(),s)!=v.end();
3224 }
3225
3226 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3227 {
3228   std::vector<std::string> v=getLocs();
3229   std::string s(locName);
3230   return std::find(v.begin(),v.end(),s)!=v.end();
3231 }
3232
3233 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3234 {
3235   std::map<int,std::vector<int> > m;
3236   int i=0;
3237   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3238     {
3239       const DataArrayInt *tmp=(*it);
3240       if(tmp)
3241         {
3242           m[tmp->getHashCode()].push_back(i);
3243         }
3244     }
3245   std::vector< std::vector<int> > ret;
3246   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3247     {
3248       if((*it2).second.size()>1)
3249         {
3250           std::vector<int> ret0;
3251           bool equalityOrNot=false;
3252           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3253             {
3254               std::vector<int>::const_iterator it4=it3; it4++;
3255               for(;it4!=(*it2).second.end();it4++)
3256                 {
3257                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3258                     {
3259                       if(!equalityOrNot)
3260                         ret0.push_back(*it3);
3261                       ret0.push_back(*it4);
3262                       equalityOrNot=true;
3263                     }
3264                 }
3265             }
3266           if(!ret0.empty())
3267             ret.push_back(ret0);
3268         }
3269     }
3270   return ret;
3271 }
3272
3273 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3274 {
3275   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3276 }
3277
3278 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3279 {
3280   std::string name(pfl->getName());
3281   if(name.empty())
3282     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3283   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3284     if(name==(*it)->getName())
3285       {
3286         if(!pfl->isEqual(*(*it)))
3287           {
3288             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3289             throw INTERP_KERNEL::Exception(oss.str());
3290           }
3291       }
3292   pfl->incrRef();
3293   _pfls.push_back(pfl);
3294 }
3295
3296 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)
3297 {
3298   std::string name(locName);
3299   if(name.empty())
3300     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3301   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3302   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3303     if((*it)->isName(locName))
3304       {
3305         if(!(*it)->isEqual(*obj,1e-12))
3306           {
3307             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3308             throw INTERP_KERNEL::Exception(oss.str());
3309           }
3310       }
3311   _locs.push_back(obj);
3312 }
3313
3314 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3315 {
3316   std::vector<std::string> names=getPfls();
3317   return CreateNewNameNotIn("NewPfl_",names);
3318 }
3319
3320 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3321 {
3322   std::vector<std::string> names=getLocs();
3323   return CreateNewNameNotIn("NewLoc_",names);
3324 }
3325
3326 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3327 {
3328   for(std::size_t sz=0;sz<100000;sz++)
3329     {
3330       std::ostringstream tryName;
3331       tryName << prefix << sz;
3332       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3333         return tryName.str();
3334     }
3335   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3336 }
3337
3338 /*!
3339  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3340  *  \param [in] fname - the file name.
3341  */
3342 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3343 {
3344 }
3345
3346 /*!
3347  * Creates an empty MEDFileFieldGlobsReal.
3348  */
3349 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3350 {
3351 }
3352
3353 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3354 {
3355   return 0;
3356 }
3357
3358 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3359 {
3360   std::vector<const BigMemoryObject *> ret;
3361   ret.push_back((const MEDFileFieldGlobs *)_globals);
3362   return ret;
3363 }
3364
3365 /*!
3366  * Returns a string describing profiles and Gauss points held in \a this.
3367  *  \return std::string - the description string.
3368  */
3369 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3370 {
3371   const MEDFileFieldGlobs *glob=_globals;
3372   std::ostringstream oss2; oss2 << glob;
3373   std::string stars(oss2.str().length(),'*');
3374   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3375   if(glob)
3376     glob->simpleRepr(oss);
3377   else
3378     oss << "NO GLOBAL INFORMATION !\n";
3379 }
3380
3381 void MEDFileFieldGlobsReal::resetContent()
3382 {
3383   _globals=MEDFileFieldGlobs::New();
3384 }
3385
3386 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3387 {
3388 }
3389
3390 /*!
3391  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3392  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3393  */
3394 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3395 {
3396   _globals=other._globals;
3397 }
3398
3399 /*!
3400  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3401  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3402  */
3403 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3404 {
3405   const MEDFileFieldGlobs *otherg(other._globals);
3406   if(!otherg)
3407     return ;
3408   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3409 }
3410
3411 /*!
3412  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3413  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3414  */
3415 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3416 {
3417   const MEDFileFieldGlobs *otherg(other._globals);
3418   if(!otherg)
3419     return ;
3420   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3421 }
3422
3423 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3424 {
3425   _globals=other._globals;
3426   if((const MEDFileFieldGlobs *)_globals)
3427     _globals=other._globals->deepCopy();
3428 }
3429
3430 /*!
3431  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3432  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3433  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3434  *         \a this and \a other MEDFileFieldGlobsReal.
3435  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3436  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3437  */
3438 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3439 {
3440   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3441   if(thisGlobals==otherGlobals)
3442     return ;
3443   if(!thisGlobals)
3444     {
3445       _globals=other._globals;
3446       return ;
3447     }
3448   _globals->appendGlobs(*other._globals,eps);
3449 }
3450
3451 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3452 {
3453   checkGlobsPflsPartCoherency();
3454   checkGlobsLocsPartCoherency();
3455 }
3456
3457 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3458 {
3459   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3460 }
3461
3462 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3463 {
3464   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3465 }
3466
3467 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3468 {
3469   contentNotNull()->loadProfileInFile(fid,id,pflName);
3470 }
3471
3472 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3473 {
3474   contentNotNull()->loadProfileInFile(fid,id);
3475 }
3476
3477 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3478 {
3479   contentNotNull()->loadGlobals(fid,*this);
3480 }
3481
3482 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3483 {
3484   contentNotNull()->loadAllGlobals(fid);
3485 }
3486
3487 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3488 {
3489   contentNotNull()->writeGlobals(fid,opt);
3490 }
3491
3492 /*!
3493  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3494  * or getPflsReallyUsedMulti().
3495  *  \return std::vector<std::string> - a sequence of names of all profiles.
3496  */
3497 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3498 {
3499   return contentNotNull()->getPfls();
3500 }
3501
3502 /*!
3503  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3504  * or getLocsReallyUsedMulti().
3505  *  \return std::vector<std::string> - a sequence of names of all localizations.
3506  */
3507 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3508 {
3509   return contentNotNull()->getLocs();
3510 }
3511
3512 /*!
3513  * Checks if the profile with a given name exists.
3514  *  \param [in] pflName - the profile name of interest.
3515  *  \return bool - \c true if the profile named \a pflName exists.
3516  */
3517 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3518 {
3519   return contentNotNull()->existsPfl(pflName);
3520 }
3521
3522 /*!
3523  * Checks if the localization with a given name exists.
3524  *  \param [in] locName - the localization name of interest.
3525  *  \return bool - \c true if the localization named \a locName exists.
3526  */
3527 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3528 {
3529   return contentNotNull()->existsLoc(locName);
3530 }
3531
3532 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3533 {
3534   return contentNotNull()->createNewNameOfPfl();
3535 }
3536
3537 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3538 {
3539   return contentNotNull()->createNewNameOfLoc();
3540 }
3541
3542 /*!
3543  * Sets the name of a MED file.
3544  *  \param [inout] fileName - the file name.
3545  */
3546 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3547 {
3548   contentNotNull()->setFileName(fileName);
3549 }
3550
3551 /*!
3552  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3553  * in the same order.
3554  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3555  *          Each item of this sequence is a vector containing ids of equal profiles.
3556  */
3557 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3558 {
3559   return contentNotNull()->whichAreEqualProfiles();
3560 }
3561
3562 /*!
3563  * Finds equal localizations.
3564  *  \param [in] eps - a precision used to compare real values of the localizations.
3565  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3566  *          Each item of this sequence is a vector containing ids of equal localizations.
3567  */
3568 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3569 {
3570   return contentNotNull()->whichAreEqualLocs(eps);
3571 }
3572
3573 /*!
3574  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3575  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3576  *        this sequence is a pair whose 
3577  *        - the first item is a vector of profile names to replace by the second item,
3578  *        - the second item is a profile name to replace every profile name of the first item.
3579  */
3580 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3581 {
3582   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3583 }
3584
3585 /*!
3586  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3587  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3588  *        this sequence is a pair whose 
3589  *        - the first item is a vector of localization names to replace by the second item,
3590  *        - the second item is a localization name to replace every localization name of the first item.
3591  */
3592 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3593 {
3594   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3595 }
3596
3597 /*!
3598  * Replaces references to some profiles (a reference is a profile name) by references
3599  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3600  * them-selves accordingly. <br>
3601  * This method is a generalization of changePflName().
3602  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3603  *        this sequence is a pair whose 
3604  *        - the first item is a vector of profile names to replace by the second item,
3605  *        - the second item is a profile name to replace every profile of the first item.
3606  * \sa changePflsRefsNamesGen()
3607  * \sa changePflName()
3608  */
3609 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3610 {
3611   changePflsRefsNamesGen(mapOfModif);
3612   changePflsNamesInStruct(mapOfModif);
3613 }
3614
3615 /*!
3616  * Replaces references to some localizations (a reference is a localization name) by references
3617  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3618  * them-selves accordingly. <br>
3619  * This method is a generalization of changeLocName().
3620  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3621  *        this sequence is a pair whose 
3622  *        - the first item is a vector of localization names to replace by the second item,
3623  *        - the second item is a localization name to replace every localization of the first item.
3624  * \sa changeLocsRefsNamesGen()
3625  * \sa changeLocName()
3626  */
3627 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3628 {
3629   changeLocsRefsNamesGen(mapOfModif);
3630   changeLocsNamesInStruct(mapOfModif);
3631 }
3632
3633 /*!
3634  * Renames the profile having a given name and updates references to this profile.
3635  *  \param [in] oldName - the name of the profile to rename.
3636  *  \param [in] newName - a new name of the profile.
3637  * \sa changePflsNames().
3638  */
3639 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3640 {
3641   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3642   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3643   mapOfModif[0]=p;
3644   changePflsNames(mapOfModif);
3645 }
3646
3647 /*!
3648  * Renames the localization having a given name and updates references to this localization.
3649  *  \param [in] oldName - the name of the localization to rename.
3650  *  \param [in] newName - a new name of the localization.
3651  * \sa changeLocsNames().
3652  */
3653 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3654 {
3655   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3656   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3657   mapOfModif[0]=p;
3658   changeLocsNames(mapOfModif);
3659 }
3660
3661 /*!
3662  * Removes duplicated profiles. Returns a map used to update references to removed 
3663  * profiles via changePflsRefsNamesGen().
3664  * Equal profiles are found using whichAreEqualProfiles().
3665  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3666  *          a sequence describing the performed replacements of profiles. Each element of
3667  *          this sequence is a pair whose
3668  *          - the first item is a vector of profile names replaced by the second item,
3669  *          - the second item is a profile name replacing every profile of the first item.
3670  */
3671 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3672 {
3673   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3674   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3675   int i=0;
3676   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3677     {
3678       std::vector< std::string > tmp((*it).size());
3679       int j=0;
3680       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3681         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3682       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3683       ret[i]=p;
3684       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3685       killProfileIds(tmp2);
3686     }
3687   changePflsRefsNamesGen(ret);
3688   return ret;
3689 }
3690
3691 /*!
3692  * Removes duplicated localizations. Returns a map used to update references to removed 
3693  * localizations via changeLocsRefsNamesGen().
3694  * Equal localizations are found using whichAreEqualLocs().
3695  *  \param [in] eps - a precision used to compare real values of the localizations.
3696  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3697  *          a sequence describing the performed replacements of localizations. Each element of
3698  *          this sequence is a pair whose
3699  *          - the first item is a vector of localization names replaced by the second item,
3700  *          - the second item is a localization name replacing every localization of the first item.
3701  */
3702 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3703 {
3704   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3705   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3706   int i=0;
3707   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3708     {
3709       std::vector< std::string > tmp((*it).size());
3710       int j=0;
3711       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3712         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3713       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3714       ret[i]=p;
3715       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3716       killLocalizationIds(tmp2);
3717     }
3718   changeLocsRefsNamesGen(ret);
3719   return ret;
3720 }
3721
3722 /*!
3723  * Returns number of Gauss points per cell in a given localization.
3724  *  \param [in] locId - an id of the localization of interest.
3725  *  \return int - the number of the Gauss points per cell.
3726  */
3727 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3728 {
3729   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3730 }
3731
3732 /*!
3733  * Returns an id of a localization by its name.
3734  *  \param [in] loc - the localization name of interest.
3735  *  \return int - the id of the localization.
3736  *  \throw If there is no a localization named \a loc.
3737  */
3738 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3739 {
3740   return contentNotNull()->getLocalizationId(loc);
3741 }
3742
3743 /*!
3744  * Returns the name of the MED file.
3745  *  \return const std::string&  - the MED file name.
3746  */
3747 std::string MEDFileFieldGlobsReal::getFileName() const
3748 {
3749   return contentNotNull()->getFileName();
3750 }
3751
3752 /*!
3753  * Returns a localization object by its name.
3754  *  \param [in] locName - the name of the localization of interest.
3755  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3756  *  \throw If there is no a localization named \a locName.
3757  */
3758 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3759 {
3760   return contentNotNull()->getLocalization(locName);
3761 }
3762
3763 /*!
3764  * Returns a localization object by its id.
3765  *  \param [in] locId - the id of the localization of interest.
3766  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3767  *  \throw If there is no a localization with id \a locId.
3768  */
3769 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3770 {
3771   return contentNotNull()->getLocalizationFromId(locId);
3772 }
3773
3774 /*!
3775  * Returns a profile array by its name.
3776  *  \param [in] pflName - the name of the profile of interest.
3777  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3778  *  \throw If there is no a profile named \a pflName.
3779  */
3780 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3781 {
3782   return contentNotNull()->getProfile(pflName);
3783 }
3784
3785 /*!
3786  * Returns a profile array by its id.
3787  *  \param [in] pflId - the id of the profile of interest.
3788  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3789  *  \throw If there is no a profile with id \a pflId.
3790  */
3791 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3792 {
3793   return contentNotNull()->getProfileFromId(pflId);
3794 }
3795
3796 /*!
3797  * Returns a localization object, apt for modification, by its id.
3798  *  \param [in] locId - the id of the localization of interest.
3799  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3800  *          having the id \a locId.
3801  *  \throw If there is no a localization with id \a locId.
3802  */
3803 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3804 {
3805   return contentNotNull()->getLocalizationFromId(locId);
3806 }
3807
3808 /*!
3809  * Returns a localization object, apt for modification, by its name.
3810  *  \param [in] locName - the name of the localization of interest.
3811  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3812  *          having the name \a locName.
3813  *  \throw If there is no a localization named \a locName.
3814  */
3815 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3816 {
3817   return contentNotNull()->getLocalization(locName);
3818 }
3819
3820 /*!
3821  * Returns a profile array, apt for modification, by its name.
3822  *  \param [in] pflName - the name of the profile of interest.
3823  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3824  *  \throw If there is no a profile named \a pflName.
3825  */
3826 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3827 {
3828   return contentNotNull()->getProfile(pflName);
3829 }
3830
3831 /*!
3832  * Returns a profile array, apt for modification, by its id.
3833  *  \param [in] pflId - the id of the profile of interest.
3834  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3835  *  \throw If there is no a profile with id \a pflId.
3836  */
3837 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3838 {
3839   return contentNotNull()->getProfileFromId(pflId);
3840 }
3841
3842 /*!
3843  * Removes profiles given by their ids. No data is updated to track this removal.
3844  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3845  */
3846 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3847 {
3848   contentNotNull()->killProfileIds(pflIds);
3849 }
3850
3851 /*!
3852  * Removes localizations given by their ids. No data is updated to track this removal.
3853  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3854  */
3855 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3856 {
3857   contentNotNull()->killLocalizationIds(locIds);
3858 }
3859
3860 /*!
3861  * Stores a profile array.
3862  *  \param [in] pfl - the profile array to store.
3863  *  \throw If the name of \a pfl is empty.
3864  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3865  *         different ids.
3866  */
3867 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3868 {
3869   contentNotNull()->appendProfile(pfl);
3870 }
3871
3872 /*!
3873  * Adds a new localization of Gauss points.
3874  *  \param [in] locName - the name of the new localization.
3875  *  \param [in] geoType - a geometrical type of the reference cell.
3876  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3877  *         must be \c nbOfNodesPerCell * \c dimOfType.
3878  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3879  *         must be  _wg_.size() * \c dimOfType.
3880  *  \param [in] w - the weights of Gauss points.
3881  *  \throw If \a locName is empty.
3882  *  \throw If a localization with the name \a locName already exists but is
3883  *         different form the new one.
3884  */
3885 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)
3886 {
3887   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3888 }
3889
3890 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3891 {
3892   MEDFileFieldGlobs *g(_globals);
3893   if(!g)
3894     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3895   return g;
3896 }
3897
3898 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3899 {
3900   const MEDFileFieldGlobs *g(_globals);
3901   if(!g)
3902     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
3903   return g;
3904 }
3905
3906 //= MEDFileFieldNameScope
3907
3908 MEDFileFieldNameScope::MEDFileFieldNameScope()
3909 {
3910 }
3911
3912 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
3913 {
3914 }
3915
3916 /*!
3917  * Returns the name of \a this field.
3918  *  \return std::string - a string containing the field name.
3919  */
3920 std::string MEDFileFieldNameScope::getName() const
3921 {
3922   return _name;
3923 }
3924
3925 /*!
3926  * Sets name of \a this field
3927  *  \param [in] name - the new field name.
3928  */
3929 void MEDFileFieldNameScope::setName(const std::string& fieldName)
3930 {
3931   _name=fieldName;
3932 }
3933
3934 std::string MEDFileFieldNameScope::getDtUnit() const
3935 {
3936   return _dt_unit;
3937 }
3938
3939 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
3940 {
3941   _dt_unit=dtUnit;
3942 }
3943
3944 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
3945 {
3946   _name=other._name;
3947   _dt_unit=other._dt_unit;
3948 }
3949
3950 //= MEDFileAnyTypeField1TSWithoutSDA
3951
3952 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
3953 {
3954   _field_per_mesh.resize(other._field_per_mesh.size());
3955   std::size_t i=0;
3956   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
3957     {
3958       if((const MEDFileFieldPerMesh *)*it)
3959         _field_per_mesh[i]=(*it)->deepCopy(this);
3960     }
3961 }
3962
3963 /*!
3964  * Prints a string describing \a this field into a stream. This string is outputted 
3965  * by \c print Python command.
3966  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
3967  *  \param [in,out] oss - the out stream.
3968  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
3969  *          info id printed, else, not.
3970  */
3971 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
3972 {
3973   std::string startOfLine(bkOffset,' ');
3974   oss << startOfLine << "Field ";
3975   if(bkOffset==0)
3976     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
3977   oss << "on one time Step ";
3978   if(f1tsId>=0)
3979     oss << "(" << f1tsId << ") ";
3980   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
3981   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
3982   const DataArray *arr=getUndergroundDataArray();
3983   if(arr)
3984     {
3985       const std::vector<std::string> &comps=arr->getInfoOnComponents();
3986       if(f1tsId<0)
3987         {
3988           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
3989           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
3990             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
3991         }
3992       if(arr->isAllocated())
3993         {
3994           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
3995         }
3996       else
3997         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
3998     }
3999   else
4000     {
4001       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4002     }
4003   oss << startOfLine << "----------------------" << std::endl;
4004   if(!_field_per_mesh.empty())
4005     {
4006       int i=0;
4007       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4008         {
4009           const MEDFileFieldPerMesh *cur=(*it2);
4010           if(cur)
4011             cur->simpleRepr(bkOffset,oss,i);
4012           else
4013             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4014         }
4015     }
4016   else
4017     {
4018       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4019     }
4020   oss << startOfLine << "----------------------" << std::endl;
4021 }
4022
4023 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4024 {
4025   const DataArray *arr(getUndergroundDataArray());
4026   if(!arr)
4027     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4028   int nbOfCompo=arr->getNumberOfComponents();
4029   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4030   for(int i=0;i<nbOfCompo;i++)
4031     {
4032       ret[i]=deepCopy();
4033       std::vector<int> v(1,i);
4034       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4035       ret[i]->setArray(arr2);
4036     }
4037   return ret;
4038 }
4039
4040 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)
4041 {
4042 }
4043
4044 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4045 {
4046 }
4047
4048 /*!
4049  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4050  * empty. Returns -1 if this in on nodes.
4051  *  \return int - the dimension of \a this.
4052  */
4053 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4054 {
4055   int ret=-2;
4056   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4057     (*it)->getDimension(ret);
4058   return ret;
4059 }
4060
4061 /*!
4062  * Returns the mesh name.
4063  *  \return std::string - a string holding the mesh name.
4064  *  \throw If \c _field_per_mesh.empty()
4065  */
4066 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
4067 {
4068   if(_field_per_mesh.empty())
4069     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
4070   return _field_per_mesh[0]->getMeshName();
4071 }
4072
4073 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
4074 {
4075   std::string oldName(getMeshName());
4076   std::vector< std::pair<std::string,std::string> > v(1);
4077   v[0].first=oldName; v[0].second=newMeshName;
4078   changeMeshNames(v);
4079 }
4080
4081 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4082 {
4083   bool ret=false;
4084   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4085     {
4086       MEDFileFieldPerMesh *cur(*it);
4087       if(cur)
4088         ret=cur->changeMeshNames(modifTab) || ret;
4089     }
4090   return ret;
4091 }
4092
4093 /*!
4094  * Returns the number of iteration of the state of underlying mesh.
4095  *  \return int - the iteration number.
4096  *  \throw If \c _field_per_mesh.empty()
4097  */
4098 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4099 {
4100   if(_field_per_mesh.empty())
4101     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4102   return _field_per_mesh[0]->getMeshIteration();
4103 }
4104
4105 /*!
4106  * Returns the order number of iteration of the state of underlying mesh.
4107  *  \return int - the order number.
4108  *  \throw If \c _field_per_mesh.empty()
4109  */
4110 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4111 {
4112   if(_field_per_mesh.empty())
4113     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4114   return _field_per_mesh[0]->getMeshOrder();
4115 }
4116
4117 /*!
4118  * Checks if \a this field is tagged by a given iteration number and a given
4119  * iteration order number.
4120  *  \param [in] iteration - the iteration number of interest.
4121  *  \param [in] order - the iteration order number of interest.
4122  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4123  *          \a this->getOrder() == \a order.
4124  */
4125 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4126 {
4127   return iteration==_iteration && order==_order;
4128 }
4129
4130 /*!
4131  * Returns number of iteration and order number of iteration when
4132  * \a this field has been calculated.
4133  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4134  *          order number.
4135  */
4136 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4137 {
4138   std::pair<int,int> p;
4139   fillIteration(p);
4140   return p;
4141 }
4142
4143 /*!
4144  * Returns number of iteration and order number of iteration when
4145  * \a this field has been calculated.
4146  *  \param [in,out] p - a pair returning the iteration number and the iteration
4147  *          order number.
4148  */
4149 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4150 {
4151   p.first=_iteration;
4152   p.second=_order;
4153 }
4154
4155 /*!
4156  * Returns all types of spatial discretization of \a this field.
4157  *  \param [in,out] types - a sequence of types of \a this field.
4158  */
4159 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4160 {
4161   std::set<TypeOfField> types2;
4162   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4163     {
4164       (*it)->fillTypesOfFieldAvailable(types2);
4165     }
4166   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4167   std::copy(types2.begin(),types2.end(),bi);
4168 }
4169
4170 /*!
4171  * Returns all types of spatial discretization of \a this field.
4172  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4173  *          of \a this field.
4174  */
4175 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4176 {
4177   std::vector<TypeOfField> ret;
4178   fillTypesOfFieldAvailable(ret);
4179   return ret;
4180 }
4181
4182 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4183 {
4184   std::vector<std::string> ret;
4185   std::set<std::string> ret2;
4186   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4187     {
4188       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4189       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4190         if(ret2.find(*it2)==ret2.end())
4191           {
4192             ret.push_back(*it2);
4193             ret2.insert(*it2);
4194           }
4195     }
4196   return ret;
4197 }
4198
4199 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4200 {
4201   std::vector<std::string> ret;
4202   std::set<std::string> ret2;
4203   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4204     {
4205       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4206       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4207         if(ret2.find(*it2)==ret2.end())
4208           {
4209             ret.push_back(*it2);
4210             ret2.insert(*it2);
4211           }
4212     }
4213   return ret;
4214 }
4215
4216 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4217 {
4218   std::vector<std::string> ret;
4219   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4220     {
4221       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4222       ret.insert(ret.end(),tmp.begin(),tmp.end());
4223     }
4224   return ret;
4225 }
4226
4227 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4228 {
4229   std::vector<std::string> ret;
4230   std::set<std::string> ret2;
4231   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4232     {
4233       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4234       ret.insert(ret.end(),tmp.begin(),tmp.end());
4235     }
4236   return ret;
4237 }
4238
4239 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4240 {
4241   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4242     (*it)->changePflsRefsNamesGen(mapOfModif);
4243 }
4244
4245 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4246 {
4247   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4248     (*it)->changeLocsRefsNamesGen(mapOfModif);
4249 }
4250
4251 /*!
4252  * Returns all attributes of parts of \a this field lying on a given mesh.
4253  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4254  * item of every of returned sequences refers to the _i_-th part of \a this field.
4255  * Thus all sequences returned by this method are of the same length equal to number
4256  * of different types of supporting entities.<br>
4257  * A field part can include sub-parts with several different spatial discretizations,
4258  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4259  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4260  * of a nested sequence corresponds to a type of spatial discretization.<br>
4261  * This method allows for iteration over MEDFile DataStructure without any overhead.
4262  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4263  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4264  *          not checked if \a mname == \c NULL).
4265  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4266  *          a field part is returned. 
4267  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4268  *          This sequence is of the same length as \a types. 
4269  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4270  *          discretization. A profile name can be empty.
4271  *          Length of this and of nested sequences is the same as that of \a typesF.
4272  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4273  *          discretization. A localization name can be empty.
4274  *          Length of this and of nested sequences is the same as that of \a typesF.
4275  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4276  *          of ids of tuples within the data array, per each type of spatial
4277  *          discretization within one mesh entity type. 
4278  *          Length of this and of nested sequences is the same as that of \a typesF.
4279  *  \throw If no field is lying on \a mname.
4280  */
4281 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
4282 {
4283   int meshId=0;
4284   if(!mname.empty())
4285     meshId=getMeshIdFromMeshName(mname);
4286   else
4287     if(_field_per_mesh.empty())
4288       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4289   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4290 }
4291
4292 /*!
4293  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4294  * maximal absolute dimension and values returned via the out parameter \a levs are 
4295  * dimensions relative to the maximal absolute dimension. <br>
4296  * This method is designed for MEDFileField1TS instances that have a discretization
4297  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4298  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4299  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4300  * Only these 3 discretizations will be taken into account here. If \a this is
4301  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4302  * This method is useful to make the link between the dimension of the underlying mesh
4303  * and the levels of \a this, because it is possible that the highest dimension of \a this
4304  * field is not equal to the dimension of the underlying mesh.
4305  * 
4306  * Let's consider the following case:
4307  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4308  * TETRA4, HEXA8, TRI3 and SEG2.
4309  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4310  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4311  *
4312  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4313  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4314  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4315  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4316  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4317  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4318  * For example<br>
4319  * to retrieve the highest level of
4320  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4321  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4322  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4323  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4324  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4325  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4326  *          not checked if \a mname == \c NULL).
4327  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4328  *          absolute one. They are in decreasing order. This sequence is cleared before
4329  *          filling it in.
4330  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4331  *  \throw If no field is lying on \a mname.
4332  */
4333 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4334 {
4335   levs.clear();
4336   int meshId=getMeshIdFromMeshName(mname);
4337   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4338   std::vector< std::vector<TypeOfField> > typesF;
4339   std::vector< std::vector<std::string> > pfls, locs;
4340   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4341   if(types.empty())
4342     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4343   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4344   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4345     return -1;
4346   st.erase(INTERP_KERNEL::NORM_ERROR);
4347   std::set<int> ret1;
4348   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4349     {
4350       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4351       ret1.insert((int)cm.getDimension());
4352     }
4353   int ret=*std::max_element(ret1.begin(),ret1.end());
4354   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4355   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4356   return ret;
4357 }
4358
4359 /*!
4360  * \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.
4361  * \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.
4362  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4363  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4364  */
4365 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4366 {
4367   int mid=getMeshIdFromMeshName(mName);
4368   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4369 }
4370
4371 /*!
4372  * \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.
4373  * \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.
4374  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4375  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4376  */
4377 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4378 {
4379   int mid=getMeshIdFromMeshName(mName);
4380   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4381 }
4382
4383 /*!
4384  * \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.
4385  */
4386 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4387 {
4388   if(_field_per_mesh.empty())
4389     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4390   if(mName.empty())
4391     return 0;
4392   std::string mName2(mName);
4393   int ret=0;
4394   std::vector<std::string> msg;
4395   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4396     if(mName2==(*it)->getMeshName())
4397       return ret;
4398     else
4399       msg.push_back((*it)->getMeshName());
4400   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4401   oss << "Possible meshes are : ";
4402   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4403     oss << "\"" << (*it2) << "\" ";
4404   throw INTERP_KERNEL::Exception(oss.str());
4405 }
4406
4407 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4408 {
4409   if(!mesh)
4410     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4411   std::string tmp(mesh->getName());
4412   if(tmp.empty())
4413     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4414   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4415   int i=0;
4416   for(;it!=_field_per_mesh.end();it++,i++)
4417     {
4418       if((*it)->getMeshName()==tmp)
4419         return i;
4420     }
4421   int sz=_field_per_mesh.size();
4422   _field_per_mesh.resize(sz+1);
4423   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4424   return sz;
4425 }
4426
4427 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4428                                                                    MEDFileFieldGlobsReal& glob)
4429 {
4430   bool ret=false;
4431   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4432     {
4433       MEDFileFieldPerMesh *fpm(*it);
4434       if(fpm)
4435         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4436     }
4437   return ret;
4438 }
4439
4440 /*!
4441  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4442  * splitting that leads to single spatial discretization of this.
4443  *
4444  * \sa splitMultiDiscrPerGeoTypes
4445  */
4446 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4447 {
4448   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4449   std::vector< std::vector<TypeOfField> > typesF;
4450   std::vector< std::vector<std::string> > pfls,locs;
4451   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4452   std::set<TypeOfField> allEnt;
4453   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4454     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4455       allEnt.insert(*it2);
4456   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4457   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4458   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4459     {
4460       std::vector< std::pair<int,int> > its;
4461       ret[i]=shallowCpy();
4462       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4463       ret[i]->updateData(newLgth,its);
4464     }
4465   return ret;
4466 }
4467
4468 /*!
4469  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4470  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4471  *
4472  * \sa splitDiscretizations
4473  */
4474 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4475 {
4476   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4477   std::vector< std::vector<TypeOfField> > typesF;
4478   std::vector< std::vector<std::string> > pfls,locs;
4479   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4480   std::set<TypeOfField> allEnt;
4481   std::size_t nbOfMDPGT(0),ii(0);
4482   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4483     {
4484       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4485       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4486         allEnt.insert(*it2);
4487     }
4488   if(allEnt.size()!=1)
4489     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4490   if(nbOfMDPGT==0)
4491     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4492   if(nbOfMDPGT==1)
4493     {
4494       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4495       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4496       return ret0;
4497     }
4498   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4499   for(std::size_t i=0;i<nbOfMDPGT;i++)
4500     {
4501       std::vector< std::pair<int,int> > its;
4502       ret[i]=shallowCpy();
4503       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4504       ret[i]->updateData(newLgth,its);
4505     }
4506   return ret;
4507 }
4508
4509 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4510 {
4511   int globalCounter(0);
4512   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4513     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4514   return globalCounter;
4515 }
4516
4517 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4518 {
4519   int globalCounter(0);
4520   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4521     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4522   return globalCounter;
4523 }
4524
4525 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4526 {
4527   if(_nb_of_tuples_to_be_allocated>=0)
4528     {
4529       _nb_of_tuples_to_be_allocated=newLgth;
4530       const DataArray *oldArr(getUndergroundDataArray());
4531       if(oldArr)
4532         {
4533           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4534           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4535           setArray(newArr);
4536           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4537         }
4538       return ;
4539     }
4540   if(_nb_of_tuples_to_be_allocated==-1)
4541     return ;
4542   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4543     {
4544       const DataArray *oldArr(getUndergroundDataArray());
4545       if(!oldArr || !oldArr->isAllocated())
4546         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4547       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4548       newArr->alloc(newLgth,getNumberOfComponents());
4549       if(oldArr)
4550         newArr->copyStringInfoFrom(*oldArr);
4551       int pos=0;
4552       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4553         {
4554           if((*it).second<(*it).first)
4555             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4556           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4557           pos+=(*it).second-(*it).first;
4558         }
4559       setArray(newArr);
4560       return ;
4561     }
4562   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4563 }
4564
4565 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4566 {
4567   if(_field_per_mesh.empty())
4568     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4569   if(_field_per_mesh.size()>1)
4570     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4571   _field_per_mesh[0]->copyOptionsFrom(opts);
4572   _field_per_mesh[0]->writeLL(fid,nasc);
4573 }
4574
4575 /*!
4576  * 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.
4577  * If false is returned the memory allocation is not required.
4578  */
4579 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4580 {
4581   if(_nb_of_tuples_to_be_allocated>=0)
4582     {
4583       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4584       _nb_of_tuples_to_be_allocated=-2;
4585       return true;
4586     }
4587   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4588     return false;
4589   if(_nb_of_tuples_to_be_allocated==-1)
4590     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4591   if(_nb_of_tuples_to_be_allocated<-3)
4592     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4593   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4594 }
4595
4596 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4597 {
4598   med_int numdt,numit;
4599   med_float dt;
4600   med_int nmesh;
4601   med_bool localMesh;
4602   med_int meshnumdt,meshnumit;
4603   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4604   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4605   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4606   if(_iteration!=numdt || _order!=numit)
4607     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4608   _field_per_mesh.resize(nmesh);
4609   //
4610   MEDFileMesh *mm(0);
4611   if(ms)
4612     {
4613       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4614       mm=ms->getMeshWithName(meshNameCpp);
4615     }
4616   //
4617   for(int i=0;i<nmesh;i++)
4618     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4619   _nb_of_tuples_to_be_allocated=0;
4620   for(int i=0;i<nmesh;i++)
4621     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4622 }
4623
4624 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4625 {
4626   allocIfNecessaryTheArrayToReceiveDataFromFile();
4627   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4628     (*it)->loadBigArraysRecursively(fid,nasc);
4629 }
4630
4631 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4632 {
4633   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4634     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4635       (*it)->loadBigArraysRecursively(fid,nasc);
4636 }
4637
4638 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4639 {
4640   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4641   loadBigArraysRecursively(fid,nasc);
4642 }
4643
4644 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4645 {
4646   DataArray *thisArr(getUndergroundDataArray());
4647   if(thisArr && thisArr->isAllocated())
4648     {
4649       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4650       thisArr->desallocate();
4651     }
4652 }
4653
4654 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4655 {
4656   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4657 }
4658
4659 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4660 {
4661   std::vector<const BigMemoryObject *> ret;
4662   if(getUndergroundDataArray())
4663     ret.push_back(getUndergroundDataArray());
4664   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4665     ret.push_back((const MEDFileFieldPerMesh *)*it);
4666   return ret;
4667 }
4668
4669 /*!
4670  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4671  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4672  * "Sort By Type"), if not, an exception is thrown. 
4673  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4674  *  \param [in] arr - the array of values.
4675  *  \param [in,out] glob - the global data where profiles and localization present in
4676  *          \a field, if any, are added.
4677  *  \throw If the name of \a field is empty.
4678  *  \throw If the data array of \a field is not set.
4679  *  \throw If \a this->_arr is already allocated but has different number of components
4680  *         than \a field.
4681  *  \throw If the underlying mesh of \a field has no name.
4682  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4683  */
4684 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4685 {
4686   const MEDCouplingMesh *mesh=field->getMesh();
4687   //
4688   TypeOfField type=field->getTypeOfField();
4689   std::vector<DataArrayInt *> dummy;
4690   int start=copyTinyInfoFrom(field,arr);
4691   int pos=addNewEntryIfNecessary(mesh);
4692   if(type!=ON_NODES)
4693     {
4694       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4695       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4696     }
4697   else
4698     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4699 }
4700
4701 /*!
4702  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4703  * of a given mesh are used as the support of the given field (a real support is not used). 
4704  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4705  * Order of underlying mesh entities of the given field specified by \a profile parameter
4706  * is not prescribed; this method permutes field values to have them sorted by element
4707  * type as required for writing to MED file. A new profile is added only if no equal
4708  * profile is missing. 
4709  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4710  *  \param [in] arrOfVals - the values of the field \a field used.
4711  *  \param [in] mesh - the supporting mesh of \a field.
4712  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4713  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4714  *  \param [in,out] glob - the global data where profiles and localization present in
4715  *          \a field, if any, are added.
4716  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4717  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4718  *  \throw If the data array of \a field is not set.
4719  *  \throw If \a this->_arr is already allocated but has different number of components
4720  *         than \a field.
4721  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4722  *  \sa setFieldNoProfileSBT()
4723  */
4724 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4725 {
4726   if(!field)
4727     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4728   if(!arrOfVals || !arrOfVals->isAllocated())
4729     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4730   TypeOfField type=field->getTypeOfField();
4731   std::vector<DataArrayInt *> idsInPflPerType;
4732   std::vector<DataArrayInt *> idsPerType;
4733   std::vector<int> code,code2;
4734   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4735   if(type!=ON_NODES)
4736     {
4737       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4738       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4739       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4740       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4741       // start of check
4742       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4743       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4744       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4745         {
4746           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4747           throw INTERP_KERNEL::Exception(oss.str());
4748         }
4749       // end of check
4750       int start=copyTinyInfoFrom(field,arrOfVals);
4751       code2=m->getDistributionOfTypes();
4752       //
4753       int pos=addNewEntryIfNecessary(m);
4754       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4755     }
4756   else
4757     {
4758       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4759         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4760       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4761       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4762       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4763       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4764         {
4765           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4766           throw INTERP_KERNEL::Exception(oss.str());
4767         }
4768       int start=copyTinyInfoFrom(field,arrOfVals);
4769       int pos=addNewEntryIfNecessary(m);
4770       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4771     }
4772 }
4773
4774 /*!
4775  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4776  */
4777 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4778 {
4779   if(_nb_of_tuples_to_be_allocated>=0)
4780     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 !");
4781   DataArray *arr(getOrCreateAndGetArray());
4782   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4783   _nb_of_tuples_to_be_allocated=-3;
4784 }
4785
4786 /*!
4787  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4788  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4789  * larger by the size of \a field. Returns an id of the first not filled
4790  * tuple of \a this->_arr.
4791  *  \param [in] field - the field to copy the info on components and the name from.
4792  *  \return int - the id of first not initialized tuple of \a this->_arr.
4793  *  \throw If the name of \a field is empty.
4794  *  \throw If the data array of \a field is not set.
4795  *  \throw If \a this->_arr is already allocated but has different number of components
4796  *         than \a field.
4797  */
4798 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4799 {
4800   if(!field)
4801     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4802   std::string name(field->getName());
4803   setName(name.c_str());
4804   setDtUnit(field->getTimeUnit());
4805   if(name.empty())
4806     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4807   if(!arr)
4808     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4809   if(!arr->isAllocated())
4810     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4811   _dt=field->getTime(_iteration,_order);
4812   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4813   if(!getOrCreateAndGetArray()->isAllocated())
4814     {
4815       allocNotFromFile(arr->getNumberOfTuples());
4816       return 0;
4817     }
4818   else
4819     {
4820       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4821       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4822       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4823       _nb_of_tuples_to_be_allocated=-3;
4824       return oldNbOfTuples;
4825     }
4826 }
4827
4828 /*!
4829  * Returns number of components in \a this field
4830  *  \return int - the number of components.
4831  */
4832 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4833 {
4834   return getOrCreateAndGetArray()->getNumberOfComponents();
4835 }
4836
4837 /*!
4838  * Change info on components in \a this.
4839  * \throw If size of \a infos is not equal to the number of components already in \a this.
4840  */
4841 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4842 {
4843   DataArray *arr=getOrCreateAndGetArray();
4844   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4845 }
4846
4847 /*!
4848  * Returns info on components of \a this field.
4849  *  \return const std::vector<std::string>& - a sequence of strings each being an
4850  *          information on _i_-th component.
4851  */
4852 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4853 {
4854   const DataArray *arr=getOrCreateAndGetArray();
4855   return arr->getInfoOnComponents();
4856 }
4857
4858 /*!
4859  * Returns a mutable info on components of \a this field.
4860  *  \return std::vector<std::string>& - a sequence of strings each being an
4861  *          information on _i_-th component.
4862  */
4863 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4864 {
4865   DataArray *arr=getOrCreateAndGetArray();
4866   return arr->getInfoOnComponents();
4867 }
4868
4869 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4870 {
4871   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4872     {
4873       const MEDFileFieldPerMesh *fpm(*it);
4874       if(!fpm)
4875         continue;
4876       if(fpm->presenceOfMultiDiscPerGeoType())
4877         return true;
4878     }
4879   return false;
4880 }
4881
4882 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4883 {
4884   static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to be extracted with  \"field\" method ! Call getFieldOnMeshAtLevel method instead to deal with complexity !";
4885   if(_field_per_mesh.empty())
4886     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
4887   if(_field_per_mesh.size()>1)
4888     throw INTERP_KERNEL::Exception(MSG0);
4889   if(_field_per_mesh[0].isNull())
4890     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
4891   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
4892   std::set<TypeOfField> types;
4893   pm->fillTypesOfFieldAvailable(types);
4894   if(types.size()!=1)
4895     throw INTERP_KERNEL::Exception(MSG0);
4896   TypeOfField type(*types.begin());
4897   int meshDimRelToMax(0);
4898   if(type==ON_NODES)
4899     meshDimRelToMax=0;
4900   else
4901     {
4902       int myDim(std::numeric_limits<int>::max());
4903       bool isUnique(pm->isUniqueLevel(myDim));
4904       if(!isUnique)
4905         throw INTERP_KERNEL::Exception(MSG0);
4906       meshDimRelToMax=myDim-mesh->getMeshDimension();
4907       if(meshDimRelToMax>0)
4908         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
4909     }
4910   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
4911 }
4912
4913 /*!
4914  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4915  *  \param [in] type - a spatial discretization of the new field.
4916  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4917  *  \param [in] mName - a name of the supporting mesh.
4918  *  \param [in] renumPol - specifies how to permute values of the result field according to
4919  *          the optional numbers of cells and nodes, if any. The valid values are
4920  *          - 0 - do not permute.
4921  *          - 1 - permute cells.
4922  *          - 2 - permute nodes.
4923  *          - 3 - permute cells and nodes.
4924  *
4925  *  \param [in] glob - the global data storing profiles and localization.
4926  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4927  *          caller is to delete this field using decrRef() as it is no more needed. 
4928  *  \throw If the MED file is not readable.
4929  *  \throw If there is no mesh named \a mName in the MED file.
4930  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4931  *  \throw If no field of \a this is lying on the mesh \a mName.
4932  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4933  */
4934 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4935 {
4936   MCAuto<MEDFileMesh> mm;
4937   if(mName.empty())
4938     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4939   else
4940     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
4941   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
4942 }
4943
4944 /*!
4945  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
4946  *  \param [in] type - a spatial discretization of the new field.
4947  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
4948  *  \param [in] renumPol - specifies how to permute values of the result field according to
4949  *          the optional numbers of cells and nodes, if any. The valid values are
4950  *          - 0 - do not permute.
4951  *          - 1 - permute cells.
4952  *          - 2 - permute nodes.
4953  *          - 3 - permute cells and nodes.
4954  *
4955  *  \param [in] glob - the global data storing profiles and localization.
4956  *  \param [in] mesh - the supporting mesh.
4957  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4958  *          caller is to delete this field using decrRef() as it is no more needed. 
4959  *  \throw If the MED file is not readable.
4960  *  \throw If no field of \a this is lying on \a mesh.
4961  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
4962  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
4963  */
4964 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4965 {
4966   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
4967   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
4968   if(meshDimRelToMax==1)
4969     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
4970   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
4971 }
4972
4973 /*!
4974  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
4975  * given mesh. 
4976  *  \param [in] type - a spatial discretization of the new field.
4977  *  \param [in] mName - a name of the supporting mesh.
4978  *  \param [in] renumPol - specifies how to permute values of the result field according to
4979  *          the optional numbers of cells and nodes, if any. The valid values are
4980  *          - 0 - do not permute.
4981  *          - 1 - permute cells.
4982  *          - 2 - permute nodes.
4983  *          - 3 - permute cells and nodes.
4984  *
4985  *  \param [in] glob - the global data storing profiles and localization.
4986  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
4987  *          caller is to delete this field using decrRef() as it is no more needed. 
4988  *  \throw If the MED file is not readable.
4989  *  \throw If there is no mesh named \a mName in the MED file.
4990  *  \throw If there are no mesh entities in the mesh.
4991  *  \throw If no field values of the given \a type are available.
4992  */
4993 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4994 {
4995   MCAuto<MEDFileMesh> mm;
4996   if(mName.empty())
4997     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
4998   else
4999     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5000   int absDim=getDimension();
5001   int meshDimRelToMax=absDim-mm->getMeshDimension();
5002   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5003 }
5004
5005 /*!
5006  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5007  *  \param [in] type - a spatial discretization of the new field.
5008  *  \param [in] renumPol - specifies how to permute values of the result field according to
5009  *          the optional numbers of cells and nodes, if any. The valid values are
5010  *          - 0 - do not permute.
5011  *          - 1 - permute cells.
5012  *          - 2 - permute nodes.
5013  *          - 3 - permute cells and nodes.
5014  *
5015  *  \param [in] glob - the global data storing profiles and localization.
5016  *  \param [in] mesh - the supporting mesh.
5017  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5018  *         field according to \a renumPol.
5019  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5020  *         field according to \a renumPol.
5021  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5022  *          caller is to delete this field using decrRef() as it is no more needed. 
5023  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5024  *  \throw If no field of \a this is lying on \a mesh.
5025  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5026  */
5027 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5028 {
5029   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5030   int meshId=getMeshIdFromMeshName(mesh->getName());
5031   bool isPfl=false;
5032   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5033   switch(renumPol)
5034   {
5035     case 0:
5036       {
5037         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5038         return ret.retn();
5039       }
5040     case 3:
5041     case 1:
5042       {
5043         if(isPfl)
5044           throw INTERP_KERNEL::Exception(msg1);
5045         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5046         if(cellRenum)
5047           {
5048             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5049               {
5050                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5051                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5052                 throw INTERP_KERNEL::Exception(oss.str());
5053               }
5054             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5055             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5056             std::vector<DataArray *> arrOut2(1,arrOut);
5057             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5058             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5059             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5060           }
5061         if(renumPol==1)
5062           return ret.retn();
5063       }
5064     case 2:
5065       {
5066         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5067         if(isPfl)
5068           throw INTERP_KERNEL::Exception(msg1);
5069         if(nodeRenum)
5070           {
5071             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5072               {
5073                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5074                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5075                 throw INTERP_KERNEL::Exception(oss.str());
5076               }
5077             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5078             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5079               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5080             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5081           }
5082         return ret.retn();
5083       }
5084     default:
5085       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5086   }
5087 }
5088
5089 /*!
5090  * Returns values and a profile of the field of a given type lying on a given support.
5091  *  \param [in] type - a spatial discretization of the field.
5092  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5093  *  \param [in] mesh - the supporting mesh.
5094  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5095  *          field of interest lies on. If the field lies on all entities of the given
5096  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5097  *          using decrRef() as it is no more needed.  
5098  *  \param [in] glob - the global data storing profiles and localization.
5099  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5100  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5101  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5102  *  \throw If no field of \a this is lying on \a mesh.
5103  *  \throw If no field values of the given \a type are available.
5104  */
5105 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5106 {
5107   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5108   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
5109   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5110   ret->setName(nasc.getName().c_str());
5111   return ret.retn();
5112 }
5113
5114 //= MEDFileField1TSWithoutSDA
5115
5116 /*!
5117  * Throws if a given value is not a valid (non-extended) relative dimension.
5118  *  \param [in] meshDimRelToMax - the relative dimension value.
5119  *  \throw If \a meshDimRelToMax > 0.
5120  */
5121 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5122 {
5123   if(meshDimRelToMax>0)
5124     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5125 }
5126
5127 /*!
5128  * Checks if elements of a given mesh are in the order suitable for writing 
5129  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5130  * vector describing types of elements and their number.
5131  *  \param [in] mesh - the mesh to check.
5132  *  \return std::vector<int> - a vector holding for each element type (1) item of
5133  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5134  *          These values are in full-interlace mode.
5135  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5136  */
5137 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5138 {
5139   if(!mesh)
5140     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5141   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5142   int nbOfTypes=geoTypes.size();
5143   std::vector<int> code(3*nbOfTypes);
5144   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5145   arr1->alloc(nbOfTypes,1);
5146   int *arrPtr=arr1->getPointer();
5147   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5148   for(int i=0;i<nbOfTypes;i++,it++)
5149     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5150   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5151   const int *arrPtr2=arr2->getConstPointer();
5152   int i=0;
5153   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5154     {
5155       int pos=arrPtr2[i];
5156       int nbCells=mesh->getNumberOfCellsWithType(*it);
5157       code[3*pos]=(int)(*it);
5158       code[3*pos+1]=nbCells;
5159       code[3*pos+2]=-1;//no profiles
5160     }
5161   std::vector<const DataArrayInt *> idsPerType;//no profiles
5162   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5163   if(da)
5164     {
5165       da->decrRef();
5166       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5167     }
5168   return code;
5169 }
5170
5171 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5172 {
5173   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5174 }
5175
5176 /*!
5177  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5178  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5179  * item of every of returned sequences refers to the _i_-th part of \a this field.
5180  * Thus all sequences returned by this method are of the same length equal to number
5181  * of different types of supporting entities.<br>
5182  * A field part can include sub-parts with several different spatial discretizations,
5183  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5184  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5185  * of a nested sequence corresponds to a type of spatial discretization.<br>
5186  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5187  * The overhead is due to selecting values into new instances of DataArrayDouble.
5188  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5189  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5190  *          not checked if \a mname == \c NULL).
5191  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5192  *          a field part is returned. 
5193  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5194  *          A field part can include sub-parts with several different spatial discretizations,
5195  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5196  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5197  *          This sequence is of the same length as \a types. 
5198  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5199  *          discretization. A profile name can be empty.
5200  *          Length of this and of nested sequences is the same as that of \a typesF.
5201  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5202  *          discretization. A localization name can be empty.
5203  *          Length of this and of nested sequences is the same as that of \a typesF.
5204  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5205  *          per each type of spatial discretization within one mesh entity type.
5206  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5207  *          Length of this and of nested sequences is the same as that of \a typesF.
5208  *  \throw If no field is lying on \a mname.
5209  */
5210 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
5211 {
5212   int meshId=0;
5213   if(!mname.empty())
5214     meshId=getMeshIdFromMeshName(mname);
5215   else
5216     if(_field_per_mesh.empty())
5217       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5218   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5219   int nbOfRet=ret0.size();
5220   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5221   for(int i=0;i<nbOfRet;i++)
5222     {
5223       const std::vector< std::pair<int,int> >& p=ret0[i];
5224       int nbOfRet1=p.size();
5225       ret[i].resize(nbOfRet1);
5226       for(int j=0;j<nbOfRet1;j++)
5227         {
5228           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5229           ret[i][j]=tmp;
5230         }
5231     }
5232   return ret;
5233 }
5234
5235 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5236 {
5237   return TYPE_STR;
5238 }
5239
5240 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5241 {
5242   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5243   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5244   ret->deepCpyLeavesFrom(*this);
5245   const DataArrayDouble *arr(_arr);
5246   if(arr)
5247     {
5248       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5249       ret->setArray(arr2);
5250     }
5251   return ret.retn();
5252 }
5253
5254 /*!
5255  * Returns a pointer to the underground DataArrayDouble instance and a
5256  * sequence describing parameters of a support of each part of \a this field. The
5257  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5258  * direct access to the field values. This method is intended for the field lying on one
5259  * mesh only.
5260  *  \param [in,out] entries - the sequence describing parameters of a support of each
5261  *         part of \a this field. Each item of this sequence consists of two parts. The
5262  *         first part describes a type of mesh entity and an id of discretization of a
5263  *         current field part. The second part describes a range of values [begin,end)
5264  *         within the returned array relating to the current field part.
5265  *  \return DataArrayDouble * - the pointer to the field values array.
5266  *  \throw If the number of underlying meshes is not equal to 1.
5267  *  \throw If no field values are available.
5268  *  \sa getUndergroundDataArray()
5269  */
5270 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5271 {
5272   if(_field_per_mesh.size()!=1)
5273     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5274   if(_field_per_mesh[0]==0)
5275     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5276   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5277   return getUndergroundDataArrayTemplate();
5278 }
5279
5280 /*!
5281  * Returns a pointer to the underground DataArrayDouble instance and a
5282  * sequence describing parameters of a support of each part of \a this field. The
5283  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5284  * direct access to the field values. This method is intended for the field lying on one
5285  * mesh only.
5286  *  \param [in,out] entries - the sequence describing parameters of a support of each
5287  *         part of \a this field. Each item of this sequence consists of two parts. The
5288  *         first part describes a type of mesh entity and an id of discretization of a
5289  *         current field part. The second part describes a range of values [begin,end)
5290  *         within the returned array relating to the current field part.
5291  *  \return DataArrayDouble * - the pointer to the field values array.
5292  *  \throw If the number of underlying meshes is not equal to 1.
5293  *  \throw If no field values are available.
5294  *  \sa getUndergroundDataArray()
5295  */
5296 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5297 {
5298   return getUndergroundDataArrayDoubleExt(entries);
5299 }
5300
5301 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,csit,iteration,order)
5302 {
5303   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5304   arr->setInfoAndChangeNbOfCompo(infos);
5305 }
5306
5307 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5308 {
5309 }
5310
5311 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5312 {
5313   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5314   ret->deepCpyLeavesFrom(*this);
5315   return ret.retn();
5316 }
5317
5318 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5319 {
5320   MCAuto<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5321   if((const DataArrayDouble *)_arr)
5322     ret->_arr=_arr->deepCopy();
5323   return ret.retn();
5324 }
5325
5326 //= MEDFileIntField1TSWithoutSDA
5327
5328 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5329 {
5330   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5331 }
5332
5333 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5334 {
5335 }
5336
5337 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5338                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,csit,iteration,order)
5339 {
5340   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5341   arr->setInfoAndChangeNbOfCompo(infos);
5342 }
5343
5344 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5345 {
5346   return TYPE_STR;
5347 }
5348
5349 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5350 {
5351   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5352   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5353   ret->deepCpyLeavesFrom(*this);
5354   const DataArrayInt *arr(_arr);
5355   if(arr)
5356     {
5357       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5358       ret->setArray(arr2);
5359     }
5360   return ret.retn();
5361 }
5362
5363 /*!
5364  * Returns a pointer to the underground DataArrayInt instance and a
5365  * sequence describing parameters of a support of each part of \a this field. The
5366  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5367  * direct access to the field values. This method is intended for the field lying on one
5368  * mesh only.
5369  *  \param [in,out] entries - the sequence describing parameters of a support of each
5370  *         part of \a this field. Each item of this sequence consists of two parts. The
5371  *         first part describes a type of mesh entity and an id of discretization of a
5372  *         current field part. The second part describes a range of values [begin,end)
5373  *         within the returned array relating to the current field part.
5374  *  \return DataArrayInt * - the pointer to the field values array.
5375  *  \throw If the number of underlying meshes is not equal to 1.
5376  *  \throw If no field values are available.
5377  *  \sa getUndergroundDataArray()
5378  */
5379 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5380 {
5381   return getUndergroundDataArrayIntExt(entries);
5382 }
5383
5384 /*!
5385  * Returns a pointer to the underground DataArrayInt instance and a
5386  * sequence describing parameters of a support of each part of \a this field. The
5387  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5388  * direct access to the field values. This method is intended for the field lying on one
5389  * mesh only.
5390  *  \param [in,out] entries - the sequence describing parameters of a support of each
5391  *         part of \a this field. Each item of this sequence consists of two parts. The
5392  *         first part describes a type of mesh entity and an id of discretization of a
5393  *         current field part. The second part describes a range of values [begin,end)
5394  *         within the returned array relating to the current field part.
5395  *  \return DataArrayInt * - the pointer to the field values array.
5396  *  \throw If the number of underlying meshes is not equal to 1.
5397  *  \throw If no field values are available.
5398  *  \sa getUndergroundDataArray()
5399  */
5400 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5401 {
5402   if(_field_per_mesh.size()!=1)
5403     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5404   if(_field_per_mesh[0]==0)
5405     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5406   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5407   return getUndergroundDataArrayTemplate();
5408 }
5409
5410 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5411 {
5412   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5413   ret->deepCpyLeavesFrom(*this);
5414   return ret.retn();
5415 }
5416
5417 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5418 {
5419   MCAuto<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5420   if((const DataArrayInt *)_arr)
5421     ret->_arr=_arr->deepCopy();
5422   return ret.retn();
5423 }
5424
5425 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5426 {
5427 }
5428
5429 //= MEDFileAnyTypeField1TS
5430
5431 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5432 {
5433   med_field_type typcha;
5434   //
5435   std::vector<std::string> infos;
5436   std::string dtunit,fieldName;
5437   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
5438   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5439   switch(typcha)
5440   {
5441     case MED_FLOAT64:
5442       {
5443         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5444         break;
5445       }
5446     case MED_INT32:
5447       {
5448         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5449         break;
5450       }
5451     default:
5452       {
5453         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
5454         throw INTERP_KERNEL::Exception(oss.str());
5455       }
5456   }
5457   ret->setDtUnit(dtunit.c_str());
5458   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5459   //
5460   med_int numdt,numit;
5461   med_float dt;
5462   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5463   ret->setTime(numdt,numit,dt);
5464   ret->_csit=1;
5465   if(loadAll)
5466     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5467   else
5468     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5469   return ret.retn();
5470 }
5471
5472 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5473 try:MEDFileFieldGlobsReal(fid)
5474 {
5475   _content=BuildContentFrom(fid,loadAll,ms);
5476   loadGlobals(fid);
5477 }
5478 catch(INTERP_KERNEL::Exception& e)
5479 {
5480     throw e;
5481 }
5482
5483 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5484 {
5485   med_field_type typcha;
5486   std::vector<std::string> infos;
5487   std::string dtunit;
5488   int iii=-1;
5489   int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit);
5490   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5491   switch(typcha)
5492   {
5493     case MED_FLOAT64:
5494       {
5495         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5496         break;
5497       }
5498     case MED_INT32:
5499       {
5500         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5501         break;
5502       }
5503     default:
5504       {
5505         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5506         throw INTERP_KERNEL::Exception(oss.str());
5507       }
5508   }
5509   ret->setDtUnit(dtunit.c_str());
5510   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5511   //
5512   if(nbSteps<1)
5513     {
5514       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5515       throw INTERP_KERNEL::Exception(oss.str());
5516     }
5517   //
5518   med_int numdt,numit;
5519   med_float dt;
5520   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5521   ret->setTime(numdt,numit,dt);
5522   ret->_csit=1;
5523   if(loadAll)
5524     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5525   else
5526     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5527   return ret.retn();
5528 }
5529
5530 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5531 try:MEDFileFieldGlobsReal(fid)
5532 {
5533   _content=BuildContentFrom(fid,fieldName,loadAll,ms);
5534   loadGlobals(fid);
5535 }
5536 catch(INTERP_KERNEL::Exception& e)
5537 {
5538     throw e;
5539 }
5540
5541 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
5542 {
5543   if(!c)
5544     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5545   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5546     {
5547       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
5548       ret->_content=c; c->incrRef();
5549       return ret.retn();
5550     }
5551   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5552     {
5553       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
5554       ret->_content=c; c->incrRef();
5555       return ret.retn();
5556     }
5557   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5558 }
5559
5560 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
5561 {
5562   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
5563   ret->setFileName(FileNameFromFID(fid));
5564   return ret;
5565 }
5566
5567 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5568 {
5569   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5570   return New(fid,loadAll);
5571 }
5572
5573 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
5574 {
5575   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
5576   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5577   ret->loadGlobals(fid);
5578   return ret.retn();
5579 }
5580
5581 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5582 {
5583   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5584   return New(fid,fieldName,loadAll);
5585 }
5586
5587 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
5588 {
5589   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0));
5590   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5591   ret->loadGlobals(fid);
5592   return ret.retn();
5593 }
5594
5595 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5596 {
5597   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5598   return New(fid,fieldName,iteration,order,loadAll);
5599 }
5600
5601 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
5602 {
5603   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0));
5604   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5605   ret->loadGlobals(fid);
5606   return ret.retn();
5607 }
5608
5609 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5610 {
5611   med_field_type typcha;
5612   std::vector<std::string> infos;
5613   std::string dtunit;
5614   int iii(-1);
5615   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit));
5616   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5617   switch(typcha)
5618   {
5619     case MED_FLOAT64:
5620       {
5621         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5622         break;
5623       }
5624     case MED_INT32:
5625       {
5626         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5627         break;
5628       }
5629     default:
5630       {
5631         std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName,iteration,order) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
5632         throw INTERP_KERNEL::Exception(oss.str());
5633       }
5634   }
5635   ret->setDtUnit(dtunit.c_str());
5636   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5637   //
5638   bool found=false;
5639   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5640   for(int i=0;i<nbOfStep2 && !found;i++)
5641     {
5642       med_int numdt,numit;
5643       med_float dt;
5644       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5645       if(numdt==iteration && numit==order)
5646         {
5647           found=true;
5648           ret->_csit=i+1;
5649         }
5650       else
5651         dtits[i]=std::pair<int,int>(numdt,numit);
5652     }
5653   if(!found)
5654     {
5655       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
5656       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5657         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5658       throw INTERP_KERNEL::Exception(oss.str());
5659     }
5660   if(loadAll)
5661     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5662   else
5663     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5664   return ret.retn();
5665 }
5666
5667 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5668 try:MEDFileFieldGlobsReal(fid)
5669 {
5670   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms);
5671   loadGlobals(fid);
5672 }
5673 catch(INTERP_KERNEL::Exception& e)
5674 {
5675     throw e;
5676 }
5677
5678 /*!
5679  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5680  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5681  *
5682  * \warning this is a shallow copy constructor
5683  */
5684 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5685 {
5686   if(!shallowCopyOfContent)
5687     {
5688       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5689       otherPtr->incrRef();
5690       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5691     }
5692   else
5693     {
5694       _content=other.shallowCpy();
5695     }
5696 }
5697
5698 int MEDFileAnyTypeField1TS::LocateField2(med_idt fid, int fieldIdCFormat, bool checkFieldId, std::string& fieldName, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5699 {
5700   if(checkFieldId)
5701     {
5702       int nbFields=MEDnField(fid);
5703       if(fieldIdCFormat>=nbFields)
5704         {
5705           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5706           throw INTERP_KERNEL::Exception(oss.str());
5707         }
5708     }
5709   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5710   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5711   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5712   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5713   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5714   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5715   med_bool localMesh;
5716   int nbOfStep;
5717   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5718   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5719   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5720   infos.clear(); infos.resize(ncomp);
5721   for(int j=0;j<ncomp;j++)
5722     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5723   return nbOfStep;
5724 }
5725
5726 /*!
5727  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5728  * 
5729  * \param [out]
5730  * \return in case of success the number of time steps available for the field with name \a fieldName.
5731  */
5732 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5733 {
5734   int nbFields=MEDnField(fid);
5735   bool found=false;
5736   std::vector<std::string> fns(nbFields);
5737   int nbOfStep2(-1);
5738   for(int i=0;i<nbFields && !found;i++)
5739     {
5740       std::string tmp;
5741       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut);
5742       fns[i]=tmp;
5743       found=(tmp==fieldName);
5744       if(found)
5745         posCFormat=i;
5746     }
5747   if(!found)
5748     {
5749       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
5750       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5751         oss << "\"" << *it << "\" ";
5752       throw INTERP_KERNEL::Exception(oss.str());
5753     }
5754   return nbOfStep2;
5755 }
5756
5757 /*!
5758  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5759  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5760  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5761  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5762  * to keep a valid instance.
5763  * 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.
5764  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5765  * 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.
5766  *
5767  * \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.
5768  * \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.
5769  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5770  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5771  * \param [in] newLocName is the new localization name.
5772  * \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.
5773  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5774  */
5775 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5776 {
5777   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5778   std::string oldPflName=disc->getProfile();
5779   std::vector<std::string> vv=getPflsReallyUsedMulti();
5780   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5781   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5782     {
5783       disc->setProfile(newPflName);
5784       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5785       pfl->setName(newPflName);
5786     }
5787   else
5788     {
5789       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5790       throw INTERP_KERNEL::Exception(oss.str());
5791     }
5792 }
5793
5794 /*!
5795  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5796  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5797  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5798  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5799  * to keep a valid instance.
5800  * 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.
5801  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5802  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5803  * 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.
5804  *
5805  * \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.
5806  * \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.
5807  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5808  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5809  * \param [in] newLocName is the new localization name.
5810  * \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.
5811  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5812  */
5813 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5814 {
5815   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5816   std::string oldLocName=disc->getLocalization();
5817   std::vector<std::string> vv=getLocsReallyUsedMulti();
5818   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5819   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5820     {
5821       disc->setLocalization(newLocName);
5822       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5823       loc.setName(newLocName);
5824     }
5825   else
5826     {
5827       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5828       throw INTERP_KERNEL::Exception(oss.str());
5829     }
5830 }
5831
5832 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5833 {
5834   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5835   if(!ret)
5836     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5837   return ret;
5838 }
5839
5840 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5841 {
5842   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5843   if(!ret)
5844     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5845   return ret;
5846 }
5847
5848 /*!
5849  * This method alloc the arrays and load potentially huge arrays contained in this field.
5850  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5851  * This method can be also called to refresh or reinit values from a file.
5852  * 
5853  * \throw If the fileName is not set or points to a non readable MED file.
5854  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5855  */
5856 void MEDFileAnyTypeField1TS::loadArrays()
5857 {
5858   if(getFileName().empty())
5859     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5860   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
5861   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5862 }
5863
5864 /*!
5865  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5866  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5867  * this method does not throw if \a this does not come from file read.
5868  * 
5869  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5870  */
5871 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5872 {
5873   if(!getFileName().empty())
5874     {
5875       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
5876       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5877     }
5878 }
5879
5880 /*!
5881  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5882  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5883  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5884  * 
5885  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5886  */
5887 void MEDFileAnyTypeField1TS::unloadArrays()
5888 {
5889   contentNotNullBase()->unloadArrays();
5890 }
5891
5892 /*!
5893  * 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.
5894  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5895  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5896  * 
5897  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5898  */
5899 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5900 {
5901   if(!getFileName().empty())
5902     contentNotNullBase()->unloadArrays();
5903 }
5904
5905 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
5906 {
5907   int nbComp(getNumberOfComponents());
5908   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
5909   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
5910   for(int i=0;i<nbComp;i++)
5911     {
5912       std::string info=getInfo()[i];
5913       std::string c,u;
5914       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
5915       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
5916       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
5917     }
5918   if(getName().empty())
5919     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
5920   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
5921   writeGlobals(fid,*this);
5922   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
5923 }
5924
5925 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
5926 {
5927   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
5928 }
5929
5930 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
5931 {
5932   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
5933   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
5934   return ret;
5935 }
5936
5937 /*!
5938  * Returns a string describing \a this field. This string is outputted 
5939  * by \c print Python command.
5940  */
5941 std::string MEDFileAnyTypeField1TS::simpleRepr() const
5942 {
5943   std::ostringstream oss;
5944   contentNotNullBase()->simpleRepr(0,oss,-1);
5945   simpleReprGlobs(oss);
5946   return oss.str();
5947 }
5948
5949 /*!
5950  * This method returns all profiles whose name is non empty used.
5951  * \b WARNING If profile is used several times it will be reported \b only \b once.
5952  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
5953  */
5954 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
5955 {
5956   return contentNotNullBase()->getPflsReallyUsed2();
5957 }
5958
5959 /*!
5960  * This method returns all localizations whose name is non empty used.
5961  * \b WARNING If localization is used several times it will be reported \b only \b once.
5962  */
5963 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
5964 {
5965   return contentNotNullBase()->getLocsReallyUsed2();
5966 }
5967
5968 /*!
5969  * This method returns all profiles whose name is non empty used.
5970  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
5971  */
5972 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
5973 {
5974   return contentNotNullBase()->getPflsReallyUsedMulti2();
5975 }
5976
5977 /*!
5978  * This method returns all localizations whose name is non empty used.
5979  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
5980  */
5981 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
5982 {
5983   return contentNotNullBase()->getLocsReallyUsedMulti2();
5984 }
5985
5986 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5987 {
5988   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
5989 }
5990
5991 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
5992 {
5993   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
5994 }
5995
5996 int MEDFileAnyTypeField1TS::getDimension() const
5997 {
5998   return contentNotNullBase()->getDimension();
5999 }
6000
6001 int MEDFileAnyTypeField1TS::getIteration() const
6002 {
6003   return contentNotNullBase()->getIteration();
6004 }
6005
6006 int MEDFileAnyTypeField1TS::getOrder() const
6007 {
6008   return contentNotNullBase()->getOrder();
6009 }
6010
6011 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6012 {
6013   return contentNotNullBase()->getTime(iteration,order);
6014 }
6015
6016 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6017 {
6018   contentNotNullBase()->setTime(iteration,order,val);
6019 }
6020
6021 std::string MEDFileAnyTypeField1TS::getName() const
6022 {
6023   return contentNotNullBase()->getName();
6024 }
6025
6026 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6027 {
6028   contentNotNullBase()->setName(name);
6029 }
6030
6031 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6032 {
6033   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6034 }
6035
6036 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6037 {
6038   return contentNotNullBase()->getDtUnit();
6039 }
6040
6041 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6042 {
6043   contentNotNullBase()->setDtUnit(dtUnit);
6044 }
6045
6046 std::string MEDFileAnyTypeField1TS::getMeshName() const
6047 {
6048   return contentNotNullBase()->getMeshName();
6049 }
6050
6051 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6052 {
6053   contentNotNullBase()->setMeshName(newMeshName);
6054 }
6055
6056 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6057 {
6058   return contentNotNullBase()->changeMeshNames(modifTab);
6059 }
6060
6061 int MEDFileAnyTypeField1TS::getMeshIteration() const
6062 {
6063   return contentNotNullBase()->getMeshIteration();
6064 }
6065
6066 int MEDFileAnyTypeField1TS::getMeshOrder() const
6067 {
6068   return contentNotNullBase()->getMeshOrder();
6069 }
6070
6071 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6072 {
6073   return contentNotNullBase()->getNumberOfComponents();
6074 }
6075
6076 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6077 {
6078   return contentNotNullBase()->isDealingTS(iteration,order);
6079 }
6080
6081 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6082 {
6083   return contentNotNullBase()->getDtIt();
6084 }
6085
6086 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6087 {
6088   contentNotNullBase()->fillIteration(p);
6089 }
6090
6091 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6092 {
6093   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6094 }
6095
6096 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6097 {
6098   contentNotNullBase()->setInfo(infos);
6099 }
6100
6101 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6102 {
6103   return contentNotNullBase()->getInfo();
6104 }
6105 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6106 {
6107   return contentNotNullBase()->getInfo();
6108 }
6109
6110 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6111 {
6112   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6113 }
6114
6115 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6116 {
6117   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6118 }
6119
6120 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6121 {
6122   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6123 }
6124
6125 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6126 {
6127   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6128 }
6129
6130 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6131 {
6132   return contentNotNullBase()->getTypesOfFieldAvailable();
6133 }
6134
6135 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,
6136                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6137 {
6138   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6139 }
6140
6141 /*!
6142  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6143  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6144  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6145  */
6146 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6147 {
6148   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6149   if(!content)
6150     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6151   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6152   std::size_t sz(contentsSplit.size());
6153   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6154   for(std::size_t i=0;i<sz;i++)
6155     {
6156       ret[i]=shallowCpy();
6157       ret[i]->_content=contentsSplit[i];
6158     }
6159   return ret;
6160 }
6161
6162 /*!
6163  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6164  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6165  */
6166 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6167 {
6168   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6169   if(!content)
6170     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6171   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6172   std::size_t sz(contentsSplit.size());
6173   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6174   for(std::size_t i=0;i<sz;i++)
6175     {
6176       ret[i]=shallowCpy();
6177       ret[i]->_content=contentsSplit[i];
6178     }
6179   return ret;
6180 }
6181
6182 /*!
6183  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6184  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6185  */
6186 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6187 {
6188   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6189   if(!content)
6190     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6191   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6192   std::size_t sz(contentsSplit.size());
6193   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6194   for(std::size_t i=0;i<sz;i++)
6195     {
6196       ret[i]=shallowCpy();
6197       ret[i]->_content=contentsSplit[i];
6198     }
6199   return ret;
6200 }
6201
6202 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6203 {
6204   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6205   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6206     ret->_content=_content->deepCopy();
6207   ret->deepCpyGlobs(*this);
6208   return ret.retn();
6209 }
6210
6211 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6212 {
6213   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6214 }
6215
6216 //= MEDFileField1TS
6217
6218 /*!
6219  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6220  * the first field that has been read from a specified MED file.
6221  *  \param [in] fileName - the name of the MED file to read.
6222  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6223  *          is to delete this field using decrRef() as it is no more needed.
6224  *  \throw If reading the file fails.
6225  */
6226 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6227 {
6228   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6229   return New(fid,loadAll);
6230 }
6231
6232 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
6233 {
6234   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
6235   ret->contentNotNull();
6236   return ret.retn();
6237 }
6238
6239 /*!
6240  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6241  * a given field that has been read from a specified MED file.
6242  *  \param [in] fileName - the name of the MED file to read.
6243  *  \param [in] fieldName - the name of the field to read.
6244  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6245  *          is to delete this field using decrRef() as it is no more needed.
6246  *  \throw If reading the file fails.
6247  *  \throw If there is no field named \a fieldName in the file.
6248  */
6249 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6250 {
6251   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6252   return New(fid,fieldName,loadAll);
6253 }
6254
6255 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6256 {
6257   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
6258   ret->contentNotNull();
6259   return ret.retn();
6260 }
6261
6262 /*!
6263  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6264  * a given field that has been read from a specified MED file.
6265  *  \param [in] fileName - the name of the MED file to read.
6266  *  \param [in] fieldName - the name of the field to read.
6267  *  \param [in] iteration - the iteration number of a required time step.
6268  *  \param [in] order - the iteration order number of required time step.
6269  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6270  *          is to delete this field using decrRef() as it is no more needed.
6271  *  \throw If reading the file fails.
6272  *  \throw If there is no field named \a fieldName in the file.
6273  *  \throw If the required time step is missing from the file.
6274  */
6275 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6276 {
6277   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6278   return New(fid,fieldName,iteration,order,loadAll);
6279 }
6280
6281 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6282 {
6283   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
6284   ret->contentNotNull();
6285   return ret.retn();
6286 }
6287
6288 /*!
6289  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6290  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6291  *
6292  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6293  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6294  * \warning this is a shallow copy constructor
6295  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6296  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6297  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6298  *          is to delete this field using decrRef() as it is no more needed.
6299  */
6300 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6301 {
6302   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6303   ret->contentNotNull();
6304   return ret.retn();
6305 }
6306
6307 /*!
6308  * Returns a new empty instance of MEDFileField1TS.
6309  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6310  *          is to delete this field using decrRef() as it is no more needed.
6311  */
6312 MEDFileField1TS *MEDFileField1TS::New()
6313 {
6314   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6315   ret->contentNotNull();
6316   return ret.retn();
6317 }
6318
6319 /*!
6320  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6321  * following the given input policy.
6322  *
6323  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6324  *                            By default (true) the globals are deeply copied.
6325  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6326  */
6327 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6328 {
6329   MCAuto<MEDFileIntField1TS> ret;
6330   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6331   if(content)
6332     {
6333       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6334       if(!contc)
6335         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6336       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6337       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6338     }
6339   else
6340     ret=MEDFileIntField1TS::New();
6341   if(isDeepCpyGlobs)
6342     ret->deepCpyGlobs(*this);
6343   else
6344     ret->shallowCpyGlobs(*this);
6345   return ret.retn();
6346 }
6347
6348 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6349 {
6350   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6351   if(!pt)
6352     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6353   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6354   if(!ret)
6355     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 !");
6356   return ret;
6357 }
6358
6359 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6360 {
6361   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6362   if(!pt)
6363     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6364   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6365   if(!ret)
6366     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 !");
6367   return ret;
6368 }
6369
6370 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6371 {
6372   if(!f)
6373     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6374   if(arr.isNull())
6375     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6376   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6377   if(!arrOutC)
6378     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6379   f->setArray(arrOutC);
6380 }
6381
6382 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6383 {
6384   if(arr.isNull())
6385     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6386   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6387   if(!arrOutC)
6388     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6389   arrOutC->incrRef();
6390   return arrOutC;
6391 }
6392
6393 /*!
6394  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6395  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6396  *
6397  * \return A new object that the caller is responsible to deallocate.
6398  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6399  */
6400 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6401 {
6402   if(!mm)
6403     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6404   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6405   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6406   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6407     {
6408       if((*it0)!=ON_NODES)
6409         {
6410           std::vector<int> levs;
6411           getNonEmptyLevels(mm->getName(),levs);
6412           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6413             {
6414               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6415               if(it2!=extractDef.end())
6416                 {
6417                   MCAuto<DataArrayInt> t((*it2).second);
6418                   if(t.isNull())
6419                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6420                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6421                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6422                   ret->setFieldNoProfileSBT(fOut);
6423                 }
6424             }
6425         }
6426       else
6427         {
6428           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6429           if(it2==extractDef.end())
6430             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6431           MCAuto<DataArrayInt> t((*it2).second);
6432           if(t.isNull())
6433             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6434           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6435           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6436           DataArrayDouble *arr(f->getArray());
6437           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6438           fOut->setArray(newArr);
6439           ret->setFieldNoProfileSBT(fOut);
6440         }
6441     }
6442   return ret.retn();
6443 }
6444
6445 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6446 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6447 {
6448 }
6449 catch(INTERP_KERNEL::Exception& e)
6450 { throw e; }
6451
6452 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6453 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6454 {
6455 }
6456 catch(INTERP_KERNEL::Exception& e)
6457 { throw e; }
6458
6459 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6460 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6461 {
6462 }
6463 catch(INTERP_KERNEL::Exception& e)
6464 { throw e; }
6465
6466 /*!
6467  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6468  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6469  *
6470  * \warning this is a shallow copy constructor
6471  */
6472 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6473 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6474 {
6475 }
6476 catch(INTERP_KERNEL::Exception& e)
6477 { throw e; }
6478
6479 MEDFileField1TS::MEDFileField1TS()
6480 {
6481   _content=new MEDFileField1TSWithoutSDA;
6482 }
6483
6484 /*!
6485  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
6486  * method should be called (getFieldOnMeshAtLevel for example).
6487  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6488  *
6489  * \param [in] mesh - the mesh the field is lying on
6490  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6491  *          caller is to delete this field using decrRef() as it is no more needed. 
6492  */
6493 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6494 {
6495   MCAuto<DataArray> arrOut;
6496   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6497   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6498   return ret.retn();
6499 }
6500
6501 /*!
6502  * Returns a new MEDCouplingFieldDouble of a given type lying on
6503  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6504  * has not been constructed via file reading, an exception is thrown.
6505  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6506  *  \param [in] type - a spatial discretization of interest.
6507  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6508  *  \param [in] renumPol - specifies how to permute values of the result field according to
6509  *          the optional numbers of cells and nodes, if any. The valid values are
6510  *          - 0 - do not permute.
6511  *          - 1 - permute cells.
6512  *          - 2 - permute nodes.
6513  *          - 3 - permute cells and nodes.
6514  *
6515  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6516  *          caller is to delete this field using decrRef() as it is no more needed. 
6517  *  \throw If \a this field has not been constructed via file reading.
6518  *  \throw If the MED file is not readable.
6519  *  \throw If there is no mesh in the MED file.
6520  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6521  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6522  *  \sa getFieldOnMeshAtLevel()
6523  */
6524 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6525 {
6526   if(getFileName().empty())
6527     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6528   MCAuto<DataArray> arrOut;
6529   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6530   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6531   return ret.retn();
6532 }
6533
6534 /*!
6535  * Returns a new MEDCouplingFieldDouble of a given type lying on
6536  * the top level cells of the first mesh in MED file. If \a this field 
6537  * has not been constructed via file reading, an exception is thrown.
6538  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6539  *  \param [in] type - a spatial discretization of interest.
6540  *  \param [in] renumPol - specifies how to permute values of the result field according to
6541  *          the optional numbers of cells and nodes, if any. The valid values are
6542  *          - 0 - do not permute.
6543  *          - 1 - permute cells.
6544  *          - 2 - permute nodes.
6545  *          - 3 - permute cells and nodes.
6546  *
6547  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6548  *          caller is to delete this field using decrRef() as it is no more needed. 
6549  *  \throw If \a this field has not been constructed via file reading.
6550  *  \throw If the MED file is not readable.
6551  *  \throw If there is no mesh in the MED file.
6552  *  \throw If no field values of the given \a type.
6553  *  \throw If no field values lying on the top level support.
6554  *  \sa getFieldAtLevel()
6555  */
6556 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6557 {
6558   if(getFileName().empty())
6559     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6560   MCAuto<DataArray> arrOut;
6561   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6562   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6563   return ret.retn();
6564 }
6565
6566 /*!
6567  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6568  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6569  *  \param [in] type - a spatial discretization of the new field.
6570  *  \param [in] mesh - the supporting mesh.
6571  *  \param [in] renumPol - specifies how to permute values of the result field according to
6572  *          the optional numbers of cells and nodes, if any. The valid values are
6573  *          - 0 - do not permute.
6574  *          - 1 - permute cells.
6575  *          - 2 - permute nodes.
6576  *          - 3 - permute cells and nodes.
6577  *
6578  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6579  *          caller is to delete this field using decrRef() as it is no more needed. 
6580  *  \throw If no field of \a this is lying on \a mesh.
6581  *  \throw If the mesh is empty.
6582  *  \throw If no field values of the given \a type are available.
6583  *  \sa getFieldAtLevel()
6584  *  \sa getFieldOnMeshAtLevel() 
6585  */
6586 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6587 {
6588   MCAuto<DataArray> arrOut;
6589   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
6590   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6591   return ret.retn();
6592 }
6593
6594 /*!
6595  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6596  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6597  *  \param [in] type - a spatial discretization of interest.
6598  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6599  *  \param [in] mesh - the supporting mesh.
6600  *  \param [in] renumPol - specifies how to permute values of the result field according to
6601  *          the optional numbers of cells and nodes, if any. The valid values are
6602  *          - 0 - do not permute.
6603  *          - 1 - permute cells.
6604  *          - 2 - permute nodes.
6605  *          - 3 - permute cells and nodes.
6606  *
6607  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6608  *          caller is to delete this field using decrRef() as it is no more needed. 
6609  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6610  *  \throw If no field of \a this is lying on \a mesh.
6611  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6612  *  \sa getFieldAtLevel()
6613  *  \sa getFieldOnMeshAtLevel() 
6614  */
6615 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6616 {
6617   MCAuto<DataArray> arrOut;
6618   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
6619   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6620   return ret.retn();
6621 }
6622
6623 /*!
6624  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6625  * This method is called "Old" because in MED3 norm a field has only one meshName
6626  * attached, so this method is for readers of MED2 files. If \a this field 
6627  * has not been constructed via file reading, an exception is thrown.
6628  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6629  *  \param [in] type - a spatial discretization of interest.
6630  *  \param [in] mName - a name of the supporting mesh.
6631  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6632  *  \param [in] renumPol - specifies how to permute values of the result field according to
6633  *          the optional numbers of cells and nodes, if any. The valid values are
6634  *          - 0 - do not permute.
6635  *          - 1 - permute cells.
6636  *          - 2 - permute nodes.
6637  *          - 3 - permute cells and nodes.
6638  *
6639  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6640  *          caller is to delete this field using decrRef() as it is no more needed. 
6641  *  \throw If the MED file is not readable.
6642  *  \throw If there is no mesh named \a mName in the MED file.
6643  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6644  *  \throw If \a this field has not been constructed via file reading.
6645  *  \throw If no field of \a this is lying on the mesh named \a mName.
6646  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6647  *  \sa getFieldAtLevel()
6648  */
6649 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6650 {
6651   if(getFileName().empty())
6652     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6653   MCAuto<DataArray> arrOut;
6654   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
6655   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6656   return ret.retn();
6657 }
6658
6659 /*!
6660  * Returns values and a profile of the field of a given type lying on a given support.
6661  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6662  *  \param [in] type - a spatial discretization of the field.
6663  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6664  *  \param [in] mesh - the supporting mesh.
6665  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6666  *          field of interest lies on. If the field lies on all entities of the given
6667  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6668  *          using decrRef() as it is no more needed.  
6669  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6670  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6671  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6672  *  \throw If no field of \a this is lying on \a mesh.
6673  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6674  */
6675 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6676 {
6677   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6678   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6679 }
6680
6681 /*!
6682  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6683  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6684  * "Sort By Type"), if not, an exception is thrown. 
6685  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6686  *  \param [in] field - the field to add to \a this.
6687  *  \throw If the name of \a field is empty.
6688  *  \throw If the data array of \a field is not set.
6689  *  \throw If the data array is already allocated but has different number of components
6690  *         than \a field.
6691  *  \throw If the underlying mesh of \a field has no name.
6692  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6693  */
6694 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6695 {
6696   setFileName("");
6697   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6698 }
6699
6700 /*!
6701  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6702  * can be an aggregation of several MEDCouplingFieldDouble instances.
6703  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6704  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6705  * and \a profile.
6706  *
6707  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6708  * A new profile is added only if no equal profile is missing.
6709  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6710  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6711  *  \param [in] mesh - the supporting mesh of \a field.
6712  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6713  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6714  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6715  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6716  *  \throw If the data array of \a field is not set.
6717  *  \throw If the data array of \a this is already allocated but has different number of
6718  *         components than \a field.
6719  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6720  *  \sa setFieldNoProfileSBT()
6721  */
6722 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6723 {
6724   setFileName("");
6725   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6726 }
6727
6728 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6729 {
6730   return new MEDFileField1TS(*this);
6731 }
6732
6733 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6734 {
6735   return contentNotNull()->getUndergroundDataArrayTemplate();
6736 }
6737
6738 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6739 {
6740   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6741 }
6742
6743 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6744                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6745 {
6746   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6747 }
6748
6749 //= MEDFileIntField1TS
6750
6751 MEDFileIntField1TS *MEDFileIntField1TS::New()
6752 {
6753   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
6754   ret->contentNotNull();
6755   return ret.retn();
6756 }
6757
6758 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6759 {
6760   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6761   return MEDFileIntField1TS::New(fid,loadAll);
6762 }
6763
6764 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
6765 {
6766   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
6767   ret->contentNotNull();
6768   return ret.retn();
6769 }
6770
6771 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6772 {
6773   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6774   return MEDFileIntField1TS::New(fid,fieldName,loadAll);
6775 }
6776
6777 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6778 {
6779   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
6780   ret->contentNotNull();
6781   return ret.retn();
6782 }
6783
6784 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6785 {
6786   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6787   return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
6788 }
6789
6790 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6791 {
6792   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
6793   ret->contentNotNull();
6794   return ret.retn();
6795 }
6796
6797 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6798 {
6799   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6800   ret->contentNotNull();
6801   return ret.retn();
6802 }
6803
6804 MEDFileIntField1TS::MEDFileIntField1TS()
6805 {
6806   _content=new MEDFileIntField1TSWithoutSDA;
6807 }
6808
6809 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6810 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6811 {
6812 }
6813 catch(INTERP_KERNEL::Exception& e)
6814 { throw e; }
6815
6816 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6817 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6818 {
6819 }
6820 catch(INTERP_KERNEL::Exception& e)
6821 { throw e; }
6822
6823 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6824 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6825 {
6826 }
6827 catch(INTERP_KERNEL::Exception& e)
6828 { throw e; }
6829
6830 /*!
6831  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6832  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6833  *
6834  * \warning this is a shallow copy constructor
6835  */
6836 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6837 {
6838 }
6839
6840 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6841 {
6842   return new MEDFileIntField1TS(*this);
6843 }
6844
6845 /*!
6846  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6847  * following the given input policy.
6848  *
6849  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6850  *                            By default (true) the globals are deeply copied.
6851  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6852  */
6853 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6854 {
6855   MCAuto<MEDFileField1TS> ret;
6856   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6857   if(content)
6858     {
6859       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6860       if(!contc)
6861         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6862       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6863       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
6864     }
6865   else
6866     ret=MEDFileField1TS::New();
6867   if(isDeepCpyGlobs)
6868     ret->deepCpyGlobs(*this);
6869   else
6870     ret->shallowCpyGlobs(*this);
6871   return ret.retn();
6872 }
6873
6874 /*!
6875  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
6876  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6877  * "Sort By Type"), if not, an exception is thrown. 
6878  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6879  *  \param [in] field - the field to add to \a this.
6880  *  \throw If the name of \a field is empty.
6881  *  \throw If the data array of \a field is not set.
6882  *  \throw If the data array is already allocated but has different number of components
6883  *         than \a field.
6884  *  \throw If the underlying mesh of \a field has no name.
6885  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6886  */
6887 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
6888 {
6889   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
6890   setFileName("");
6891   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
6892 }
6893
6894 /*!
6895  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6896  * can be an aggregation of several MEDCouplingFieldDouble instances.
6897  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6898  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6899  * and \a profile.
6900  *
6901  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6902  * A new profile is added only if no equal profile is missing.
6903  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6904  *  \param [in] field - the field to add to \a this.
6905  *  \param [in] mesh - the supporting mesh of \a field.
6906  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6907  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6908  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6909  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6910  *  \throw If the data array of \a field is not set.
6911  *  \throw If the data array of \a this is already allocated but has different number of
6912  *         components than \a field.
6913  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6914  *  \sa setFieldNoProfileSBT()
6915  */
6916 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6917 {
6918   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
6919   setFileName("");
6920   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6921 }
6922
6923 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
6924 {
6925   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6926   if(!pt)
6927     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
6928   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
6929   if(!ret)
6930     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 !");
6931   return ret;
6932 }
6933
6934 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6935 {
6936   if(getFileName().empty())
6937     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6938   MCAuto<DataArray> arrOut;
6939   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6940   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
6941   return ret2.retn();
6942 }
6943
6944 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
6945 {
6946   if(arr.isNull())
6947     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
6948   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
6949   if(!arrC)
6950     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
6951   arrC->incrRef();
6952   return arrC;
6953 }
6954
6955 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6956 {
6957   int t1,t2;
6958   double t0(f->getTime(t1,t2));
6959   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
6960   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
6961   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
6962   ret->setTime(t0,t1,t2); ret->setArray(arr2);
6963   return ret.retn();
6964 }
6965
6966 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
6967 {
6968   if(!f)
6969     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
6970   int t1,t2;
6971   double t0(f->getTime(t1,t2));
6972   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
6973   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
6974   ret->setTime(t0,t1,t2);
6975   return ret;
6976 }
6977
6978 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6979 {
6980   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
6981 }
6982
6983 /*!
6984  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
6985  * method should be called (getFieldOnMeshAtLevel for example).
6986  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6987  *
6988  * \param [in] mesh - the mesh the field is lying on
6989  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
6990  *          caller is to delete this field using decrRef() as it is no more needed. 
6991  */
6992 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
6993 {
6994   MCAuto<DataArray> arrOut;
6995   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6996   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
6997   return ret2.retn();
6998 }
6999
7000 /*!
7001  * Returns a new MEDCouplingFieldInt of a given type lying on
7002  * the top level cells of the first mesh in MED file. If \a this field 
7003  * has not been constructed via file reading, an exception is thrown.
7004  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7005  *  \param [in] type - a spatial discretization of interest.
7006  *  \param [in] renumPol - specifies how to permute values of the result field according to
7007  *          the optional numbers of cells and nodes, if any. The valid values are
7008  *          - 0 - do not permute.
7009  *          - 1 - permute cells.
7010  *          - 2 - permute nodes.
7011  *          - 3 - permute cells and nodes.
7012  *
7013  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7014  *          caller is to delete this field using decrRef() as it is no more needed. 
7015  *  \throw If \a this field has not been constructed via file reading.
7016  *  \throw If the MED file is not readable.
7017  *  \throw If there is no mesh in the MED file.
7018  *  \throw If no field values of the given \a type.
7019  *  \throw If no field values lying on the top level support.
7020  *  \sa getFieldAtLevel()
7021  */
7022 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7023 {
7024   if(getFileName().empty())
7025     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7026   MCAuto<DataArray> arrOut;
7027   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7028   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7029   return ret2.retn();
7030 }
7031
7032 /*!
7033  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
7034  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7035  *  \param [in] type - a spatial discretization of the new field.
7036  *  \param [in] mesh - the supporting mesh.
7037  *  \param [in] renumPol - specifies how to permute values of the result field according to
7038  *          the optional numbers of cells and nodes, if any. The valid values are
7039  *          - 0 - do not permute.
7040  *          - 1 - permute cells.
7041  *          - 2 - permute nodes.
7042  *          - 3 - permute cells and nodes.
7043  *
7044  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7045  *          caller is to delete this field using decrRef() as it is no more needed. 
7046  *  \throw If no field of \a this is lying on \a mesh.
7047  *  \throw If the mesh is empty.
7048  *  \throw If no field values of the given \a type are available.
7049  *  \sa getFieldAtLevel()
7050  *  \sa getFieldOnMeshAtLevel() 
7051  */
7052 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7053 {
7054   MCAuto<DataArray> arrOut;
7055   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7056   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7057   return ret2.retn();
7058 }
7059
7060 /*!
7061  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7062  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7063  *  \param [in] type - a spatial discretization of interest.
7064  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7065  *  \param [in] mesh - the supporting mesh.
7066  *  \param [in] renumPol - specifies how to permute values of the result field according to
7067  *          the optional numbers of cells and nodes, if any. The valid values are
7068  *          - 0 - do not permute.
7069  *          - 1 - permute cells.
7070  *          - 2 - permute nodes.
7071  *          - 3 - permute cells and nodes.
7072  *
7073  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7074  *          caller is to delete this field using decrRef() as it is no more needed. 
7075  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7076  *  \throw If no field of \a this is lying on \a mesh.
7077  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7078  *  \sa getFieldAtLevel()
7079  *  \sa getFieldOnMeshAtLevel() 
7080  */
7081 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7082 {
7083   MCAuto<DataArray> arrOut;
7084   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7085   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7086   return ret2.retn();
7087 }
7088
7089 /*!
7090  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7091  * This method is called "Old" because in MED3 norm a field has only one meshName
7092  * attached, so this method is for readers of MED2 files. If \a this field 
7093  * has not been constructed via file reading, an exception is thrown.
7094  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7095  *  \param [in] type - a spatial discretization of interest.
7096  *  \param [in] mName - a name of the supporting mesh.
7097  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7098  *  \param [in] renumPol - specifies how to permute values of the result field according to
7099  *          the optional numbers of cells and nodes, if any. The valid values are
7100  *          - 0 - do not permute.
7101  *          - 1 - permute cells.
7102  *          - 2 - permute nodes.
7103  *          - 3 - permute cells and nodes.
7104  *
7105  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7106  *          caller is to delete this field using decrRef() as it is no more needed. 
7107  *  \throw If the MED file is not readable.
7108  *  \throw If there is no mesh named \a mName in the MED file.
7109  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7110  *  \throw If \a this field has not been constructed via file reading.
7111  *  \throw If no field of \a this is lying on the mesh named \a mName.
7112  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7113  *  \sa getFieldAtLevel()
7114  */
7115 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7116 {
7117   if(getFileName().empty())
7118     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7119   MCAuto<DataArray> arrOut;
7120   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7121   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7122   return ret2.retn();
7123 }
7124
7125 /*!
7126  * Returns values and a profile of the field of a given type lying on a given support.
7127  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7128  *  \param [in] type - a spatial discretization of the field.
7129  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7130  *  \param [in] mesh - the supporting mesh.
7131  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7132  *          field of interest lies on. If the field lies on all entities of the given
7133  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7134  *          using decrRef() as it is no more needed.  
7135  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7136  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7137  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7138  *  \throw If no field of \a this is lying on \a mesh.
7139  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7140  */
7141 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7142 {
7143   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7144   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7145 }
7146
7147 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7148 {
7149   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7150   if(!pt)
7151     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7152   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7153   if(!ret)
7154     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 !");
7155   return ret;
7156 }
7157
7158 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7159 {
7160   return contentNotNull()->getUndergroundDataArrayTemplate();
7161 }
7162
7163 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7164
7165 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7166 {
7167 }
7168
7169 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7170 {
7171 }
7172
7173 /*!
7174  * \param [in] fieldId field id in C mode
7175  */
7176 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7177 {
7178   med_field_type typcha;
7179   std::string dtunitOut;
7180   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut));
7181   setDtUnit(dtunitOut.c_str());
7182   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7183 }
7184
7185 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7186 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7187 {
7188   setDtUnit(dtunit.c_str());
7189   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7190 }
7191 catch(INTERP_KERNEL::Exception& e)
7192 {
7193     throw e;
7194 }
7195
7196 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7197 {
7198   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7199   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7200     ret+=(*it).capacity();
7201   return ret;
7202 }
7203
7204 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7205 {
7206   std::vector<const BigMemoryObject *> ret;
7207   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7208     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7209   return ret;
7210 }
7211
7212 /*!
7213  * 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
7214  * NULL.
7215  */
7216 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7217 {
7218   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7219   ret->setInfo(_infos);
7220   int sz=(int)_time_steps.size();
7221   for(const int *id=startIds;id!=endIds;id++)
7222     {
7223       if(*id>=0 && *id<sz)
7224         {
7225           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7226           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7227           if(tse)
7228             {
7229               tse->incrRef();
7230               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7231             }
7232           ret->pushBackTimeStep(tse2);
7233         }
7234       else
7235         {
7236           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7237           oss << " ! Should be in [0," << sz << ") !";
7238           throw INTERP_KERNEL::Exception(oss.str());
7239         }
7240     }
7241   if(ret->getNumberOfTS()>0)
7242     ret->synchronizeNameScope();
7243   ret->copyNameScope(*this);
7244   return ret.retn();
7245 }
7246
7247 /*!
7248  * 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
7249  * NULL.
7250  */
7251 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7252 {
7253   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7254   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7255   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7256   ret->setInfo(_infos);
7257   int sz=(int)_time_steps.size();
7258   int j=bg;
7259   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7260     {
7261       if(j>=0 && j<sz)
7262         {
7263           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7264           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7265           if(tse)
7266             {
7267               tse->incrRef();
7268               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7269             }
7270           ret->pushBackTimeStep(tse2);
7271         }
7272       else
7273         {
7274           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7275           oss << " ! Should be in [0," << sz << ") !";
7276           throw INTERP_KERNEL::Exception(oss.str());
7277         }
7278     }
7279   if(ret->getNumberOfTS()>0)
7280     ret->synchronizeNameScope();
7281   ret->copyNameScope(*this);
7282   return ret.retn();
7283 }
7284
7285 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7286 {
7287   int id=0;
7288   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7289   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7290     {
7291       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7292       if(!cur)
7293         continue;
7294       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7295       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7296         ids->pushBackSilent(id);
7297     }
7298   return buildFromTimeStepIds(ids->begin(),ids->end());
7299 }
7300
7301 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7302 {
7303   int id=0;
7304   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7305   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7306     {
7307       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7308       if(!cur)
7309         continue;
7310       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7311       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7312         ids->pushBackSilent(id);
7313     }
7314   return buildFromTimeStepIds(ids->begin(),ids->end());
7315 }
7316
7317 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7318 {
7319   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7320     {
7321       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7322       if(!cur)
7323         continue;
7324       if(cur->presenceOfMultiDiscPerGeoType())
7325         return true;
7326     }
7327   return false;
7328 }
7329
7330 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7331 {
7332   return _infos;
7333 }
7334
7335 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7336 {
7337   _infos=info;
7338 }
7339
7340 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7341 {
7342   int ret=0;
7343   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7344     {
7345       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7346       if(pt->isDealingTS(iteration,order))
7347         return ret;
7348     }
7349   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7350   std::vector< std::pair<int,int> > vp=getIterations();
7351   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7352     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7353   throw INTERP_KERNEL::Exception(oss.str());
7354 }
7355
7356 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7357 {
7358   return *_time_steps[getTimeStepPos(iteration,order)];
7359 }
7360
7361 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7362 {
7363   return *_time_steps[getTimeStepPos(iteration,order)];
7364 }
7365
7366 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7367 {
7368   if(_time_steps.empty())
7369     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7370   return _time_steps[0]->getMeshName();
7371 }
7372
7373 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7374 {
7375   std::string oldName(getMeshName());
7376   std::vector< std::pair<std::string,std::string> > v(1);
7377   v[0].first=oldName; v[0].second=newMeshName;
7378   changeMeshNames(v);
7379 }
7380
7381 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7382 {
7383   bool ret=false;
7384   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7385     {
7386       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7387       if(cur)
7388         ret=cur->changeMeshNames(modifTab) || ret;
7389     }
7390   return ret;
7391 }
7392
7393 /*!
7394  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7395  */
7396 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7397 {
7398   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7399 }
7400
7401 /*!
7402  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7403  */
7404 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7405 {
7406   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7407 }
7408
7409 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7410                                                                        MEDFileFieldGlobsReal& glob)
7411 {
7412   bool ret=false;
7413   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7414     {
7415       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7416       if(f1ts)
7417         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7418     }
7419   return ret;
7420 }
7421
7422 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7423 {
7424   std::string startLine(bkOffset,' ');
7425   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7426   if(fmtsId>=0)
7427     oss << " (" << fmtsId << ")";
7428   oss << " has the following name: \"" << _name << "\"." << std::endl;
7429   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7430   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7431     {
7432       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7433     }
7434   int i=0;
7435   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7436     {
7437       std::string chapter(17,'0'+i);
7438       oss << startLine << chapter << std::endl;
7439       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7440       if(cur)
7441         cur->simpleRepr(bkOffset+2,oss,i);
7442       else
7443         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7444       oss << startLine << chapter << std::endl;
7445     }
7446 }
7447
7448 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7449 {
7450   std::size_t sz=_time_steps.size();
7451   std::vector< std::pair<int,int> > ret(sz);
7452   ret1.resize(sz);
7453   for(std::size_t i=0;i<sz;i++)
7454     {
7455       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7456       if(f1ts)
7457         {
7458           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7459         }
7460       else
7461         {
7462           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7463           throw INTERP_KERNEL::Exception(oss.str());
7464         }
7465     }
7466   return ret;
7467 }
7468
7469 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7470 {
7471   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7472   if(!tse2)
7473     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7474   checkCoherencyOfType(tse2);
7475   if(_time_steps.empty())
7476     {
7477       setName(tse2->getName().c_str());
7478       setInfo(tse2->getInfo());
7479     }
7480   checkThatComponentsMatch(tse2->getInfo());
7481   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7482     setDtUnit(tse->getDtUnit());
7483   _time_steps.push_back(tse);
7484 }
7485
7486 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7487 {
7488   std::size_t nbOfCompo=_infos.size();
7489   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7490     {
7491       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7492       if(cur)
7493         {
7494           if((cur->getInfo()).size()!=nbOfCompo)
7495             {
7496               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7497               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7498               throw INTERP_KERNEL::Exception(oss.str());
7499             }
7500           cur->copyNameScope(*this);
7501         }
7502     }
7503 }
7504
7505 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7506 {
7507   _time_steps.resize(nbPdt);
7508   for(int i=0;i<nbPdt;i++)
7509     {
7510       std::vector< std::pair<int,int> > ts;
7511       med_int numdt=0,numo=0;
7512       med_float dt=0.0;
7513       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7514       switch(fieldTyp)
7515       {
7516         case MED_FLOAT64:
7517           {
7518             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7519             break;
7520           }
7521         case MED_INT32:
7522           {
7523             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7524             break;
7525           }
7526         default:
7527           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7528       }
7529       if(loadAll)
7530         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7531       else
7532         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7533       synchronizeNameScope();
7534     }
7535 }
7536
7537 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7538 {
7539   if(_time_steps.empty())
7540     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7541   checkThatNbOfCompoOfTSMatchThis();
7542   std::vector<std::string> infos(getInfo());
7543   int nbComp=infos.size();
7544   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7545   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7546   for(int i=0;i<nbComp;i++)
7547     {
7548       std::string info=infos[i];
7549       std::string c,u;
7550       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7551       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7552       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7553     }
7554   if(_name.empty())
7555     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7556   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7557   int nbOfTS=_time_steps.size();
7558   for(int i=0;i<nbOfTS;i++)
7559     _time_steps[i]->writeLL(fid,opts,*this);
7560 }
7561
7562 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7563 {
7564   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7565     {
7566       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7567       if(elt)
7568         elt->loadBigArraysRecursively(fid,nasc);
7569     }
7570 }
7571
7572 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7573 {
7574   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7575     {
7576       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7577       if(elt)
7578         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7579     }
7580 }
7581
7582 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7583 {
7584   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7585     {
7586       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7587       if(elt)
7588         elt->unloadArrays();
7589     }
7590 }
7591
7592 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7593 {
7594   return _time_steps.size();
7595 }
7596
7597 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7598 {
7599   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7600   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7601     {
7602       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7603       if(tmp)
7604         newTS.push_back(*it);
7605     }
7606   _time_steps=newTS;
7607 }
7608
7609 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7610 {
7611   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7612   int maxId=(int)_time_steps.size();
7613   int ii=0;
7614   std::set<int> idsToDel;
7615   for(const int *id=startIds;id!=endIds;id++,ii++)
7616     {
7617       if(*id>=0 && *id<maxId)
7618         {
7619           idsToDel.insert(*id);
7620         }
7621       else
7622         {
7623           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7624           throw INTERP_KERNEL::Exception(oss.str());
7625         }
7626     }
7627   for(int iii=0;iii<maxId;iii++)
7628     if(idsToDel.find(iii)==idsToDel.end())
7629       newTS.push_back(_time_steps[iii]);
7630   _time_steps=newTS;
7631 }
7632
7633 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7634 {
7635   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7636   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7637   if(nbOfEntriesToKill==0)
7638     return ;
7639   std::size_t sz=_time_steps.size();
7640   std::vector<bool> b(sz,true);
7641   int j=bg;
7642   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7643     b[j]=false;
7644   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7645   for(std::size_t i=0;i<sz;i++)
7646     if(b[i])
7647       newTS.push_back(_time_steps[i]);
7648   _time_steps=newTS;
7649 }
7650
7651 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7652 {
7653   int ret=0;
7654   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7655   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7656     {
7657       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7658       if(tmp)
7659         {
7660           int it2,ord;
7661           tmp->getTime(it2,ord);
7662           if(it2==iteration && order==ord)
7663             return ret;
7664           else
7665             oss << "(" << it2 << ","  << ord << "), ";
7666         }
7667     }
7668   throw INTERP_KERNEL::Exception(oss.str());
7669 }
7670
7671 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7672 {
7673   int ret=0;
7674   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7675   oss.precision(15);
7676   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7677     {
7678       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7679       if(tmp)
7680         {
7681           int it2,ord;
7682           double ti=tmp->getTime(it2,ord);
7683           if(fabs(time-ti)<eps)
7684             return ret;
7685           else
7686             oss << ti << ", ";
7687         }
7688     }
7689   throw INTERP_KERNEL::Exception(oss.str());
7690 }
7691
7692 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7693 {
7694   int lgth=_time_steps.size();
7695   std::vector< std::pair<int,int> > ret(lgth);
7696   for(int i=0;i<lgth;i++)
7697     _time_steps[i]->fillIteration(ret[i]);
7698   return ret;
7699 }
7700
7701 /*!
7702  * 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'
7703  * This method returns two things.
7704  * - The absolute dimension of 'this' in first parameter. 
7705  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7706  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7707  *
7708  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7709  * Only these 3 discretizations will be taken into account here.
7710  *
7711  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7712  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7713  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7714  *
7715  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7716  * 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'.
7717  * 
7718  * Let's consider the typical following case :
7719  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7720  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7721  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7722  *   TETRA4 and SEG2
7723  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7724  *
7725  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7726  * 
7727  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7728  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7729  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7730  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7731  */
7732 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7733 {
7734   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7735 }
7736
7737 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7738 {
7739   if(pos<0 || pos>=(int)_time_steps.size())
7740     {
7741       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7742       throw INTERP_KERNEL::Exception(oss.str());
7743     }
7744   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7745   if(item==0)
7746     {
7747       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7748       oss << "\nTry to use following method eraseEmptyTS !";
7749       throw INTERP_KERNEL::Exception(oss.str());
7750     }
7751   return item;
7752 }
7753
7754 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7755 {
7756   if(pos<0 || pos>=(int)_time_steps.size())
7757     {
7758       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7759       throw INTERP_KERNEL::Exception(oss.str());
7760     }
7761   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7762   if(item==0)
7763     {
7764       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7765       oss << "\nTry to use following method eraseEmptyTS !";
7766       throw INTERP_KERNEL::Exception(oss.str());
7767     }
7768   return item;
7769 }
7770
7771 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7772 {
7773   std::vector<std::string> ret;
7774   std::set<std::string> ret2;
7775   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7776     {
7777       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7778       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7779         if(ret2.find(*it2)==ret2.end())
7780           {
7781             ret.push_back(*it2);
7782             ret2.insert(*it2);
7783           }
7784     }
7785   return ret;
7786 }
7787
7788 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7789 {
7790   std::vector<std::string> ret;
7791   std::set<std::string> ret2;
7792   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7793     {
7794       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7795       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7796         if(ret2.find(*it2)==ret2.end())
7797           {
7798             ret.push_back(*it2);
7799             ret2.insert(*it2);
7800           }
7801     }
7802   return ret;
7803 }
7804
7805 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7806 {
7807   std::vector<std::string> ret;
7808   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7809     {
7810       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7811       ret.insert(ret.end(),tmp.begin(),tmp.end());
7812     }
7813   return ret;
7814 }
7815
7816 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7817 {
7818   std::vector<std::string> ret;
7819   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7820     {
7821       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7822       ret.insert(ret.end(),tmp.begin(),tmp.end());
7823     }
7824   return ret;
7825 }
7826
7827 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7828 {
7829   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7830     (*it)->changePflsRefsNamesGen2(mapOfModif);
7831 }
7832
7833 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7834 {
7835   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7836     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7837 }
7838
7839 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7840 {
7841   int lgth=_time_steps.size();
7842   std::vector< std::vector<TypeOfField> > ret(lgth);
7843   for(int i=0;i<lgth;i++)
7844     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7845   return ret;
7846 }
7847
7848 /*!
7849  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7850  */
7851 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
7852 {
7853   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7854 }
7855
7856 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7857 {
7858   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7859   std::size_t i=0;
7860   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7861     {
7862       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7863         ret->_time_steps[i]=(*it)->deepCopy();
7864     }
7865   return ret.retn();
7866 }
7867
7868 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7869 {
7870   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7871   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7872   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7873   for(std::size_t i=0;i<sz;i++)
7874     {
7875       ret[i]=shallowCpy();
7876       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7877     }
7878   for(std::size_t i=0;i<sz2;i++)
7879     {
7880       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7881       if(ret1.size()!=sz)
7882         {
7883           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7884           throw INTERP_KERNEL::Exception(oss.str());
7885         }
7886       ts[i]=ret1;
7887     }
7888   for(std::size_t i=0;i<sz;i++)
7889     for(std::size_t j=0;j<sz2;j++)
7890       ret[i]->_time_steps[j]=ts[j][i];
7891   return ret;
7892 }
7893
7894 /*!
7895  * This method splits into discretization each time steps in \a this.
7896  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7897  */
7898 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7899 {
7900   std::size_t sz(_time_steps.size());
7901   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7902   for(std::size_t i=0;i<sz;i++)
7903     {
7904       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7905       if(!timeStep)
7906         {
7907           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
7908           throw INTERP_KERNEL::Exception(oss.str());
7909         }
7910       items[i]=timeStep->splitDiscretizations();  
7911     }
7912   //
7913   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
7914   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
7915   std::vector< TypeOfField > types;
7916   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7917     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7918       {
7919         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
7920         if(ts.size()!=1)
7921           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
7922         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
7923         if(it2==types.end())
7924           types.push_back(ts[0]);
7925       }
7926   ret.resize(types.size()); ret2.resize(types.size());
7927   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
7928     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
7929       {
7930         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
7931         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
7932         ret2[pos].push_back(*it1);
7933       }
7934   for(std::size_t i=0;i<types.size();i++)
7935     {
7936       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7937       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
7938         elt->pushBackTimeStep(*it1);//also updates infos in elt
7939       ret[i]=elt;
7940       elt->MEDFileFieldNameScope::operator=(*this);
7941     }
7942   return ret;
7943 }
7944
7945 /*!
7946  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
7947  */
7948 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
7949 {
7950   std::size_t sz(_time_steps.size());
7951   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7952   std::size_t szOut(std::numeric_limits<std::size_t>::max());
7953   for(std::size_t i=0;i<sz;i++)
7954     {
7955       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
7956       if(!timeStep)
7957         {
7958           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
7959           throw INTERP_KERNEL::Exception(oss.str());
7960         }
7961       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
7962       if(szOut==std::numeric_limits<std::size_t>::max())
7963         szOut=items[i].size();
7964       else
7965         if(items[i].size()!=szOut)
7966           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
7967     }
7968   if(szOut==std::numeric_limits<std::size_t>::max())
7969     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
7970   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
7971   for(std::size_t i=0;i<szOut;i++)
7972     {
7973       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
7974       for(std::size_t j=0;j<sz;j++)
7975         elt->pushBackTimeStep(items[j][i]);
7976       ret[i]=elt;
7977       elt->MEDFileFieldNameScope::operator=(*this);
7978     }
7979   return ret;
7980 }
7981
7982 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
7983 {
7984   _name=field->getName();
7985   if(_name.empty())
7986     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
7987   if(!arr)
7988     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
7989   _infos=arr->getInfoOnComponents();
7990 }
7991
7992 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
7993 {
7994   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
7995   if(_name!=field->getName())
7996     {
7997       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
7998       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
7999       throw INTERP_KERNEL::Exception(oss.str());
8000     }
8001   if(!arr)
8002     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
8003   checkThatComponentsMatch(arr->getInfoOnComponents());
8004 }
8005
8006 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
8007 {
8008   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
8009   if(getInfo().size()!=compos.size())
8010     {
8011       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
8012       oss << " number of components of element to append (" << compos.size() << ") !";
8013       throw INTERP_KERNEL::Exception(oss.str());
8014     }
8015   if(_infos!=compos)
8016     {
8017       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
8018       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
8019       oss << " But compo in input fields are : ";
8020       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
8021       oss << " !";
8022       throw INTERP_KERNEL::Exception(oss.str());
8023     }
8024 }
8025
8026 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
8027 {
8028   std::size_t sz=_infos.size();
8029   int j=0;
8030   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
8031     {
8032       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8033       if(elt)
8034         if(elt->getInfo().size()!=sz)
8035           {
8036             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
8037             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
8038             throw INTERP_KERNEL::Exception(oss.str());
8039           }
8040     }
8041 }
8042
8043 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8044 {
8045   if(!field)
8046     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8047   if(!_time_steps.empty())
8048     checkCoherencyOfTinyInfo(field,arr);
8049   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8050   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8051   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8052   copyTinyInfoFrom(field,arr);
8053   _time_steps.push_back(obj);
8054 }
8055
8056 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8057 {
8058   if(!field)
8059     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8060   if(!_time_steps.empty())
8061     checkCoherencyOfTinyInfo(field,arr);
8062   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8063   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8064   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8065   copyTinyInfoFrom(field,arr);
8066   _time_steps.push_back(obj);
8067 }
8068
8069 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8070 {
8071   int sz=(int)_time_steps.size();
8072   if(i<0 || i>=sz)
8073     {
8074       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8075       throw INTERP_KERNEL::Exception(oss.str());
8076     }
8077   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8078   if(tsPtr)
8079     {
8080       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8081         {
8082           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8083           throw INTERP_KERNEL::Exception(oss.str());
8084         }
8085     }
8086   _time_steps[i]=ts;
8087 }
8088
8089 //= MEDFileFieldMultiTSWithoutSDA
8090
8091 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8092 {
8093   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8094 }
8095
8096 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8097 {
8098 }
8099
8100 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8101 {
8102 }
8103
8104 /*!
8105  * \param [in] fieldId field id in C mode
8106  */
8107 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8108 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8109 {
8110 }
8111 catch(INTERP_KERNEL::Exception& e)
8112 { throw e; }
8113
8114 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8115 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8116 {
8117 }
8118 catch(INTERP_KERNEL::Exception& e)
8119 { throw e; }
8120
8121 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8122 {
8123   return new MEDFileField1TSWithoutSDA;
8124 }
8125
8126 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8127 {
8128   if(!f1ts)
8129     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8130   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8131   if(!f1tsC)
8132     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8133 }
8134
8135 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8136 {
8137   return MEDFileField1TSWithoutSDA::TYPE_STR;
8138 }
8139
8140 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8141 {
8142   return new MEDFileFieldMultiTSWithoutSDA(*this);
8143 }
8144
8145 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8146 {
8147   return new MEDFileFieldMultiTSWithoutSDA;
8148 }
8149
8150 /*!
8151  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8152  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8153  */
8154 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
8155 {
8156   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8157   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8158   if(!myF1TSC)
8159     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8160   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8161 }
8162
8163 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8164 {
8165   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8166   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8167   int i=0;
8168   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8169     {
8170       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8171       if(eltToConv)
8172         {
8173           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8174           if(!eltToConvC)
8175             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8176           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8177           ret->setIteration(i,elt);
8178         }
8179     }
8180   return ret.retn();
8181 }
8182
8183 //= MEDFileAnyTypeFieldMultiTS
8184
8185 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8186 {
8187 }
8188
8189 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8190 try:MEDFileFieldGlobsReal(fid)
8191 {
8192   _content=BuildContentFrom(fid,loadAll,ms);
8193   loadGlobals(fid);
8194 }
8195 catch(INTERP_KERNEL::Exception& e)
8196 {
8197     throw e;
8198 }
8199
8200 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8201 {
8202   med_field_type typcha;
8203   std::vector<std::string> infos;
8204   std::string dtunit;
8205   int i(-1);
8206   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit);
8207   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8208   switch(typcha)
8209   {
8210     case MED_FLOAT64:
8211       {
8212         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8213         break;
8214       }
8215     case MED_INT32:
8216       {
8217         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8218         break;
8219       }
8220     default:
8221       {
8222         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
8223         throw INTERP_KERNEL::Exception(oss.str());
8224       }
8225   }
8226   ret->setDtUnit(dtunit.c_str());
8227   return ret.retn();
8228 }
8229
8230 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8231 {
8232   med_field_type typcha;
8233   //
8234   std::vector<std::string> infos;
8235   std::string dtunit,fieldName;
8236   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
8237   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8238   switch(typcha)
8239   {
8240     case MED_FLOAT64:
8241       {
8242         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8243         break;
8244       }
8245     case MED_INT32:
8246       {
8247         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8248         break;
8249       }
8250     default:
8251       {
8252         std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !";
8253         throw INTERP_KERNEL::Exception(oss.str());
8254       }
8255   }
8256   ret->setDtUnit(dtunit.c_str());
8257   return ret.retn();
8258 }
8259
8260 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8261 {
8262   if(!c)
8263     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8264   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8265     {
8266       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8267       ret->_content=c;  c->incrRef();
8268       return ret.retn();
8269     }
8270   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8271     {
8272       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8273       ret->_content=c;  c->incrRef();
8274       return ret.retn();
8275     }
8276   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8277 }
8278
8279 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8280 {
8281   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8282   std::string fileName(FileNameFromFID(fid));
8283   ret->setFileName(fileName);
8284   return ret;
8285 }
8286
8287 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8288 try:MEDFileFieldGlobsReal(fid)
8289 {
8290   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8291   loadGlobals(fid);
8292 }
8293 catch(INTERP_KERNEL::Exception& e)
8294 {
8295     throw e;
8296 }
8297
8298 //= MEDFileIntFieldMultiTSWithoutSDA
8299
8300 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::New(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8301 {
8302   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8303 }
8304
8305 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8306 {
8307 }
8308
8309 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8310 {
8311 }
8312
8313 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8314 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8315 {
8316 }
8317 catch(INTERP_KERNEL::Exception& e)
8318 { throw e; }
8319
8320 /*!
8321  * \param [in] fieldId field id in C mode
8322  */
8323 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8324 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8325 {
8326 }
8327 catch(INTERP_KERNEL::Exception& e)
8328 { throw e; }
8329
8330 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8331 {
8332   return new MEDFileIntField1TSWithoutSDA;
8333 }
8334
8335 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8336 {
8337   if(!f1ts)
8338     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8339   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8340   if(!f1tsC)
8341     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8342 }
8343
8344 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8345 {
8346   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8347 }
8348
8349 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8350 {
8351   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8352 }
8353
8354 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8355 {
8356   return new MEDFileIntFieldMultiTSWithoutSDA;
8357 }
8358
8359 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8360 {
8361   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8362   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8363   int i=0;
8364   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8365     {
8366       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8367       if(eltToConv)
8368         {
8369           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8370           if(!eltToConvC)
8371             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8372           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8373           ret->setIteration(i,elt);
8374         }
8375     }
8376   return ret.retn();
8377 }
8378
8379 //= MEDFileAnyTypeFieldMultiTS
8380
8381 /*!
8382  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8383  * that has been read from a specified MED file.
8384  *  \param [in] fileName - the name of the MED file to read.
8385  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8386  *          is to delete this field using decrRef() as it is no more needed.
8387  *  \throw If reading the file fails.
8388  */
8389 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8390 {
8391   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8392   return New(fid,loadAll);
8393 }
8394
8395 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8396 {
8397   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8398   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8399   ret->loadGlobals(fid);
8400   return ret.retn();
8401 }
8402
8403 /*!
8404  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8405  * that has been read from a specified MED file.
8406  *  \param [in] fileName - the name of the MED file to read.
8407  *  \param [in] fieldName - the name of the field to read.
8408  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8409  *          is to delete this field using decrRef() as it is no more needed.
8410  *  \throw If reading the file fails.
8411  *  \throw If there is no field named \a fieldName in the file.
8412  */
8413 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8414 {
8415   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8416   return New(fid,fieldName,loadAll);
8417 }
8418
8419 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8420 {
8421   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8422   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8423   ret->loadGlobals(fid);
8424   return ret.retn();
8425 }
8426
8427 /*!
8428  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8429  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8430  *
8431  * \warning this is a shallow copy constructor
8432  */
8433 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8434 {
8435   if(!shallowCopyOfContent)
8436     {
8437       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8438       otherPtr->incrRef();
8439       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8440     }
8441   else
8442     {
8443       _content=other.shallowCpy();
8444     }
8445 }
8446
8447 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8448 {
8449   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8450   if(!ret)
8451     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8452   return ret;
8453 }
8454
8455 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8456 {
8457   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8458   if(!ret)
8459     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8460   return ret;
8461 }
8462
8463 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8464 {
8465   return contentNotNullBase()->getPflsReallyUsed2();
8466 }
8467
8468 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8469 {
8470   return contentNotNullBase()->getLocsReallyUsed2();
8471 }
8472
8473 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8474 {
8475   return contentNotNullBase()->getPflsReallyUsedMulti2();
8476 }
8477
8478 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8479 {
8480   return contentNotNullBase()->getLocsReallyUsedMulti2();
8481 }
8482
8483 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8484 {
8485   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8486 }
8487
8488 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8489 {
8490   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8491 }
8492
8493 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8494 {
8495   return contentNotNullBase()->getNumberOfTS();
8496 }
8497
8498 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8499 {
8500   contentNotNullBase()->eraseEmptyTS();
8501 }
8502
8503 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8504 {
8505   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8506 }
8507
8508 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8509 {
8510   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8511 }
8512
8513 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8514 {
8515   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8516   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8517   ret->_content=c;
8518   return ret.retn();
8519 }
8520
8521 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8522 {
8523   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8524   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8525   ret->_content=c;
8526   return ret.retn();
8527 }
8528
8529 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8530 {
8531   return contentNotNullBase()->getIterations();
8532 }
8533
8534 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8535 {
8536   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8537     pushBackTimeStep(*it);
8538 }
8539
8540 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8541 {
8542   if(!fmts)
8543     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8544   int nbOfTS(fmts->getNumberOfTS());
8545   for(int i=0;i<nbOfTS;i++)
8546     {
8547       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8548       pushBackTimeStep(elt);
8549     }
8550 }
8551
8552 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8553 {
8554   if(!f1ts)
8555     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8556   checkCoherencyOfType(f1ts);
8557   f1ts->incrRef();
8558   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8559   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8560   c->incrRef();
8561   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8562   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8563     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8564   _content->pushBackTimeStep(cSafe);
8565   appendGlobs(*f1ts,1e-12);
8566 }
8567
8568 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8569 {
8570   contentNotNullBase()->synchronizeNameScope();
8571 }
8572
8573 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8574 {
8575   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8576 }
8577
8578 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8579 {
8580   return contentNotNullBase()->getPosGivenTime(time,eps);
8581 }
8582
8583 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8584 {
8585   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8586 }
8587
8588 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8589 {
8590   return contentNotNullBase()->getTypesOfFieldAvailable();
8591 }
8592
8593 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
8594 {
8595   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8596 }
8597
8598 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8599 {
8600   return contentNotNullBase()->getName();
8601 }
8602
8603 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8604 {
8605   contentNotNullBase()->setName(name);
8606 }
8607
8608 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8609 {
8610   return contentNotNullBase()->getDtUnit();
8611 }
8612
8613 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8614 {
8615   contentNotNullBase()->setDtUnit(dtUnit);
8616 }
8617
8618 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8619 {
8620   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8621 }
8622
8623 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8624 {
8625   return contentNotNullBase()->getTimeSteps(ret1);
8626 }
8627
8628 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8629 {
8630   return contentNotNullBase()->getMeshName();
8631 }
8632
8633 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8634 {
8635   contentNotNullBase()->setMeshName(newMeshName);
8636 }
8637
8638 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8639 {
8640   return contentNotNullBase()->changeMeshNames(modifTab);
8641 }
8642
8643 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8644 {
8645   return contentNotNullBase()->getInfo();
8646 }
8647
8648 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8649 {
8650   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8651 }
8652
8653 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8654 {
8655   return contentNotNullBase()->setInfo(info);
8656 }
8657
8658 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8659 {
8660   const std::vector<std::string> ret=getInfo();
8661   return (int)ret.size();
8662 }
8663
8664 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8665 {
8666   writeGlobals(fid,*this);
8667   contentNotNullBase()->writeLL(fid,*this);
8668 }
8669
8670 /*!
8671  * This method alloc the arrays and load potentially huge arrays contained in this field.
8672  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8673  * This method can be also called to refresh or reinit values from a file.
8674  * 
8675  * \throw If the fileName is not set or points to a non readable MED file.
8676  */
8677 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8678 {
8679   if(getFileName().empty())
8680     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8681   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8682   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8683 }
8684
8685 /*!
8686  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8687  * But once data loaded once, this method does nothing.
8688  * 
8689  * \throw If the fileName is not set or points to a non readable MED file.
8690  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8691  */
8692 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8693 {
8694   if(!getFileName().empty())
8695     {
8696       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8697       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8698     }
8699 }
8700
8701 /*!
8702  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8703  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8704  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8705  * 
8706  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8707  */
8708 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8709 {
8710   contentNotNullBase()->unloadArrays();
8711 }
8712
8713 /*!
8714  * 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.
8715  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8716  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8717  * 
8718  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8719  */
8720 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8721 {
8722   if(!getFileName().empty())
8723     contentNotNullBase()->unloadArrays();
8724 }
8725
8726 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8727 {
8728   std::ostringstream oss;
8729   contentNotNullBase()->simpleRepr(0,oss,-1);
8730   simpleReprGlobs(oss);
8731   return oss.str();
8732 }
8733
8734 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8735 {
8736   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8737 }
8738
8739 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8740 {
8741   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8742   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8743   return ret;
8744 }
8745
8746 /*!
8747  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8748  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8749  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8750  */
8751 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8752 {
8753   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8754   if(!content)
8755     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8756   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8757   std::size_t sz(contentsSplit.size());
8758   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8759   for(std::size_t i=0;i<sz;i++)
8760     {
8761       ret[i]=shallowCpy();
8762       ret[i]->_content=contentsSplit[i];
8763     }
8764   return ret;
8765 }
8766
8767 /*!
8768  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8769  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8770  */
8771 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8772 {
8773   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8774   if(!content)
8775     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8776   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8777   std::size_t sz(contentsSplit.size());
8778   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8779   for(std::size_t i=0;i<sz;i++)
8780     {
8781       ret[i]=shallowCpy();
8782       ret[i]->_content=contentsSplit[i];
8783     }
8784   return ret;
8785 }
8786
8787 /*!
8788  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8789  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8790  */
8791 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8792 {
8793   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8794   if(!content)
8795     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8796   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8797   std::size_t sz(contentsSplit.size());
8798   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8799   for(std::size_t i=0;i<sz;i++)
8800     {
8801       ret[i]=shallowCpy();
8802       ret[i]->_content=contentsSplit[i];
8803     }
8804   return ret;
8805 }
8806
8807 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8808 {
8809   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8810   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8811     ret->_content=_content->deepCopy();
8812   ret->deepCpyGlobs(*this);
8813   return ret.retn();
8814 }
8815
8816 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8817 {
8818   return _content;
8819 }
8820
8821 /*!
8822  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8823  *  \param [in] iteration - the iteration number of a required time step.
8824  *  \param [in] order - the iteration order number of required time step.
8825  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8826  *          delete this field using decrRef() as it is no more needed.
8827  *  \throw If there is no required time step in \a this field.
8828  */
8829 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8830 {
8831   int pos=getPosOfTimeStep(iteration,order);
8832   return getTimeStepAtPos(pos);
8833 }
8834
8835 /*!
8836  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8837  *  \param [in] time - the time of the time step of interest.
8838  *  \param [in] eps - a precision used to compare time values.
8839  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8840  *          delete this field using decrRef() as it is no more needed.
8841  *  \throw If there is no required time step in \a this field.
8842  */
8843 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8844 {
8845   int pos=getPosGivenTime(time,eps);
8846   return getTimeStepAtPos(pos);
8847 }
8848
8849 /*!
8850  * 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.
8851  * The float64 value of time attached to the pair of integers are not considered here.
8852  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8853  *
8854  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8855  * \throw If there is a null pointer in \a vectFMTS.
8856  */
8857 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8858 {
8859   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8860   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8861   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8862   while(!lstFMTS.empty())
8863     {
8864       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8865       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8866       if(!curIt)
8867         throw INTERP_KERNEL::Exception(msg);
8868       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8869       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8870       elt.push_back(curIt); it=lstFMTS.erase(it);
8871       while(it!=lstFMTS.end())
8872         {
8873           curIt=*it;
8874           if(!curIt)
8875             throw INTERP_KERNEL::Exception(msg);
8876           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8877           if(refIts==curIts)
8878             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8879           else
8880             it++;
8881         }
8882       ret.push_back(elt);
8883     }
8884   return ret;
8885 }
8886
8887 /*!
8888  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8889  * All returned instances in a subvector can be safely loaded, rendered along time
8890  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8891  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8892  * 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).
8893  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8894  * 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.
8895  *
8896  * \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().
8897  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8898  * \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.
8899  * \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.
8900  *
8901  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8902  * \throw If an element in \a vectFMTS change of spatial discretization along time.
8903  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
8904  * \thorw If some elements in \a vectFMTS do not have the same times steps.
8905  * \throw If mesh is null.
8906  * \throw If an element in \a vectFMTS is null.
8907  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
8908  */
8909 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
8910 {
8911   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
8912   if(!mesh)
8913     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
8914   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8915   if(vectFMTS.empty())
8916     return ret;
8917   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
8918   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
8919   if(!frstElt)
8920     throw INTERP_KERNEL::Exception(msg);
8921   std::size_t i=0;
8922   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
8923   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
8924   for(;it!=vectFMTS.end();it++,i++)
8925     {
8926       if(!(*it))
8927         throw INTERP_KERNEL::Exception(msg);
8928       TypeOfField tof0,tof1;
8929       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
8930         {
8931           if(tof1!=ON_NODES)
8932             vectFMTSNotNodes.push_back(*it);
8933           else
8934             vectFMTSNodes.push_back(*it);
8935         }
8936       else
8937         vectFMTSNotNodes.push_back(*it);
8938     }
8939   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
8940   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
8941   ret=retCell;
8942   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
8943     {
8944       i=0;
8945       bool isFetched(false);
8946       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
8947         {
8948           if((*it0).empty())
8949             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
8950           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
8951             { ret[i].push_back(*it2); isFetched=true; }
8952         }
8953       if(!isFetched)
8954         {
8955           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
8956           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
8957           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
8958         }
8959     }
8960   fsc=cmps;
8961   return ret;
8962 }
8963
8964 /*!
8965  * 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.
8966  * \param [out] cmps - same size than the returned vector.
8967  */
8968 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
8969 {
8970   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8971   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8972   while(!lstFMTS.empty())
8973     {
8974       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8975       MEDFileAnyTypeFieldMultiTS *ref(*it);
8976       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8977       elt.push_back(ref); it=lstFMTS.erase(it);
8978       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
8979       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
8980       while(it!=lstFMTS.end())
8981         {
8982           MEDFileAnyTypeFieldMultiTS *curIt(*it);
8983           if(cmp->isEqual(curIt))
8984             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8985           else
8986             it++;
8987         }
8988       ret.push_back(elt); cmps.push_back(cmp);
8989     }
8990   return ret;
8991 }
8992
8993 /*!
8994  * 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.
8995  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
8996  *
8997  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
8998  * \throw If \a f0 or \a f1 change of spatial discretization along time.
8999  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
9000  * \thorw If \a f0 and \a f1 do not have the same times steps.
9001  * \throw If mesh is null.
9002  * \throw If \a f0 or \a f1 is null.
9003  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
9004  */
9005 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
9006 {
9007   if(!mesh)
9008     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
9009   if(!f0 || !f1)
9010     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
9011   if(f0->getMeshName()!=mesh->getName())
9012     {
9013       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9014       throw INTERP_KERNEL::Exception(oss.str());
9015     }
9016   if(f1->getMeshName()!=mesh->getName())
9017     {
9018       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9019       throw INTERP_KERNEL::Exception(oss.str());
9020     }
9021   int nts=f0->getNumberOfTS();
9022   if(nts!=f1->getNumberOfTS())
9023     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
9024   if(nts==0)
9025     return nts;
9026   for(int i=0;i<nts;i++)
9027     {
9028       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
9029       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
9030       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
9031       if(tofs0.size()!=1 || tofs1.size()!=1)
9032         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
9033       if(i!=0)
9034         {
9035           if(tof0!=tofs0[0] || tof1!=tofs1[0])
9036             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
9037         }
9038       else
9039         { tof0=tofs0[0]; tof1=tofs1[0]; }
9040       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9041         {
9042           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() << ") !";
9043           throw INTERP_KERNEL::Exception(oss.str());
9044         }
9045       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9046         {
9047           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() << ") !";
9048           throw INTERP_KERNEL::Exception(oss.str());
9049         }
9050       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9051         {
9052           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() << ") !";
9053           throw INTERP_KERNEL::Exception(oss.str());
9054         }
9055     }
9056   return nts;
9057 }
9058
9059 /*!
9060  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9061  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9062  *
9063  * \return A new object that the caller is responsible to deallocate.
9064  */
9065 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9066 {
9067   if(!mm)
9068     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9069   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9070   int nbTS(getNumberOfTS());
9071   for(int i=0;i<nbTS;i++)
9072     {
9073       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9074       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9075       fmtsOut->pushBackTimeStep(f1tsOut);
9076     }
9077   return fmtsOut.retn();
9078 }
9079
9080 template<class T>
9081 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9082 {
9083   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9084   if(f1tss.empty())
9085     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9086   std::size_t sz(f1tss.size()),i(0);
9087   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9088   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9089     {
9090       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9091       if(!elt)
9092         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9093       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9094     }
9095   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9096   if(!retc)
9097     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9098   retc->aggregate(f1tsw,dts);
9099   ret->setDtUnit(f1tss[0]->getDtUnit());
9100   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9101 }
9102
9103 template<class T>
9104 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9105 {
9106   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9107   if(fmtss.empty())
9108     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9109   std::size_t sz(fmtss.size());
9110   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9111     {
9112       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9113       if(!elt)
9114         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9115     }
9116   int nbTS(fmtss[0]->getNumberOfTS());
9117   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9118     if((*it)->getNumberOfTS()!=nbTS)
9119       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9120   for(int iterTS=0;iterTS<nbTS;iterTS++)
9121     {
9122       std::size_t i(0);
9123       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9124       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9125       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9126         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9127       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9128       ret->pushBackTimeStep(f1ts);
9129       ret->setDtUnit(f1ts->getDtUnit());
9130     }
9131   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9132 }
9133
9134 /*!
9135  * \a dts and \a ftmss are expected to have same size.
9136  */
9137 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9138 {
9139   if(fmtss.empty())
9140     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9141   std::size_t sz(fmtss.size());
9142   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9143   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9144   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9145     {
9146       if(!(*it))
9147         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9148       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9149       if(elt1)
9150         {
9151           fmtss1.push_back(elt1);
9152           continue;
9153         }
9154       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9155       if(elt2)
9156         {
9157           fmtss2.push_back(elt2);
9158           continue;
9159         }
9160       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9161     }
9162   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9163     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9164   if(fmtss1.size()==sz)
9165     return AggregateHelperFMTS<double>(fmtss1,dts);
9166   if(fmtss2.size()!=sz)
9167     return AggregateHelperFMTS<int>(fmtss2,dts);
9168   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9169 }
9170
9171 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9172 {
9173   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9174 }
9175
9176 //= MEDFileFieldMultiTS
9177
9178 /*!
9179  * Returns a new empty instance of MEDFileFieldMultiTS.
9180  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9181  *          is to delete this field using decrRef() as it is no more needed.
9182  */
9183 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9184 {
9185   return new MEDFileFieldMultiTS;
9186 }
9187
9188 /*!
9189  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9190  * that has been read from a specified MED file.
9191  *  \param [in] fileName - the name of the MED file to read.
9192  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9193  *          is to delete this field using decrRef() as it is no more needed.
9194  *  \throw If reading the file fails.
9195  */
9196 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9197 {
9198   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9199   return New(fid,loadAll);
9200 }
9201
9202 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9203 {
9204   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9205   ret->contentNotNull();//to check that content type matches with \a this type.
9206   return ret.retn();
9207 }
9208
9209 /*!
9210  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9211  * that has been read from a specified MED file.
9212  *  \param [in] fileName - the name of the MED file to read.
9213  *  \param [in] fieldName - the name of the field to read.
9214  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9215  *          is to delete this field using decrRef() as it is no more needed.
9216  *  \throw If reading the file fails.
9217  *  \throw If there is no field named \a fieldName in the file.
9218  */
9219 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9220 {
9221   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9222   return New(fid,fieldName,loadAll);
9223 }
9224
9225 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9226 {
9227   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9228   ret->contentNotNull();//to check that content type matches with \a this type.
9229   return ret.retn();
9230 }
9231
9232 /*!
9233  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9234  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9235  *
9236  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9237  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9238  * \warning this is a shallow copy constructor
9239  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9240  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9241  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9242  *          is to delete this field using decrRef() as it is no more needed.
9243  */
9244 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9245 {
9246   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9247 }
9248
9249 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9250 {
9251   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9252   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9253   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
9254   ret->contentNotNull();//to check that content type matches with \a this type.
9255   return ret.retn();
9256 }
9257
9258 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9259 {
9260   return new MEDFileFieldMultiTS(*this);
9261 }
9262
9263 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9264 {
9265   if(!f1ts)
9266     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9267   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9268   if(!f1tsC)
9269     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9270 }
9271
9272 /*!
9273  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9274  * following the given input policy.
9275  *
9276  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9277  *                            By default (true) the globals are deeply copied.
9278  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9279  */
9280 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9281 {
9282   MCAuto<MEDFileIntFieldMultiTS> ret;
9283   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9284   if(content)
9285     {
9286       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9287       if(!contc)
9288         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9289       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9290       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9291     }
9292   else
9293     ret=MEDFileIntFieldMultiTS::New();
9294   if(isDeepCpyGlobs)
9295     ret->deepCpyGlobs(*this);
9296   else
9297     ret->shallowCpyGlobs(*this);
9298   return ret.retn();
9299 }
9300
9301 /*!
9302  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9303  *  \param [in] pos - a time step id.
9304  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9305  *          delete this field using decrRef() as it is no more needed.
9306  *  \throw If \a pos is not a valid time step id.
9307  */
9308 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9309 {
9310   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9311   if(!item)
9312     {
9313       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9314       throw INTERP_KERNEL::Exception(oss.str());
9315     }
9316   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9317   if(itemC)
9318     {
9319       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9320       ret->shallowCpyGlobs(*this);
9321       return ret.retn();
9322     }
9323   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9324   throw INTERP_KERNEL::Exception(oss.str());
9325 }
9326
9327 /*!
9328  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9329  * mesh entities of a given dimension of the first mesh in MED file.
9330  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9331  *  \param [in] type - a spatial discretization of interest.
9332  *  \param [in] iteration - the iteration number of a required time step.
9333  *  \param [in] order - the iteration order number of required time step.
9334  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9335  *  \param [in] renumPol - specifies how to permute values of the result field according to
9336  *          the optional numbers of cells and nodes, if any. The valid values are
9337  *          - 0 - do not permute.
9338  *          - 1 - permute cells.
9339  *          - 2 - permute nodes.
9340  *          - 3 - permute cells and nodes.
9341  *
9342  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9343  *          caller is to delete this field using decrRef() as it is no more needed. 
9344  *  \throw If the MED file is not readable.
9345  *  \throw If there is no mesh in the MED file.
9346  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9347  *  \throw If no field values of the required parameters are available.
9348  */
9349 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9350 {
9351   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9352   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9353   if(!myF1TSC)
9354     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9355   MCAuto<DataArray> arrOut;
9356   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9357   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9358   return ret.retn();
9359 }
9360
9361 /*!
9362  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9363  * the top level cells of the first mesh in MED file.
9364  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9365  *  \param [in] type - a spatial discretization of interest.
9366  *  \param [in] iteration - the iteration number of a required time step.
9367  *  \param [in] order - the iteration order number of required time step.
9368  *  \param [in] renumPol - specifies how to permute values of the result field according to
9369  *          the optional numbers of cells and nodes, if any. The valid values are
9370  *          - 0 - do not permute.
9371  *          - 1 - permute cells.
9372  *          - 2 - permute nodes.
9373  *          - 3 - permute cells and nodes.
9374  *
9375  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9376  *          caller is to delete this field using decrRef() as it is no more needed. 
9377  *  \throw If the MED file is not readable.
9378  *  \throw If there is no mesh in the MED file.
9379  *  \throw If no field values of the required parameters are available.
9380  */
9381 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9382 {
9383   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9384   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9385   if(!myF1TSC)
9386     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9387   MCAuto<DataArray> arrOut;
9388   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9389   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9390   return ret.retn();
9391 }
9392
9393 /*!
9394  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
9395  * method should be called (getFieldOnMeshAtLevel for example).
9396  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9397  *
9398  * \param [in] iteration - the iteration number of a required time step.
9399  * \param [in] order - the iteration order number of required time step.
9400  * \param [in] mesh - the mesh the field is lying on
9401  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9402  *          caller is to delete this field using decrRef() as it is no more needed. 
9403  */
9404 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9405 {
9406   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9407   MCAuto<DataArray> arrOut;
9408   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9409   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9410   return ret.retn();
9411 }
9412
9413 /*!
9414  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9415  * a given support.
9416  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9417  *  \param [in] type - a spatial discretization of interest.
9418  *  \param [in] iteration - the iteration number of a required time step.
9419  *  \param [in] order - the iteration order number of required time step.
9420  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9421  *  \param [in] mesh - the supporting mesh.
9422  *  \param [in] renumPol - specifies how to permute values of the result field according to
9423  *          the optional numbers of cells and nodes, if any. The valid values are
9424  *          - 0 - do not permute.
9425  *          - 1 - permute cells.
9426  *          - 2 - permute nodes.
9427  *          - 3 - permute cells and nodes.
9428  *
9429  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9430  *          caller is to delete this field using decrRef() as it is no more needed. 
9431  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9432  *  \throw If no field of \a this is lying on \a mesh.
9433  *  \throw If no field values of the required parameters are available.
9434  */
9435 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9436 {
9437   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9438   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9439   if(!myF1TSC)
9440     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9441   MCAuto<DataArray> arrOut;
9442   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9443   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9444   return ret.retn();
9445 }
9446
9447 /*!
9448  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9449  * given support. 
9450  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9451  *  \param [in] type - a spatial discretization of the new field.
9452  *  \param [in] iteration - the iteration number of a required time step.
9453  *  \param [in] order - the iteration order number of required time step.
9454  *  \param [in] mesh - the supporting mesh.
9455  *  \param [in] renumPol - specifies how to permute values of the result field according to
9456  *          the optional numbers of cells and nodes, if any. The valid values are
9457  *          - 0 - do not permute.
9458  *          - 1 - permute cells.
9459  *          - 2 - permute nodes.
9460  *          - 3 - permute cells and nodes.
9461  *
9462  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9463  *          caller is to delete this field using decrRef() as it is no more needed. 
9464  *  \throw If no field of \a this is lying on \a mesh.
9465  *  \throw If no field values of the required parameters are available.
9466  */
9467 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9468 {
9469   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9470   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9471   if(!myF1TSC)
9472     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9473   MCAuto<DataArray> arrOut;
9474   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9475   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9476   return ret.retn();
9477 }
9478
9479 /*!
9480  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9481  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9482  * This method is useful for MED2 file format when field on different mesh was autorized.
9483  */
9484 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9485 {
9486   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9487   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9488   if(!myF1TSC)
9489     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9490   MCAuto<DataArray> arrOut;
9491   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9492   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9493   return ret.retn();
9494 }
9495
9496 /*!
9497  * Returns values and a profile of the field of a given type, of a given time step,
9498  * lying on a given support.
9499  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9500  *  \param [in] type - a spatial discretization of the field.
9501  *  \param [in] iteration - the iteration number of a required time step.
9502  *  \param [in] order - the iteration order number of required time step.
9503  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9504  *  \param [in] mesh - the supporting mesh.
9505  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9506  *          field of interest lies on. If the field lies on all entities of the given
9507  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9508  *          using decrRef() as it is no more needed.  
9509  *  \param [in] glob - the global data storing profiles and localization.
9510  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9511  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9512  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9513  *  \throw If no field of \a this is lying on \a mesh.
9514  *  \throw If no field values of the required parameters are available.
9515  */
9516 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9517 {
9518   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9519   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9520   if(!myF1TSC)
9521     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9522   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9523   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9524 }
9525
9526 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9527 {
9528   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9529   if(!pt)
9530     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9531   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9532   if(!ret)
9533     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 !");
9534   return ret;
9535 }
9536
9537 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9538 {
9539   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9540   if(!pt)
9541     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9542   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9543   if(!ret)
9544     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 !");
9545   return ret;
9546 }
9547
9548 /*!
9549  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9550  * the given field is checked if its elements are sorted suitable for writing to MED file
9551  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9552  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9553  *  \param [in] field - the field to add to \a this.
9554  *  \throw If the name of \a field is empty.
9555  *  \throw If the data array of \a field is not set.
9556  *  \throw If existing time steps have different name or number of components than \a field.
9557  *  \throw If the underlying mesh of \a field has no name.
9558  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9559  */
9560 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9561 {
9562   const DataArrayDouble *arr=0;
9563   if(field)
9564     arr=field->getArray();
9565   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9566 }
9567
9568 /*!
9569  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9570  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9571  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9572  * and \a profile.
9573  *
9574  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9575  * A new profile is added only if no equal profile is missing.
9576  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9577  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9578  *  \param [in] mesh - the supporting mesh of \a field.
9579  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9580  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9581  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9582  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9583  *  \throw If the data array of \a field is not set.
9584  *  \throw If the data array of \a this is already allocated but has different number of
9585  *         components than \a field.
9586  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9587  *  \sa setFieldNoProfileSBT()
9588  */
9589 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9590 {
9591   const DataArrayDouble *arr=0;
9592   if(field)
9593     arr=field->getArray();
9594   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9595 }
9596
9597 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9598 {
9599   _content=new MEDFileFieldMultiTSWithoutSDA;
9600 }
9601
9602 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
9603 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
9604 {
9605 }
9606 catch(INTERP_KERNEL::Exception& e)
9607 { throw e; }
9608
9609 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9610 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
9611 {
9612 }
9613 catch(INTERP_KERNEL::Exception& e)
9614 { throw e; }
9615
9616 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9617 {
9618 }
9619
9620 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
9621 {
9622   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9623 }
9624
9625 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9626 {
9627   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9628 }
9629
9630 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9631 {
9632   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9633 }
9634
9635 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
9636 {
9637   return MEDFileFieldMultiTS::New();
9638 }
9639
9640 //= MEDFileAnyTypeFieldMultiTSIterator
9641
9642 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9643 {
9644   if(fmts)
9645     {
9646       fmts->incrRef();
9647       _nb_iter=fmts->getNumberOfTS();
9648     }
9649 }
9650
9651 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9652 {
9653 }
9654
9655 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9656 {
9657   if(_iter_id<_nb_iter)
9658     {
9659       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9660       if(fmts)
9661         return fmts->getTimeStepAtPos(_iter_id++);
9662       else
9663         return 0;
9664     }
9665   else
9666     return 0;
9667 }
9668
9669 //= MEDFileIntFieldMultiTS
9670
9671 /*!
9672  * Returns a new empty instance of MEDFileFieldMultiTS.
9673  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9674  *          is to delete this field using decrRef() as it is no more needed.
9675  */
9676 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9677 {
9678   return new MEDFileIntFieldMultiTS;
9679 }
9680
9681 /*!
9682  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9683  * that has been read from a specified MED file.
9684  *  \param [in] fileName - the name of the MED file to read.
9685  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9686  *          is to delete this field using decrRef() as it is no more needed.
9687  *  \throw If reading the file fails.
9688  */
9689 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9690 {
9691   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9692   return New(fid,loadAll);
9693 }
9694
9695 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
9696 {
9697   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
9698   ret->contentNotNull();//to check that content type matches with \a this type.
9699   return ret.retn();
9700 }
9701
9702 /*!
9703  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9704  * that has been read from a specified MED file.
9705  *  \param [in] fileName - the name of the MED file to read.
9706  *  \param [in] fieldName - the name of the field to read.
9707  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9708  *          is to delete this field using decrRef() as it is no more needed.
9709  *  \throw If reading the file fails.
9710  *  \throw If there is no field named \a fieldName in the file.
9711  */
9712 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9713 {
9714   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9715   return New(fid,fieldName,loadAll);
9716 }
9717
9718 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9719 {
9720   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
9721   ret->contentNotNull();//to check that content type matches with \a this type.
9722   return ret.retn();
9723 }
9724
9725 /*!
9726  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9727  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9728  *
9729  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9730  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9731  * \warning this is a shallow copy constructor
9732  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9733  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9734  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9735  *          is to delete this field using decrRef() as it is no more needed.
9736  */
9737 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9738 {
9739   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9740 }
9741
9742 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9743 {
9744   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9745   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9746   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
9747   ret->contentNotNull();//to check that content type matches with \a this type.
9748   return ret.retn();
9749 }
9750
9751 /*!
9752  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9753  * following the given input policy.
9754  *
9755  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9756  *                            By default (true) the globals are deeply copied.
9757  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9758  */
9759 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9760 {
9761   MCAuto<MEDFileFieldMultiTS> ret;
9762   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9763   if(content)
9764     {
9765       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9766       if(!contc)
9767         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9768       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9769       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
9770     }
9771   else
9772     ret=MEDFileFieldMultiTS::New();
9773   if(isDeepCpyGlobs)
9774     ret->deepCpyGlobs(*this);
9775   else
9776     ret->shallowCpyGlobs(*this);
9777   return ret.retn();
9778 }
9779
9780 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9781 {
9782   return new MEDFileIntFieldMultiTS(*this);
9783 }
9784
9785 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9786 {
9787   if(!f1ts)
9788     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9789   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9790   if(!f1tsC)
9791     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9792 }
9793
9794 /*!
9795  * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance
9796  * method should be called (getFieldOnMeshAtLevel for example).
9797  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9798  *
9799  * \param [in] iteration - the iteration number of a required time step.
9800  * \param [in] order - the iteration order number of required time step.
9801  * \param [in] mesh - the mesh the field is lying on
9802  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
9803  *          caller is to delete this field using decrRef() as it is no more needed. 
9804  */
9805 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9806 {
9807   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9808   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9809   if(!myF1TSC)
9810     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
9811   MCAuto<DataArray> arrOut;
9812   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9813   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
9814   return ret2.retn();
9815 }
9816
9817 /*!
9818  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9819  * mesh entities of a given dimension of the first mesh in MED file.
9820  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9821  *  \param [in] type - a spatial discretization of interest.
9822  *  \param [in] iteration - the iteration number of a required time step.
9823  *  \param [in] order - the iteration order number of required time step.
9824  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9825  *  \param [in] renumPol - specifies how to permute values of the result field according to
9826  *          the optional numbers of cells and nodes, if any. The valid values are
9827  *          - 0 - do not permute.
9828  *          - 1 - permute cells.
9829  *          - 2 - permute nodes.
9830  *          - 3 - permute cells and nodes.
9831  *
9832  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9833  *          caller is to delete this field using decrRef() as it is no more needed. 
9834  *  \throw If the MED file is not readable.
9835  *  \throw If there is no mesh in the MED file.
9836  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9837  *  \throw If no field values of the required parameters are available.
9838  */
9839 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9840 {
9841   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9842   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9843   if(!myF1TSC)
9844     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9845   MCAuto<DataArray> arr;
9846   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
9847   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9848   return ret2.retn();
9849 }
9850
9851 /*!
9852  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9853  * the top level cells of the first mesh in MED file.
9854  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9855  *  \param [in] type - a spatial discretization of interest.
9856  *  \param [in] iteration - the iteration number of a required time step.
9857  *  \param [in] order - the iteration order number of required time step.
9858  *  \param [in] renumPol - specifies how to permute values of the result field according to
9859  *          the optional numbers of cells and nodes, if any. The valid values are
9860  *          - 0 - do not permute.
9861  *          - 1 - permute cells.
9862  *          - 2 - permute nodes.
9863  *          - 3 - permute cells and nodes.
9864  *
9865  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9866  *          caller is to delete this field using decrRef() as it is no more needed. 
9867  *  \throw If the MED file is not readable.
9868  *  \throw If there is no mesh in the MED file.
9869  *  \throw If no field values of the required parameters are available.
9870  */
9871 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9872 {
9873   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9874   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9875   if(!myF1TSC)
9876     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9877   MCAuto<DataArray> arr;
9878   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
9879   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9880   return ret2.retn();
9881 }
9882
9883 /*!
9884  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9885  * a given support.
9886  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9887  *  \param [in] type - a spatial discretization of interest.
9888  *  \param [in] iteration - the iteration number of a required time step.
9889  *  \param [in] order - the iteration order number of required time step.
9890  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9891  *  \param [in] mesh - the supporting mesh.
9892  *  \param [in] renumPol - specifies how to permute values of the result field according to
9893  *          the optional numbers of cells and nodes, if any. The valid values are
9894  *          - 0 - do not permute.
9895  *          - 1 - permute cells.
9896  *          - 2 - permute nodes.
9897  *          - 3 - permute cells and nodes.
9898  *
9899  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9900  *          caller is to delete this field using decrRef() as it is no more needed. 
9901  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9902  *  \throw If no field of \a this is lying on \a mesh.
9903  *  \throw If no field values of the required parameters are available.
9904  */
9905 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9906 {
9907   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9908   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9909   if(!myF1TSC)
9910     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9911   MCAuto<DataArray> arr;
9912   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
9913   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9914   return ret2.retn();
9915 }
9916
9917 /*!
9918  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
9919  * given support. 
9920  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9921  *  \param [in] type - a spatial discretization of the new field.
9922  *  \param [in] iteration - the iteration number of a required time step.
9923  *  \param [in] order - the iteration order number of required time step.
9924  *  \param [in] mesh - the supporting mesh.
9925  *  \param [out] arrOut - the DataArrayInt containing values of field.
9926  *  \param [in] renumPol - specifies how to permute values of the result field according to
9927  *          the optional numbers of cells and nodes, if any. The valid values are
9928  *          - 0 - do not permute.
9929  *          - 1 - permute cells.
9930  *          - 2 - permute nodes.
9931  *          - 3 - permute cells and nodes.
9932  *
9933  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9934  *          caller is to delete this field using decrRef() as it is no more needed. 
9935  *  \throw If no field of \a this is lying on \a mesh.
9936  *  \throw If no field values of the required parameters are available.
9937  */
9938 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9939 {
9940   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9941   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9942   if(!myF1TSC)
9943     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9944   MCAuto<DataArray> arr;
9945   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
9946   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9947   return ret2.retn();
9948 }
9949
9950 /*!
9951  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
9952  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9953  * This method is useful for MED2 file format when field on different mesh was autorized.
9954  */
9955 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
9956 {
9957   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9958   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9959   if(!myF1TSC)
9960     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
9961   MCAuto<DataArray> arr;
9962   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
9963   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9964   return ret2.retn();
9965 }
9966
9967 /*!
9968  * Returns values and a profile of the field of a given type, of a given time step,
9969  * lying on a given support.
9970  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9971  *  \param [in] type - a spatial discretization of the field.
9972  *  \param [in] iteration - the iteration number of a required time step.
9973  *  \param [in] order - the iteration order number of required time step.
9974  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9975  *  \param [in] mesh - the supporting mesh.
9976  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9977  *          field of interest lies on. If the field lies on all entities of the given
9978  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9979  *          using decrRef() as it is no more needed.  
9980  *  \param [in] glob - the global data storing profiles and localization.
9981  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
9982  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9983  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9984  *  \throw If no field of \a this is lying on \a mesh.
9985  *  \throw If no field values of the required parameters are available.
9986  */
9987 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9988 {
9989   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9990   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
9991   if(!myF1TSC)
9992     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
9993   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9994   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
9995 }
9996
9997 /*!
9998  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
9999  *  \param [in] pos - a time step id.
10000  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
10001  *          delete this field using decrRef() as it is no more needed.
10002  *  \throw If \a pos is not a valid time step id.
10003  */
10004 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
10005 {
10006   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
10007   if(!item)
10008     {
10009       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
10010       throw INTERP_KERNEL::Exception(oss.str());
10011     }
10012   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
10013   if(itemC)
10014     {
10015       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
10016       ret->shallowCpyGlobs(*this);
10017       return ret.retn();
10018     }
10019   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
10020   throw INTERP_KERNEL::Exception(oss.str());
10021 }
10022
10023 /*!
10024  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
10025  * the given field is checked if its elements are sorted suitable for writing to MED file
10026  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10027  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10028  *  \param [in] field - the field to add to \a this.
10029  *  \throw If the name of \a field is empty.
10030  *  \throw If the data array of \a field is not set.
10031  *  \throw If existing time steps have different name or number of components than \a field.
10032  *  \throw If the underlying mesh of \a field has no name.
10033  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10034  */
10035 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
10036 {
10037   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10038   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
10039 }
10040
10041 /*!
10042  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10043  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10044  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10045  * and \a profile.
10046  *
10047  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10048  * A new profile is added only if no equal profile is missing.
10049  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10050  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10051  *  \param [in] arrOfVals - the values of the field \a field used.
10052  *  \param [in] mesh - the supporting mesh of \a field.
10053  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10054  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10055  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10056  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10057  *  \throw If the data array of \a field is not set.
10058  *  \throw If the data array of \a this is already allocated but has different number of
10059  *         components than \a field.
10060  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10061  *  \sa setFieldNoProfileSBT()
10062  */
10063 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10064 {
10065   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10066   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10067 }
10068
10069 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10070 {
10071   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10072   if(!pt)
10073     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10074   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10075   if(!ret)
10076     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 !");
10077   return ret;
10078 }
10079
10080 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10081 {
10082   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10083   if(!pt)
10084     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10085   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10086   if(!ret)
10087     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 !");
10088   return ret;
10089 }
10090
10091 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10092 {
10093   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10094 }
10095
10096 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10097 {
10098 }
10099
10100 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10101 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10102 {
10103 }
10104 catch(INTERP_KERNEL::Exception& e)
10105 { throw e; }
10106
10107 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10108 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10109 {
10110 }
10111 catch(INTERP_KERNEL::Exception& e)
10112 { throw e; }
10113
10114 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10115 {
10116   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10117 }
10118
10119 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10120 {
10121   return MEDFileIntFieldMultiTS::New();
10122 }
10123
10124 //= MEDFileFields
10125
10126 MEDFileFields *MEDFileFields::New()
10127 {
10128   return new MEDFileFields;
10129 }
10130
10131 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10132 {
10133   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10134   return New(fid,loadAll);
10135 }
10136
10137 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
10138 {
10139   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10140   if(!se)
10141     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
10142   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
10143   return new MEDFileFields(fid,loadAll,0,entities);
10144 }
10145
10146 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10147 {
10148   return new MEDFileFields(fid,loadAll,0,0);
10149 }
10150
10151 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10152 {
10153   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10154   return new MEDFileFields(fid,loadAll,ms,0);
10155 }
10156
10157 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10158 {
10159   MEDFileUtilities::CheckFileForRead(fileName);
10160   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10161   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10162   return new MEDFileFields(fid,loadAll,0,ent);
10163 }
10164
10165 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10166 {
10167   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10168   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10169   return ret;
10170 }
10171
10172 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10173 {
10174   std::vector<const BigMemoryObject *> ret;
10175   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10176     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10177   return ret;
10178 }
10179
10180 MEDFileFields *MEDFileFields::deepCopy() const
10181 {
10182   MCAuto<MEDFileFields> ret(shallowCpy());
10183   std::size_t i(0);
10184   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10185     {
10186       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10187         ret->_fields[i]=(*it)->deepCopy();
10188     }
10189   ret->deepCpyGlobs(*this);
10190   return ret.retn();
10191 }
10192
10193 MEDFileFields *MEDFileFields::shallowCpy() const
10194 {
10195   return new MEDFileFields(*this);
10196 }
10197
10198 /*!
10199  * 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
10200  * 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.
10201  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10202  *
10203  * \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.
10204  * \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.
10205  * 
10206  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10207  */
10208 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10209 {
10210   std::set< std::pair<int,int> > s;
10211   bool firstShot=true;
10212   areThereSomeForgottenTS=false;
10213   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10214     {
10215       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10216         continue;
10217       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10218       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10219       if(firstShot)
10220         { s=s1; firstShot=false; }
10221       else
10222         {
10223           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10224           if(s!=s2)
10225             areThereSomeForgottenTS=true;
10226           s=s2;
10227         }
10228     }
10229   std::vector< std::pair<int,int> > ret;
10230   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10231   return ret;
10232 }
10233
10234 int MEDFileFields::getNumberOfFields() const
10235 {
10236   return _fields.size();
10237 }
10238
10239 std::vector<std::string> MEDFileFields::getFieldsNames() const
10240 {
10241   std::vector<std::string> ret(_fields.size());
10242   int i(0);
10243   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10244     {
10245       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10246       if(f)
10247         {
10248           ret[i]=f->getName();
10249         }
10250       else
10251         {
10252           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10253           throw INTERP_KERNEL::Exception(oss.str());
10254         }
10255     }
10256   return ret;
10257 }
10258
10259 std::vector<std::string> MEDFileFields::getMeshesNames() const
10260 {
10261   std::vector<std::string> ret;
10262   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10263     {
10264       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10265       if(cur)
10266         ret.push_back(cur->getMeshName());
10267     }
10268   return ret;
10269 }
10270
10271 std::string MEDFileFields::simpleRepr() const
10272 {
10273   std::ostringstream oss;
10274   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10275   simpleRepr(0,oss);
10276   return oss.str();
10277 }
10278
10279 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10280 {
10281   int nbOfFields(getNumberOfFields());
10282   std::string startLine(bkOffset,' ');
10283   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10284   int i=0;
10285   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10286     {
10287       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10288       if(cur)
10289         {
10290           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10291         }
10292       else
10293         {
10294           oss << startLine << "  - not defined !" << std::endl;
10295         }
10296     }
10297   i=0;
10298   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10299     {
10300       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10301       std::string chapter(17,'0'+i);
10302       oss << startLine << chapter << std::endl;
10303       if(cur)
10304         {
10305           cur->simpleRepr(bkOffset+2,oss,i);
10306         }
10307       else
10308         {
10309           oss << startLine << "  - not defined !" << std::endl;
10310         }
10311       oss << startLine << chapter << std::endl;
10312     }
10313   simpleReprGlobs(oss);
10314 }
10315
10316 MEDFileFields::MEDFileFields()
10317 {
10318 }
10319
10320 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10321 try:MEDFileFieldGlobsReal(fid)
10322 {
10323   int nbFields(MEDnField(fid));
10324   _fields.resize(nbFields);
10325   med_field_type typcha;
10326   for(int i=0;i<nbFields;i++)
10327     {
10328       std::vector<std::string> infos;
10329       std::string fieldName,dtunit;
10330       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit));
10331       switch(typcha)
10332       {
10333         case MED_FLOAT64:
10334           {
10335             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10336             break;
10337           }
10338         case MED_INT32:
10339           {
10340             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10341             break;
10342           }
10343         default:
10344           {
10345             std::ostringstream oss; oss << "constructor MEDFileFields(fileName) : file \'" << FileNameFromFID(fid) << "\' at pos #" << i << " field has name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !";
10346             throw INTERP_KERNEL::Exception(oss.str());
10347           }
10348       }
10349     }
10350   loadAllGlobals(fid);
10351 }
10352 catch(INTERP_KERNEL::Exception& e)
10353 {
10354     throw e;
10355 }
10356
10357 void MEDFileFields::writeLL(med_idt fid) const
10358 {
10359   int i=0;
10360   writeGlobals(fid,*this);
10361   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10362     {
10363       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10364       if(!elt)
10365         {
10366           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10367           throw INTERP_KERNEL::Exception(oss.str());
10368         }
10369       elt->writeLL(fid,*this);
10370     }
10371 }
10372
10373 /*!
10374  * This method alloc the arrays and load potentially huge arrays contained in this field.
10375  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10376  * This method can be also called to refresh or reinit values from a file.
10377  * 
10378  * \throw If the fileName is not set or points to a non readable MED file.
10379  */
10380 void MEDFileFields::loadArrays()
10381 {
10382   if(getFileName().empty())
10383     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10384   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10385   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10386     {
10387       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10388       if(elt)
10389         elt->loadBigArraysRecursively(fid,*elt);
10390     }
10391 }
10392
10393 /*!
10394  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10395  * But once data loaded once, this method does nothing.
10396  * 
10397  * \throw If the fileName is not set or points to a non readable MED file.
10398  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10399  */
10400 void MEDFileFields::loadArraysIfNecessary()
10401 {
10402   if(!getFileName().empty())
10403     {
10404       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10405       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10406         {
10407           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10408           if(elt)
10409             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10410         }
10411     }
10412 }
10413
10414 /*!
10415  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10416  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10417  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10418  * 
10419  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10420  */
10421 void MEDFileFields::unloadArrays()
10422 {
10423   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10424     {
10425       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10426       if(elt)
10427         elt->unloadArrays();
10428     }
10429 }
10430
10431 /*!
10432  * 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.
10433  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10434  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10435  * 
10436  * \sa MEDFileFields::loadArraysIfNecessary
10437  */
10438 void MEDFileFields::unloadArraysWithoutDataLoss()
10439 {
10440   if(!getFileName().empty())
10441     unloadArrays();
10442 }
10443
10444 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10445 {
10446   std::vector<std::string> ret;
10447   std::set<std::string> ret2;
10448   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10449     {
10450       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10451       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10452         if(ret2.find(*it2)==ret2.end())
10453           {
10454             ret.push_back(*it2);
10455             ret2.insert(*it2);
10456           }
10457     }
10458   return ret;
10459 }
10460
10461 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10462 {
10463   std::vector<std::string> ret;
10464   std::set<std::string> ret2;
10465   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10466     {
10467       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10468       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10469         if(ret2.find(*it2)==ret2.end())
10470           {
10471             ret.push_back(*it2);
10472             ret2.insert(*it2);
10473           }
10474     }
10475   return ret;
10476 }
10477
10478 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10479 {
10480   std::vector<std::string> ret;
10481   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10482     {
10483       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
10484       ret.insert(ret.end(),tmp.begin(),tmp.end());
10485     }
10486   return ret;
10487 }
10488
10489 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10490 {
10491   std::vector<std::string> ret;
10492   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10493     {
10494       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10495       ret.insert(ret.end(),tmp.begin(),tmp.end());
10496     }
10497   return ret;
10498 }
10499
10500 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10501 {
10502   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10503     (*it)->changePflsRefsNamesGen2(mapOfModif);
10504 }
10505
10506 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10507 {
10508   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10509     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10510 }
10511
10512 void MEDFileFields::resize(int newSize)
10513 {
10514   _fields.resize(newSize);
10515 }
10516
10517 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10518 {
10519   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10520     pushField(*it);
10521 }
10522
10523 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10524 {
10525   if(!field)
10526     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10527   _fields.push_back(field->getContent());
10528   appendGlobs(*field,1e-12);
10529 }
10530
10531 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10532 {
10533   if(!field)
10534     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10535   if(i>=(int)_fields.size())
10536     _fields.resize(i+1);
10537   _fields[i]=field->getContent();
10538   appendGlobs(*field,1e-12);
10539 }
10540
10541 void MEDFileFields::destroyFieldAtPos(int i)
10542 {
10543   destroyFieldsAtPos(&i,&i+1);
10544 }
10545
10546 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10547 {
10548   std::vector<bool> b(_fields.size(),true);
10549   for(const int *i=startIds;i!=endIds;i++)
10550     {
10551       if(*i<0 || *i>=(int)_fields.size())
10552         {
10553           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10554           throw INTERP_KERNEL::Exception(oss.str());
10555         }
10556       b[*i]=false;
10557     }
10558   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10559   std::size_t j=0;
10560   for(std::size_t i=0;i<_fields.size();i++)
10561     if(b[i])
10562       fields[j++]=_fields[i];
10563   _fields=fields;
10564 }
10565
10566 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10567 {
10568   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10569   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
10570   std::vector<bool> b(_fields.size(),true);
10571   int k=bg;
10572   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10573     {
10574       if(k<0 || k>=(int)_fields.size())
10575         {
10576           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10577           throw INTERP_KERNEL::Exception(oss.str());
10578         }
10579       b[k]=false;
10580     }
10581   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10582   std::size_t j(0);
10583   for(std::size_t i=0;i<_fields.size();i++)
10584     if(b[i])
10585       fields[j++]=_fields[i];
10586   _fields=fields;
10587 }
10588
10589 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10590 {
10591   bool ret(false);
10592   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10593     {
10594       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10595       if(cur)
10596         ret=cur->changeMeshNames(modifTab) || ret;
10597     }
10598   return ret;
10599 }
10600
10601 /*!
10602  * \param [in] meshName the name of the mesh that will be renumbered.
10603  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10604  *             This code corresponds to the distribution of types in the corresponding mesh.
10605  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10606  * \param [in] renumO2N the old to new renumber array.
10607  * \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 
10608  *         field in \a this.
10609  */
10610 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10611 {
10612   bool ret(false);
10613   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10614     {
10615       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10616       if(fmts)
10617         {
10618           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10619         }
10620     }
10621   return ret;
10622 }
10623
10624 /*!
10625  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10626  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10627  *
10628  * \return A new object that the caller is responsible to deallocate.
10629  */
10630 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10631 {
10632   if(!mm)
10633     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10634   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10635   int nbFields(getNumberOfFields());
10636   for(int i=0;i<nbFields;i++)
10637     {
10638       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
10639       if(!fmts)
10640         {
10641           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10642           throw INTERP_KERNEL::Exception(oss.str());
10643         }
10644       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10645       fsOut->pushField(fmtsOut);
10646     }
10647   return fsOut.retn();
10648 }
10649
10650 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10651 {
10652   if(i<0 || i>=(int)_fields.size())
10653     {
10654       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10655       throw INTERP_KERNEL::Exception(oss.str());
10656     }
10657   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10658   if(!fmts)
10659     return 0;
10660   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10661   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
10662   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
10663   if(fmtsC)
10664     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10665   else if(fmtsC2)
10666     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10667   else
10668     {
10669       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10670       throw INTERP_KERNEL::Exception(oss.str());
10671     }
10672   ret->shallowCpyGlobs(*this);
10673   return ret.retn();
10674 }
10675
10676 /*!
10677  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10678  * This method is accessible in python using __getitem__ with a list in input.
10679  * \return a new object that the caller should deal with.
10680  */
10681 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10682 {
10683   MCAuto<MEDFileFields> ret=shallowCpy();
10684   std::size_t sz=std::distance(startIds,endIds);
10685   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10686   int j=0;
10687   for(const int *i=startIds;i!=endIds;i++,j++)
10688     {
10689       if(*i<0 || *i>=(int)_fields.size())
10690         {
10691           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10692           throw INTERP_KERNEL::Exception(oss.str());
10693         }
10694       fields[j]=_fields[*i];
10695     }
10696   ret->_fields=fields;
10697   return ret.retn();
10698 }
10699
10700 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10701 {
10702   return getFieldAtPos(getPosFromFieldName(fieldName));
10703 }
10704
10705 /*!
10706  * This method removes, if any, fields in \a this having no time steps.
10707  * 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.
10708  * 
10709  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10710  */
10711 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10712 {
10713   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10714   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10715     {
10716       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10717       if(elt)
10718         {
10719           if(elt->getNumberOfTS()>0)
10720             newFields.push_back(*it);
10721         }
10722     }
10723   if(_fields.size()==newFields.size())
10724     return false;
10725   _fields=newFields;
10726   return true;
10727 }
10728
10729 /*!
10730  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10731  * This method can be seen as a filter applied on \a this, that returns an object containing
10732  * 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
10733  * shallow copied from \a this.
10734  * 
10735  * \param [in] meshName - the name of the mesh on w
10736  * \return a new object that the caller should deal with.
10737  */
10738 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10739 {
10740   MCAuto<MEDFileFields> ret(MEDFileFields::New());
10741   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10742     {
10743       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10744       if(!cur)
10745         continue;
10746       if(cur->getMeshName()==meshName)
10747         {
10748           cur->incrRef();
10749           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10750           ret->_fields.push_back(cur2);
10751         }
10752     }
10753   ret->shallowCpyOnlyUsedGlobs(*this);
10754   return ret.retn();
10755 }
10756
10757 /*!
10758  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10759  * Input time steps are specified using a pair of integer (iteration, order).
10760  * 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,
10761  * but for each multitimestep only the time steps in \a timeSteps are kept.
10762  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10763  * 
10764  * The returned object points to shallow copy of elements in \a this.
10765  * 
10766  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10767  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10768  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10769  */
10770 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10771 {
10772   MCAuto<MEDFileFields> ret(MEDFileFields::New());
10773   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10774     {
10775       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10776       if(!cur)
10777         continue;
10778       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10779       ret->_fields.push_back(elt);
10780     }
10781   ret->shallowCpyOnlyUsedGlobs(*this);
10782   return ret.retn();
10783 }
10784
10785 /*!
10786  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10787  */
10788 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10789 {
10790   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10791   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10792     {
10793       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10794       if(!cur)
10795         continue;
10796       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10797       if(elt->getNumberOfTS()!=0)
10798         ret->_fields.push_back(elt);
10799     }
10800   ret->shallowCpyOnlyUsedGlobs(*this);
10801   return ret.retn();
10802 }
10803
10804 MEDFileFieldsIterator *MEDFileFields::iterator()
10805 {
10806   return new MEDFileFieldsIterator(this);
10807 }
10808
10809 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10810 {
10811   std::string tmp(fieldName);
10812   std::vector<std::string> poss;
10813   for(std::size_t i=0;i<_fields.size();i++)
10814     {
10815       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
10816       if(f)
10817         {
10818           std::string fname(f->getName());
10819           if(tmp==fname)
10820             return i;
10821           else
10822             poss.push_back(fname);
10823         }
10824     }
10825   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10826   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10827   oss << " !";
10828   throw INTERP_KERNEL::Exception(oss.str());
10829 }
10830
10831 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10832 {
10833   if(fs)
10834     {
10835       fs->incrRef();
10836       _nb_iter=fs->getNumberOfFields();
10837     }
10838 }
10839
10840 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10841 {
10842 }
10843
10844 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10845 {
10846   if(_iter_id<_nb_iter)
10847     {
10848       MEDFileFields *fs(_fs);
10849       if(fs)
10850         return fs->getFieldAtPos(_iter_id++);
10851       else
10852         return 0;
10853     }
10854   else
10855     return 0;
10856 }