Salome HOME
Finished. But maybe we have to manage profile. Only sky is the limit
[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 void MEDFileFieldPerMeshPerTypeCommon::pushDiscretization(MEDFileFieldPerMeshPerTypePerDisc *disc)
1351 {
1352   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt;
1353   elt.takeRef(disc);
1354   _field_pm_pt_pd.push_back(elt);
1355 }
1356
1357 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1358 {
1359   return _father->getOrCreateAndGetArray();
1360 }
1361
1362 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1363 {
1364   const MEDFileFieldPerMesh *fath=_father;
1365   return fath->getOrCreateAndGetArray();
1366 }
1367
1368 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1369 {
1370   return _father->getInfo();
1371 }
1372
1373 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1374 {
1375   std::vector<std::string> ret;
1376   std::set<std::string> ret2;
1377   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1378     {
1379       std::string tmp=(*it1)->getProfile();
1380       if(!tmp.empty())
1381         if(ret2.find(tmp)==ret2.end())
1382           {
1383             ret.push_back(tmp);
1384             ret2.insert(tmp);
1385           }
1386     }
1387   return ret;
1388 }
1389
1390 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1391 {
1392   std::vector<std::string> ret;
1393   std::set<std::string> ret2;
1394   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1395     {
1396       std::string tmp=(*it1)->getLocalization();
1397       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1398         if(ret2.find(tmp)==ret2.end())
1399           {
1400             ret.push_back(tmp);
1401             ret2.insert(tmp);
1402           }
1403     }
1404   return ret;
1405 }
1406
1407 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1408 {
1409   std::vector<std::string> ret;
1410   std::set<std::string> ret2;
1411   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1412     {
1413       std::string tmp=(*it1)->getProfile();
1414       if(!tmp.empty())
1415         ret.push_back(tmp);
1416     }
1417   return ret;
1418 }
1419
1420 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1421 {
1422   std::vector<std::string> ret;
1423   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1424     {
1425       std::string tmp=(*it1)->getLocalization();
1426       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1427         ret.push_back(tmp);
1428     }
1429   return ret;
1430 }
1431
1432 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1433 {
1434   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1435     (*it1)->changePflsRefsNamesGen(mapOfModif);
1436 }
1437
1438 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1439 {
1440   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1441     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1442 }
1443
1444 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1445 {
1446   if(_field_pm_pt_pd.empty())
1447     {
1448       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1449       throw INTERP_KERNEL::Exception(oss.str());
1450     }
1451   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1452     return _field_pm_pt_pd[locId];
1453   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1454   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1455   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1456   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1457 }
1458
1459 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1460 {
1461   if(_field_pm_pt_pd.empty())
1462     {
1463       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1464       throw INTERP_KERNEL::Exception(oss.str());
1465     }
1466   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1467     return _field_pm_pt_pd[locId];
1468   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1469   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1470   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1471   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1472 }
1473
1474 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1475 {
1476   int i=0;
1477   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1478     {
1479       (*it)->fillValues(i,startEntryId,entries);
1480     }
1481 }
1482
1483 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1484 {
1485   _field_pm_pt_pd=leaves;
1486   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1487     (*it)->setFather(this);
1488 }
1489
1490 /*!
1491  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1492  *  \param [out] its - list of pair (start,stop) kept
1493  *  \return bool - false if the type of field \a tof is not contained in \a this.
1494  */
1495 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1496 {
1497   bool ret(false);
1498   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1499   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1500     if((*it)->getType()==tof)
1501       {
1502         newPmPtPd.push_back(*it);
1503         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1504         (*it)->setNewStart(globalNum);
1505         globalNum=(*it)->getEnd();
1506         its.push_back(bgEnd);
1507         ret=true;
1508       }
1509   if(ret)
1510     _field_pm_pt_pd=newPmPtPd;
1511   return ret;
1512 }
1513
1514 /*!
1515  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1516  *  \param [out] its - list of pair (start,stop) kept
1517  *  \return bool - false if the type of field \a tof is not contained in \a this.
1518  */
1519 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1520 {
1521   if(_field_pm_pt_pd.size()<=idOfDisc)
1522     return false;
1523   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1524   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1525   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1526   elt->setNewStart(globalNum);
1527   globalNum=elt->getEnd();
1528   its.push_back(bgEnd);
1529   _field_pm_pt_pd=newPmPtPd;
1530   return true;
1531 }
1532
1533 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1534 {
1535   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1536     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1537 }
1538
1539 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1540 {
1541   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1542     (*it)->loadBigArray(fid,nasc);
1543 }
1544
1545 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1546 {
1547   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1548     {
1549       (*it)->copyOptionsFrom(*this);
1550       (*it)->writeLL(fid,nasc);
1551     }
1552 }
1553
1554 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1555 {
1556   switch(ikType)
1557   {
1558     case ON_CELLS:
1559       medfGeoType=typmai3[(int)ikGeoType];
1560       return MED_CELL;
1561     case ON_NODES:
1562       medfGeoType=MED_NONE;
1563       return MED_NODE;
1564     case ON_GAUSS_NE:
1565       medfGeoType=typmai3[(int)ikGeoType];
1566       return MED_NODE_ELEMENT;
1567     case ON_GAUSS_PT:
1568       medfGeoType=typmai3[(int)ikGeoType];
1569       return MED_CELL;
1570     default:
1571       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1572   }
1573   return MED_UNDEF_ENTITY_TYPE;
1574 }
1575
1576 //////////////////////////////////////////////////
1577
1578 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1579 {
1580   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1581 }
1582
1583 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1584 {
1585   return new MEDFileFieldPerMeshPerType(fath,geoType);
1586 }
1587
1588 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1589 {
1590   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1591   ret->setFather(father);
1592   ret->deepCopyElements();
1593   return ret.retn();
1594 }
1595
1596 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
1597 {
1598   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1599     {
1600       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1601       if(meshDim!=(int)cm.getDimension())
1602         return ;
1603     }
1604   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1605     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1606 }
1607
1608 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1609 {
1610   return _geo_type;
1611 }
1612
1613 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1614 {
1615   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1616 }
1617
1618 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1619 {
1620   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1621   int curDim((int)cm.getDimension());
1622   dim=std::max(dim,curDim);
1623 }
1624
1625 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1626 {
1627   const char startLine[]="  ## ";
1628   std::string startLine2(bkOffset,' ');
1629   std::string startLine3(startLine2);
1630   startLine3+=startLine;
1631   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1632     {
1633       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1634       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1635     }
1636   else
1637     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1638   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1639   int i=0;
1640   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1641     {
1642       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1643       if(cur)
1644         cur->simpleRepr(bkOffset,oss,i);
1645       else
1646         {
1647           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1648         }
1649     }
1650 }
1651
1652 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1653 {
1654   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1655   return std::string(cm.getRepr());
1656 }
1657
1658 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1659 {
1660 }
1661
1662 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1663 {
1664   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1665   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1666   med_geometry_type mgeoti;
1667   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1668   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1669   _field_pm_pt_pd.resize(nbProfiles);
1670   for(int i=0;i<nbProfiles;i++)
1671     {
1672       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1673     }
1674   if(type==ON_CELLS)
1675     {
1676       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1677       for(int i=0;i<nbProfiles2;i++)
1678         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1679     }
1680 }
1681
1682 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)
1683 {
1684   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1685   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1686   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1687     {
1688       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1689         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1690     }
1691   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1692     {
1693       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1694       ret->_field_pm_pt_pd.push_back(agg);
1695     }
1696   return ret;
1697 }
1698
1699 //////////////////////////////////////////////////
1700
1701 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1702 {
1703   if(!entities)
1704     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1705   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1706   if(!entities2)
1707     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1708   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1709   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1710 }
1711
1712 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1713 {
1714   _se.takeRef(se);
1715   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1716   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1717   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1718   _field_pm_pt_pd.resize(nbProfiles);
1719   for(int i=0;i<nbProfiles;i++)
1720     {
1721       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1722     }
1723 }
1724
1725 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1726 {
1727   return _se->getDynGT();
1728 }
1729
1730 std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const
1731 {
1732   return _se->getName();
1733 }
1734
1735 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1736 {
1737   throw INTERP_KERNEL::Exception("not implemented yet !");
1738 }
1739
1740 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1741 {
1742   gt=getDynGT();
1743   ent=MED_STRUCT_ELEMENT;
1744 }
1745
1746 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1747 {
1748   throw INTERP_KERNEL::Exception("not implemented yet !");
1749 }
1750
1751 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1752 {
1753   const char startLine[]="  ## ";
1754   std::string startLine2(bkOffset,' ');
1755   std::string startLine3(startLine2);
1756   startLine3+=startLine;
1757   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1758   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1759   int i=0;
1760   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1761     {
1762       if((*it).isNotNull())
1763         (*it)->simpleRepr(bkOffset,oss,i);
1764       else
1765         {
1766           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1767         }
1768     }
1769 }
1770
1771 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1772 {
1773   throw INTERP_KERNEL::Exception("not implemented yet !");
1774 }
1775
1776 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1777 {
1778   MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1779   ret->setFather(father);
1780   ret->deepCopyElements();
1781   return ret.retn();
1782 }
1783
1784 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
1785 {
1786   throw INTERP_KERNEL::Exception("not implemented yet !");
1787 }
1788
1789 //////////////////////////////////////////////////
1790
1791 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1792 {
1793   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1794 }
1795
1796 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1797 {
1798   return new MEDFileFieldPerMesh(fath,mesh);
1799 }
1800
1801 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1802 {
1803   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1804 }
1805
1806 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1807 {
1808   std::vector<const BigMemoryObject *> ret;
1809   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1810     ret.push_back(*it);
1811   return ret;
1812 }
1813
1814 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1815 {
1816   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1817   ret->_father=father;
1818   std::size_t i=0;
1819   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1820     {
1821       if((*it).isNotNull())
1822         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1823     }
1824   return ret.retn();
1825 }
1826
1827 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1828 {
1829   std::string startLine(bkOffset,' ');
1830   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1831   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1832   int i=0;
1833   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1834     {
1835       if((*it).isNotNull())
1836         (*it)->simpleRepr(bkOffset,oss,i);
1837       else
1838         {
1839           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1840         }
1841     }
1842 }
1843
1844 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1845 {
1846   _mesh_name=mesh->getName();
1847   mesh->getTime(_mesh_iteration,_mesh_order);
1848 }
1849
1850 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1851 {
1852   int nbOfTypes=code.size()/3;
1853   int offset=0;
1854   for(int i=0;i<nbOfTypes;i++)
1855     {
1856       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1857       int nbOfCells=code[3*i+1];
1858       int pos=addNewEntryIfNecessary(type);
1859       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1860       offset+=nbOfCells;
1861     }
1862 }
1863
1864 /*!
1865  * This method is the most general one. No optimization is done here.
1866  * \param [in] multiTypePfl is the end user profile specified in high level API
1867  * \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].
1868  * \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.
1869  * \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.
1870  * \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.
1871  * \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.
1872  */
1873 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)
1874 {
1875   int nbOfTypes(code.size()/3);
1876   for(int i=0;i<nbOfTypes;i++)
1877     {
1878       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1879       int pos=addNewEntryIfNecessary(type);
1880       DataArrayInt *pfl=0;
1881       if(code[3*i+2]!=-1)
1882         pfl=idsPerType[code[3*i+2]];
1883       int nbOfTupes2=code2.size()/3;
1884       int found=0;
1885       for(;found<nbOfTupes2;found++)
1886         if(code[3*i]==code2[3*found])
1887           break;
1888       if(found==nbOfTupes2)
1889         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1890       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1891     }
1892 }
1893
1894 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1895 {
1896   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1897   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1898 }
1899
1900 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1901 {
1902   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1903   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1904 }
1905
1906 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1907 {
1908   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1909     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1910 }
1911
1912 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1913 {
1914   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1915     (*it)->loadBigArraysRecursively(fid,nasc);
1916 }
1917
1918 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1919 {
1920   int nbOfTypes=_field_pm_pt.size();
1921   for(int i=0;i<nbOfTypes;i++)
1922     {
1923       _field_pm_pt[i]->copyOptionsFrom(*this);
1924       _field_pm_pt[i]->writeLL(fid,nasc);
1925     }
1926 }
1927
1928 void MEDFileFieldPerMesh::getDimension(int& dim) const
1929 {
1930   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1931     (*it)->getDimension(dim);
1932 }
1933
1934 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
1935 {
1936   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1937     if(!(*it)->isUniqueLevel(dim))
1938       return false;
1939   return true;
1940 }
1941
1942 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1943 {
1944   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1945     (*it)->fillTypesOfFieldAvailable(types);
1946 }
1947
1948 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
1949 {
1950   int sz=_field_pm_pt.size();
1951   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1952   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1953   for(int i=0;i<sz;i++)
1954     {
1955       types[i]=_field_pm_pt[i]->getGeoType();
1956       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1957     }
1958   return ret;
1959 }
1960
1961 double MEDFileFieldPerMesh::getTime() const
1962 {
1963   int tmp1,tmp2;
1964   return _father->getTime(tmp1,tmp2);
1965 }
1966
1967 int MEDFileFieldPerMesh::getIteration() const
1968 {
1969   return _father->getIteration();
1970 }
1971
1972 int MEDFileFieldPerMesh::getOrder() const
1973 {
1974   return _father->getOrder();
1975 }
1976
1977 int MEDFileFieldPerMesh::getNumberOfComponents() const
1978 {
1979   return _father->getNumberOfComponents();
1980 }
1981
1982 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1983 {
1984   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1985     {
1986       if((*it).isNull())
1987         continue;
1988       if((*it)->presenceOfMultiDiscPerGeoType())
1989         return true;
1990     }
1991   return false;
1992 }
1993
1994 bool MEDFileFieldPerMesh::presenceOfStructureElements() 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 true;
2002       }
2003   return false;
2004 }
2005
2006 bool MEDFileFieldPerMesh::onlyStructureElements() const
2007 {
2008   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2009     if((*it).isNotNull())
2010       {
2011         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2012         if(!pt)
2013           return false;
2014       }
2015   return true;
2016 }
2017
2018 void MEDFileFieldPerMesh::killStructureElements()
2019 {
2020   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2021   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2022     {
2023       if((*it).isNotNull())
2024         {
2025           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2026           if(!pt)
2027             res.push_back(*it);
2028         }
2029     }
2030   _field_pm_pt=res;
2031 }
2032
2033 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2034 {
2035   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2036   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2037     {
2038       if((*it).isNotNull())
2039         {
2040           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2041           if(pt)
2042             res.push_back(*it);
2043         }
2044     }
2045   _field_pm_pt=res;
2046 }
2047
2048 void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName)
2049 {
2050   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2051   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2052     {
2053       if((*it).isNotNull())
2054         {
2055           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2056           if(!pt)
2057             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !");
2058           if(pt->getModelName()==seName)
2059             res.push_back(*it);
2060         }
2061     }
2062   _field_pm_pt=res;
2063 }
2064
2065 void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
2066 {
2067   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2068     {
2069       if((*it).isNotNull())
2070         {
2071           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2072           if(pt)
2073             {
2074               ps.push_back(std::pair<std::string,std::string>(getMeshName(),pt->getModelName()));
2075             }
2076           else
2077             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !");
2078         }
2079     }
2080 }
2081
2082 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2083 {
2084   if(!_father)
2085     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2086   return _father->getOrCreateAndGetArray();
2087 }
2088
2089 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2090 {
2091   if(!_father)
2092     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2093   return _father->getOrCreateAndGetArray();
2094 }
2095
2096 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2097 {
2098   return _father->getInfo();
2099 }
2100
2101 /*!
2102  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2103  * 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.
2104  * It returns 2 output vectors :
2105  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2106  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2107  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2108  */
2109 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)
2110 {
2111   int notNullPflsSz=0;
2112   int nbOfArrs=geoTypes.size();
2113   for(int i=0;i<nbOfArrs;i++)
2114     if(pfls[i])
2115       notNullPflsSz++;
2116   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2117   int nbOfDiffGeoTypes=geoTypes3.size();
2118   code.resize(3*nbOfDiffGeoTypes);
2119   notNullPfls.resize(notNullPflsSz);
2120   notNullPflsSz=0;
2121   int j=0;
2122   for(int i=0;i<nbOfDiffGeoTypes;i++)
2123     {
2124       int startZone=j;
2125       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2126       std::vector<const DataArrayInt *> notNullTmp;
2127       if(pfls[j])
2128         notNullTmp.push_back(pfls[j]);
2129       j++;
2130       for(;j<nbOfArrs;j++)
2131         if(geoTypes[j]==refType)
2132           {
2133             if(pfls[j])
2134               notNullTmp.push_back(pfls[j]);
2135           }
2136         else
2137           break;
2138       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2139       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2140       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2141       code[3*i]=(int)refType;
2142       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2143       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2144       if(notNullTmp.empty())
2145         code[3*i+2]=-1;
2146       else
2147         {
2148           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2149           code[3*i+2]=notNullPflsSz++;
2150         }
2151     }
2152 }
2153
2154 /*!
2155  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2156  */
2157 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)
2158 {
2159   int sz=dads.size();
2160   int ret=0;
2161   for(int i=0;i<sz;i++)
2162     {
2163       if(locs[i]==-1)
2164         {
2165           if(type!=ON_GAUSS_NE)
2166             ret+=dads[i].second-dads[i].first;
2167           else
2168             {
2169               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2170               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2171             }
2172         }
2173       else
2174         {
2175           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2176           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2177         }
2178     }
2179   return ret;
2180 }
2181
2182 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2183 {
2184   std::vector<std::string> ret;
2185   std::set<std::string> ret2;
2186   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2187     {
2188       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2189       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2190         if(ret2.find(*it2)==ret2.end())
2191           {
2192             ret.push_back(*it2);
2193             ret2.insert(*it2);
2194           }
2195     }
2196   return ret;
2197 }
2198
2199 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2200 {
2201   std::vector<std::string> ret;
2202   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2203     {
2204       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2205       ret.insert(ret.end(),tmp.begin(),tmp.end());
2206     }
2207   return ret;
2208 }
2209
2210 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2211 {
2212   std::vector<std::string> ret;
2213   std::set<std::string> ret2;
2214   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2215     {
2216       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2217       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2218         if(ret2.find(*it2)==ret2.end())
2219           {
2220             ret.push_back(*it2);
2221             ret2.insert(*it2);
2222           }
2223     }
2224   return ret;
2225 }
2226
2227 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2228 {
2229   std::vector<std::string> ret;
2230   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2231     {
2232       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2233       ret.insert(ret.end(),tmp.begin(),tmp.end());
2234     }
2235   return ret;
2236 }
2237
2238 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2239 {
2240   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2241     {
2242       if((*it).first==_mesh_name)
2243         {
2244           _mesh_name=(*it).second;
2245           return true;
2246         }
2247     }
2248   return false;
2249 }
2250
2251 void MEDFileFieldPerMesh::convertMedBallIntoClassic()
2252 {
2253   if(_field_pm_pt.size()!=1)
2254     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : Only managed for single mesh !");
2255   if(_field_pm_pt[0].isNull())
2256     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : null pointer !");
2257   MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<MEDFileFieldPerMeshPerTypeDyn *>((MEDFileFieldPerMeshPerTypeCommon *)_field_pm_pt[0]));
2258   if(!pt)
2259     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : this is expected to be marked as structure element !");
2260   if(pt->getNumberOfLoc()!=1)
2261     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : only one loc managed !");
2262   const MEDFileFieldPerMeshPerTypePerDisc *disc(pt->getLeafGivenLocId(0));
2263   if(!disc)
2264     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::convertMedBallIntoClassic : internal error !");
2265   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> disc2(MEDFileFieldPerMeshPerTypePerDisc::New(*disc));
2266   disc2->setType(ON_NODES);
2267   MCAuto<MEDFileFieldPerMeshPerType> pt2(MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR));
2268   disc2->setFather(pt2);
2269   pt2->setFather(this);
2270   pt2->pushDiscretization(disc2);
2271   _field_pm_pt[0]=DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(pt2);
2272 }
2273
2274 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2275                                                       MEDFileFieldGlobsReal& glob)
2276 {
2277   if(_mesh_name!=meshName)
2278     return false;
2279   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2280   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2281   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2282   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2283   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2284   getUndergroundDataArrayExt(entries);
2285   DataArray *arr0(getOrCreateAndGetArray());//tony
2286   if(!arr0)
2287     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2288   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2289   if(!arr0)
2290     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2291   int sz=0;
2292   if(!arr)
2293     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2294   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2295     {
2296       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2297         {
2298           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2299           sz+=(*it).second.second-(*it).second.first;
2300         }
2301       else
2302         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2303     }
2304   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2305   ////////////////////
2306   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2307   int *workI2=explicitIdsOldInMesh->getPointer();
2308   int sz1=0,sz2=0,sid=1;
2309   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2310   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2311   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2312     {
2313       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2314       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2315       int *workI=explicitIdsOldInArr->getPointer();
2316       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2317         {
2318           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2319           (*itL2)->setLocId(sz2);
2320           (*itL2)->_tmp_work1=(*itL2)->getStart();
2321           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2322         }
2323       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2324     }
2325   explicitIdsOldInMesh->reAlloc(sz2);
2326   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2327   ////////////////////
2328   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2329   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2330   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2331   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2332     {
2333       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2334       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2335       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2336     }
2337   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2338   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2339   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2340     {
2341       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2342       int newStart=elt->getLocId();
2343       elt->setLocId((*it)->getGeoType());
2344       elt->setNewStart(newStart);
2345       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2346       entriesKeptNew.push_back(elt);
2347       entriesKeptNew2.push_back(elt);
2348     }
2349   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2350   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2351   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2352   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2353   bool ret=false;
2354   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2355     {
2356       sid=0;
2357       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2358         {
2359           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2360           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2361           }*/
2362       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2363                                                             glob,arr2,otherEntriesNew) || ret;
2364     }
2365   if(!ret)
2366     return false;
2367   // Assign new dispatching
2368   assignNewLeaves(otherEntriesNew);
2369   arr->deepCopyFrom(*arr2);
2370   return true;
2371 }
2372
2373 /*!
2374  * \param [in,out] globalNum a global numbering counter for the renumbering.
2375  * \param [out] its - list of pair (start,stop) kept
2376  */
2377 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2378 {
2379   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2380   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2381     {
2382       std::vector< std::pair<int,int> > its2;
2383       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2384         {
2385           ret.push_back(*it);
2386           its.insert(its.end(),its2.begin(),its2.end());
2387         }
2388     }
2389   _field_pm_pt=ret;
2390 }
2391
2392 /*!
2393  * \param [in,out] globalNum a global numbering counter for the renumbering.
2394  * \param [out] its - list of pair (start,stop) kept
2395  */
2396 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2397 {
2398   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2399   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2400     {
2401       std::vector< std::pair<int,int> > its2;
2402       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2403         {
2404           ret.push_back(*it);
2405           its.insert(its.end(),its2.begin(),its2.end());
2406         }
2407     }
2408   _field_pm_pt=ret;
2409 }
2410
2411 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2412 {
2413   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2414   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2415     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2416   //
2417   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2418   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2419   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2420   for(;it1!=types.end();it1++,it2++)
2421     {
2422       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2423       elt->setLeaves((*it1).second);
2424       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2425       *it2=elt2;
2426     }
2427   _field_pm_pt=fieldPmPt;
2428 }
2429
2430 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2431 {
2432   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2433     (*it)->changePflsRefsNamesGen(mapOfModif);
2434 }
2435
2436 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2437 {
2438   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2439     (*it)->changeLocsRefsNamesGen(mapOfModif);
2440 }
2441
2442 /*!
2443  * \param [in] mesh is the whole mesh
2444  */
2445 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2446 {
2447   if(_field_pm_pt.empty())
2448     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2449   //
2450   std::vector< std::pair<int,int> > dads;
2451   std::vector<const DataArrayInt *> pfls;
2452   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2453   std::vector<int> locs,code;
2454   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2455   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2456     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2457   // Sort by types
2458   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2459   if(code.empty())
2460     {
2461       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2462       throw INTERP_KERNEL::Exception(oss.str());
2463     }
2464   //
2465   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2466   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2467   if(type!=ON_NODES)
2468     {
2469       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2470       if(!arr)
2471         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2472       else
2473         {
2474           MCAuto<DataArrayInt> arr2(arr);
2475           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2476         }
2477     }
2478   else
2479     {
2480       if(code.size()!=3)
2481         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2482       int nb=code[1];
2483       if(code[2]==-1)
2484         {
2485           if(nb!=mesh->getNumberOfNodes())
2486             {
2487               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2488               oss << " nodes in mesh !";
2489               throw INTERP_KERNEL::Exception(oss.str());
2490             }
2491           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2492         }
2493       else
2494         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2495     }
2496 }
2497
2498 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2499 {
2500   if(_field_pm_pt.empty())
2501     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2502   //
2503   std::vector<std::pair<int,int> > dads;
2504   std::vector<const DataArrayInt *> pfls;
2505   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2506   std::vector<int> locs,code;
2507   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2508   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2509     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2510   // Sort by types
2511   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2512   if(code.empty())
2513     {
2514       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2515       throw INTERP_KERNEL::Exception(oss.str());
2516     }
2517   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2518   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2519   if(type!=ON_NODES)
2520     {
2521       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2522       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2523     }
2524   else
2525     {
2526       if(code.size()!=3)
2527         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2528       int nb=code[1];
2529       if(code[2]==-1)
2530         {
2531           if(nb!=mesh->getNumberOfNodes())
2532             {
2533               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2534               oss << " nodes in mesh !";
2535               throw INTERP_KERNEL::Exception(oss.str());
2536             }
2537         }
2538       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2539     }
2540   //
2541   return 0;
2542 }
2543
2544 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2545 {
2546   int globalSz=0;
2547   int nbOfEntries=0;
2548   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2549     {
2550       (*it)->getSizes(globalSz,nbOfEntries);
2551     }
2552   entries.resize(nbOfEntries);
2553   nbOfEntries=0;
2554   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2555     {
2556       (*it)->fillValues(nbOfEntries,entries);
2557     }
2558 }
2559
2560 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2561 {
2562   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2563     {
2564       if((*it)->getGeoType()==typ)
2565         return (*it)->getLeafGivenLocId(locId);
2566     }
2567   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2568   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2569   oss << "Possiblities are : ";
2570   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2571     {
2572       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2573       oss << "\"" << cm2.getRepr() << "\", ";
2574     }
2575   throw INTERP_KERNEL::Exception(oss.str());
2576 }
2577
2578 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2579 {
2580   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2581     {
2582       if((*it)->getGeoType()==typ)
2583         return (*it)->getLeafGivenLocId(locId);
2584     }
2585   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2586   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2587   oss << "Possiblities are : ";
2588   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2589     {
2590       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2591       oss << "\"" << cm2.getRepr() << "\", ";
2592     }
2593   throw INTERP_KERNEL::Exception(oss.str());
2594 }
2595
2596 /*!
2597  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2598  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2599  * \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.
2600  * \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.
2601  */
2602 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)
2603 {
2604   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2605   if(pms.empty())
2606     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2607   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2608     {
2609       if(!(*it).second)
2610         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2611       if(!(*it).second->getProfile().empty())
2612         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2613       if(!(*it).second->getLocalization().empty())
2614         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2615     }
2616   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2617   std::size_t i(0);
2618   std::vector< std::pair<int,int> > filteredDTS;
2619   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2620     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2621       if((*it2).first==gt)
2622         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2623   if(pms.size()!=filteredDTS.size())
2624     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2625   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2626   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2627   int zeStart(start),nval(0);
2628   for(;it1!=pms.end();it1++,it2++)
2629     {
2630       if((*it1).first!=(*it2).first)
2631         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2632       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2633       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2634       start+=e1-s1;
2635       nval+=((*it1).second)->getNumberOfVals();
2636     }
2637   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2638   return ret;
2639 }
2640
2641 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)
2642 {
2643   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2644   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2645   std::size_t i(0);
2646   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2647     {
2648       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2649       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2650         {
2651           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2652           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2653           if(!elt)
2654             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2655           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2656         }
2657     }
2658   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2659     {
2660       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2661       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2662       ret->_field_pm_pt.push_back(agg2);
2663     }
2664   return ret;
2665 }
2666
2667 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2668 {
2669   int i=0;
2670   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2671   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2672   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2673     {
2674       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2675       if(type==curType)
2676         return i;
2677       else
2678         {
2679           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2680           if(pos>pos2)
2681             it2=it+1;
2682         }
2683     }
2684   int ret=std::distance(_field_pm_pt.begin(),it2);
2685   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2686   return ret;
2687 }
2688
2689 /*!
2690  * 'dads' and 'locs' input parameters have the same number of elements
2691  * \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
2692  */
2693 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2694                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2695                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2696 {
2697   isPfl=false;
2698   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2699   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2700   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2701   const std::vector<std::string>& infos=getInfo();
2702   da->setInfoOnComponents(infos);
2703   da->setName("");
2704   if(type==ON_GAUSS_PT)
2705     {
2706       int offset=0;
2707       int nbOfArrs=dads.size();
2708       for(int i=0;i<nbOfArrs;i++)
2709         {
2710           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2711           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2712           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2713           MCAuto<DataArrayInt> di=DataArrayInt::New();
2714           di->alloc(nbOfElems,1);
2715           di->iota(offset);
2716           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2717           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2718           offset+=nbOfElems;
2719         }
2720     }
2721   arrOut=da;
2722   return ret.retn();
2723 }
2724
2725 /*!
2726  * 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.
2727  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2728  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2729  * The order of cells in the returned field is those imposed by the profile.
2730  * \param [in] mesh is the global mesh.
2731  */
2732 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2733                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2734                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2735                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2736 {
2737   if(da->isIota(mesh->getNumberOfCells()))
2738     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2739   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2740   m2->setName(mesh->getName().c_str());
2741   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2742   isPfl=true;
2743   return ret.retn();
2744 }
2745
2746 /*!
2747  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2748  */
2749 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2750                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2751                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2752 {
2753   if(da->isIota(mesh->getNumberOfNodes()))
2754     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2755   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2756   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2757   if(meshu)
2758     {
2759       if(meshu->getNodalConnectivity()==0)
2760         {
2761           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2762           int nb=da->getNbOfElems();
2763           const int *ptr=da->getConstPointer();
2764           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2765           meshuc->allocateCells(nb);
2766           for(int i=0;i<nb;i++)
2767             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2768           meshuc->finishInsertingCells();
2769           ret->setMesh(meshuc);
2770           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2771           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2772           disc->checkCoherencyBetween(meshuc,arrOut);
2773           return ret.retn();
2774         }
2775     }
2776   //
2777   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2778   isPfl=true;
2779   DataArrayInt *arr2=0;
2780   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2781   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2782   MCAuto<DataArrayInt> arr3(arr2);
2783   int nnodes=mesh2->getNumberOfNodes();
2784   if(nnodes==(int)da->getNbOfElems())
2785     {
2786       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2787       arrOut->renumberInPlace(da3->getConstPointer());
2788       mesh2->setName(mesh->getName().c_str());
2789       ret->setMesh(mesh2);
2790       return ret.retn();
2791     }
2792   else
2793     {
2794       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 !!!";
2795       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2796       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2797       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2798       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2799       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2800       throw INTERP_KERNEL::Exception(oss.str());
2801     }
2802   return 0;
2803 }
2804
2805 /*!
2806  * This method is the most light method of field retrieving.
2807  */
2808 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2809 {
2810   if(!pflIn)
2811     {
2812       pflOut=DataArrayInt::New();
2813       pflOut->alloc(nbOfElems,1);
2814       pflOut->iota(0);
2815     }
2816   else
2817     {
2818       pflOut=const_cast<DataArrayInt*>(pflIn);
2819       pflOut->incrRef();
2820     }
2821   MCAuto<DataArrayInt> safePfl(pflOut);
2822   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2823   const std::vector<std::string>& infos=getInfo();
2824   int nbOfComp=infos.size();
2825   for(int i=0;i<nbOfComp;i++)
2826     da->setInfoOnComponent(i,infos[i].c_str());
2827   safePfl->incrRef();
2828   return da.retn();
2829 }
2830
2831
2832 /// @cond INTERNAL
2833
2834 class MFFPMIter
2835 {
2836 public:
2837   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2838   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2839   virtual ~MFFPMIter() { }
2840   virtual void begin() = 0;
2841   virtual bool finished() const = 0;
2842   virtual void next() = 0;
2843   virtual int current() const = 0;
2844 };
2845
2846 class MFFPMIterSimple : public MFFPMIter
2847 {
2848 public:
2849   MFFPMIterSimple():_pos(0) { }
2850   void begin() { _pos=0; }
2851   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2852   void next() { _pos++; }
2853   int current() const { return _pos; }
2854 private:
2855   int _pos;
2856 };
2857
2858 class MFFPMIter2 : public MFFPMIter
2859 {
2860 public:
2861   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2862   void begin() { _it=_ids.begin(); }
2863   bool finished() const { return _it==_ids.end(); }
2864   void next() { _it++; }
2865   int current() const { return *_it; }
2866 private:
2867   std::vector<int> _ids;
2868   std::vector<int>::const_iterator _it;
2869 };
2870
2871 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
2872 {
2873   if(!entities)
2874     return new MFFPMIterSimple;
2875   else
2876     {
2877       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2878       if(entities2)
2879         {
2880           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2881           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2882           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2883             {
2884               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2885                 tmp.push_back((*it).second);
2886             }
2887           return new MFFPMIter2(tmp);
2888         }
2889       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
2890     }
2891 }
2892
2893 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
2894 {
2895   if(!entities)
2896     return true;
2897   else
2898     {
2899       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2900       if(entities2)
2901         {
2902           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2903           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2904             if((*it).first==ON_NODES)
2905               return true;
2906           return false;
2907         }
2908       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
2909     }
2910 }
2911
2912 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2913 {
2914   std::size_t sz(cts.size());
2915   _ids.resize(sz);
2916   for(std::size_t i=0;i<sz;i++)
2917     {
2918       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2919       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2920         _ids[i]=(int)std::distance(typmai2,loc);
2921       else
2922         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2923     }
2924 }
2925
2926 /// @endcond
2927
2928 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),
2929     _father(fath)
2930 {
2931   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2932   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2933   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2934   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2935   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2936   for(iter0->begin();!iter0->finished();iter0->next())
2937     {
2938       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2939       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2940       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2941       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2942       if(nbProfile>0 || nbProfile2>0)
2943         {
2944           const PartDefinition *pd(0);
2945           if(mmu)
2946             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2947           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2948           if(nbProfile>0)
2949             _mesh_name=name0;
2950           else
2951             _mesh_name=name1;
2952         }
2953     }
2954   if(MFFPMIter::IsPresenceOfNode(entities))
2955     {
2956       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2957       if(nbProfile>0)
2958         {
2959           const PartDefinition *pd(0);
2960           if(mmu)
2961             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2962           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2963           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2964         }
2965     }
2966   if(!entities)
2967     return ;
2968   std::vector<int> dynGT(entities->getDynGTAvail());
2969   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
2970     {
2971       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
2972       if(nbPfl>0)
2973         {
2974           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
2975           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2976         }
2977     }
2978 }
2979
2980 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2981 {
2982   copyTinyInfoFrom(mesh);
2983 }
2984
2985 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2986 {
2987   if(id>=(int)_pfls.size())
2988     _pfls.resize(id+1);
2989   _pfls[id]=DataArrayInt::New();
2990   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2991   _pfls[id]->setName(pflName);
2992   _pfls[id]->alloc(lgth,1);
2993   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2994   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2995 }
2996
2997 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2998 {
2999   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3000   int sz;
3001   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
3002   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
3003   if(i>=(int)_pfls.size())
3004     _pfls.resize(i+1);
3005   _pfls[i]=DataArrayInt::New();
3006   _pfls[i]->alloc(sz,1);
3007   _pfls[i]->setName(pflCpp.c_str());
3008   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
3009   _pfls[i]->applyLin(1,-1,0);//Converting into C format
3010 }
3011
3012 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3013 {
3014   int nbOfPfls=_pfls.size();
3015   for(int i=0;i<nbOfPfls;i++)
3016     {
3017       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
3018       cpy->applyLin(1,1,0);
3019       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3020       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
3021       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
3022     }
3023   //
3024   int nbOfLocs=_locs.size();
3025   for(int i=0;i<nbOfLocs;i++)
3026     _locs[i]->writeLL(fid);
3027 }
3028
3029 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
3030 {
3031   std::vector<std::string> pfls=getPfls();
3032   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
3033     {
3034       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
3035       if(it2==pfls.end())
3036         {
3037           _pfls.push_back(*it);
3038         }
3039       else
3040         {
3041           int id=std::distance(pfls.begin(),it2);
3042           if(!(*it)->isEqual(*_pfls[id]))
3043             {
3044               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3045               throw INTERP_KERNEL::Exception(oss.str());
3046             }
3047         }
3048     }
3049   std::vector<std::string> locs=getLocs();
3050   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
3051     {
3052       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
3053       if(it2==locs.end())
3054         {
3055           _locs.push_back(*it);
3056         }
3057       else
3058         {
3059           int id=std::distance(locs.begin(),it2);
3060           if(!(*it)->isEqual(*_locs[id],eps))
3061             {
3062               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3063               throw INTERP_KERNEL::Exception(oss.str());
3064             }
3065         }
3066     }
3067 }
3068
3069 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
3070 {
3071   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
3072     getProfile((*it).c_str());
3073 }
3074
3075 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
3076 {
3077   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
3078     getLocalization((*it).c_str());
3079 }
3080
3081 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
3082 {
3083   std::vector<std::string> profiles=real.getPflsReallyUsed();
3084   int sz=profiles.size();
3085   _pfls.resize(sz);
3086   for(int i=0;i<sz;i++)
3087     loadProfileInFile(fid,i,profiles[i].c_str());
3088   //
3089   std::vector<std::string> locs=real.getLocsReallyUsed();
3090   sz=locs.size();
3091   _locs.resize(sz);
3092   for(int i=0;i<sz;i++)
3093     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
3094 }
3095
3096 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
3097 {
3098   int nProfil=MEDnProfile(fid);
3099   for(int i=0;i<nProfil;i++)
3100     loadProfileInFile(fid,i);
3101   int sz=MEDnLocalization(fid);
3102   _locs.resize(sz);
3103   for(int i=0;i<sz;i++)
3104     {
3105       _locs[i]=MEDFileFieldLoc::New(fid,i);
3106     }
3107 }
3108
3109 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
3110 {
3111   return new MEDFileFieldGlobs(fid);
3112 }
3113
3114 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
3115 {
3116   return new MEDFileFieldGlobs;
3117 }
3118
3119 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
3120 {
3121   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
3122 }
3123
3124 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
3125 {
3126   std::vector<const BigMemoryObject *> ret;
3127   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3128     ret.push_back((const DataArrayInt *)*it);
3129   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3130     ret.push_back((const MEDFileFieldLoc *)*it);
3131   return ret;
3132 }
3133
3134 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3135 {
3136   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3137   std::size_t i=0;
3138   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3139     {
3140       if((const DataArrayInt *)*it)
3141         ret->_pfls[i]=(*it)->deepCopy();
3142     }
3143   i=0;
3144   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3145     {
3146       if((const MEDFileFieldLoc*)*it)
3147         ret->_locs[i]=(*it)->deepCopy();
3148     }
3149   return ret.retn();
3150 }
3151
3152 /*!
3153  * \throw if a profile in \a pfls in not in \a this.
3154  * \throw if a localization in \a locs in not in \a this.
3155  * \sa MEDFileFieldGlobs::deepCpyPart
3156  */
3157 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3158 {
3159   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3160   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3161     {
3162       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3163       if(!pfl)
3164         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3165       pfl->incrRef();
3166       MCAuto<DataArrayInt> pfl2(pfl);
3167       ret->_pfls.push_back(pfl2);
3168     }
3169   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3170     {
3171       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3172       if(!loc)
3173         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3174       loc->incrRef();
3175       MCAuto<MEDFileFieldLoc> loc2(loc);
3176       ret->_locs.push_back(loc2);
3177     }
3178   ret->setFileName(getFileName());
3179   return ret.retn();
3180 }
3181
3182 /*!
3183  * \throw if a profile in \a pfls in not in \a this.
3184  * \throw if a localization in \a locs in not in \a this.
3185  * \sa MEDFileFieldGlobs::shallowCpyPart
3186  */
3187 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3188 {
3189   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3190   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3191     {
3192       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3193       if(!pfl)
3194         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3195       ret->_pfls.push_back(pfl->deepCopy());
3196     }
3197   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3198     {
3199       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3200       if(!loc)
3201         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3202       ret->_locs.push_back(loc->deepCopy());
3203     }
3204   ret->setFileName(getFileName());
3205   return ret.retn();
3206 }
3207
3208 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3209 {
3210 }
3211
3212 MEDFileFieldGlobs::MEDFileFieldGlobs()
3213 {
3214 }
3215
3216 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3217 {
3218 }
3219
3220 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3221 {
3222   oss << "Profiles :\n";
3223   std::size_t n=_pfls.size();
3224   for(std::size_t i=0;i<n;i++)
3225     {
3226       oss << "  - #" << i << " ";
3227       const DataArrayInt *pfl=_pfls[i];
3228       if(pfl)
3229         oss << "\"" << pfl->getName() << "\"\n";
3230       else
3231         oss << "EMPTY !\n";
3232     }
3233   n=_locs.size();
3234   oss << "Localizations :\n";
3235   for(std::size_t i=0;i<n;i++)
3236     {
3237       oss << "  - #" << i << " ";
3238       const MEDFileFieldLoc *loc=_locs[i];
3239       if(loc)
3240         loc->simpleRepr(oss);
3241       else
3242         oss<< "EMPTY !\n";
3243     }
3244 }
3245
3246 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3247 {
3248   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3249     {
3250       DataArrayInt *elt(*it);
3251       if(elt)
3252         {
3253           std::string name(elt->getName());
3254           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3255             {
3256               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3257                 {
3258                   elt->setName((*it2).second.c_str());
3259                   return;
3260                 }
3261             }
3262         }
3263     }
3264 }
3265
3266 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3267 {
3268   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3269     {
3270       MEDFileFieldLoc *elt(*it);
3271       if(elt)
3272         {
3273           std::string name(elt->getName());
3274           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3275             {
3276               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3277                 {
3278                   elt->setName((*it2).second.c_str());
3279                   return;
3280                 }
3281             }
3282         }
3283     }
3284 }
3285
3286 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3287 {
3288   if(locId<0 || locId>=(int)_locs.size())
3289     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3290   return _locs[locId]->getNbOfGaussPtPerCell();
3291 }
3292
3293 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3294 {
3295   return getLocalizationFromId(getLocalizationId(locName));
3296 }
3297
3298 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3299 {
3300   if(locId<0 || locId>=(int)_locs.size())
3301     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3302   return *_locs[locId];
3303 }
3304
3305 /// @cond INTERNAL
3306 namespace MEDCouplingImpl
3307 {
3308   class LocFinder
3309   {
3310   public:
3311     LocFinder(const std::string& loc):_loc(loc) { }
3312     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3313   private:
3314     const std::string &_loc;
3315   };
3316
3317   class PflFinder
3318   {
3319   public:
3320     PflFinder(const std::string& pfl):_pfl(pfl) { }
3321     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3322   private:
3323     const std::string& _pfl;
3324   };
3325 }
3326 /// @endcond
3327
3328 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3329 {
3330   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3331   if(it==_locs.end())
3332     {
3333       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3334       for(it=_locs.begin();it!=_locs.end();it++)
3335         oss << "\"" << (*it)->getName() << "\", ";
3336       throw INTERP_KERNEL::Exception(oss.str());
3337     }
3338   return std::distance(_locs.begin(),it);
3339 }
3340
3341 /*!
3342  * The returned value is never null.
3343  */
3344 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3345 {
3346   std::string pflNameCpp(pflName);
3347   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3348   if(it==_pfls.end())
3349     {
3350       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3351       for(it=_pfls.begin();it!=_pfls.end();it++)
3352         oss << "\"" << (*it)->getName() << "\", ";
3353       throw INTERP_KERNEL::Exception(oss.str());
3354     }
3355   return *it;
3356 }
3357
3358 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3359 {
3360   if(pflId<0 || pflId>=(int)_pfls.size())
3361     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3362   return _pfls[pflId];
3363 }
3364
3365 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3366 {
3367   if(locId<0 || locId>=(int)_locs.size())
3368     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3369   return *_locs[locId];
3370 }
3371
3372 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3373 {
3374   return getLocalizationFromId(getLocalizationId(locName));
3375 }
3376
3377 /*!
3378  * The returned value is never null.
3379  */
3380 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3381 {
3382   std::string pflNameCpp(pflName);
3383   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3384   if(it==_pfls.end())
3385     {
3386       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3387       for(it=_pfls.begin();it!=_pfls.end();it++)
3388         oss << "\"" << (*it)->getName() << "\", ";
3389       throw INTERP_KERNEL::Exception(oss.str());
3390     }
3391   return *it;
3392 }
3393
3394 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3395 {
3396   if(pflId<0 || pflId>=(int)_pfls.size())
3397     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3398   return _pfls[pflId];
3399 }
3400
3401 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3402 {
3403   std::vector< MCAuto<DataArrayInt> > newPfls;
3404   int i=0;
3405   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3406     {
3407       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3408         newPfls.push_back(*it);
3409     }
3410   _pfls=newPfls;
3411 }
3412
3413 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3414 {
3415   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3416   int i=0;
3417   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3418     {
3419       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3420         newLocs.push_back(*it);
3421     }
3422   _locs=newLocs;
3423 }
3424
3425 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3426 {
3427   int sz=_pfls.size();
3428   std::vector<std::string> ret(sz);
3429   for(int i=0;i<sz;i++)
3430     ret[i]=_pfls[i]->getName();
3431   return ret;
3432 }
3433
3434 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3435 {
3436   int sz=_locs.size();
3437   std::vector<std::string> ret(sz);
3438   for(int i=0;i<sz;i++)
3439     ret[i]=_locs[i]->getName();
3440   return ret;
3441 }
3442
3443 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3444 {
3445   std::vector<std::string> v=getPfls();
3446   std::string s(pflName);
3447   return std::find(v.begin(),v.end(),s)!=v.end();
3448 }
3449
3450 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3451 {
3452   std::vector<std::string> v=getLocs();
3453   std::string s(locName);
3454   return std::find(v.begin(),v.end(),s)!=v.end();
3455 }
3456
3457 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3458 {
3459   std::map<int,std::vector<int> > m;
3460   int i=0;
3461   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3462     {
3463       const DataArrayInt *tmp=(*it);
3464       if(tmp)
3465         {
3466           m[tmp->getHashCode()].push_back(i);
3467         }
3468     }
3469   std::vector< std::vector<int> > ret;
3470   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3471     {
3472       if((*it2).second.size()>1)
3473         {
3474           std::vector<int> ret0;
3475           bool equalityOrNot=false;
3476           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3477             {
3478               std::vector<int>::const_iterator it4=it3; it4++;
3479               for(;it4!=(*it2).second.end();it4++)
3480                 {
3481                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3482                     {
3483                       if(!equalityOrNot)
3484                         ret0.push_back(*it3);
3485                       ret0.push_back(*it4);
3486                       equalityOrNot=true;
3487                     }
3488                 }
3489             }
3490           if(!ret0.empty())
3491             ret.push_back(ret0);
3492         }
3493     }
3494   return ret;
3495 }
3496
3497 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3498 {
3499   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3500 }
3501
3502 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3503 {
3504   std::string name(pfl->getName());
3505   if(name.empty())
3506     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3507   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3508     if(name==(*it)->getName())
3509       {
3510         if(!pfl->isEqual(*(*it)))
3511           {
3512             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3513             throw INTERP_KERNEL::Exception(oss.str());
3514           }
3515       }
3516   pfl->incrRef();
3517   _pfls.push_back(pfl);
3518 }
3519
3520 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)
3521 {
3522   std::string name(locName);
3523   if(name.empty())
3524     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3525   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3526   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3527     if((*it)->isName(locName))
3528       {
3529         if(!(*it)->isEqual(*obj,1e-12))
3530           {
3531             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3532             throw INTERP_KERNEL::Exception(oss.str());
3533           }
3534       }
3535   _locs.push_back(obj);
3536 }
3537
3538 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3539 {
3540   std::vector<std::string> names=getPfls();
3541   return CreateNewNameNotIn("NewPfl_",names);
3542 }
3543
3544 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3545 {
3546   std::vector<std::string> names=getLocs();
3547   return CreateNewNameNotIn("NewLoc_",names);
3548 }
3549
3550 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3551 {
3552   for(std::size_t sz=0;sz<100000;sz++)
3553     {
3554       std::ostringstream tryName;
3555       tryName << prefix << sz;
3556       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3557         return tryName.str();
3558     }
3559   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3560 }
3561
3562 /*!
3563  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3564  *  \param [in] fname - the file name.
3565  */
3566 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3567 {
3568 }
3569
3570 /*!
3571  * Creates an empty MEDFileFieldGlobsReal.
3572  */
3573 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3574 {
3575 }
3576
3577 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3578 {
3579   return 0;
3580 }
3581
3582 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3583 {
3584   std::vector<const BigMemoryObject *> ret;
3585   ret.push_back((const MEDFileFieldGlobs *)_globals);
3586   return ret;
3587 }
3588
3589 /*!
3590  * Returns a string describing profiles and Gauss points held in \a this.
3591  *  \return std::string - the description string.
3592  */
3593 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3594 {
3595   const MEDFileFieldGlobs *glob=_globals;
3596   std::ostringstream oss2; oss2 << glob;
3597   std::string stars(oss2.str().length(),'*');
3598   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3599   if(glob)
3600     glob->simpleRepr(oss);
3601   else
3602     oss << "NO GLOBAL INFORMATION !\n";
3603 }
3604
3605 void MEDFileFieldGlobsReal::resetContent()
3606 {
3607   _globals=MEDFileFieldGlobs::New();
3608 }
3609
3610 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3611 {
3612 }
3613
3614 /*!
3615  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3616  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3617  */
3618 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3619 {
3620   _globals=other._globals;
3621 }
3622
3623 /*!
3624  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3625  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3626  */
3627 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3628 {
3629   const MEDFileFieldGlobs *otherg(other._globals);
3630   if(!otherg)
3631     return ;
3632   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3633 }
3634
3635 /*!
3636  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3637  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3638  */
3639 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3640 {
3641   const MEDFileFieldGlobs *otherg(other._globals);
3642   if(!otherg)
3643     return ;
3644   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3645 }
3646
3647 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3648 {
3649   _globals=other._globals;
3650   if((const MEDFileFieldGlobs *)_globals)
3651     _globals=other._globals->deepCopy();
3652 }
3653
3654 /*!
3655  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3656  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3657  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3658  *         \a this and \a other MEDFileFieldGlobsReal.
3659  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3660  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3661  */
3662 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3663 {
3664   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3665   if(thisGlobals==otherGlobals)
3666     return ;
3667   if(!thisGlobals)
3668     {
3669       _globals=other._globals;
3670       return ;
3671     }
3672   _globals->appendGlobs(*other._globals,eps);
3673 }
3674
3675 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3676 {
3677   checkGlobsPflsPartCoherency();
3678   checkGlobsLocsPartCoherency();
3679 }
3680
3681 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3682 {
3683   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3684 }
3685
3686 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3687 {
3688   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3689 }
3690
3691 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3692 {
3693   contentNotNull()->loadProfileInFile(fid,id,pflName);
3694 }
3695
3696 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3697 {
3698   contentNotNull()->loadProfileInFile(fid,id);
3699 }
3700
3701 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3702 {
3703   contentNotNull()->loadGlobals(fid,*this);
3704 }
3705
3706 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3707 {
3708   contentNotNull()->loadAllGlobals(fid);
3709 }
3710
3711 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3712 {
3713   contentNotNull()->writeGlobals(fid,opt);
3714 }
3715
3716 /*!
3717  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3718  * or getPflsReallyUsedMulti().
3719  *  \return std::vector<std::string> - a sequence of names of all profiles.
3720  */
3721 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3722 {
3723   return contentNotNull()->getPfls();
3724 }
3725
3726 /*!
3727  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3728  * or getLocsReallyUsedMulti().
3729  *  \return std::vector<std::string> - a sequence of names of all localizations.
3730  */
3731 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3732 {
3733   return contentNotNull()->getLocs();
3734 }
3735
3736 /*!
3737  * Checks if the profile with a given name exists.
3738  *  \param [in] pflName - the profile name of interest.
3739  *  \return bool - \c true if the profile named \a pflName exists.
3740  */
3741 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3742 {
3743   return contentNotNull()->existsPfl(pflName);
3744 }
3745
3746 /*!
3747  * Checks if the localization with a given name exists.
3748  *  \param [in] locName - the localization name of interest.
3749  *  \return bool - \c true if the localization named \a locName exists.
3750  */
3751 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3752 {
3753   return contentNotNull()->existsLoc(locName);
3754 }
3755
3756 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3757 {
3758   return contentNotNull()->createNewNameOfPfl();
3759 }
3760
3761 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3762 {
3763   return contentNotNull()->createNewNameOfLoc();
3764 }
3765
3766 /*!
3767  * Sets the name of a MED file.
3768  *  \param [inout] fileName - the file name.
3769  */
3770 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3771 {
3772   contentNotNull()->setFileName(fileName);
3773 }
3774
3775 /*!
3776  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3777  * in the same order.
3778  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3779  *          Each item of this sequence is a vector containing ids of equal profiles.
3780  */
3781 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3782 {
3783   return contentNotNull()->whichAreEqualProfiles();
3784 }
3785
3786 /*!
3787  * Finds equal localizations.
3788  *  \param [in] eps - a precision used to compare real values of the localizations.
3789  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3790  *          Each item of this sequence is a vector containing ids of equal localizations.
3791  */
3792 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3793 {
3794   return contentNotNull()->whichAreEqualLocs(eps);
3795 }
3796
3797 /*!
3798  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3799  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3800  *        this sequence is a pair whose 
3801  *        - the first item is a vector of profile names to replace by the second item,
3802  *        - the second item is a profile name to replace every profile name of the first item.
3803  */
3804 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3805 {
3806   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3807 }
3808
3809 /*!
3810  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3811  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3812  *        this sequence is a pair whose 
3813  *        - the first item is a vector of localization names to replace by the second item,
3814  *        - the second item is a localization name to replace every localization name of the first item.
3815  */
3816 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3817 {
3818   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3819 }
3820
3821 /*!
3822  * Replaces references to some profiles (a reference is a profile name) by references
3823  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3824  * them-selves accordingly. <br>
3825  * This method is a generalization of changePflName().
3826  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3827  *        this sequence is a pair whose 
3828  *        - the first item is a vector of profile names to replace by the second item,
3829  *        - the second item is a profile name to replace every profile of the first item.
3830  * \sa changePflsRefsNamesGen()
3831  * \sa changePflName()
3832  */
3833 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3834 {
3835   changePflsRefsNamesGen(mapOfModif);
3836   changePflsNamesInStruct(mapOfModif);
3837 }
3838
3839 /*!
3840  * Replaces references to some localizations (a reference is a localization name) by references
3841  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3842  * them-selves accordingly. <br>
3843  * This method is a generalization of changeLocName().
3844  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3845  *        this sequence is a pair whose 
3846  *        - the first item is a vector of localization names to replace by the second item,
3847  *        - the second item is a localization name to replace every localization of the first item.
3848  * \sa changeLocsRefsNamesGen()
3849  * \sa changeLocName()
3850  */
3851 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3852 {
3853   changeLocsRefsNamesGen(mapOfModif);
3854   changeLocsNamesInStruct(mapOfModif);
3855 }
3856
3857 /*!
3858  * Renames the profile having a given name and updates references to this profile.
3859  *  \param [in] oldName - the name of the profile to rename.
3860  *  \param [in] newName - a new name of the profile.
3861  * \sa changePflsNames().
3862  */
3863 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3864 {
3865   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3866   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3867   mapOfModif[0]=p;
3868   changePflsNames(mapOfModif);
3869 }
3870
3871 /*!
3872  * Renames the localization having a given name and updates references to this localization.
3873  *  \param [in] oldName - the name of the localization to rename.
3874  *  \param [in] newName - a new name of the localization.
3875  * \sa changeLocsNames().
3876  */
3877 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3878 {
3879   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3880   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3881   mapOfModif[0]=p;
3882   changeLocsNames(mapOfModif);
3883 }
3884
3885 /*!
3886  * Removes duplicated profiles. Returns a map used to update references to removed 
3887  * profiles via changePflsRefsNamesGen().
3888  * Equal profiles are found using whichAreEqualProfiles().
3889  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3890  *          a sequence describing the performed replacements of profiles. Each element of
3891  *          this sequence is a pair whose
3892  *          - the first item is a vector of profile names replaced by the second item,
3893  *          - the second item is a profile name replacing every profile of the first item.
3894  */
3895 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3896 {
3897   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3898   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3899   int i=0;
3900   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3901     {
3902       std::vector< std::string > tmp((*it).size());
3903       int j=0;
3904       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3905         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3906       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3907       ret[i]=p;
3908       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3909       killProfileIds(tmp2);
3910     }
3911   changePflsRefsNamesGen(ret);
3912   return ret;
3913 }
3914
3915 /*!
3916  * Removes duplicated localizations. Returns a map used to update references to removed 
3917  * localizations via changeLocsRefsNamesGen().
3918  * Equal localizations are found using whichAreEqualLocs().
3919  *  \param [in] eps - a precision used to compare real values of the localizations.
3920  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3921  *          a sequence describing the performed replacements of localizations. Each element of
3922  *          this sequence is a pair whose
3923  *          - the first item is a vector of localization names replaced by the second item,
3924  *          - the second item is a localization name replacing every localization of the first item.
3925  */
3926 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3927 {
3928   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3929   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3930   int i=0;
3931   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3932     {
3933       std::vector< std::string > tmp((*it).size());
3934       int j=0;
3935       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3936         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3937       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3938       ret[i]=p;
3939       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3940       killLocalizationIds(tmp2);
3941     }
3942   changeLocsRefsNamesGen(ret);
3943   return ret;
3944 }
3945
3946 /*!
3947  * Returns number of Gauss points per cell in a given localization.
3948  *  \param [in] locId - an id of the localization of interest.
3949  *  \return int - the number of the Gauss points per cell.
3950  */
3951 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3952 {
3953   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3954 }
3955
3956 /*!
3957  * Returns an id of a localization by its name.
3958  *  \param [in] loc - the localization name of interest.
3959  *  \return int - the id of the localization.
3960  *  \throw If there is no a localization named \a loc.
3961  */
3962 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3963 {
3964   return contentNotNull()->getLocalizationId(loc);
3965 }
3966
3967 /*!
3968  * Returns the name of the MED file.
3969  *  \return const std::string&  - the MED file name.
3970  */
3971 std::string MEDFileFieldGlobsReal::getFileName() const
3972 {
3973   return contentNotNull()->getFileName();
3974 }
3975
3976 /*!
3977  * Returns a localization object by its name.
3978  *  \param [in] locName - the name of the localization of interest.
3979  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3980  *  \throw If there is no a localization named \a locName.
3981  */
3982 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3983 {
3984   return contentNotNull()->getLocalization(locName);
3985 }
3986
3987 /*!
3988  * Returns a localization object by its id.
3989  *  \param [in] locId - the id of the localization of interest.
3990  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3991  *  \throw If there is no a localization with id \a locId.
3992  */
3993 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3994 {
3995   return contentNotNull()->getLocalizationFromId(locId);
3996 }
3997
3998 /*!
3999  * Returns a profile array by its name.
4000  *  \param [in] pflName - the name of the profile of interest.
4001  *  \return const DataArrayInt * - the profile array having the name \a pflName.
4002  *  \throw If there is no a profile named \a pflName.
4003  */
4004 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
4005 {
4006   return contentNotNull()->getProfile(pflName);
4007 }
4008
4009 /*!
4010  * Returns a profile array by its id.
4011  *  \param [in] pflId - the id of the profile of interest.
4012  *  \return const DataArrayInt * - the profile array having the id \a pflId.
4013  *  \throw If there is no a profile with id \a pflId.
4014  */
4015 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
4016 {
4017   return contentNotNull()->getProfileFromId(pflId);
4018 }
4019
4020 /*!
4021  * Returns a localization object, apt for modification, by its id.
4022  *  \param [in] locId - the id of the localization of interest.
4023  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4024  *          having the id \a locId.
4025  *  \throw If there is no a localization with id \a locId.
4026  */
4027 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
4028 {
4029   return contentNotNull()->getLocalizationFromId(locId);
4030 }
4031
4032 /*!
4033  * Returns a localization object, apt for modification, by its name.
4034  *  \param [in] locName - the name of the localization of interest.
4035  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4036  *          having the name \a locName.
4037  *  \throw If there is no a localization named \a locName.
4038  */
4039 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
4040 {
4041   return contentNotNull()->getLocalization(locName);
4042 }
4043
4044 /*!
4045  * Returns a profile array, apt for modification, by its name.
4046  *  \param [in] pflName - the name of the profile of interest.
4047  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
4048  *  \throw If there is no a profile named \a pflName.
4049  */
4050 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
4051 {
4052   return contentNotNull()->getProfile(pflName);
4053 }
4054
4055 /*!
4056  * Returns a profile array, apt for modification, by its id.
4057  *  \param [in] pflId - the id of the profile of interest.
4058  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
4059  *  \throw If there is no a profile with id \a pflId.
4060  */
4061 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
4062 {
4063   return contentNotNull()->getProfileFromId(pflId);
4064 }
4065
4066 /*!
4067  * Removes profiles given by their ids. No data is updated to track this removal.
4068  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
4069  */
4070 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
4071 {
4072   contentNotNull()->killProfileIds(pflIds);
4073 }
4074
4075 /*!
4076  * Removes localizations given by their ids. No data is updated to track this removal.
4077  *  \param [in] locIds - a sequence of ids of the localizations to remove.
4078  */
4079 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
4080 {
4081   contentNotNull()->killLocalizationIds(locIds);
4082 }
4083
4084 /*!
4085  * Stores a profile array.
4086  *  \param [in] pfl - the profile array to store.
4087  *  \throw If the name of \a pfl is empty.
4088  *  \throw If a profile with the same name as that of \a pfl already exists but contains
4089  *         different ids.
4090  */
4091 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
4092 {
4093   contentNotNull()->appendProfile(pfl);
4094 }
4095
4096 /*!
4097  * Adds a new localization of Gauss points.
4098  *  \param [in] locName - the name of the new localization.
4099  *  \param [in] geoType - a geometrical type of the reference cell.
4100  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
4101  *         must be \c nbOfNodesPerCell * \c dimOfType.
4102  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
4103  *         must be  _wg_.size() * \c dimOfType.
4104  *  \param [in] w - the weights of Gauss points.
4105  *  \throw If \a locName is empty.
4106  *  \throw If a localization with the name \a locName already exists but is
4107  *         different form the new one.
4108  */
4109 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)
4110 {
4111   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
4112 }
4113
4114 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
4115 {
4116   MEDFileFieldGlobs *g(_globals);
4117   if(!g)
4118     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
4119   return g;
4120 }
4121
4122 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
4123 {
4124   const MEDFileFieldGlobs *g(_globals);
4125   if(!g)
4126     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4127   return g;
4128 }
4129
4130 //= MEDFileFieldNameScope
4131
4132 MEDFileFieldNameScope::MEDFileFieldNameScope()
4133 {
4134 }
4135
4136 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
4137 {
4138 }
4139
4140 /*!
4141  * Returns the name of \a this field.
4142  *  \return std::string - a string containing the field name.
4143  */
4144 std::string MEDFileFieldNameScope::getName() const
4145 {
4146   return _name;
4147 }
4148
4149 /*!
4150  * Sets name of \a this field
4151  *  \param [in] name - the new field name.
4152  */
4153 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4154 {
4155   _name=fieldName;
4156 }
4157
4158 std::string MEDFileFieldNameScope::getDtUnit() const
4159 {
4160   return _dt_unit;
4161 }
4162
4163 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4164 {
4165   _dt_unit=dtUnit;
4166 }
4167
4168 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4169 {
4170   _name=other._name;
4171   _dt_unit=other._dt_unit;
4172 }
4173
4174 //= MEDFileAnyTypeField1TSWithoutSDA
4175
4176 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4177 {
4178   _field_per_mesh.resize(other._field_per_mesh.size());
4179   std::size_t i=0;
4180   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4181     {
4182       if((const MEDFileFieldPerMesh *)*it)
4183         _field_per_mesh[i]=(*it)->deepCopy(this);
4184     }
4185 }
4186
4187 /*!
4188  * Prints a string describing \a this field into a stream. This string is outputted 
4189  * by \c print Python command.
4190  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4191  *  \param [in,out] oss - the out stream.
4192  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4193  *          info id printed, else, not.
4194  */
4195 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4196 {
4197   std::string startOfLine(bkOffset,' ');
4198   oss << startOfLine << "Field ";
4199   if(bkOffset==0)
4200     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4201   oss << "on one time Step ";
4202   if(f1tsId>=0)
4203     oss << "(" << f1tsId << ") ";
4204   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4205   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4206   const DataArray *arr=getUndergroundDataArray();
4207   if(arr)
4208     {
4209       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4210       if(f1tsId<0)
4211         {
4212           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4213           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4214             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4215         }
4216       if(arr->isAllocated())
4217         {
4218           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4219         }
4220       else
4221         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4222     }
4223   else
4224     {
4225       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4226     }
4227   oss << startOfLine << "----------------------" << std::endl;
4228   if(!_field_per_mesh.empty())
4229     {
4230       int i=0;
4231       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4232         {
4233           const MEDFileFieldPerMesh *cur=(*it2);
4234           if(cur)
4235             cur->simpleRepr(bkOffset,oss,i);
4236           else
4237             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4238         }
4239     }
4240   else
4241     {
4242       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4243     }
4244   oss << startOfLine << "----------------------" << std::endl;
4245 }
4246
4247 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4248 {
4249   const DataArray *arr(getUndergroundDataArray());
4250   if(!arr)
4251     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4252   int nbOfCompo=arr->getNumberOfComponents();
4253   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4254   for(int i=0;i<nbOfCompo;i++)
4255     {
4256       ret[i]=deepCopy();
4257       std::vector<int> v(1,i);
4258       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4259       ret[i]->setArray(arr2);
4260     }
4261   return ret;
4262 }
4263
4264 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)
4265 {
4266 }
4267
4268 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4269 {
4270 }
4271
4272 /*!
4273  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4274  * empty. Returns -1 if this in on nodes.
4275  *  \return int - the dimension of \a this.
4276  */
4277 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4278 {
4279   int ret=-2;
4280   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4281     (*it)->getDimension(ret);
4282   return ret;
4283 }
4284
4285 /*!
4286  * Returns the mesh name.
4287  *  \return std::string - a string holding the mesh name.
4288  *  \throw If \c _field_per_mesh.empty()
4289  */
4290 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
4291 {
4292   if(_field_per_mesh.empty())
4293     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
4294   return _field_per_mesh[0]->getMeshName();
4295 }
4296
4297 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
4298 {
4299   std::string oldName(getMeshName());
4300   std::vector< std::pair<std::string,std::string> > v(1);
4301   v[0].first=oldName; v[0].second=newMeshName;
4302   changeMeshNames(v);
4303 }
4304
4305 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4306 {
4307   bool ret=false;
4308   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4309     {
4310       MEDFileFieldPerMesh *cur(*it);
4311       if(cur)
4312         ret=cur->changeMeshNames(modifTab) || ret;
4313     }
4314   return ret;
4315 }
4316
4317 /*!
4318  * Returns the number of iteration of the state of underlying mesh.
4319  *  \return int - the iteration number.
4320  *  \throw If \c _field_per_mesh.empty()
4321  */
4322 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4323 {
4324   if(_field_per_mesh.empty())
4325     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4326   return _field_per_mesh[0]->getMeshIteration();
4327 }
4328
4329 /*!
4330  * Returns the order number of iteration of the state of underlying mesh.
4331  *  \return int - the order number.
4332  *  \throw If \c _field_per_mesh.empty()
4333  */
4334 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4335 {
4336   if(_field_per_mesh.empty())
4337     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4338   return _field_per_mesh[0]->getMeshOrder();
4339 }
4340
4341 /*!
4342  * Checks if \a this field is tagged by a given iteration number and a given
4343  * iteration order number.
4344  *  \param [in] iteration - the iteration number of interest.
4345  *  \param [in] order - the iteration order number of interest.
4346  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4347  *          \a this->getOrder() == \a order.
4348  */
4349 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4350 {
4351   return iteration==_iteration && order==_order;
4352 }
4353
4354 /*!
4355  * Returns number of iteration and order number of iteration when
4356  * \a this field has been calculated.
4357  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4358  *          order number.
4359  */
4360 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4361 {
4362   std::pair<int,int> p;
4363   fillIteration(p);
4364   return p;
4365 }
4366
4367 /*!
4368  * Returns number of iteration and order number of iteration when
4369  * \a this field has been calculated.
4370  *  \param [in,out] p - a pair returning the iteration number and the iteration
4371  *          order number.
4372  */
4373 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4374 {
4375   p.first=_iteration;
4376   p.second=_order;
4377 }
4378
4379 /*!
4380  * Returns all types of spatial discretization of \a this field.
4381  *  \param [in,out] types - a sequence of types of \a this field.
4382  */
4383 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4384 {
4385   std::set<TypeOfField> types2;
4386   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4387     {
4388       (*it)->fillTypesOfFieldAvailable(types2);
4389     }
4390   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4391   std::copy(types2.begin(),types2.end(),bi);
4392 }
4393
4394 /*!
4395  * Returns all types of spatial discretization of \a this field.
4396  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4397  *          of \a this field.
4398  */
4399 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4400 {
4401   std::vector<TypeOfField> ret;
4402   fillTypesOfFieldAvailable(ret);
4403   return ret;
4404 }
4405
4406 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4407 {
4408   std::vector<std::string> ret;
4409   std::set<std::string> ret2;
4410   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4411     {
4412       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4413       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4414         if(ret2.find(*it2)==ret2.end())
4415           {
4416             ret.push_back(*it2);
4417             ret2.insert(*it2);
4418           }
4419     }
4420   return ret;
4421 }
4422
4423 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4424 {
4425   std::vector<std::string> ret;
4426   std::set<std::string> ret2;
4427   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4428     {
4429       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4430       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4431         if(ret2.find(*it2)==ret2.end())
4432           {
4433             ret.push_back(*it2);
4434             ret2.insert(*it2);
4435           }
4436     }
4437   return ret;
4438 }
4439
4440 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4441 {
4442   std::vector<std::string> ret;
4443   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4444     {
4445       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4446       ret.insert(ret.end(),tmp.begin(),tmp.end());
4447     }
4448   return ret;
4449 }
4450
4451 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4452 {
4453   std::vector<std::string> ret;
4454   std::set<std::string> ret2;
4455   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4456     {
4457       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4458       ret.insert(ret.end(),tmp.begin(),tmp.end());
4459     }
4460   return ret;
4461 }
4462
4463 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4464 {
4465   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4466     (*it)->changePflsRefsNamesGen(mapOfModif);
4467 }
4468
4469 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4470 {
4471   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4472     (*it)->changeLocsRefsNamesGen(mapOfModif);
4473 }
4474
4475 /*!
4476  * Returns all attributes of parts of \a this field lying on a given mesh.
4477  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4478  * item of every of returned sequences refers to the _i_-th part of \a this field.
4479  * Thus all sequences returned by this method are of the same length equal to number
4480  * of different types of supporting entities.<br>
4481  * A field part can include sub-parts with several different spatial discretizations,
4482  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4483  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4484  * of a nested sequence corresponds to a type of spatial discretization.<br>
4485  * This method allows for iteration over MEDFile DataStructure without any overhead.
4486  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4487  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4488  *          not checked if \a mname == \c NULL).
4489  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4490  *          a field part is returned. 
4491  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4492  *          This sequence is of the same length as \a types. 
4493  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4494  *          discretization. A profile name can be empty.
4495  *          Length of this and of nested sequences is the same as that of \a typesF.
4496  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4497  *          discretization. A localization name can be empty.
4498  *          Length of this and of nested sequences is the same as that of \a typesF.
4499  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4500  *          of ids of tuples within the data array, per each type of spatial
4501  *          discretization within one mesh entity type. 
4502  *          Length of this and of nested sequences is the same as that of \a typesF.
4503  *  \throw If no field is lying on \a mname.
4504  */
4505 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
4506 {
4507   int meshId=0;
4508   if(!mname.empty())
4509     meshId=getMeshIdFromMeshName(mname);
4510   else
4511     if(_field_per_mesh.empty())
4512       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4513   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4514 }
4515
4516 /*!
4517  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4518  * maximal absolute dimension and values returned via the out parameter \a levs are 
4519  * dimensions relative to the maximal absolute dimension. <br>
4520  * This method is designed for MEDFileField1TS instances that have a discretization
4521  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4522  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4523  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4524  * Only these 3 discretizations will be taken into account here. If \a this is
4525  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4526  * This method is useful to make the link between the dimension of the underlying mesh
4527  * and the levels of \a this, because it is possible that the highest dimension of \a this
4528  * field is not equal to the dimension of the underlying mesh.
4529  * 
4530  * Let's consider the following case:
4531  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4532  * TETRA4, HEXA8, TRI3 and SEG2.
4533  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4534  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4535  *
4536  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4537  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4538  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4539  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4540  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4541  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4542  * For example<br>
4543  * to retrieve the highest level of
4544  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4545  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4546  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4547  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4548  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4549  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4550  *          not checked if \a mname == \c NULL).
4551  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4552  *          absolute one. They are in decreasing order. This sequence is cleared before
4553  *          filling it in.
4554  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4555  *  \throw If no field is lying on \a mname.
4556  */
4557 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4558 {
4559   levs.clear();
4560   int meshId=getMeshIdFromMeshName(mname);
4561   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4562   std::vector< std::vector<TypeOfField> > typesF;
4563   std::vector< std::vector<std::string> > pfls, locs;
4564   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4565   if(types.empty())
4566     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4567   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4568   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4569     return -1;
4570   st.erase(INTERP_KERNEL::NORM_ERROR);
4571   std::set<int> ret1;
4572   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4573     {
4574       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4575       ret1.insert((int)cm.getDimension());
4576     }
4577   int ret=*std::max_element(ret1.begin(),ret1.end());
4578   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4579   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4580   return ret;
4581 }
4582
4583 void MEDFileAnyTypeField1TSWithoutSDA::convertMedBallIntoClassic()
4584 {
4585   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it<_field_per_mesh.end();it++)
4586     if((*it).isNotNull())
4587       (*it)->convertMedBallIntoClassic();
4588 }
4589
4590 /*!
4591  * \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.
4592  * \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.
4593  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4594  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4595  */
4596 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4597 {
4598   int mid=getMeshIdFromMeshName(mName);
4599   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4600 }
4601
4602 /*!
4603  * \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.
4604  * \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.
4605  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4606  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4607  */
4608 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4609 {
4610   int mid=getMeshIdFromMeshName(mName);
4611   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4612 }
4613
4614 /*!
4615  * \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.
4616  */
4617 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4618 {
4619   if(_field_per_mesh.empty())
4620     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4621   if(mName.empty())
4622     return 0;
4623   std::string mName2(mName);
4624   int ret=0;
4625   std::vector<std::string> msg;
4626   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4627     if(mName2==(*it)->getMeshName())
4628       return ret;
4629     else
4630       msg.push_back((*it)->getMeshName());
4631   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4632   oss << "Possible meshes are : ";
4633   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4634     oss << "\"" << (*it2) << "\" ";
4635   throw INTERP_KERNEL::Exception(oss.str());
4636 }
4637
4638 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4639 {
4640   if(!mesh)
4641     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4642   std::string tmp(mesh->getName());
4643   if(tmp.empty())
4644     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4645   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4646   int i=0;
4647   for(;it!=_field_per_mesh.end();it++,i++)
4648     {
4649       if((*it)->getMeshName()==tmp)
4650         return i;
4651     }
4652   int sz=_field_per_mesh.size();
4653   _field_per_mesh.resize(sz+1);
4654   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4655   return sz;
4656 }
4657
4658 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4659                                                                    MEDFileFieldGlobsReal& glob)
4660 {
4661   bool ret=false;
4662   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4663     {
4664       MEDFileFieldPerMesh *fpm(*it);
4665       if(fpm)
4666         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4667     }
4668   return ret;
4669 }
4670
4671 /*!
4672  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4673  * splitting that leads to single spatial discretization of this.
4674  *
4675  * \sa splitMultiDiscrPerGeoTypes
4676  */
4677 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4678 {
4679   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4680   std::vector< std::vector<TypeOfField> > typesF;
4681   std::vector< std::vector<std::string> > pfls,locs;
4682   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4683   std::set<TypeOfField> allEnt;
4684   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4685     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4686       allEnt.insert(*it2);
4687   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4688   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4689   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4690     {
4691       std::vector< std::pair<int,int> > its;
4692       ret[i]=shallowCpy();
4693       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4694       ret[i]->updateData(newLgth,its);
4695     }
4696   return ret;
4697 }
4698
4699 /*!
4700  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4701  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4702  *
4703  * \sa splitDiscretizations
4704  */
4705 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4706 {
4707   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4708   std::vector< std::vector<TypeOfField> > typesF;
4709   std::vector< std::vector<std::string> > pfls,locs;
4710   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4711   std::set<TypeOfField> allEnt;
4712   std::size_t nbOfMDPGT(0),ii(0);
4713   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4714     {
4715       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4716       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4717         allEnt.insert(*it2);
4718     }
4719   if(allEnt.size()!=1)
4720     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4721   if(nbOfMDPGT==0)
4722     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4723   if(nbOfMDPGT==1)
4724     {
4725       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4726       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4727       return ret0;
4728     }
4729   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4730   for(std::size_t i=0;i<nbOfMDPGT;i++)
4731     {
4732       std::vector< std::pair<int,int> > its;
4733       ret[i]=shallowCpy();
4734       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4735       ret[i]->updateData(newLgth,its);
4736     }
4737   return ret;
4738 }
4739
4740 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4741 {
4742   int globalCounter(0);
4743   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4744     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4745   return globalCounter;
4746 }
4747
4748 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4749 {
4750   int globalCounter(0);
4751   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4752     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4753   return globalCounter;
4754 }
4755
4756 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4757 {
4758   if(_nb_of_tuples_to_be_allocated>=0)
4759     {
4760       _nb_of_tuples_to_be_allocated=newLgth;
4761       const DataArray *oldArr(getUndergroundDataArray());
4762       if(oldArr)
4763         {
4764           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4765           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4766           setArray(newArr);
4767           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4768         }
4769       return ;
4770     }
4771   if(_nb_of_tuples_to_be_allocated==-1)
4772     return ;
4773   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4774     {
4775       const DataArray *oldArr(getUndergroundDataArray());
4776       if(!oldArr || !oldArr->isAllocated())
4777         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4778       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4779       newArr->alloc(newLgth,getNumberOfComponents());
4780       if(oldArr)
4781         newArr->copyStringInfoFrom(*oldArr);
4782       int pos=0;
4783       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4784         {
4785           if((*it).second<(*it).first)
4786             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4787           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4788           pos+=(*it).second-(*it).first;
4789         }
4790       setArray(newArr);
4791       return ;
4792     }
4793   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4794 }
4795
4796 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4797 {
4798   if(_field_per_mesh.empty())
4799     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4800   if(_field_per_mesh.size()>1)
4801     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4802   _field_per_mesh[0]->copyOptionsFrom(opts);
4803   _field_per_mesh[0]->writeLL(fid,nasc);
4804 }
4805
4806 /*!
4807  * 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.
4808  * If false is returned the memory allocation is not required.
4809  */
4810 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4811 {
4812   if(_nb_of_tuples_to_be_allocated>=0)
4813     {
4814       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4815       _nb_of_tuples_to_be_allocated=-2;
4816       return true;
4817     }
4818   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4819     return false;
4820   if(_nb_of_tuples_to_be_allocated==-1)
4821     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4822   if(_nb_of_tuples_to_be_allocated<-3)
4823     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4824   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4825 }
4826
4827 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4828 {
4829   med_int numdt,numit;
4830   med_float dt;
4831   med_int nmesh;
4832   med_bool localMesh;
4833   med_int meshnumdt,meshnumit;
4834   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4835   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4836   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4837   if(_iteration!=numdt || _order!=numit)
4838     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4839   _field_per_mesh.resize(nmesh);
4840   //
4841   MEDFileMesh *mm(0);
4842   if(ms)
4843     {
4844       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4845       mm=ms->getMeshWithName(meshNameCpp);
4846     }
4847   //
4848   for(int i=0;i<nmesh;i++)
4849     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4850   _nb_of_tuples_to_be_allocated=0;
4851   for(int i=0;i<nmesh;i++)
4852     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4853 }
4854
4855 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4856 {
4857   allocIfNecessaryTheArrayToReceiveDataFromFile();
4858   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4859     (*it)->loadBigArraysRecursively(fid,nasc);
4860 }
4861
4862 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4863 {
4864   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4865     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4866       (*it)->loadBigArraysRecursively(fid,nasc);
4867 }
4868
4869 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4870 {
4871   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4872   loadBigArraysRecursively(fid,nasc);
4873 }
4874
4875 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4876 {
4877   DataArray *thisArr(getUndergroundDataArray());
4878   if(thisArr && thisArr->isAllocated())
4879     {
4880       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4881       thisArr->desallocate();
4882     }
4883 }
4884
4885 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4886 {
4887   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4888 }
4889
4890 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4891 {
4892   std::vector<const BigMemoryObject *> ret;
4893   if(getUndergroundDataArray())
4894     ret.push_back(getUndergroundDataArray());
4895   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4896     ret.push_back((const MEDFileFieldPerMesh *)*it);
4897   return ret;
4898 }
4899
4900 /*!
4901  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4902  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4903  * "Sort By Type"), if not, an exception is thrown. 
4904  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4905  *  \param [in] arr - the array of values.
4906  *  \param [in,out] glob - the global data where profiles and localization present in
4907  *          \a field, if any, are added.
4908  *  \throw If the name of \a field is empty.
4909  *  \throw If the data array of \a field is not set.
4910  *  \throw If \a this->_arr is already allocated but has different number of components
4911  *         than \a field.
4912  *  \throw If the underlying mesh of \a field has no name.
4913  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4914  */
4915 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4916 {
4917   const MEDCouplingMesh *mesh=field->getMesh();
4918   //
4919   TypeOfField type=field->getTypeOfField();
4920   std::vector<DataArrayInt *> dummy;
4921   int start=copyTinyInfoFrom(field,arr);
4922   int pos=addNewEntryIfNecessary(mesh);
4923   if(type!=ON_NODES)
4924     {
4925       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4926       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4927     }
4928   else
4929     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4930 }
4931
4932 /*!
4933  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4934  * of a given mesh are used as the support of the given field (a real support is not used). 
4935  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4936  * Order of underlying mesh entities of the given field specified by \a profile parameter
4937  * is not prescribed; this method permutes field values to have them sorted by element
4938  * type as required for writing to MED file. A new profile is added only if no equal
4939  * profile is missing. 
4940  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4941  *  \param [in] arrOfVals - the values of the field \a field used.
4942  *  \param [in] mesh - the supporting mesh of \a field.
4943  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4944  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4945  *  \param [in,out] glob - the global data where profiles and localization present in
4946  *          \a field, if any, are added.
4947  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4948  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
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  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4953  *  \sa setFieldNoProfileSBT()
4954  */
4955 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4956 {
4957   if(!field)
4958     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4959   if(!arrOfVals || !arrOfVals->isAllocated())
4960     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4961   TypeOfField type=field->getTypeOfField();
4962   std::vector<DataArrayInt *> idsInPflPerType;
4963   std::vector<DataArrayInt *> idsPerType;
4964   std::vector<int> code,code2;
4965   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4966   if(type!=ON_NODES)
4967     {
4968       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4969       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4970       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4971       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4972       // start of check
4973       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4974       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4975       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4976         {
4977           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4978           throw INTERP_KERNEL::Exception(oss.str());
4979         }
4980       // end of check
4981       int start=copyTinyInfoFrom(field,arrOfVals);
4982       code2=m->getDistributionOfTypes();
4983       //
4984       int pos=addNewEntryIfNecessary(m);
4985       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4986     }
4987   else
4988     {
4989       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4990         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4991       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4992       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4993       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4994       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4995         {
4996           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4997           throw INTERP_KERNEL::Exception(oss.str());
4998         }
4999       int start=copyTinyInfoFrom(field,arrOfVals);
5000       int pos=addNewEntryIfNecessary(m);
5001       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
5002     }
5003 }
5004
5005 /*!
5006  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
5007  */
5008 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
5009 {
5010   if(_nb_of_tuples_to_be_allocated>=0)
5011     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 !");
5012   DataArray *arr(getOrCreateAndGetArray());
5013   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
5014   _nb_of_tuples_to_be_allocated=-3;
5015 }
5016
5017 /*!
5018  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
5019  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
5020  * larger by the size of \a field. Returns an id of the first not filled
5021  * tuple of \a this->_arr.
5022  *  \param [in] field - the field to copy the info on components and the name from.
5023  *  \return int - the id of first not initialized tuple of \a this->_arr.
5024  *  \throw If the name of \a field is empty.
5025  *  \throw If the data array of \a field is not set.
5026  *  \throw If \a this->_arr is already allocated but has different number of components
5027  *         than \a field.
5028  */
5029 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
5030 {
5031   if(!field)
5032     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
5033   std::string name(field->getName());
5034   setName(name.c_str());
5035   setDtUnit(field->getTimeUnit());
5036   if(name.empty())
5037     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
5038   if(!arr)
5039     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
5040   if(!arr->isAllocated())
5041     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
5042   _dt=field->getTime(_iteration,_order);
5043   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
5044   if(!getOrCreateAndGetArray()->isAllocated())
5045     {
5046       allocNotFromFile(arr->getNumberOfTuples());
5047       return 0;
5048     }
5049   else
5050     {
5051       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
5052       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
5053       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
5054       _nb_of_tuples_to_be_allocated=-3;
5055       return oldNbOfTuples;
5056     }
5057 }
5058
5059 /*!
5060  * Returns number of components in \a this field
5061  *  \return int - the number of components.
5062  */
5063 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
5064 {
5065   return getOrCreateAndGetArray()->getNumberOfComponents();
5066 }
5067
5068 /*!
5069  * Change info on components in \a this.
5070  * \throw If size of \a infos is not equal to the number of components already in \a this.
5071  */
5072 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
5073 {
5074   DataArray *arr=getOrCreateAndGetArray();
5075   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
5076 }
5077
5078 /*!
5079  * Returns info on components of \a this field.
5080  *  \return const std::vector<std::string>& - a sequence of strings each being an
5081  *          information on _i_-th component.
5082  */
5083 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
5084 {
5085   const DataArray *arr=getOrCreateAndGetArray();
5086   return arr->getInfoOnComponents();
5087 }
5088
5089 /*!
5090  * Returns a mutable info on components of \a this field.
5091  *  \return std::vector<std::string>& - a sequence of strings each being an
5092  *          information on _i_-th component.
5093  */
5094 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
5095 {
5096   DataArray *arr=getOrCreateAndGetArray();
5097   return arr->getInfoOnComponents();
5098 }
5099
5100 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
5101 {
5102   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5103     {
5104       const MEDFileFieldPerMesh *fpm(*it);
5105       if(!fpm)
5106         continue;
5107       if(fpm->presenceOfMultiDiscPerGeoType())
5108         return true;
5109     }
5110   return false;
5111 }
5112
5113 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
5114 {
5115   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5116     if((*it).isNotNull())
5117       if((*it)->presenceOfStructureElements())
5118         return true;
5119   return false;
5120 }
5121
5122 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
5123 {
5124   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5125     if((*it).isNotNull())
5126       if(!(*it)->onlyStructureElements())
5127         return false;
5128   return true;
5129 }
5130
5131 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
5132 {
5133   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5134     if((*it).isNotNull())
5135       (*it)->killStructureElements();
5136 }
5137
5138 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
5139 {
5140   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5141     if((*it).isNotNull())
5142       (*it)->keepOnlyStructureElements();
5143 }
5144
5145 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName)
5146 {
5147   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5148     if((*it).isNotNull())
5149       (*it)->keepOnlyOnSE(seName);
5150 }
5151
5152 void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
5153 {
5154   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5155     if((*it).isNotNull())
5156       (*it)->getMeshSENames(ps);
5157 }
5158
5159 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5160 {
5161   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 !";
5162   if(_field_per_mesh.empty())
5163     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
5164   if(_field_per_mesh.size()>1)
5165     throw INTERP_KERNEL::Exception(MSG0);
5166   if(_field_per_mesh[0].isNull())
5167     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
5168   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
5169   std::set<TypeOfField> types;
5170   pm->fillTypesOfFieldAvailable(types);
5171   if(types.size()!=1)
5172     throw INTERP_KERNEL::Exception(MSG0);
5173   TypeOfField type(*types.begin());
5174   int meshDimRelToMax(0);
5175   if(type==ON_NODES)
5176     meshDimRelToMax=0;
5177   else
5178     {
5179       int myDim(std::numeric_limits<int>::max());
5180       bool isUnique(pm->isUniqueLevel(myDim));
5181       if(!isUnique)
5182         throw INTERP_KERNEL::Exception(MSG0);
5183       meshDimRelToMax=myDim-mesh->getMeshDimension();
5184       if(meshDimRelToMax>0)
5185         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5186     }
5187   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5188 }
5189
5190 /*!
5191  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5192  *  \param [in] type - a spatial discretization of the new field.
5193  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5194  *  \param [in] mName - a name of the supporting mesh.
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  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5204  *          caller is to delete this field using decrRef() as it is no more needed. 
5205  *  \throw If the MED file is not readable.
5206  *  \throw If there is no mesh named \a mName in the MED file.
5207  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5208  *  \throw If no field of \a this is lying on the mesh \a mName.
5209  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5210  */
5211 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5212 {
5213   MCAuto<MEDFileMesh> mm;
5214   if(mName.empty())
5215     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5216   else
5217     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5218   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5219 }
5220
5221 /*!
5222  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5223  *  \param [in] type - a spatial discretization of the new field.
5224  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5225  *  \param [in] renumPol - specifies how to permute values of the result field according to
5226  *          the optional numbers of cells and nodes, if any. The valid values are
5227  *          - 0 - do not permute.
5228  *          - 1 - permute cells.
5229  *          - 2 - permute nodes.
5230  *          - 3 - permute cells and nodes.
5231  *
5232  *  \param [in] glob - the global data storing profiles and localization.
5233  *  \param [in] mesh - the supporting mesh.
5234  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5235  *          caller is to delete this field using decrRef() as it is no more needed. 
5236  *  \throw If the MED file is not readable.
5237  *  \throw If no field of \a this is lying on \a mesh.
5238  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5239  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5240  */
5241 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5242 {
5243   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5244   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5245   if(meshDimRelToMax==1)
5246     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5247   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5248 }
5249
5250 /*!
5251  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5252  * given mesh. 
5253  *  \param [in] type - a spatial discretization of the new field.
5254  *  \param [in] mName - a name of the supporting mesh.
5255  *  \param [in] renumPol - specifies how to permute values of the result field according to
5256  *          the optional numbers of cells and nodes, if any. The valid values are
5257  *          - 0 - do not permute.
5258  *          - 1 - permute cells.
5259  *          - 2 - permute nodes.
5260  *          - 3 - permute cells and nodes.
5261  *
5262  *  \param [in] glob - the global data storing profiles and localization.
5263  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5264  *          caller is to delete this field using decrRef() as it is no more needed. 
5265  *  \throw If the MED file is not readable.
5266  *  \throw If there is no mesh named \a mName in the MED file.
5267  *  \throw If there are no mesh entities in the mesh.
5268  *  \throw If no field values of the given \a type are available.
5269  */
5270 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5271 {
5272   MCAuto<MEDFileMesh> mm;
5273   if(mName.empty())
5274     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5275   else
5276     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5277   int absDim=getDimension();
5278   int meshDimRelToMax=absDim-mm->getMeshDimension();
5279   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5280 }
5281
5282 /*!
5283  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5284  *  \param [in] type - a spatial discretization of the new field.
5285  *  \param [in] renumPol - specifies how to permute values of the result field according to
5286  *          the optional numbers of cells and nodes, if any. The valid values are
5287  *          - 0 - do not permute.
5288  *          - 1 - permute cells.
5289  *          - 2 - permute nodes.
5290  *          - 3 - permute cells and nodes.
5291  *
5292  *  \param [in] glob - the global data storing profiles and localization.
5293  *  \param [in] mesh - the supporting mesh.
5294  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5295  *         field according to \a renumPol.
5296  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5297  *         field according to \a renumPol.
5298  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5299  *          caller is to delete this field using decrRef() as it is no more needed. 
5300  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5301  *  \throw If no field of \a this is lying on \a mesh.
5302  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5303  */
5304 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
5305 {
5306   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5307   int meshId=getMeshIdFromMeshName(mesh->getName());
5308   bool isPfl=false;
5309   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5310   switch(renumPol)
5311   {
5312     case 0:
5313       {
5314         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5315         return ret.retn();
5316       }
5317     case 3:
5318     case 1:
5319       {
5320         if(isPfl)
5321           throw INTERP_KERNEL::Exception(msg1);
5322         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5323         if(cellRenum)
5324           {
5325             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5326               {
5327                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5328                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5329                 throw INTERP_KERNEL::Exception(oss.str());
5330               }
5331             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5332             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5333             std::vector<DataArray *> arrOut2(1,arrOut);
5334             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5335             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5336             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5337           }
5338         if(renumPol==1)
5339           return ret.retn();
5340       }
5341     case 2:
5342       {
5343         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5344         if(isPfl)
5345           throw INTERP_KERNEL::Exception(msg1);
5346         if(nodeRenum)
5347           {
5348             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5349               {
5350                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5351                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5352                 throw INTERP_KERNEL::Exception(oss.str());
5353               }
5354             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5355             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5356               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5357             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5358           }
5359         return ret.retn();
5360       }
5361     default:
5362       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5363   }
5364 }
5365
5366 /*!
5367  * Returns values and a profile of the field of a given type lying on a given support.
5368  *  \param [in] type - a spatial discretization of the field.
5369  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5370  *  \param [in] mesh - the supporting mesh.
5371  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5372  *          field of interest lies on. If the field lies on all entities of the given
5373  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5374  *          using decrRef() as it is no more needed.  
5375  *  \param [in] glob - the global data storing profiles and localization.
5376  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5377  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5378  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5379  *  \throw If no field of \a this is lying on \a mesh.
5380  *  \throw If no field values of the given \a type are available.
5381  */
5382 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5383 {
5384   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5385   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
5386   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5387   ret->setName(nasc.getName().c_str());
5388   return ret.retn();
5389 }
5390
5391 //= MEDFileField1TSWithoutSDA
5392
5393 /*!
5394  * Throws if a given value is not a valid (non-extended) relative dimension.
5395  *  \param [in] meshDimRelToMax - the relative dimension value.
5396  *  \throw If \a meshDimRelToMax > 0.
5397  */
5398 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5399 {
5400   if(meshDimRelToMax>0)
5401     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5402 }
5403
5404 /*!
5405  * Checks if elements of a given mesh are in the order suitable for writing 
5406  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5407  * vector describing types of elements and their number.
5408  *  \param [in] mesh - the mesh to check.
5409  *  \return std::vector<int> - a vector holding for each element type (1) item of
5410  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5411  *          These values are in full-interlace mode.
5412  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5413  */
5414 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5415 {
5416   if(!mesh)
5417     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5418   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5419   int nbOfTypes=geoTypes.size();
5420   std::vector<int> code(3*nbOfTypes);
5421   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5422   arr1->alloc(nbOfTypes,1);
5423   int *arrPtr=arr1->getPointer();
5424   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5425   for(int i=0;i<nbOfTypes;i++,it++)
5426     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5427   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5428   const int *arrPtr2=arr2->getConstPointer();
5429   int i=0;
5430   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5431     {
5432       int pos=arrPtr2[i];
5433       int nbCells=mesh->getNumberOfCellsWithType(*it);
5434       code[3*pos]=(int)(*it);
5435       code[3*pos+1]=nbCells;
5436       code[3*pos+2]=-1;//no profiles
5437     }
5438   std::vector<const DataArrayInt *> idsPerType;//no profiles
5439   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5440   if(da)
5441     {
5442       da->decrRef();
5443       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5444     }
5445   return code;
5446 }
5447
5448 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5449 {
5450   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5451 }
5452
5453 /*!
5454  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5455  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5456  * item of every of returned sequences refers to the _i_-th part of \a this field.
5457  * Thus all sequences returned by this method are of the same length equal to number
5458  * of different types of supporting entities.<br>
5459  * A field part can include sub-parts with several different spatial discretizations,
5460  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5461  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5462  * of a nested sequence corresponds to a type of spatial discretization.<br>
5463  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5464  * The overhead is due to selecting values into new instances of DataArrayDouble.
5465  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5466  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5467  *          not checked if \a mname == \c NULL).
5468  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5469  *          a field part is returned. 
5470  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5471  *          A field part can include sub-parts with several different spatial discretizations,
5472  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5473  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5474  *          This sequence is of the same length as \a types. 
5475  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5476  *          discretization. A profile name can be empty.
5477  *          Length of this and of nested sequences is the same as that of \a typesF.
5478  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5479  *          discretization. A localization name can be empty.
5480  *          Length of this and of nested sequences is the same as that of \a typesF.
5481  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5482  *          per each type of spatial discretization within one mesh entity type.
5483  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5484  *          Length of this and of nested sequences is the same as that of \a typesF.
5485  *  \throw If no field is lying on \a mname.
5486  */
5487 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
5488 {
5489   int meshId=0;
5490   if(!mname.empty())
5491     meshId=getMeshIdFromMeshName(mname);
5492   else
5493     if(_field_per_mesh.empty())
5494       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5495   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5496   int nbOfRet=ret0.size();
5497   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5498   for(int i=0;i<nbOfRet;i++)
5499     {
5500       const std::vector< std::pair<int,int> >& p=ret0[i];
5501       int nbOfRet1=p.size();
5502       ret[i].resize(nbOfRet1);
5503       for(int j=0;j<nbOfRet1;j++)
5504         {
5505           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5506           ret[i][j]=tmp;
5507         }
5508     }
5509   return ret;
5510 }
5511
5512 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5513 {
5514   return TYPE_STR;
5515 }
5516
5517 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5518 {
5519   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5520   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5521   ret->deepCpyLeavesFrom(*this);
5522   const DataArrayDouble *arr(_arr);
5523   if(arr)
5524     {
5525       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5526       ret->setArray(arr2);
5527     }
5528   return ret.retn();
5529 }
5530
5531 /*!
5532  * Returns a pointer to the underground DataArrayDouble instance and a
5533  * sequence describing parameters of a support of each part of \a this field. The
5534  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5535  * direct access to the field values. This method is intended for the field lying on one
5536  * mesh only.
5537  *  \param [in,out] entries - the sequence describing parameters of a support of each
5538  *         part of \a this field. Each item of this sequence consists of two parts. The
5539  *         first part describes a type of mesh entity and an id of discretization of a
5540  *         current field part. The second part describes a range of values [begin,end)
5541  *         within the returned array relating to the current field part.
5542  *  \return DataArrayDouble * - the pointer to the field values array.
5543  *  \throw If the number of underlying meshes is not equal to 1.
5544  *  \throw If no field values are available.
5545  *  \sa getUndergroundDataArray()
5546  */
5547 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5548 {
5549   if(_field_per_mesh.size()!=1)
5550     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5551   if(_field_per_mesh[0]==0)
5552     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5553   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5554   return getUndergroundDataArrayTemplate();
5555 }
5556
5557 /*!
5558  * Returns a pointer to the underground DataArrayDouble instance and a
5559  * sequence describing parameters of a support of each part of \a this field. The
5560  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5561  * direct access to the field values. This method is intended for the field lying on one
5562  * mesh only.
5563  *  \param [in,out] entries - the sequence describing parameters of a support of each
5564  *         part of \a this field. Each item of this sequence consists of two parts. The
5565  *         first part describes a type of mesh entity and an id of discretization of a
5566  *         current field part. The second part describes a range of values [begin,end)
5567  *         within the returned array relating to the current field part.
5568  *  \return DataArrayDouble * - the pointer to the field values array.
5569  *  \throw If the number of underlying meshes is not equal to 1.
5570  *  \throw If no field values are available.
5571  *  \sa getUndergroundDataArray()
5572  */
5573 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5574 {
5575   return getUndergroundDataArrayDoubleExt(entries);
5576 }
5577
5578 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,csit,iteration,order)
5579 {
5580   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5581   arr->setInfoAndChangeNbOfCompo(infos);
5582 }
5583
5584 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5585 {
5586 }
5587
5588 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5589 {
5590   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5591   ret->deepCpyLeavesFrom(*this);
5592   return ret.retn();
5593 }
5594
5595 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5596 {
5597   MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
5598   if(_arr.isNotNull())
5599     ret->_arr=_arr->deepCopy();
5600   return ret.retn();
5601 }
5602
5603 //= MEDFileIntField1TSWithoutSDA
5604
5605 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5606 {
5607   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5608 }
5609
5610 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5611 {
5612 }
5613
5614 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5615                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,csit,iteration,order)
5616 {
5617   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5618   arr->setInfoAndChangeNbOfCompo(infos);
5619 }
5620
5621 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5622 {
5623   return TYPE_STR;
5624 }
5625
5626 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5627 {
5628   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5629   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5630   ret->deepCpyLeavesFrom(*this);
5631   const DataArrayInt *arr(_arr);
5632   if(arr)
5633     {
5634       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5635       ret->setArray(arr2);
5636     }
5637   return ret.retn();
5638 }
5639
5640 /*!
5641  * Returns a pointer to the underground DataArrayInt instance and a
5642  * sequence describing parameters of a support of each part of \a this field. The
5643  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5644  * direct access to the field values. This method is intended for the field lying on one
5645  * mesh only.
5646  *  \param [in,out] entries - the sequence describing parameters of a support of each
5647  *         part of \a this field. Each item of this sequence consists of two parts. The
5648  *         first part describes a type of mesh entity and an id of discretization of a
5649  *         current field part. The second part describes a range of values [begin,end)
5650  *         within the returned array relating to the current field part.
5651  *  \return DataArrayInt * - the pointer to the field values array.
5652  *  \throw If the number of underlying meshes is not equal to 1.
5653  *  \throw If no field values are available.
5654  *  \sa getUndergroundDataArray()
5655  */
5656 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5657 {
5658   return getUndergroundDataArrayIntExt(entries);
5659 }
5660
5661 /*!
5662  * Returns a pointer to the underground DataArrayInt instance and a
5663  * sequence describing parameters of a support of each part of \a this field. The
5664  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5665  * direct access to the field values. This method is intended for the field lying on one
5666  * mesh only.
5667  *  \param [in,out] entries - the sequence describing parameters of a support of each
5668  *         part of \a this field. Each item of this sequence consists of two parts. The
5669  *         first part describes a type of mesh entity and an id of discretization of a
5670  *         current field part. The second part describes a range of values [begin,end)
5671  *         within the returned array relating to the current field part.
5672  *  \return DataArrayInt * - the pointer to the field values array.
5673  *  \throw If the number of underlying meshes is not equal to 1.
5674  *  \throw If no field values are available.
5675  *  \sa getUndergroundDataArray()
5676  */
5677 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5678 {
5679   if(_field_per_mesh.size()!=1)
5680     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5681   if(_field_per_mesh[0]==0)
5682     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5683   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5684   return getUndergroundDataArrayTemplate();
5685 }
5686
5687 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5688 {
5689   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5690   ret->deepCpyLeavesFrom(*this);
5691   return ret.retn();
5692 }
5693
5694 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5695 {
5696   MCAuto<MEDFileIntField1TSWithoutSDA> ret(shallowCpy());
5697   if(_arr.isNotNull())
5698     ret->_arr=_arr->deepCopy();
5699   return ret.retn();
5700 }
5701
5702 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5703 {
5704 }
5705
5706 //= MEDFileAnyTypeField1TS
5707
5708 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5709 {
5710   med_field_type typcha;
5711   //
5712   std::vector<std::string> infos;
5713   std::string dtunit,fieldName;
5714   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
5715   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5716   switch(typcha)
5717   {
5718     case MED_FLOAT64:
5719       {
5720         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5721         break;
5722       }
5723     case MED_INT32:
5724       {
5725         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5726         break;
5727       }
5728     default:
5729       {
5730         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] !";
5731         throw INTERP_KERNEL::Exception(oss.str());
5732       }
5733   }
5734   ret->setDtUnit(dtunit.c_str());
5735   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5736   //
5737   med_int numdt,numit;
5738   med_float dt;
5739   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5740   ret->setTime(numdt,numit,dt);
5741   ret->_csit=1;
5742   if(loadAll)
5743     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5744   else
5745     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5746   return ret.retn();
5747 }
5748
5749 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5750 try:MEDFileFieldGlobsReal(fid)
5751 {
5752   _content=BuildContentFrom(fid,loadAll,ms);
5753   loadGlobals(fid);
5754 }
5755 catch(INTERP_KERNEL::Exception& e)
5756 {
5757     throw e;
5758 }
5759
5760 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5761 {
5762   med_field_type typcha;
5763   std::vector<std::string> infos;
5764   std::string dtunit;
5765   int iii=-1;
5766   int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit);
5767   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5768   switch(typcha)
5769   {
5770     case MED_FLOAT64:
5771       {
5772         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5773         break;
5774       }
5775     case MED_INT32:
5776       {
5777         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5778         break;
5779       }
5780     default:
5781       {
5782         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] !";
5783         throw INTERP_KERNEL::Exception(oss.str());
5784       }
5785   }
5786   ret->setDtUnit(dtunit.c_str());
5787   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5788   //
5789   if(nbSteps<1)
5790     {
5791       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5792       throw INTERP_KERNEL::Exception(oss.str());
5793     }
5794   //
5795   med_int numdt,numit;
5796   med_float dt;
5797   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5798   ret->setTime(numdt,numit,dt);
5799   ret->_csit=1;
5800   if(loadAll)
5801     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5802   else
5803     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5804   return ret.retn();
5805 }
5806
5807 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5808 try:MEDFileFieldGlobsReal(fid)
5809 {
5810   _content=BuildContentFrom(fid,fieldName,loadAll,ms);
5811   loadGlobals(fid);
5812 }
5813 catch(INTERP_KERNEL::Exception& e)
5814 {
5815     throw e;
5816 }
5817
5818 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
5819 {
5820   if(!c)
5821     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5822   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5823     {
5824       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
5825       ret->_content=c; c->incrRef();
5826       return ret.retn();
5827     }
5828   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5829     {
5830       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
5831       ret->_content=c; c->incrRef();
5832       return ret.retn();
5833     }
5834   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5835 }
5836
5837 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
5838 {
5839   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
5840   ret->setFileName(FileNameFromFID(fid));
5841   return ret;
5842 }
5843
5844 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5845 {
5846   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5847   return New(fid,loadAll);
5848 }
5849
5850 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
5851 {
5852   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
5853   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5854   ret->loadGlobals(fid);
5855   return ret.retn();
5856 }
5857
5858 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5859 {
5860   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5861   return New(fid,fieldName,loadAll);
5862 }
5863
5864 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
5865 {
5866   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0));
5867   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5868   ret->loadGlobals(fid);
5869   return ret.retn();
5870 }
5871
5872 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5873 {
5874   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5875   return New(fid,fieldName,iteration,order,loadAll);
5876 }
5877
5878 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
5879 {
5880   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0));
5881   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5882   ret->loadGlobals(fid);
5883   return ret.retn();
5884 }
5885
5886 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5887 {
5888   med_field_type typcha;
5889   std::vector<std::string> infos;
5890   std::string dtunit;
5891   int iii(-1);
5892   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit));
5893   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5894   switch(typcha)
5895   {
5896     case MED_FLOAT64:
5897       {
5898         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5899         break;
5900       }
5901     case MED_INT32:
5902       {
5903         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5904         break;
5905       }
5906     default:
5907       {
5908         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] !";
5909         throw INTERP_KERNEL::Exception(oss.str());
5910       }
5911   }
5912   ret->setDtUnit(dtunit.c_str());
5913   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5914   //
5915   bool found=false;
5916   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5917   for(int i=0;i<nbOfStep2 && !found;i++)
5918     {
5919       med_int numdt,numit;
5920       med_float dt;
5921       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5922       if(numdt==iteration && numit==order)
5923         {
5924           found=true;
5925           ret->_csit=i+1;
5926         }
5927       else
5928         dtits[i]=std::pair<int,int>(numdt,numit);
5929     }
5930   if(!found)
5931     {
5932       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
5933       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5934         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5935       throw INTERP_KERNEL::Exception(oss.str());
5936     }
5937   if(loadAll)
5938     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5939   else
5940     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5941   return ret.retn();
5942 }
5943
5944 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5945 try:MEDFileFieldGlobsReal(fid)
5946 {
5947   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms);
5948   loadGlobals(fid);
5949 }
5950 catch(INTERP_KERNEL::Exception& e)
5951 {
5952     throw e;
5953 }
5954
5955 /*!
5956  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5957  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5958  *
5959  * \warning this is a shallow copy constructor
5960  */
5961 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5962 {
5963   if(!shallowCopyOfContent)
5964     {
5965       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5966       otherPtr->incrRef();
5967       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5968     }
5969   else
5970     {
5971       _content=other.shallowCpy();
5972     }
5973 }
5974
5975 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)
5976 {
5977   if(checkFieldId)
5978     {
5979       int nbFields=MEDnField(fid);
5980       if(fieldIdCFormat>=nbFields)
5981         {
5982           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5983           throw INTERP_KERNEL::Exception(oss.str());
5984         }
5985     }
5986   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5987   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5988   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5989   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5990   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5991   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5992   med_bool localMesh;
5993   int nbOfStep;
5994   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5995   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5996   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5997   infos.clear(); infos.resize(ncomp);
5998   for(int j=0;j<ncomp;j++)
5999     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
6000   return nbOfStep;
6001 }
6002
6003 /*!
6004  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
6005  * 
6006  * \param [out]
6007  * \return in case of success the number of time steps available for the field with name \a fieldName.
6008  */
6009 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
6010 {
6011   int nbFields=MEDnField(fid);
6012   bool found=false;
6013   std::vector<std::string> fns(nbFields);
6014   int nbOfStep2(-1);
6015   for(int i=0;i<nbFields && !found;i++)
6016     {
6017       std::string tmp;
6018       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut);
6019       fns[i]=tmp;
6020       found=(tmp==fieldName);
6021       if(found)
6022         posCFormat=i;
6023     }
6024   if(!found)
6025     {
6026       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
6027       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
6028         oss << "\"" << *it << "\" ";
6029       throw INTERP_KERNEL::Exception(oss.str());
6030     }
6031   return nbOfStep2;
6032 }
6033
6034 /*!
6035  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6036  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6037  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6038  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6039  * to keep a valid instance.
6040  * 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.
6041  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
6042  * 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.
6043  *
6044  * \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.
6045  * \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.
6046  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6047  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6048  * \param [in] newLocName is the new localization name.
6049  * \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.
6050  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
6051  */
6052 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
6053 {
6054   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6055   std::string oldPflName=disc->getProfile();
6056   std::vector<std::string> vv=getPflsReallyUsedMulti();
6057   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
6058   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
6059     {
6060       disc->setProfile(newPflName);
6061       DataArrayInt *pfl=getProfile(oldPflName.c_str());
6062       pfl->setName(newPflName);
6063     }
6064   else
6065     {
6066       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
6067       throw INTERP_KERNEL::Exception(oss.str());
6068     }
6069 }
6070
6071 /*!
6072  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
6073  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6074  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6075  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6076  * to keep a valid instance.
6077  * 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.
6078  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
6079  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
6080  * 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.
6081  *
6082  * \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.
6083  * \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.
6084  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6085  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6086  * \param [in] newLocName is the new localization name.
6087  * \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.
6088  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
6089  */
6090 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
6091 {
6092   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6093   std::string oldLocName=disc->getLocalization();
6094   std::vector<std::string> vv=getLocsReallyUsedMulti();
6095   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
6096   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
6097     {
6098       disc->setLocalization(newLocName);
6099       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
6100       loc.setName(newLocName);
6101     }
6102   else
6103     {
6104       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
6105       throw INTERP_KERNEL::Exception(oss.str());
6106     }
6107 }
6108
6109 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
6110 {
6111   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6112   if(!ret)
6113     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
6114   return ret;
6115 }
6116
6117 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
6118 {
6119   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6120   if(!ret)
6121     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
6122   return ret;
6123 }
6124
6125 /*!
6126  * This method alloc the arrays and load potentially huge arrays contained in this field.
6127  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
6128  * This method can be also called to refresh or reinit values from a file.
6129  * 
6130  * \throw If the fileName is not set or points to a non readable MED file.
6131  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6132  */
6133 void MEDFileAnyTypeField1TS::loadArrays()
6134 {
6135   if(getFileName().empty())
6136     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
6137   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6138   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
6139 }
6140
6141 /*!
6142  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
6143  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
6144  * this method does not throw if \a this does not come from file read.
6145  * 
6146  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
6147  */
6148 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
6149 {
6150   if(!getFileName().empty())
6151     {
6152       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6153       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
6154     }
6155 }
6156
6157 /*!
6158  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
6159  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
6160  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
6161  * 
6162  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
6163  */
6164 void MEDFileAnyTypeField1TS::unloadArrays()
6165 {
6166   contentNotNullBase()->unloadArrays();
6167 }
6168
6169 /*!
6170  * 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.
6171  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
6172  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
6173  * 
6174  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6175  */
6176 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
6177 {
6178   if(!getFileName().empty())
6179     contentNotNullBase()->unloadArrays();
6180 }
6181
6182 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6183 {
6184   int nbComp(getNumberOfComponents());
6185   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6186   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6187   for(int i=0;i<nbComp;i++)
6188     {
6189       std::string info=getInfo()[i];
6190       std::string c,u;
6191       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6192       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6193       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6194     }
6195   if(getName().empty())
6196     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6197   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6198   writeGlobals(fid,*this);
6199   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6200 }
6201
6202 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6203 {
6204   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6205 }
6206
6207 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6208 {
6209   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6210   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6211   return ret;
6212 }
6213
6214 /*!
6215  * Returns a string describing \a this field. This string is outputted 
6216  * by \c print Python command.
6217  */
6218 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6219 {
6220   std::ostringstream oss;
6221   contentNotNullBase()->simpleRepr(0,oss,-1);
6222   simpleReprGlobs(oss);
6223   return oss.str();
6224 }
6225
6226 /*!
6227  * This method returns all profiles whose name is non empty used.
6228  * \b WARNING If profile is used several times it will be reported \b only \b once.
6229  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6230  */
6231 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6232 {
6233   return contentNotNullBase()->getPflsReallyUsed2();
6234 }
6235
6236 /*!
6237  * This method returns all localizations whose name is non empty used.
6238  * \b WARNING If localization is used several times it will be reported \b only \b once.
6239  */
6240 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6241 {
6242   return contentNotNullBase()->getLocsReallyUsed2();
6243 }
6244
6245 /*!
6246  * This method returns all profiles whose name is non empty used.
6247  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6248  */
6249 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6250 {
6251   return contentNotNullBase()->getPflsReallyUsedMulti2();
6252 }
6253
6254 /*!
6255  * This method returns all localizations whose name is non empty used.
6256  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6257  */
6258 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6259 {
6260   return contentNotNullBase()->getLocsReallyUsedMulti2();
6261 }
6262
6263 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6264 {
6265   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6266 }
6267
6268 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6269 {
6270   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6271 }
6272
6273 int MEDFileAnyTypeField1TS::getDimension() const
6274 {
6275   return contentNotNullBase()->getDimension();
6276 }
6277
6278 int MEDFileAnyTypeField1TS::getIteration() const
6279 {
6280   return contentNotNullBase()->getIteration();
6281 }
6282
6283 int MEDFileAnyTypeField1TS::getOrder() const
6284 {
6285   return contentNotNullBase()->getOrder();
6286 }
6287
6288 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6289 {
6290   return contentNotNullBase()->getTime(iteration,order);
6291 }
6292
6293 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6294 {
6295   contentNotNullBase()->setTime(iteration,order,val);
6296 }
6297
6298 std::string MEDFileAnyTypeField1TS::getName() const
6299 {
6300   return contentNotNullBase()->getName();
6301 }
6302
6303 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6304 {
6305   contentNotNullBase()->setName(name);
6306 }
6307
6308 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6309 {
6310   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6311 }
6312
6313 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6314 {
6315   return contentNotNullBase()->getDtUnit();
6316 }
6317
6318 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6319 {
6320   contentNotNullBase()->setDtUnit(dtUnit);
6321 }
6322
6323 std::string MEDFileAnyTypeField1TS::getMeshName() const
6324 {
6325   return contentNotNullBase()->getMeshName();
6326 }
6327
6328 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6329 {
6330   contentNotNullBase()->setMeshName(newMeshName);
6331 }
6332
6333 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6334 {
6335   return contentNotNullBase()->changeMeshNames(modifTab);
6336 }
6337
6338 int MEDFileAnyTypeField1TS::getMeshIteration() const
6339 {
6340   return contentNotNullBase()->getMeshIteration();
6341 }
6342
6343 int MEDFileAnyTypeField1TS::getMeshOrder() const
6344 {
6345   return contentNotNullBase()->getMeshOrder();
6346 }
6347
6348 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6349 {
6350   return contentNotNullBase()->getNumberOfComponents();
6351 }
6352
6353 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6354 {
6355   return contentNotNullBase()->isDealingTS(iteration,order);
6356 }
6357
6358 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6359 {
6360   return contentNotNullBase()->getDtIt();
6361 }
6362
6363 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6364 {
6365   contentNotNullBase()->fillIteration(p);
6366 }
6367
6368 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6369 {
6370   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6371 }
6372
6373 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6374 {
6375   contentNotNullBase()->setInfo(infos);
6376 }
6377
6378 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6379 {
6380   return contentNotNullBase()->getInfo();
6381 }
6382 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6383 {
6384   return contentNotNullBase()->getInfo();
6385 }
6386
6387 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6388 {
6389   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6390 }
6391
6392 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6393 {
6394   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6395 }
6396
6397 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6398 {
6399   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6400 }
6401
6402 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6403 {
6404   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6405 }
6406
6407 void MEDFileAnyTypeField1TS::convertMedBallIntoClassic()
6408 {
6409   return contentNotNullBase()->convertMedBallIntoClassic();
6410 }
6411
6412 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6413 {
6414   return contentNotNullBase()->getTypesOfFieldAvailable();
6415 }
6416
6417 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,
6418                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6419 {
6420   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6421 }
6422
6423 /*!
6424  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6425  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6426  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6427  */
6428 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6429 {
6430   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6431   if(!content)
6432     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6433   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6434   std::size_t sz(contentsSplit.size());
6435   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6436   for(std::size_t i=0;i<sz;i++)
6437     {
6438       ret[i]=shallowCpy();
6439       ret[i]->_content=contentsSplit[i];
6440     }
6441   return ret;
6442 }
6443
6444 /*!
6445  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6446  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6447  */
6448 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6449 {
6450   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6451   if(!content)
6452     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6453   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6454   std::size_t sz(contentsSplit.size());
6455   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6456   for(std::size_t i=0;i<sz;i++)
6457     {
6458       ret[i]=shallowCpy();
6459       ret[i]->_content=contentsSplit[i];
6460     }
6461   return ret;
6462 }
6463
6464 /*!
6465  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6466  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6467  */
6468 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6469 {
6470   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6471   if(!content)
6472     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6473   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6474   std::size_t sz(contentsSplit.size());
6475   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6476   for(std::size_t i=0;i<sz;i++)
6477     {
6478       ret[i]=shallowCpy();
6479       ret[i]->_content=contentsSplit[i];
6480     }
6481   return ret;
6482 }
6483
6484 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6485 {
6486   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6487   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6488     ret->_content=_content->deepCopy();
6489   ret->deepCpyGlobs(*this);
6490   return ret.retn();
6491 }
6492
6493 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6494 {
6495   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6496 }
6497
6498 //= MEDFileField1TS
6499
6500 /*!
6501  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6502  * the first field that has been read from a specified MED file.
6503  *  \param [in] fileName - the name of the MED file to read.
6504  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6505  *          is to delete this field using decrRef() as it is no more needed.
6506  *  \throw If reading the file fails.
6507  */
6508 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6509 {
6510   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6511   return New(fid,loadAll);
6512 }
6513
6514 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
6515 {
6516   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
6517   ret->contentNotNull();
6518   return ret.retn();
6519 }
6520
6521 /*!
6522  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6523  * a given field that has been read from a specified MED file.
6524  *  \param [in] fileName - the name of the MED file to read.
6525  *  \param [in] fieldName - the name of the field to read.
6526  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6527  *          is to delete this field using decrRef() as it is no more needed.
6528  *  \throw If reading the file fails.
6529  *  \throw If there is no field named \a fieldName in the file.
6530  */
6531 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6532 {
6533   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6534   return New(fid,fieldName,loadAll);
6535 }
6536
6537 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6538 {
6539   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
6540   ret->contentNotNull();
6541   return ret.retn();
6542 }
6543
6544 /*!
6545  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6546  * a given field that has been read from a specified MED file.
6547  *  \param [in] fileName - the name of the MED file to read.
6548  *  \param [in] fieldName - the name of the field to read.
6549  *  \param [in] iteration - the iteration number of a required time step.
6550  *  \param [in] order - the iteration order number of required time step.
6551  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6552  *          is to delete this field using decrRef() as it is no more needed.
6553  *  \throw If reading the file fails.
6554  *  \throw If there is no field named \a fieldName in the file.
6555  *  \throw If the required time step is missing from the file.
6556  */
6557 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6558 {
6559   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6560   return New(fid,fieldName,iteration,order,loadAll);
6561 }
6562
6563 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6564 {
6565   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
6566   ret->contentNotNull();
6567   return ret.retn();
6568 }
6569
6570 /*!
6571  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6572  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6573  *
6574  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6575  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6576  * \warning this is a shallow copy constructor
6577  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6578  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6579  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6580  *          is to delete this field using decrRef() as it is no more needed.
6581  */
6582 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6583 {
6584   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6585   ret->contentNotNull();
6586   return ret.retn();
6587 }
6588
6589 /*!
6590  * Returns a new empty instance of MEDFileField1TS.
6591  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6592  *          is to delete this field using decrRef() as it is no more needed.
6593  */
6594 MEDFileField1TS *MEDFileField1TS::New()
6595 {
6596   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6597   ret->contentNotNull();
6598   return ret.retn();
6599 }
6600
6601 /*!
6602  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6603  * following the given input policy.
6604  *
6605  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6606  *                            By default (true) the globals are deeply copied.
6607  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6608  */
6609 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6610 {
6611   MCAuto<MEDFileIntField1TS> ret;
6612   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6613   if(content)
6614     {
6615       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6616       if(!contc)
6617         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6618       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6619       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6620     }
6621   else
6622     ret=MEDFileIntField1TS::New();
6623   if(isDeepCpyGlobs)
6624     ret->deepCpyGlobs(*this);
6625   else
6626     ret->shallowCpyGlobs(*this);
6627   return ret.retn();
6628 }
6629
6630 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6631 {
6632   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6633   if(!pt)
6634     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6635   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6636   if(!ret)
6637     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 !");
6638   return ret;
6639 }
6640
6641 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6642 {
6643   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6644   if(!pt)
6645     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6646   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6647   if(!ret)
6648     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 !");
6649   return ret;
6650 }
6651
6652 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6653 {
6654   if(!f)
6655     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6656   if(arr.isNull())
6657     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6658   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6659   if(!arrOutC)
6660     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6661   f->setArray(arrOutC);
6662 }
6663
6664 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6665 {
6666   if(arr.isNull())
6667     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6668   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6669   if(!arrOutC)
6670     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6671   arrOutC->incrRef();
6672   return arrOutC;
6673 }
6674
6675 /*!
6676  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6677  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6678  *
6679  * \return A new object that the caller is responsible to deallocate.
6680  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6681  */
6682 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6683 {
6684   if(!mm)
6685     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6686   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6687   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6688   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6689     {
6690       if((*it0)!=ON_NODES)
6691         {
6692           std::vector<int> levs;
6693           getNonEmptyLevels(mm->getName(),levs);
6694           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6695             {
6696               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6697               if(it2!=extractDef.end())
6698                 {
6699                   MCAuto<DataArrayInt> t((*it2).second);
6700                   if(t.isNull())
6701                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6702                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6703                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6704                   ret->setFieldNoProfileSBT(fOut);
6705                 }
6706             }
6707         }
6708       else
6709         {
6710           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6711           if(it2==extractDef.end())
6712             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6713           MCAuto<DataArrayInt> t((*it2).second);
6714           if(t.isNull())
6715             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6716           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6717           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6718           DataArrayDouble *arr(f->getArray());
6719           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6720           fOut->setArray(newArr);
6721           ret->setFieldNoProfileSBT(fOut);
6722         }
6723     }
6724   return ret.retn();
6725 }
6726
6727 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6728 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6729 {
6730 }
6731 catch(INTERP_KERNEL::Exception& e)
6732 { throw e; }
6733
6734 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6735 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6736 {
6737 }
6738 catch(INTERP_KERNEL::Exception& e)
6739 { throw e; }
6740
6741 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6742 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6743 {
6744 }
6745 catch(INTERP_KERNEL::Exception& e)
6746 { throw e; }
6747
6748 /*!
6749  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6750  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6751  *
6752  * \warning this is a shallow copy constructor
6753  */
6754 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6755 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6756 {
6757 }
6758 catch(INTERP_KERNEL::Exception& e)
6759 { throw e; }
6760
6761 MEDFileField1TS::MEDFileField1TS()
6762 {
6763   _content=new MEDFileField1TSWithoutSDA;
6764 }
6765
6766 /*!
6767  * 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
6768  * method should be called (getFieldOnMeshAtLevel for example).
6769  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6770  *
6771  * \param [in] mesh - the mesh the field is lying on
6772  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6773  *          caller is to delete this field using decrRef() as it is no more needed. 
6774  */
6775 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6776 {
6777   MCAuto<DataArray> arrOut;
6778   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6779   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6780   return ret.retn();
6781 }
6782
6783 /*!
6784  * Returns a new MEDCouplingFieldDouble of a given type lying on
6785  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6786  * has not been constructed via file reading, an exception is thrown.
6787  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6788  *  \param [in] type - a spatial discretization of interest.
6789  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6790  *  \param [in] renumPol - specifies how to permute values of the result field according to
6791  *          the optional numbers of cells and nodes, if any. The valid values are
6792  *          - 0 - do not permute.
6793  *          - 1 - permute cells.
6794  *          - 2 - permute nodes.
6795  *          - 3 - permute cells and nodes.
6796  *
6797  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6798  *          caller is to delete this field using decrRef() as it is no more needed. 
6799  *  \throw If \a this field has not been constructed via file reading.
6800  *  \throw If the MED file is not readable.
6801  *  \throw If there is no mesh in the MED file.
6802  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6803  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6804  *  \sa getFieldOnMeshAtLevel()
6805  */
6806 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6807 {
6808   if(getFileName().empty())
6809     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6810   MCAuto<DataArray> arrOut;
6811   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6812   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6813   return ret.retn();
6814 }
6815
6816 /*!
6817  * Returns a new MEDCouplingFieldDouble of a given type lying on
6818  * the top level cells of the first mesh in MED file. If \a this field 
6819  * has not been constructed via file reading, an exception is thrown.
6820  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6821  *  \param [in] type - a spatial discretization of interest.
6822  *  \param [in] renumPol - specifies how to permute values of the result field according to
6823  *          the optional numbers of cells and nodes, if any. The valid values are
6824  *          - 0 - do not permute.
6825  *          - 1 - permute cells.
6826  *          - 2 - permute nodes.
6827  *          - 3 - permute cells and nodes.
6828  *
6829  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6830  *          caller is to delete this field using decrRef() as it is no more needed. 
6831  *  \throw If \a this field has not been constructed via file reading.
6832  *  \throw If the MED file is not readable.
6833  *  \throw If there is no mesh in the MED file.
6834  *  \throw If no field values of the given \a type.
6835  *  \throw If no field values lying on the top level support.
6836  *  \sa getFieldAtLevel()
6837  */
6838 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6839 {
6840   if(getFileName().empty())
6841     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6842   MCAuto<DataArray> arrOut;
6843   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6844   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6845   return ret.retn();
6846 }
6847
6848 /*!
6849  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6850  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6851  *  \param [in] type - a spatial discretization of the new field.
6852  *  \param [in] mesh - the supporting mesh.
6853  *  \param [in] renumPol - specifies how to permute values of the result field according to
6854  *          the optional numbers of cells and nodes, if any. The valid values are
6855  *          - 0 - do not permute.
6856  *          - 1 - permute cells.
6857  *          - 2 - permute nodes.
6858  *          - 3 - permute cells and nodes.
6859  *
6860  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6861  *          caller is to delete this field using decrRef() as it is no more needed. 
6862  *  \throw If no field of \a this is lying on \a mesh.
6863  *  \throw If the mesh is empty.
6864  *  \throw If no field values of the given \a type are available.
6865  *  \sa getFieldAtLevel()
6866  *  \sa getFieldOnMeshAtLevel() 
6867  */
6868 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6869 {
6870   MCAuto<DataArray> arrOut;
6871   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
6872   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6873   return ret.retn();
6874 }
6875
6876 /*!
6877  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6878  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6879  *  \param [in] type - a spatial discretization of interest.
6880  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6881  *  \param [in] mesh - the supporting mesh.
6882  *  \param [in] renumPol - specifies how to permute values of the result field according to
6883  *          the optional numbers of cells and nodes, if any. The valid values are
6884  *          - 0 - do not permute.
6885  *          - 1 - permute cells.
6886  *          - 2 - permute nodes.
6887  *          - 3 - permute cells and nodes.
6888  *
6889  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6890  *          caller is to delete this field using decrRef() as it is no more needed. 
6891  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6892  *  \throw If no field of \a this is lying on \a mesh.
6893  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6894  *  \sa getFieldAtLevel()
6895  *  \sa getFieldOnMeshAtLevel() 
6896  */
6897 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6898 {
6899   MCAuto<DataArray> arrOut;
6900   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
6901   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6902   return ret.retn();
6903 }
6904
6905 /*!
6906  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6907  * This method is called "Old" because in MED3 norm a field has only one meshName
6908  * attached, so this method is for readers of MED2 files. If \a this field 
6909  * has not been constructed via file reading, an exception is thrown.
6910  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6911  *  \param [in] type - a spatial discretization of interest.
6912  *  \param [in] mName - a name of the supporting mesh.
6913  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6914  *  \param [in] renumPol - specifies how to permute values of the result field according to
6915  *          the optional numbers of cells and nodes, if any. The valid values are
6916  *          - 0 - do not permute.
6917  *          - 1 - permute cells.
6918  *          - 2 - permute nodes.
6919  *          - 3 - permute cells and nodes.
6920  *
6921  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6922  *          caller is to delete this field using decrRef() as it is no more needed. 
6923  *  \throw If the MED file is not readable.
6924  *  \throw If there is no mesh named \a mName in the MED file.
6925  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6926  *  \throw If \a this field has not been constructed via file reading.
6927  *  \throw If no field of \a this is lying on the mesh named \a mName.
6928  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6929  *  \sa getFieldAtLevel()
6930  */
6931 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6932 {
6933   if(getFileName().empty())
6934     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6935   MCAuto<DataArray> arrOut;
6936   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
6937   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6938   return ret.retn();
6939 }
6940
6941 /*!
6942  * Returns values and a profile of the field of a given type lying on a given support.
6943  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6944  *  \param [in] type - a spatial discretization of the field.
6945  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6946  *  \param [in] mesh - the supporting mesh.
6947  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6948  *          field of interest lies on. If the field lies on all entities of the given
6949  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6950  *          using decrRef() as it is no more needed.  
6951  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6952  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6953  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6954  *  \throw If no field of \a this is lying on \a mesh.
6955  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6956  */
6957 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6958 {
6959   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6960   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6961 }
6962
6963 /*!
6964  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6965  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6966  * "Sort By Type"), if not, an exception is thrown. 
6967  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6968  *  \param [in] field - the field to add to \a this.
6969  *  \throw If the name of \a field is empty.
6970  *  \throw If the data array of \a field is not set.
6971  *  \throw If the data array is already allocated but has different number of components
6972  *         than \a field.
6973  *  \throw If the underlying mesh of \a field has no name.
6974  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6975  */
6976 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6977 {
6978   setFileName("");
6979   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6980 }
6981
6982 /*!
6983  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6984  * can be an aggregation of several MEDCouplingFieldDouble instances.
6985  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6986  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6987  * and \a profile.
6988  *
6989  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6990  * A new profile is added only if no equal profile is missing.
6991  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6992  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6993  *  \param [in] mesh - the supporting mesh of \a field.
6994  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6995  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6996  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6997  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6998  *  \throw If the data array of \a field is not set.
6999  *  \throw If the data array of \a this is already allocated but has different number of
7000  *         components than \a field.
7001  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7002  *  \sa setFieldNoProfileSBT()
7003  */
7004 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7005 {
7006   setFileName("");
7007   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7008 }
7009
7010 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
7011 {
7012   return new MEDFileField1TS(*this);
7013 }
7014
7015 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
7016 {
7017   return contentNotNull()->getUndergroundDataArrayTemplate();
7018 }
7019
7020 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7021 {
7022   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
7023 }
7024
7025 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
7026                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
7027 {
7028   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
7029 }
7030
7031 //= MEDFileIntField1TS
7032
7033 MEDFileIntField1TS *MEDFileIntField1TS::New()
7034 {
7035   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
7036   ret->contentNotNull();
7037   return ret.retn();
7038 }
7039
7040 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
7041 {
7042   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7043   return MEDFileIntField1TS::New(fid,loadAll);
7044 }
7045
7046 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
7047 {
7048   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
7049   ret->contentNotNull();
7050   return ret.retn();
7051 }
7052
7053 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
7054 {
7055   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7056   return MEDFileIntField1TS::New(fid,fieldName,loadAll);
7057 }
7058
7059 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
7060 {
7061   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
7062   ret->contentNotNull();
7063   return ret.retn();
7064 }
7065
7066 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
7067 {
7068   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7069   return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
7070 }
7071
7072 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
7073 {
7074   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
7075   ret->contentNotNull();
7076   return ret.retn();
7077 }
7078
7079 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
7080 {
7081   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
7082   ret->contentNotNull();
7083   return ret.retn();
7084 }
7085
7086 MEDFileIntField1TS::MEDFileIntField1TS()
7087 {
7088   _content=new MEDFileIntField1TSWithoutSDA;
7089 }
7090
7091 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
7092 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
7093 {
7094 }
7095 catch(INTERP_KERNEL::Exception& e)
7096 { throw e; }
7097
7098 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7099 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
7100 {
7101 }
7102 catch(INTERP_KERNEL::Exception& e)
7103 { throw e; }
7104
7105 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
7106 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
7107 {
7108 }
7109 catch(INTERP_KERNEL::Exception& e)
7110 { throw e; }
7111
7112 /*!
7113  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7114  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7115  *
7116  * \warning this is a shallow copy constructor
7117  */
7118 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
7119 {
7120 }
7121
7122 MEDFileIntField1TS *MEDFileIntField1TS::shallowCpy() const
7123 {
7124   return new MEDFileIntField1TS(*this);
7125 }
7126
7127 /*!
7128  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
7129  * following the given input policy.
7130  *
7131  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
7132  *                            By default (true) the globals are deeply copied.
7133  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
7134  */
7135 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
7136 {
7137   MCAuto<MEDFileField1TS> ret;
7138   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
7139   if(content)
7140     {
7141       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
7142       if(!contc)
7143         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
7144       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
7145       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
7146     }
7147   else
7148     ret=MEDFileField1TS::New();
7149   if(isDeepCpyGlobs)
7150     ret->deepCpyGlobs(*this);
7151   else
7152     ret->shallowCpyGlobs(*this);
7153   return ret.retn();
7154 }
7155
7156 /*!
7157  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
7158  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
7159  * "Sort By Type"), if not, an exception is thrown. 
7160  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7161  *  \param [in] field - the field to add to \a this.
7162  *  \throw If the name of \a field is empty.
7163  *  \throw If the data array of \a field is not set.
7164  *  \throw If the data array is already allocated but has different number of components
7165  *         than \a field.
7166  *  \throw If the underlying mesh of \a field has no name.
7167  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7168  */
7169 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
7170 {
7171   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7172   setFileName("");
7173   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
7174 }
7175
7176 /*!
7177  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
7178  * can be an aggregation of several MEDCouplingFieldDouble instances.
7179  * The mesh support of input parameter \a field is ignored here, it can be NULL.
7180  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
7181  * and \a profile.
7182  *
7183  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7184  * A new profile is added only if no equal profile is missing.
7185  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7186  *  \param [in] field - the field to add to \a this.
7187  *  \param [in] mesh - the supporting mesh of \a field.
7188  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7189  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7190  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7191  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7192  *  \throw If the data array of \a field is not set.
7193  *  \throw If the data array of \a this is already allocated but has different number of
7194  *         components than \a field.
7195  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7196  *  \sa setFieldNoProfileSBT()
7197  */
7198 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7199 {
7200   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7201   setFileName("");
7202   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7203 }
7204
7205 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
7206 {
7207   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7208   if(!pt)
7209     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
7210   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
7211   if(!ret)
7212     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 !");
7213   return ret;
7214 }
7215
7216 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7217 {
7218   if(getFileName().empty())
7219     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7220   MCAuto<DataArray> arrOut;
7221   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7222   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7223   return ret2.retn();
7224 }
7225
7226 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
7227 {
7228   if(arr.isNull())
7229     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
7230   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
7231   if(!arrC)
7232     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
7233   arrC->incrRef();
7234   return arrC;
7235 }
7236
7237 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
7238 {
7239   int t1,t2;
7240   double t0(f->getTime(t1,t2));
7241   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
7242   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7243   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
7244   ret->setTime(t0,t1,t2); ret->setArray(arr2);
7245   return ret.retn();
7246 }
7247
7248 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
7249 {
7250   if(!f)
7251     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
7252   int t1,t2;
7253   double t0(f->getTime(t1,t2));
7254   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7255   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
7256   ret->setTime(t0,t1,t2);
7257   return ret;
7258 }
7259
7260 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
7261 {
7262   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
7263 }
7264
7265 /*!
7266  * 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
7267  * method should be called (getFieldOnMeshAtLevel for example).
7268  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
7269  *
7270  * \param [in] mesh - the mesh the field is lying on
7271  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
7272  *          caller is to delete this field using decrRef() as it is no more needed. 
7273  */
7274 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
7275 {
7276   MCAuto<DataArray> arrOut;
7277   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
7278   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7279   return ret2.retn();
7280 }
7281
7282 /*!
7283  * Returns a new MEDCouplingFieldInt of a given type lying on
7284  * the top level cells of the first mesh in MED file. If \a this field 
7285  * has not been constructed via file reading, an exception is thrown.
7286  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7287  *  \param [in] type - a spatial discretization of interest.
7288  *  \param [in] renumPol - specifies how to permute values of the result field according to
7289  *          the optional numbers of cells and nodes, if any. The valid values are
7290  *          - 0 - do not permute.
7291  *          - 1 - permute cells.
7292  *          - 2 - permute nodes.
7293  *          - 3 - permute cells and nodes.
7294  *
7295  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7296  *          caller is to delete this field using decrRef() as it is no more needed. 
7297  *  \throw If \a this field has not been constructed via file reading.
7298  *  \throw If the MED file is not readable.
7299  *  \throw If there is no mesh in the MED file.
7300  *  \throw If no field values of the given \a type.
7301  *  \throw If no field values lying on the top level support.
7302  *  \sa getFieldAtLevel()
7303  */
7304 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7305 {
7306   if(getFileName().empty())
7307     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7308   MCAuto<DataArray> arrOut;
7309   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7310   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7311   return ret2.retn();
7312 }
7313
7314 /*!
7315  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
7316  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7317  *  \param [in] type - a spatial discretization of the new field.
7318  *  \param [in] mesh - the supporting mesh.
7319  *  \param [in] renumPol - specifies how to permute values of the result field according to
7320  *          the optional numbers of cells and nodes, if any. The valid values are
7321  *          - 0 - do not permute.
7322  *          - 1 - permute cells.
7323  *          - 2 - permute nodes.
7324  *          - 3 - permute cells and nodes.
7325  *
7326  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7327  *          caller is to delete this field using decrRef() as it is no more needed. 
7328  *  \throw If no field of \a this is lying on \a mesh.
7329  *  \throw If the mesh is empty.
7330  *  \throw If no field values of the given \a type are available.
7331  *  \sa getFieldAtLevel()
7332  *  \sa getFieldOnMeshAtLevel() 
7333  */
7334 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7335 {
7336   MCAuto<DataArray> arrOut;
7337   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7338   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7339   return ret2.retn();
7340 }
7341
7342 /*!
7343  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7344  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7345  *  \param [in] type - a spatial discretization of interest.
7346  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7347  *  \param [in] mesh - the supporting mesh.
7348  *  \param [in] renumPol - specifies how to permute values of the result field according to
7349  *          the optional numbers of cells and nodes, if any. The valid values are
7350  *          - 0 - do not permute.
7351  *          - 1 - permute cells.
7352  *          - 2 - permute nodes.
7353  *          - 3 - permute cells and nodes.
7354  *
7355  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7356  *          caller is to delete this field using decrRef() as it is no more needed. 
7357  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7358  *  \throw If no field of \a this is lying on \a mesh.
7359  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7360  *  \sa getFieldAtLevel()
7361  *  \sa getFieldOnMeshAtLevel() 
7362  */
7363 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7364 {
7365   MCAuto<DataArray> arrOut;
7366   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7367   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7368   return ret2.retn();
7369 }
7370
7371 /*!
7372  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7373  * This method is called "Old" because in MED3 norm a field has only one meshName
7374  * attached, so this method is for readers of MED2 files. If \a this field 
7375  * has not been constructed via file reading, an exception is thrown.
7376  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7377  *  \param [in] type - a spatial discretization of interest.
7378  *  \param [in] mName - a name of the supporting mesh.
7379  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7380  *  \param [in] renumPol - specifies how to permute values of the result field according to
7381  *          the optional numbers of cells and nodes, if any. The valid values are
7382  *          - 0 - do not permute.
7383  *          - 1 - permute cells.
7384  *          - 2 - permute nodes.
7385  *          - 3 - permute cells and nodes.
7386  *
7387  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7388  *          caller is to delete this field using decrRef() as it is no more needed. 
7389  *  \throw If the MED file is not readable.
7390  *  \throw If there is no mesh named \a mName in the MED file.
7391  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7392  *  \throw If \a this field has not been constructed via file reading.
7393  *  \throw If no field of \a this is lying on the mesh named \a mName.
7394  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7395  *  \sa getFieldAtLevel()
7396  */
7397 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7398 {
7399   if(getFileName().empty())
7400     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7401   MCAuto<DataArray> arrOut;
7402   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7403   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7404   return ret2.retn();
7405 }
7406
7407 /*!
7408  * Returns values and a profile of the field of a given type lying on a given support.
7409  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7410  *  \param [in] type - a spatial discretization of the field.
7411  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7412  *  \param [in] mesh - the supporting mesh.
7413  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7414  *          field of interest lies on. If the field lies on all entities of the given
7415  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7416  *          using decrRef() as it is no more needed.  
7417  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7418  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7419  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7420  *  \throw If no field of \a this is lying on \a mesh.
7421  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7422  */
7423 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7424 {
7425   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7426   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7427 }
7428
7429 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7430 {
7431   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7432   if(!pt)
7433     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7434   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7435   if(!ret)
7436     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 !");
7437   return ret;
7438 }
7439
7440 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7441 {
7442   return contentNotNull()->getUndergroundDataArrayTemplate();
7443 }
7444
7445 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7446
7447 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7448 {
7449 }
7450
7451 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7452 {
7453 }
7454
7455 /*!
7456  * \param [in] fieldId field id in C mode
7457  */
7458 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7459 {
7460   med_field_type typcha;
7461   std::string dtunitOut;
7462   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut));
7463   setDtUnit(dtunitOut.c_str());
7464   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7465 }
7466
7467 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)
7468 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7469 {
7470   setDtUnit(dtunit.c_str());
7471   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7472 }
7473 catch(INTERP_KERNEL::Exception& e)
7474 {
7475     throw e;
7476 }
7477
7478 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7479 {
7480   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7481   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7482     ret+=(*it).capacity();
7483   return ret;
7484 }
7485
7486 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7487 {
7488   std::vector<const BigMemoryObject *> ret;
7489   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7490     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7491   return ret;
7492 }
7493
7494 /*!
7495  * 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
7496  * NULL.
7497  */
7498 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7499 {
7500   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7501   ret->setInfo(_infos);
7502   int sz=(int)_time_steps.size();
7503   for(const int *id=startIds;id!=endIds;id++)
7504     {
7505       if(*id>=0 && *id<sz)
7506         {
7507           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7508           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7509           if(tse)
7510             {
7511               tse->incrRef();
7512               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7513             }
7514           ret->pushBackTimeStep(tse2);
7515         }
7516       else
7517         {
7518           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7519           oss << " ! Should be in [0," << sz << ") !";
7520           throw INTERP_KERNEL::Exception(oss.str());
7521         }
7522     }
7523   if(ret->getNumberOfTS()>0)
7524     ret->synchronizeNameScope();
7525   ret->copyNameScope(*this);
7526   return ret.retn();
7527 }
7528
7529 /*!
7530  * 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
7531  * NULL.
7532  */
7533 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7534 {
7535   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7536   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7537   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7538   ret->setInfo(_infos);
7539   int sz=(int)_time_steps.size();
7540   int j=bg;
7541   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7542     {
7543       if(j>=0 && j<sz)
7544         {
7545           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7546           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7547           if(tse)
7548             {
7549               tse->incrRef();
7550               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7551             }
7552           ret->pushBackTimeStep(tse2);
7553         }
7554       else
7555         {
7556           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7557           oss << " ! Should be in [0," << sz << ") !";
7558           throw INTERP_KERNEL::Exception(oss.str());
7559         }
7560     }
7561   if(ret->getNumberOfTS()>0)
7562     ret->synchronizeNameScope();
7563   ret->copyNameScope(*this);
7564   return ret.retn();
7565 }
7566
7567 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7568 {
7569   int id=0;
7570   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7571   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7572     {
7573       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7574       if(!cur)
7575         continue;
7576       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7577       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7578         ids->pushBackSilent(id);
7579     }
7580   return buildFromTimeStepIds(ids->begin(),ids->end());
7581 }
7582
7583 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7584 {
7585   int id=0;
7586   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7587   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7588     {
7589       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7590       if(!cur)
7591         continue;
7592       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7593       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7594         ids->pushBackSilent(id);
7595     }
7596   return buildFromTimeStepIds(ids->begin(),ids->end());
7597 }
7598
7599 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
7600 {
7601   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7602     if((*it).isNotNull())
7603       if((*it)->presenceOfStructureElements())
7604         return true;
7605   return false;
7606 }
7607
7608 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
7609 {
7610   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7611     if((*it).isNotNull())
7612       if(!(*it)->onlyStructureElements())
7613         return false;
7614   return true;
7615 }
7616
7617 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
7618 {
7619   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7620   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7621     if((*it).isNotNull())
7622       {
7623         if((*it)->presenceOfStructureElements())
7624           {
7625             if(!(*it)->onlyStructureElements())
7626               {
7627                 (*it)->killStructureElements();
7628                 ret.push_back(*it);
7629               }
7630           }
7631         else
7632           {
7633             ret.push_back(*it);
7634           }
7635       }
7636   _time_steps=ret;
7637 }
7638
7639 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
7640 {
7641   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7642   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7643     if((*it).isNotNull())
7644       {
7645         if((*it)->presenceOfStructureElements())
7646           {
7647             if(!(*it)->onlyStructureElements())
7648               (*it)->keepOnlyStructureElements();
7649             ret.push_back(*it);
7650           }
7651       }
7652   _time_steps=ret;
7653 }
7654
7655 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
7656 {
7657   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7658   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7659     if((*it).isNotNull())
7660       (*it)->keepOnlyOnSE(seName);
7661 }
7662
7663 void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
7664 {
7665   std::vector< std::pair<std::string,std::string> > ps2;
7666   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7667     if((*it).isNotNull())
7668       {
7669         (*it)->getMeshSENames(ps2);
7670         break;
7671       }
7672   if(ps2.empty())
7673     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
7674   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7675     if((*it).isNotNull())
7676       {
7677         std::vector< std::pair<std::string,std::string> > ps3;
7678         (*it)->getMeshSENames(ps3);
7679         if(ps2!=ps3)
7680           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
7681       }
7682   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
7683     {
7684       std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
7685       if(it2==ps.end())
7686         ps.push_back(*it);
7687     }
7688 }
7689
7690 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7691 {
7692   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7693     {
7694       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7695       if(!cur)
7696         continue;
7697       if(cur->presenceOfMultiDiscPerGeoType())
7698         return true;
7699     }
7700   return false;
7701 }
7702
7703 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7704 {
7705   return _infos;
7706 }
7707
7708 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7709 {
7710   _infos=info;
7711 }
7712
7713 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7714 {
7715   int ret=0;
7716   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7717     {
7718       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7719       if(pt->isDealingTS(iteration,order))
7720         return ret;
7721     }
7722   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7723   std::vector< std::pair<int,int> > vp=getIterations();
7724   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7725     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7726   throw INTERP_KERNEL::Exception(oss.str());
7727 }
7728
7729 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7730 {
7731   return *_time_steps[getTimeStepPos(iteration,order)];
7732 }
7733
7734 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7735 {
7736   return *_time_steps[getTimeStepPos(iteration,order)];
7737 }
7738
7739 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7740 {
7741   if(_time_steps.empty())
7742     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7743   return _time_steps[0]->getMeshName();
7744 }
7745
7746 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7747 {
7748   std::string oldName(getMeshName());
7749   std::vector< std::pair<std::string,std::string> > v(1);
7750   v[0].first=oldName; v[0].second=newMeshName;
7751   changeMeshNames(v);
7752 }
7753
7754 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7755 {
7756   bool ret=false;
7757   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7758     {
7759       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7760       if(cur)
7761         ret=cur->changeMeshNames(modifTab) || ret;
7762     }
7763   return ret;
7764 }
7765
7766 /*!
7767  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7768  */
7769 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7770 {
7771   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7772 }
7773
7774 /*!
7775  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7776  */
7777 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7778 {
7779   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7780 }
7781
7782 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7783                                                                        MEDFileFieldGlobsReal& glob)
7784 {
7785   bool ret=false;
7786   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7787     {
7788       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7789       if(f1ts)
7790         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7791     }
7792   return ret;
7793 }
7794
7795 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7796 {
7797   std::string startLine(bkOffset,' ');
7798   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7799   if(fmtsId>=0)
7800     oss << " (" << fmtsId << ")";
7801   oss << " has the following name: \"" << _name << "\"." << std::endl;
7802   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7803   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7804     {
7805       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7806     }
7807   int i=0;
7808   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7809     {
7810       std::string chapter(17,'0'+i);
7811       oss << startLine << chapter << std::endl;
7812       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7813       if(cur)
7814         cur->simpleRepr(bkOffset+2,oss,i);
7815       else
7816         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7817       oss << startLine << chapter << std::endl;
7818     }
7819 }
7820
7821 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7822 {
7823   std::size_t sz=_time_steps.size();
7824   std::vector< std::pair<int,int> > ret(sz);
7825   ret1.resize(sz);
7826   for(std::size_t i=0;i<sz;i++)
7827     {
7828       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7829       if(f1ts)
7830         {
7831           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7832         }
7833       else
7834         {
7835           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7836           throw INTERP_KERNEL::Exception(oss.str());
7837         }
7838     }
7839   return ret;
7840 }
7841
7842 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7843 {
7844   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7845   if(!tse2)
7846     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7847   checkCoherencyOfType(tse2);
7848   if(_time_steps.empty())
7849     {
7850       setName(tse2->getName().c_str());
7851       setInfo(tse2->getInfo());
7852     }
7853   checkThatComponentsMatch(tse2->getInfo());
7854   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7855     setDtUnit(tse->getDtUnit());
7856   _time_steps.push_back(tse);
7857 }
7858
7859 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7860 {
7861   std::size_t nbOfCompo=_infos.size();
7862   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7863     {
7864       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7865       if(cur)
7866         {
7867           if((cur->getInfo()).size()!=nbOfCompo)
7868             {
7869               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7870               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7871               throw INTERP_KERNEL::Exception(oss.str());
7872             }
7873           cur->copyNameScope(*this);
7874         }
7875     }
7876 }
7877
7878 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7879 {
7880   _time_steps.resize(nbPdt);
7881   for(int i=0;i<nbPdt;i++)
7882     {
7883       std::vector< std::pair<int,int> > ts;
7884       med_int numdt=0,numo=0;
7885       med_float dt=0.0;
7886       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7887       switch(fieldTyp)
7888       {
7889         case MED_FLOAT64:
7890           {
7891             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7892             break;
7893           }
7894         case MED_INT32:
7895           {
7896             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7897             break;
7898           }
7899         default:
7900           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7901       }
7902       if(loadAll)
7903         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7904       else
7905         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7906       synchronizeNameScope();
7907     }
7908 }
7909
7910 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7911 {
7912   if(_time_steps.empty())
7913     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7914   checkThatNbOfCompoOfTSMatchThis();
7915   std::vector<std::string> infos(getInfo());
7916   int nbComp=infos.size();
7917   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7918   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7919   for(int i=0;i<nbComp;i++)
7920     {
7921       std::string info=infos[i];
7922       std::string c,u;
7923       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7924       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7925       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7926     }
7927   if(_name.empty())
7928     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7929   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7930   int nbOfTS=_time_steps.size();
7931   for(int i=0;i<nbOfTS;i++)
7932     _time_steps[i]->writeLL(fid,opts,*this);
7933 }
7934
7935 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7936 {
7937   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7938     {
7939       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7940       if(elt)
7941         elt->loadBigArraysRecursively(fid,nasc);
7942     }
7943 }
7944
7945 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7946 {
7947   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7948     {
7949       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7950       if(elt)
7951         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7952     }
7953 }
7954
7955 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7956 {
7957   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7958     {
7959       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7960       if(elt)
7961         elt->unloadArrays();
7962     }
7963 }
7964
7965 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7966 {
7967   return _time_steps.size();
7968 }
7969
7970 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7971 {
7972   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7973   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7974     {
7975       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7976       if(tmp)
7977         newTS.push_back(*it);
7978     }
7979   _time_steps=newTS;
7980 }
7981
7982 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7983 {
7984   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7985   int maxId=(int)_time_steps.size();
7986   int ii=0;
7987   std::set<int> idsToDel;
7988   for(const int *id=startIds;id!=endIds;id++,ii++)
7989     {
7990       if(*id>=0 && *id<maxId)
7991         {
7992           idsToDel.insert(*id);
7993         }
7994       else
7995         {
7996           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7997           throw INTERP_KERNEL::Exception(oss.str());
7998         }
7999     }
8000   for(int iii=0;iii<maxId;iii++)
8001     if(idsToDel.find(iii)==idsToDel.end())
8002       newTS.push_back(_time_steps[iii]);
8003   _time_steps=newTS;
8004 }
8005
8006 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
8007 {
8008   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
8009   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
8010   if(nbOfEntriesToKill==0)
8011     return ;
8012   std::size_t sz=_time_steps.size();
8013   std::vector<bool> b(sz,true);
8014   int j=bg;
8015   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
8016     b[j]=false;
8017   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
8018   for(std::size_t i=0;i<sz;i++)
8019     if(b[i])
8020       newTS.push_back(_time_steps[i]);
8021   _time_steps=newTS;
8022 }
8023
8024 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
8025 {
8026   int ret=0;
8027   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
8028   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
8029     {
8030       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
8031       if(tmp)
8032         {
8033           int it2,ord;
8034           tmp->getTime(it2,ord);
8035           if(it2==iteration && order==ord)
8036             return ret;
8037           else
8038             oss << "(" << it2 << ","  << ord << "), ";
8039         }
8040     }
8041   throw INTERP_KERNEL::Exception(oss.str());
8042 }
8043
8044 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
8045 {
8046   int ret=0;
8047   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
8048   oss.precision(15);
8049   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
8050     {
8051       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
8052       if(tmp)
8053         {
8054           int it2,ord;
8055           double ti=tmp->getTime(it2,ord);
8056           if(fabs(time-ti)<eps)
8057             return ret;
8058           else
8059             oss << ti << ", ";
8060         }
8061     }
8062   throw INTERP_KERNEL::Exception(oss.str());
8063 }
8064
8065 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
8066 {
8067   int lgth=_time_steps.size();
8068   std::vector< std::pair<int,int> > ret(lgth);
8069   for(int i=0;i<lgth;i++)
8070     _time_steps[i]->fillIteration(ret[i]);
8071   return ret;
8072 }
8073
8074 /*!
8075  * 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'
8076  * This method returns two things.
8077  * - The absolute dimension of 'this' in first parameter. 
8078  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
8079  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
8080  *
8081  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
8082  * Only these 3 discretizations will be taken into account here.
8083  *
8084  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
8085  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
8086  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
8087  *
8088  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
8089  * 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'.
8090  * 
8091  * Let's consider the typical following case :
8092  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
8093  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
8094  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
8095  *   TETRA4 and SEG2
8096  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
8097  *
8098  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
8099  * 
8100  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
8101  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
8102  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
8103  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
8104  */
8105 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8106 {
8107   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
8108 }
8109
8110 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
8111 {
8112   if(pos<0 || pos>=(int)_time_steps.size())
8113     {
8114       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8115       throw INTERP_KERNEL::Exception(oss.str());
8116     }
8117   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8118   if(item==0)
8119     {
8120       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8121       oss << "\nTry to use following method eraseEmptyTS !";
8122       throw INTERP_KERNEL::Exception(oss.str());
8123     }
8124   return item;
8125 }
8126
8127 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
8128 {
8129   if(pos<0 || pos>=(int)_time_steps.size())
8130     {
8131       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8132       throw INTERP_KERNEL::Exception(oss.str());
8133     }
8134   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8135   if(item==0)
8136     {
8137       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8138       oss << "\nTry to use following method eraseEmptyTS !";
8139       throw INTERP_KERNEL::Exception(oss.str());
8140     }
8141   return item;
8142 }
8143
8144 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
8145 {
8146   std::vector<std::string> ret;
8147   std::set<std::string> ret2;
8148   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8149     {
8150       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
8151       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8152         if(ret2.find(*it2)==ret2.end())
8153           {
8154             ret.push_back(*it2);
8155             ret2.insert(*it2);
8156           }
8157     }
8158   return ret;
8159 }
8160
8161 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
8162 {
8163   std::vector<std::string> ret;
8164   std::set<std::string> ret2;
8165   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8166     {
8167       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8168       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8169         if(ret2.find(*it2)==ret2.end())
8170           {
8171             ret.push_back(*it2);
8172             ret2.insert(*it2);
8173           }
8174     }
8175   return ret;
8176 }
8177
8178 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
8179 {
8180   std::vector<std::string> ret;
8181   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8182     {
8183       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
8184       ret.insert(ret.end(),tmp.begin(),tmp.end());
8185     }
8186   return ret;
8187 }
8188
8189 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
8190 {
8191   std::vector<std::string> ret;
8192   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8193     {
8194       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
8195       ret.insert(ret.end(),tmp.begin(),tmp.end());
8196     }
8197   return ret;
8198 }
8199
8200 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8201 {
8202   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8203     (*it)->changePflsRefsNamesGen2(mapOfModif);
8204 }
8205
8206 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8207 {
8208   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8209     (*it)->changeLocsRefsNamesGen2(mapOfModif);
8210 }
8211
8212 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
8213 {
8214   int lgth=_time_steps.size();
8215   std::vector< std::vector<TypeOfField> > ret(lgth);
8216   for(int i=0;i<lgth;i++)
8217     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
8218   return ret;
8219 }
8220
8221 /*!
8222  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
8223  */
8224 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
8225 {
8226   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
8227 }
8228
8229 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
8230 {
8231   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
8232   std::size_t i=0;
8233   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8234     {
8235       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
8236         ret->_time_steps[i]=(*it)->deepCopy();
8237     }
8238   return ret.retn();
8239 }
8240
8241 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
8242 {
8243   std::size_t sz(_infos.size()),sz2(_time_steps.size());
8244   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
8245   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
8246   for(std::size_t i=0;i<sz;i++)
8247     {
8248       ret[i]=shallowCpy();
8249       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
8250     }
8251   for(std::size_t i=0;i<sz2;i++)
8252     {
8253       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
8254       if(ret1.size()!=sz)
8255         {
8256           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
8257           throw INTERP_KERNEL::Exception(oss.str());
8258         }
8259       ts[i]=ret1;
8260     }
8261   for(std::size_t i=0;i<sz;i++)
8262     for(std::size_t j=0;j<sz2;j++)
8263       ret[i]->_time_steps[j]=ts[j][i];
8264   return ret;
8265 }
8266
8267 /*!
8268  * This method splits into discretization each time steps in \a this.
8269  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
8270  */
8271 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
8272 {
8273   std::size_t sz(_time_steps.size());
8274   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8275   for(std::size_t i=0;i<sz;i++)
8276     {
8277       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8278       if(!timeStep)
8279         {
8280           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
8281           throw INTERP_KERNEL::Exception(oss.str());
8282         }
8283       items[i]=timeStep->splitDiscretizations();  
8284     }
8285   //
8286   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
8287   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
8288   std::vector< TypeOfField > types;
8289   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8290     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8291       {
8292         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
8293         if(ts.size()!=1)
8294           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
8295         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
8296         if(it2==types.end())
8297           types.push_back(ts[0]);
8298       }
8299   ret.resize(types.size()); ret2.resize(types.size());
8300   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8301     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8302       {
8303         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
8304         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
8305         ret2[pos].push_back(*it1);
8306       }
8307   for(std::size_t i=0;i<types.size();i++)
8308     {
8309       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8310       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
8311         elt->pushBackTimeStep(*it1);//also updates infos in elt
8312       ret[i]=elt;
8313       elt->MEDFileFieldNameScope::operator=(*this);
8314     }
8315   return ret;
8316 }
8317
8318 /*!
8319  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
8320  */
8321 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
8322 {
8323   std::size_t sz(_time_steps.size());
8324   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8325   std::size_t szOut(std::numeric_limits<std::size_t>::max());
8326   for(std::size_t i=0;i<sz;i++)
8327     {
8328       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8329       if(!timeStep)
8330         {
8331           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
8332           throw INTERP_KERNEL::Exception(oss.str());
8333         }
8334       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
8335       if(szOut==std::numeric_limits<std::size_t>::max())
8336         szOut=items[i].size();
8337       else
8338         if(items[i].size()!=szOut)
8339           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
8340     }
8341   if(szOut==std::numeric_limits<std::size_t>::max())
8342     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
8343   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
8344   for(std::size_t i=0;i<szOut;i++)
8345     {
8346       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8347       for(std::size_t j=0;j<sz;j++)
8348         elt->pushBackTimeStep(items[j][i]);
8349       ret[i]=elt;
8350       elt->MEDFileFieldNameScope::operator=(*this);
8351     }
8352   return ret;
8353 }
8354
8355 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
8356 {
8357   _name=field->getName();
8358   if(_name.empty())
8359     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
8360   if(!arr)
8361     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
8362   _infos=arr->getInfoOnComponents();
8363 }
8364
8365 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
8366 {
8367   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
8368   if(_name!=field->getName())
8369     {
8370       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
8371       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
8372       throw INTERP_KERNEL::Exception(oss.str());
8373     }
8374   if(!arr)
8375     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
8376   checkThatComponentsMatch(arr->getInfoOnComponents());
8377 }
8378
8379 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
8380 {
8381   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
8382   if(getInfo().size()!=compos.size())
8383     {
8384       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
8385       oss << " number of components of element to append (" << compos.size() << ") !";
8386       throw INTERP_KERNEL::Exception(oss.str());
8387     }
8388   if(_infos!=compos)
8389     {
8390       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
8391       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
8392       oss << " But compo in input fields are : ";
8393       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
8394       oss << " !";
8395       throw INTERP_KERNEL::Exception(oss.str());
8396     }
8397 }
8398
8399 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
8400 {
8401   std::size_t sz=_infos.size();
8402   int j=0;
8403   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
8404     {
8405       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8406       if(elt)
8407         if(elt->getInfo().size()!=sz)
8408           {
8409             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
8410             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
8411             throw INTERP_KERNEL::Exception(oss.str());
8412           }
8413     }
8414 }
8415
8416 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8417 {
8418   if(!field)
8419     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8420   if(!_time_steps.empty())
8421     checkCoherencyOfTinyInfo(field,arr);
8422   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8423   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8424   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8425   copyTinyInfoFrom(field,arr);
8426   _time_steps.push_back(obj);
8427 }
8428
8429 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8430 {
8431   if(!field)
8432     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8433   if(!_time_steps.empty())
8434     checkCoherencyOfTinyInfo(field,arr);
8435   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8436   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8437   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8438   copyTinyInfoFrom(field,arr);
8439   _time_steps.push_back(obj);
8440 }
8441
8442 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8443 {
8444   int sz=(int)_time_steps.size();
8445   if(i<0 || i>=sz)
8446     {
8447       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8448       throw INTERP_KERNEL::Exception(oss.str());
8449     }
8450   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8451   if(tsPtr)
8452     {
8453       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8454         {
8455           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8456           throw INTERP_KERNEL::Exception(oss.str());
8457         }
8458     }
8459   _time_steps[i]=ts;
8460 }
8461
8462 //= MEDFileFieldMultiTSWithoutSDA
8463
8464 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)
8465 {
8466   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8467 }
8468
8469 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8470 {
8471 }
8472
8473 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8474 {
8475 }
8476
8477 /*!
8478  * \param [in] fieldId field id in C mode
8479  */
8480 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8481 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8482 {
8483 }
8484 catch(INTERP_KERNEL::Exception& e)
8485 { throw e; }
8486
8487 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)
8488 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8489 {
8490 }
8491 catch(INTERP_KERNEL::Exception& e)
8492 { throw e; }
8493
8494 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8495 {
8496   return new MEDFileField1TSWithoutSDA;
8497 }
8498
8499 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8500 {
8501   if(!f1ts)
8502     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8503   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8504   if(!f1tsC)
8505     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8506 }
8507
8508 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8509 {
8510   return MEDFileField1TSWithoutSDA::TYPE_STR;
8511 }
8512
8513 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8514 {
8515   return new MEDFileFieldMultiTSWithoutSDA(*this);
8516 }
8517
8518 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8519 {
8520   return new MEDFileFieldMultiTSWithoutSDA;
8521 }
8522
8523 /*!
8524  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8525  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8526  */
8527 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
8528 {
8529   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8530   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8531   if(!myF1TSC)
8532     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8533   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8534 }
8535
8536 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8537 {
8538   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8539   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8540   int i=0;
8541   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8542     {
8543       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8544       if(eltToConv)
8545         {
8546           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8547           if(!eltToConvC)
8548             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8549           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8550           ret->setIteration(i,elt);
8551         }
8552     }
8553   return ret.retn();
8554 }
8555
8556 //= MEDFileAnyTypeFieldMultiTS
8557
8558 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8559 {
8560 }
8561
8562 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8563 try:MEDFileFieldGlobsReal(fid)
8564 {
8565   _content=BuildContentFrom(fid,loadAll,ms);
8566   loadGlobals(fid);
8567 }
8568 catch(INTERP_KERNEL::Exception& e)
8569 {
8570     throw e;
8571 }
8572
8573 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8574 {
8575   med_field_type typcha;
8576   std::vector<std::string> infos;
8577   std::string dtunit;
8578   int i(-1);
8579   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit);
8580   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8581   switch(typcha)
8582   {
8583     case MED_FLOAT64:
8584       {
8585         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8586         break;
8587       }
8588     case MED_INT32:
8589       {
8590         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8591         break;
8592       }
8593     default:
8594       {
8595         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] !";
8596         throw INTERP_KERNEL::Exception(oss.str());
8597       }
8598   }
8599   ret->setDtUnit(dtunit.c_str());
8600   return ret.retn();
8601 }
8602
8603 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8604 {
8605   med_field_type typcha;
8606   //
8607   std::vector<std::string> infos;
8608   std::string dtunit,fieldName;
8609   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
8610   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8611   switch(typcha)
8612   {
8613     case MED_FLOAT64:
8614       {
8615         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8616         break;
8617       }
8618     case MED_INT32:
8619       {
8620         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8621         break;
8622       }
8623     default:
8624       {
8625         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] !";
8626         throw INTERP_KERNEL::Exception(oss.str());
8627       }
8628   }
8629   ret->setDtUnit(dtunit.c_str());
8630   return ret.retn();
8631 }
8632
8633 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8634 {
8635   if(!c)
8636     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8637   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8638     {
8639       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8640       ret->_content=c;  c->incrRef();
8641       return ret.retn();
8642     }
8643   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8644     {
8645       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8646       ret->_content=c;  c->incrRef();
8647       return ret.retn();
8648     }
8649   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8650 }
8651
8652 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8653 {
8654   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8655   std::string fileName(FileNameFromFID(fid));
8656   ret->setFileName(fileName);
8657   return ret;
8658 }
8659
8660 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8661 try:MEDFileFieldGlobsReal(fid)
8662 {
8663   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8664   loadGlobals(fid);
8665 }
8666 catch(INTERP_KERNEL::Exception& e)
8667 {
8668     throw e;
8669 }
8670
8671 //= MEDFileIntFieldMultiTSWithoutSDA
8672
8673 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)
8674 {
8675   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8676 }
8677
8678 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8679 {
8680 }
8681
8682 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8683 {
8684 }
8685
8686 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)
8687 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8688 {
8689 }
8690 catch(INTERP_KERNEL::Exception& e)
8691 { throw e; }
8692
8693 /*!
8694  * \param [in] fieldId field id in C mode
8695  */
8696 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8697 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8698 {
8699 }
8700 catch(INTERP_KERNEL::Exception& e)
8701 { throw e; }
8702
8703 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8704 {
8705   return new MEDFileIntField1TSWithoutSDA;
8706 }
8707
8708 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8709 {
8710   if(!f1ts)
8711     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8712   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8713   if(!f1tsC)
8714     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8715 }
8716
8717 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8718 {
8719   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8720 }
8721
8722 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8723 {
8724   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8725 }
8726
8727 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8728 {
8729   return new MEDFileIntFieldMultiTSWithoutSDA;
8730 }
8731
8732 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8733 {
8734   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8735   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8736   int i=0;
8737   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8738     {
8739       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8740       if(eltToConv)
8741         {
8742           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8743           if(!eltToConvC)
8744             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8745           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8746           ret->setIteration(i,elt);
8747         }
8748     }
8749   return ret.retn();
8750 }
8751
8752 //= MEDFileAnyTypeFieldMultiTS
8753
8754 /*!
8755  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8756  * that has been read from a specified MED file.
8757  *  \param [in] fileName - the name of the MED file to read.
8758  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8759  *          is to delete this field using decrRef() as it is no more needed.
8760  *  \throw If reading the file fails.
8761  */
8762 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8763 {
8764   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8765   return New(fid,loadAll);
8766 }
8767
8768 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8769 {
8770   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8771   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8772   ret->loadGlobals(fid);
8773   return ret.retn();
8774 }
8775
8776 /*!
8777  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8778  * that has been read from a specified MED file.
8779  *  \param [in] fileName - the name of the MED file to read.
8780  *  \param [in] fieldName - the name of the field to read.
8781  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8782  *          is to delete this field using decrRef() as it is no more needed.
8783  *  \throw If reading the file fails.
8784  *  \throw If there is no field named \a fieldName in the file.
8785  */
8786 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8787 {
8788   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8789   return New(fid,fieldName,loadAll);
8790 }
8791
8792 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8793 {
8794   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8795   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8796   ret->loadGlobals(fid);
8797   return ret.retn();
8798 }
8799
8800 /*!
8801  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8802  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8803  *
8804  * \warning this is a shallow copy constructor
8805  */
8806 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8807 {
8808   if(!shallowCopyOfContent)
8809     {
8810       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8811       otherPtr->incrRef();
8812       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8813     }
8814   else
8815     {
8816       _content=other.shallowCpy();
8817     }
8818 }
8819
8820 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8821 {
8822   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8823   if(!ret)
8824     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8825   return ret;
8826 }
8827
8828 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8829 {
8830   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8831   if(!ret)
8832     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8833   return ret;
8834 }
8835
8836 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8837 {
8838   return contentNotNullBase()->getPflsReallyUsed2();
8839 }
8840
8841 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8842 {
8843   return contentNotNullBase()->getLocsReallyUsed2();
8844 }
8845
8846 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8847 {
8848   return contentNotNullBase()->getPflsReallyUsedMulti2();
8849 }
8850
8851 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8852 {
8853   return contentNotNullBase()->getLocsReallyUsedMulti2();
8854 }
8855
8856 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8857 {
8858   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8859 }
8860
8861 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8862 {
8863   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8864 }
8865
8866 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8867 {
8868   return contentNotNullBase()->getNumberOfTS();
8869 }
8870
8871 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8872 {
8873   contentNotNullBase()->eraseEmptyTS();
8874 }
8875
8876 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8877 {
8878   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8879 }
8880
8881 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8882 {
8883   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8884 }
8885
8886 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8887 {
8888   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8889   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8890   ret->_content=c;
8891   return ret.retn();
8892 }
8893
8894 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8895 {
8896   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8897   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8898   ret->_content=c;
8899   return ret.retn();
8900 }
8901
8902 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8903 {
8904   return contentNotNullBase()->getIterations();
8905 }
8906
8907 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8908 {
8909   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8910     pushBackTimeStep(*it);
8911 }
8912
8913 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8914 {
8915   if(!fmts)
8916     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8917   int nbOfTS(fmts->getNumberOfTS());
8918   for(int i=0;i<nbOfTS;i++)
8919     {
8920       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8921       pushBackTimeStep(elt);
8922     }
8923 }
8924
8925 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8926 {
8927   if(!f1ts)
8928     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8929   checkCoherencyOfType(f1ts);
8930   f1ts->incrRef();
8931   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8932   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8933   c->incrRef();
8934   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8935   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8936     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8937   _content->pushBackTimeStep(cSafe);
8938   appendGlobs(*f1ts,1e-12);
8939 }
8940
8941 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8942 {
8943   contentNotNullBase()->synchronizeNameScope();
8944 }
8945
8946 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8947 {
8948   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8949 }
8950
8951 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8952 {
8953   return contentNotNullBase()->getPosGivenTime(time,eps);
8954 }
8955
8956 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8957 {
8958   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8959 }
8960
8961 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8962 {
8963   return contentNotNullBase()->getTypesOfFieldAvailable();
8964 }
8965
8966 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
8967 {
8968   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8969 }
8970
8971 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8972 {
8973   return contentNotNullBase()->getName();
8974 }
8975
8976 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8977 {
8978   contentNotNullBase()->setName(name);
8979 }
8980
8981 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8982 {
8983   return contentNotNullBase()->getDtUnit();
8984 }
8985
8986 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8987 {
8988   contentNotNullBase()->setDtUnit(dtUnit);
8989 }
8990
8991 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8992 {
8993   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8994 }
8995
8996 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8997 {
8998   return contentNotNullBase()->getTimeSteps(ret1);
8999 }
9000
9001 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
9002 {
9003   return contentNotNullBase()->getMeshName();
9004 }
9005
9006 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
9007 {
9008   contentNotNullBase()->setMeshName(newMeshName);
9009 }
9010
9011 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
9012 {
9013   return contentNotNullBase()->changeMeshNames(modifTab);
9014 }
9015
9016 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
9017 {
9018   return contentNotNullBase()->getInfo();
9019 }
9020
9021 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
9022 {
9023   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
9024 }
9025
9026 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
9027 {
9028   return contentNotNullBase()->setInfo(info);
9029 }
9030
9031 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
9032 {
9033   const std::vector<std::string> ret=getInfo();
9034   return (int)ret.size();
9035 }
9036
9037 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
9038 {
9039   writeGlobals(fid,*this);
9040   contentNotNullBase()->writeLL(fid,*this);
9041 }
9042
9043 /*!
9044  * This method alloc the arrays and load potentially huge arrays contained in this field.
9045  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9046  * This method can be also called to refresh or reinit values from a file.
9047  * 
9048  * \throw If the fileName is not set or points to a non readable MED file.
9049  */
9050 void MEDFileAnyTypeFieldMultiTS::loadArrays()
9051 {
9052   if(getFileName().empty())
9053     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
9054   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9055   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
9056 }
9057
9058 /*!
9059  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9060  * But once data loaded once, this method does nothing.
9061  * 
9062  * \throw If the fileName is not set or points to a non readable MED file.
9063  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
9064  */
9065 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
9066 {
9067   if(!getFileName().empty())
9068     {
9069       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9070       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
9071     }
9072 }
9073
9074 /*!
9075  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9076  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9077  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
9078  * 
9079  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
9080  */
9081 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
9082 {
9083   contentNotNullBase()->unloadArrays();
9084 }
9085
9086 /*!
9087  * 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.
9088  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
9089  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9090  * 
9091  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
9092  */
9093 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
9094 {
9095   if(!getFileName().empty())
9096     contentNotNullBase()->unloadArrays();
9097 }
9098
9099 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
9100 {
9101   std::ostringstream oss;
9102   contentNotNullBase()->simpleRepr(0,oss,-1);
9103   simpleReprGlobs(oss);
9104   return oss.str();
9105 }
9106
9107 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
9108 {
9109   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
9110 }
9111
9112 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
9113 {
9114   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
9115   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
9116   return ret;
9117 }
9118
9119 /*!
9120  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
9121  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
9122  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
9123  */
9124 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
9125 {
9126   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9127   if(!content)
9128     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
9129   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
9130   std::size_t sz(contentsSplit.size());
9131   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9132   for(std::size_t i=0;i<sz;i++)
9133     {
9134       ret[i]=shallowCpy();
9135       ret[i]->_content=contentsSplit[i];
9136     }
9137   return ret;
9138 }
9139
9140 /*!
9141  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
9142  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9143  */
9144 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
9145 {
9146   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9147   if(!content)
9148     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
9149   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
9150   std::size_t sz(contentsSplit.size());
9151   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9152   for(std::size_t i=0;i<sz;i++)
9153     {
9154       ret[i]=shallowCpy();
9155       ret[i]->_content=contentsSplit[i];
9156     }
9157   return ret;
9158 }
9159
9160 /*!
9161  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
9162  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9163  */
9164 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
9165 {
9166   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9167   if(!content)
9168     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
9169   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
9170   std::size_t sz(contentsSplit.size());
9171   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9172   for(std::size_t i=0;i<sz;i++)
9173     {
9174       ret[i]=shallowCpy();
9175       ret[i]->_content=contentsSplit[i];
9176     }
9177   return ret;
9178 }
9179
9180 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
9181 {
9182   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9183   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
9184     ret->_content=_content->deepCopy();
9185   ret->deepCpyGlobs(*this);
9186   return ret.retn();
9187 }
9188
9189 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
9190 {
9191   return _content;
9192 }
9193
9194 /*!
9195  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9196  *  \param [in] iteration - the iteration number of a required time step.
9197  *  \param [in] order - the iteration order number of required time step.
9198  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
9199  *          delete this field using decrRef() as it is no more needed.
9200  *  \throw If there is no required time step in \a this field.
9201  */
9202 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
9203 {
9204   int pos=getPosOfTimeStep(iteration,order);
9205   return getTimeStepAtPos(pos);
9206 }
9207
9208 /*!
9209  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9210  *  \param [in] time - the time of the time step of interest.
9211  *  \param [in] eps - a precision used to compare time values.
9212  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9213  *          delete this field using decrRef() as it is no more needed.
9214  *  \throw If there is no required time step in \a this field.
9215  */
9216 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
9217 {
9218   int pos=getPosGivenTime(time,eps);
9219   return getTimeStepAtPos(pos);
9220 }
9221
9222 /*!
9223  * 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.
9224  * The float64 value of time attached to the pair of integers are not considered here.
9225  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
9226  *
9227  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
9228  * \throw If there is a null pointer in \a vectFMTS.
9229  */
9230 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
9231 {
9232   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
9233   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9234   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9235   while(!lstFMTS.empty())
9236     {
9237       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9238       MEDFileAnyTypeFieldMultiTS *curIt(*it);
9239       if(!curIt)
9240         throw INTERP_KERNEL::Exception(msg);
9241       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
9242       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9243       elt.push_back(curIt); it=lstFMTS.erase(it);
9244       while(it!=lstFMTS.end())
9245         {
9246           curIt=*it;
9247           if(!curIt)
9248             throw INTERP_KERNEL::Exception(msg);
9249           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
9250           if(refIts==curIts)
9251             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9252           else
9253             it++;
9254         }
9255       ret.push_back(elt);
9256     }
9257   return ret;
9258 }
9259
9260 /*!
9261  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
9262  * All returned instances in a subvector can be safely loaded, rendered along time
9263  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
9264  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
9265  * 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).
9266  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
9267  * 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.
9268  *
9269  * \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().
9270  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
9271  * \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.
9272  * \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.
9273  *
9274  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
9275  * \throw If an element in \a vectFMTS change of spatial discretization along time.
9276  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
9277  * \thorw If some elements in \a vectFMTS do not have the same times steps.
9278  * \throw If mesh is null.
9279  * \throw If an element in \a vectFMTS is null.
9280  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
9281  */
9282 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
9283 {
9284   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
9285   if(!mesh)
9286     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
9287   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9288   if(vectFMTS.empty())
9289     return ret;
9290   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
9291   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
9292   if(!frstElt)
9293     throw INTERP_KERNEL::Exception(msg);
9294   std::size_t i=0;
9295   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
9296   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
9297   for(;it!=vectFMTS.end();it++,i++)
9298     {
9299       if(!(*it))
9300         throw INTERP_KERNEL::Exception(msg);
9301       TypeOfField tof0,tof1;
9302       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
9303         {
9304           if(tof1!=ON_NODES)
9305             vectFMTSNotNodes.push_back(*it);
9306           else
9307             vectFMTSNodes.push_back(*it);
9308         }
9309       else
9310         vectFMTSNotNodes.push_back(*it);
9311     }
9312   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
9313   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
9314   ret=retCell;
9315   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
9316     {
9317       i=0;
9318       bool isFetched(false);
9319       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
9320         {
9321           if((*it0).empty())
9322             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
9323           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
9324             { ret[i].push_back(*it2); isFetched=true; }
9325         }
9326       if(!isFetched)
9327         {
9328           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
9329           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
9330           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
9331         }
9332     }
9333   fsc=cmps;
9334   return ret;
9335 }
9336
9337 /*!
9338  * 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.
9339  * \param [out] cmps - same size than the returned vector.
9340  */
9341 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
9342 {
9343   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9344   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9345   while(!lstFMTS.empty())
9346     {
9347       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9348       MEDFileAnyTypeFieldMultiTS *ref(*it);
9349       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9350       elt.push_back(ref); it=lstFMTS.erase(it);
9351       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
9352       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
9353       while(it!=lstFMTS.end())
9354         {
9355           MEDFileAnyTypeFieldMultiTS *curIt(*it);
9356           if(cmp->isEqual(curIt))
9357             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9358           else
9359             it++;
9360         }
9361       ret.push_back(elt); cmps.push_back(cmp);
9362     }
9363   return ret;
9364 }
9365
9366 /*!
9367  * 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.
9368  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
9369  *
9370  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
9371  * \throw If \a f0 or \a f1 change of spatial discretization along time.
9372  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
9373  * \thorw If \a f0 and \a f1 do not have the same times steps.
9374  * \throw If mesh is null.
9375  * \throw If \a f0 or \a f1 is null.
9376  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
9377  */
9378 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
9379 {
9380   if(!mesh)
9381     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
9382   if(!f0 || !f1)
9383     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
9384   if(f0->getMeshName()!=mesh->getName())
9385     {
9386       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9387       throw INTERP_KERNEL::Exception(oss.str());
9388     }
9389   if(f1->getMeshName()!=mesh->getName())
9390     {
9391       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9392       throw INTERP_KERNEL::Exception(oss.str());
9393     }
9394   int nts=f0->getNumberOfTS();
9395   if(nts!=f1->getNumberOfTS())
9396     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
9397   if(nts==0)
9398     return nts;
9399   for(int i=0;i<nts;i++)
9400     {
9401       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
9402       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
9403       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
9404       if(tofs0.size()!=1 || tofs1.size()!=1)
9405         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
9406       if(i!=0)
9407         {
9408           if(tof0!=tofs0[0] || tof1!=tofs1[0])
9409             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
9410         }
9411       else
9412         { tof0=tofs0[0]; tof1=tofs1[0]; }
9413       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9414         {
9415           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() << ") !";
9416           throw INTERP_KERNEL::Exception(oss.str());
9417         }
9418       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9419         {
9420           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() << ") !";
9421           throw INTERP_KERNEL::Exception(oss.str());
9422         }
9423       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9424         {
9425           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() << ") !";
9426           throw INTERP_KERNEL::Exception(oss.str());
9427         }
9428     }
9429   return nts;
9430 }
9431
9432 /*!
9433  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9434  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9435  *
9436  * \return A new object that the caller is responsible to deallocate.
9437  */
9438 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9439 {
9440   if(!mm)
9441     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9442   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9443   int nbTS(getNumberOfTS());
9444   for(int i=0;i<nbTS;i++)
9445     {
9446       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9447       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9448       fmtsOut->pushBackTimeStep(f1tsOut);
9449     }
9450   return fmtsOut.retn();
9451 }
9452
9453 template<class T>
9454 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9455 {
9456   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9457   if(f1tss.empty())
9458     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9459   std::size_t sz(f1tss.size()),i(0);
9460   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9461   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9462     {
9463       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9464       if(!elt)
9465         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9466       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9467     }
9468   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9469   if(!retc)
9470     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9471   retc->aggregate(f1tsw,dts);
9472   ret->setDtUnit(f1tss[0]->getDtUnit());
9473   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9474 }
9475
9476 template<class T>
9477 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9478 {
9479   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9480   if(fmtss.empty())
9481     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9482   std::size_t sz(fmtss.size());
9483   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9484     {
9485       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9486       if(!elt)
9487         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9488     }
9489   int nbTS(fmtss[0]->getNumberOfTS());
9490   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9491     if((*it)->getNumberOfTS()!=nbTS)
9492       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9493   for(int iterTS=0;iterTS<nbTS;iterTS++)
9494     {
9495       std::size_t i(0);
9496       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9497       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9498       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9499         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9500       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9501       ret->pushBackTimeStep(f1ts);
9502       ret->setDtUnit(f1ts->getDtUnit());
9503     }
9504   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9505 }
9506
9507 /*!
9508  * \a dts and \a ftmss are expected to have same size.
9509  */
9510 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9511 {
9512   if(fmtss.empty())
9513     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9514   std::size_t sz(fmtss.size());
9515   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9516   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9517   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9518     {
9519       if(!(*it))
9520         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9521       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9522       if(elt1)
9523         {
9524           fmtss1.push_back(elt1);
9525           continue;
9526         }
9527       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9528       if(elt2)
9529         {
9530           fmtss2.push_back(elt2);
9531           continue;
9532         }
9533       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9534     }
9535   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9536     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9537   if(fmtss1.size()==sz)
9538     return AggregateHelperFMTS<double>(fmtss1,dts);
9539   if(fmtss2.size()!=sz)
9540     return AggregateHelperFMTS<int>(fmtss2,dts);
9541   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9542 }
9543
9544 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9545 {
9546   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9547 }
9548
9549 //= MEDFileFieldMultiTS
9550
9551 /*!
9552  * Returns a new empty instance of MEDFileFieldMultiTS.
9553  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9554  *          is to delete this field using decrRef() as it is no more needed.
9555  */
9556 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9557 {
9558   return new MEDFileFieldMultiTS;
9559 }
9560
9561 /*!
9562  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9563  * that has been read from a specified MED file.
9564  *  \param [in] fileName - the name of the MED file to read.
9565  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9566  *          is to delete this field using decrRef() as it is no more needed.
9567  *  \throw If reading the file fails.
9568  */
9569 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9570 {
9571   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9572   return New(fid,loadAll);
9573 }
9574
9575 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9576 {
9577   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9578   ret->contentNotNull();//to check that content type matches with \a this type.
9579   return ret.retn();
9580 }
9581
9582 /*!
9583  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9584  * that has been read from a specified MED file.
9585  *  \param [in] fileName - the name of the MED file to read.
9586  *  \param [in] fieldName - the name of the field to read.
9587  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9588  *          is to delete this field using decrRef() as it is no more needed.
9589  *  \throw If reading the file fails.
9590  *  \throw If there is no field named \a fieldName in the file.
9591  */
9592 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9593 {
9594   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9595   return New(fid,fieldName,loadAll);
9596 }
9597
9598 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9599 {
9600   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9601   ret->contentNotNull();//to check that content type matches with \a this type.
9602   return ret.retn();
9603 }
9604
9605 /*!
9606  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9607  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9608  *
9609  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9610  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9611  * \warning this is a shallow copy constructor
9612  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9613  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9614  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9615  *          is to delete this field using decrRef() as it is no more needed.
9616  */
9617 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9618 {
9619   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9620 }
9621
9622 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9623 {
9624   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9625   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9626   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
9627   ret->contentNotNull();//to check that content type matches with \a this type.
9628   return ret.retn();
9629 }
9630
9631 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9632 {
9633   return new MEDFileFieldMultiTS(*this);
9634 }
9635
9636 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9637 {
9638   if(!f1ts)
9639     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9640   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9641   if(!f1tsC)
9642     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9643 }
9644
9645 /*!
9646  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9647  * following the given input policy.
9648  *
9649  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9650  *                            By default (true) the globals are deeply copied.
9651  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9652  */
9653 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9654 {
9655   MCAuto<MEDFileIntFieldMultiTS> ret;
9656   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9657   if(content)
9658     {
9659       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9660       if(!contc)
9661         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9662       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9663       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9664     }
9665   else
9666     ret=MEDFileIntFieldMultiTS::New();
9667   if(isDeepCpyGlobs)
9668     ret->deepCpyGlobs(*this);
9669   else
9670     ret->shallowCpyGlobs(*this);
9671   return ret.retn();
9672 }
9673
9674 /*!
9675  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9676  *  \param [in] pos - a time step id.
9677  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9678  *          delete this field using decrRef() as it is no more needed.
9679  *  \throw If \a pos is not a valid time step id.
9680  */
9681 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9682 {
9683   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9684   if(!item)
9685     {
9686       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9687       throw INTERP_KERNEL::Exception(oss.str());
9688     }
9689   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9690   if(itemC)
9691     {
9692       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9693       ret->shallowCpyGlobs(*this);
9694       return ret.retn();
9695     }
9696   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9697   throw INTERP_KERNEL::Exception(oss.str());
9698 }
9699
9700 /*!
9701  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9702  * mesh entities of a given dimension of the first mesh in MED file.
9703  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9704  *  \param [in] type - a spatial discretization of interest.
9705  *  \param [in] iteration - the iteration number of a required time step.
9706  *  \param [in] order - the iteration order number of required time step.
9707  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9708  *  \param [in] renumPol - specifies how to permute values of the result field according to
9709  *          the optional numbers of cells and nodes, if any. The valid values are
9710  *          - 0 - do not permute.
9711  *          - 1 - permute cells.
9712  *          - 2 - permute nodes.
9713  *          - 3 - permute cells and nodes.
9714  *
9715  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9716  *          caller is to delete this field using decrRef() as it is no more needed. 
9717  *  \throw If the MED file is not readable.
9718  *  \throw If there is no mesh in the MED file.
9719  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9720  *  \throw If no field values of the required parameters are available.
9721  */
9722 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9723 {
9724   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9725   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9726   if(!myF1TSC)
9727     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9728   MCAuto<DataArray> arrOut;
9729   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9730   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9731   return ret.retn();
9732 }
9733
9734 /*!
9735  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9736  * the top level cells of the first mesh in MED file.
9737  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9738  *  \param [in] type - a spatial discretization of interest.
9739  *  \param [in] iteration - the iteration number of a required time step.
9740  *  \param [in] order - the iteration order number of required time step.
9741  *  \param [in] renumPol - specifies how to permute values of the result field according to
9742  *          the optional numbers of cells and nodes, if any. The valid values are
9743  *          - 0 - do not permute.
9744  *          - 1 - permute cells.
9745  *          - 2 - permute nodes.
9746  *          - 3 - permute cells and nodes.
9747  *
9748  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9749  *          caller is to delete this field using decrRef() as it is no more needed. 
9750  *  \throw If the MED file is not readable.
9751  *  \throw If there is no mesh in the MED file.
9752  *  \throw If no field values of the required parameters are available.
9753  */
9754 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9755 {
9756   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9757   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9758   if(!myF1TSC)
9759     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9760   MCAuto<DataArray> arrOut;
9761   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9762   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9763   return ret.retn();
9764 }
9765
9766 /*!
9767  * 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
9768  * method should be called (getFieldOnMeshAtLevel for example).
9769  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9770  *
9771  * \param [in] iteration - the iteration number of a required time step.
9772  * \param [in] order - the iteration order number of required time step.
9773  * \param [in] mesh - the mesh the field is lying on
9774  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9775  *          caller is to delete this field using decrRef() as it is no more needed. 
9776  */
9777 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9778 {
9779   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9780   MCAuto<DataArray> arrOut;
9781   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9782   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9783   return ret.retn();
9784 }
9785
9786 /*!
9787  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9788  * a given support.
9789  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9790  *  \param [in] type - a spatial discretization of interest.
9791  *  \param [in] iteration - the iteration number of a required time step.
9792  *  \param [in] order - the iteration order number of required time step.
9793  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9794  *  \param [in] mesh - the supporting mesh.
9795  *  \param [in] renumPol - specifies how to permute values of the result field according to
9796  *          the optional numbers of cells and nodes, if any. The valid values are
9797  *          - 0 - do not permute.
9798  *          - 1 - permute cells.
9799  *          - 2 - permute nodes.
9800  *          - 3 - permute cells and nodes.
9801  *
9802  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9803  *          caller is to delete this field using decrRef() as it is no more needed. 
9804  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9805  *  \throw If no field of \a this is lying on \a mesh.
9806  *  \throw If no field values of the required parameters are available.
9807  */
9808 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9809 {
9810   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9811   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9812   if(!myF1TSC)
9813     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9814   MCAuto<DataArray> arrOut;
9815   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9816   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9817   return ret.retn();
9818 }
9819
9820 /*!
9821  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9822  * given support. 
9823  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9824  *  \param [in] type - a spatial discretization of the new field.
9825  *  \param [in] iteration - the iteration number of a required time step.
9826  *  \param [in] order - the iteration order number of required time step.
9827  *  \param [in] mesh - the supporting mesh.
9828  *  \param [in] renumPol - specifies how to permute values of the result field according to
9829  *          the optional numbers of cells and nodes, if any. The valid values are
9830  *          - 0 - do not permute.
9831  *          - 1 - permute cells.
9832  *          - 2 - permute nodes.
9833  *          - 3 - permute cells and nodes.
9834  *
9835  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9836  *          caller is to delete this field using decrRef() as it is no more needed. 
9837  *  \throw If no field of \a this is lying on \a mesh.
9838  *  \throw If no field values of the required parameters are available.
9839  */
9840 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9841 {
9842   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9843   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9844   if(!myF1TSC)
9845     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9846   MCAuto<DataArray> arrOut;
9847   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9848   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9849   return ret.retn();
9850 }
9851
9852 /*!
9853  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9854  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9855  * This method is useful for MED2 file format when field on different mesh was autorized.
9856  */
9857 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9858 {
9859   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9860   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9861   if(!myF1TSC)
9862     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9863   MCAuto<DataArray> arrOut;
9864   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9865   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9866   return ret.retn();
9867 }
9868
9869 /*!
9870  * Returns values and a profile of the field of a given type, of a given time step,
9871  * lying on a given support.
9872  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9873  *  \param [in] type - a spatial discretization of the field.
9874  *  \param [in] iteration - the iteration number of a required time step.
9875  *  \param [in] order - the iteration order number of required time step.
9876  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9877  *  \param [in] mesh - the supporting mesh.
9878  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9879  *          field of interest lies on. If the field lies on all entities of the given
9880  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9881  *          using decrRef() as it is no more needed.  
9882  *  \param [in] glob - the global data storing profiles and localization.
9883  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9884  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9885  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9886  *  \throw If no field of \a this is lying on \a mesh.
9887  *  \throw If no field values of the required parameters are available.
9888  */
9889 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9890 {
9891   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9892   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9893   if(!myF1TSC)
9894     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9895   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9896   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9897 }
9898
9899 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9900 {
9901   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9902   if(!pt)
9903     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9904   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9905   if(!ret)
9906     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 !");
9907   return ret;
9908 }
9909
9910 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9911 {
9912   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9913   if(!pt)
9914     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9915   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9916   if(!ret)
9917     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 !");
9918   return ret;
9919 }
9920
9921 /*!
9922  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9923  * the given field is checked if its elements are sorted suitable for writing to MED file
9924  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9925  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9926  *  \param [in] field - the field to add to \a this.
9927  *  \throw If the name of \a field is empty.
9928  *  \throw If the data array of \a field is not set.
9929  *  \throw If existing time steps have different name or number of components than \a field.
9930  *  \throw If the underlying mesh of \a field has no name.
9931  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9932  */
9933 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9934 {
9935   const DataArrayDouble *arr=0;
9936   if(field)
9937     arr=field->getArray();
9938   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9939 }
9940
9941 /*!
9942  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9943  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9944  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9945  * and \a profile.
9946  *
9947  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9948  * A new profile is added only if no equal profile is missing.
9949  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9950  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9951  *  \param [in] mesh - the supporting mesh of \a field.
9952  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9953  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9954  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9955  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9956  *  \throw If the data array of \a field is not set.
9957  *  \throw If the data array of \a this is already allocated but has different number of
9958  *         components than \a field.
9959  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9960  *  \sa setFieldNoProfileSBT()
9961  */
9962 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9963 {
9964   const DataArrayDouble *arr=0;
9965   if(field)
9966     arr=field->getArray();
9967   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9968 }
9969
9970 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9971 {
9972   _content=new MEDFileFieldMultiTSWithoutSDA;
9973 }
9974
9975 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
9976 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
9977 {
9978 }
9979 catch(INTERP_KERNEL::Exception& e)
9980 { throw e; }
9981
9982 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9983 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
9984 {
9985 }
9986 catch(INTERP_KERNEL::Exception& e)
9987 { throw e; }
9988
9989 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9990 {
9991 }
9992
9993 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
9994 {
9995   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9996 }
9997
9998 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9999 {
10000   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10001 }
10002
10003 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
10004 {
10005   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
10006 }
10007
10008 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
10009 {
10010   return MEDFileFieldMultiTS::New();
10011 }
10012
10013 //= MEDFileAnyTypeFieldMultiTSIterator
10014
10015 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
10016 {
10017   if(fmts)
10018     {
10019       fmts->incrRef();
10020       _nb_iter=fmts->getNumberOfTS();
10021     }
10022 }
10023
10024 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
10025 {
10026 }
10027
10028 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
10029 {
10030   if(_iter_id<_nb_iter)
10031     {
10032       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
10033       if(fmts)
10034         return fmts->getTimeStepAtPos(_iter_id++);
10035       else
10036         return 0;
10037     }
10038   else
10039     return 0;
10040 }
10041
10042 //= MEDFileIntFieldMultiTS
10043
10044 /*!
10045  * Returns a new empty instance of MEDFileFieldMultiTS.
10046  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10047  *          is to delete this field using decrRef() as it is no more needed.
10048  */
10049 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
10050 {
10051   return new MEDFileIntFieldMultiTS;
10052 }
10053
10054 /*!
10055  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
10056  * that has been read from a specified MED file.
10057  *  \param [in] fileName - the name of the MED file to read.
10058  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10059  *          is to delete this field using decrRef() as it is no more needed.
10060  *  \throw If reading the file fails.
10061  */
10062 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
10063 {
10064   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10065   return New(fid,loadAll);
10066 }
10067
10068 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
10069 {
10070   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
10071   ret->contentNotNull();//to check that content type matches with \a this type.
10072   return ret.retn();
10073 }
10074
10075 /*!
10076  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
10077  * that has been read from a specified MED file.
10078  *  \param [in] fileName - the name of the MED file to read.
10079  *  \param [in] fieldName - the name of the field to read.
10080  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10081  *          is to delete this field using decrRef() as it is no more needed.
10082  *  \throw If reading the file fails.
10083  *  \throw If there is no field named \a fieldName in the file.
10084  */
10085 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
10086 {
10087   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10088   return New(fid,fieldName,loadAll);
10089 }
10090
10091 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
10092 {
10093   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
10094   ret->contentNotNull();//to check that content type matches with \a this type.
10095   return ret.retn();
10096 }
10097
10098 /*!
10099  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
10100  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
10101  *
10102  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
10103  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
10104  * \warning this is a shallow copy constructor
10105  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
10106  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
10107  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10108  *          is to delete this field using decrRef() as it is no more needed.
10109  */
10110 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
10111 {
10112   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
10113 }
10114
10115 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10116 {
10117   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10118   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10119   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
10120   ret->contentNotNull();//to check that content type matches with \a this type.
10121   return ret.retn();
10122 }
10123
10124 /*!
10125  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
10126  * following the given input policy.
10127  *
10128  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
10129  *                            By default (true) the globals are deeply copied.
10130  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
10131  */
10132 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
10133 {
10134   MCAuto<MEDFileFieldMultiTS> ret;
10135   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
10136   if(content)
10137     {
10138       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
10139       if(!contc)
10140         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
10141       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
10142       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
10143     }
10144   else
10145     ret=MEDFileFieldMultiTS::New();
10146   if(isDeepCpyGlobs)
10147     ret->deepCpyGlobs(*this);
10148   else
10149     ret->shallowCpyGlobs(*this);
10150   return ret.retn();
10151 }
10152
10153 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
10154 {
10155   return new MEDFileIntFieldMultiTS(*this);
10156 }
10157
10158 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
10159 {
10160   if(!f1ts)
10161     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
10162   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
10163   if(!f1tsC)
10164     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
10165 }
10166
10167 /*!
10168  * 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
10169  * method should be called (getFieldOnMeshAtLevel for example).
10170  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
10171  *
10172  * \param [in] iteration - the iteration number of a required time step.
10173  * \param [in] order - the iteration order number of required time step.
10174  * \param [in] mesh - the mesh the field is lying on
10175  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
10176  *          caller is to delete this field using decrRef() as it is no more needed. 
10177  */
10178 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
10179 {
10180   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10181   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10182   if(!myF1TSC)
10183     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
10184   MCAuto<DataArray> arrOut;
10185   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
10186   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
10187   return ret2.retn();
10188 }
10189
10190 /*!
10191  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10192  * mesh entities of a given dimension of the first mesh in MED file.
10193  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10194  *  \param [in] type - a spatial discretization of interest.
10195  *  \param [in] iteration - the iteration number of a required time step.
10196  *  \param [in] order - the iteration order number of required time step.
10197  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10198  *  \param [in] renumPol - specifies how to permute values of the result field according to
10199  *          the optional numbers of cells and nodes, if any. The valid values are
10200  *          - 0 - do not permute.
10201  *          - 1 - permute cells.
10202  *          - 2 - permute nodes.
10203  *          - 3 - permute cells and nodes.
10204  *
10205  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10206  *          caller is to delete this field using decrRef() as it is no more needed. 
10207  *  \throw If the MED file is not readable.
10208  *  \throw If there is no mesh in the MED file.
10209  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10210  *  \throw If no field values of the required parameters are available.
10211  */
10212 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
10213 {
10214   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10215   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10216   if(!myF1TSC)
10217     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
10218   MCAuto<DataArray> arr;
10219   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
10220   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10221   return ret2.retn();
10222 }
10223
10224 /*!
10225  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10226  * the top level cells of the first mesh in MED file.
10227  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10228  *  \param [in] type - a spatial discretization of interest.
10229  *  \param [in] iteration - the iteration number of a required time step.
10230  *  \param [in] order - the iteration order number of required time step.
10231  *  \param [in] renumPol - specifies how to permute values of the result field according to
10232  *          the optional numbers of cells and nodes, if any. The valid values are
10233  *          - 0 - do not permute.
10234  *          - 1 - permute cells.
10235  *          - 2 - permute nodes.
10236  *          - 3 - permute cells and nodes.
10237  *
10238  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10239  *          caller is to delete this field using decrRef() as it is no more needed. 
10240  *  \throw If the MED file is not readable.
10241  *  \throw If there is no mesh in the MED file.
10242  *  \throw If no field values of the required parameters are available.
10243  */
10244 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
10245 {
10246   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10247   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10248   if(!myF1TSC)
10249     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
10250   MCAuto<DataArray> arr;
10251   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
10252   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10253   return ret2.retn();
10254 }
10255
10256 /*!
10257  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10258  * a given support.
10259  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10260  *  \param [in] type - a spatial discretization of interest.
10261  *  \param [in] iteration - the iteration number of a required time step.
10262  *  \param [in] order - the iteration order number of required time step.
10263  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10264  *  \param [in] mesh - the supporting mesh.
10265  *  \param [in] renumPol - specifies how to permute values of the result field according to
10266  *          the optional numbers of cells and nodes, if any. The valid values are
10267  *          - 0 - do not permute.
10268  *          - 1 - permute cells.
10269  *          - 2 - permute nodes.
10270  *          - 3 - permute cells and nodes.
10271  *
10272  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10273  *          caller is to delete this field using decrRef() as it is no more needed. 
10274  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10275  *  \throw If no field of \a this is lying on \a mesh.
10276  *  \throw If no field values of the required parameters are available.
10277  */
10278 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10279 {
10280   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10281   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10282   if(!myF1TSC)
10283     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10284   MCAuto<DataArray> arr;
10285   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
10286   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10287   return ret2.retn();
10288 }
10289
10290 /*!
10291  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
10292  * given support. 
10293  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10294  *  \param [in] type - a spatial discretization of the new field.
10295  *  \param [in] iteration - the iteration number of a required time step.
10296  *  \param [in] order - the iteration order number of required time step.
10297  *  \param [in] mesh - the supporting mesh.
10298  *  \param [out] arrOut - the DataArrayInt containing values of field.
10299  *  \param [in] renumPol - specifies how to permute values of the result field according to
10300  *          the optional numbers of cells and nodes, if any. The valid values are
10301  *          - 0 - do not permute.
10302  *          - 1 - permute cells.
10303  *          - 2 - permute nodes.
10304  *          - 3 - permute cells and nodes.
10305  *
10306  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10307  *          caller is to delete this field using decrRef() as it is no more needed. 
10308  *  \throw If no field of \a this is lying on \a mesh.
10309  *  \throw If no field values of the required parameters are available.
10310  */
10311 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10312 {
10313   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10314   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10315   if(!myF1TSC)
10316     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10317   MCAuto<DataArray> arr;
10318   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
10319   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10320   return ret2.retn();
10321 }
10322
10323 /*!
10324  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
10325  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10326  * This method is useful for MED2 file format when field on different mesh was autorized.
10327  */
10328 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
10329 {
10330   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10331   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10332   if(!myF1TSC)
10333     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10334   MCAuto<DataArray> arr;
10335   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
10336   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10337   return ret2.retn();
10338 }
10339
10340 /*!
10341  * Returns values and a profile of the field of a given type, of a given time step,
10342  * lying on a given support.
10343  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10344  *  \param [in] type - a spatial discretization of the field.
10345  *  \param [in] iteration - the iteration number of a required time step.
10346  *  \param [in] order - the iteration order number of required time step.
10347  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10348  *  \param [in] mesh - the supporting mesh.
10349  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10350  *          field of interest lies on. If the field lies on all entities of the given
10351  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10352  *          using decrRef() as it is no more needed.  
10353  *  \param [in] glob - the global data storing profiles and localization.
10354  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
10355  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10356  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10357  *  \throw If no field of \a this is lying on \a mesh.
10358  *  \throw If no field values of the required parameters are available.
10359  */
10360 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10361 {
10362   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10363   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
10364   if(!myF1TSC)
10365     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
10366   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10367   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
10368 }
10369
10370 /*!
10371  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
10372  *  \param [in] pos - a time step id.
10373  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
10374  *          delete this field using decrRef() as it is no more needed.
10375  *  \throw If \a pos is not a valid time step id.
10376  */
10377 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
10378 {
10379   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
10380   if(!item)
10381     {
10382       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
10383       throw INTERP_KERNEL::Exception(oss.str());
10384     }
10385   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
10386   if(itemC)
10387     {
10388       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
10389       ret->shallowCpyGlobs(*this);
10390       return ret.retn();
10391     }
10392   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
10393   throw INTERP_KERNEL::Exception(oss.str());
10394 }
10395
10396 /*!
10397  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
10398  * the given field is checked if its elements are sorted suitable for writing to MED file
10399  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10400  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10401  *  \param [in] field - the field to add to \a this.
10402  *  \throw If the name of \a field is empty.
10403  *  \throw If the data array of \a field is not set.
10404  *  \throw If existing time steps have different name or number of components than \a field.
10405  *  \throw If the underlying mesh of \a field has no name.
10406  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10407  */
10408 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
10409 {
10410   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10411   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
10412 }
10413
10414 /*!
10415  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10416  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10417  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10418  * and \a profile.
10419  *
10420  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10421  * A new profile is added only if no equal profile is missing.
10422  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10423  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10424  *  \param [in] arrOfVals - the values of the field \a field used.
10425  *  \param [in] mesh - the supporting mesh of \a field.
10426  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10427  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10428  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10429  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10430  *  \throw If the data array of \a field is not set.
10431  *  \throw If the data array of \a this is already allocated but has different number of
10432  *         components than \a field.
10433  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10434  *  \sa setFieldNoProfileSBT()
10435  */
10436 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10437 {
10438   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10439   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10440 }
10441
10442 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10443 {
10444   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10445   if(!pt)
10446     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10447   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10448   if(!ret)
10449     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 !");
10450   return ret;
10451 }
10452
10453 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10454 {
10455   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10456   if(!pt)
10457     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10458   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10459   if(!ret)
10460     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 !");
10461   return ret;
10462 }
10463
10464 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10465 {
10466   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10467 }
10468
10469 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10470 {
10471 }
10472
10473 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10474 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10475 {
10476 }
10477 catch(INTERP_KERNEL::Exception& e)
10478 { throw e; }
10479
10480 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10481 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10482 {
10483 }
10484 catch(INTERP_KERNEL::Exception& e)
10485 { throw e; }
10486
10487 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10488 {
10489   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10490 }
10491
10492 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10493 {
10494   return MEDFileIntFieldMultiTS::New();
10495 }
10496
10497 //= MEDFileFields
10498
10499 MEDFileFields *MEDFileFields::New()
10500 {
10501   return new MEDFileFields;
10502 }
10503
10504 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10505 {
10506   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10507   return New(fid,loadAll);
10508 }
10509
10510 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
10511 {
10512   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10513   return NewWithDynGT(fid,se,loadAll);
10514 }
10515
10516 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
10517 {
10518   if(!se)
10519     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
10520   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
10521   return new MEDFileFields(fid,loadAll,0,entities);
10522 }
10523
10524 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10525 {
10526   return new MEDFileFields(fid,loadAll,0,0);
10527 }
10528
10529 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10530 {
10531   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10532   return new MEDFileFields(fid,loadAll,ms,0);
10533 }
10534
10535 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10536 {
10537   MEDFileUtilities::CheckFileForRead(fileName);
10538   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10539   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10540   return new MEDFileFields(fid,loadAll,0,ent);
10541 }
10542
10543 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10544 {
10545   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10546   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10547   return ret;
10548 }
10549
10550 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10551 {
10552   std::vector<const BigMemoryObject *> ret;
10553   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10554     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10555   return ret;
10556 }
10557
10558 MEDFileFields *MEDFileFields::deepCopy() const
10559 {
10560   MCAuto<MEDFileFields> ret(shallowCpy());
10561   std::size_t i(0);
10562   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10563     {
10564       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10565         ret->_fields[i]=(*it)->deepCopy();
10566     }
10567   ret->deepCpyGlobs(*this);
10568   return ret.retn();
10569 }
10570
10571 MEDFileFields *MEDFileFields::shallowCpy() const
10572 {
10573   return new MEDFileFields(*this);
10574 }
10575
10576 /*!
10577  * 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
10578  * 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.
10579  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10580  *
10581  * \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.
10582  * \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.
10583  * 
10584  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10585  */
10586 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10587 {
10588   std::set< std::pair<int,int> > s;
10589   bool firstShot=true;
10590   areThereSomeForgottenTS=false;
10591   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10592     {
10593       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10594         continue;
10595       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10596       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10597       if(firstShot)
10598         { s=s1; firstShot=false; }
10599       else
10600         {
10601           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10602           if(s!=s2)
10603             areThereSomeForgottenTS=true;
10604           s=s2;
10605         }
10606     }
10607   std::vector< std::pair<int,int> > ret;
10608   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10609   return ret;
10610 }
10611
10612 int MEDFileFields::getNumberOfFields() const
10613 {
10614   return _fields.size();
10615 }
10616
10617 std::vector<std::string> MEDFileFields::getFieldsNames() const
10618 {
10619   std::vector<std::string> ret(_fields.size());
10620   int i(0);
10621   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10622     {
10623       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10624       if(f)
10625         {
10626           ret[i]=f->getName();
10627         }
10628       else
10629         {
10630           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10631           throw INTERP_KERNEL::Exception(oss.str());
10632         }
10633     }
10634   return ret;
10635 }
10636
10637 std::vector<std::string> MEDFileFields::getMeshesNames() const
10638 {
10639   std::vector<std::string> ret;
10640   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10641     {
10642       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10643       if(cur)
10644         ret.push_back(cur->getMeshName());
10645     }
10646   return ret;
10647 }
10648
10649 std::string MEDFileFields::simpleRepr() const
10650 {
10651   std::ostringstream oss;
10652   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10653   simpleRepr(0,oss);
10654   return oss.str();
10655 }
10656
10657 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10658 {
10659   int nbOfFields(getNumberOfFields());
10660   std::string startLine(bkOffset,' ');
10661   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10662   int i=0;
10663   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10664     {
10665       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10666       if(cur)
10667         {
10668           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10669         }
10670       else
10671         {
10672           oss << startLine << "  - not defined !" << std::endl;
10673         }
10674     }
10675   i=0;
10676   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10677     {
10678       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10679       std::string chapter(17,'0'+i);
10680       oss << startLine << chapter << std::endl;
10681       if(cur)
10682         {
10683           cur->simpleRepr(bkOffset+2,oss,i);
10684         }
10685       else
10686         {
10687           oss << startLine << "  - not defined !" << std::endl;
10688         }
10689       oss << startLine << chapter << std::endl;
10690     }
10691   simpleReprGlobs(oss);
10692 }
10693
10694 MEDFileFields::MEDFileFields()
10695 {
10696 }
10697
10698 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10699 try:MEDFileFieldGlobsReal(fid)
10700 {
10701   int nbFields(MEDnField(fid));
10702   _fields.resize(nbFields);
10703   med_field_type typcha;
10704   for(int i=0;i<nbFields;i++)
10705     {
10706       std::vector<std::string> infos;
10707       std::string fieldName,dtunit;
10708       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit));
10709       switch(typcha)
10710       {
10711         case MED_FLOAT64:
10712           {
10713             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10714             break;
10715           }
10716         case MED_INT32:
10717           {
10718             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10719             break;
10720           }
10721         default:
10722           {
10723             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] !";
10724             throw INTERP_KERNEL::Exception(oss.str());
10725           }
10726       }
10727     }
10728   loadAllGlobals(fid);
10729 }
10730 catch(INTERP_KERNEL::Exception& e)
10731 {
10732     throw e;
10733 }
10734
10735 void MEDFileFields::writeLL(med_idt fid) const
10736 {
10737   int i=0;
10738   writeGlobals(fid,*this);
10739   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10740     {
10741       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10742       if(!elt)
10743         {
10744           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10745           throw INTERP_KERNEL::Exception(oss.str());
10746         }
10747       elt->writeLL(fid,*this);
10748     }
10749 }
10750
10751 /*!
10752  * This method alloc the arrays and load potentially huge arrays contained in this field.
10753  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10754  * This method can be also called to refresh or reinit values from a file.
10755  * 
10756  * \throw If the fileName is not set or points to a non readable MED file.
10757  */
10758 void MEDFileFields::loadArrays()
10759 {
10760   if(getFileName().empty())
10761     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10762   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10763   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10764     {
10765       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10766       if(elt)
10767         elt->loadBigArraysRecursively(fid,*elt);
10768     }
10769 }
10770
10771 /*!
10772  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10773  * But once data loaded once, this method does nothing.
10774  * 
10775  * \throw If the fileName is not set or points to a non readable MED file.
10776  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10777  */
10778 void MEDFileFields::loadArraysIfNecessary()
10779 {
10780   if(!getFileName().empty())
10781     {
10782       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10783       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10784         {
10785           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10786           if(elt)
10787             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10788         }
10789     }
10790 }
10791
10792 /*!
10793  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10794  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10795  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10796  * 
10797  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10798  */
10799 void MEDFileFields::unloadArrays()
10800 {
10801   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10802     {
10803       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10804       if(elt)
10805         elt->unloadArrays();
10806     }
10807 }
10808
10809 /*!
10810  * 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.
10811  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10812  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10813  * 
10814  * \sa MEDFileFields::loadArraysIfNecessary
10815  */
10816 void MEDFileFields::unloadArraysWithoutDataLoss()
10817 {
10818   if(!getFileName().empty())
10819     unloadArrays();
10820 }
10821
10822 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10823 {
10824   std::vector<std::string> ret;
10825   std::set<std::string> ret2;
10826   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10827     {
10828       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10829       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10830         if(ret2.find(*it2)==ret2.end())
10831           {
10832             ret.push_back(*it2);
10833             ret2.insert(*it2);
10834           }
10835     }
10836   return ret;
10837 }
10838
10839 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10840 {
10841   std::vector<std::string> ret;
10842   std::set<std::string> ret2;
10843   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10844     {
10845       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10846       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10847         if(ret2.find(*it2)==ret2.end())
10848           {
10849             ret.push_back(*it2);
10850             ret2.insert(*it2);
10851           }
10852     }
10853   return ret;
10854 }
10855
10856 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10857 {
10858   std::vector<std::string> ret;
10859   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10860     {
10861       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
10862       ret.insert(ret.end(),tmp.begin(),tmp.end());
10863     }
10864   return ret;
10865 }
10866
10867 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10868 {
10869   std::vector<std::string> ret;
10870   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10871     {
10872       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10873       ret.insert(ret.end(),tmp.begin(),tmp.end());
10874     }
10875   return ret;
10876 }
10877
10878 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10879 {
10880   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10881     (*it)->changePflsRefsNamesGen2(mapOfModif);
10882 }
10883
10884 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10885 {
10886   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10887     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10888 }
10889
10890 void MEDFileFields::resize(int newSize)
10891 {
10892   _fields.resize(newSize);
10893 }
10894
10895 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10896 {
10897   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10898     pushField(*it);
10899 }
10900
10901 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10902 {
10903   if(!field)
10904     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10905   _fields.push_back(field->getContent());
10906   appendGlobs(*field,1e-12);
10907 }
10908
10909 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10910 {
10911   if(!field)
10912     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10913   if(i>=(int)_fields.size())
10914     _fields.resize(i+1);
10915   _fields[i]=field->getContent();
10916   appendGlobs(*field,1e-12);
10917 }
10918
10919 void MEDFileFields::destroyFieldAtPos(int i)
10920 {
10921   destroyFieldsAtPos(&i,&i+1);
10922 }
10923
10924 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10925 {
10926   std::vector<bool> b(_fields.size(),true);
10927   for(const int *i=startIds;i!=endIds;i++)
10928     {
10929       if(*i<0 || *i>=(int)_fields.size())
10930         {
10931           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10932           throw INTERP_KERNEL::Exception(oss.str());
10933         }
10934       b[*i]=false;
10935     }
10936   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10937   std::size_t j=0;
10938   for(std::size_t i=0;i<_fields.size();i++)
10939     if(b[i])
10940       fields[j++]=_fields[i];
10941   _fields=fields;
10942 }
10943
10944 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10945 {
10946   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10947   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
10948   std::vector<bool> b(_fields.size(),true);
10949   int k=bg;
10950   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10951     {
10952       if(k<0 || k>=(int)_fields.size())
10953         {
10954           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10955           throw INTERP_KERNEL::Exception(oss.str());
10956         }
10957       b[k]=false;
10958     }
10959   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10960   std::size_t j(0);
10961   for(std::size_t i=0;i<_fields.size();i++)
10962     if(b[i])
10963       fields[j++]=_fields[i];
10964   _fields=fields;
10965 }
10966
10967 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10968 {
10969   bool ret(false);
10970   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10971     {
10972       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10973       if(cur)
10974         ret=cur->changeMeshNames(modifTab) || ret;
10975     }
10976   return ret;
10977 }
10978
10979 /*!
10980  * \param [in] meshName the name of the mesh that will be renumbered.
10981  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10982  *             This code corresponds to the distribution of types in the corresponding mesh.
10983  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10984  * \param [in] renumO2N the old to new renumber array.
10985  * \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 
10986  *         field in \a this.
10987  */
10988 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10989 {
10990   bool ret(false);
10991   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10992     {
10993       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10994       if(fmts)
10995         {
10996           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10997         }
10998     }
10999   return ret;
11000 }
11001
11002 /*!
11003  * Return an extraction of \a this using \a extractDef map to specify the extraction.
11004  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
11005  *
11006  * \return A new object that the caller is responsible to deallocate.
11007  */
11008 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
11009 {
11010   if(!mm)
11011     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
11012   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
11013   int nbFields(getNumberOfFields());
11014   for(int i=0;i<nbFields;i++)
11015     {
11016       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
11017       if(!fmts)
11018         {
11019           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
11020           throw INTERP_KERNEL::Exception(oss.str());
11021         }
11022       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
11023       fsOut->pushField(fmtsOut);
11024     }
11025   return fsOut.retn();
11026 }
11027
11028 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
11029 {
11030   if(i<0 || i>=(int)_fields.size())
11031     {
11032       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
11033       throw INTERP_KERNEL::Exception(oss.str());
11034     }
11035   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
11036   if(!fmts)
11037     return 0;
11038   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
11039   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
11040   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
11041   if(fmtsC)
11042     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
11043   else if(fmtsC2)
11044     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
11045   else
11046     {
11047       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
11048       throw INTERP_KERNEL::Exception(oss.str());
11049     }
11050   ret->shallowCpyGlobs(*this);
11051   return ret.retn();
11052 }
11053
11054 /*!
11055  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
11056  * This method is accessible in python using __getitem__ with a list in input.
11057  * \return a new object that the caller should deal with.
11058  */
11059 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
11060 {
11061   MCAuto<MEDFileFields> ret=shallowCpy();
11062   std::size_t sz=std::distance(startIds,endIds);
11063   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
11064   int j=0;
11065   for(const int *i=startIds;i!=endIds;i++,j++)
11066     {
11067       if(*i<0 || *i>=(int)_fields.size())
11068         {
11069           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
11070           throw INTERP_KERNEL::Exception(oss.str());
11071         }
11072       fields[j]=_fields[*i];
11073     }
11074   ret->_fields=fields;
11075   return ret.retn();
11076 }
11077
11078 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
11079 {
11080   return getFieldAtPos(getPosFromFieldName(fieldName));
11081 }
11082
11083 /*!
11084  * This method removes, if any, fields in \a this having no time steps.
11085  * 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.
11086  * 
11087  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
11088  */
11089 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
11090 {
11091   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
11092   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11093     {
11094       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
11095       if(elt)
11096         {
11097           if(elt->getNumberOfTS()>0)
11098             newFields.push_back(*it);
11099         }
11100     }
11101   if(_fields.size()==newFields.size())
11102     return false;
11103   _fields=newFields;
11104   return true;
11105 }
11106
11107 /*!
11108  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
11109  * This method can be seen as a filter applied on \a this, that returns an object containing
11110  * 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
11111  * shallow copied from \a this.
11112  * 
11113  * \param [in] meshName - the name of the mesh on w
11114  * \return a new object that the caller should deal with.
11115  */
11116 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
11117 {
11118   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11119   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11120     {
11121       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11122       if(!cur)
11123         continue;
11124       if(cur->getMeshName()==meshName)
11125         {
11126           cur->incrRef();
11127           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
11128           ret->_fields.push_back(cur2);
11129         }
11130     }
11131   ret->shallowCpyOnlyUsedGlobs(*this);
11132   return ret.retn();
11133 }
11134
11135 /*!
11136  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
11137  * Input time steps are specified using a pair of integer (iteration, order).
11138  * 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,
11139  * but for each multitimestep only the time steps in \a timeSteps are kept.
11140  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
11141  * 
11142  * The returned object points to shallow copy of elements in \a this.
11143  * 
11144  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
11145  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
11146  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
11147  */
11148 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11149 {
11150   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11151   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11152     {
11153       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11154       if(!cur)
11155         continue;
11156       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
11157       ret->_fields.push_back(elt);
11158     }
11159   ret->shallowCpyOnlyUsedGlobs(*this);
11160   return ret.retn();
11161 }
11162
11163 /*!
11164  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
11165  */
11166 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11167 {
11168   MCAuto<MEDFileFields> ret=MEDFileFields::New();
11169   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11170     {
11171       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11172       if(!cur)
11173         continue;
11174       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
11175       if(elt->getNumberOfTS()!=0)
11176         ret->_fields.push_back(elt);
11177     }
11178   ret->shallowCpyOnlyUsedGlobs(*this);
11179   return ret.retn();
11180 }
11181
11182 bool MEDFileFields::presenceOfStructureElements() const
11183 {
11184   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11185     if((*it).isNotNull())
11186       if((*it)->presenceOfStructureElements())
11187         return true;
11188   return false;
11189 }
11190
11191 void MEDFileFields::killStructureElements()
11192 {
11193   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11194   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11195     if((*it).isNotNull())
11196       {
11197         if((*it)->presenceOfStructureElements())
11198           {
11199             if(!(*it)->onlyStructureElements())
11200               {
11201                 (*it)->killStructureElements();
11202                 ret.push_back(*it);
11203               }
11204           }
11205         else
11206           {
11207             ret.push_back(*it);
11208           }
11209       }
11210   _fields=ret;
11211 }
11212
11213 void MEDFileFields::keepOnlyStructureElements()
11214 {
11215   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11216   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11217     if((*it).isNotNull())
11218       {
11219         if((*it)->presenceOfStructureElements())
11220           {
11221             if(!(*it)->onlyStructureElements())
11222               (*it)->keepOnlyStructureElements();
11223             ret.push_back(*it);
11224           }
11225       }
11226   _fields=ret;
11227 }
11228
11229 void MEDFileFields::keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName)
11230 {
11231   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11232   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11233     if((*it).isNotNull())
11234       {
11235         if((*it)->getMeshName()!=meshName)
11236           continue;
11237         std::vector< std::pair<std::string,std::string> > ps;
11238         (*it)->getMeshSENames(ps);
11239         std::pair<std::string,std::string> p(meshName,seName);
11240         if(std::find(ps.begin(),ps.end(),p)!=ps.end())
11241           (*it)->keepOnlyOnSE(seName);
11242         ret.push_back(*it);
11243       }
11244   _fields=ret;
11245 }
11246
11247 void MEDFileFields::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
11248 {
11249   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11250     if((*it).isNotNull())
11251       (*it)->getMeshSENames(ps);
11252 }
11253
11254 MCAuto<MEDFileFields> MEDFileFields::partOfThisOnStructureElements() const
11255 {
11256   MCAuto<MEDFileFields> ret(deepCopy());
11257   ret->keepOnlyStructureElements();
11258   return ret;
11259 }
11260
11261 MCAuto<MEDFileFields> MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const
11262 {
11263   MCAuto<MEDFileFields> ret(deepCopy());
11264   ret->keepOnlyOnMeshSE(meshName,seName);
11265   return ret;
11266 }
11267
11268 void MEDFileFields::aggregate(const MEDFileFields& other)
11269 {
11270   int nbFieldsToAdd(other.getNumberOfFields());
11271   std::vector<std::string> fsn(getFieldsNames());
11272   for(int i=0;i<nbFieldsToAdd;i++)
11273     {
11274       MCAuto<MEDFileAnyTypeFieldMultiTS> elt(other.getFieldAtPos(i));
11275       std::string name(elt->getName());
11276       if(std::find(fsn.begin(),fsn.end(),name)!=fsn.end())
11277         {
11278           std::ostringstream oss; oss << "MEDFileFields::aggregate : name \"" << name << "\" already appears !";
11279           throw INTERP_KERNEL::Exception(oss.str());
11280         }
11281       pushField(elt);
11282     }
11283 }
11284
11285 MEDFileFieldsIterator *MEDFileFields::iterator()
11286 {
11287   return new MEDFileFieldsIterator(this);
11288 }
11289
11290 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
11291 {
11292   std::string tmp(fieldName);
11293   std::vector<std::string> poss;
11294   for(std::size_t i=0;i<_fields.size();i++)
11295     {
11296       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
11297       if(f)
11298         {
11299           std::string fname(f->getName());
11300           if(tmp==fname)
11301             return i;
11302           else
11303             poss.push_back(fname);
11304         }
11305     }
11306   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
11307   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
11308   oss << " !";
11309   throw INTERP_KERNEL::Exception(oss.str());
11310 }
11311
11312 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
11313 {
11314   if(fs)
11315     {
11316       fs->incrRef();
11317       _nb_iter=fs->getNumberOfFields();
11318     }
11319 }
11320
11321 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
11322 {
11323 }
11324
11325 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
11326 {
11327   if(_iter_id<_nb_iter)
11328     {
11329       MEDFileFields *fs(_fs);
11330       if(fs)
11331         return fs->getFieldAtPos(_iter_id++);
11332       else
11333         return 0;
11334     }
11335   else
11336     return 0;
11337 }