Salome HOME
Debugging before generation of classic fields/meshes from structure elements...
[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()),profilesize,nbi;
541   TypeOfField type(getType());
542   med_geometry_type mgeoti;
543   med_entity_type menti;
544   _father->entriesForMEDfile(type,mgeoti,menti);
545   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
546   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
547   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
548   const PartDefinition *pd(_pd);
549   if(!pd)
550     {
551       _nval=zeNVal;
552     }
553   else
554     {
555       if(!_profile.empty())
556         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
557       _nval=pd->getNumberOfElems();
558     }
559   _start=start;
560   _end=start+_nval*nbi;
561   start=_end;
562   if(type==ON_CELLS && !_localization.empty())
563     {
564       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
565         setType(ON_GAUSS_PT);
566       else
567         {
568           setType(ON_GAUSS_NE);
569           _localization.clear();
570         }
571     }
572 }
573
574 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
575 {
576   std::string fieldName(nasc.getName()),meshName(getMeshName());
577   int iteration(getIteration()),order(getOrder());
578   TypeOfField type(getType());
579   med_geometry_type mgeoti;
580   med_entity_type menti;
581   _father->entriesForMEDfile(type,mgeoti,menti);
582   if(_start>_end)
583     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
584   if(_start==_end)
585     return ;
586   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
587   if(_start<0 || _start>=arr->getNumberOfTuples())
588     {
589       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
590       throw INTERP_KERNEL::Exception(oss.str());
591     }
592   if(_end<0 || _end>arr->getNumberOfTuples())
593     {
594       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
595       throw INTERP_KERNEL::Exception(oss.str());
596     }
597   int nbOfCompo(arr->getNumberOfComponents());
598   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
599   if(arrD)
600     {
601       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
602       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
603       return ;
604     }
605   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
606   if(arrI)
607     {
608       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
609       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
610       return ;
611     }
612   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
613 }
614
615 /*!
616  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
617  */
618 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
619 {
620   int delta=_end-_start;
621   _start=newValueOfStart;
622   _end=_start+delta;
623 }
624
625 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
626 {
627   return _father->getIteration();
628 }
629
630 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
631 {
632   return _father->getOrder();
633 }
634
635 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
636 {
637   return _father->getTime();
638 }
639
640 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
641 {
642   return _father->getMeshName();
643 }
644
645 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
646 {
647   const char startLine[]="    ## ";
648   std::string startLine2(bkOffset,' ');
649   startLine2+=startLine;
650   INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
651   oss << startLine2 << "Localization #" << id << "." << std::endl;
652   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
653   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
654   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
655   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
656 }
657
658 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
659 {
660   return _type;
661 }
662
663 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
664 {
665   return _father->getGeoType();
666 }
667
668 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
669 {
670   types.insert(_type);
671 }
672
673 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
674 {
675   _type=newType;
676 }
677
678 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
679 {
680   return _father->getNumberOfComponents();
681 }
682
683 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
684 {
685   return _end-_start;
686 }
687
688 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
689 {
690   return _father->getOrCreateAndGetArray();
691 }
692
693 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
694 {
695   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
696   return fath->getOrCreateAndGetArray();
697 }
698
699 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
700 {
701   return _father->getInfo();
702 }
703
704 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
705 {
706   return _profile;
707 }
708
709 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
710 {
711   _profile=newPflName;
712 }
713
714 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
715 {
716   return _localization;
717 }
718
719 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
720 {
721   _localization=newLocName;
722 }
723
724 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
725 {
726   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
727     {
728       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
729         {
730           _profile=(*it2).second;
731           return;
732         }
733     }
734 }
735
736 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
737 {
738   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
739     {
740       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
741         {
742           _localization=(*it2).second;
743           return;
744         }
745     }
746 }
747
748 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
749 {
750   if(type!=_type)
751     return ;
752   dads.push_back(std::pair<int,int>(_start,_end));
753   geoTypes.push_back(getGeoType());
754   if(_profile.empty())
755     pfls.push_back(0);
756   else
757     {
758       pfls.push_back(glob->getProfile(_profile.c_str()));
759     }
760   if(_localization.empty())
761     locs.push_back(-1);
762   else
763     {
764       locs.push_back(glob->getLocalizationId(_localization.c_str()));
765     }
766 }
767
768 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
769 {
770   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));
771   startEntryId++;
772 }
773
774 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
775 {
776   TypeOfField type=getType();
777   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
778   med_geometry_type mgeoti;
779   med_entity_type menti;
780   _father->entriesForMEDfile(getType(),mgeoti,menti);
781   const DataArray *arr(getOrCreateAndGetArray());
782   if(!arr)
783     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
784   if(!arr->isAllocated())
785     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
786   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
787   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
788   const unsigned char *locToWrite=0;
789   if(arrD)
790     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
791   else if(arrI)
792     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
793   else
794     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
795   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
796                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
797                                                    locToWrite));
798 }
799
800 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
801 {
802   type=_type;
803   pfl=_profile;
804   loc=_localization;
805   dad.first=_start; dad.second=_end;
806 }
807
808 /*!
809  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
810  *             This code corresponds to the distribution of types in the corresponding mesh.
811  * \param [out] ptToFill memory zone where the output will be stored.
812  * \return the size of data pushed into output param \a ptToFill
813  */
814 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
815 {
816   _loc_id=offset;
817   std::ostringstream oss;
818   std::size_t nbOfType=codeOfMesh.size()/3;
819   int found=-1;
820   for(std::size_t i=0;i<nbOfType && found==-1;i++)
821     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
822       found=(int)i;
823   if(found==-1)
824     {
825       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
826       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
827       throw INTERP_KERNEL::Exception(oss.str());
828     }
829   int *work=ptToFill;
830   if(_profile.empty())
831     {
832       if(_nval!=codeOfMesh[3*found+1])
833         {
834           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
835           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
836           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
837           throw INTERP_KERNEL::Exception(oss.str());
838         }
839       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
840         *work++=ii;
841     }
842   else
843     {
844       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
845       if(pfl->getNumberOfTuples()!=_nval)
846         {
847           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
848           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
849           oss << _nval;
850           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
851           throw INTERP_KERNEL::Exception(oss.str());
852         }
853       int offset2=codeOfMesh[3*found+2];
854       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
855         {
856           if(*pflId<codeOfMesh[3*found+1])
857             *work++=offset2+*pflId;
858         }
859     }
860   return _nval;
861 }
862
863 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
864 {
865   for(int i=_start;i<_end;i++)
866     *ptToFill++=i;
867   return _end-_start;
868 }
869
870 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
871 {
872   switch(type)
873   {
874     case ON_CELLS:
875       return -2;
876     case ON_GAUSS_NE:
877       return -1;
878     case ON_GAUSS_PT:
879       return locId;
880     default:
881       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
882   }
883 }
884
885 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
886 {
887   int id=0;
888   std::map<std::pair<std::string,TypeOfField>,int> m;
889   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
890   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
891     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
892       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
893   ret.resize(id);
894   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
895     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
896   return ret;
897 }
898
899 /*!
900  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
901  * 
902  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
903  * \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.
904  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
905  * \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)
906  * \param [in,out] glob if necessary by the method, new profiles can be added to it
907  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
908  * \param [out] result All new entries will be appended on it.
909  * \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 !)
910  */
911 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
912                                                        const DataArrayInt *explicitIdsInMesh,
913                                                        const std::vector<int>& newCode,
914                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
915                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
916 {
917   if(entriesOnSameDisc.empty())
918     return false;
919   TypeOfField type=entriesOnSameDisc[0]->getType();
920   int szEntities=0,szTuples=0;
921   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
922     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
923   int nbi=szTuples/szEntities;
924   if(szTuples%szEntities!=0)
925     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
926   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
927   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
928   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
929   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
930   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
931   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
932   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
933   int id=0;
934   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
935     {
936       int startOfEltIdOfChunk=(*it)->_start;
937       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
938       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
939       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
940       //
941       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
942       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
943       //
944       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
945       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
946     }
947   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
948   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
949   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
950   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
951   //
952   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
953   //
954   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
955   arrPart->renumberInPlace(renumTupleIds->begin());
956   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
957   bool ret=false;
958   const int *idIt=diffVals->begin();
959   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
960   int offset2=0;
961   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
962     {
963       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
964       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
965       int nbEntityElts=subIds->getNumberOfTuples();
966       bool ret2;
967       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
968           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
969                                       offset+offset2,
970                                       li,glob,ret2);
971       ret=ret || ret2;
972       result.push_back(eltToAdd);
973       offset2+=nbEntityElts*nbi;
974     }
975   ret=ret || li.empty();
976   return ret;
977 }
978
979 /*!
980  * \param [in] typeF type of field of new chunk
981  * \param [in] geoType the geometric type of the chunk
982  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
983  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
984  * \param [in] nbi number of integration points
985  * \param [in] offset The offset in the **global array of data**.
986  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
987  *                 to the new chunk to create.
988  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
989  * \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
990  *              and corresponding entry erased from \a entriesOnSameDisc.
991  * \return a newly allocated chunk
992  */
993 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
994                                                                                                   bool isPfl, int nbi, int offset,
995                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
996                                                                                                   MEDFileFieldGlobsReal& glob,
997                                                                                                   bool &notInExisting)
998 {
999   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1000   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1001   for(;it!=entriesOnSameDisc.end();it++)
1002     {
1003       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1004         {
1005           if(!isPfl)
1006             {
1007               if((*it)->_profile.empty())
1008                 break;
1009               else
1010                 if(!(*it)->_profile.empty())
1011                   {
1012                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1013                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1014                       break;
1015                   }
1016             }
1017         }
1018     }
1019   if(it==entriesOnSameDisc.end())
1020     {
1021       notInExisting=true;
1022       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1023       ret->_type=typeF;
1024       ret->_loc_id=(int)geoType;
1025       ret->_nval=nbMeshEntities;
1026       ret->_start=offset;
1027       ret->_end=ret->_start+ret->_nval*nbi;
1028       if(isPfl)
1029         {
1030           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1031           glob.appendProfile(idsOfMeshElt);
1032           ret->_profile=idsOfMeshElt->getName();
1033         }
1034       //tony treatment of localization
1035       return ret;
1036     }
1037   else
1038     {
1039       notInExisting=false;
1040       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1041       ret->_loc_id=(int)geoType;
1042       ret->setNewStart(offset);
1043       entriesOnSameDisc.erase(it);
1044       return ret;
1045     }
1046
1047 }
1048
1049 ////////////////////////////////////
1050
1051 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1052  {
1053  }
1054
1055 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1056 {
1057   _father=father;
1058 }
1059
1060 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1061 {
1062   std::size_t i=0;
1063   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1064     {
1065       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1066         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1067     }
1068 }
1069
1070 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1071 {
1072   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1073 }
1074
1075 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1076 {
1077   std::vector<const BigMemoryObject *> ret;
1078   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1079     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1080   return ret;
1081 }
1082
1083 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1084 {
1085   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1086   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1087     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1088 }
1089
1090 /*!
1091  * This method is the most general one. No optimization is done here.
1092  * \param [in] multiTypePfl is the end user profile specified in high level API
1093  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1094  * \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.
1095  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1096  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1097  * \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.
1098  */
1099 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)
1100 {
1101   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1102   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1103     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1104 }
1105
1106 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1107 {
1108   _field_pm_pt_pd.resize(1);
1109   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1110   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1111 }
1112
1113 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1114 {
1115   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1116   if(!arr || !arr->isAllocated())
1117     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1118   _field_pm_pt_pd.resize(1);
1119   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1120   _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.
1121 }
1122
1123 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1124 {
1125   TypeOfField type=field->getTypeOfField();
1126   if(type!=ON_GAUSS_PT)
1127     {
1128       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1129       int sz=_field_pm_pt_pd.size();
1130       bool found=false;
1131       for(int j=0;j<sz && !found;j++)
1132         {
1133           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1134             {
1135               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1136               found=true;
1137             }
1138         }
1139       if(!found)
1140         {
1141           _field_pm_pt_pd.resize(sz+1);
1142           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1143         }
1144       std::vector<int> ret(1,(int)sz);
1145       return ret;
1146     }
1147   else
1148     {
1149       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1150       int sz2=ret2.size();
1151       std::vector<int> ret3(sz2);
1152       int k=0;
1153       for(int i=0;i<sz2;i++)
1154         {
1155           int sz=_field_pm_pt_pd.size();
1156           int locIdToFind=ret2[i];
1157           bool found=false;
1158           for(int j=0;j<sz && !found;j++)
1159             {
1160               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1161                 {
1162                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1163                   ret3[k++]=j;
1164                   found=true;
1165                 }
1166             }
1167           if(!found)
1168             {
1169               _field_pm_pt_pd.resize(sz+1);
1170               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1171               ret3[k++]=sz;
1172             }
1173         }
1174       return ret3;
1175     }
1176 }
1177
1178 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1179 {
1180   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1181   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1182   if(!disc2)
1183     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1184   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1185   if(!da)
1186     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1187   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1188   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1189   if(retTmp->presenceOfValue(-1))
1190     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1191   std::vector<int> ret(retTmp->begin(),retTmp->end());
1192   return ret;
1193 }
1194
1195 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1196 {
1197   TypeOfField type=field->getTypeOfField();
1198   if(type!=ON_GAUSS_PT)
1199     {
1200       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1201       int sz=_field_pm_pt_pd.size();
1202       bool found=false;
1203       for(int j=0;j<sz && !found;j++)
1204         {
1205           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1206             {
1207               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1208               found=true;
1209             }
1210         }
1211       if(!found)
1212         {
1213           _field_pm_pt_pd.resize(sz+1);
1214           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1215         }
1216       std::vector<int> ret(1,0);
1217       return ret;
1218     }
1219   else
1220     {
1221       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1222       int sz2=ret2.size();
1223       std::vector<int> ret3(sz2);
1224       int k=0;
1225       for(int i=0;i<sz2;i++)
1226         {
1227           int sz=_field_pm_pt_pd.size();
1228           int locIdToFind=ret2[i];
1229           bool found=false;
1230           for(int j=0;j<sz && !found;j++)
1231             {
1232               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1233                 {
1234                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1235                   ret3[k++]=j;
1236                   found=true;
1237                 }
1238             }
1239           if(!found)
1240             {
1241               _field_pm_pt_pd.resize(sz+1);
1242               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1243               ret3[k++]=sz;
1244             }
1245         }
1246       return ret3;
1247     }
1248 }
1249
1250 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1251 {
1252   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1253   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1254   if(!disc2)
1255     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1256   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1257   if(!da)
1258     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1259   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1260   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1261   if(retTmp->presenceOfValue(-1))
1262     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1263   std::vector<int> ret(retTmp->begin(),retTmp->end());
1264   return ret;
1265 }
1266
1267 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1268 {
1269   return _father;
1270 }
1271
1272 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1273 {
1274   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1275   int curDim((int)cm.getDimension());
1276   if(dim!=std::numeric_limits<int>::max())
1277     {
1278       if(dim!=curDim)
1279         return false;
1280     }
1281   else
1282     dim=curDim;
1283   return true;
1284 }
1285
1286 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1287 {
1288   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1289     {
1290       (*it)->fillTypesOfFieldAvailable(types);
1291     }
1292 }
1293
1294 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
1295 {
1296   int sz=_field_pm_pt_pd.size();
1297   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1298   for(int i=0;i<sz;i++)
1299     {
1300       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1301     }
1302 }
1303
1304 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1305 {
1306   return _father->getIteration();
1307 }
1308
1309 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1310 {
1311   return _father->getOrder();
1312 }
1313
1314 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1315 {
1316   return _father->getTime();
1317 }
1318
1319 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1320 {
1321   return _father->getMeshName();
1322 }
1323
1324 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1325 {
1326   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1327     {
1328       globalSz+=(*it)->getNumberOfTuples();
1329     }
1330   nbOfEntries+=(int)_field_pm_pt_pd.size();
1331 }
1332
1333 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1334 {
1335   return _father->getNumberOfComponents();
1336 }
1337
1338 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1339 {
1340   std::size_t nb(0);
1341   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1342     {
1343       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1344       if(fmtd)
1345         nb++;
1346     }
1347   return nb>1;
1348 }
1349
1350 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1351 {
1352   return _father->getOrCreateAndGetArray();
1353 }
1354
1355 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1356 {
1357   const MEDFileFieldPerMesh *fath=_father;
1358   return fath->getOrCreateAndGetArray();
1359 }
1360
1361 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1362 {
1363   return _father->getInfo();
1364 }
1365
1366 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1367 {
1368   std::vector<std::string> ret;
1369   std::set<std::string> ret2;
1370   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1371     {
1372       std::string tmp=(*it1)->getProfile();
1373       if(!tmp.empty())
1374         if(ret2.find(tmp)==ret2.end())
1375           {
1376             ret.push_back(tmp);
1377             ret2.insert(tmp);
1378           }
1379     }
1380   return ret;
1381 }
1382
1383 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1384 {
1385   std::vector<std::string> ret;
1386   std::set<std::string> ret2;
1387   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1388     {
1389       std::string tmp=(*it1)->getLocalization();
1390       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1391         if(ret2.find(tmp)==ret2.end())
1392           {
1393             ret.push_back(tmp);
1394             ret2.insert(tmp);
1395           }
1396     }
1397   return ret;
1398 }
1399
1400 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1401 {
1402   std::vector<std::string> ret;
1403   std::set<std::string> ret2;
1404   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1405     {
1406       std::string tmp=(*it1)->getProfile();
1407       if(!tmp.empty())
1408         ret.push_back(tmp);
1409     }
1410   return ret;
1411 }
1412
1413 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1414 {
1415   std::vector<std::string> ret;
1416   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1417     {
1418       std::string tmp=(*it1)->getLocalization();
1419       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1420         ret.push_back(tmp);
1421     }
1422   return ret;
1423 }
1424
1425 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1426 {
1427   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1428     (*it1)->changePflsRefsNamesGen(mapOfModif);
1429 }
1430
1431 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1432 {
1433   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1434     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1435 }
1436
1437 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1438 {
1439   if(_field_pm_pt_pd.empty())
1440     {
1441       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1442       throw INTERP_KERNEL::Exception(oss.str());
1443     }
1444   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1445     return _field_pm_pt_pd[locId];
1446   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1447   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1448   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1449   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1450 }
1451
1452 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1453 {
1454   if(_field_pm_pt_pd.empty())
1455     {
1456       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1457       throw INTERP_KERNEL::Exception(oss.str());
1458     }
1459   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1460     return _field_pm_pt_pd[locId];
1461   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1462   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1463   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1464   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1465 }
1466
1467 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1468 {
1469   int i=0;
1470   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1471     {
1472       (*it)->fillValues(i,startEntryId,entries);
1473     }
1474 }
1475
1476 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1477 {
1478   _field_pm_pt_pd=leaves;
1479   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1480     (*it)->setFather(this);
1481 }
1482
1483 /*!
1484  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1485  *  \param [out] its - list of pair (start,stop) kept
1486  *  \return bool - false if the type of field \a tof is not contained in \a this.
1487  */
1488 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1489 {
1490   bool ret(false);
1491   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1492   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1493     if((*it)->getType()==tof)
1494       {
1495         newPmPtPd.push_back(*it);
1496         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1497         (*it)->setNewStart(globalNum);
1498         globalNum=(*it)->getEnd();
1499         its.push_back(bgEnd);
1500         ret=true;
1501       }
1502   if(ret)
1503     _field_pm_pt_pd=newPmPtPd;
1504   return ret;
1505 }
1506
1507 /*!
1508  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1509  *  \param [out] its - list of pair (start,stop) kept
1510  *  \return bool - false if the type of field \a tof is not contained in \a this.
1511  */
1512 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1513 {
1514   if(_field_pm_pt_pd.size()<=idOfDisc)
1515     return false;
1516   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1517   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1518   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1519   elt->setNewStart(globalNum);
1520   globalNum=elt->getEnd();
1521   its.push_back(bgEnd);
1522   _field_pm_pt_pd=newPmPtPd;
1523   return true;
1524 }
1525
1526 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1527 {
1528   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1529     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1530 }
1531
1532 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1533 {
1534   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1535     (*it)->loadBigArray(fid,nasc);
1536 }
1537
1538 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1539 {
1540   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1541     {
1542       (*it)->copyOptionsFrom(*this);
1543       (*it)->writeLL(fid,nasc);
1544     }
1545 }
1546
1547 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1548 {
1549   switch(ikType)
1550   {
1551     case ON_CELLS:
1552       medfGeoType=typmai3[(int)ikGeoType];
1553       return MED_CELL;
1554     case ON_NODES:
1555       medfGeoType=MED_NONE;
1556       return MED_NODE;
1557     case ON_GAUSS_NE:
1558       medfGeoType=typmai3[(int)ikGeoType];
1559       return MED_NODE_ELEMENT;
1560     case ON_GAUSS_PT:
1561       medfGeoType=typmai3[(int)ikGeoType];
1562       return MED_CELL;
1563     default:
1564       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1565   }
1566   return MED_UNDEF_ENTITY_TYPE;
1567 }
1568
1569 //////////////////////////////////////////////////
1570
1571 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1572 {
1573   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1574 }
1575
1576 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1577 {
1578   return new MEDFileFieldPerMeshPerType(fath,geoType);
1579 }
1580
1581 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1582 {
1583   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1584   ret->setFather(father);
1585   ret->deepCopyElements();
1586   return ret.retn();
1587 }
1588
1589 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
1590 {
1591   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1592     {
1593       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1594       if(meshDim!=(int)cm.getDimension())
1595         return ;
1596     }
1597   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1598     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1599 }
1600
1601 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1602 {
1603   return _geo_type;
1604 }
1605
1606 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1607 {
1608   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1609 }
1610
1611 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1612 {
1613   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1614   int curDim((int)cm.getDimension());
1615   dim=std::max(dim,curDim);
1616 }
1617
1618 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1619 {
1620   const char startLine[]="  ## ";
1621   std::string startLine2(bkOffset,' ');
1622   std::string startLine3(startLine2);
1623   startLine3+=startLine;
1624   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1625     {
1626       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1627       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1628     }
1629   else
1630     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1631   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1632   int i=0;
1633   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1634     {
1635       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1636       if(cur)
1637         cur->simpleRepr(bkOffset,oss,i);
1638       else
1639         {
1640           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1641         }
1642     }
1643 }
1644
1645 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1646 {
1647   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1648   return std::string(cm.getRepr());
1649 }
1650
1651 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1652 {
1653 }
1654
1655 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1656 {
1657   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1658   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1659   med_geometry_type mgeoti;
1660   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1661   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1662   _field_pm_pt_pd.resize(nbProfiles);
1663   for(int i=0;i<nbProfiles;i++)
1664     {
1665       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1666     }
1667   if(type==ON_CELLS)
1668     {
1669       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1670       for(int i=0;i<nbProfiles2;i++)
1671         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1672     }
1673 }
1674
1675 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)
1676 {
1677   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1678   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1679   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1680     {
1681       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1682         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1683     }
1684   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1685     {
1686       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1687       ret->_field_pm_pt_pd.push_back(agg);
1688     }
1689   return ret;
1690 }
1691
1692 //////////////////////////////////////////////////
1693
1694 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1695 {
1696   if(!entities)
1697     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1698   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1699   if(!entities2)
1700     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1701   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1702   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1703 }
1704
1705 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1706 {
1707   _se.takeRef(se);
1708   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1709   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1710   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1711   _field_pm_pt_pd.resize(nbProfiles);
1712   for(int i=0;i<nbProfiles;i++)
1713     {
1714       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1715     }
1716 }
1717
1718 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1719 {
1720   return _se->getDynGT();
1721 }
1722
1723 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1724 {
1725   throw INTERP_KERNEL::Exception("not implemented yet !");
1726 }
1727
1728 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1729 {
1730   gt=getDynGT();
1731   ent=MED_STRUCT_ELEMENT;
1732 }
1733
1734 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1735 {
1736   throw INTERP_KERNEL::Exception("not implemented yet !");
1737 }
1738
1739 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1740 {
1741   const char startLine[]="  ## ";
1742   std::string startLine2(bkOffset,' ');
1743   std::string startLine3(startLine2);
1744   startLine3+=startLine;
1745   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1746   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1747   int i=0;
1748   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1749     {
1750       if((*it).isNotNull())
1751         (*it)->simpleRepr(bkOffset,oss,i);
1752       else
1753         {
1754           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1755         }
1756     }
1757 }
1758
1759 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1760 {
1761   throw INTERP_KERNEL::Exception("not implemented yet !");
1762 }
1763
1764 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1765 {
1766   MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1767   ret->setFather(father);
1768   ret->deepCopyElements();
1769   return ret.retn();
1770 }
1771
1772 void MEDFileFieldPerMeshPerTypeDyn::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
1773 {
1774   throw INTERP_KERNEL::Exception("not implemented yet !");
1775 }
1776
1777 //////////////////////////////////////////////////
1778
1779 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1780 {
1781   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1782 }
1783
1784 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1785 {
1786   return new MEDFileFieldPerMesh(fath,mesh);
1787 }
1788
1789 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1790 {
1791   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1792 }
1793
1794 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1795 {
1796   std::vector<const BigMemoryObject *> ret;
1797   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1798     ret.push_back(*it);
1799   return ret;
1800 }
1801
1802 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1803 {
1804   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1805   ret->_father=father;
1806   std::size_t i=0;
1807   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1808     {
1809       if((*it).isNotNull())
1810         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1811     }
1812   return ret.retn();
1813 }
1814
1815 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1816 {
1817   std::string startLine(bkOffset,' ');
1818   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1819   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1820   int i=0;
1821   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1822     {
1823       if((*it).isNotNull())
1824         (*it)->simpleRepr(bkOffset,oss,i);
1825       else
1826         {
1827           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1828         }
1829     }
1830 }
1831
1832 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1833 {
1834   _mesh_name=mesh->getName();
1835   mesh->getTime(_mesh_iteration,_mesh_order);
1836 }
1837
1838 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1839 {
1840   int nbOfTypes=code.size()/3;
1841   int offset=0;
1842   for(int i=0;i<nbOfTypes;i++)
1843     {
1844       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1845       int nbOfCells=code[3*i+1];
1846       int pos=addNewEntryIfNecessary(type);
1847       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1848       offset+=nbOfCells;
1849     }
1850 }
1851
1852 /*!
1853  * This method is the most general one. No optimization is done here.
1854  * \param [in] multiTypePfl is the end user profile specified in high level API
1855  * \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].
1856  * \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.
1857  * \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.
1858  * \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.
1859  * \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.
1860  */
1861 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)
1862 {
1863   int nbOfTypes(code.size()/3);
1864   for(int i=0;i<nbOfTypes;i++)
1865     {
1866       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1867       int pos=addNewEntryIfNecessary(type);
1868       DataArrayInt *pfl=0;
1869       if(code[3*i+2]!=-1)
1870         pfl=idsPerType[code[3*i+2]];
1871       int nbOfTupes2=code2.size()/3;
1872       int found=0;
1873       for(;found<nbOfTupes2;found++)
1874         if(code[3*i]==code2[3*found])
1875           break;
1876       if(found==nbOfTupes2)
1877         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1878       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1879     }
1880 }
1881
1882 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1883 {
1884   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1885   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1886 }
1887
1888 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1889 {
1890   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1891   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1892 }
1893
1894 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1895 {
1896   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1897     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1898 }
1899
1900 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1901 {
1902   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1903     (*it)->loadBigArraysRecursively(fid,nasc);
1904 }
1905
1906 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1907 {
1908   int nbOfTypes=_field_pm_pt.size();
1909   for(int i=0;i<nbOfTypes;i++)
1910     {
1911       _field_pm_pt[i]->copyOptionsFrom(*this);
1912       _field_pm_pt[i]->writeLL(fid,nasc);
1913     }
1914 }
1915
1916 void MEDFileFieldPerMesh::getDimension(int& dim) const
1917 {
1918   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1919     (*it)->getDimension(dim);
1920 }
1921
1922 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
1923 {
1924   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1925     if(!(*it)->isUniqueLevel(dim))
1926       return false;
1927   return true;
1928 }
1929
1930 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1931 {
1932   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1933     (*it)->fillTypesOfFieldAvailable(types);
1934 }
1935
1936 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
1937 {
1938   int sz=_field_pm_pt.size();
1939   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1940   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1941   for(int i=0;i<sz;i++)
1942     {
1943       types[i]=_field_pm_pt[i]->getGeoType();
1944       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1945     }
1946   return ret;
1947 }
1948
1949 double MEDFileFieldPerMesh::getTime() const
1950 {
1951   int tmp1,tmp2;
1952   return _father->getTime(tmp1,tmp2);
1953 }
1954
1955 int MEDFileFieldPerMesh::getIteration() const
1956 {
1957   return _father->getIteration();
1958 }
1959
1960 int MEDFileFieldPerMesh::getOrder() const
1961 {
1962   return _father->getOrder();
1963 }
1964
1965 int MEDFileFieldPerMesh::getNumberOfComponents() const
1966 {
1967   return _father->getNumberOfComponents();
1968 }
1969
1970 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1971 {
1972   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1973     {
1974       if((*it).isNull())
1975         continue;
1976       if((*it)->presenceOfMultiDiscPerGeoType())
1977         return true;
1978     }
1979   return false;
1980 }
1981
1982 bool MEDFileFieldPerMesh::presenceOfStructureElements() const
1983 {
1984   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1985     if((*it).isNotNull())
1986       {
1987         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
1988         if(pt)
1989           return true;
1990       }
1991   return false;
1992 }
1993
1994 bool MEDFileFieldPerMesh::onlyStructureElements() const
1995 {
1996   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1997     if((*it).isNotNull())
1998       {
1999         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2000         if(!pt)
2001           return false;
2002       }
2003   return true;
2004 }
2005
2006 void MEDFileFieldPerMesh::killStructureElements()
2007 {
2008   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2009   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2010     {
2011       if((*it).isNotNull())
2012         {
2013           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2014           if(!pt)
2015             res.push_back(*it);
2016         }
2017     }
2018   _field_pm_pt=res;
2019 }
2020
2021 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2022 {
2023   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2024   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2025     {
2026       if((*it).isNotNull())
2027         {
2028           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2029           if(pt)
2030             res.push_back(*it);
2031         }
2032     }
2033   _field_pm_pt=res;
2034 }
2035
2036 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2037 {
2038   if(!_father)
2039     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2040   return _father->getOrCreateAndGetArray();
2041 }
2042
2043 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2044 {
2045   if(!_father)
2046     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2047   return _father->getOrCreateAndGetArray();
2048 }
2049
2050 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2051 {
2052   return _father->getInfo();
2053 }
2054
2055 /*!
2056  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2057  * 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.
2058  * It returns 2 output vectors :
2059  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2060  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2061  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2062  */
2063 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)
2064 {
2065   int notNullPflsSz=0;
2066   int nbOfArrs=geoTypes.size();
2067   for(int i=0;i<nbOfArrs;i++)
2068     if(pfls[i])
2069       notNullPflsSz++;
2070   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2071   int nbOfDiffGeoTypes=geoTypes3.size();
2072   code.resize(3*nbOfDiffGeoTypes);
2073   notNullPfls.resize(notNullPflsSz);
2074   notNullPflsSz=0;
2075   int j=0;
2076   for(int i=0;i<nbOfDiffGeoTypes;i++)
2077     {
2078       int startZone=j;
2079       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2080       std::vector<const DataArrayInt *> notNullTmp;
2081       if(pfls[j])
2082         notNullTmp.push_back(pfls[j]);
2083       j++;
2084       for(;j<nbOfArrs;j++)
2085         if(geoTypes[j]==refType)
2086           {
2087             if(pfls[j])
2088               notNullTmp.push_back(pfls[j]);
2089           }
2090         else
2091           break;
2092       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2093       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2094       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2095       code[3*i]=(int)refType;
2096       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2097       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2098       if(notNullTmp.empty())
2099         code[3*i+2]=-1;
2100       else
2101         {
2102           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2103           code[3*i+2]=notNullPflsSz++;
2104         }
2105     }
2106 }
2107
2108 /*!
2109  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2110  */
2111 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)
2112 {
2113   int sz=dads.size();
2114   int ret=0;
2115   for(int i=0;i<sz;i++)
2116     {
2117       if(locs[i]==-1)
2118         {
2119           if(type!=ON_GAUSS_NE)
2120             ret+=dads[i].second-dads[i].first;
2121           else
2122             {
2123               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2124               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2125             }
2126         }
2127       else
2128         {
2129           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2130           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2131         }
2132     }
2133   return ret;
2134 }
2135
2136 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2137 {
2138   std::vector<std::string> ret;
2139   std::set<std::string> ret2;
2140   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2141     {
2142       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2143       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2144         if(ret2.find(*it2)==ret2.end())
2145           {
2146             ret.push_back(*it2);
2147             ret2.insert(*it2);
2148           }
2149     }
2150   return ret;
2151 }
2152
2153 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2154 {
2155   std::vector<std::string> ret;
2156   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2157     {
2158       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2159       ret.insert(ret.end(),tmp.begin(),tmp.end());
2160     }
2161   return ret;
2162 }
2163
2164 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2165 {
2166   std::vector<std::string> ret;
2167   std::set<std::string> ret2;
2168   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2169     {
2170       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2171       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2172         if(ret2.find(*it2)==ret2.end())
2173           {
2174             ret.push_back(*it2);
2175             ret2.insert(*it2);
2176           }
2177     }
2178   return ret;
2179 }
2180
2181 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2182 {
2183   std::vector<std::string> ret;
2184   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2185     {
2186       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2187       ret.insert(ret.end(),tmp.begin(),tmp.end());
2188     }
2189   return ret;
2190 }
2191
2192 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2193 {
2194   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2195     {
2196       if((*it).first==_mesh_name)
2197         {
2198           _mesh_name=(*it).second;
2199           return true;
2200         }
2201     }
2202   return false;
2203 }
2204
2205 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2206                                                       MEDFileFieldGlobsReal& glob)
2207 {
2208   if(_mesh_name!=meshName)
2209     return false;
2210   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2211   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2212   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2213   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2214   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2215   getUndergroundDataArrayExt(entries);
2216   DataArray *arr0(getOrCreateAndGetArray());//tony
2217   if(!arr0)
2218     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2219   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2220   if(!arr0)
2221     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2222   int sz=0;
2223   if(!arr)
2224     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2225   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2226     {
2227       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2228         {
2229           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2230           sz+=(*it).second.second-(*it).second.first;
2231         }
2232       else
2233         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2234     }
2235   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2236   ////////////////////
2237   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2238   int *workI2=explicitIdsOldInMesh->getPointer();
2239   int sz1=0,sz2=0,sid=1;
2240   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2241   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2242   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2243     {
2244       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2245       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2246       int *workI=explicitIdsOldInArr->getPointer();
2247       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2248         {
2249           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2250           (*itL2)->setLocId(sz2);
2251           (*itL2)->_tmp_work1=(*itL2)->getStart();
2252           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2253         }
2254       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2255     }
2256   explicitIdsOldInMesh->reAlloc(sz2);
2257   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2258   ////////////////////
2259   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2260   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2261   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2262   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2263     {
2264       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2265       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2266       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2267     }
2268   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2269   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2270   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2271     {
2272       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2273       int newStart=elt->getLocId();
2274       elt->setLocId((*it)->getGeoType());
2275       elt->setNewStart(newStart);
2276       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2277       entriesKeptNew.push_back(elt);
2278       entriesKeptNew2.push_back(elt);
2279     }
2280   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2281   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2282   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2283   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2284   bool ret=false;
2285   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2286     {
2287       sid=0;
2288       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2289         {
2290           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2291           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2292           }*/
2293       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2294                                                             glob,arr2,otherEntriesNew) || ret;
2295     }
2296   if(!ret)
2297     return false;
2298   // Assign new dispatching
2299   assignNewLeaves(otherEntriesNew);
2300   arr->deepCopyFrom(*arr2);
2301   return true;
2302 }
2303
2304 /*!
2305  * \param [in,out] globalNum a global numbering counter for the renumbering.
2306  * \param [out] its - list of pair (start,stop) kept
2307  */
2308 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2309 {
2310   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2311   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2312     {
2313       std::vector< std::pair<int,int> > its2;
2314       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2315         {
2316           ret.push_back(*it);
2317           its.insert(its.end(),its2.begin(),its2.end());
2318         }
2319     }
2320   _field_pm_pt=ret;
2321 }
2322
2323 /*!
2324  * \param [in,out] globalNum a global numbering counter for the renumbering.
2325  * \param [out] its - list of pair (start,stop) kept
2326  */
2327 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2328 {
2329   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2330   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2331     {
2332       std::vector< std::pair<int,int> > its2;
2333       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2334         {
2335           ret.push_back(*it);
2336           its.insert(its.end(),its2.begin(),its2.end());
2337         }
2338     }
2339   _field_pm_pt=ret;
2340 }
2341
2342 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2343 {
2344   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2345   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2346     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2347   //
2348   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2349   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2350   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2351   for(;it1!=types.end();it1++,it2++)
2352     {
2353       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2354       elt->setLeaves((*it1).second);
2355       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2356       *it2=elt2;
2357     }
2358   _field_pm_pt=fieldPmPt;
2359 }
2360
2361 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2362 {
2363   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2364     (*it)->changePflsRefsNamesGen(mapOfModif);
2365 }
2366
2367 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2368 {
2369   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2370     (*it)->changeLocsRefsNamesGen(mapOfModif);
2371 }
2372
2373 /*!
2374  * \param [in] mesh is the whole mesh
2375  */
2376 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2377 {
2378   if(_field_pm_pt.empty())
2379     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2380   //
2381   std::vector< std::pair<int,int> > dads;
2382   std::vector<const DataArrayInt *> pfls;
2383   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2384   std::vector<int> locs,code;
2385   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2386   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2387     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2388   // Sort by types
2389   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2390   if(code.empty())
2391     {
2392       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2393       throw INTERP_KERNEL::Exception(oss.str());
2394     }
2395   //
2396   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2397   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2398   if(type!=ON_NODES)
2399     {
2400       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2401       if(!arr)
2402         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2403       else
2404         {
2405           MCAuto<DataArrayInt> arr2(arr);
2406           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2407         }
2408     }
2409   else
2410     {
2411       if(code.size()!=3)
2412         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2413       int nb=code[1];
2414       if(code[2]==-1)
2415         {
2416           if(nb!=mesh->getNumberOfNodes())
2417             {
2418               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2419               oss << " nodes in mesh !";
2420               throw INTERP_KERNEL::Exception(oss.str());
2421             }
2422           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2423         }
2424       else
2425         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2426     }
2427 }
2428
2429 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2430 {
2431   if(_field_pm_pt.empty())
2432     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2433   //
2434   std::vector<std::pair<int,int> > dads;
2435   std::vector<const DataArrayInt *> pfls;
2436   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2437   std::vector<int> locs,code;
2438   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2439   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2440     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2441   // Sort by types
2442   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2443   if(code.empty())
2444     {
2445       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2446       throw INTERP_KERNEL::Exception(oss.str());
2447     }
2448   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2449   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2450   if(type!=ON_NODES)
2451     {
2452       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2453       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2454     }
2455   else
2456     {
2457       if(code.size()!=3)
2458         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2459       int nb=code[1];
2460       if(code[2]==-1)
2461         {
2462           if(nb!=mesh->getNumberOfNodes())
2463             {
2464               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2465               oss << " nodes in mesh !";
2466               throw INTERP_KERNEL::Exception(oss.str());
2467             }
2468         }
2469       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2470     }
2471   //
2472   return 0;
2473 }
2474
2475 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2476 {
2477   int globalSz=0;
2478   int nbOfEntries=0;
2479   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2480     {
2481       (*it)->getSizes(globalSz,nbOfEntries);
2482     }
2483   entries.resize(nbOfEntries);
2484   nbOfEntries=0;
2485   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2486     {
2487       (*it)->fillValues(nbOfEntries,entries);
2488     }
2489 }
2490
2491 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2492 {
2493   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2494     {
2495       if((*it)->getGeoType()==typ)
2496         return (*it)->getLeafGivenLocId(locId);
2497     }
2498   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2499   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2500   oss << "Possiblities are : ";
2501   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2502     {
2503       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2504       oss << "\"" << cm2.getRepr() << "\", ";
2505     }
2506   throw INTERP_KERNEL::Exception(oss.str());
2507 }
2508
2509 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2510 {
2511   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2512     {
2513       if((*it)->getGeoType()==typ)
2514         return (*it)->getLeafGivenLocId(locId);
2515     }
2516   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2517   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2518   oss << "Possiblities are : ";
2519   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2520     {
2521       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2522       oss << "\"" << cm2.getRepr() << "\", ";
2523     }
2524   throw INTERP_KERNEL::Exception(oss.str());
2525 }
2526
2527 /*!
2528  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2529  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2530  * \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.
2531  * \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.
2532  */
2533 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)
2534 {
2535   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2536   if(pms.empty())
2537     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2538   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2539     {
2540       if(!(*it).second)
2541         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2542       if(!(*it).second->getProfile().empty())
2543         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2544       if(!(*it).second->getLocalization().empty())
2545         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2546     }
2547   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2548   std::size_t i(0);
2549   std::vector< std::pair<int,int> > filteredDTS;
2550   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2551     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2552       if((*it2).first==gt)
2553         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2554   if(pms.size()!=filteredDTS.size())
2555     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2556   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2557   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2558   int zeStart(start),nval(0);
2559   for(;it1!=pms.end();it1++,it2++)
2560     {
2561       if((*it1).first!=(*it2).first)
2562         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2563       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2564       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2565       start+=e1-s1;
2566       nval+=((*it1).second)->getNumberOfVals();
2567     }
2568   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2569   return ret;
2570 }
2571
2572 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)
2573 {
2574   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2575   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2576   std::size_t i(0);
2577   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2578     {
2579       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2580       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2581         {
2582           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2583           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2584           if(!elt)
2585             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2586           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2587         }
2588     }
2589   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2590     {
2591       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2592       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2593       ret->_field_pm_pt.push_back(agg2);
2594     }
2595   return ret;
2596 }
2597
2598 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2599 {
2600   int i=0;
2601   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2602   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2603   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2604     {
2605       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2606       if(type==curType)
2607         return i;
2608       else
2609         {
2610           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2611           if(pos>pos2)
2612             it2=it+1;
2613         }
2614     }
2615   int ret=std::distance(_field_pm_pt.begin(),it2);
2616   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2617   return ret;
2618 }
2619
2620 /*!
2621  * 'dads' and 'locs' input parameters have the same number of elements
2622  * \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
2623  */
2624 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2625                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2626                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2627 {
2628   isPfl=false;
2629   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2630   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2631   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2632   const std::vector<std::string>& infos=getInfo();
2633   da->setInfoOnComponents(infos);
2634   da->setName("");
2635   if(type==ON_GAUSS_PT)
2636     {
2637       int offset=0;
2638       int nbOfArrs=dads.size();
2639       for(int i=0;i<nbOfArrs;i++)
2640         {
2641           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2642           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2643           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2644           MCAuto<DataArrayInt> di=DataArrayInt::New();
2645           di->alloc(nbOfElems,1);
2646           di->iota(offset);
2647           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2648           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2649           offset+=nbOfElems;
2650         }
2651     }
2652   arrOut=da;
2653   return ret.retn();
2654 }
2655
2656 /*!
2657  * 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.
2658  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2659  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2660  * The order of cells in the returned field is those imposed by the profile.
2661  * \param [in] mesh is the global mesh.
2662  */
2663 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2664                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2665                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2666                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2667 {
2668   if(da->isIota(mesh->getNumberOfCells()))
2669     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2670   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2671   m2->setName(mesh->getName().c_str());
2672   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2673   isPfl=true;
2674   return ret.retn();
2675 }
2676
2677 /*!
2678  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2679  */
2680 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2681                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2682                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2683 {
2684   if(da->isIota(mesh->getNumberOfNodes()))
2685     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2686   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2687   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2688   if(meshu)
2689     {
2690       if(meshu->getNodalConnectivity()==0)
2691         {
2692           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2693           int nb=da->getNbOfElems();
2694           const int *ptr=da->getConstPointer();
2695           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2696           meshuc->allocateCells(nb);
2697           for(int i=0;i<nb;i++)
2698             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2699           meshuc->finishInsertingCells();
2700           ret->setMesh(meshuc);
2701           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2702           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2703           disc->checkCoherencyBetween(meshuc,arrOut);
2704           return ret.retn();
2705         }
2706     }
2707   //
2708   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2709   isPfl=true;
2710   DataArrayInt *arr2=0;
2711   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2712   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2713   MCAuto<DataArrayInt> arr3(arr2);
2714   int nnodes=mesh2->getNumberOfNodes();
2715   if(nnodes==(int)da->getNbOfElems())
2716     {
2717       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2718       arrOut->renumberInPlace(da3->getConstPointer());
2719       mesh2->setName(mesh->getName().c_str());
2720       ret->setMesh(mesh2);
2721       return ret.retn();
2722     }
2723   else
2724     {
2725       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 !!!";
2726       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2727       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2728       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2729       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2730       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2731       throw INTERP_KERNEL::Exception(oss.str());
2732     }
2733   return 0;
2734 }
2735
2736 /*!
2737  * This method is the most light method of field retrieving.
2738  */
2739 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2740 {
2741   if(!pflIn)
2742     {
2743       pflOut=DataArrayInt::New();
2744       pflOut->alloc(nbOfElems,1);
2745       pflOut->iota(0);
2746     }
2747   else
2748     {
2749       pflOut=const_cast<DataArrayInt*>(pflIn);
2750       pflOut->incrRef();
2751     }
2752   MCAuto<DataArrayInt> safePfl(pflOut);
2753   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2754   const std::vector<std::string>& infos=getInfo();
2755   int nbOfComp=infos.size();
2756   for(int i=0;i<nbOfComp;i++)
2757     da->setInfoOnComponent(i,infos[i].c_str());
2758   safePfl->incrRef();
2759   return da.retn();
2760 }
2761
2762
2763 /// @cond INTERNAL
2764
2765 class MFFPMIter
2766 {
2767 public:
2768   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2769   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2770   virtual ~MFFPMIter() { }
2771   virtual void begin() = 0;
2772   virtual bool finished() const = 0;
2773   virtual void next() = 0;
2774   virtual int current() const = 0;
2775 };
2776
2777 class MFFPMIterSimple : public MFFPMIter
2778 {
2779 public:
2780   MFFPMIterSimple():_pos(0) { }
2781   void begin() { _pos=0; }
2782   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2783   void next() { _pos++; }
2784   int current() const { return _pos; }
2785 private:
2786   int _pos;
2787 };
2788
2789 class MFFPMIter2 : public MFFPMIter
2790 {
2791 public:
2792   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2793   void begin() { _it=_ids.begin(); }
2794   bool finished() const { return _it==_ids.end(); }
2795   void next() { _it++; }
2796   int current() const { return *_it; }
2797 private:
2798   std::vector<int> _ids;
2799   std::vector<int>::const_iterator _it;
2800 };
2801
2802 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
2803 {
2804   if(!entities)
2805     return new MFFPMIterSimple;
2806   else
2807     {
2808       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2809       if(entities2)
2810         {
2811           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2812           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2813           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2814             {
2815               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2816                 tmp.push_back((*it).second);
2817             }
2818           return new MFFPMIter2(tmp);
2819         }
2820       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
2821     }
2822 }
2823
2824 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
2825 {
2826   if(!entities)
2827     return true;
2828   else
2829     {
2830       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2831       if(entities2)
2832         {
2833           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2834           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2835             if((*it).first==ON_NODES)
2836               return true;
2837           return false;
2838         }
2839       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
2840     }
2841 }
2842
2843 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2844 {
2845   std::size_t sz(cts.size());
2846   _ids.resize(sz);
2847   for(std::size_t i=0;i<sz;i++)
2848     {
2849       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2850       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2851         _ids[i]=(int)std::distance(typmai2,loc);
2852       else
2853         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2854     }
2855 }
2856
2857 /// @endcond
2858
2859 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),
2860     _father(fath)
2861 {
2862   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2863   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2864   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2865   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2866   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2867   for(iter0->begin();!iter0->finished();iter0->next())
2868     {
2869       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2870       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2871       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2872       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2873       if(nbProfile>0 || nbProfile2>0)
2874         {
2875           const PartDefinition *pd(0);
2876           if(mmu)
2877             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2878           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2879           if(nbProfile>0)
2880             _mesh_name=name0;
2881           else
2882             _mesh_name=name1;
2883         }
2884     }
2885   if(MFFPMIter::IsPresenceOfNode(entities))
2886     {
2887       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2888       if(nbProfile>0)
2889         {
2890           const PartDefinition *pd(0);
2891           if(mmu)
2892             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2893           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2894           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2895         }
2896     }
2897   if(!entities)
2898     return ;
2899   std::vector<int> dynGT(entities->getDynGTAvail());
2900   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
2901     {
2902       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
2903       if(nbPfl>0)
2904         {
2905           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
2906           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2907         }
2908     }
2909 }
2910
2911 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2912 {
2913   copyTinyInfoFrom(mesh);
2914 }
2915
2916 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2917 {
2918   if(id>=(int)_pfls.size())
2919     _pfls.resize(id+1);
2920   _pfls[id]=DataArrayInt::New();
2921   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2922   _pfls[id]->setName(pflName);
2923   _pfls[id]->alloc(lgth,1);
2924   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2925   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2926 }
2927
2928 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2929 {
2930   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2931   int sz;
2932   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2933   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2934   if(i>=(int)_pfls.size())
2935     _pfls.resize(i+1);
2936   _pfls[i]=DataArrayInt::New();
2937   _pfls[i]->alloc(sz,1);
2938   _pfls[i]->setName(pflCpp.c_str());
2939   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2940   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2941 }
2942
2943 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2944 {
2945   int nbOfPfls=_pfls.size();
2946   for(int i=0;i<nbOfPfls;i++)
2947     {
2948       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2949       cpy->applyLin(1,1,0);
2950       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2951       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2952       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2953     }
2954   //
2955   int nbOfLocs=_locs.size();
2956   for(int i=0;i<nbOfLocs;i++)
2957     _locs[i]->writeLL(fid);
2958 }
2959
2960 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2961 {
2962   std::vector<std::string> pfls=getPfls();
2963   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2964     {
2965       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2966       if(it2==pfls.end())
2967         {
2968           _pfls.push_back(*it);
2969         }
2970       else
2971         {
2972           int id=std::distance(pfls.begin(),it2);
2973           if(!(*it)->isEqual(*_pfls[id]))
2974             {
2975               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2976               throw INTERP_KERNEL::Exception(oss.str());
2977             }
2978         }
2979     }
2980   std::vector<std::string> locs=getLocs();
2981   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2982     {
2983       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2984       if(it2==locs.end())
2985         {
2986           _locs.push_back(*it);
2987         }
2988       else
2989         {
2990           int id=std::distance(locs.begin(),it2);
2991           if(!(*it)->isEqual(*_locs[id],eps))
2992             {
2993               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2994               throw INTERP_KERNEL::Exception(oss.str());
2995             }
2996         }
2997     }
2998 }
2999
3000 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
3001 {
3002   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
3003     getProfile((*it).c_str());
3004 }
3005
3006 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
3007 {
3008   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
3009     getLocalization((*it).c_str());
3010 }
3011
3012 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
3013 {
3014   std::vector<std::string> profiles=real.getPflsReallyUsed();
3015   int sz=profiles.size();
3016   _pfls.resize(sz);
3017   for(int i=0;i<sz;i++)
3018     loadProfileInFile(fid,i,profiles[i].c_str());
3019   //
3020   std::vector<std::string> locs=real.getLocsReallyUsed();
3021   sz=locs.size();
3022   _locs.resize(sz);
3023   for(int i=0;i<sz;i++)
3024     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
3025 }
3026
3027 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
3028 {
3029   int nProfil=MEDnProfile(fid);
3030   for(int i=0;i<nProfil;i++)
3031     loadProfileInFile(fid,i);
3032   int sz=MEDnLocalization(fid);
3033   _locs.resize(sz);
3034   for(int i=0;i<sz;i++)
3035     {
3036       _locs[i]=MEDFileFieldLoc::New(fid,i);
3037     }
3038 }
3039
3040 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
3041 {
3042   return new MEDFileFieldGlobs(fid);
3043 }
3044
3045 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
3046 {
3047   return new MEDFileFieldGlobs;
3048 }
3049
3050 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
3051 {
3052   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
3053 }
3054
3055 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
3056 {
3057   std::vector<const BigMemoryObject *> ret;
3058   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3059     ret.push_back((const DataArrayInt *)*it);
3060   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3061     ret.push_back((const MEDFileFieldLoc *)*it);
3062   return ret;
3063 }
3064
3065 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3066 {
3067   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3068   std::size_t i=0;
3069   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3070     {
3071       if((const DataArrayInt *)*it)
3072         ret->_pfls[i]=(*it)->deepCopy();
3073     }
3074   i=0;
3075   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3076     {
3077       if((const MEDFileFieldLoc*)*it)
3078         ret->_locs[i]=(*it)->deepCopy();
3079     }
3080   return ret.retn();
3081 }
3082
3083 /*!
3084  * \throw if a profile in \a pfls in not in \a this.
3085  * \throw if a localization in \a locs in not in \a this.
3086  * \sa MEDFileFieldGlobs::deepCpyPart
3087  */
3088 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3089 {
3090   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3091   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3092     {
3093       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3094       if(!pfl)
3095         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3096       pfl->incrRef();
3097       MCAuto<DataArrayInt> pfl2(pfl);
3098       ret->_pfls.push_back(pfl2);
3099     }
3100   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3101     {
3102       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3103       if(!loc)
3104         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3105       loc->incrRef();
3106       MCAuto<MEDFileFieldLoc> loc2(loc);
3107       ret->_locs.push_back(loc2);
3108     }
3109   ret->setFileName(getFileName());
3110   return ret.retn();
3111 }
3112
3113 /*!
3114  * \throw if a profile in \a pfls in not in \a this.
3115  * \throw if a localization in \a locs in not in \a this.
3116  * \sa MEDFileFieldGlobs::shallowCpyPart
3117  */
3118 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3119 {
3120   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3121   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3122     {
3123       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3124       if(!pfl)
3125         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3126       ret->_pfls.push_back(pfl->deepCopy());
3127     }
3128   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3129     {
3130       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3131       if(!loc)
3132         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3133       ret->_locs.push_back(loc->deepCopy());
3134     }
3135   ret->setFileName(getFileName());
3136   return ret.retn();
3137 }
3138
3139 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3140 {
3141 }
3142
3143 MEDFileFieldGlobs::MEDFileFieldGlobs()
3144 {
3145 }
3146
3147 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3148 {
3149 }
3150
3151 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3152 {
3153   oss << "Profiles :\n";
3154   std::size_t n=_pfls.size();
3155   for(std::size_t i=0;i<n;i++)
3156     {
3157       oss << "  - #" << i << " ";
3158       const DataArrayInt *pfl=_pfls[i];
3159       if(pfl)
3160         oss << "\"" << pfl->getName() << "\"\n";
3161       else
3162         oss << "EMPTY !\n";
3163     }
3164   n=_locs.size();
3165   oss << "Localizations :\n";
3166   for(std::size_t i=0;i<n;i++)
3167     {
3168       oss << "  - #" << i << " ";
3169       const MEDFileFieldLoc *loc=_locs[i];
3170       if(loc)
3171         loc->simpleRepr(oss);
3172       else
3173         oss<< "EMPTY !\n";
3174     }
3175 }
3176
3177 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3178 {
3179   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3180     {
3181       DataArrayInt *elt(*it);
3182       if(elt)
3183         {
3184           std::string name(elt->getName());
3185           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3186             {
3187               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3188                 {
3189                   elt->setName((*it2).second.c_str());
3190                   return;
3191                 }
3192             }
3193         }
3194     }
3195 }
3196
3197 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3198 {
3199   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3200     {
3201       MEDFileFieldLoc *elt(*it);
3202       if(elt)
3203         {
3204           std::string name(elt->getName());
3205           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3206             {
3207               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3208                 {
3209                   elt->setName((*it2).second.c_str());
3210                   return;
3211                 }
3212             }
3213         }
3214     }
3215 }
3216
3217 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3218 {
3219   if(locId<0 || locId>=(int)_locs.size())
3220     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3221   return _locs[locId]->getNbOfGaussPtPerCell();
3222 }
3223
3224 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3225 {
3226   return getLocalizationFromId(getLocalizationId(locName));
3227 }
3228
3229 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3230 {
3231   if(locId<0 || locId>=(int)_locs.size())
3232     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3233   return *_locs[locId];
3234 }
3235
3236 /// @cond INTERNAL
3237 namespace MEDCouplingImpl
3238 {
3239   class LocFinder
3240   {
3241   public:
3242     LocFinder(const std::string& loc):_loc(loc) { }
3243     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3244   private:
3245     const std::string &_loc;
3246   };
3247
3248   class PflFinder
3249   {
3250   public:
3251     PflFinder(const std::string& pfl):_pfl(pfl) { }
3252     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3253   private:
3254     const std::string& _pfl;
3255   };
3256 }
3257 /// @endcond
3258
3259 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3260 {
3261   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3262   if(it==_locs.end())
3263     {
3264       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3265       for(it=_locs.begin();it!=_locs.end();it++)
3266         oss << "\"" << (*it)->getName() << "\", ";
3267       throw INTERP_KERNEL::Exception(oss.str());
3268     }
3269   return std::distance(_locs.begin(),it);
3270 }
3271
3272 /*!
3273  * The returned value is never null.
3274  */
3275 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3276 {
3277   std::string pflNameCpp(pflName);
3278   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3279   if(it==_pfls.end())
3280     {
3281       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3282       for(it=_pfls.begin();it!=_pfls.end();it++)
3283         oss << "\"" << (*it)->getName() << "\", ";
3284       throw INTERP_KERNEL::Exception(oss.str());
3285     }
3286   return *it;
3287 }
3288
3289 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3290 {
3291   if(pflId<0 || pflId>=(int)_pfls.size())
3292     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3293   return _pfls[pflId];
3294 }
3295
3296 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3297 {
3298   if(locId<0 || locId>=(int)_locs.size())
3299     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3300   return *_locs[locId];
3301 }
3302
3303 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3304 {
3305   return getLocalizationFromId(getLocalizationId(locName));
3306 }
3307
3308 /*!
3309  * The returned value is never null.
3310  */
3311 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3312 {
3313   std::string pflNameCpp(pflName);
3314   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3315   if(it==_pfls.end())
3316     {
3317       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3318       for(it=_pfls.begin();it!=_pfls.end();it++)
3319         oss << "\"" << (*it)->getName() << "\", ";
3320       throw INTERP_KERNEL::Exception(oss.str());
3321     }
3322   return *it;
3323 }
3324
3325 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3326 {
3327   if(pflId<0 || pflId>=(int)_pfls.size())
3328     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3329   return _pfls[pflId];
3330 }
3331
3332 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3333 {
3334   std::vector< MCAuto<DataArrayInt> > newPfls;
3335   int i=0;
3336   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3337     {
3338       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3339         newPfls.push_back(*it);
3340     }
3341   _pfls=newPfls;
3342 }
3343
3344 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3345 {
3346   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3347   int i=0;
3348   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3349     {
3350       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3351         newLocs.push_back(*it);
3352     }
3353   _locs=newLocs;
3354 }
3355
3356 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3357 {
3358   int sz=_pfls.size();
3359   std::vector<std::string> ret(sz);
3360   for(int i=0;i<sz;i++)
3361     ret[i]=_pfls[i]->getName();
3362   return ret;
3363 }
3364
3365 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3366 {
3367   int sz=_locs.size();
3368   std::vector<std::string> ret(sz);
3369   for(int i=0;i<sz;i++)
3370     ret[i]=_locs[i]->getName();
3371   return ret;
3372 }
3373
3374 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3375 {
3376   std::vector<std::string> v=getPfls();
3377   std::string s(pflName);
3378   return std::find(v.begin(),v.end(),s)!=v.end();
3379 }
3380
3381 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3382 {
3383   std::vector<std::string> v=getLocs();
3384   std::string s(locName);
3385   return std::find(v.begin(),v.end(),s)!=v.end();
3386 }
3387
3388 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3389 {
3390   std::map<int,std::vector<int> > m;
3391   int i=0;
3392   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3393     {
3394       const DataArrayInt *tmp=(*it);
3395       if(tmp)
3396         {
3397           m[tmp->getHashCode()].push_back(i);
3398         }
3399     }
3400   std::vector< std::vector<int> > ret;
3401   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3402     {
3403       if((*it2).second.size()>1)
3404         {
3405           std::vector<int> ret0;
3406           bool equalityOrNot=false;
3407           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3408             {
3409               std::vector<int>::const_iterator it4=it3; it4++;
3410               for(;it4!=(*it2).second.end();it4++)
3411                 {
3412                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3413                     {
3414                       if(!equalityOrNot)
3415                         ret0.push_back(*it3);
3416                       ret0.push_back(*it4);
3417                       equalityOrNot=true;
3418                     }
3419                 }
3420             }
3421           if(!ret0.empty())
3422             ret.push_back(ret0);
3423         }
3424     }
3425   return ret;
3426 }
3427
3428 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3429 {
3430   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3431 }
3432
3433 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3434 {
3435   std::string name(pfl->getName());
3436   if(name.empty())
3437     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3438   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3439     if(name==(*it)->getName())
3440       {
3441         if(!pfl->isEqual(*(*it)))
3442           {
3443             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3444             throw INTERP_KERNEL::Exception(oss.str());
3445           }
3446       }
3447   pfl->incrRef();
3448   _pfls.push_back(pfl);
3449 }
3450
3451 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)
3452 {
3453   std::string name(locName);
3454   if(name.empty())
3455     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3456   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3457   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3458     if((*it)->isName(locName))
3459       {
3460         if(!(*it)->isEqual(*obj,1e-12))
3461           {
3462             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3463             throw INTERP_KERNEL::Exception(oss.str());
3464           }
3465       }
3466   _locs.push_back(obj);
3467 }
3468
3469 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3470 {
3471   std::vector<std::string> names=getPfls();
3472   return CreateNewNameNotIn("NewPfl_",names);
3473 }
3474
3475 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3476 {
3477   std::vector<std::string> names=getLocs();
3478   return CreateNewNameNotIn("NewLoc_",names);
3479 }
3480
3481 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3482 {
3483   for(std::size_t sz=0;sz<100000;sz++)
3484     {
3485       std::ostringstream tryName;
3486       tryName << prefix << sz;
3487       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3488         return tryName.str();
3489     }
3490   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3491 }
3492
3493 /*!
3494  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3495  *  \param [in] fname - the file name.
3496  */
3497 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3498 {
3499 }
3500
3501 /*!
3502  * Creates an empty MEDFileFieldGlobsReal.
3503  */
3504 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3505 {
3506 }
3507
3508 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3509 {
3510   return 0;
3511 }
3512
3513 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3514 {
3515   std::vector<const BigMemoryObject *> ret;
3516   ret.push_back((const MEDFileFieldGlobs *)_globals);
3517   return ret;
3518 }
3519
3520 /*!
3521  * Returns a string describing profiles and Gauss points held in \a this.
3522  *  \return std::string - the description string.
3523  */
3524 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3525 {
3526   const MEDFileFieldGlobs *glob=_globals;
3527   std::ostringstream oss2; oss2 << glob;
3528   std::string stars(oss2.str().length(),'*');
3529   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3530   if(glob)
3531     glob->simpleRepr(oss);
3532   else
3533     oss << "NO GLOBAL INFORMATION !\n";
3534 }
3535
3536 void MEDFileFieldGlobsReal::resetContent()
3537 {
3538   _globals=MEDFileFieldGlobs::New();
3539 }
3540
3541 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3542 {
3543 }
3544
3545 /*!
3546  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3547  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3548  */
3549 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3550 {
3551   _globals=other._globals;
3552 }
3553
3554 /*!
3555  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3556  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3557  */
3558 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3559 {
3560   const MEDFileFieldGlobs *otherg(other._globals);
3561   if(!otherg)
3562     return ;
3563   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3564 }
3565
3566 /*!
3567  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3568  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3569  */
3570 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3571 {
3572   const MEDFileFieldGlobs *otherg(other._globals);
3573   if(!otherg)
3574     return ;
3575   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3576 }
3577
3578 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3579 {
3580   _globals=other._globals;
3581   if((const MEDFileFieldGlobs *)_globals)
3582     _globals=other._globals->deepCopy();
3583 }
3584
3585 /*!
3586  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3587  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3588  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3589  *         \a this and \a other MEDFileFieldGlobsReal.
3590  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3591  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3592  */
3593 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3594 {
3595   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3596   if(thisGlobals==otherGlobals)
3597     return ;
3598   if(!thisGlobals)
3599     {
3600       _globals=other._globals;
3601       return ;
3602     }
3603   _globals->appendGlobs(*other._globals,eps);
3604 }
3605
3606 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3607 {
3608   checkGlobsPflsPartCoherency();
3609   checkGlobsLocsPartCoherency();
3610 }
3611
3612 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3613 {
3614   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3615 }
3616
3617 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3618 {
3619   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3620 }
3621
3622 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3623 {
3624   contentNotNull()->loadProfileInFile(fid,id,pflName);
3625 }
3626
3627 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3628 {
3629   contentNotNull()->loadProfileInFile(fid,id);
3630 }
3631
3632 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3633 {
3634   contentNotNull()->loadGlobals(fid,*this);
3635 }
3636
3637 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3638 {
3639   contentNotNull()->loadAllGlobals(fid);
3640 }
3641
3642 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3643 {
3644   contentNotNull()->writeGlobals(fid,opt);
3645 }
3646
3647 /*!
3648  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3649  * or getPflsReallyUsedMulti().
3650  *  \return std::vector<std::string> - a sequence of names of all profiles.
3651  */
3652 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3653 {
3654   return contentNotNull()->getPfls();
3655 }
3656
3657 /*!
3658  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3659  * or getLocsReallyUsedMulti().
3660  *  \return std::vector<std::string> - a sequence of names of all localizations.
3661  */
3662 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3663 {
3664   return contentNotNull()->getLocs();
3665 }
3666
3667 /*!
3668  * Checks if the profile with a given name exists.
3669  *  \param [in] pflName - the profile name of interest.
3670  *  \return bool - \c true if the profile named \a pflName exists.
3671  */
3672 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3673 {
3674   return contentNotNull()->existsPfl(pflName);
3675 }
3676
3677 /*!
3678  * Checks if the localization with a given name exists.
3679  *  \param [in] locName - the localization name of interest.
3680  *  \return bool - \c true if the localization named \a locName exists.
3681  */
3682 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3683 {
3684   return contentNotNull()->existsLoc(locName);
3685 }
3686
3687 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3688 {
3689   return contentNotNull()->createNewNameOfPfl();
3690 }
3691
3692 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3693 {
3694   return contentNotNull()->createNewNameOfLoc();
3695 }
3696
3697 /*!
3698  * Sets the name of a MED file.
3699  *  \param [inout] fileName - the file name.
3700  */
3701 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3702 {
3703   contentNotNull()->setFileName(fileName);
3704 }
3705
3706 /*!
3707  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3708  * in the same order.
3709  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3710  *          Each item of this sequence is a vector containing ids of equal profiles.
3711  */
3712 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3713 {
3714   return contentNotNull()->whichAreEqualProfiles();
3715 }
3716
3717 /*!
3718  * Finds equal localizations.
3719  *  \param [in] eps - a precision used to compare real values of the localizations.
3720  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3721  *          Each item of this sequence is a vector containing ids of equal localizations.
3722  */
3723 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3724 {
3725   return contentNotNull()->whichAreEqualLocs(eps);
3726 }
3727
3728 /*!
3729  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3730  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3731  *        this sequence is a pair whose 
3732  *        - the first item is a vector of profile names to replace by the second item,
3733  *        - the second item is a profile name to replace every profile name of the first item.
3734  */
3735 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3736 {
3737   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3738 }
3739
3740 /*!
3741  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3742  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3743  *        this sequence is a pair whose 
3744  *        - the first item is a vector of localization names to replace by the second item,
3745  *        - the second item is a localization name to replace every localization name of the first item.
3746  */
3747 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3748 {
3749   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3750 }
3751
3752 /*!
3753  * Replaces references to some profiles (a reference is a profile name) by references
3754  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3755  * them-selves accordingly. <br>
3756  * This method is a generalization of changePflName().
3757  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3758  *        this sequence is a pair whose 
3759  *        - the first item is a vector of profile names to replace by the second item,
3760  *        - the second item is a profile name to replace every profile of the first item.
3761  * \sa changePflsRefsNamesGen()
3762  * \sa changePflName()
3763  */
3764 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3765 {
3766   changePflsRefsNamesGen(mapOfModif);
3767   changePflsNamesInStruct(mapOfModif);
3768 }
3769
3770 /*!
3771  * Replaces references to some localizations (a reference is a localization name) by references
3772  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3773  * them-selves accordingly. <br>
3774  * This method is a generalization of changeLocName().
3775  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3776  *        this sequence is a pair whose 
3777  *        - the first item is a vector of localization names to replace by the second item,
3778  *        - the second item is a localization name to replace every localization of the first item.
3779  * \sa changeLocsRefsNamesGen()
3780  * \sa changeLocName()
3781  */
3782 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3783 {
3784   changeLocsRefsNamesGen(mapOfModif);
3785   changeLocsNamesInStruct(mapOfModif);
3786 }
3787
3788 /*!
3789  * Renames the profile having a given name and updates references to this profile.
3790  *  \param [in] oldName - the name of the profile to rename.
3791  *  \param [in] newName - a new name of the profile.
3792  * \sa changePflsNames().
3793  */
3794 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3795 {
3796   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3797   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3798   mapOfModif[0]=p;
3799   changePflsNames(mapOfModif);
3800 }
3801
3802 /*!
3803  * Renames the localization having a given name and updates references to this localization.
3804  *  \param [in] oldName - the name of the localization to rename.
3805  *  \param [in] newName - a new name of the localization.
3806  * \sa changeLocsNames().
3807  */
3808 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3809 {
3810   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3811   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3812   mapOfModif[0]=p;
3813   changeLocsNames(mapOfModif);
3814 }
3815
3816 /*!
3817  * Removes duplicated profiles. Returns a map used to update references to removed 
3818  * profiles via changePflsRefsNamesGen().
3819  * Equal profiles are found using whichAreEqualProfiles().
3820  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3821  *          a sequence describing the performed replacements of profiles. Each element of
3822  *          this sequence is a pair whose
3823  *          - the first item is a vector of profile names replaced by the second item,
3824  *          - the second item is a profile name replacing every profile of the first item.
3825  */
3826 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3827 {
3828   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3829   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3830   int i=0;
3831   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3832     {
3833       std::vector< std::string > tmp((*it).size());
3834       int j=0;
3835       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3836         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3837       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3838       ret[i]=p;
3839       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3840       killProfileIds(tmp2);
3841     }
3842   changePflsRefsNamesGen(ret);
3843   return ret;
3844 }
3845
3846 /*!
3847  * Removes duplicated localizations. Returns a map used to update references to removed 
3848  * localizations via changeLocsRefsNamesGen().
3849  * Equal localizations are found using whichAreEqualLocs().
3850  *  \param [in] eps - a precision used to compare real values of the localizations.
3851  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3852  *          a sequence describing the performed replacements of localizations. Each element of
3853  *          this sequence is a pair whose
3854  *          - the first item is a vector of localization names replaced by the second item,
3855  *          - the second item is a localization name replacing every localization of the first item.
3856  */
3857 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3858 {
3859   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3860   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3861   int i=0;
3862   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3863     {
3864       std::vector< std::string > tmp((*it).size());
3865       int j=0;
3866       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3867         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3868       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3869       ret[i]=p;
3870       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3871       killLocalizationIds(tmp2);
3872     }
3873   changeLocsRefsNamesGen(ret);
3874   return ret;
3875 }
3876
3877 /*!
3878  * Returns number of Gauss points per cell in a given localization.
3879  *  \param [in] locId - an id of the localization of interest.
3880  *  \return int - the number of the Gauss points per cell.
3881  */
3882 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3883 {
3884   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3885 }
3886
3887 /*!
3888  * Returns an id of a localization by its name.
3889  *  \param [in] loc - the localization name of interest.
3890  *  \return int - the id of the localization.
3891  *  \throw If there is no a localization named \a loc.
3892  */
3893 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3894 {
3895   return contentNotNull()->getLocalizationId(loc);
3896 }
3897
3898 /*!
3899  * Returns the name of the MED file.
3900  *  \return const std::string&  - the MED file name.
3901  */
3902 std::string MEDFileFieldGlobsReal::getFileName() const
3903 {
3904   return contentNotNull()->getFileName();
3905 }
3906
3907 /*!
3908  * Returns a localization object by its name.
3909  *  \param [in] locName - the name of the localization of interest.
3910  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3911  *  \throw If there is no a localization named \a locName.
3912  */
3913 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3914 {
3915   return contentNotNull()->getLocalization(locName);
3916 }
3917
3918 /*!
3919  * Returns a localization object by its id.
3920  *  \param [in] locId - the id of the localization of interest.
3921  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3922  *  \throw If there is no a localization with id \a locId.
3923  */
3924 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3925 {
3926   return contentNotNull()->getLocalizationFromId(locId);
3927 }
3928
3929 /*!
3930  * Returns a profile array by its name.
3931  *  \param [in] pflName - the name of the profile of interest.
3932  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3933  *  \throw If there is no a profile named \a pflName.
3934  */
3935 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3936 {
3937   return contentNotNull()->getProfile(pflName);
3938 }
3939
3940 /*!
3941  * Returns a profile array by its id.
3942  *  \param [in] pflId - the id of the profile of interest.
3943  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3944  *  \throw If there is no a profile with id \a pflId.
3945  */
3946 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3947 {
3948   return contentNotNull()->getProfileFromId(pflId);
3949 }
3950
3951 /*!
3952  * Returns a localization object, apt for modification, by its id.
3953  *  \param [in] locId - the id of the localization of interest.
3954  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3955  *          having the id \a locId.
3956  *  \throw If there is no a localization with id \a locId.
3957  */
3958 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3959 {
3960   return contentNotNull()->getLocalizationFromId(locId);
3961 }
3962
3963 /*!
3964  * Returns a localization object, apt for modification, by its name.
3965  *  \param [in] locName - the name of the localization of interest.
3966  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3967  *          having the name \a locName.
3968  *  \throw If there is no a localization named \a locName.
3969  */
3970 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3971 {
3972   return contentNotNull()->getLocalization(locName);
3973 }
3974
3975 /*!
3976  * Returns a profile array, apt for modification, by its name.
3977  *  \param [in] pflName - the name of the profile of interest.
3978  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3979  *  \throw If there is no a profile named \a pflName.
3980  */
3981 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3982 {
3983   return contentNotNull()->getProfile(pflName);
3984 }
3985
3986 /*!
3987  * Returns a profile array, apt for modification, by its id.
3988  *  \param [in] pflId - the id of the profile of interest.
3989  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3990  *  \throw If there is no a profile with id \a pflId.
3991  */
3992 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3993 {
3994   return contentNotNull()->getProfileFromId(pflId);
3995 }
3996
3997 /*!
3998  * Removes profiles given by their ids. No data is updated to track this removal.
3999  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
4000  */
4001 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
4002 {
4003   contentNotNull()->killProfileIds(pflIds);
4004 }
4005
4006 /*!
4007  * Removes localizations given by their ids. No data is updated to track this removal.
4008  *  \param [in] locIds - a sequence of ids of the localizations to remove.
4009  */
4010 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
4011 {
4012   contentNotNull()->killLocalizationIds(locIds);
4013 }
4014
4015 /*!
4016  * Stores a profile array.
4017  *  \param [in] pfl - the profile array to store.
4018  *  \throw If the name of \a pfl is empty.
4019  *  \throw If a profile with the same name as that of \a pfl already exists but contains
4020  *         different ids.
4021  */
4022 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
4023 {
4024   contentNotNull()->appendProfile(pfl);
4025 }
4026
4027 /*!
4028  * Adds a new localization of Gauss points.
4029  *  \param [in] locName - the name of the new localization.
4030  *  \param [in] geoType - a geometrical type of the reference cell.
4031  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
4032  *         must be \c nbOfNodesPerCell * \c dimOfType.
4033  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
4034  *         must be  _wg_.size() * \c dimOfType.
4035  *  \param [in] w - the weights of Gauss points.
4036  *  \throw If \a locName is empty.
4037  *  \throw If a localization with the name \a locName already exists but is
4038  *         different form the new one.
4039  */
4040 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)
4041 {
4042   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
4043 }
4044
4045 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
4046 {
4047   MEDFileFieldGlobs *g(_globals);
4048   if(!g)
4049     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
4050   return g;
4051 }
4052
4053 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
4054 {
4055   const MEDFileFieldGlobs *g(_globals);
4056   if(!g)
4057     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4058   return g;
4059 }
4060
4061 //= MEDFileFieldNameScope
4062
4063 MEDFileFieldNameScope::MEDFileFieldNameScope()
4064 {
4065 }
4066
4067 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
4068 {
4069 }
4070
4071 /*!
4072  * Returns the name of \a this field.
4073  *  \return std::string - a string containing the field name.
4074  */
4075 std::string MEDFileFieldNameScope::getName() const
4076 {
4077   return _name;
4078 }
4079
4080 /*!
4081  * Sets name of \a this field
4082  *  \param [in] name - the new field name.
4083  */
4084 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4085 {
4086   _name=fieldName;
4087 }
4088
4089 std::string MEDFileFieldNameScope::getDtUnit() const
4090 {
4091   return _dt_unit;
4092 }
4093
4094 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4095 {
4096   _dt_unit=dtUnit;
4097 }
4098
4099 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4100 {
4101   _name=other._name;
4102   _dt_unit=other._dt_unit;
4103 }
4104
4105 //= MEDFileAnyTypeField1TSWithoutSDA
4106
4107 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4108 {
4109   _field_per_mesh.resize(other._field_per_mesh.size());
4110   std::size_t i=0;
4111   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4112     {
4113       if((const MEDFileFieldPerMesh *)*it)
4114         _field_per_mesh[i]=(*it)->deepCopy(this);
4115     }
4116 }
4117
4118 /*!
4119  * Prints a string describing \a this field into a stream. This string is outputted 
4120  * by \c print Python command.
4121  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4122  *  \param [in,out] oss - the out stream.
4123  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4124  *          info id printed, else, not.
4125  */
4126 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4127 {
4128   std::string startOfLine(bkOffset,' ');
4129   oss << startOfLine << "Field ";
4130   if(bkOffset==0)
4131     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4132   oss << "on one time Step ";
4133   if(f1tsId>=0)
4134     oss << "(" << f1tsId << ") ";
4135   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4136   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4137   const DataArray *arr=getUndergroundDataArray();
4138   if(arr)
4139     {
4140       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4141       if(f1tsId<0)
4142         {
4143           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4144           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4145             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4146         }
4147       if(arr->isAllocated())
4148         {
4149           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4150         }
4151       else
4152         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4153     }
4154   else
4155     {
4156       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4157     }
4158   oss << startOfLine << "----------------------" << std::endl;
4159   if(!_field_per_mesh.empty())
4160     {
4161       int i=0;
4162       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4163         {
4164           const MEDFileFieldPerMesh *cur=(*it2);
4165           if(cur)
4166             cur->simpleRepr(bkOffset,oss,i);
4167           else
4168             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4169         }
4170     }
4171   else
4172     {
4173       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4174     }
4175   oss << startOfLine << "----------------------" << std::endl;
4176 }
4177
4178 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4179 {
4180   const DataArray *arr(getUndergroundDataArray());
4181   if(!arr)
4182     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4183   int nbOfCompo=arr->getNumberOfComponents();
4184   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4185   for(int i=0;i<nbOfCompo;i++)
4186     {
4187       ret[i]=deepCopy();
4188       std::vector<int> v(1,i);
4189       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4190       ret[i]->setArray(arr2);
4191     }
4192   return ret;
4193 }
4194
4195 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)
4196 {
4197 }
4198
4199 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4200 {
4201 }
4202
4203 /*!
4204  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4205  * empty. Returns -1 if this in on nodes.
4206  *  \return int - the dimension of \a this.
4207  */
4208 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4209 {
4210   int ret=-2;
4211   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4212     (*it)->getDimension(ret);
4213   return ret;
4214 }
4215
4216 /*!
4217  * Returns the mesh name.
4218  *  \return std::string - a string holding the mesh name.
4219  *  \throw If \c _field_per_mesh.empty()
4220  */
4221 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
4222 {
4223   if(_field_per_mesh.empty())
4224     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
4225   return _field_per_mesh[0]->getMeshName();
4226 }
4227
4228 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
4229 {
4230   std::string oldName(getMeshName());
4231   std::vector< std::pair<std::string,std::string> > v(1);
4232   v[0].first=oldName; v[0].second=newMeshName;
4233   changeMeshNames(v);
4234 }
4235
4236 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4237 {
4238   bool ret=false;
4239   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4240     {
4241       MEDFileFieldPerMesh *cur(*it);
4242       if(cur)
4243         ret=cur->changeMeshNames(modifTab) || ret;
4244     }
4245   return ret;
4246 }
4247
4248 /*!
4249  * Returns the number of iteration of the state of underlying mesh.
4250  *  \return int - the iteration number.
4251  *  \throw If \c _field_per_mesh.empty()
4252  */
4253 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4254 {
4255   if(_field_per_mesh.empty())
4256     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4257   return _field_per_mesh[0]->getMeshIteration();
4258 }
4259
4260 /*!
4261  * Returns the order number of iteration of the state of underlying mesh.
4262  *  \return int - the order number.
4263  *  \throw If \c _field_per_mesh.empty()
4264  */
4265 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4266 {
4267   if(_field_per_mesh.empty())
4268     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4269   return _field_per_mesh[0]->getMeshOrder();
4270 }
4271
4272 /*!
4273  * Checks if \a this field is tagged by a given iteration number and a given
4274  * iteration order number.
4275  *  \param [in] iteration - the iteration number of interest.
4276  *  \param [in] order - the iteration order number of interest.
4277  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4278  *          \a this->getOrder() == \a order.
4279  */
4280 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4281 {
4282   return iteration==_iteration && order==_order;
4283 }
4284
4285 /*!
4286  * Returns number of iteration and order number of iteration when
4287  * \a this field has been calculated.
4288  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4289  *          order number.
4290  */
4291 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4292 {
4293   std::pair<int,int> p;
4294   fillIteration(p);
4295   return p;
4296 }
4297
4298 /*!
4299  * Returns number of iteration and order number of iteration when
4300  * \a this field has been calculated.
4301  *  \param [in,out] p - a pair returning the iteration number and the iteration
4302  *          order number.
4303  */
4304 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4305 {
4306   p.first=_iteration;
4307   p.second=_order;
4308 }
4309
4310 /*!
4311  * Returns all types of spatial discretization of \a this field.
4312  *  \param [in,out] types - a sequence of types of \a this field.
4313  */
4314 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4315 {
4316   std::set<TypeOfField> types2;
4317   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4318     {
4319       (*it)->fillTypesOfFieldAvailable(types2);
4320     }
4321   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4322   std::copy(types2.begin(),types2.end(),bi);
4323 }
4324
4325 /*!
4326  * Returns all types of spatial discretization of \a this field.
4327  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4328  *          of \a this field.
4329  */
4330 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4331 {
4332   std::vector<TypeOfField> ret;
4333   fillTypesOfFieldAvailable(ret);
4334   return ret;
4335 }
4336
4337 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4338 {
4339   std::vector<std::string> ret;
4340   std::set<std::string> ret2;
4341   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4342     {
4343       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4344       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4345         if(ret2.find(*it2)==ret2.end())
4346           {
4347             ret.push_back(*it2);
4348             ret2.insert(*it2);
4349           }
4350     }
4351   return ret;
4352 }
4353
4354 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4355 {
4356   std::vector<std::string> ret;
4357   std::set<std::string> ret2;
4358   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4359     {
4360       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4361       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4362         if(ret2.find(*it2)==ret2.end())
4363           {
4364             ret.push_back(*it2);
4365             ret2.insert(*it2);
4366           }
4367     }
4368   return ret;
4369 }
4370
4371 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4372 {
4373   std::vector<std::string> ret;
4374   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4375     {
4376       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4377       ret.insert(ret.end(),tmp.begin(),tmp.end());
4378     }
4379   return ret;
4380 }
4381
4382 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4383 {
4384   std::vector<std::string> ret;
4385   std::set<std::string> ret2;
4386   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4387     {
4388       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4389       ret.insert(ret.end(),tmp.begin(),tmp.end());
4390     }
4391   return ret;
4392 }
4393
4394 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4395 {
4396   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4397     (*it)->changePflsRefsNamesGen(mapOfModif);
4398 }
4399
4400 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4401 {
4402   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4403     (*it)->changeLocsRefsNamesGen(mapOfModif);
4404 }
4405
4406 /*!
4407  * Returns all attributes of parts of \a this field lying on a given mesh.
4408  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4409  * item of every of returned sequences refers to the _i_-th part of \a this field.
4410  * Thus all sequences returned by this method are of the same length equal to number
4411  * of different types of supporting entities.<br>
4412  * A field part can include sub-parts with several different spatial discretizations,
4413  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4414  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4415  * of a nested sequence corresponds to a type of spatial discretization.<br>
4416  * This method allows for iteration over MEDFile DataStructure without any overhead.
4417  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4418  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4419  *          not checked if \a mname == \c NULL).
4420  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4421  *          a field part is returned. 
4422  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4423  *          This sequence is of the same length as \a types. 
4424  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4425  *          discretization. A profile name can be empty.
4426  *          Length of this and of nested sequences is the same as that of \a typesF.
4427  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4428  *          discretization. A localization name can be empty.
4429  *          Length of this and of nested sequences is the same as that of \a typesF.
4430  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4431  *          of ids of tuples within the data array, per each type of spatial
4432  *          discretization within one mesh entity type. 
4433  *          Length of this and of nested sequences is the same as that of \a typesF.
4434  *  \throw If no field is lying on \a mname.
4435  */
4436 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
4437 {
4438   int meshId=0;
4439   if(!mname.empty())
4440     meshId=getMeshIdFromMeshName(mname);
4441   else
4442     if(_field_per_mesh.empty())
4443       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4444   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4445 }
4446
4447 /*!
4448  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4449  * maximal absolute dimension and values returned via the out parameter \a levs are 
4450  * dimensions relative to the maximal absolute dimension. <br>
4451  * This method is designed for MEDFileField1TS instances that have a discretization
4452  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4453  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4454  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4455  * Only these 3 discretizations will be taken into account here. If \a this is
4456  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4457  * This method is useful to make the link between the dimension of the underlying mesh
4458  * and the levels of \a this, because it is possible that the highest dimension of \a this
4459  * field is not equal to the dimension of the underlying mesh.
4460  * 
4461  * Let's consider the following case:
4462  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4463  * TETRA4, HEXA8, TRI3 and SEG2.
4464  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4465  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4466  *
4467  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4468  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4469  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4470  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4471  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4472  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4473  * For example<br>
4474  * to retrieve the highest level of
4475  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4476  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4477  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4478  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4479  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4480  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4481  *          not checked if \a mname == \c NULL).
4482  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4483  *          absolute one. They are in decreasing order. This sequence is cleared before
4484  *          filling it in.
4485  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4486  *  \throw If no field is lying on \a mname.
4487  */
4488 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4489 {
4490   levs.clear();
4491   int meshId=getMeshIdFromMeshName(mname);
4492   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4493   std::vector< std::vector<TypeOfField> > typesF;
4494   std::vector< std::vector<std::string> > pfls, locs;
4495   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4496   if(types.empty())
4497     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4498   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4499   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4500     return -1;
4501   st.erase(INTERP_KERNEL::NORM_ERROR);
4502   std::set<int> ret1;
4503   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4504     {
4505       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4506       ret1.insert((int)cm.getDimension());
4507     }
4508   int ret=*std::max_element(ret1.begin(),ret1.end());
4509   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4510   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4511   return ret;
4512 }
4513
4514 /*!
4515  * \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.
4516  * \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.
4517  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4518  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4519  */
4520 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4521 {
4522   int mid=getMeshIdFromMeshName(mName);
4523   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4524 }
4525
4526 /*!
4527  * \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.
4528  * \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.
4529  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4530  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4531  */
4532 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4533 {
4534   int mid=getMeshIdFromMeshName(mName);
4535   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4536 }
4537
4538 /*!
4539  * \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.
4540  */
4541 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4542 {
4543   if(_field_per_mesh.empty())
4544     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4545   if(mName.empty())
4546     return 0;
4547   std::string mName2(mName);
4548   int ret=0;
4549   std::vector<std::string> msg;
4550   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4551     if(mName2==(*it)->getMeshName())
4552       return ret;
4553     else
4554       msg.push_back((*it)->getMeshName());
4555   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4556   oss << "Possible meshes are : ";
4557   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4558     oss << "\"" << (*it2) << "\" ";
4559   throw INTERP_KERNEL::Exception(oss.str());
4560 }
4561
4562 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4563 {
4564   if(!mesh)
4565     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4566   std::string tmp(mesh->getName());
4567   if(tmp.empty())
4568     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4569   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4570   int i=0;
4571   for(;it!=_field_per_mesh.end();it++,i++)
4572     {
4573       if((*it)->getMeshName()==tmp)
4574         return i;
4575     }
4576   int sz=_field_per_mesh.size();
4577   _field_per_mesh.resize(sz+1);
4578   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4579   return sz;
4580 }
4581
4582 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4583                                                                    MEDFileFieldGlobsReal& glob)
4584 {
4585   bool ret=false;
4586   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4587     {
4588       MEDFileFieldPerMesh *fpm(*it);
4589       if(fpm)
4590         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4591     }
4592   return ret;
4593 }
4594
4595 /*!
4596  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4597  * splitting that leads to single spatial discretization of this.
4598  *
4599  * \sa splitMultiDiscrPerGeoTypes
4600  */
4601 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4602 {
4603   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4604   std::vector< std::vector<TypeOfField> > typesF;
4605   std::vector< std::vector<std::string> > pfls,locs;
4606   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4607   std::set<TypeOfField> allEnt;
4608   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4609     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4610       allEnt.insert(*it2);
4611   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4612   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4613   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4614     {
4615       std::vector< std::pair<int,int> > its;
4616       ret[i]=shallowCpy();
4617       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4618       ret[i]->updateData(newLgth,its);
4619     }
4620   return ret;
4621 }
4622
4623 /*!
4624  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4625  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4626  *
4627  * \sa splitDiscretizations
4628  */
4629 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4630 {
4631   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4632   std::vector< std::vector<TypeOfField> > typesF;
4633   std::vector< std::vector<std::string> > pfls,locs;
4634   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4635   std::set<TypeOfField> allEnt;
4636   std::size_t nbOfMDPGT(0),ii(0);
4637   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4638     {
4639       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4640       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4641         allEnt.insert(*it2);
4642     }
4643   if(allEnt.size()!=1)
4644     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4645   if(nbOfMDPGT==0)
4646     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4647   if(nbOfMDPGT==1)
4648     {
4649       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4650       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4651       return ret0;
4652     }
4653   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4654   for(std::size_t i=0;i<nbOfMDPGT;i++)
4655     {
4656       std::vector< std::pair<int,int> > its;
4657       ret[i]=shallowCpy();
4658       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4659       ret[i]->updateData(newLgth,its);
4660     }
4661   return ret;
4662 }
4663
4664 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4665 {
4666   int globalCounter(0);
4667   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4668     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4669   return globalCounter;
4670 }
4671
4672 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4673 {
4674   int globalCounter(0);
4675   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4676     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4677   return globalCounter;
4678 }
4679
4680 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4681 {
4682   if(_nb_of_tuples_to_be_allocated>=0)
4683     {
4684       _nb_of_tuples_to_be_allocated=newLgth;
4685       const DataArray *oldArr(getUndergroundDataArray());
4686       if(oldArr)
4687         {
4688           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4689           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4690           setArray(newArr);
4691           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4692         }
4693       return ;
4694     }
4695   if(_nb_of_tuples_to_be_allocated==-1)
4696     return ;
4697   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4698     {
4699       const DataArray *oldArr(getUndergroundDataArray());
4700       if(!oldArr || !oldArr->isAllocated())
4701         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4702       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4703       newArr->alloc(newLgth,getNumberOfComponents());
4704       if(oldArr)
4705         newArr->copyStringInfoFrom(*oldArr);
4706       int pos=0;
4707       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4708         {
4709           if((*it).second<(*it).first)
4710             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4711           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4712           pos+=(*it).second-(*it).first;
4713         }
4714       setArray(newArr);
4715       return ;
4716     }
4717   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4718 }
4719
4720 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4721 {
4722   if(_field_per_mesh.empty())
4723     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4724   if(_field_per_mesh.size()>1)
4725     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4726   _field_per_mesh[0]->copyOptionsFrom(opts);
4727   _field_per_mesh[0]->writeLL(fid,nasc);
4728 }
4729
4730 /*!
4731  * 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.
4732  * If false is returned the memory allocation is not required.
4733  */
4734 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4735 {
4736   if(_nb_of_tuples_to_be_allocated>=0)
4737     {
4738       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4739       _nb_of_tuples_to_be_allocated=-2;
4740       return true;
4741     }
4742   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4743     return false;
4744   if(_nb_of_tuples_to_be_allocated==-1)
4745     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4746   if(_nb_of_tuples_to_be_allocated<-3)
4747     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4748   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4749 }
4750
4751 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4752 {
4753   med_int numdt,numit;
4754   med_float dt;
4755   med_int nmesh;
4756   med_bool localMesh;
4757   med_int meshnumdt,meshnumit;
4758   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4759   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4760   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4761   if(_iteration!=numdt || _order!=numit)
4762     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4763   _field_per_mesh.resize(nmesh);
4764   //
4765   MEDFileMesh *mm(0);
4766   if(ms)
4767     {
4768       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4769       mm=ms->getMeshWithName(meshNameCpp);
4770     }
4771   //
4772   for(int i=0;i<nmesh;i++)
4773     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4774   _nb_of_tuples_to_be_allocated=0;
4775   for(int i=0;i<nmesh;i++)
4776     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4777 }
4778
4779 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4780 {
4781   allocIfNecessaryTheArrayToReceiveDataFromFile();
4782   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4783     (*it)->loadBigArraysRecursively(fid,nasc);
4784 }
4785
4786 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4787 {
4788   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4789     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4790       (*it)->loadBigArraysRecursively(fid,nasc);
4791 }
4792
4793 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4794 {
4795   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4796   loadBigArraysRecursively(fid,nasc);
4797 }
4798
4799 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4800 {
4801   DataArray *thisArr(getUndergroundDataArray());
4802   if(thisArr && thisArr->isAllocated())
4803     {
4804       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4805       thisArr->desallocate();
4806     }
4807 }
4808
4809 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4810 {
4811   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4812 }
4813
4814 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4815 {
4816   std::vector<const BigMemoryObject *> ret;
4817   if(getUndergroundDataArray())
4818     ret.push_back(getUndergroundDataArray());
4819   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4820     ret.push_back((const MEDFileFieldPerMesh *)*it);
4821   return ret;
4822 }
4823
4824 /*!
4825  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4826  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4827  * "Sort By Type"), if not, an exception is thrown. 
4828  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4829  *  \param [in] arr - the array of values.
4830  *  \param [in,out] glob - the global data where profiles and localization present in
4831  *          \a field, if any, are added.
4832  *  \throw If the name of \a field is empty.
4833  *  \throw If the data array of \a field is not set.
4834  *  \throw If \a this->_arr is already allocated but has different number of components
4835  *         than \a field.
4836  *  \throw If the underlying mesh of \a field has no name.
4837  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4838  */
4839 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4840 {
4841   const MEDCouplingMesh *mesh=field->getMesh();
4842   //
4843   TypeOfField type=field->getTypeOfField();
4844   std::vector<DataArrayInt *> dummy;
4845   int start=copyTinyInfoFrom(field,arr);
4846   int pos=addNewEntryIfNecessary(mesh);
4847   if(type!=ON_NODES)
4848     {
4849       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4850       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4851     }
4852   else
4853     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4854 }
4855
4856 /*!
4857  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4858  * of a given mesh are used as the support of the given field (a real support is not used). 
4859  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4860  * Order of underlying mesh entities of the given field specified by \a profile parameter
4861  * is not prescribed; this method permutes field values to have them sorted by element
4862  * type as required for writing to MED file. A new profile is added only if no equal
4863  * profile is missing. 
4864  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4865  *  \param [in] arrOfVals - the values of the field \a field used.
4866  *  \param [in] mesh - the supporting mesh of \a field.
4867  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4868  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4869  *  \param [in,out] glob - the global data where profiles and localization present in
4870  *          \a field, if any, are added.
4871  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4872  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4873  *  \throw If the data array of \a field is not set.
4874  *  \throw If \a this->_arr is already allocated but has different number of components
4875  *         than \a field.
4876  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4877  *  \sa setFieldNoProfileSBT()
4878  */
4879 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4880 {
4881   if(!field)
4882     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4883   if(!arrOfVals || !arrOfVals->isAllocated())
4884     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4885   TypeOfField type=field->getTypeOfField();
4886   std::vector<DataArrayInt *> idsInPflPerType;
4887   std::vector<DataArrayInt *> idsPerType;
4888   std::vector<int> code,code2;
4889   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4890   if(type!=ON_NODES)
4891     {
4892       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4893       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4894       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4895       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4896       // start of check
4897       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4898       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4899       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4900         {
4901           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4902           throw INTERP_KERNEL::Exception(oss.str());
4903         }
4904       // end of check
4905       int start=copyTinyInfoFrom(field,arrOfVals);
4906       code2=m->getDistributionOfTypes();
4907       //
4908       int pos=addNewEntryIfNecessary(m);
4909       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4910     }
4911   else
4912     {
4913       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4914         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4915       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4916       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4917       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4918       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4919         {
4920           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4921           throw INTERP_KERNEL::Exception(oss.str());
4922         }
4923       int start=copyTinyInfoFrom(field,arrOfVals);
4924       int pos=addNewEntryIfNecessary(m);
4925       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4926     }
4927 }
4928
4929 /*!
4930  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4931  */
4932 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4933 {
4934   if(_nb_of_tuples_to_be_allocated>=0)
4935     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 !");
4936   DataArray *arr(getOrCreateAndGetArray());
4937   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4938   _nb_of_tuples_to_be_allocated=-3;
4939 }
4940
4941 /*!
4942  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4943  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4944  * larger by the size of \a field. Returns an id of the first not filled
4945  * tuple of \a this->_arr.
4946  *  \param [in] field - the field to copy the info on components and the name from.
4947  *  \return int - the id of first not initialized tuple of \a this->_arr.
4948  *  \throw If the name of \a field is empty.
4949  *  \throw If the data array of \a field is not set.
4950  *  \throw If \a this->_arr is already allocated but has different number of components
4951  *         than \a field.
4952  */
4953 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4954 {
4955   if(!field)
4956     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4957   std::string name(field->getName());
4958   setName(name.c_str());
4959   setDtUnit(field->getTimeUnit());
4960   if(name.empty())
4961     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4962   if(!arr)
4963     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4964   if(!arr->isAllocated())
4965     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4966   _dt=field->getTime(_iteration,_order);
4967   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4968   if(!getOrCreateAndGetArray()->isAllocated())
4969     {
4970       allocNotFromFile(arr->getNumberOfTuples());
4971       return 0;
4972     }
4973   else
4974     {
4975       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4976       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4977       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4978       _nb_of_tuples_to_be_allocated=-3;
4979       return oldNbOfTuples;
4980     }
4981 }
4982
4983 /*!
4984  * Returns number of components in \a this field
4985  *  \return int - the number of components.
4986  */
4987 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4988 {
4989   return getOrCreateAndGetArray()->getNumberOfComponents();
4990 }
4991
4992 /*!
4993  * Change info on components in \a this.
4994  * \throw If size of \a infos is not equal to the number of components already in \a this.
4995  */
4996 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4997 {
4998   DataArray *arr=getOrCreateAndGetArray();
4999   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
5000 }
5001
5002 /*!
5003  * Returns info on components of \a this field.
5004  *  \return const std::vector<std::string>& - a sequence of strings each being an
5005  *          information on _i_-th component.
5006  */
5007 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
5008 {
5009   const DataArray *arr=getOrCreateAndGetArray();
5010   return arr->getInfoOnComponents();
5011 }
5012
5013 /*!
5014  * Returns a mutable info on components of \a this field.
5015  *  \return std::vector<std::string>& - a sequence of strings each being an
5016  *          information on _i_-th component.
5017  */
5018 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
5019 {
5020   DataArray *arr=getOrCreateAndGetArray();
5021   return arr->getInfoOnComponents();
5022 }
5023
5024 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
5025 {
5026   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5027     {
5028       const MEDFileFieldPerMesh *fpm(*it);
5029       if(!fpm)
5030         continue;
5031       if(fpm->presenceOfMultiDiscPerGeoType())
5032         return true;
5033     }
5034   return false;
5035 }
5036
5037 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
5038 {
5039   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5040     if((*it).isNotNull())
5041       if((*it)->presenceOfStructureElements())
5042         return true;
5043   return false;
5044 }
5045
5046 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
5047 {
5048   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5049     if((*it).isNotNull())
5050       if(!(*it)->onlyStructureElements())
5051         return false;
5052   return true;
5053 }
5054
5055 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
5056 {
5057   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5058     if((*it).isNotNull())
5059       (*it)->killStructureElements();
5060 }
5061
5062 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
5063 {
5064   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5065     if((*it).isNotNull())
5066       (*it)->keepOnlyStructureElements();
5067 }
5068
5069 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5070 {
5071   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 !";
5072   if(_field_per_mesh.empty())
5073     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
5074   if(_field_per_mesh.size()>1)
5075     throw INTERP_KERNEL::Exception(MSG0);
5076   if(_field_per_mesh[0].isNull())
5077     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
5078   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
5079   std::set<TypeOfField> types;
5080   pm->fillTypesOfFieldAvailable(types);
5081   if(types.size()!=1)
5082     throw INTERP_KERNEL::Exception(MSG0);
5083   TypeOfField type(*types.begin());
5084   int meshDimRelToMax(0);
5085   if(type==ON_NODES)
5086     meshDimRelToMax=0;
5087   else
5088     {
5089       int myDim(std::numeric_limits<int>::max());
5090       bool isUnique(pm->isUniqueLevel(myDim));
5091       if(!isUnique)
5092         throw INTERP_KERNEL::Exception(MSG0);
5093       meshDimRelToMax=myDim-mesh->getMeshDimension();
5094       if(meshDimRelToMax>0)
5095         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5096     }
5097   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5098 }
5099
5100 /*!
5101  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5102  *  \param [in] type - a spatial discretization of the new field.
5103  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5104  *  \param [in] mName - a name of the supporting mesh.
5105  *  \param [in] renumPol - specifies how to permute values of the result field according to
5106  *          the optional numbers of cells and nodes, if any. The valid values are
5107  *          - 0 - do not permute.
5108  *          - 1 - permute cells.
5109  *          - 2 - permute nodes.
5110  *          - 3 - permute cells and nodes.
5111  *
5112  *  \param [in] glob - the global data storing profiles and localization.
5113  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5114  *          caller is to delete this field using decrRef() as it is no more needed. 
5115  *  \throw If the MED file is not readable.
5116  *  \throw If there is no mesh named \a mName in the MED file.
5117  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5118  *  \throw If no field of \a this is lying on the mesh \a mName.
5119  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5120  */
5121 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5122 {
5123   MCAuto<MEDFileMesh> mm;
5124   if(mName.empty())
5125     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5126   else
5127     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5128   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5129 }
5130
5131 /*!
5132  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5133  *  \param [in] type - a spatial discretization of the new field.
5134  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5135  *  \param [in] renumPol - specifies how to permute values of the result field according to
5136  *          the optional numbers of cells and nodes, if any. The valid values are
5137  *          - 0 - do not permute.
5138  *          - 1 - permute cells.
5139  *          - 2 - permute nodes.
5140  *          - 3 - permute cells and nodes.
5141  *
5142  *  \param [in] glob - the global data storing profiles and localization.
5143  *  \param [in] mesh - the supporting mesh.
5144  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5145  *          caller is to delete this field using decrRef() as it is no more needed. 
5146  *  \throw If the MED file is not readable.
5147  *  \throw If no field of \a this is lying on \a mesh.
5148  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5149  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5150  */
5151 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5152 {
5153   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5154   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5155   if(meshDimRelToMax==1)
5156     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5157   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5158 }
5159
5160 /*!
5161  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5162  * given mesh. 
5163  *  \param [in] type - a spatial discretization of the new field.
5164  *  \param [in] mName - a name of the supporting mesh.
5165  *  \param [in] renumPol - specifies how to permute values of the result field according to
5166  *          the optional numbers of cells and nodes, if any. The valid values are
5167  *          - 0 - do not permute.
5168  *          - 1 - permute cells.
5169  *          - 2 - permute nodes.
5170  *          - 3 - permute cells and nodes.
5171  *
5172  *  \param [in] glob - the global data storing profiles and localization.
5173  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5174  *          caller is to delete this field using decrRef() as it is no more needed. 
5175  *  \throw If the MED file is not readable.
5176  *  \throw If there is no mesh named \a mName in the MED file.
5177  *  \throw If there are no mesh entities in the mesh.
5178  *  \throw If no field values of the given \a type are available.
5179  */
5180 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5181 {
5182   MCAuto<MEDFileMesh> mm;
5183   if(mName.empty())
5184     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5185   else
5186     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5187   int absDim=getDimension();
5188   int meshDimRelToMax=absDim-mm->getMeshDimension();
5189   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5190 }
5191
5192 /*!
5193  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5194  *  \param [in] type - a spatial discretization of the new field.
5195  *  \param [in] renumPol - specifies how to permute values of the result field according to
5196  *          the optional numbers of cells and nodes, if any. The valid values are
5197  *          - 0 - do not permute.
5198  *          - 1 - permute cells.
5199  *          - 2 - permute nodes.
5200  *          - 3 - permute cells and nodes.
5201  *
5202  *  \param [in] glob - the global data storing profiles and localization.
5203  *  \param [in] mesh - the supporting mesh.
5204  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5205  *         field according to \a renumPol.
5206  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5207  *         field according to \a renumPol.
5208  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5209  *          caller is to delete this field using decrRef() as it is no more needed. 
5210  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5211  *  \throw If no field of \a this is lying on \a mesh.
5212  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5213  */
5214 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
5215 {
5216   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5217   int meshId=getMeshIdFromMeshName(mesh->getName());
5218   bool isPfl=false;
5219   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5220   switch(renumPol)
5221   {
5222     case 0:
5223       {
5224         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5225         return ret.retn();
5226       }
5227     case 3:
5228     case 1:
5229       {
5230         if(isPfl)
5231           throw INTERP_KERNEL::Exception(msg1);
5232         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5233         if(cellRenum)
5234           {
5235             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5236               {
5237                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5238                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5239                 throw INTERP_KERNEL::Exception(oss.str());
5240               }
5241             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5242             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5243             std::vector<DataArray *> arrOut2(1,arrOut);
5244             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5245             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5246             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5247           }
5248         if(renumPol==1)
5249           return ret.retn();
5250       }
5251     case 2:
5252       {
5253         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5254         if(isPfl)
5255           throw INTERP_KERNEL::Exception(msg1);
5256         if(nodeRenum)
5257           {
5258             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5259               {
5260                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5261                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5262                 throw INTERP_KERNEL::Exception(oss.str());
5263               }
5264             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5265             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5266               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5267             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5268           }
5269         return ret.retn();
5270       }
5271     default:
5272       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5273   }
5274 }
5275
5276 /*!
5277  * Returns values and a profile of the field of a given type lying on a given support.
5278  *  \param [in] type - a spatial discretization of the field.
5279  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5280  *  \param [in] mesh - the supporting mesh.
5281  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5282  *          field of interest lies on. If the field lies on all entities of the given
5283  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5284  *          using decrRef() as it is no more needed.  
5285  *  \param [in] glob - the global data storing profiles and localization.
5286  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5287  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5288  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5289  *  \throw If no field of \a this is lying on \a mesh.
5290  *  \throw If no field values of the given \a type are available.
5291  */
5292 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5293 {
5294   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5295   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
5296   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5297   ret->setName(nasc.getName().c_str());
5298   return ret.retn();
5299 }
5300
5301 //= MEDFileField1TSWithoutSDA
5302
5303 /*!
5304  * Throws if a given value is not a valid (non-extended) relative dimension.
5305  *  \param [in] meshDimRelToMax - the relative dimension value.
5306  *  \throw If \a meshDimRelToMax > 0.
5307  */
5308 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5309 {
5310   if(meshDimRelToMax>0)
5311     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5312 }
5313
5314 /*!
5315  * Checks if elements of a given mesh are in the order suitable for writing 
5316  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5317  * vector describing types of elements and their number.
5318  *  \param [in] mesh - the mesh to check.
5319  *  \return std::vector<int> - a vector holding for each element type (1) item of
5320  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5321  *          These values are in full-interlace mode.
5322  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5323  */
5324 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5325 {
5326   if(!mesh)
5327     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5328   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5329   int nbOfTypes=geoTypes.size();
5330   std::vector<int> code(3*nbOfTypes);
5331   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5332   arr1->alloc(nbOfTypes,1);
5333   int *arrPtr=arr1->getPointer();
5334   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5335   for(int i=0;i<nbOfTypes;i++,it++)
5336     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5337   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5338   const int *arrPtr2=arr2->getConstPointer();
5339   int i=0;
5340   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5341     {
5342       int pos=arrPtr2[i];
5343       int nbCells=mesh->getNumberOfCellsWithType(*it);
5344       code[3*pos]=(int)(*it);
5345       code[3*pos+1]=nbCells;
5346       code[3*pos+2]=-1;//no profiles
5347     }
5348   std::vector<const DataArrayInt *> idsPerType;//no profiles
5349   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5350   if(da)
5351     {
5352       da->decrRef();
5353       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5354     }
5355   return code;
5356 }
5357
5358 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5359 {
5360   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5361 }
5362
5363 /*!
5364  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5365  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5366  * item of every of returned sequences refers to the _i_-th part of \a this field.
5367  * Thus all sequences returned by this method are of the same length equal to number
5368  * of different types of supporting entities.<br>
5369  * A field part can include sub-parts with several different spatial discretizations,
5370  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5371  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5372  * of a nested sequence corresponds to a type of spatial discretization.<br>
5373  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5374  * The overhead is due to selecting values into new instances of DataArrayDouble.
5375  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5376  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5377  *          not checked if \a mname == \c NULL).
5378  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5379  *          a field part is returned. 
5380  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5381  *          A field part can include sub-parts with several different spatial discretizations,
5382  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5383  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5384  *          This sequence is of the same length as \a types. 
5385  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5386  *          discretization. A profile name can be empty.
5387  *          Length of this and of nested sequences is the same as that of \a typesF.
5388  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5389  *          discretization. A localization name can be empty.
5390  *          Length of this and of nested sequences is the same as that of \a typesF.
5391  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5392  *          per each type of spatial discretization within one mesh entity type.
5393  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5394  *          Length of this and of nested sequences is the same as that of \a typesF.
5395  *  \throw If no field is lying on \a mname.
5396  */
5397 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
5398 {
5399   int meshId=0;
5400   if(!mname.empty())
5401     meshId=getMeshIdFromMeshName(mname);
5402   else
5403     if(_field_per_mesh.empty())
5404       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5405   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5406   int nbOfRet=ret0.size();
5407   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5408   for(int i=0;i<nbOfRet;i++)
5409     {
5410       const std::vector< std::pair<int,int> >& p=ret0[i];
5411       int nbOfRet1=p.size();
5412       ret[i].resize(nbOfRet1);
5413       for(int j=0;j<nbOfRet1;j++)
5414         {
5415           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5416           ret[i][j]=tmp;
5417         }
5418     }
5419   return ret;
5420 }
5421
5422 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5423 {
5424   return TYPE_STR;
5425 }
5426
5427 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5428 {
5429   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5430   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5431   ret->deepCpyLeavesFrom(*this);
5432   const DataArrayDouble *arr(_arr);
5433   if(arr)
5434     {
5435       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5436       ret->setArray(arr2);
5437     }
5438   return ret.retn();
5439 }
5440
5441 /*!
5442  * Returns a pointer to the underground DataArrayDouble instance and a
5443  * sequence describing parameters of a support of each part of \a this field. The
5444  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5445  * direct access to the field values. This method is intended for the field lying on one
5446  * mesh only.
5447  *  \param [in,out] entries - the sequence describing parameters of a support of each
5448  *         part of \a this field. Each item of this sequence consists of two parts. The
5449  *         first part describes a type of mesh entity and an id of discretization of a
5450  *         current field part. The second part describes a range of values [begin,end)
5451  *         within the returned array relating to the current field part.
5452  *  \return DataArrayDouble * - the pointer to the field values array.
5453  *  \throw If the number of underlying meshes is not equal to 1.
5454  *  \throw If no field values are available.
5455  *  \sa getUndergroundDataArray()
5456  */
5457 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5458 {
5459   if(_field_per_mesh.size()!=1)
5460     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5461   if(_field_per_mesh[0]==0)
5462     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5463   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5464   return getUndergroundDataArrayTemplate();
5465 }
5466
5467 /*!
5468  * Returns a pointer to the underground DataArrayDouble instance and a
5469  * sequence describing parameters of a support of each part of \a this field. The
5470  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5471  * direct access to the field values. This method is intended for the field lying on one
5472  * mesh only.
5473  *  \param [in,out] entries - the sequence describing parameters of a support of each
5474  *         part of \a this field. Each item of this sequence consists of two parts. The
5475  *         first part describes a type of mesh entity and an id of discretization of a
5476  *         current field part. The second part describes a range of values [begin,end)
5477  *         within the returned array relating to the current field part.
5478  *  \return DataArrayDouble * - the pointer to the field values array.
5479  *  \throw If the number of underlying meshes is not equal to 1.
5480  *  \throw If no field values are available.
5481  *  \sa getUndergroundDataArray()
5482  */
5483 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5484 {
5485   return getUndergroundDataArrayDoubleExt(entries);
5486 }
5487
5488 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,csit,iteration,order)
5489 {
5490   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5491   arr->setInfoAndChangeNbOfCompo(infos);
5492 }
5493
5494 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5495 {
5496 }
5497
5498 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5499 {
5500   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5501   ret->deepCpyLeavesFrom(*this);
5502   return ret.retn();
5503 }
5504
5505 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5506 {
5507   MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
5508   if(_arr.isNotNull())
5509     ret->_arr=_arr->deepCopy();
5510   return ret.retn();
5511 }
5512
5513 //= MEDFileIntField1TSWithoutSDA
5514
5515 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5516 {
5517   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5518 }
5519
5520 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5521 {
5522 }
5523
5524 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5525                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,csit,iteration,order)
5526 {
5527   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5528   arr->setInfoAndChangeNbOfCompo(infos);
5529 }
5530
5531 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5532 {
5533   return TYPE_STR;
5534 }
5535
5536 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5537 {
5538   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5539   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5540   ret->deepCpyLeavesFrom(*this);
5541   const DataArrayInt *arr(_arr);
5542   if(arr)
5543     {
5544       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5545       ret->setArray(arr2);
5546     }
5547   return ret.retn();
5548 }
5549
5550 /*!
5551  * Returns a pointer to the underground DataArrayInt instance and a
5552  * sequence describing parameters of a support of each part of \a this field. The
5553  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5554  * direct access to the field values. This method is intended for the field lying on one
5555  * mesh only.
5556  *  \param [in,out] entries - the sequence describing parameters of a support of each
5557  *         part of \a this field. Each item of this sequence consists of two parts. The
5558  *         first part describes a type of mesh entity and an id of discretization of a
5559  *         current field part. The second part describes a range of values [begin,end)
5560  *         within the returned array relating to the current field part.
5561  *  \return DataArrayInt * - the pointer to the field values array.
5562  *  \throw If the number of underlying meshes is not equal to 1.
5563  *  \throw If no field values are available.
5564  *  \sa getUndergroundDataArray()
5565  */
5566 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5567 {
5568   return getUndergroundDataArrayIntExt(entries);
5569 }
5570
5571 /*!
5572  * Returns a pointer to the underground DataArrayInt instance and a
5573  * sequence describing parameters of a support of each part of \a this field. The
5574  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5575  * direct access to the field values. This method is intended for the field lying on one
5576  * mesh only.
5577  *  \param [in,out] entries - the sequence describing parameters of a support of each
5578  *         part of \a this field. Each item of this sequence consists of two parts. The
5579  *         first part describes a type of mesh entity and an id of discretization of a
5580  *         current field part. The second part describes a range of values [begin,end)
5581  *         within the returned array relating to the current field part.
5582  *  \return DataArrayInt * - the pointer to the field values array.
5583  *  \throw If the number of underlying meshes is not equal to 1.
5584  *  \throw If no field values are available.
5585  *  \sa getUndergroundDataArray()
5586  */
5587 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5588 {
5589   if(_field_per_mesh.size()!=1)
5590     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5591   if(_field_per_mesh[0]==0)
5592     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5593   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5594   return getUndergroundDataArrayTemplate();
5595 }
5596
5597 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5598 {
5599   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5600   ret->deepCpyLeavesFrom(*this);
5601   return ret.retn();
5602 }
5603
5604 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5605 {
5606   MCAuto<MEDFileIntField1TSWithoutSDA> ret(shallowCpy());
5607   if(_arr.isNotNull())
5608     ret->_arr=_arr->deepCopy();
5609   return ret.retn();
5610 }
5611
5612 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5613 {
5614 }
5615
5616 //= MEDFileAnyTypeField1TS
5617
5618 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5619 {
5620   med_field_type typcha;
5621   //
5622   std::vector<std::string> infos;
5623   std::string dtunit,fieldName;
5624   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
5625   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5626   switch(typcha)
5627   {
5628     case MED_FLOAT64:
5629       {
5630         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5631         break;
5632       }
5633     case MED_INT32:
5634       {
5635         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5636         break;
5637       }
5638     default:
5639       {
5640         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] !";
5641         throw INTERP_KERNEL::Exception(oss.str());
5642       }
5643   }
5644   ret->setDtUnit(dtunit.c_str());
5645   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5646   //
5647   med_int numdt,numit;
5648   med_float dt;
5649   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5650   ret->setTime(numdt,numit,dt);
5651   ret->_csit=1;
5652   if(loadAll)
5653     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5654   else
5655     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5656   return ret.retn();
5657 }
5658
5659 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5660 try:MEDFileFieldGlobsReal(fid)
5661 {
5662   _content=BuildContentFrom(fid,loadAll,ms);
5663   loadGlobals(fid);
5664 }
5665 catch(INTERP_KERNEL::Exception& e)
5666 {
5667     throw e;
5668 }
5669
5670 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5671 {
5672   med_field_type typcha;
5673   std::vector<std::string> infos;
5674   std::string dtunit;
5675   int iii=-1;
5676   int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit);
5677   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5678   switch(typcha)
5679   {
5680     case MED_FLOAT64:
5681       {
5682         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5683         break;
5684       }
5685     case MED_INT32:
5686       {
5687         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5688         break;
5689       }
5690     default:
5691       {
5692         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] !";
5693         throw INTERP_KERNEL::Exception(oss.str());
5694       }
5695   }
5696   ret->setDtUnit(dtunit.c_str());
5697   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5698   //
5699   if(nbSteps<1)
5700     {
5701       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5702       throw INTERP_KERNEL::Exception(oss.str());
5703     }
5704   //
5705   med_int numdt,numit;
5706   med_float dt;
5707   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5708   ret->setTime(numdt,numit,dt);
5709   ret->_csit=1;
5710   if(loadAll)
5711     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5712   else
5713     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5714   return ret.retn();
5715 }
5716
5717 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5718 try:MEDFileFieldGlobsReal(fid)
5719 {
5720   _content=BuildContentFrom(fid,fieldName,loadAll,ms);
5721   loadGlobals(fid);
5722 }
5723 catch(INTERP_KERNEL::Exception& e)
5724 {
5725     throw e;
5726 }
5727
5728 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
5729 {
5730   if(!c)
5731     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5732   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5733     {
5734       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
5735       ret->_content=c; c->incrRef();
5736       return ret.retn();
5737     }
5738   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5739     {
5740       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
5741       ret->_content=c; c->incrRef();
5742       return ret.retn();
5743     }
5744   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5745 }
5746
5747 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
5748 {
5749   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
5750   ret->setFileName(FileNameFromFID(fid));
5751   return ret;
5752 }
5753
5754 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5755 {
5756   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5757   return New(fid,loadAll);
5758 }
5759
5760 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
5761 {
5762   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
5763   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5764   ret->loadGlobals(fid);
5765   return ret.retn();
5766 }
5767
5768 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5769 {
5770   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5771   return New(fid,fieldName,loadAll);
5772 }
5773
5774 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
5775 {
5776   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0));
5777   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5778   ret->loadGlobals(fid);
5779   return ret.retn();
5780 }
5781
5782 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5783 {
5784   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5785   return New(fid,fieldName,iteration,order,loadAll);
5786 }
5787
5788 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
5789 {
5790   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0));
5791   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5792   ret->loadGlobals(fid);
5793   return ret.retn();
5794 }
5795
5796 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5797 {
5798   med_field_type typcha;
5799   std::vector<std::string> infos;
5800   std::string dtunit;
5801   int iii(-1);
5802   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit));
5803   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5804   switch(typcha)
5805   {
5806     case MED_FLOAT64:
5807       {
5808         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5809         break;
5810       }
5811     case MED_INT32:
5812       {
5813         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5814         break;
5815       }
5816     default:
5817       {
5818         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] !";
5819         throw INTERP_KERNEL::Exception(oss.str());
5820       }
5821   }
5822   ret->setDtUnit(dtunit.c_str());
5823   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5824   //
5825   bool found=false;
5826   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5827   for(int i=0;i<nbOfStep2 && !found;i++)
5828     {
5829       med_int numdt,numit;
5830       med_float dt;
5831       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5832       if(numdt==iteration && numit==order)
5833         {
5834           found=true;
5835           ret->_csit=i+1;
5836         }
5837       else
5838         dtits[i]=std::pair<int,int>(numdt,numit);
5839     }
5840   if(!found)
5841     {
5842       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
5843       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5844         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5845       throw INTERP_KERNEL::Exception(oss.str());
5846     }
5847   if(loadAll)
5848     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5849   else
5850     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5851   return ret.retn();
5852 }
5853
5854 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5855 try:MEDFileFieldGlobsReal(fid)
5856 {
5857   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms);
5858   loadGlobals(fid);
5859 }
5860 catch(INTERP_KERNEL::Exception& e)
5861 {
5862     throw e;
5863 }
5864
5865 /*!
5866  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5867  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5868  *
5869  * \warning this is a shallow copy constructor
5870  */
5871 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5872 {
5873   if(!shallowCopyOfContent)
5874     {
5875       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5876       otherPtr->incrRef();
5877       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5878     }
5879   else
5880     {
5881       _content=other.shallowCpy();
5882     }
5883 }
5884
5885 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)
5886 {
5887   if(checkFieldId)
5888     {
5889       int nbFields=MEDnField(fid);
5890       if(fieldIdCFormat>=nbFields)
5891         {
5892           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5893           throw INTERP_KERNEL::Exception(oss.str());
5894         }
5895     }
5896   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5897   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5898   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5899   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5900   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5901   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5902   med_bool localMesh;
5903   int nbOfStep;
5904   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5905   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5906   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5907   infos.clear(); infos.resize(ncomp);
5908   for(int j=0;j<ncomp;j++)
5909     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5910   return nbOfStep;
5911 }
5912
5913 /*!
5914  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5915  * 
5916  * \param [out]
5917  * \return in case of success the number of time steps available for the field with name \a fieldName.
5918  */
5919 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5920 {
5921   int nbFields=MEDnField(fid);
5922   bool found=false;
5923   std::vector<std::string> fns(nbFields);
5924   int nbOfStep2(-1);
5925   for(int i=0;i<nbFields && !found;i++)
5926     {
5927       std::string tmp;
5928       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut);
5929       fns[i]=tmp;
5930       found=(tmp==fieldName);
5931       if(found)
5932         posCFormat=i;
5933     }
5934   if(!found)
5935     {
5936       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
5937       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5938         oss << "\"" << *it << "\" ";
5939       throw INTERP_KERNEL::Exception(oss.str());
5940     }
5941   return nbOfStep2;
5942 }
5943
5944 /*!
5945  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5946  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5947  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5948  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5949  * to keep a valid instance.
5950  * 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.
5951  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5952  * 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.
5953  *
5954  * \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.
5955  * \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.
5956  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5957  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5958  * \param [in] newLocName is the new localization name.
5959  * \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.
5960  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5961  */
5962 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5963 {
5964   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5965   std::string oldPflName=disc->getProfile();
5966   std::vector<std::string> vv=getPflsReallyUsedMulti();
5967   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5968   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5969     {
5970       disc->setProfile(newPflName);
5971       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5972       pfl->setName(newPflName);
5973     }
5974   else
5975     {
5976       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5977       throw INTERP_KERNEL::Exception(oss.str());
5978     }
5979 }
5980
5981 /*!
5982  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5983  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5984  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5985  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5986  * to keep a valid instance.
5987  * 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.
5988  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5989  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5990  * 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.
5991  *
5992  * \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.
5993  * \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.
5994  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5995  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5996  * \param [in] newLocName is the new localization name.
5997  * \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.
5998  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5999  */
6000 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
6001 {
6002   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6003   std::string oldLocName=disc->getLocalization();
6004   std::vector<std::string> vv=getLocsReallyUsedMulti();
6005   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
6006   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
6007     {
6008       disc->setLocalization(newLocName);
6009       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
6010       loc.setName(newLocName);
6011     }
6012   else
6013     {
6014       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
6015       throw INTERP_KERNEL::Exception(oss.str());
6016     }
6017 }
6018
6019 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
6020 {
6021   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6022   if(!ret)
6023     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
6024   return ret;
6025 }
6026
6027 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
6028 {
6029   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6030   if(!ret)
6031     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
6032   return ret;
6033 }
6034
6035 /*!
6036  * This method alloc the arrays and load potentially huge arrays contained in this field.
6037  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
6038  * This method can be also called to refresh or reinit values from a file.
6039  * 
6040  * \throw If the fileName is not set or points to a non readable MED file.
6041  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6042  */
6043 void MEDFileAnyTypeField1TS::loadArrays()
6044 {
6045   if(getFileName().empty())
6046     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
6047   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6048   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
6049 }
6050
6051 /*!
6052  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
6053  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
6054  * this method does not throw if \a this does not come from file read.
6055  * 
6056  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
6057  */
6058 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
6059 {
6060   if(!getFileName().empty())
6061     {
6062       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6063       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
6064     }
6065 }
6066
6067 /*!
6068  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
6069  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
6070  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
6071  * 
6072  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
6073  */
6074 void MEDFileAnyTypeField1TS::unloadArrays()
6075 {
6076   contentNotNullBase()->unloadArrays();
6077 }
6078
6079 /*!
6080  * 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.
6081  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
6082  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
6083  * 
6084  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6085  */
6086 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
6087 {
6088   if(!getFileName().empty())
6089     contentNotNullBase()->unloadArrays();
6090 }
6091
6092 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6093 {
6094   int nbComp(getNumberOfComponents());
6095   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6096   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6097   for(int i=0;i<nbComp;i++)
6098     {
6099       std::string info=getInfo()[i];
6100       std::string c,u;
6101       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6102       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6103       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6104     }
6105   if(getName().empty())
6106     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6107   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6108   writeGlobals(fid,*this);
6109   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6110 }
6111
6112 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6113 {
6114   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6115 }
6116
6117 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6118 {
6119   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6120   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6121   return ret;
6122 }
6123
6124 /*!
6125  * Returns a string describing \a this field. This string is outputted 
6126  * by \c print Python command.
6127  */
6128 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6129 {
6130   std::ostringstream oss;
6131   contentNotNullBase()->simpleRepr(0,oss,-1);
6132   simpleReprGlobs(oss);
6133   return oss.str();
6134 }
6135
6136 /*!
6137  * This method returns all profiles whose name is non empty used.
6138  * \b WARNING If profile is used several times it will be reported \b only \b once.
6139  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6140  */
6141 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6142 {
6143   return contentNotNullBase()->getPflsReallyUsed2();
6144 }
6145
6146 /*!
6147  * This method returns all localizations whose name is non empty used.
6148  * \b WARNING If localization is used several times it will be reported \b only \b once.
6149  */
6150 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6151 {
6152   return contentNotNullBase()->getLocsReallyUsed2();
6153 }
6154
6155 /*!
6156  * This method returns all profiles whose name is non empty used.
6157  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6158  */
6159 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6160 {
6161   return contentNotNullBase()->getPflsReallyUsedMulti2();
6162 }
6163
6164 /*!
6165  * This method returns all localizations whose name is non empty used.
6166  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6167  */
6168 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6169 {
6170   return contentNotNullBase()->getLocsReallyUsedMulti2();
6171 }
6172
6173 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6174 {
6175   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6176 }
6177
6178 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6179 {
6180   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6181 }
6182
6183 int MEDFileAnyTypeField1TS::getDimension() const
6184 {
6185   return contentNotNullBase()->getDimension();
6186 }
6187
6188 int MEDFileAnyTypeField1TS::getIteration() const
6189 {
6190   return contentNotNullBase()->getIteration();
6191 }
6192
6193 int MEDFileAnyTypeField1TS::getOrder() const
6194 {
6195   return contentNotNullBase()->getOrder();
6196 }
6197
6198 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6199 {
6200   return contentNotNullBase()->getTime(iteration,order);
6201 }
6202
6203 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6204 {
6205   contentNotNullBase()->setTime(iteration,order,val);
6206 }
6207
6208 std::string MEDFileAnyTypeField1TS::getName() const
6209 {
6210   return contentNotNullBase()->getName();
6211 }
6212
6213 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6214 {
6215   contentNotNullBase()->setName(name);
6216 }
6217
6218 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6219 {
6220   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6221 }
6222
6223 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6224 {
6225   return contentNotNullBase()->getDtUnit();
6226 }
6227
6228 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6229 {
6230   contentNotNullBase()->setDtUnit(dtUnit);
6231 }
6232
6233 std::string MEDFileAnyTypeField1TS::getMeshName() const
6234 {
6235   return contentNotNullBase()->getMeshName();
6236 }
6237
6238 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6239 {
6240   contentNotNullBase()->setMeshName(newMeshName);
6241 }
6242
6243 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6244 {
6245   return contentNotNullBase()->changeMeshNames(modifTab);
6246 }
6247
6248 int MEDFileAnyTypeField1TS::getMeshIteration() const
6249 {
6250   return contentNotNullBase()->getMeshIteration();
6251 }
6252
6253 int MEDFileAnyTypeField1TS::getMeshOrder() const
6254 {
6255   return contentNotNullBase()->getMeshOrder();
6256 }
6257
6258 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6259 {
6260   return contentNotNullBase()->getNumberOfComponents();
6261 }
6262
6263 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6264 {
6265   return contentNotNullBase()->isDealingTS(iteration,order);
6266 }
6267
6268 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6269 {
6270   return contentNotNullBase()->getDtIt();
6271 }
6272
6273 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6274 {
6275   contentNotNullBase()->fillIteration(p);
6276 }
6277
6278 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6279 {
6280   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6281 }
6282
6283 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6284 {
6285   contentNotNullBase()->setInfo(infos);
6286 }
6287
6288 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6289 {
6290   return contentNotNullBase()->getInfo();
6291 }
6292 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6293 {
6294   return contentNotNullBase()->getInfo();
6295 }
6296
6297 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6298 {
6299   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6300 }
6301
6302 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6303 {
6304   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6305 }
6306
6307 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6308 {
6309   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6310 }
6311
6312 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6313 {
6314   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6315 }
6316
6317 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6318 {
6319   return contentNotNullBase()->getTypesOfFieldAvailable();
6320 }
6321
6322 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,
6323                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6324 {
6325   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6326 }
6327
6328 /*!
6329  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6330  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6331  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6332  */
6333 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6334 {
6335   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6336   if(!content)
6337     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6338   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6339   std::size_t sz(contentsSplit.size());
6340   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6341   for(std::size_t i=0;i<sz;i++)
6342     {
6343       ret[i]=shallowCpy();
6344       ret[i]->_content=contentsSplit[i];
6345     }
6346   return ret;
6347 }
6348
6349 /*!
6350  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6351  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6352  */
6353 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6354 {
6355   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6356   if(!content)
6357     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6358   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6359   std::size_t sz(contentsSplit.size());
6360   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6361   for(std::size_t i=0;i<sz;i++)
6362     {
6363       ret[i]=shallowCpy();
6364       ret[i]->_content=contentsSplit[i];
6365     }
6366   return ret;
6367 }
6368
6369 /*!
6370  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6371  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6372  */
6373 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6374 {
6375   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6376   if(!content)
6377     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6378   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6379   std::size_t sz(contentsSplit.size());
6380   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6381   for(std::size_t i=0;i<sz;i++)
6382     {
6383       ret[i]=shallowCpy();
6384       ret[i]->_content=contentsSplit[i];
6385     }
6386   return ret;
6387 }
6388
6389 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6390 {
6391   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6392   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6393     ret->_content=_content->deepCopy();
6394   ret->deepCpyGlobs(*this);
6395   return ret.retn();
6396 }
6397
6398 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6399 {
6400   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6401 }
6402
6403 //= MEDFileField1TS
6404
6405 /*!
6406  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6407  * the first field that has been read from a specified MED file.
6408  *  \param [in] fileName - the name of the MED file to read.
6409  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6410  *          is to delete this field using decrRef() as it is no more needed.
6411  *  \throw If reading the file fails.
6412  */
6413 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6414 {
6415   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6416   return New(fid,loadAll);
6417 }
6418
6419 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
6420 {
6421   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
6422   ret->contentNotNull();
6423   return ret.retn();
6424 }
6425
6426 /*!
6427  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6428  * a given field that has been read from a specified MED file.
6429  *  \param [in] fileName - the name of the MED file to read.
6430  *  \param [in] fieldName - the name of the field to read.
6431  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6432  *          is to delete this field using decrRef() as it is no more needed.
6433  *  \throw If reading the file fails.
6434  *  \throw If there is no field named \a fieldName in the file.
6435  */
6436 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6437 {
6438   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6439   return New(fid,fieldName,loadAll);
6440 }
6441
6442 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6443 {
6444   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
6445   ret->contentNotNull();
6446   return ret.retn();
6447 }
6448
6449 /*!
6450  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6451  * a given field that has been read from a specified MED file.
6452  *  \param [in] fileName - the name of the MED file to read.
6453  *  \param [in] fieldName - the name of the field to read.
6454  *  \param [in] iteration - the iteration number of a required time step.
6455  *  \param [in] order - the iteration order number of required time step.
6456  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6457  *          is to delete this field using decrRef() as it is no more needed.
6458  *  \throw If reading the file fails.
6459  *  \throw If there is no field named \a fieldName in the file.
6460  *  \throw If the required time step is missing from the file.
6461  */
6462 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6463 {
6464   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6465   return New(fid,fieldName,iteration,order,loadAll);
6466 }
6467
6468 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6469 {
6470   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
6471   ret->contentNotNull();
6472   return ret.retn();
6473 }
6474
6475 /*!
6476  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6477  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6478  *
6479  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6480  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6481  * \warning this is a shallow copy constructor
6482  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6483  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6484  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6485  *          is to delete this field using decrRef() as it is no more needed.
6486  */
6487 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6488 {
6489   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6490   ret->contentNotNull();
6491   return ret.retn();
6492 }
6493
6494 /*!
6495  * Returns a new empty instance of MEDFileField1TS.
6496  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6497  *          is to delete this field using decrRef() as it is no more needed.
6498  */
6499 MEDFileField1TS *MEDFileField1TS::New()
6500 {
6501   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6502   ret->contentNotNull();
6503   return ret.retn();
6504 }
6505
6506 /*!
6507  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6508  * following the given input policy.
6509  *
6510  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6511  *                            By default (true) the globals are deeply copied.
6512  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6513  */
6514 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6515 {
6516   MCAuto<MEDFileIntField1TS> ret;
6517   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6518   if(content)
6519     {
6520       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6521       if(!contc)
6522         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6523       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6524       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6525     }
6526   else
6527     ret=MEDFileIntField1TS::New();
6528   if(isDeepCpyGlobs)
6529     ret->deepCpyGlobs(*this);
6530   else
6531     ret->shallowCpyGlobs(*this);
6532   return ret.retn();
6533 }
6534
6535 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6536 {
6537   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6538   if(!pt)
6539     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6540   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6541   if(!ret)
6542     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 !");
6543   return ret;
6544 }
6545
6546 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6547 {
6548   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6549   if(!pt)
6550     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6551   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6552   if(!ret)
6553     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 !");
6554   return ret;
6555 }
6556
6557 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6558 {
6559   if(!f)
6560     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6561   if(arr.isNull())
6562     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6563   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6564   if(!arrOutC)
6565     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6566   f->setArray(arrOutC);
6567 }
6568
6569 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6570 {
6571   if(arr.isNull())
6572     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6573   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6574   if(!arrOutC)
6575     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6576   arrOutC->incrRef();
6577   return arrOutC;
6578 }
6579
6580 /*!
6581  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6582  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6583  *
6584  * \return A new object that the caller is responsible to deallocate.
6585  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6586  */
6587 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6588 {
6589   if(!mm)
6590     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6591   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6592   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6593   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6594     {
6595       if((*it0)!=ON_NODES)
6596         {
6597           std::vector<int> levs;
6598           getNonEmptyLevels(mm->getName(),levs);
6599           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6600             {
6601               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6602               if(it2!=extractDef.end())
6603                 {
6604                   MCAuto<DataArrayInt> t((*it2).second);
6605                   if(t.isNull())
6606                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6607                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6608                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6609                   ret->setFieldNoProfileSBT(fOut);
6610                 }
6611             }
6612         }
6613       else
6614         {
6615           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6616           if(it2==extractDef.end())
6617             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6618           MCAuto<DataArrayInt> t((*it2).second);
6619           if(t.isNull())
6620             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6621           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6622           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6623           DataArrayDouble *arr(f->getArray());
6624           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6625           fOut->setArray(newArr);
6626           ret->setFieldNoProfileSBT(fOut);
6627         }
6628     }
6629   return ret.retn();
6630 }
6631
6632 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6633 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6634 {
6635 }
6636 catch(INTERP_KERNEL::Exception& e)
6637 { throw e; }
6638
6639 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6640 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6641 {
6642 }
6643 catch(INTERP_KERNEL::Exception& e)
6644 { throw e; }
6645
6646 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6647 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6648 {
6649 }
6650 catch(INTERP_KERNEL::Exception& e)
6651 { throw e; }
6652
6653 /*!
6654  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6655  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6656  *
6657  * \warning this is a shallow copy constructor
6658  */
6659 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6660 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6661 {
6662 }
6663 catch(INTERP_KERNEL::Exception& e)
6664 { throw e; }
6665
6666 MEDFileField1TS::MEDFileField1TS()
6667 {
6668   _content=new MEDFileField1TSWithoutSDA;
6669 }
6670
6671 /*!
6672  * 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
6673  * method should be called (getFieldOnMeshAtLevel for example).
6674  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6675  *
6676  * \param [in] mesh - the mesh the field is lying on
6677  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6678  *          caller is to delete this field using decrRef() as it is no more needed. 
6679  */
6680 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6681 {
6682   MCAuto<DataArray> arrOut;
6683   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6684   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6685   return ret.retn();
6686 }
6687
6688 /*!
6689  * Returns a new MEDCouplingFieldDouble of a given type lying on
6690  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6691  * has not been constructed via file reading, an exception is thrown.
6692  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6693  *  \param [in] type - a spatial discretization of interest.
6694  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6695  *  \param [in] renumPol - specifies how to permute values of the result field according to
6696  *          the optional numbers of cells and nodes, if any. The valid values are
6697  *          - 0 - do not permute.
6698  *          - 1 - permute cells.
6699  *          - 2 - permute nodes.
6700  *          - 3 - permute cells and nodes.
6701  *
6702  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6703  *          caller is to delete this field using decrRef() as it is no more needed. 
6704  *  \throw If \a this field has not been constructed via file reading.
6705  *  \throw If the MED file is not readable.
6706  *  \throw If there is no mesh in the MED file.
6707  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6708  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6709  *  \sa getFieldOnMeshAtLevel()
6710  */
6711 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6712 {
6713   if(getFileName().empty())
6714     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6715   MCAuto<DataArray> arrOut;
6716   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6717   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6718   return ret.retn();
6719 }
6720
6721 /*!
6722  * Returns a new MEDCouplingFieldDouble of a given type lying on
6723  * the top level cells of the first mesh in MED file. If \a this field 
6724  * has not been constructed via file reading, an exception is thrown.
6725  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6726  *  \param [in] type - a spatial discretization of interest.
6727  *  \param [in] renumPol - specifies how to permute values of the result field according to
6728  *          the optional numbers of cells and nodes, if any. The valid values are
6729  *          - 0 - do not permute.
6730  *          - 1 - permute cells.
6731  *          - 2 - permute nodes.
6732  *          - 3 - permute cells and nodes.
6733  *
6734  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6735  *          caller is to delete this field using decrRef() as it is no more needed. 
6736  *  \throw If \a this field has not been constructed via file reading.
6737  *  \throw If the MED file is not readable.
6738  *  \throw If there is no mesh in the MED file.
6739  *  \throw If no field values of the given \a type.
6740  *  \throw If no field values lying on the top level support.
6741  *  \sa getFieldAtLevel()
6742  */
6743 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6744 {
6745   if(getFileName().empty())
6746     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6747   MCAuto<DataArray> arrOut;
6748   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6749   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6750   return ret.retn();
6751 }
6752
6753 /*!
6754  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6755  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6756  *  \param [in] type - a spatial discretization of the new field.
6757  *  \param [in] mesh - the supporting mesh.
6758  *  \param [in] renumPol - specifies how to permute values of the result field according to
6759  *          the optional numbers of cells and nodes, if any. The valid values are
6760  *          - 0 - do not permute.
6761  *          - 1 - permute cells.
6762  *          - 2 - permute nodes.
6763  *          - 3 - permute cells and nodes.
6764  *
6765  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6766  *          caller is to delete this field using decrRef() as it is no more needed. 
6767  *  \throw If no field of \a this is lying on \a mesh.
6768  *  \throw If the mesh is empty.
6769  *  \throw If no field values of the given \a type are available.
6770  *  \sa getFieldAtLevel()
6771  *  \sa getFieldOnMeshAtLevel() 
6772  */
6773 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6774 {
6775   MCAuto<DataArray> arrOut;
6776   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
6777   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6778   return ret.retn();
6779 }
6780
6781 /*!
6782  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6783  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6784  *  \param [in] type - a spatial discretization of interest.
6785  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6786  *  \param [in] mesh - the supporting mesh.
6787  *  \param [in] renumPol - specifies how to permute values of the result field according to
6788  *          the optional numbers of cells and nodes, if any. The valid values are
6789  *          - 0 - do not permute.
6790  *          - 1 - permute cells.
6791  *          - 2 - permute nodes.
6792  *          - 3 - permute cells and nodes.
6793  *
6794  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6795  *          caller is to delete this field using decrRef() as it is no more needed. 
6796  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6797  *  \throw If no field of \a this is lying on \a mesh.
6798  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6799  *  \sa getFieldAtLevel()
6800  *  \sa getFieldOnMeshAtLevel() 
6801  */
6802 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6803 {
6804   MCAuto<DataArray> arrOut;
6805   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
6806   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6807   return ret.retn();
6808 }
6809
6810 /*!
6811  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6812  * This method is called "Old" because in MED3 norm a field has only one meshName
6813  * attached, so this method is for readers of MED2 files. If \a this field 
6814  * has not been constructed via file reading, an exception is thrown.
6815  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6816  *  \param [in] type - a spatial discretization of interest.
6817  *  \param [in] mName - a name of the supporting mesh.
6818  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6819  *  \param [in] renumPol - specifies how to permute values of the result field according to
6820  *          the optional numbers of cells and nodes, if any. The valid values are
6821  *          - 0 - do not permute.
6822  *          - 1 - permute cells.
6823  *          - 2 - permute nodes.
6824  *          - 3 - permute cells and nodes.
6825  *
6826  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6827  *          caller is to delete this field using decrRef() as it is no more needed. 
6828  *  \throw If the MED file is not readable.
6829  *  \throw If there is no mesh named \a mName in the MED file.
6830  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6831  *  \throw If \a this field has not been constructed via file reading.
6832  *  \throw If no field of \a this is lying on the mesh named \a mName.
6833  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6834  *  \sa getFieldAtLevel()
6835  */
6836 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6837 {
6838   if(getFileName().empty())
6839     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6840   MCAuto<DataArray> arrOut;
6841   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
6842   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6843   return ret.retn();
6844 }
6845
6846 /*!
6847  * Returns values and a profile of the field of a given type lying on a given support.
6848  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6849  *  \param [in] type - a spatial discretization of the field.
6850  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6851  *  \param [in] mesh - the supporting mesh.
6852  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6853  *          field of interest lies on. If the field lies on all entities of the given
6854  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6855  *          using decrRef() as it is no more needed.  
6856  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6857  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6858  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6859  *  \throw If no field of \a this is lying on \a mesh.
6860  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6861  */
6862 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6863 {
6864   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6865   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6866 }
6867
6868 /*!
6869  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6870  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6871  * "Sort By Type"), if not, an exception is thrown. 
6872  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6873  *  \param [in] field - the field to add to \a this.
6874  *  \throw If the name of \a field is empty.
6875  *  \throw If the data array of \a field is not set.
6876  *  \throw If the data array is already allocated but has different number of components
6877  *         than \a field.
6878  *  \throw If the underlying mesh of \a field has no name.
6879  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6880  */
6881 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6882 {
6883   setFileName("");
6884   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6885 }
6886
6887 /*!
6888  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6889  * can be an aggregation of several MEDCouplingFieldDouble instances.
6890  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6891  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6892  * and \a profile.
6893  *
6894  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6895  * A new profile is added only if no equal profile is missing.
6896  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6897  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6898  *  \param [in] mesh - the supporting mesh of \a field.
6899  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6900  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6901  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6902  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6903  *  \throw If the data array of \a field is not set.
6904  *  \throw If the data array of \a this is already allocated but has different number of
6905  *         components than \a field.
6906  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6907  *  \sa setFieldNoProfileSBT()
6908  */
6909 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6910 {
6911   setFileName("");
6912   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6913 }
6914
6915 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
6916 {
6917   return new MEDFileField1TS(*this);
6918 }
6919
6920 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6921 {
6922   return contentNotNull()->getUndergroundDataArrayTemplate();
6923 }
6924
6925 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6926 {
6927   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6928 }
6929
6930 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6931                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6932 {
6933   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6934 }
6935
6936 //= MEDFileIntField1TS
6937
6938 MEDFileIntField1TS *MEDFileIntField1TS::New()
6939 {
6940   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
6941   ret->contentNotNull();
6942   return ret.retn();
6943 }
6944
6945 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6946 {
6947   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6948   return MEDFileIntField1TS::New(fid,loadAll);
6949 }
6950
6951 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
6952 {
6953   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
6954   ret->contentNotNull();
6955   return ret.retn();
6956 }
6957
6958 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6959 {
6960   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6961   return MEDFileIntField1TS::New(fid,fieldName,loadAll);
6962 }
6963
6964 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6965 {
6966   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
6967   ret->contentNotNull();
6968   return ret.retn();
6969 }
6970
6971 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6972 {
6973   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6974   return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
6975 }
6976
6977 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6978 {
6979   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
6980   ret->contentNotNull();
6981   return ret.retn();
6982 }
6983
6984 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6985 {
6986   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6987   ret->contentNotNull();
6988   return ret.retn();
6989 }
6990
6991 MEDFileIntField1TS::MEDFileIntField1TS()
6992 {
6993   _content=new MEDFileIntField1TSWithoutSDA;
6994 }
6995
6996 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6997 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6998 {
6999 }
7000 catch(INTERP_KERNEL::Exception& e)
7001 { throw e; }
7002
7003 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7004 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
7005 {
7006 }
7007 catch(INTERP_KERNEL::Exception& e)
7008 { throw e; }
7009
7010 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
7011 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
7012 {
7013 }
7014 catch(INTERP_KERNEL::Exception& e)
7015 { throw e; }
7016
7017 /*!
7018  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7019  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7020  *
7021  * \warning this is a shallow copy constructor
7022  */
7023 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
7024 {
7025 }
7026
7027 MEDFileIntField1TS *MEDFileIntField1TS::shallowCpy() const
7028 {
7029   return new MEDFileIntField1TS(*this);
7030 }
7031
7032 /*!
7033  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
7034  * following the given input policy.
7035  *
7036  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
7037  *                            By default (true) the globals are deeply copied.
7038  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
7039  */
7040 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
7041 {
7042   MCAuto<MEDFileField1TS> ret;
7043   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
7044   if(content)
7045     {
7046       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
7047       if(!contc)
7048         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
7049       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
7050       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
7051     }
7052   else
7053     ret=MEDFileField1TS::New();
7054   if(isDeepCpyGlobs)
7055     ret->deepCpyGlobs(*this);
7056   else
7057     ret->shallowCpyGlobs(*this);
7058   return ret.retn();
7059 }
7060
7061 /*!
7062  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
7063  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
7064  * "Sort By Type"), if not, an exception is thrown. 
7065  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7066  *  \param [in] field - the field to add to \a this.
7067  *  \throw If the name of \a field is empty.
7068  *  \throw If the data array of \a field is not set.
7069  *  \throw If the data array is already allocated but has different number of components
7070  *         than \a field.
7071  *  \throw If the underlying mesh of \a field has no name.
7072  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7073  */
7074 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
7075 {
7076   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7077   setFileName("");
7078   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
7079 }
7080
7081 /*!
7082  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
7083  * can be an aggregation of several MEDCouplingFieldDouble instances.
7084  * The mesh support of input parameter \a field is ignored here, it can be NULL.
7085  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
7086  * and \a profile.
7087  *
7088  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7089  * A new profile is added only if no equal profile is missing.
7090  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7091  *  \param [in] field - the field to add to \a this.
7092  *  \param [in] mesh - the supporting mesh of \a field.
7093  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7094  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7095  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7096  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7097  *  \throw If the data array of \a field is not set.
7098  *  \throw If the data array of \a this is already allocated but has different number of
7099  *         components than \a field.
7100  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7101  *  \sa setFieldNoProfileSBT()
7102  */
7103 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7104 {
7105   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7106   setFileName("");
7107   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7108 }
7109
7110 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
7111 {
7112   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7113   if(!pt)
7114     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
7115   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
7116   if(!ret)
7117     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 !");
7118   return ret;
7119 }
7120
7121 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7122 {
7123   if(getFileName().empty())
7124     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7125   MCAuto<DataArray> arrOut;
7126   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7127   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7128   return ret2.retn();
7129 }
7130
7131 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
7132 {
7133   if(arr.isNull())
7134     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
7135   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
7136   if(!arrC)
7137     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
7138   arrC->incrRef();
7139   return arrC;
7140 }
7141
7142 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
7143 {
7144   int t1,t2;
7145   double t0(f->getTime(t1,t2));
7146   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
7147   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7148   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
7149   ret->setTime(t0,t1,t2); ret->setArray(arr2);
7150   return ret.retn();
7151 }
7152
7153 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
7154 {
7155   if(!f)
7156     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
7157   int t1,t2;
7158   double t0(f->getTime(t1,t2));
7159   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7160   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
7161   ret->setTime(t0,t1,t2);
7162   return ret;
7163 }
7164
7165 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
7166 {
7167   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
7168 }
7169
7170 /*!
7171  * 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
7172  * method should be called (getFieldOnMeshAtLevel for example).
7173  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
7174  *
7175  * \param [in] mesh - the mesh the field is lying on
7176  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
7177  *          caller is to delete this field using decrRef() as it is no more needed. 
7178  */
7179 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
7180 {
7181   MCAuto<DataArray> arrOut;
7182   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
7183   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7184   return ret2.retn();
7185 }
7186
7187 /*!
7188  * Returns a new MEDCouplingFieldInt of a given type lying on
7189  * the top level cells of the first mesh in MED file. If \a this field 
7190  * has not been constructed via file reading, an exception is thrown.
7191  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7192  *  \param [in] type - a spatial discretization of interest.
7193  *  \param [in] renumPol - specifies how to permute values of the result field according to
7194  *          the optional numbers of cells and nodes, if any. The valid values are
7195  *          - 0 - do not permute.
7196  *          - 1 - permute cells.
7197  *          - 2 - permute nodes.
7198  *          - 3 - permute cells and nodes.
7199  *
7200  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7201  *          caller is to delete this field using decrRef() as it is no more needed. 
7202  *  \throw If \a this field has not been constructed via file reading.
7203  *  \throw If the MED file is not readable.
7204  *  \throw If there is no mesh in the MED file.
7205  *  \throw If no field values of the given \a type.
7206  *  \throw If no field values lying on the top level support.
7207  *  \sa getFieldAtLevel()
7208  */
7209 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7210 {
7211   if(getFileName().empty())
7212     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7213   MCAuto<DataArray> arrOut;
7214   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7215   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7216   return ret2.retn();
7217 }
7218
7219 /*!
7220  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
7221  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7222  *  \param [in] type - a spatial discretization of the new field.
7223  *  \param [in] mesh - the supporting mesh.
7224  *  \param [in] renumPol - specifies how to permute values of the result field according to
7225  *          the optional numbers of cells and nodes, if any. The valid values are
7226  *          - 0 - do not permute.
7227  *          - 1 - permute cells.
7228  *          - 2 - permute nodes.
7229  *          - 3 - permute cells and nodes.
7230  *
7231  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7232  *          caller is to delete this field using decrRef() as it is no more needed. 
7233  *  \throw If no field of \a this is lying on \a mesh.
7234  *  \throw If the mesh is empty.
7235  *  \throw If no field values of the given \a type are available.
7236  *  \sa getFieldAtLevel()
7237  *  \sa getFieldOnMeshAtLevel() 
7238  */
7239 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7240 {
7241   MCAuto<DataArray> arrOut;
7242   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7243   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7244   return ret2.retn();
7245 }
7246
7247 /*!
7248  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7249  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7250  *  \param [in] type - a spatial discretization of interest.
7251  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7252  *  \param [in] mesh - the supporting mesh.
7253  *  \param [in] renumPol - specifies how to permute values of the result field according to
7254  *          the optional numbers of cells and nodes, if any. The valid values are
7255  *          - 0 - do not permute.
7256  *          - 1 - permute cells.
7257  *          - 2 - permute nodes.
7258  *          - 3 - permute cells and nodes.
7259  *
7260  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7261  *          caller is to delete this field using decrRef() as it is no more needed. 
7262  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7263  *  \throw If no field of \a this is lying on \a mesh.
7264  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7265  *  \sa getFieldAtLevel()
7266  *  \sa getFieldOnMeshAtLevel() 
7267  */
7268 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7269 {
7270   MCAuto<DataArray> arrOut;
7271   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7272   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7273   return ret2.retn();
7274 }
7275
7276 /*!
7277  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7278  * This method is called "Old" because in MED3 norm a field has only one meshName
7279  * attached, so this method is for readers of MED2 files. If \a this field 
7280  * has not been constructed via file reading, an exception is thrown.
7281  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7282  *  \param [in] type - a spatial discretization of interest.
7283  *  \param [in] mName - a name of the supporting mesh.
7284  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7285  *  \param [in] renumPol - specifies how to permute values of the result field according to
7286  *          the optional numbers of cells and nodes, if any. The valid values are
7287  *          - 0 - do not permute.
7288  *          - 1 - permute cells.
7289  *          - 2 - permute nodes.
7290  *          - 3 - permute cells and nodes.
7291  *
7292  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7293  *          caller is to delete this field using decrRef() as it is no more needed. 
7294  *  \throw If the MED file is not readable.
7295  *  \throw If there is no mesh named \a mName in the MED file.
7296  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7297  *  \throw If \a this field has not been constructed via file reading.
7298  *  \throw If no field of \a this is lying on the mesh named \a mName.
7299  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7300  *  \sa getFieldAtLevel()
7301  */
7302 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7303 {
7304   if(getFileName().empty())
7305     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7306   MCAuto<DataArray> arrOut;
7307   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7308   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7309   return ret2.retn();
7310 }
7311
7312 /*!
7313  * Returns values and a profile of the field of a given type lying on a given support.
7314  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7315  *  \param [in] type - a spatial discretization of the field.
7316  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7317  *  \param [in] mesh - the supporting mesh.
7318  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7319  *          field of interest lies on. If the field lies on all entities of the given
7320  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7321  *          using decrRef() as it is no more needed.  
7322  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7323  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7324  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7325  *  \throw If no field of \a this is lying on \a mesh.
7326  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7327  */
7328 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7329 {
7330   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7331   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7332 }
7333
7334 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7335 {
7336   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7337   if(!pt)
7338     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7339   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7340   if(!ret)
7341     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 !");
7342   return ret;
7343 }
7344
7345 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7346 {
7347   return contentNotNull()->getUndergroundDataArrayTemplate();
7348 }
7349
7350 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7351
7352 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7353 {
7354 }
7355
7356 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7357 {
7358 }
7359
7360 /*!
7361  * \param [in] fieldId field id in C mode
7362  */
7363 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7364 {
7365   med_field_type typcha;
7366   std::string dtunitOut;
7367   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut));
7368   setDtUnit(dtunitOut.c_str());
7369   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7370 }
7371
7372 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)
7373 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7374 {
7375   setDtUnit(dtunit.c_str());
7376   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7377 }
7378 catch(INTERP_KERNEL::Exception& e)
7379 {
7380     throw e;
7381 }
7382
7383 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7384 {
7385   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7386   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7387     ret+=(*it).capacity();
7388   return ret;
7389 }
7390
7391 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7392 {
7393   std::vector<const BigMemoryObject *> ret;
7394   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7395     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7396   return ret;
7397 }
7398
7399 /*!
7400  * 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
7401  * NULL.
7402  */
7403 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7404 {
7405   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7406   ret->setInfo(_infos);
7407   int sz=(int)_time_steps.size();
7408   for(const int *id=startIds;id!=endIds;id++)
7409     {
7410       if(*id>=0 && *id<sz)
7411         {
7412           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7413           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7414           if(tse)
7415             {
7416               tse->incrRef();
7417               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7418             }
7419           ret->pushBackTimeStep(tse2);
7420         }
7421       else
7422         {
7423           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7424           oss << " ! Should be in [0," << sz << ") !";
7425           throw INTERP_KERNEL::Exception(oss.str());
7426         }
7427     }
7428   if(ret->getNumberOfTS()>0)
7429     ret->synchronizeNameScope();
7430   ret->copyNameScope(*this);
7431   return ret.retn();
7432 }
7433
7434 /*!
7435  * 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
7436  * NULL.
7437  */
7438 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7439 {
7440   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7441   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7442   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7443   ret->setInfo(_infos);
7444   int sz=(int)_time_steps.size();
7445   int j=bg;
7446   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7447     {
7448       if(j>=0 && j<sz)
7449         {
7450           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7451           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7452           if(tse)
7453             {
7454               tse->incrRef();
7455               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7456             }
7457           ret->pushBackTimeStep(tse2);
7458         }
7459       else
7460         {
7461           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7462           oss << " ! Should be in [0," << sz << ") !";
7463           throw INTERP_KERNEL::Exception(oss.str());
7464         }
7465     }
7466   if(ret->getNumberOfTS()>0)
7467     ret->synchronizeNameScope();
7468   ret->copyNameScope(*this);
7469   return ret.retn();
7470 }
7471
7472 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7473 {
7474   int id=0;
7475   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7476   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7477     {
7478       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7479       if(!cur)
7480         continue;
7481       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7482       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7483         ids->pushBackSilent(id);
7484     }
7485   return buildFromTimeStepIds(ids->begin(),ids->end());
7486 }
7487
7488 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7489 {
7490   int id=0;
7491   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7492   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7493     {
7494       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7495       if(!cur)
7496         continue;
7497       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7498       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7499         ids->pushBackSilent(id);
7500     }
7501   return buildFromTimeStepIds(ids->begin(),ids->end());
7502 }
7503
7504 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
7505 {
7506   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7507     if((*it).isNotNull())
7508       if((*it)->presenceOfStructureElements())
7509         return true;
7510   return false;
7511 }
7512
7513 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
7514 {
7515   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7516     if((*it).isNotNull())
7517       if(!(*it)->onlyStructureElements())
7518         return false;
7519   return true;
7520 }
7521
7522 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
7523 {
7524   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7525   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7526     if((*it).isNotNull())
7527       {
7528         if((*it)->presenceOfStructureElements())
7529           {
7530             if(!(*it)->onlyStructureElements())
7531               {
7532                 (*it)->killStructureElements();
7533                 ret.push_back(*it);
7534               }
7535           }
7536         else
7537           {
7538             ret.push_back(*it);
7539           }
7540       }
7541   _time_steps=ret;
7542 }
7543
7544 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
7545 {
7546   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7547   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7548     if((*it).isNotNull())
7549       {
7550         if((*it)->presenceOfStructureElements())
7551           {
7552             if(!(*it)->onlyStructureElements())
7553               (*it)->keepOnlyStructureElements();
7554             ret.push_back(*it);
7555           }
7556       }
7557   _time_steps=ret;
7558 }
7559
7560 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7561 {
7562   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7563     {
7564       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7565       if(!cur)
7566         continue;
7567       if(cur->presenceOfMultiDiscPerGeoType())
7568         return true;
7569     }
7570   return false;
7571 }
7572
7573 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7574 {
7575   return _infos;
7576 }
7577
7578 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7579 {
7580   _infos=info;
7581 }
7582
7583 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7584 {
7585   int ret=0;
7586   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7587     {
7588       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7589       if(pt->isDealingTS(iteration,order))
7590         return ret;
7591     }
7592   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7593   std::vector< std::pair<int,int> > vp=getIterations();
7594   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7595     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7596   throw INTERP_KERNEL::Exception(oss.str());
7597 }
7598
7599 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7600 {
7601   return *_time_steps[getTimeStepPos(iteration,order)];
7602 }
7603
7604 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7605 {
7606   return *_time_steps[getTimeStepPos(iteration,order)];
7607 }
7608
7609 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7610 {
7611   if(_time_steps.empty())
7612     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7613   return _time_steps[0]->getMeshName();
7614 }
7615
7616 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7617 {
7618   std::string oldName(getMeshName());
7619   std::vector< std::pair<std::string,std::string> > v(1);
7620   v[0].first=oldName; v[0].second=newMeshName;
7621   changeMeshNames(v);
7622 }
7623
7624 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7625 {
7626   bool ret=false;
7627   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7628     {
7629       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7630       if(cur)
7631         ret=cur->changeMeshNames(modifTab) || ret;
7632     }
7633   return ret;
7634 }
7635
7636 /*!
7637  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7638  */
7639 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7640 {
7641   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7642 }
7643
7644 /*!
7645  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7646  */
7647 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7648 {
7649   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7650 }
7651
7652 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7653                                                                        MEDFileFieldGlobsReal& glob)
7654 {
7655   bool ret=false;
7656   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7657     {
7658       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7659       if(f1ts)
7660         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7661     }
7662   return ret;
7663 }
7664
7665 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7666 {
7667   std::string startLine(bkOffset,' ');
7668   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7669   if(fmtsId>=0)
7670     oss << " (" << fmtsId << ")";
7671   oss << " has the following name: \"" << _name << "\"." << std::endl;
7672   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7673   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7674     {
7675       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7676     }
7677   int i=0;
7678   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7679     {
7680       std::string chapter(17,'0'+i);
7681       oss << startLine << chapter << std::endl;
7682       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7683       if(cur)
7684         cur->simpleRepr(bkOffset+2,oss,i);
7685       else
7686         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7687       oss << startLine << chapter << std::endl;
7688     }
7689 }
7690
7691 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7692 {
7693   std::size_t sz=_time_steps.size();
7694   std::vector< std::pair<int,int> > ret(sz);
7695   ret1.resize(sz);
7696   for(std::size_t i=0;i<sz;i++)
7697     {
7698       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7699       if(f1ts)
7700         {
7701           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7702         }
7703       else
7704         {
7705           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7706           throw INTERP_KERNEL::Exception(oss.str());
7707         }
7708     }
7709   return ret;
7710 }
7711
7712 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7713 {
7714   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7715   if(!tse2)
7716     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7717   checkCoherencyOfType(tse2);
7718   if(_time_steps.empty())
7719     {
7720       setName(tse2->getName().c_str());
7721       setInfo(tse2->getInfo());
7722     }
7723   checkThatComponentsMatch(tse2->getInfo());
7724   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7725     setDtUnit(tse->getDtUnit());
7726   _time_steps.push_back(tse);
7727 }
7728
7729 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7730 {
7731   std::size_t nbOfCompo=_infos.size();
7732   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7733     {
7734       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7735       if(cur)
7736         {
7737           if((cur->getInfo()).size()!=nbOfCompo)
7738             {
7739               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7740               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7741               throw INTERP_KERNEL::Exception(oss.str());
7742             }
7743           cur->copyNameScope(*this);
7744         }
7745     }
7746 }
7747
7748 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7749 {
7750   _time_steps.resize(nbPdt);
7751   for(int i=0;i<nbPdt;i++)
7752     {
7753       std::vector< std::pair<int,int> > ts;
7754       med_int numdt=0,numo=0;
7755       med_float dt=0.0;
7756       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7757       switch(fieldTyp)
7758       {
7759         case MED_FLOAT64:
7760           {
7761             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7762             break;
7763           }
7764         case MED_INT32:
7765           {
7766             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7767             break;
7768           }
7769         default:
7770           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7771       }
7772       if(loadAll)
7773         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7774       else
7775         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7776       synchronizeNameScope();
7777     }
7778 }
7779
7780 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7781 {
7782   if(_time_steps.empty())
7783     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7784   checkThatNbOfCompoOfTSMatchThis();
7785   std::vector<std::string> infos(getInfo());
7786   int nbComp=infos.size();
7787   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7788   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7789   for(int i=0;i<nbComp;i++)
7790     {
7791       std::string info=infos[i];
7792       std::string c,u;
7793       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7794       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7795       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7796     }
7797   if(_name.empty())
7798     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7799   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7800   int nbOfTS=_time_steps.size();
7801   for(int i=0;i<nbOfTS;i++)
7802     _time_steps[i]->writeLL(fid,opts,*this);
7803 }
7804
7805 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7806 {
7807   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7808     {
7809       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7810       if(elt)
7811         elt->loadBigArraysRecursively(fid,nasc);
7812     }
7813 }
7814
7815 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7816 {
7817   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7818     {
7819       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7820       if(elt)
7821         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7822     }
7823 }
7824
7825 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7826 {
7827   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7828     {
7829       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7830       if(elt)
7831         elt->unloadArrays();
7832     }
7833 }
7834
7835 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7836 {
7837   return _time_steps.size();
7838 }
7839
7840 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7841 {
7842   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7843   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7844     {
7845       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7846       if(tmp)
7847         newTS.push_back(*it);
7848     }
7849   _time_steps=newTS;
7850 }
7851
7852 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7853 {
7854   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7855   int maxId=(int)_time_steps.size();
7856   int ii=0;
7857   std::set<int> idsToDel;
7858   for(const int *id=startIds;id!=endIds;id++,ii++)
7859     {
7860       if(*id>=0 && *id<maxId)
7861         {
7862           idsToDel.insert(*id);
7863         }
7864       else
7865         {
7866           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7867           throw INTERP_KERNEL::Exception(oss.str());
7868         }
7869     }
7870   for(int iii=0;iii<maxId;iii++)
7871     if(idsToDel.find(iii)==idsToDel.end())
7872       newTS.push_back(_time_steps[iii]);
7873   _time_steps=newTS;
7874 }
7875
7876 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7877 {
7878   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7879   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7880   if(nbOfEntriesToKill==0)
7881     return ;
7882   std::size_t sz=_time_steps.size();
7883   std::vector<bool> b(sz,true);
7884   int j=bg;
7885   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7886     b[j]=false;
7887   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7888   for(std::size_t i=0;i<sz;i++)
7889     if(b[i])
7890       newTS.push_back(_time_steps[i]);
7891   _time_steps=newTS;
7892 }
7893
7894 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7895 {
7896   int ret=0;
7897   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7898   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7899     {
7900       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7901       if(tmp)
7902         {
7903           int it2,ord;
7904           tmp->getTime(it2,ord);
7905           if(it2==iteration && order==ord)
7906             return ret;
7907           else
7908             oss << "(" << it2 << ","  << ord << "), ";
7909         }
7910     }
7911   throw INTERP_KERNEL::Exception(oss.str());
7912 }
7913
7914 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7915 {
7916   int ret=0;
7917   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7918   oss.precision(15);
7919   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7920     {
7921       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7922       if(tmp)
7923         {
7924           int it2,ord;
7925           double ti=tmp->getTime(it2,ord);
7926           if(fabs(time-ti)<eps)
7927             return ret;
7928           else
7929             oss << ti << ", ";
7930         }
7931     }
7932   throw INTERP_KERNEL::Exception(oss.str());
7933 }
7934
7935 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7936 {
7937   int lgth=_time_steps.size();
7938   std::vector< std::pair<int,int> > ret(lgth);
7939   for(int i=0;i<lgth;i++)
7940     _time_steps[i]->fillIteration(ret[i]);
7941   return ret;
7942 }
7943
7944 /*!
7945  * 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'
7946  * This method returns two things.
7947  * - The absolute dimension of 'this' in first parameter. 
7948  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7949  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7950  *
7951  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7952  * Only these 3 discretizations will be taken into account here.
7953  *
7954  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7955  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7956  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7957  *
7958  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7959  * 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'.
7960  * 
7961  * Let's consider the typical following case :
7962  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7963  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7964  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7965  *   TETRA4 and SEG2
7966  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7967  *
7968  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7969  * 
7970  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7971  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7972  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7973  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7974  */
7975 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7976 {
7977   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7978 }
7979
7980 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7981 {
7982   if(pos<0 || pos>=(int)_time_steps.size())
7983     {
7984       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7985       throw INTERP_KERNEL::Exception(oss.str());
7986     }
7987   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7988   if(item==0)
7989     {
7990       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7991       oss << "\nTry to use following method eraseEmptyTS !";
7992       throw INTERP_KERNEL::Exception(oss.str());
7993     }
7994   return item;
7995 }
7996
7997 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7998 {
7999   if(pos<0 || pos>=(int)_time_steps.size())
8000     {
8001       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8002       throw INTERP_KERNEL::Exception(oss.str());
8003     }
8004   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8005   if(item==0)
8006     {
8007       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8008       oss << "\nTry to use following method eraseEmptyTS !";
8009       throw INTERP_KERNEL::Exception(oss.str());
8010     }
8011   return item;
8012 }
8013
8014 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
8015 {
8016   std::vector<std::string> ret;
8017   std::set<std::string> ret2;
8018   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8019     {
8020       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
8021       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8022         if(ret2.find(*it2)==ret2.end())
8023           {
8024             ret.push_back(*it2);
8025             ret2.insert(*it2);
8026           }
8027     }
8028   return ret;
8029 }
8030
8031 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
8032 {
8033   std::vector<std::string> ret;
8034   std::set<std::string> ret2;
8035   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8036     {
8037       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8038       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8039         if(ret2.find(*it2)==ret2.end())
8040           {
8041             ret.push_back(*it2);
8042             ret2.insert(*it2);
8043           }
8044     }
8045   return ret;
8046 }
8047
8048 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
8049 {
8050   std::vector<std::string> ret;
8051   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8052     {
8053       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
8054       ret.insert(ret.end(),tmp.begin(),tmp.end());
8055     }
8056   return ret;
8057 }
8058
8059 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
8060 {
8061   std::vector<std::string> ret;
8062   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8063     {
8064       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
8065       ret.insert(ret.end(),tmp.begin(),tmp.end());
8066     }
8067   return ret;
8068 }
8069
8070 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8071 {
8072   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8073     (*it)->changePflsRefsNamesGen2(mapOfModif);
8074 }
8075
8076 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8077 {
8078   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8079     (*it)->changeLocsRefsNamesGen2(mapOfModif);
8080 }
8081
8082 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
8083 {
8084   int lgth=_time_steps.size();
8085   std::vector< std::vector<TypeOfField> > ret(lgth);
8086   for(int i=0;i<lgth;i++)
8087     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
8088   return ret;
8089 }
8090
8091 /*!
8092  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
8093  */
8094 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
8095 {
8096   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
8097 }
8098
8099 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
8100 {
8101   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
8102   std::size_t i=0;
8103   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8104     {
8105       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
8106         ret->_time_steps[i]=(*it)->deepCopy();
8107     }
8108   return ret.retn();
8109 }
8110
8111 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
8112 {
8113   std::size_t sz(_infos.size()),sz2(_time_steps.size());
8114   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
8115   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
8116   for(std::size_t i=0;i<sz;i++)
8117     {
8118       ret[i]=shallowCpy();
8119       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
8120     }
8121   for(std::size_t i=0;i<sz2;i++)
8122     {
8123       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
8124       if(ret1.size()!=sz)
8125         {
8126           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
8127           throw INTERP_KERNEL::Exception(oss.str());
8128         }
8129       ts[i]=ret1;
8130     }
8131   for(std::size_t i=0;i<sz;i++)
8132     for(std::size_t j=0;j<sz2;j++)
8133       ret[i]->_time_steps[j]=ts[j][i];
8134   return ret;
8135 }
8136
8137 /*!
8138  * This method splits into discretization each time steps in \a this.
8139  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
8140  */
8141 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
8142 {
8143   std::size_t sz(_time_steps.size());
8144   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8145   for(std::size_t i=0;i<sz;i++)
8146     {
8147       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8148       if(!timeStep)
8149         {
8150           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
8151           throw INTERP_KERNEL::Exception(oss.str());
8152         }
8153       items[i]=timeStep->splitDiscretizations();  
8154     }
8155   //
8156   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
8157   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
8158   std::vector< TypeOfField > types;
8159   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8160     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8161       {
8162         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
8163         if(ts.size()!=1)
8164           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
8165         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
8166         if(it2==types.end())
8167           types.push_back(ts[0]);
8168       }
8169   ret.resize(types.size()); ret2.resize(types.size());
8170   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8171     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8172       {
8173         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
8174         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
8175         ret2[pos].push_back(*it1);
8176       }
8177   for(std::size_t i=0;i<types.size();i++)
8178     {
8179       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8180       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
8181         elt->pushBackTimeStep(*it1);//also updates infos in elt
8182       ret[i]=elt;
8183       elt->MEDFileFieldNameScope::operator=(*this);
8184     }
8185   return ret;
8186 }
8187
8188 /*!
8189  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
8190  */
8191 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
8192 {
8193   std::size_t sz(_time_steps.size());
8194   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8195   std::size_t szOut(std::numeric_limits<std::size_t>::max());
8196   for(std::size_t i=0;i<sz;i++)
8197     {
8198       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8199       if(!timeStep)
8200         {
8201           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
8202           throw INTERP_KERNEL::Exception(oss.str());
8203         }
8204       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
8205       if(szOut==std::numeric_limits<std::size_t>::max())
8206         szOut=items[i].size();
8207       else
8208         if(items[i].size()!=szOut)
8209           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
8210     }
8211   if(szOut==std::numeric_limits<std::size_t>::max())
8212     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
8213   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
8214   for(std::size_t i=0;i<szOut;i++)
8215     {
8216       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8217       for(std::size_t j=0;j<sz;j++)
8218         elt->pushBackTimeStep(items[j][i]);
8219       ret[i]=elt;
8220       elt->MEDFileFieldNameScope::operator=(*this);
8221     }
8222   return ret;
8223 }
8224
8225 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
8226 {
8227   _name=field->getName();
8228   if(_name.empty())
8229     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
8230   if(!arr)
8231     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
8232   _infos=arr->getInfoOnComponents();
8233 }
8234
8235 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
8236 {
8237   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
8238   if(_name!=field->getName())
8239     {
8240       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
8241       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
8242       throw INTERP_KERNEL::Exception(oss.str());
8243     }
8244   if(!arr)
8245     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
8246   checkThatComponentsMatch(arr->getInfoOnComponents());
8247 }
8248
8249 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
8250 {
8251   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
8252   if(getInfo().size()!=compos.size())
8253     {
8254       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
8255       oss << " number of components of element to append (" << compos.size() << ") !";
8256       throw INTERP_KERNEL::Exception(oss.str());
8257     }
8258   if(_infos!=compos)
8259     {
8260       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
8261       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
8262       oss << " But compo in input fields are : ";
8263       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
8264       oss << " !";
8265       throw INTERP_KERNEL::Exception(oss.str());
8266     }
8267 }
8268
8269 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
8270 {
8271   std::size_t sz=_infos.size();
8272   int j=0;
8273   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
8274     {
8275       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8276       if(elt)
8277         if(elt->getInfo().size()!=sz)
8278           {
8279             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
8280             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
8281             throw INTERP_KERNEL::Exception(oss.str());
8282           }
8283     }
8284 }
8285
8286 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8287 {
8288   if(!field)
8289     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8290   if(!_time_steps.empty())
8291     checkCoherencyOfTinyInfo(field,arr);
8292   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8293   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8294   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8295   copyTinyInfoFrom(field,arr);
8296   _time_steps.push_back(obj);
8297 }
8298
8299 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8300 {
8301   if(!field)
8302     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8303   if(!_time_steps.empty())
8304     checkCoherencyOfTinyInfo(field,arr);
8305   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8306   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8307   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8308   copyTinyInfoFrom(field,arr);
8309   _time_steps.push_back(obj);
8310 }
8311
8312 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8313 {
8314   int sz=(int)_time_steps.size();
8315   if(i<0 || i>=sz)
8316     {
8317       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8318       throw INTERP_KERNEL::Exception(oss.str());
8319     }
8320   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8321   if(tsPtr)
8322     {
8323       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8324         {
8325           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8326           throw INTERP_KERNEL::Exception(oss.str());
8327         }
8328     }
8329   _time_steps[i]=ts;
8330 }
8331
8332 //= MEDFileFieldMultiTSWithoutSDA
8333
8334 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)
8335 {
8336   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8337 }
8338
8339 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8340 {
8341 }
8342
8343 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8344 {
8345 }
8346
8347 /*!
8348  * \param [in] fieldId field id in C mode
8349  */
8350 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8351 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8352 {
8353 }
8354 catch(INTERP_KERNEL::Exception& e)
8355 { throw e; }
8356
8357 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)
8358 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8359 {
8360 }
8361 catch(INTERP_KERNEL::Exception& e)
8362 { throw e; }
8363
8364 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8365 {
8366   return new MEDFileField1TSWithoutSDA;
8367 }
8368
8369 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8370 {
8371   if(!f1ts)
8372     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8373   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8374   if(!f1tsC)
8375     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8376 }
8377
8378 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8379 {
8380   return MEDFileField1TSWithoutSDA::TYPE_STR;
8381 }
8382
8383 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8384 {
8385   return new MEDFileFieldMultiTSWithoutSDA(*this);
8386 }
8387
8388 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8389 {
8390   return new MEDFileFieldMultiTSWithoutSDA;
8391 }
8392
8393 /*!
8394  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8395  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8396  */
8397 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
8398 {
8399   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8400   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8401   if(!myF1TSC)
8402     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8403   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8404 }
8405
8406 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8407 {
8408   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8409   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8410   int i=0;
8411   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8412     {
8413       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8414       if(eltToConv)
8415         {
8416           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8417           if(!eltToConvC)
8418             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8419           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8420           ret->setIteration(i,elt);
8421         }
8422     }
8423   return ret.retn();
8424 }
8425
8426 //= MEDFileAnyTypeFieldMultiTS
8427
8428 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8429 {
8430 }
8431
8432 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8433 try:MEDFileFieldGlobsReal(fid)
8434 {
8435   _content=BuildContentFrom(fid,loadAll,ms);
8436   loadGlobals(fid);
8437 }
8438 catch(INTERP_KERNEL::Exception& e)
8439 {
8440     throw e;
8441 }
8442
8443 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8444 {
8445   med_field_type typcha;
8446   std::vector<std::string> infos;
8447   std::string dtunit;
8448   int i(-1);
8449   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit);
8450   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8451   switch(typcha)
8452   {
8453     case MED_FLOAT64:
8454       {
8455         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8456         break;
8457       }
8458     case MED_INT32:
8459       {
8460         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8461         break;
8462       }
8463     default:
8464       {
8465         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] !";
8466         throw INTERP_KERNEL::Exception(oss.str());
8467       }
8468   }
8469   ret->setDtUnit(dtunit.c_str());
8470   return ret.retn();
8471 }
8472
8473 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8474 {
8475   med_field_type typcha;
8476   //
8477   std::vector<std::string> infos;
8478   std::string dtunit,fieldName;
8479   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
8480   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8481   switch(typcha)
8482   {
8483     case MED_FLOAT64:
8484       {
8485         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8486         break;
8487       }
8488     case MED_INT32:
8489       {
8490         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8491         break;
8492       }
8493     default:
8494       {
8495         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] !";
8496         throw INTERP_KERNEL::Exception(oss.str());
8497       }
8498   }
8499   ret->setDtUnit(dtunit.c_str());
8500   return ret.retn();
8501 }
8502
8503 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8504 {
8505   if(!c)
8506     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8507   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8508     {
8509       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8510       ret->_content=c;  c->incrRef();
8511       return ret.retn();
8512     }
8513   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8514     {
8515       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8516       ret->_content=c;  c->incrRef();
8517       return ret.retn();
8518     }
8519   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8520 }
8521
8522 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8523 {
8524   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8525   std::string fileName(FileNameFromFID(fid));
8526   ret->setFileName(fileName);
8527   return ret;
8528 }
8529
8530 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8531 try:MEDFileFieldGlobsReal(fid)
8532 {
8533   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8534   loadGlobals(fid);
8535 }
8536 catch(INTERP_KERNEL::Exception& e)
8537 {
8538     throw e;
8539 }
8540
8541 //= MEDFileIntFieldMultiTSWithoutSDA
8542
8543 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)
8544 {
8545   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8546 }
8547
8548 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8549 {
8550 }
8551
8552 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8553 {
8554 }
8555
8556 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)
8557 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8558 {
8559 }
8560 catch(INTERP_KERNEL::Exception& e)
8561 { throw e; }
8562
8563 /*!
8564  * \param [in] fieldId field id in C mode
8565  */
8566 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8567 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8568 {
8569 }
8570 catch(INTERP_KERNEL::Exception& e)
8571 { throw e; }
8572
8573 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8574 {
8575   return new MEDFileIntField1TSWithoutSDA;
8576 }
8577
8578 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8579 {
8580   if(!f1ts)
8581     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8582   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8583   if(!f1tsC)
8584     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8585 }
8586
8587 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8588 {
8589   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8590 }
8591
8592 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8593 {
8594   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8595 }
8596
8597 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8598 {
8599   return new MEDFileIntFieldMultiTSWithoutSDA;
8600 }
8601
8602 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8603 {
8604   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8605   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8606   int i=0;
8607   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8608     {
8609       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8610       if(eltToConv)
8611         {
8612           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8613           if(!eltToConvC)
8614             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8615           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8616           ret->setIteration(i,elt);
8617         }
8618     }
8619   return ret.retn();
8620 }
8621
8622 //= MEDFileAnyTypeFieldMultiTS
8623
8624 /*!
8625  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8626  * that has been read from a specified MED file.
8627  *  \param [in] fileName - the name of the MED file to read.
8628  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8629  *          is to delete this field using decrRef() as it is no more needed.
8630  *  \throw If reading the file fails.
8631  */
8632 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8633 {
8634   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8635   return New(fid,loadAll);
8636 }
8637
8638 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8639 {
8640   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8641   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8642   ret->loadGlobals(fid);
8643   return ret.retn();
8644 }
8645
8646 /*!
8647  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8648  * that has been read from a specified MED file.
8649  *  \param [in] fileName - the name of the MED file to read.
8650  *  \param [in] fieldName - the name of the field to read.
8651  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8652  *          is to delete this field using decrRef() as it is no more needed.
8653  *  \throw If reading the file fails.
8654  *  \throw If there is no field named \a fieldName in the file.
8655  */
8656 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8657 {
8658   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8659   return New(fid,fieldName,loadAll);
8660 }
8661
8662 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8663 {
8664   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8665   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8666   ret->loadGlobals(fid);
8667   return ret.retn();
8668 }
8669
8670 /*!
8671  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8672  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8673  *
8674  * \warning this is a shallow copy constructor
8675  */
8676 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8677 {
8678   if(!shallowCopyOfContent)
8679     {
8680       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8681       otherPtr->incrRef();
8682       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8683     }
8684   else
8685     {
8686       _content=other.shallowCpy();
8687     }
8688 }
8689
8690 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8691 {
8692   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8693   if(!ret)
8694     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8695   return ret;
8696 }
8697
8698 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8699 {
8700   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8701   if(!ret)
8702     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8703   return ret;
8704 }
8705
8706 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8707 {
8708   return contentNotNullBase()->getPflsReallyUsed2();
8709 }
8710
8711 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8712 {
8713   return contentNotNullBase()->getLocsReallyUsed2();
8714 }
8715
8716 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8717 {
8718   return contentNotNullBase()->getPflsReallyUsedMulti2();
8719 }
8720
8721 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8722 {
8723   return contentNotNullBase()->getLocsReallyUsedMulti2();
8724 }
8725
8726 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8727 {
8728   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8729 }
8730
8731 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8732 {
8733   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8734 }
8735
8736 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8737 {
8738   return contentNotNullBase()->getNumberOfTS();
8739 }
8740
8741 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8742 {
8743   contentNotNullBase()->eraseEmptyTS();
8744 }
8745
8746 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8747 {
8748   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8749 }
8750
8751 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8752 {
8753   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8754 }
8755
8756 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8757 {
8758   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8759   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8760   ret->_content=c;
8761   return ret.retn();
8762 }
8763
8764 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8765 {
8766   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8767   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8768   ret->_content=c;
8769   return ret.retn();
8770 }
8771
8772 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8773 {
8774   return contentNotNullBase()->getIterations();
8775 }
8776
8777 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8778 {
8779   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8780     pushBackTimeStep(*it);
8781 }
8782
8783 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8784 {
8785   if(!fmts)
8786     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8787   int nbOfTS(fmts->getNumberOfTS());
8788   for(int i=0;i<nbOfTS;i++)
8789     {
8790       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8791       pushBackTimeStep(elt);
8792     }
8793 }
8794
8795 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8796 {
8797   if(!f1ts)
8798     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8799   checkCoherencyOfType(f1ts);
8800   f1ts->incrRef();
8801   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8802   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8803   c->incrRef();
8804   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8805   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8806     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8807   _content->pushBackTimeStep(cSafe);
8808   appendGlobs(*f1ts,1e-12);
8809 }
8810
8811 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8812 {
8813   contentNotNullBase()->synchronizeNameScope();
8814 }
8815
8816 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8817 {
8818   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8819 }
8820
8821 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8822 {
8823   return contentNotNullBase()->getPosGivenTime(time,eps);
8824 }
8825
8826 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8827 {
8828   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8829 }
8830
8831 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8832 {
8833   return contentNotNullBase()->getTypesOfFieldAvailable();
8834 }
8835
8836 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
8837 {
8838   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8839 }
8840
8841 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8842 {
8843   return contentNotNullBase()->getName();
8844 }
8845
8846 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8847 {
8848   contentNotNullBase()->setName(name);
8849 }
8850
8851 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8852 {
8853   return contentNotNullBase()->getDtUnit();
8854 }
8855
8856 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8857 {
8858   contentNotNullBase()->setDtUnit(dtUnit);
8859 }
8860
8861 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8862 {
8863   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8864 }
8865
8866 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8867 {
8868   return contentNotNullBase()->getTimeSteps(ret1);
8869 }
8870
8871 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8872 {
8873   return contentNotNullBase()->getMeshName();
8874 }
8875
8876 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8877 {
8878   contentNotNullBase()->setMeshName(newMeshName);
8879 }
8880
8881 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8882 {
8883   return contentNotNullBase()->changeMeshNames(modifTab);
8884 }
8885
8886 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8887 {
8888   return contentNotNullBase()->getInfo();
8889 }
8890
8891 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8892 {
8893   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8894 }
8895
8896 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8897 {
8898   return contentNotNullBase()->setInfo(info);
8899 }
8900
8901 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8902 {
8903   const std::vector<std::string> ret=getInfo();
8904   return (int)ret.size();
8905 }
8906
8907 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8908 {
8909   writeGlobals(fid,*this);
8910   contentNotNullBase()->writeLL(fid,*this);
8911 }
8912
8913 /*!
8914  * This method alloc the arrays and load potentially huge arrays contained in this field.
8915  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8916  * This method can be also called to refresh or reinit values from a file.
8917  * 
8918  * \throw If the fileName is not set or points to a non readable MED file.
8919  */
8920 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8921 {
8922   if(getFileName().empty())
8923     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8924   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8925   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8926 }
8927
8928 /*!
8929  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8930  * But once data loaded once, this method does nothing.
8931  * 
8932  * \throw If the fileName is not set or points to a non readable MED file.
8933  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8934  */
8935 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8936 {
8937   if(!getFileName().empty())
8938     {
8939       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8940       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8941     }
8942 }
8943
8944 /*!
8945  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8946  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8947  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8948  * 
8949  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8950  */
8951 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8952 {
8953   contentNotNullBase()->unloadArrays();
8954 }
8955
8956 /*!
8957  * 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.
8958  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8959  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8960  * 
8961  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8962  */
8963 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8964 {
8965   if(!getFileName().empty())
8966     contentNotNullBase()->unloadArrays();
8967 }
8968
8969 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8970 {
8971   std::ostringstream oss;
8972   contentNotNullBase()->simpleRepr(0,oss,-1);
8973   simpleReprGlobs(oss);
8974   return oss.str();
8975 }
8976
8977 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8978 {
8979   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8980 }
8981
8982 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8983 {
8984   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8985   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8986   return ret;
8987 }
8988
8989 /*!
8990  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8991  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8992  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8993  */
8994 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8995 {
8996   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8997   if(!content)
8998     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8999   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
9000   std::size_t sz(contentsSplit.size());
9001   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9002   for(std::size_t i=0;i<sz;i++)
9003     {
9004       ret[i]=shallowCpy();
9005       ret[i]->_content=contentsSplit[i];
9006     }
9007   return ret;
9008 }
9009
9010 /*!
9011  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
9012  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9013  */
9014 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
9015 {
9016   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9017   if(!content)
9018     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
9019   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
9020   std::size_t sz(contentsSplit.size());
9021   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9022   for(std::size_t i=0;i<sz;i++)
9023     {
9024       ret[i]=shallowCpy();
9025       ret[i]->_content=contentsSplit[i];
9026     }
9027   return ret;
9028 }
9029
9030 /*!
9031  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
9032  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9033  */
9034 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
9035 {
9036   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9037   if(!content)
9038     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
9039   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
9040   std::size_t sz(contentsSplit.size());
9041   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9042   for(std::size_t i=0;i<sz;i++)
9043     {
9044       ret[i]=shallowCpy();
9045       ret[i]->_content=contentsSplit[i];
9046     }
9047   return ret;
9048 }
9049
9050 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
9051 {
9052   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9053   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
9054     ret->_content=_content->deepCopy();
9055   ret->deepCpyGlobs(*this);
9056   return ret.retn();
9057 }
9058
9059 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
9060 {
9061   return _content;
9062 }
9063
9064 /*!
9065  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9066  *  \param [in] iteration - the iteration number of a required time step.
9067  *  \param [in] order - the iteration order number of required time step.
9068  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
9069  *          delete this field using decrRef() as it is no more needed.
9070  *  \throw If there is no required time step in \a this field.
9071  */
9072 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
9073 {
9074   int pos=getPosOfTimeStep(iteration,order);
9075   return getTimeStepAtPos(pos);
9076 }
9077
9078 /*!
9079  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9080  *  \param [in] time - the time of the time step of interest.
9081  *  \param [in] eps - a precision used to compare time values.
9082  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9083  *          delete this field using decrRef() as it is no more needed.
9084  *  \throw If there is no required time step in \a this field.
9085  */
9086 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
9087 {
9088   int pos=getPosGivenTime(time,eps);
9089   return getTimeStepAtPos(pos);
9090 }
9091
9092 /*!
9093  * 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.
9094  * The float64 value of time attached to the pair of integers are not considered here.
9095  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
9096  *
9097  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
9098  * \throw If there is a null pointer in \a vectFMTS.
9099  */
9100 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
9101 {
9102   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
9103   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9104   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9105   while(!lstFMTS.empty())
9106     {
9107       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9108       MEDFileAnyTypeFieldMultiTS *curIt(*it);
9109       if(!curIt)
9110         throw INTERP_KERNEL::Exception(msg);
9111       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
9112       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9113       elt.push_back(curIt); it=lstFMTS.erase(it);
9114       while(it!=lstFMTS.end())
9115         {
9116           curIt=*it;
9117           if(!curIt)
9118             throw INTERP_KERNEL::Exception(msg);
9119           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
9120           if(refIts==curIts)
9121             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9122           else
9123             it++;
9124         }
9125       ret.push_back(elt);
9126     }
9127   return ret;
9128 }
9129
9130 /*!
9131  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
9132  * All returned instances in a subvector can be safely loaded, rendered along time
9133  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
9134  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
9135  * 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).
9136  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
9137  * 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.
9138  *
9139  * \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().
9140  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
9141  * \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.
9142  * \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.
9143  *
9144  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
9145  * \throw If an element in \a vectFMTS change of spatial discretization along time.
9146  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
9147  * \thorw If some elements in \a vectFMTS do not have the same times steps.
9148  * \throw If mesh is null.
9149  * \throw If an element in \a vectFMTS is null.
9150  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
9151  */
9152 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
9153 {
9154   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
9155   if(!mesh)
9156     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
9157   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9158   if(vectFMTS.empty())
9159     return ret;
9160   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
9161   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
9162   if(!frstElt)
9163     throw INTERP_KERNEL::Exception(msg);
9164   std::size_t i=0;
9165   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
9166   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
9167   for(;it!=vectFMTS.end();it++,i++)
9168     {
9169       if(!(*it))
9170         throw INTERP_KERNEL::Exception(msg);
9171       TypeOfField tof0,tof1;
9172       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
9173         {
9174           if(tof1!=ON_NODES)
9175             vectFMTSNotNodes.push_back(*it);
9176           else
9177             vectFMTSNodes.push_back(*it);
9178         }
9179       else
9180         vectFMTSNotNodes.push_back(*it);
9181     }
9182   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
9183   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
9184   ret=retCell;
9185   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
9186     {
9187       i=0;
9188       bool isFetched(false);
9189       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
9190         {
9191           if((*it0).empty())
9192             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
9193           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
9194             { ret[i].push_back(*it2); isFetched=true; }
9195         }
9196       if(!isFetched)
9197         {
9198           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
9199           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
9200           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
9201         }
9202     }
9203   fsc=cmps;
9204   return ret;
9205 }
9206
9207 /*!
9208  * 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.
9209  * \param [out] cmps - same size than the returned vector.
9210  */
9211 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
9212 {
9213   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9214   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9215   while(!lstFMTS.empty())
9216     {
9217       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9218       MEDFileAnyTypeFieldMultiTS *ref(*it);
9219       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9220       elt.push_back(ref); it=lstFMTS.erase(it);
9221       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
9222       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
9223       while(it!=lstFMTS.end())
9224         {
9225           MEDFileAnyTypeFieldMultiTS *curIt(*it);
9226           if(cmp->isEqual(curIt))
9227             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9228           else
9229             it++;
9230         }
9231       ret.push_back(elt); cmps.push_back(cmp);
9232     }
9233   return ret;
9234 }
9235
9236 /*!
9237  * 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.
9238  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
9239  *
9240  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
9241  * \throw If \a f0 or \a f1 change of spatial discretization along time.
9242  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
9243  * \thorw If \a f0 and \a f1 do not have the same times steps.
9244  * \throw If mesh is null.
9245  * \throw If \a f0 or \a f1 is null.
9246  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
9247  */
9248 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
9249 {
9250   if(!mesh)
9251     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
9252   if(!f0 || !f1)
9253     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
9254   if(f0->getMeshName()!=mesh->getName())
9255     {
9256       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9257       throw INTERP_KERNEL::Exception(oss.str());
9258     }
9259   if(f1->getMeshName()!=mesh->getName())
9260     {
9261       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9262       throw INTERP_KERNEL::Exception(oss.str());
9263     }
9264   int nts=f0->getNumberOfTS();
9265   if(nts!=f1->getNumberOfTS())
9266     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
9267   if(nts==0)
9268     return nts;
9269   for(int i=0;i<nts;i++)
9270     {
9271       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
9272       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
9273       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
9274       if(tofs0.size()!=1 || tofs1.size()!=1)
9275         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
9276       if(i!=0)
9277         {
9278           if(tof0!=tofs0[0] || tof1!=tofs1[0])
9279             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
9280         }
9281       else
9282         { tof0=tofs0[0]; tof1=tofs1[0]; }
9283       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9284         {
9285           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() << ") !";
9286           throw INTERP_KERNEL::Exception(oss.str());
9287         }
9288       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9289         {
9290           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() << ") !";
9291           throw INTERP_KERNEL::Exception(oss.str());
9292         }
9293       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9294         {
9295           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() << ") !";
9296           throw INTERP_KERNEL::Exception(oss.str());
9297         }
9298     }
9299   return nts;
9300 }
9301
9302 /*!
9303  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9304  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9305  *
9306  * \return A new object that the caller is responsible to deallocate.
9307  */
9308 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9309 {
9310   if(!mm)
9311     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9312   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9313   int nbTS(getNumberOfTS());
9314   for(int i=0;i<nbTS;i++)
9315     {
9316       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9317       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9318       fmtsOut->pushBackTimeStep(f1tsOut);
9319     }
9320   return fmtsOut.retn();
9321 }
9322
9323 template<class T>
9324 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9325 {
9326   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9327   if(f1tss.empty())
9328     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9329   std::size_t sz(f1tss.size()),i(0);
9330   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9331   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9332     {
9333       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9334       if(!elt)
9335         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9336       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9337     }
9338   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9339   if(!retc)
9340     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9341   retc->aggregate(f1tsw,dts);
9342   ret->setDtUnit(f1tss[0]->getDtUnit());
9343   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9344 }
9345
9346 template<class T>
9347 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9348 {
9349   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9350   if(fmtss.empty())
9351     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9352   std::size_t sz(fmtss.size());
9353   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9354     {
9355       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9356       if(!elt)
9357         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9358     }
9359   int nbTS(fmtss[0]->getNumberOfTS());
9360   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9361     if((*it)->getNumberOfTS()!=nbTS)
9362       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9363   for(int iterTS=0;iterTS<nbTS;iterTS++)
9364     {
9365       std::size_t i(0);
9366       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9367       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9368       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9369         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9370       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9371       ret->pushBackTimeStep(f1ts);
9372       ret->setDtUnit(f1ts->getDtUnit());
9373     }
9374   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9375 }
9376
9377 /*!
9378  * \a dts and \a ftmss are expected to have same size.
9379  */
9380 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9381 {
9382   if(fmtss.empty())
9383     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9384   std::size_t sz(fmtss.size());
9385   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9386   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9387   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9388     {
9389       if(!(*it))
9390         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9391       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9392       if(elt1)
9393         {
9394           fmtss1.push_back(elt1);
9395           continue;
9396         }
9397       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9398       if(elt2)
9399         {
9400           fmtss2.push_back(elt2);
9401           continue;
9402         }
9403       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9404     }
9405   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9406     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9407   if(fmtss1.size()==sz)
9408     return AggregateHelperFMTS<double>(fmtss1,dts);
9409   if(fmtss2.size()!=sz)
9410     return AggregateHelperFMTS<int>(fmtss2,dts);
9411   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9412 }
9413
9414 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9415 {
9416   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9417 }
9418
9419 //= MEDFileFieldMultiTS
9420
9421 /*!
9422  * Returns a new empty instance of MEDFileFieldMultiTS.
9423  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9424  *          is to delete this field using decrRef() as it is no more needed.
9425  */
9426 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9427 {
9428   return new MEDFileFieldMultiTS;
9429 }
9430
9431 /*!
9432  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9433  * that has been read from a specified MED file.
9434  *  \param [in] fileName - the name of the MED file to read.
9435  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9436  *          is to delete this field using decrRef() as it is no more needed.
9437  *  \throw If reading the file fails.
9438  */
9439 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9440 {
9441   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9442   return New(fid,loadAll);
9443 }
9444
9445 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9446 {
9447   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9448   ret->contentNotNull();//to check that content type matches with \a this type.
9449   return ret.retn();
9450 }
9451
9452 /*!
9453  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9454  * that has been read from a specified MED file.
9455  *  \param [in] fileName - the name of the MED file to read.
9456  *  \param [in] fieldName - the name of the field to read.
9457  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9458  *          is to delete this field using decrRef() as it is no more needed.
9459  *  \throw If reading the file fails.
9460  *  \throw If there is no field named \a fieldName in the file.
9461  */
9462 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9463 {
9464   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9465   return New(fid,fieldName,loadAll);
9466 }
9467
9468 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9469 {
9470   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9471   ret->contentNotNull();//to check that content type matches with \a this type.
9472   return ret.retn();
9473 }
9474
9475 /*!
9476  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9477  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9478  *
9479  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9480  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9481  * \warning this is a shallow copy constructor
9482  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9483  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9484  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9485  *          is to delete this field using decrRef() as it is no more needed.
9486  */
9487 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9488 {
9489   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9490 }
9491
9492 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9493 {
9494   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9495   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9496   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
9497   ret->contentNotNull();//to check that content type matches with \a this type.
9498   return ret.retn();
9499 }
9500
9501 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9502 {
9503   return new MEDFileFieldMultiTS(*this);
9504 }
9505
9506 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9507 {
9508   if(!f1ts)
9509     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9510   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9511   if(!f1tsC)
9512     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9513 }
9514
9515 /*!
9516  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9517  * following the given input policy.
9518  *
9519  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9520  *                            By default (true) the globals are deeply copied.
9521  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9522  */
9523 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9524 {
9525   MCAuto<MEDFileIntFieldMultiTS> ret;
9526   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9527   if(content)
9528     {
9529       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9530       if(!contc)
9531         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9532       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9533       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9534     }
9535   else
9536     ret=MEDFileIntFieldMultiTS::New();
9537   if(isDeepCpyGlobs)
9538     ret->deepCpyGlobs(*this);
9539   else
9540     ret->shallowCpyGlobs(*this);
9541   return ret.retn();
9542 }
9543
9544 /*!
9545  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9546  *  \param [in] pos - a time step id.
9547  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9548  *          delete this field using decrRef() as it is no more needed.
9549  *  \throw If \a pos is not a valid time step id.
9550  */
9551 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9552 {
9553   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9554   if(!item)
9555     {
9556       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9557       throw INTERP_KERNEL::Exception(oss.str());
9558     }
9559   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9560   if(itemC)
9561     {
9562       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9563       ret->shallowCpyGlobs(*this);
9564       return ret.retn();
9565     }
9566   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9567   throw INTERP_KERNEL::Exception(oss.str());
9568 }
9569
9570 /*!
9571  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9572  * mesh entities of a given dimension of the first mesh in MED file.
9573  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9574  *  \param [in] type - a spatial discretization of interest.
9575  *  \param [in] iteration - the iteration number of a required time step.
9576  *  \param [in] order - the iteration order number of required time step.
9577  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9578  *  \param [in] renumPol - specifies how to permute values of the result field according to
9579  *          the optional numbers of cells and nodes, if any. The valid values are
9580  *          - 0 - do not permute.
9581  *          - 1 - permute cells.
9582  *          - 2 - permute nodes.
9583  *          - 3 - permute cells and nodes.
9584  *
9585  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9586  *          caller is to delete this field using decrRef() as it is no more needed. 
9587  *  \throw If the MED file is not readable.
9588  *  \throw If there is no mesh in the MED file.
9589  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9590  *  \throw If no field values of the required parameters are available.
9591  */
9592 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9593 {
9594   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9595   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9596   if(!myF1TSC)
9597     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9598   MCAuto<DataArray> arrOut;
9599   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9600   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9601   return ret.retn();
9602 }
9603
9604 /*!
9605  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9606  * the top level cells of the first mesh in MED file.
9607  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9608  *  \param [in] type - a spatial discretization of interest.
9609  *  \param [in] iteration - the iteration number of a required time step.
9610  *  \param [in] order - the iteration order number of required time step.
9611  *  \param [in] renumPol - specifies how to permute values of the result field according to
9612  *          the optional numbers of cells and nodes, if any. The valid values are
9613  *          - 0 - do not permute.
9614  *          - 1 - permute cells.
9615  *          - 2 - permute nodes.
9616  *          - 3 - permute cells and nodes.
9617  *
9618  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9619  *          caller is to delete this field using decrRef() as it is no more needed. 
9620  *  \throw If the MED file is not readable.
9621  *  \throw If there is no mesh in the MED file.
9622  *  \throw If no field values of the required parameters are available.
9623  */
9624 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9625 {
9626   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9627   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9628   if(!myF1TSC)
9629     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9630   MCAuto<DataArray> arrOut;
9631   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9632   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9633   return ret.retn();
9634 }
9635
9636 /*!
9637  * 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
9638  * method should be called (getFieldOnMeshAtLevel for example).
9639  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9640  *
9641  * \param [in] iteration - the iteration number of a required time step.
9642  * \param [in] order - the iteration order number of required time step.
9643  * \param [in] mesh - the mesh the field is lying on
9644  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9645  *          caller is to delete this field using decrRef() as it is no more needed. 
9646  */
9647 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9648 {
9649   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9650   MCAuto<DataArray> arrOut;
9651   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9652   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9653   return ret.retn();
9654 }
9655
9656 /*!
9657  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9658  * a given support.
9659  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9660  *  \param [in] type - a spatial discretization of interest.
9661  *  \param [in] iteration - the iteration number of a required time step.
9662  *  \param [in] order - the iteration order number of required time step.
9663  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9664  *  \param [in] mesh - the supporting mesh.
9665  *  \param [in] renumPol - specifies how to permute values of the result field according to
9666  *          the optional numbers of cells and nodes, if any. The valid values are
9667  *          - 0 - do not permute.
9668  *          - 1 - permute cells.
9669  *          - 2 - permute nodes.
9670  *          - 3 - permute cells and nodes.
9671  *
9672  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9673  *          caller is to delete this field using decrRef() as it is no more needed. 
9674  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9675  *  \throw If no field of \a this is lying on \a mesh.
9676  *  \throw If no field values of the required parameters are available.
9677  */
9678 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9679 {
9680   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9681   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9682   if(!myF1TSC)
9683     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9684   MCAuto<DataArray> arrOut;
9685   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9686   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9687   return ret.retn();
9688 }
9689
9690 /*!
9691  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9692  * given support. 
9693  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9694  *  \param [in] type - a spatial discretization of the new field.
9695  *  \param [in] iteration - the iteration number of a required time step.
9696  *  \param [in] order - the iteration order number of required time step.
9697  *  \param [in] mesh - the supporting mesh.
9698  *  \param [in] renumPol - specifies how to permute values of the result field according to
9699  *          the optional numbers of cells and nodes, if any. The valid values are
9700  *          - 0 - do not permute.
9701  *          - 1 - permute cells.
9702  *          - 2 - permute nodes.
9703  *          - 3 - permute cells and nodes.
9704  *
9705  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9706  *          caller is to delete this field using decrRef() as it is no more needed. 
9707  *  \throw If no field of \a this is lying on \a mesh.
9708  *  \throw If no field values of the required parameters are available.
9709  */
9710 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9711 {
9712   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9713   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9714   if(!myF1TSC)
9715     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9716   MCAuto<DataArray> arrOut;
9717   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9718   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9719   return ret.retn();
9720 }
9721
9722 /*!
9723  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9724  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9725  * This method is useful for MED2 file format when field on different mesh was autorized.
9726  */
9727 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9728 {
9729   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9730   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9731   if(!myF1TSC)
9732     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9733   MCAuto<DataArray> arrOut;
9734   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9735   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9736   return ret.retn();
9737 }
9738
9739 /*!
9740  * Returns values and a profile of the field of a given type, of a given time step,
9741  * lying on a given support.
9742  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9743  *  \param [in] type - a spatial discretization of the field.
9744  *  \param [in] iteration - the iteration number of a required time step.
9745  *  \param [in] order - the iteration order number of required time step.
9746  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9747  *  \param [in] mesh - the supporting mesh.
9748  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9749  *          field of interest lies on. If the field lies on all entities of the given
9750  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9751  *          using decrRef() as it is no more needed.  
9752  *  \param [in] glob - the global data storing profiles and localization.
9753  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9754  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9755  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9756  *  \throw If no field of \a this is lying on \a mesh.
9757  *  \throw If no field values of the required parameters are available.
9758  */
9759 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9760 {
9761   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9762   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9763   if(!myF1TSC)
9764     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9765   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9766   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9767 }
9768
9769 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9770 {
9771   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9772   if(!pt)
9773     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9774   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9775   if(!ret)
9776     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 !");
9777   return ret;
9778 }
9779
9780 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9781 {
9782   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9783   if(!pt)
9784     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9785   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9786   if(!ret)
9787     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 !");
9788   return ret;
9789 }
9790
9791 /*!
9792  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9793  * the given field is checked if its elements are sorted suitable for writing to MED file
9794  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9795  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9796  *  \param [in] field - the field to add to \a this.
9797  *  \throw If the name of \a field is empty.
9798  *  \throw If the data array of \a field is not set.
9799  *  \throw If existing time steps have different name or number of components than \a field.
9800  *  \throw If the underlying mesh of \a field has no name.
9801  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9802  */
9803 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9804 {
9805   const DataArrayDouble *arr=0;
9806   if(field)
9807     arr=field->getArray();
9808   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9809 }
9810
9811 /*!
9812  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9813  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9814  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9815  * and \a profile.
9816  *
9817  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9818  * A new profile is added only if no equal profile is missing.
9819  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9820  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9821  *  \param [in] mesh - the supporting mesh of \a field.
9822  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9823  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9824  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9825  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9826  *  \throw If the data array of \a field is not set.
9827  *  \throw If the data array of \a this is already allocated but has different number of
9828  *         components than \a field.
9829  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9830  *  \sa setFieldNoProfileSBT()
9831  */
9832 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9833 {
9834   const DataArrayDouble *arr=0;
9835   if(field)
9836     arr=field->getArray();
9837   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9838 }
9839
9840 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9841 {
9842   _content=new MEDFileFieldMultiTSWithoutSDA;
9843 }
9844
9845 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
9846 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
9847 {
9848 }
9849 catch(INTERP_KERNEL::Exception& e)
9850 { throw e; }
9851
9852 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9853 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
9854 {
9855 }
9856 catch(INTERP_KERNEL::Exception& e)
9857 { throw e; }
9858
9859 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9860 {
9861 }
9862
9863 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
9864 {
9865   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9866 }
9867
9868 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9869 {
9870   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9871 }
9872
9873 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9874 {
9875   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9876 }
9877
9878 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
9879 {
9880   return MEDFileFieldMultiTS::New();
9881 }
9882
9883 //= MEDFileAnyTypeFieldMultiTSIterator
9884
9885 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9886 {
9887   if(fmts)
9888     {
9889       fmts->incrRef();
9890       _nb_iter=fmts->getNumberOfTS();
9891     }
9892 }
9893
9894 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9895 {
9896 }
9897
9898 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9899 {
9900   if(_iter_id<_nb_iter)
9901     {
9902       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9903       if(fmts)
9904         return fmts->getTimeStepAtPos(_iter_id++);
9905       else
9906         return 0;
9907     }
9908   else
9909     return 0;
9910 }
9911
9912 //= MEDFileIntFieldMultiTS
9913
9914 /*!
9915  * Returns a new empty instance of MEDFileFieldMultiTS.
9916  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9917  *          is to delete this field using decrRef() as it is no more needed.
9918  */
9919 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9920 {
9921   return new MEDFileIntFieldMultiTS;
9922 }
9923
9924 /*!
9925  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9926  * that has been read from a specified MED file.
9927  *  \param [in] fileName - the name of the MED file to read.
9928  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9929  *          is to delete this field using decrRef() as it is no more needed.
9930  *  \throw If reading the file fails.
9931  */
9932 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9933 {
9934   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9935   return New(fid,loadAll);
9936 }
9937
9938 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
9939 {
9940   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
9941   ret->contentNotNull();//to check that content type matches with \a this type.
9942   return ret.retn();
9943 }
9944
9945 /*!
9946  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9947  * that has been read from a specified MED file.
9948  *  \param [in] fileName - the name of the MED file to read.
9949  *  \param [in] fieldName - the name of the field to read.
9950  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9951  *          is to delete this field using decrRef() as it is no more needed.
9952  *  \throw If reading the file fails.
9953  *  \throw If there is no field named \a fieldName in the file.
9954  */
9955 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9956 {
9957   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9958   return New(fid,fieldName,loadAll);
9959 }
9960
9961 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9962 {
9963   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
9964   ret->contentNotNull();//to check that content type matches with \a this type.
9965   return ret.retn();
9966 }
9967
9968 /*!
9969  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9970  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9971  *
9972  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9973  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9974  * \warning this is a shallow copy constructor
9975  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9976  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9977  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9978  *          is to delete this field using decrRef() as it is no more needed.
9979  */
9980 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9981 {
9982   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9983 }
9984
9985 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9986 {
9987   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9988   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9989   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
9990   ret->contentNotNull();//to check that content type matches with \a this type.
9991   return ret.retn();
9992 }
9993
9994 /*!
9995  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9996  * following the given input policy.
9997  *
9998  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9999  *                            By default (true) the globals are deeply copied.
10000  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
10001  */
10002 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
10003 {
10004   MCAuto<MEDFileFieldMultiTS> ret;
10005   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
10006   if(content)
10007     {
10008       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
10009       if(!contc)
10010         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
10011       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
10012       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
10013     }
10014   else
10015     ret=MEDFileFieldMultiTS::New();
10016   if(isDeepCpyGlobs)
10017     ret->deepCpyGlobs(*this);
10018   else
10019     ret->shallowCpyGlobs(*this);
10020   return ret.retn();
10021 }
10022
10023 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
10024 {
10025   return new MEDFileIntFieldMultiTS(*this);
10026 }
10027
10028 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
10029 {
10030   if(!f1ts)
10031     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
10032   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
10033   if(!f1tsC)
10034     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
10035 }
10036
10037 /*!
10038  * 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
10039  * method should be called (getFieldOnMeshAtLevel for example).
10040  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
10041  *
10042  * \param [in] iteration - the iteration number of a required time step.
10043  * \param [in] order - the iteration order number of required time step.
10044  * \param [in] mesh - the mesh the field is lying on
10045  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
10046  *          caller is to delete this field using decrRef() as it is no more needed. 
10047  */
10048 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
10049 {
10050   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10051   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10052   if(!myF1TSC)
10053     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
10054   MCAuto<DataArray> arrOut;
10055   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
10056   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
10057   return ret2.retn();
10058 }
10059
10060 /*!
10061  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10062  * mesh entities of a given dimension of the first mesh in MED file.
10063  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10064  *  \param [in] type - a spatial discretization of interest.
10065  *  \param [in] iteration - the iteration number of a required time step.
10066  *  \param [in] order - the iteration order number of required time step.
10067  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10068  *  \param [in] renumPol - specifies how to permute values of the result field according to
10069  *          the optional numbers of cells and nodes, if any. The valid values are
10070  *          - 0 - do not permute.
10071  *          - 1 - permute cells.
10072  *          - 2 - permute nodes.
10073  *          - 3 - permute cells and nodes.
10074  *
10075  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10076  *          caller is to delete this field using decrRef() as it is no more needed. 
10077  *  \throw If the MED file is not readable.
10078  *  \throw If there is no mesh in the MED file.
10079  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10080  *  \throw If no field values of the required parameters are available.
10081  */
10082 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
10083 {
10084   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10085   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10086   if(!myF1TSC)
10087     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
10088   MCAuto<DataArray> arr;
10089   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
10090   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10091   return ret2.retn();
10092 }
10093
10094 /*!
10095  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10096  * the top level cells of the first mesh in MED file.
10097  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10098  *  \param [in] type - a spatial discretization of interest.
10099  *  \param [in] iteration - the iteration number of a required time step.
10100  *  \param [in] order - the iteration order number of required time step.
10101  *  \param [in] renumPol - specifies how to permute values of the result field according to
10102  *          the optional numbers of cells and nodes, if any. The valid values are
10103  *          - 0 - do not permute.
10104  *          - 1 - permute cells.
10105  *          - 2 - permute nodes.
10106  *          - 3 - permute cells and nodes.
10107  *
10108  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10109  *          caller is to delete this field using decrRef() as it is no more needed. 
10110  *  \throw If the MED file is not readable.
10111  *  \throw If there is no mesh in the MED file.
10112  *  \throw If no field values of the required parameters are available.
10113  */
10114 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
10115 {
10116   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10117   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10118   if(!myF1TSC)
10119     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
10120   MCAuto<DataArray> arr;
10121   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
10122   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10123   return ret2.retn();
10124 }
10125
10126 /*!
10127  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10128  * a given support.
10129  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10130  *  \param [in] type - a spatial discretization of interest.
10131  *  \param [in] iteration - the iteration number of a required time step.
10132  *  \param [in] order - the iteration order number of required time step.
10133  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10134  *  \param [in] mesh - the supporting mesh.
10135  *  \param [in] renumPol - specifies how to permute values of the result field according to
10136  *          the optional numbers of cells and nodes, if any. The valid values are
10137  *          - 0 - do not permute.
10138  *          - 1 - permute cells.
10139  *          - 2 - permute nodes.
10140  *          - 3 - permute cells and nodes.
10141  *
10142  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10143  *          caller is to delete this field using decrRef() as it is no more needed. 
10144  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10145  *  \throw If no field of \a this is lying on \a mesh.
10146  *  \throw If no field values of the required parameters are available.
10147  */
10148 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10149 {
10150   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10151   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10152   if(!myF1TSC)
10153     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10154   MCAuto<DataArray> arr;
10155   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
10156   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10157   return ret2.retn();
10158 }
10159
10160 /*!
10161  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
10162  * given support. 
10163  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10164  *  \param [in] type - a spatial discretization of the new field.
10165  *  \param [in] iteration - the iteration number of a required time step.
10166  *  \param [in] order - the iteration order number of required time step.
10167  *  \param [in] mesh - the supporting mesh.
10168  *  \param [out] arrOut - the DataArrayInt containing values of field.
10169  *  \param [in] renumPol - specifies how to permute values of the result field according to
10170  *          the optional numbers of cells and nodes, if any. The valid values are
10171  *          - 0 - do not permute.
10172  *          - 1 - permute cells.
10173  *          - 2 - permute nodes.
10174  *          - 3 - permute cells and nodes.
10175  *
10176  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10177  *          caller is to delete this field using decrRef() as it is no more needed. 
10178  *  \throw If no field of \a this is lying on \a mesh.
10179  *  \throw If no field values of the required parameters are available.
10180  */
10181 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10182 {
10183   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10184   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10185   if(!myF1TSC)
10186     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10187   MCAuto<DataArray> arr;
10188   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
10189   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10190   return ret2.retn();
10191 }
10192
10193 /*!
10194  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
10195  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10196  * This method is useful for MED2 file format when field on different mesh was autorized.
10197  */
10198 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
10199 {
10200   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10201   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10202   if(!myF1TSC)
10203     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10204   MCAuto<DataArray> arr;
10205   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
10206   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10207   return ret2.retn();
10208 }
10209
10210 /*!
10211  * Returns values and a profile of the field of a given type, of a given time step,
10212  * lying on a given support.
10213  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10214  *  \param [in] type - a spatial discretization of the field.
10215  *  \param [in] iteration - the iteration number of a required time step.
10216  *  \param [in] order - the iteration order number of required time step.
10217  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10218  *  \param [in] mesh - the supporting mesh.
10219  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10220  *          field of interest lies on. If the field lies on all entities of the given
10221  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10222  *          using decrRef() as it is no more needed.  
10223  *  \param [in] glob - the global data storing profiles and localization.
10224  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
10225  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10226  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10227  *  \throw If no field of \a this is lying on \a mesh.
10228  *  \throw If no field values of the required parameters are available.
10229  */
10230 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10231 {
10232   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10233   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
10234   if(!myF1TSC)
10235     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
10236   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10237   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
10238 }
10239
10240 /*!
10241  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
10242  *  \param [in] pos - a time step id.
10243  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
10244  *          delete this field using decrRef() as it is no more needed.
10245  *  \throw If \a pos is not a valid time step id.
10246  */
10247 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
10248 {
10249   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
10250   if(!item)
10251     {
10252       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
10253       throw INTERP_KERNEL::Exception(oss.str());
10254     }
10255   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
10256   if(itemC)
10257     {
10258       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
10259       ret->shallowCpyGlobs(*this);
10260       return ret.retn();
10261     }
10262   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
10263   throw INTERP_KERNEL::Exception(oss.str());
10264 }
10265
10266 /*!
10267  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
10268  * the given field is checked if its elements are sorted suitable for writing to MED file
10269  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10270  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10271  *  \param [in] field - the field to add to \a this.
10272  *  \throw If the name of \a field is empty.
10273  *  \throw If the data array of \a field is not set.
10274  *  \throw If existing time steps have different name or number of components than \a field.
10275  *  \throw If the underlying mesh of \a field has no name.
10276  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10277  */
10278 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
10279 {
10280   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10281   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
10282 }
10283
10284 /*!
10285  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10286  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10287  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10288  * and \a profile.
10289  *
10290  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10291  * A new profile is added only if no equal profile is missing.
10292  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10293  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10294  *  \param [in] arrOfVals - the values of the field \a field used.
10295  *  \param [in] mesh - the supporting mesh of \a field.
10296  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10297  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10298  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10299  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10300  *  \throw If the data array of \a field is not set.
10301  *  \throw If the data array of \a this is already allocated but has different number of
10302  *         components than \a field.
10303  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10304  *  \sa setFieldNoProfileSBT()
10305  */
10306 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10307 {
10308   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10309   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10310 }
10311
10312 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10313 {
10314   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10315   if(!pt)
10316     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10317   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10318   if(!ret)
10319     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 !");
10320   return ret;
10321 }
10322
10323 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10324 {
10325   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10326   if(!pt)
10327     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10328   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10329   if(!ret)
10330     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 !");
10331   return ret;
10332 }
10333
10334 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10335 {
10336   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10337 }
10338
10339 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10340 {
10341 }
10342
10343 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10344 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10345 {
10346 }
10347 catch(INTERP_KERNEL::Exception& e)
10348 { throw e; }
10349
10350 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10351 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10352 {
10353 }
10354 catch(INTERP_KERNEL::Exception& e)
10355 { throw e; }
10356
10357 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10358 {
10359   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10360 }
10361
10362 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10363 {
10364   return MEDFileIntFieldMultiTS::New();
10365 }
10366
10367 //= MEDFileFields
10368
10369 MEDFileFields *MEDFileFields::New()
10370 {
10371   return new MEDFileFields;
10372 }
10373
10374 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10375 {
10376   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10377   return New(fid,loadAll);
10378 }
10379
10380 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
10381 {
10382   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10383   return NewWithDynGT(fid,se,loadAll);
10384 }
10385
10386 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
10387 {
10388   if(!se)
10389     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
10390   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
10391   return new MEDFileFields(fid,loadAll,0,entities);
10392 }
10393
10394 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10395 {
10396   return new MEDFileFields(fid,loadAll,0,0);
10397 }
10398
10399 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10400 {
10401   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10402   return new MEDFileFields(fid,loadAll,ms,0);
10403 }
10404
10405 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10406 {
10407   MEDFileUtilities::CheckFileForRead(fileName);
10408   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10409   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10410   return new MEDFileFields(fid,loadAll,0,ent);
10411 }
10412
10413 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10414 {
10415   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10416   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10417   return ret;
10418 }
10419
10420 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10421 {
10422   std::vector<const BigMemoryObject *> ret;
10423   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10424     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10425   return ret;
10426 }
10427
10428 MEDFileFields *MEDFileFields::deepCopy() const
10429 {
10430   MCAuto<MEDFileFields> ret(shallowCpy());
10431   std::size_t i(0);
10432   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10433     {
10434       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10435         ret->_fields[i]=(*it)->deepCopy();
10436     }
10437   ret->deepCpyGlobs(*this);
10438   return ret.retn();
10439 }
10440
10441 MEDFileFields *MEDFileFields::shallowCpy() const
10442 {
10443   return new MEDFileFields(*this);
10444 }
10445
10446 /*!
10447  * 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
10448  * 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.
10449  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10450  *
10451  * \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.
10452  * \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.
10453  * 
10454  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10455  */
10456 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10457 {
10458   std::set< std::pair<int,int> > s;
10459   bool firstShot=true;
10460   areThereSomeForgottenTS=false;
10461   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10462     {
10463       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10464         continue;
10465       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10466       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10467       if(firstShot)
10468         { s=s1; firstShot=false; }
10469       else
10470         {
10471           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10472           if(s!=s2)
10473             areThereSomeForgottenTS=true;
10474           s=s2;
10475         }
10476     }
10477   std::vector< std::pair<int,int> > ret;
10478   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10479   return ret;
10480 }
10481
10482 int MEDFileFields::getNumberOfFields() const
10483 {
10484   return _fields.size();
10485 }
10486
10487 std::vector<std::string> MEDFileFields::getFieldsNames() const
10488 {
10489   std::vector<std::string> ret(_fields.size());
10490   int i(0);
10491   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10492     {
10493       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10494       if(f)
10495         {
10496           ret[i]=f->getName();
10497         }
10498       else
10499         {
10500           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10501           throw INTERP_KERNEL::Exception(oss.str());
10502         }
10503     }
10504   return ret;
10505 }
10506
10507 std::vector<std::string> MEDFileFields::getMeshesNames() const
10508 {
10509   std::vector<std::string> ret;
10510   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10511     {
10512       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10513       if(cur)
10514         ret.push_back(cur->getMeshName());
10515     }
10516   return ret;
10517 }
10518
10519 std::string MEDFileFields::simpleRepr() const
10520 {
10521   std::ostringstream oss;
10522   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10523   simpleRepr(0,oss);
10524   return oss.str();
10525 }
10526
10527 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10528 {
10529   int nbOfFields(getNumberOfFields());
10530   std::string startLine(bkOffset,' ');
10531   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10532   int i=0;
10533   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10534     {
10535       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10536       if(cur)
10537         {
10538           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10539         }
10540       else
10541         {
10542           oss << startLine << "  - not defined !" << std::endl;
10543         }
10544     }
10545   i=0;
10546   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10547     {
10548       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10549       std::string chapter(17,'0'+i);
10550       oss << startLine << chapter << std::endl;
10551       if(cur)
10552         {
10553           cur->simpleRepr(bkOffset+2,oss,i);
10554         }
10555       else
10556         {
10557           oss << startLine << "  - not defined !" << std::endl;
10558         }
10559       oss << startLine << chapter << std::endl;
10560     }
10561   simpleReprGlobs(oss);
10562 }
10563
10564 MEDFileFields::MEDFileFields()
10565 {
10566 }
10567
10568 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10569 try:MEDFileFieldGlobsReal(fid)
10570 {
10571   int nbFields(MEDnField(fid));
10572   _fields.resize(nbFields);
10573   med_field_type typcha;
10574   for(int i=0;i<nbFields;i++)
10575     {
10576       std::vector<std::string> infos;
10577       std::string fieldName,dtunit;
10578       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit));
10579       switch(typcha)
10580       {
10581         case MED_FLOAT64:
10582           {
10583             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10584             break;
10585           }
10586         case MED_INT32:
10587           {
10588             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10589             break;
10590           }
10591         default:
10592           {
10593             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] !";
10594             throw INTERP_KERNEL::Exception(oss.str());
10595           }
10596       }
10597     }
10598   loadAllGlobals(fid);
10599 }
10600 catch(INTERP_KERNEL::Exception& e)
10601 {
10602     throw e;
10603 }
10604
10605 void MEDFileFields::writeLL(med_idt fid) const
10606 {
10607   int i=0;
10608   writeGlobals(fid,*this);
10609   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10610     {
10611       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10612       if(!elt)
10613         {
10614           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10615           throw INTERP_KERNEL::Exception(oss.str());
10616         }
10617       elt->writeLL(fid,*this);
10618     }
10619 }
10620
10621 /*!
10622  * This method alloc the arrays and load potentially huge arrays contained in this field.
10623  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10624  * This method can be also called to refresh or reinit values from a file.
10625  * 
10626  * \throw If the fileName is not set or points to a non readable MED file.
10627  */
10628 void MEDFileFields::loadArrays()
10629 {
10630   if(getFileName().empty())
10631     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10632   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10633   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10634     {
10635       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10636       if(elt)
10637         elt->loadBigArraysRecursively(fid,*elt);
10638     }
10639 }
10640
10641 /*!
10642  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10643  * But once data loaded once, this method does nothing.
10644  * 
10645  * \throw If the fileName is not set or points to a non readable MED file.
10646  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10647  */
10648 void MEDFileFields::loadArraysIfNecessary()
10649 {
10650   if(!getFileName().empty())
10651     {
10652       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10653       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10654         {
10655           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10656           if(elt)
10657             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10658         }
10659     }
10660 }
10661
10662 /*!
10663  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10664  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10665  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10666  * 
10667  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10668  */
10669 void MEDFileFields::unloadArrays()
10670 {
10671   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10672     {
10673       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10674       if(elt)
10675         elt->unloadArrays();
10676     }
10677 }
10678
10679 /*!
10680  * 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.
10681  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10682  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10683  * 
10684  * \sa MEDFileFields::loadArraysIfNecessary
10685  */
10686 void MEDFileFields::unloadArraysWithoutDataLoss()
10687 {
10688   if(!getFileName().empty())
10689     unloadArrays();
10690 }
10691
10692 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10693 {
10694   std::vector<std::string> ret;
10695   std::set<std::string> ret2;
10696   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10697     {
10698       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10699       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10700         if(ret2.find(*it2)==ret2.end())
10701           {
10702             ret.push_back(*it2);
10703             ret2.insert(*it2);
10704           }
10705     }
10706   return ret;
10707 }
10708
10709 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10710 {
10711   std::vector<std::string> ret;
10712   std::set<std::string> ret2;
10713   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10714     {
10715       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10716       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10717         if(ret2.find(*it2)==ret2.end())
10718           {
10719             ret.push_back(*it2);
10720             ret2.insert(*it2);
10721           }
10722     }
10723   return ret;
10724 }
10725
10726 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10727 {
10728   std::vector<std::string> ret;
10729   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10730     {
10731       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
10732       ret.insert(ret.end(),tmp.begin(),tmp.end());
10733     }
10734   return ret;
10735 }
10736
10737 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10738 {
10739   std::vector<std::string> ret;
10740   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10741     {
10742       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10743       ret.insert(ret.end(),tmp.begin(),tmp.end());
10744     }
10745   return ret;
10746 }
10747
10748 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10749 {
10750   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10751     (*it)->changePflsRefsNamesGen2(mapOfModif);
10752 }
10753
10754 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10755 {
10756   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10757     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10758 }
10759
10760 void MEDFileFields::resize(int newSize)
10761 {
10762   _fields.resize(newSize);
10763 }
10764
10765 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10766 {
10767   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10768     pushField(*it);
10769 }
10770
10771 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10772 {
10773   if(!field)
10774     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10775   _fields.push_back(field->getContent());
10776   appendGlobs(*field,1e-12);
10777 }
10778
10779 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10780 {
10781   if(!field)
10782     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10783   if(i>=(int)_fields.size())
10784     _fields.resize(i+1);
10785   _fields[i]=field->getContent();
10786   appendGlobs(*field,1e-12);
10787 }
10788
10789 void MEDFileFields::destroyFieldAtPos(int i)
10790 {
10791   destroyFieldsAtPos(&i,&i+1);
10792 }
10793
10794 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10795 {
10796   std::vector<bool> b(_fields.size(),true);
10797   for(const int *i=startIds;i!=endIds;i++)
10798     {
10799       if(*i<0 || *i>=(int)_fields.size())
10800         {
10801           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10802           throw INTERP_KERNEL::Exception(oss.str());
10803         }
10804       b[*i]=false;
10805     }
10806   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10807   std::size_t j=0;
10808   for(std::size_t i=0;i<_fields.size();i++)
10809     if(b[i])
10810       fields[j++]=_fields[i];
10811   _fields=fields;
10812 }
10813
10814 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10815 {
10816   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10817   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
10818   std::vector<bool> b(_fields.size(),true);
10819   int k=bg;
10820   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10821     {
10822       if(k<0 || k>=(int)_fields.size())
10823         {
10824           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10825           throw INTERP_KERNEL::Exception(oss.str());
10826         }
10827       b[k]=false;
10828     }
10829   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10830   std::size_t j(0);
10831   for(std::size_t i=0;i<_fields.size();i++)
10832     if(b[i])
10833       fields[j++]=_fields[i];
10834   _fields=fields;
10835 }
10836
10837 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10838 {
10839   bool ret(false);
10840   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10841     {
10842       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10843       if(cur)
10844         ret=cur->changeMeshNames(modifTab) || ret;
10845     }
10846   return ret;
10847 }
10848
10849 /*!
10850  * \param [in] meshName the name of the mesh that will be renumbered.
10851  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10852  *             This code corresponds to the distribution of types in the corresponding mesh.
10853  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10854  * \param [in] renumO2N the old to new renumber array.
10855  * \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 
10856  *         field in \a this.
10857  */
10858 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10859 {
10860   bool ret(false);
10861   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10862     {
10863       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10864       if(fmts)
10865         {
10866           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10867         }
10868     }
10869   return ret;
10870 }
10871
10872 /*!
10873  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10874  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10875  *
10876  * \return A new object that the caller is responsible to deallocate.
10877  */
10878 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10879 {
10880   if(!mm)
10881     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10882   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10883   int nbFields(getNumberOfFields());
10884   for(int i=0;i<nbFields;i++)
10885     {
10886       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
10887       if(!fmts)
10888         {
10889           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10890           throw INTERP_KERNEL::Exception(oss.str());
10891         }
10892       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10893       fsOut->pushField(fmtsOut);
10894     }
10895   return fsOut.retn();
10896 }
10897
10898 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10899 {
10900   if(i<0 || i>=(int)_fields.size())
10901     {
10902       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10903       throw INTERP_KERNEL::Exception(oss.str());
10904     }
10905   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10906   if(!fmts)
10907     return 0;
10908   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10909   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
10910   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
10911   if(fmtsC)
10912     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10913   else if(fmtsC2)
10914     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10915   else
10916     {
10917       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10918       throw INTERP_KERNEL::Exception(oss.str());
10919     }
10920   ret->shallowCpyGlobs(*this);
10921   return ret.retn();
10922 }
10923
10924 /*!
10925  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10926  * This method is accessible in python using __getitem__ with a list in input.
10927  * \return a new object that the caller should deal with.
10928  */
10929 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10930 {
10931   MCAuto<MEDFileFields> ret=shallowCpy();
10932   std::size_t sz=std::distance(startIds,endIds);
10933   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10934   int j=0;
10935   for(const int *i=startIds;i!=endIds;i++,j++)
10936     {
10937       if(*i<0 || *i>=(int)_fields.size())
10938         {
10939           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10940           throw INTERP_KERNEL::Exception(oss.str());
10941         }
10942       fields[j]=_fields[*i];
10943     }
10944   ret->_fields=fields;
10945   return ret.retn();
10946 }
10947
10948 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10949 {
10950   return getFieldAtPos(getPosFromFieldName(fieldName));
10951 }
10952
10953 /*!
10954  * This method removes, if any, fields in \a this having no time steps.
10955  * 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.
10956  * 
10957  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10958  */
10959 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10960 {
10961   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10962   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10963     {
10964       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10965       if(elt)
10966         {
10967           if(elt->getNumberOfTS()>0)
10968             newFields.push_back(*it);
10969         }
10970     }
10971   if(_fields.size()==newFields.size())
10972     return false;
10973   _fields=newFields;
10974   return true;
10975 }
10976
10977 /*!
10978  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10979  * This method can be seen as a filter applied on \a this, that returns an object containing
10980  * 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
10981  * shallow copied from \a this.
10982  * 
10983  * \param [in] meshName - the name of the mesh on w
10984  * \return a new object that the caller should deal with.
10985  */
10986 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10987 {
10988   MCAuto<MEDFileFields> ret(MEDFileFields::New());
10989   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10990     {
10991       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10992       if(!cur)
10993         continue;
10994       if(cur->getMeshName()==meshName)
10995         {
10996           cur->incrRef();
10997           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10998           ret->_fields.push_back(cur2);
10999         }
11000     }
11001   ret->shallowCpyOnlyUsedGlobs(*this);
11002   return ret.retn();
11003 }
11004
11005 /*!
11006  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
11007  * Input time steps are specified using a pair of integer (iteration, order).
11008  * 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,
11009  * but for each multitimestep only the time steps in \a timeSteps are kept.
11010  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
11011  * 
11012  * The returned object points to shallow copy of elements in \a this.
11013  * 
11014  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
11015  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
11016  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
11017  */
11018 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11019 {
11020   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11021   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11022     {
11023       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11024       if(!cur)
11025         continue;
11026       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
11027       ret->_fields.push_back(elt);
11028     }
11029   ret->shallowCpyOnlyUsedGlobs(*this);
11030   return ret.retn();
11031 }
11032
11033 /*!
11034  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
11035  */
11036 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11037 {
11038   MCAuto<MEDFileFields> ret=MEDFileFields::New();
11039   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11040     {
11041       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11042       if(!cur)
11043         continue;
11044       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
11045       if(elt->getNumberOfTS()!=0)
11046         ret->_fields.push_back(elt);
11047     }
11048   ret->shallowCpyOnlyUsedGlobs(*this);
11049   return ret.retn();
11050 }
11051
11052 bool MEDFileFields::presenceOfStructureElements() const
11053 {
11054   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11055     if((*it).isNotNull())
11056       if((*it)->presenceOfStructureElements())
11057         return true;
11058   return false;
11059 }
11060
11061 void MEDFileFields::killStructureElements()
11062 {
11063   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11064   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11065     if((*it).isNotNull())
11066       {
11067         if((*it)->presenceOfStructureElements())
11068           {
11069             if(!(*it)->onlyStructureElements())
11070               {
11071                 (*it)->killStructureElements();
11072                 ret.push_back(*it);
11073               }
11074           }
11075         else
11076           {
11077             ret.push_back(*it);
11078           }
11079       }
11080   _fields=ret;
11081 }
11082
11083 void MEDFileFields::keepOnlyStructureElements()
11084 {
11085   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11086   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11087     if((*it).isNotNull())
11088       {
11089         if((*it)->presenceOfStructureElements())
11090           {
11091             if(!(*it)->onlyStructureElements())
11092               (*it)->keepOnlyStructureElements();
11093             ret.push_back(*it);
11094           }
11095       }
11096   _fields=ret;
11097 }
11098   
11099 MCAuto<MEDFileFields> MEDFileFields::partOfThisOnStructureElements() const
11100 {
11101   MCAuto<MEDFileFields> ret(deepCopy());
11102   ret->keepOnlyStructureElements();
11103   return ret;
11104 }
11105
11106 MEDFileFieldsIterator *MEDFileFields::iterator()
11107 {
11108   return new MEDFileFieldsIterator(this);
11109 }
11110
11111 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
11112 {
11113   std::string tmp(fieldName);
11114   std::vector<std::string> poss;
11115   for(std::size_t i=0;i<_fields.size();i++)
11116     {
11117       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
11118       if(f)
11119         {
11120           std::string fname(f->getName());
11121           if(tmp==fname)
11122             return i;
11123           else
11124             poss.push_back(fname);
11125         }
11126     }
11127   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
11128   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
11129   oss << " !";
11130   throw INTERP_KERNEL::Exception(oss.str());
11131 }
11132
11133 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
11134 {
11135   if(fs)
11136     {
11137       fs->incrRef();
11138       _nb_iter=fs->getNumberOfFields();
11139     }
11140 }
11141
11142 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
11143 {
11144 }
11145
11146 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
11147 {
11148   if(_iter_id<_nb_iter)
11149     {
11150       MEDFileFields *fs(_fs);
11151       if(fs)
11152         return fs->getFieldAtPos(_iter_id++);
11153       else
11154         return 0;
11155     }
11156   else
11157     return 0;
11158 }