Salome HOME
Step 8 : meshes have been managed, fields still remaining.
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDFileField.txx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDLoaderTraits.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileFieldOverView.hxx"
27
28 #include "MEDCouplingFieldDouble.hxx"
29 #include "MEDCouplingFieldTemplate.hxx"
30 #include "MEDCouplingFieldDiscretization.hxx"
31
32 #include "InterpKernelAutoPtr.hxx"
33 #include "CellModel.hxx"
34
35 #include <algorithm>
36 #include <iterator>
37
38 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
39 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
40 extern med_geometry_type typmainoeud[1];
41 extern med_geometry_type typmai3[34];
42
43 using namespace MEDCoupling;
44
45 template class MEDFileField1TSTemplateWithoutSDA<int>;
46 template class MEDFileField1TSTemplateWithoutSDA<double>;
47
48 const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64";
49 const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32";
50
51 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const std::string& locName)
52 {
53   return new MEDFileFieldLoc(fid,locName);
54 }
55
56 MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, int id)
57 {
58   return new MEDFileFieldLoc(fid,id);
59 }
60
61 MEDFileFieldLoc *MEDFileFieldLoc::New(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
62 {
63   return new MEDFileFieldLoc(locName,geoType,refCoo,gsCoo,w);
64 }
65
66 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(locName)
67 {
68   med_geometry_type geotype;
69   med_geometry_type sectiongeotype;
70   int nsectionmeshcell;
71   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
72   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
73   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
74   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
75   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
76   _nb_node_per_cell=cm.getNumberOfNodes();
77   _ref_coo.resize(_dim*_nb_node_per_cell);
78   _gs_coo.resize(_dim*_nb_gauss_pt);
79   _w.resize(_nb_gauss_pt);
80   MEDlocalizationRd(fid,locName.c_str(),MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
81 }
82
83 MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id)
84 {
85   med_geometry_type geotype;
86   med_geometry_type sectiongeotype;
87   int nsectionmeshcell;
88   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
89   INTERP_KERNEL::AutoPtr<char> geointerpname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
90   INTERP_KERNEL::AutoPtr<char> sectionmeshname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
91   MEDlocalizationInfo(fid,id+1,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
92   _name=locName;
93   _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype)));
94   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
95   _nb_node_per_cell=cm.getNumberOfNodes();
96   _ref_coo.resize(_dim*_nb_node_per_cell);
97   _gs_coo.resize(_dim*_nb_gauss_pt);
98   _w.resize(_nb_gauss_pt);
99   MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]);
100 }
101
102 MEDFileFieldLoc::MEDFileFieldLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType,
103                                  const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w):_name(locName),_geo_type(geoType),_ref_coo(refCoo),_gs_coo(gsCoo),
104                                      _w(w)
105 {
106   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
107   _dim=cm.getDimension();
108   _nb_node_per_cell=cm.getNumberOfNodes();
109   _nb_gauss_pt=_w.size();
110 }
111
112 MEDFileFieldLoc *MEDFileFieldLoc::deepCopy() const
113 {
114   return new MEDFileFieldLoc(*this);
115 }
116
117 std::size_t MEDFileFieldLoc::getHeapMemorySizeWithoutChildren() const
118 {
119   return (_ref_coo.capacity()+_gs_coo.capacity()+_w.capacity())*sizeof(double)+_name.capacity();
120 }
121
122 std::vector<const BigMemoryObject *> MEDFileFieldLoc::getDirectChildrenWithNull() const
123 {
124   return std::vector<const BigMemoryObject *>();
125 }
126
127 void MEDFileFieldLoc::simpleRepr(std::ostream& oss) const
128 {
129   static const char OFF7[]="\n    ";
130   oss << "\"" << _name << "\"" << OFF7;
131   oss << "GeoType=" << INTERP_KERNEL::CellModel::GetCellModel(_geo_type).getRepr() << OFF7;
132   oss << "Dimension=" << _dim << OFF7;
133   oss << "Number of Gauss points=" << _nb_gauss_pt << OFF7;
134   oss << "Number of nodes per cell=" << _nb_node_per_cell << OFF7;
135   oss << "RefCoords="; std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
136   oss << "Weights="; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," ")); oss << OFF7;
137   oss << "GaussPtsCoords="; std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," ")); oss << std::endl;
138 }
139
140 void MEDFileFieldLoc::setName(const std::string& name)
141 {
142   _name=name;
143 }
144
145 bool MEDFileFieldLoc::isEqual(const MEDFileFieldLoc& other, double eps) const
146 {
147   if(_name!=other._name)
148     return false;
149   if(_dim!=other._dim)
150     return false;
151   if(_nb_gauss_pt!=other._nb_gauss_pt)
152     return false;
153   if(_nb_node_per_cell!=other._nb_node_per_cell)
154     return false;
155   if(_geo_type!=other._geo_type)
156     return false;
157   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_ref_coo,other._ref_coo,eps))
158     return false;
159   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_gs_coo,other._gs_coo,eps))
160     return false;
161   if(!MEDCouplingGaussLocalization::AreAlmostEqual(_w,other._w,eps))
162     return false;
163
164   return true;
165 }
166
167 void MEDFileFieldLoc::writeLL(med_idt fid) const
168 {
169   MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT);
170 }
171
172 std::string MEDFileFieldLoc::repr() const
173 {
174   std::ostringstream oss; oss.precision(15);
175   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
176   oss << "Localization \"" << _name << "\" :\n" << "  - Geometric Type : " << cm.getRepr();
177   oss << "\n  - Dimension : " << _dim << "\n  - Number of gauss points : ";
178   oss << _nb_gauss_pt << "\n  - Number of nodes in cell : " << _nb_node_per_cell;
179   oss << "\n  - Ref coords are : ";
180   int sz=_ref_coo.size();
181   if(sz%_dim==0)
182     {
183       int nbOfTuples=sz/_dim;
184       for(int i=0;i<nbOfTuples;i++)
185         {
186           oss << "(";
187           for(int j=0;j<_dim;j++)
188             { oss << _ref_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
189           oss << ") ";
190         }
191     }
192   else
193     std::copy(_ref_coo.begin(),_ref_coo.end(),std::ostream_iterator<double>(oss," "));
194   oss << "\n  - Gauss coords in reference element : ";
195   sz=_gs_coo.size();
196   if(sz%_dim==0)
197     {
198       int nbOfTuples=sz/_dim;
199       for(int i=0;i<nbOfTuples;i++)
200         {
201           oss << "(";
202           for(int j=0;j<_dim;j++)
203             { oss << _gs_coo[i*_dim+j]; if(j!=_dim-1) oss << ", "; }
204           oss << ") ";
205         }
206     }
207   else
208     std::copy(_gs_coo.begin(),_gs_coo.end(),std::ostream_iterator<double>(oss," "));
209   oss << "\n  - Weights of Gauss coords are : "; std::copy(_w.begin(),_w.end(),std::ostream_iterator<double>(oss," "));
210   return oss.str();
211 }
212
213 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
214 {
215   _type=field->getTypeOfField();
216   _start=start;
217   switch(_type)
218   {
219     case ON_CELLS:
220       {
221         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,offset,offset+nbOfCells,1);
222         _end=_start+nbOfCells;
223         _nval=nbOfCells;
224         break;
225       }
226     case ON_GAUSS_NE:
227       {
228         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(field->getMesh());
229         const int *arrPtr=arr->getConstPointer();
230         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,arrPtr[offset],arrPtr[offset+nbOfCells],1);
231         _end=_start+(arrPtr[offset+nbOfCells]-arrPtr[offset]);
232         _nval=nbOfCells;
233         break;
234       }
235     case ON_GAUSS_PT:
236       {
237         const MEDCouplingFieldDiscretization *disc(field->getDiscretization());
238         const MEDCouplingGaussLocalization& gsLoc(field->getGaussLocalization(_loc_id));
239         const MEDCouplingFieldDiscretizationGauss *disc2(dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc));
240         if(!disc2)
241           throw INTERP_KERNEL::Exception("assignFieldNoProfile : invalid call to this method ! Internal Error !");
242         const DataArrayInt *dai(disc2->getArrayOfDiscIds());
243         MCAuto<DataArrayInt> dai2(disc2->getOffsetArr(field->getMesh()));
244         const int *dai2Ptr(dai2->getConstPointer());
245         int nbi(gsLoc.getWeights().size());
246         MCAuto<DataArrayInt> da2(dai->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1));
247         MCAuto<DataArrayInt> da3(da2->findIdsEqual(_loc_id));
248         const int *da3Ptr(da3->getConstPointer());
249         if(da3->getNumberOfTuples()!=nbOfCells)
250           {//profile : for gauss even in NoProfile !!!
251             std::ostringstream oss; oss << "Pfl_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
252             _profile=oss.str();
253             da3->setName(_profile.c_str());
254             glob.appendProfile(da3);
255           }
256         MCAuto<DataArrayInt> da4(DataArrayInt::New());
257         _nval=da3->getNbOfElems();
258         da4->alloc(_nval*nbi,1);
259         int *da4Ptr(da4->getPointer());
260         for(int i=0;i<_nval;i++)
261           {
262             int ref=dai2Ptr[offset+da3Ptr[i]];
263             for(int j=0;j<nbi;j++)
264               *da4Ptr++=ref+j;
265           }
266         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
267         _localization=oss2.str();
268         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,da4);
269         _end=_start+_nval*nbi;
270         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
271         break;
272       }
273     default:
274       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile : not implemented yet for such discretization type of field !");
275   }
276   start=_end;
277 }
278
279 /*!
280  * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here.
281  * \param [in] pflName input containing name of profile if any. 0 if no profile (except for GAUSS_PT where a no profile can hide a profile when splitted by loc_id).
282  * \param [in] multiTypePfl is the end user profile specified in high level API
283  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
284  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
285  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
286  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
287  */
288 void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arrr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
289 {
290   _profile.clear();
291   _type=field->getTypeOfField();
292   std::string pflName(multiTypePfl->getName());
293   std::ostringstream oss; oss << pflName;
294   if(_type!=ON_NODES)
295     {
296       if(!isPflAlone)
297         { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" <<  cm.getRepr(); }
298     }
299   else
300     { oss << "_NODE"; }
301   if(locIds)
302     {
303       if(pflName.empty())
304         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !");
305       if(_type!=ON_GAUSS_PT)
306         {
307           locIds->setName(oss.str());
308           glob.appendProfile(locIds);
309           _profile=oss.str();
310         }
311     }
312   _start=start;
313   switch(_type)
314   {
315     case ON_NODES:
316       {
317         _nval=idsInPfl->getNumberOfTuples();
318         getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,arrr->getNumberOfTuples(),1);
319         _end=_start+_nval;
320         break;
321       }
322     case ON_CELLS:
323       {
324         _nval=idsInPfl->getNumberOfTuples();
325         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,idsInPfl);
326         _end=_start+_nval;
327         break;
328       }
329     case ON_GAUSS_NE:
330       {
331         MCAuto<DataArrayInt> arr=field->getDiscretization()->getOffsetArr(mesh);
332         MCAuto<DataArrayInt> arr2=arr->deltaShiftIndex();
333         MCAuto<DataArrayInt> arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end());
334         arr3->computeOffsetsFull();
335         MCAuto<DataArrayInt> tmp=idsInPfl->buildExplicitArrByRanges(arr3);
336         int trueNval=tmp->getNumberOfTuples();
337         _nval=idsInPfl->getNumberOfTuples();
338         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
339         _end=_start+trueNval;
340         break;
341       }
342     case ON_GAUSS_PT:
343       {
344         const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(field->getDiscretization());
345         if(!disc2)
346           throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
347         const DataArrayInt *da1=disc2->getArrayOfDiscIds();
348         const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id);
349         MCAuto<DataArrayInt> da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end());
350         MCAuto<DataArrayInt> da3=da2->findIdsEqual(_loc_id);
351         MCAuto<DataArrayInt> da4=idsInPfl->selectByTupleId(da3->begin(),da3->end());
352         //
353         MCAuto<MEDCouplingMesh> mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end());
354         MCAuto<DataArrayInt> arr=disc2->getOffsetArr(mesh2);
355         //
356         MCAuto<DataArrayInt> tmp=DataArrayInt::New();
357         int trueNval=0;
358         for(const int *pt=da4->begin();pt!=da4->end();pt++)
359           trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0);
360         tmp->alloc(trueNval,1);
361         int *tmpPtr=tmp->getPointer();
362         for(const int *pt=da4->begin();pt!=da4->end();pt++)
363           for(int j=arr->getIJ(*pt,0);j<arr->getIJ(*pt+1,0);j++)
364             *tmpPtr++=j;
365         //
366         _nval=da4->getNumberOfTuples();
367         getOrCreateAndGetArray()->setContigPartOfSelectedValues(_start,arrr,tmp);
368         _end=_start+trueNval;
369         oss << "_loc_" << _loc_id;
370         if(locIds)
371           {
372             MCAuto<DataArrayInt> da5=locIds->selectByTupleId(da3->begin(),da3->end());
373             da5->setName(oss.str());
374             glob.appendProfile(da5);
375             _profile=oss.str();
376           }
377         else
378           {
379             if(!da3->isIota(nbOfEltsInWholeMesh))
380               {
381                 da3->setName(oss.str());
382                 glob.appendProfile(da3);
383                 _profile=oss.str();
384               }
385           }
386         std::ostringstream oss2; oss2 << "Loc_" << nasc.getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id;
387         _localization=oss2.str();
388         glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights());
389         break;
390       }
391     default:
392       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !");
393   }
394   start=_end;
395 }
396
397 void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arrr, MEDFileFieldGlobsReal& glob)
398 {
399   _start=start;
400   _nval=arrr->getNumberOfTuples();
401   getOrCreateAndGetArray()->setContigPartOfSelectedValuesSlice(_start,arrr,0,_nval,1);
402   _end=_start+_nval;
403   start=_end;
404 }
405
406 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int profileIt, const PartDefinition *pd)
407 {
408   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,profileIt,pd);
409 }
410
411 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId)
412 {
413   return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId,std::string());
414 }
415
416 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(const MEDFileFieldPerMeshPerTypePerDisc& other)
417 {
418   return new MEDFileFieldPerMeshPerTypePerDisc(other);
419 }
420
421 std::size_t MEDFileFieldPerMeshPerTypePerDisc::getHeapMemorySizeWithoutChildren() const
422 {
423   return _profile.capacity()+_localization.capacity()+sizeof(MEDFileFieldPerMeshPerTypePerDisc);
424 }
425
426 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypePerDisc::getDirectChildrenWithNull() const
427 {
428   std::vector<const BigMemoryObject *> ret(1);
429   ret[0]=(const PartDefinition*)_pd;
430   return ret;
431 }
432
433 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const
434 {
435   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(*this));
436   ret->_father=father;
437   return ret.retn();
438 }
439
440 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField atype, int profileIt, const PartDefinition *pd)
441 try:_type(atype),_father(fath),_profile_it(profileIt),_pd(const_cast<PartDefinition *>(pd))
442 {
443   if(pd)
444     pd->incrRef();
445 }
446 catch(INTERP_KERNEL::Exception& e)
447 {
448     throw e;
449 }
450
451 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerTypeCommon *fath, TypeOfField type, int locId, const std::string& dummy):_type(type),_father(fath),_loc_id(locId)
452 {
453 }
454
455 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc& other):RefCountObject(other),_type(other._type),_father(0),_start(other._start),_end(other._end),_nval(other._nval),_profile(other._profile),_localization(other._localization),_loc_id(other._loc_id),_profile_it(other._profile_it),_pd(other._pd),_tmp_work1(other._tmp_work1)
456 {
457 }
458
459 MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc():_type(ON_CELLS),_father(0),_start(-std::numeric_limits<int>::max()),_end(-std::numeric_limits<int>::max()),
460     _nval(-std::numeric_limits<int>::max()),_loc_id(-std::numeric_limits<int>::max())
461 {
462 }
463
464 void MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile(med_idt fid, const std::string& fieldName, int nbOfCompo, int iteration, int order, med_entity_type menti, med_geometry_type mgeoti, unsigned char *startFeedingPtr)
465 {
466   const PartDefinition *pd(_pd);
467   if(!pd)
468     {
469       INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
470       int nbi,tmp1;
471       med_int nbValsInFile(MEDfieldnValueWithProfileByName(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile.c_str(),MED_COMPACT_PFLMODE,&tmp1,locname,&nbi));
472       if(_end-_start!=nbValsInFile*nbi)
473         {
474           std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : The number of tuples to read is " << nbValsInFile << "*" << nbi <<  " (nb integration points) ! But in data structure it values " << _end-_start << " is expected !";
475           throw INTERP_KERNEL::Exception(oss.str());
476         }
477       MEDFILESAFECALLERRD0(MEDfieldValueWithProfileRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE,_profile.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,startFeedingPtr));
478     }
479   else
480     {
481       if(!_profile.empty())
482         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile : not implemented !");
483       INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
484       int profilesize,nbi;
485       int overallNval(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
486       const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
487       if(spd)
488         {
489           int start,stop,step;
490           spd->getSlice(start,stop,step);
491           int nbOfEltsToLoad(DataArray::GetNumberOfItemGivenBES(start,stop,step,"MEDFileFieldPerMeshPerTypePerDisc::goReadZeValuesInFile"));
492           med_filter filter=MED_FILTER_INIT;
493           MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
494                                    MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
495                                    /*start*/start+1,/*stride*/step,/*count*/1,/*blocksize*/nbOfEltsToLoad,
496                                    /*lastblocksize=useless because count=1*/0,&filter);
497           MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,startFeedingPtr));
498           MEDfilterClose(&filter);
499           return ;
500         }
501       const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
502       if(dpd)
503         {
504           dpd->checkConsistencyLight();
505           MCAuto<DataArrayInt> myIds(dpd->toDAI());
506           int a(myIds->getMinValueInArray()),b(myIds->getMaxValueInArray());
507           myIds=myIds->deepCopy();// WARNING deep copy here because _pd is modified by applyLin !!!
508           myIds->applyLin(1,-a);
509           int nbOfEltsToLoad(b-a+1);
510           med_filter filter=MED_FILTER_INIT;
511           {//TODO : manage int32 !
512             MCAuto<DataArrayDouble> tmp(DataArrayDouble::New());
513             tmp->alloc(nbOfEltsToLoad,nbOfCompo);
514             MEDfilterBlockOfEntityCr(fid,/*nentity*/overallNval,/*nvaluesperentity*/nbi,/*nconstituentpervalue*/nbOfCompo,
515                                      MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
516                                      /*start*/a+1,/*stride*/1,/*count*/1,/*blocksize*/nbOfEltsToLoad,
517                                      /*lastblocksize=useless because count=1*/0,&filter);
518             MEDFILESAFECALLERRD0(MEDfieldValueAdvancedRd,(fid,fieldName.c_str(),iteration,order,menti,mgeoti,&filter,reinterpret_cast<unsigned char *>(tmp->getPointer())));
519             MCAuto<DataArrayDouble> feeder(DataArrayDouble::New());
520             feeder->useExternalArrayWithRWAccess(reinterpret_cast<double *>(startFeedingPtr),_nval,nbOfCompo);
521             feeder->setContigPartOfSelectedValues(0,tmp,myIds);
522           }
523           MEDfilterClose(&filter);
524         }
525       else
526         throw INTERP_KERNEL::Exception("Not implemented yet for not slices!");
527     }
528 }
529
530 const MEDFileFieldPerMeshPerTypeCommon *MEDFileFieldPerMeshPerTypePerDisc::getFather() const
531 {
532   return _father;
533 }
534
535 void MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
536 {
537   INTERP_KERNEL::AutoPtr<char> locname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
538   INTERP_KERNEL::AutoPtr<char> pflname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
539   std::string fieldName(nasc.getName()),meshName(getMeshName());
540   int iteration(getIteration()),order(getOrder()),profilesize,nbi;
541   TypeOfField type(getType());
542   med_geometry_type mgeoti;
543   med_entity_type menti;
544   _father->entriesForMEDfile(type,mgeoti,menti);
545   int zeNVal(MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,menti,mgeoti,_profile_it+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi));
546   _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
547   _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
548   const PartDefinition *pd(_pd);
549   if(!pd)
550     {
551       _nval=zeNVal;
552     }
553   else
554     {
555       if(!_profile.empty())
556         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadOnlyStructureOfDataRecursively : profiles are not managed yet with part of def !");
557       _nval=pd->getNumberOfElems();
558     }
559   _start=start;
560   _end=start+_nval*nbi;
561   start=_end;
562   if(type==ON_CELLS && !_localization.empty())
563     {
564       if(_localization!="MED_GAUSS_ELNO")//For compatibily with MED2.3
565         setType(ON_GAUSS_PT);
566       else
567         {
568           setType(ON_GAUSS_NE);
569           _localization.clear();
570         }
571     }
572 }
573
574 void MEDFileFieldPerMeshPerTypePerDisc::loadBigArray(med_idt fid, const MEDFileFieldNameScope& nasc)
575 {
576   std::string fieldName(nasc.getName()),meshName(getMeshName());
577   int iteration(getIteration()),order(getOrder());
578   TypeOfField type(getType());
579   med_geometry_type mgeoti;
580   med_entity_type menti;
581   _father->entriesForMEDfile(type,mgeoti,menti);
582   if(_start>_end)
583     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : internal error in range !");
584   if(_start==_end)
585     return ;
586   DataArray *arr(getOrCreateAndGetArray());//arr is not null due to the spec of getOrCreateAndGetArray
587   if(_start<0 || _start>=arr->getNumberOfTuples())
588     {
589       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << ") !";
590       throw INTERP_KERNEL::Exception(oss.str());
591     }
592   if(_end<0 || _end>arr->getNumberOfTuples())
593     {
594       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypePerDisc::loadBigArray : Invalid start ("<< _start << ") regarding admissible range of allocated array [0," << arr->getNumberOfTuples() << "] !";
595       throw INTERP_KERNEL::Exception(oss.str());
596     }
597   int nbOfCompo(arr->getNumberOfComponents());
598   DataArrayDouble *arrD(dynamic_cast<DataArrayDouble *>(arr));
599   if(arrD)
600     {
601       double *startFeeding(arrD->getPointer()+_start*nbOfCompo);
602       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
603       return ;
604     }
605   DataArrayInt *arrI(dynamic_cast<DataArrayInt *>(arr));
606   if(arrI)
607     {
608       int *startFeeding(arrI->getPointer()+_start*nbOfCompo);
609       goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
610       return ;
611     }
612   throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
613 }
614
615 /*!
616  * Set a \c this->_start **and** \c this->_end keeping the same delta between the two.
617  */
618 void MEDFileFieldPerMeshPerTypePerDisc::setNewStart(int newValueOfStart)
619 {
620   int delta=_end-_start;
621   _start=newValueOfStart;
622   _end=_start+delta;
623 }
624
625 int MEDFileFieldPerMeshPerTypePerDisc::getIteration() const
626 {
627   return _father->getIteration();
628 }
629
630 int MEDFileFieldPerMeshPerTypePerDisc::getOrder() const
631 {
632   return _father->getOrder();
633 }
634
635 double MEDFileFieldPerMeshPerTypePerDisc::getTime() const
636 {
637   return _father->getTime();
638 }
639
640 std::string MEDFileFieldPerMeshPerTypePerDisc::getMeshName() const
641 {
642   return _father->getMeshName();
643 }
644
645 void MEDFileFieldPerMeshPerTypePerDisc::simpleRepr(int bkOffset, std::ostream& oss, int id) const
646 {
647   const char startLine[]="    ## ";
648   std::string startLine2(bkOffset,' ');
649   startLine2+=startLine;
650   INTERP_KERNEL::AutoCppPtr<MEDCouplingFieldDiscretization> tmp(MEDCouplingFieldDiscretization::New(_type));
651   oss << startLine2 << "Localization #" << id << "." << std::endl;
652   oss << startLine2 << "  Type=" << tmp->getRepr() << "." << std::endl;
653   oss << startLine2 << "  This type discretization lies on profile : \"" << _profile << "\" and on the following localization : \"" << _localization << "\"." << std::endl;
654   oss << startLine2 << "  This type discretization has " << _end-_start << " tuples (start=" << _start << ", end=" << _end << ")." << std::endl;
655   oss << startLine2 << "  This type discretization has " << (_end-_start)/_nval << " integration points." << std::endl;
656 }
657
658 TypeOfField MEDFileFieldPerMeshPerTypePerDisc::getType() const
659 {
660   return _type;
661 }
662
663 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypePerDisc::getGeoType() const
664 {
665   return _father->getGeoType();
666 }
667
668 void MEDFileFieldPerMeshPerTypePerDisc::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
669 {
670   types.insert(_type);
671 }
672
673 void MEDFileFieldPerMeshPerTypePerDisc::setType(TypeOfField newType)
674 {
675   _type=newType;
676 }
677
678 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfComponents() const
679 {
680   return _father->getNumberOfComponents();
681 }
682
683 int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
684 {
685   return _end-_start;
686 }
687
688 DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray()
689 {
690   return _father->getOrCreateAndGetArray();
691 }
692
693 const DataArray *MEDFileFieldPerMeshPerTypePerDisc::getOrCreateAndGetArray() const
694 {
695   const MEDFileFieldPerMeshPerTypeCommon *fath=_father;
696   return fath->getOrCreateAndGetArray();
697 }
698
699 const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfo() const
700 {
701   return _father->getInfo();
702 }
703
704 std::string MEDFileFieldPerMeshPerTypePerDisc::getProfile() const
705 {
706   return _profile;
707 }
708
709 void MEDFileFieldPerMeshPerTypePerDisc::setProfile(const std::string& newPflName)
710 {
711   _profile=newPflName;
712 }
713
714 std::string MEDFileFieldPerMeshPerTypePerDisc::getLocalization() const
715 {
716   return _localization;
717 }
718
719 void MEDFileFieldPerMeshPerTypePerDisc::setLocalization(const std::string& newLocName)
720 {
721   _localization=newLocName;
722 }
723
724 void MEDFileFieldPerMeshPerTypePerDisc::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
725 {
726   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
727     {
728       if(std::find((*it2).first.begin(),(*it2).first.end(),_profile)!=(*it2).first.end())
729         {
730           _profile=(*it2).second;
731           return;
732         }
733     }
734 }
735
736 void MEDFileFieldPerMeshPerTypePerDisc::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
737 {
738   for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
739     {
740       if(std::find((*it2).first.begin(),(*it2).first.end(),_localization)!=(*it2).first.end())
741         {
742           _localization=(*it2).second;
743           return;
744         }
745     }
746 }
747
748 void MEDFileFieldPerMeshPerTypePerDisc::getFieldAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
749 {
750   if(type!=_type)
751     return ;
752   dads.push_back(std::pair<int,int>(_start,_end));
753   geoTypes.push_back(getGeoType());
754   if(_profile.empty())
755     pfls.push_back(0);
756   else
757     {
758       pfls.push_back(glob->getProfile(_profile.c_str()));
759     }
760   if(_localization.empty())
761     locs.push_back(-1);
762   else
763     {
764       locs.push_back(glob->getLocalizationId(_localization.c_str()));
765     }
766 }
767
768 void MEDFileFieldPerMeshPerTypePerDisc::fillValues(int discId, int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
769 {
770   entries[startEntryId]=std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int> ,std::pair<int,int> >(std::pair<INTERP_KERNEL::NormalizedCellType,int>(getGeoType(),discId),std::pair<int,int>(_start,_end));
771   startEntryId++;
772 }
773
774 void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
775 {
776   TypeOfField type=getType();
777   INTERP_KERNEL::NormalizedCellType geoType(getGeoType());
778   med_geometry_type mgeoti;
779   med_entity_type menti;
780   _father->entriesForMEDfile(getType(),mgeoti,menti);
781   const DataArray *arr(getOrCreateAndGetArray());
782   if(!arr)
783     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
784   if(!arr->isAllocated())
785     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
786   const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
787   const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
788   const unsigned char *locToWrite=0;
789   if(arrD)
790     locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
791   else if(arrI)
792     locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
793   else
794     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
795   MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
796                                                    MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
797                                                    locToWrite));
798 }
799
800 void MEDFileFieldPerMeshPerTypePerDisc::getCoarseData(TypeOfField& type, std::pair<int,int>& dad, std::string& pfl, std::string& loc) const
801 {
802   type=_type;
803   pfl=_profile;
804   loc=_localization;
805   dad.first=_start; dad.second=_end;
806 }
807
808 /*!
809  * \param [in] codeOfMesh is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
810  *             This code corresponds to the distribution of types in the corresponding mesh.
811  * \param [out] ptToFill memory zone where the output will be stored.
812  * \return the size of data pushed into output param \a ptToFill
813  */
814 int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std::vector<int>& codeOfMesh, const MEDFileFieldGlobsReal& glob, int *ptToFill) const
815 {
816   _loc_id=offset;
817   std::ostringstream oss;
818   std::size_t nbOfType=codeOfMesh.size()/3;
819   int found=-1;
820   for(std::size_t i=0;i<nbOfType && found==-1;i++)
821     if(getGeoType()==(INTERP_KERNEL::NormalizedCellType)codeOfMesh[3*i])
822       found=(int)i;
823   if(found==-1)
824     {
825       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
826       oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : not found geometric type " << cm.getRepr() << " in the referenced mesh of field !";
827       throw INTERP_KERNEL::Exception(oss.str());
828     }
829   int *work=ptToFill;
830   if(_profile.empty())
831     {
832       if(_nval!=codeOfMesh[3*found+1])
833         {
834           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
835           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << " number of elt ids in mesh is equal to " << _nval;
836           oss << " whereas mesh has " << codeOfMesh[3*found+1] << " for this geometric type !";
837           throw INTERP_KERNEL::Exception(oss.str());
838         }
839       for(int ii=codeOfMesh[3*found+2];ii<codeOfMesh[3*found+2]+_nval;ii++)
840         *work++=ii;
841     }
842   else
843     {
844       const DataArrayInt *pfl=glob.getProfile(_profile.c_str());
845       if(pfl->getNumberOfTuples()!=_nval)
846         {
847           const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType());
848           oss << "MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode : for geometric type " << cm.getRepr() << ", field is defined on profile \"" << _profile << "\" and size of profile is ";
849           oss << _nval;
850           oss << pfl->getNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !";
851           throw INTERP_KERNEL::Exception(oss.str());
852         }
853       int offset2=codeOfMesh[3*found+2];
854       for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++)
855         {
856           if(*pflId<codeOfMesh[3*found+1])
857             *work++=offset2+*pflId;
858         }
859     }
860   return _nval;
861 }
862
863 int MEDFileFieldPerMeshPerTypePerDisc::fillTupleIds(int *ptToFill) const
864 {
865   for(int i=_start;i<_end;i++)
866     *ptToFill++=i;
867   return _end-_start;
868 }
869
870 int MEDFileFieldPerMeshPerTypePerDisc::ConvertType(TypeOfField type, int locId)
871 {
872   switch(type)
873   {
874     case ON_CELLS:
875       return -2;
876     case ON_GAUSS_NE:
877       return -1;
878     case ON_GAUSS_PT:
879       return locId;
880     default:
881       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::ConvertType : not managed type of field !");
882   }
883 }
884
885 std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entries)
886 {
887   int id=0;
888   std::map<std::pair<std::string,TypeOfField>,int> m;
889   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > ret;
890   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
891     if(m.find(std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType()))==m.end())
892       m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]=id++;
893   ret.resize(id);
894   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entries.begin();it!=entries.end();it++)
895     ret[m[std::pair<std::string,TypeOfField>((*it)->getLocalization(),(*it)->getType())]].push_back(*it);
896   return ret;
897 }
898
899 /*!
900  * - \c this->_loc_id mutable attribute is used for elt id in mesh offsets.
901  * 
902  * \param [in] offset the offset id used to take into account that \a result is not compulsary empty in input
903  * \param [in] entriesOnSameDisc some entries **on same localization** if not the result can be invalid. The _start and _end on them are relative to \a arr parameter.
904  * \param [in] explicitIdsInMesh ids in mesh of the considered chunk.
905  * \param [in] newCode one of the input parameter to explicit the new geo type dispatch (in classical format same than those asked by MEDFileFields::renumberEntitiesLyingOnMesh)
906  * \param [in,out] glob if necessary by the method, new profiles can be added to it
907  * \param [in,out] arr after the call of this method \a arr is renumbered to be compliant with added entries to \a result.
908  * \param [out] result All new entries will be appended on it.
909  * \return false if the configuration of renumbering leads to an unnecessary resplit of input \a entriesOnSameDisc. If not true is returned (the most general case !)
910  */
911 bool MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(int offset, const std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
912                                                        const DataArrayInt *explicitIdsInMesh,
913                                                        const std::vector<int>& newCode,
914                                                        MEDFileFieldGlobsReal& glob, DataArrayDouble *arr,
915                                                        std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >& result)
916 {
917   if(entriesOnSameDisc.empty())
918     return false;
919   TypeOfField type=entriesOnSameDisc[0]->getType();
920   int szEntities=0,szTuples=0;
921   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++)
922     { szEntities+=(*it)->_nval; szTuples+=(*it)->_end-(*it)->_start; }
923   int nbi=szTuples/szEntities;
924   if(szTuples%szEntities!=0)
925     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks : internal error the splitting into same dicretization failed !");
926   MCAuto<DataArrayInt> renumTuples=DataArrayInt::New(); renumTuples->alloc(szTuples,1);
927   MCAuto<DataArrayInt> ranges=MEDCouplingUMesh::ComputeRangesFromTypeDistribution(newCode);
928   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk(entriesOnSameDisc.size());
929   std::vector< const DataArrayInt * > newGeoTypesPerChunk2(entriesOnSameDisc.size());
930   std::vector< MCAuto<DataArrayInt> > newGeoTypesPerChunk_bis(entriesOnSameDisc.size());
931   std::vector< const DataArrayInt * > newGeoTypesPerChunk3(entriesOnSameDisc.size());
932   MCAuto<DataArrayInt> newGeoTypesPerChunk4=DataArrayInt::New(); newGeoTypesPerChunk4->alloc(szEntities,nbi);
933   int id=0;
934   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesOnSameDisc.begin();it!=entriesOnSameDisc.end();it++,id++)
935     {
936       int startOfEltIdOfChunk=(*it)->_start;
937       MCAuto<DataArrayInt> newEltIds=explicitIdsInMesh->subArray(startOfEltIdOfChunk,startOfEltIdOfChunk+(*it)->_nval);
938       MCAuto<DataArrayInt> rangeIdsForChunk=newEltIds->findRangeIdForEachTuple(ranges);
939       MCAuto<DataArrayInt> idsInRrangeForChunk=newEltIds->findIdInRangeForEachTuple(ranges);
940       //
941       MCAuto<DataArrayInt> tmp=rangeIdsForChunk->duplicateEachTupleNTimes(nbi); rangeIdsForChunk->rearrange(nbi);
942       newGeoTypesPerChunk4->setPartOfValues1(tmp,(*it)->_tmp_work1-offset,(*it)->_tmp_work1+(*it)->_nval*nbi-offset,1,0,nbi,1);
943       //
944       newGeoTypesPerChunk[id]=rangeIdsForChunk; newGeoTypesPerChunk2[id]=rangeIdsForChunk;
945       newGeoTypesPerChunk_bis[id]=idsInRrangeForChunk; newGeoTypesPerChunk3[id]=idsInRrangeForChunk;
946     }
947   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather=DataArrayInt::Aggregate(newGeoTypesPerChunk2); newGeoTypesPerChunk.clear(); newGeoTypesPerChunk2.clear();
948   MCAuto<DataArrayInt> newGeoTypesEltIdsAllGather2=DataArrayInt::Aggregate(newGeoTypesPerChunk3); newGeoTypesPerChunk_bis.clear(); newGeoTypesPerChunk3.clear();
949   MCAuto<DataArrayInt> diffVals=newGeoTypesEltIdsAllGather->getDifferentValues();
950   MCAuto<DataArrayInt> renumEltIds=newGeoTypesEltIdsAllGather->buildPermArrPerLevel();
951   //
952   MCAuto<DataArrayInt> renumTupleIds=newGeoTypesPerChunk4->buildPermArrPerLevel();
953   //
954   MCAuto<DataArrayDouble> arrPart=arr->subArray(offset,offset+szTuples);
955   arrPart->renumberInPlace(renumTupleIds->begin());
956   arr->setPartOfValues1(arrPart,offset,offset+szTuples,1,0,arrPart->getNumberOfComponents(),1);
957   bool ret=false;
958   const int *idIt=diffVals->begin();
959   std::list<const MEDFileFieldPerMeshPerTypePerDisc *> li(entriesOnSameDisc.begin(),entriesOnSameDisc.end());
960   int offset2=0;
961   for(int i=0;i<diffVals->getNumberOfTuples();i++,idIt++)
962     {
963       MCAuto<DataArrayInt> ids=newGeoTypesEltIdsAllGather->findIdsEqual(*idIt);
964       MCAuto<DataArrayInt> subIds=newGeoTypesEltIdsAllGather2->selectByTupleId(ids->begin(),ids->end());
965       int nbEntityElts=subIds->getNumberOfTuples();
966       bool ret2;
967       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> eltToAdd=MEDFileFieldPerMeshPerTypePerDisc::
968           NewObjectOnSameDiscThanPool(type,(INTERP_KERNEL::NormalizedCellType)newCode[3*(*idIt)],subIds,!subIds->isIota(newCode[3*(*idIt)+1]),nbi,
969                                       offset+offset2,
970                                       li,glob,ret2);
971       ret=ret || ret2;
972       result.push_back(eltToAdd);
973       offset2+=nbEntityElts*nbi;
974     }
975   ret=ret || li.empty();
976   return ret;
977 }
978
979 /*!
980  * \param [in] typeF type of field of new chunk
981  * \param [in] geoType the geometric type of the chunk
982  * \param [in] idsOfMeshElt the entity ids of mesh (cells or nodes) of the new chunk.
983  * \param [in] isPfl specifies if a profile is requested regarding size of \a idsOfMeshElt and the number of such entities regarding underlying mesh.
984  * \param [in] nbi number of integration points
985  * \param [in] offset The offset in the **global array of data**.
986  * \param [in,out] entriesOnSameDisc the pool **on the same discretization** inside which it will be attempted to find an existing entry corresponding exactly
987  *                 to the new chunk to create.
988  * \param [in,out] glob the global shared info that will be requested for existing profiles or to append a new profile if needed.
989  * \param [out] notInExisting If false the return newly allocated entry is not coming from \a entriesOnSameDisc. If true the output comes from copy of \a entriesOnSameDisc
990  *              and corresponding entry erased from \a entriesOnSameDisc.
991  * \return a newly allocated chunk
992  */
993 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::NewObjectOnSameDiscThanPool(TypeOfField typeF, INTERP_KERNEL::NormalizedCellType geoType, DataArrayInt *idsOfMeshElt,
994                                                                                                   bool isPfl, int nbi, int offset,
995                                                                                                   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>& entriesOnSameDisc,
996                                                                                                   MEDFileFieldGlobsReal& glob,
997                                                                                                   bool &notInExisting)
998 {
999   int nbMeshEntities=idsOfMeshElt->getNumberOfTuples();
1000   std::list< const MEDFileFieldPerMeshPerTypePerDisc *>::iterator it=entriesOnSameDisc.begin();
1001   for(;it!=entriesOnSameDisc.end();it++)
1002     {
1003       if(((INTERP_KERNEL::NormalizedCellType)(*it)->_loc_id)==geoType && (*it)->_nval==nbMeshEntities)
1004         {
1005           if(!isPfl)
1006             {
1007               if((*it)->_profile.empty())
1008                 break;
1009               else
1010                 if(!(*it)->_profile.empty())
1011                   {
1012                     const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str());
1013                     if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt))
1014                       break;
1015                   }
1016             }
1017         }
1018     }
1019   if(it==entriesOnSameDisc.end())
1020     {
1021       notInExisting=true;
1022       MEDFileFieldPerMeshPerTypePerDisc *ret=new MEDFileFieldPerMeshPerTypePerDisc;
1023       ret->_type=typeF;
1024       ret->_loc_id=(int)geoType;
1025       ret->_nval=nbMeshEntities;
1026       ret->_start=offset;
1027       ret->_end=ret->_start+ret->_nval*nbi;
1028       if(isPfl)
1029         {
1030           idsOfMeshElt->setName(glob.createNewNameOfPfl().c_str());
1031           glob.appendProfile(idsOfMeshElt);
1032           ret->_profile=idsOfMeshElt->getName();
1033         }
1034       //tony treatment of localization
1035       return ret;
1036     }
1037   else
1038     {
1039       notInExisting=false;
1040       MEDFileFieldPerMeshPerTypePerDisc *ret=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
1041       ret->_loc_id=(int)geoType;
1042       ret->setNewStart(offset);
1043       entriesOnSameDisc.erase(it);
1044       return ret;
1045     }
1046
1047 }
1048
1049 ////////////////////////////////////
1050
1051 MEDFileFieldPerMeshPerTypeCommon::~MEDFileFieldPerMeshPerTypeCommon()
1052  {
1053  }
1054
1055 void MEDFileFieldPerMeshPerTypeCommon::setFather(MEDFileFieldPerMesh *father)
1056 {
1057   _father=father;
1058 }
1059
1060 void MEDFileFieldPerMeshPerTypeCommon::deepCopyElements()
1061 {
1062   std::size_t i=0;
1063   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1064     {
1065       if((const MEDFileFieldPerMeshPerTypePerDisc *)*it)
1066         _field_pm_pt_pd[i]=(*it)->deepCopy(this);
1067     }
1068 }
1069
1070 std::size_t MEDFileFieldPerMeshPerTypeCommon::getHeapMemorySizeWithoutChildren() const
1071 {
1072   return _field_pm_pt_pd.capacity()*sizeof(MCAuto<MEDFileFieldPerMeshPerTypePerDisc>);
1073 }
1074
1075 std::vector<const BigMemoryObject *> MEDFileFieldPerMeshPerTypeCommon::getDirectChildrenWithNull() const
1076 {
1077   std::vector<const BigMemoryObject *> ret;
1078   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1079     ret.push_back((const MEDFileFieldPerMeshPerTypePerDisc *)*it);
1080   return ret;
1081 }
1082
1083 void MEDFileFieldPerMeshPerTypeCommon::assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1084 {
1085   std::vector<int> pos=addNewEntryIfNecessary(field,offset,nbOfCells);
1086   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1087     _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1088 }
1089
1090 /*!
1091  * This method is the most general one. No optimization is done here.
1092  * \param [in] multiTypePfl is the end user profile specified in high level API
1093  * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type.
1094  * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl.
1095  *             \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points.
1096  * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh
1097  * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored.
1098  */
1099 void MEDFileFieldPerMeshPerTypeCommon::assignFieldProfile(bool isPflAlone, int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1100 {
1101   std::vector<int> pos=addNewEntryIfNecessary(field,idsInPfl);
1102   for(std::vector<int>::const_iterator it=pos.begin();it!=pos.end();it++)
1103     _field_pm_pt_pd[*it]->assignFieldProfile(isPflAlone,start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,arr,mesh,glob,nasc);
1104 }
1105
1106 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1107 {
1108   _field_pm_pt_pd.resize(1);
1109   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1110   _field_pm_pt_pd[0]->assignNodeFieldNoProfile(start,field,arr,glob);
1111 }
1112
1113 void MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1114 {
1115   MCAuto<DataArrayInt> pfl2=pfl->deepCopy();
1116   if(!arr || !arr->isAllocated())
1117     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::assignNodeFieldProfile : input array is null, or not allocated !");
1118   _field_pm_pt_pd.resize(1);
1119   _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3);
1120   _field_pm_pt_pd[0]->assignFieldProfile(true,start,pfl,pfl2,pfl2,-1,field,arr,0,glob,nasc);//mesh is not requested so 0 is send.
1121 }
1122
1123 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1124 {
1125   TypeOfField type=field->getTypeOfField();
1126   if(type!=ON_GAUSS_PT)
1127     {
1128       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1129       int sz=_field_pm_pt_pd.size();
1130       bool found=false;
1131       for(int j=0;j<sz && !found;j++)
1132         {
1133           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1134             {
1135               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1136               found=true;
1137             }
1138         }
1139       if(!found)
1140         {
1141           _field_pm_pt_pd.resize(sz+1);
1142           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1143         }
1144       std::vector<int> ret(1,(int)sz);
1145       return ret;
1146     }
1147   else
1148     {
1149       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,offset,nbOfCells);
1150       int sz2=ret2.size();
1151       std::vector<int> ret3(sz2);
1152       int k=0;
1153       for(int i=0;i<sz2;i++)
1154         {
1155           int sz=_field_pm_pt_pd.size();
1156           int locIdToFind=ret2[i];
1157           bool found=false;
1158           for(int j=0;j<sz && !found;j++)
1159             {
1160               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1161                 {
1162                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1163                   ret3[k++]=j;
1164                   found=true;
1165                 }
1166             }
1167           if(!found)
1168             {
1169               _field_pm_pt_pd.resize(sz+1);
1170               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1171               ret3[k++]=sz;
1172             }
1173         }
1174       return ret3;
1175     }
1176 }
1177
1178 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, int offset, int nbOfCells)
1179 {
1180   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1181   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1182   if(!disc2)
1183     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1184   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1185   if(!da)
1186     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1187   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafeSlice(offset,offset+nbOfCells,1);
1188   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1189   if(retTmp->presenceOfValue(-1))
1190     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1191   std::vector<int> ret(retTmp->begin(),retTmp->end());
1192   return ret;
1193 }
1194
1195 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1196 {
1197   TypeOfField type=field->getTypeOfField();
1198   if(type!=ON_GAUSS_PT)
1199     {
1200       int locIdToFind=MEDFileFieldPerMeshPerTypePerDisc::ConvertType(type,0);
1201       int sz=_field_pm_pt_pd.size();
1202       bool found=false;
1203       for(int j=0;j<sz && !found;j++)
1204         {
1205           if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1206             {
1207               _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1208               found=true;
1209             }
1210         }
1211       if(!found)
1212         {
1213           _field_pm_pt_pd.resize(sz+1);
1214           _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1215         }
1216       std::vector<int> ret(1,0);
1217       return ret;
1218     }
1219   else
1220     {
1221       std::vector<int> ret2=addNewEntryIfNecessaryGauss(field,subCells);
1222       int sz2=ret2.size();
1223       std::vector<int> ret3(sz2);
1224       int k=0;
1225       for(int i=0;i<sz2;i++)
1226         {
1227           int sz=_field_pm_pt_pd.size();
1228           int locIdToFind=ret2[i];
1229           bool found=false;
1230           for(int j=0;j<sz && !found;j++)
1231             {
1232               if(_field_pm_pt_pd[j]->getLocId()==locIdToFind)
1233                 {
1234                   _field_pm_pt_pd[j]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1235                   ret3[k++]=j;
1236                   found=true;
1237                 }
1238             }
1239           if(!found)
1240             {
1241               _field_pm_pt_pd.resize(sz+1);
1242               _field_pm_pt_pd[sz]=MEDFileFieldPerMeshPerTypePerDisc::New(this,type,locIdToFind);
1243               ret3[k++]=sz;
1244             }
1245         }
1246       return ret3;
1247     }
1248 }
1249
1250 std::vector<int> MEDFileFieldPerMeshPerTypeCommon::addNewEntryIfNecessaryGauss(const MEDCouplingFieldDouble *field, const DataArrayInt *subCells)
1251 {
1252   const MEDCouplingFieldDiscretization *disc=field->getDiscretization();
1253   const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast<const MEDCouplingFieldDiscretizationGauss *>(disc);
1254   if(!disc2)
1255     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !");
1256   const DataArrayInt *da=disc2->getArrayOfDiscIds();
1257   if(!da)
1258     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !");
1259   MCAuto<DataArrayInt> da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples());
1260   MCAuto<DataArrayInt> retTmp=da2->getDifferentValues();
1261   if(retTmp->presenceOfValue(-1))
1262     throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !");
1263   std::vector<int> ret(retTmp->begin(),retTmp->end());
1264   return ret;
1265 }
1266
1267 const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerTypeCommon::getFather() const
1268 {
1269   return _father;
1270 }
1271
1272 bool MEDFileFieldPerMeshPerTypeCommon::isUniqueLevel(int& dim) const
1273 {
1274   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
1275   int curDim((int)cm.getDimension());
1276   if(dim!=std::numeric_limits<int>::max())
1277     {
1278       if(dim!=curDim)
1279         return false;
1280     }
1281   else
1282     dim=curDim;
1283   return true;
1284 }
1285
1286 void MEDFileFieldPerMeshPerTypeCommon::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1287 {
1288   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1289     {
1290       (*it)->fillTypesOfFieldAvailable(types);
1291     }
1292 }
1293
1294 void MEDFileFieldPerMeshPerTypeCommon::fillFieldSplitedByType(std::vector< std::pair<int,int> >& dads, std::vector<TypeOfField>& types, std::vector<std::string>& pfls, std::vector<std::string>& locs) const
1295 {
1296   int sz=_field_pm_pt_pd.size();
1297   dads.resize(sz); types.resize(sz); pfls.resize(sz); locs.resize(sz);
1298   for(int i=0;i<sz;i++)
1299     {
1300       _field_pm_pt_pd[i]->getCoarseData(types[i],dads[i],pfls[i],locs[i]);
1301     }
1302 }
1303
1304 int MEDFileFieldPerMeshPerTypeCommon::getIteration() const
1305 {
1306   return _father->getIteration();
1307 }
1308
1309 int MEDFileFieldPerMeshPerTypeCommon::getOrder() const
1310 {
1311   return _father->getOrder();
1312 }
1313
1314 double MEDFileFieldPerMeshPerTypeCommon::getTime() const
1315 {
1316   return _father->getTime();
1317 }
1318
1319 std::string MEDFileFieldPerMeshPerTypeCommon::getMeshName() const
1320 {
1321   return _father->getMeshName();
1322 }
1323
1324 void MEDFileFieldPerMeshPerTypeCommon::getSizes(int& globalSz, int& nbOfEntries) const
1325 {
1326   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1327     {
1328       globalSz+=(*it)->getNumberOfTuples();
1329     }
1330   nbOfEntries+=(int)_field_pm_pt_pd.size();
1331 }
1332
1333 int MEDFileFieldPerMeshPerTypeCommon::getNumberOfComponents() const
1334 {
1335   return _father->getNumberOfComponents();
1336 }
1337
1338 bool MEDFileFieldPerMeshPerTypeCommon::presenceOfMultiDiscPerGeoType() const
1339 {
1340   std::size_t nb(0);
1341   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1342     {
1343       const MEDFileFieldPerMeshPerTypePerDisc *fmtd(*it);
1344       if(fmtd)
1345         nb++;
1346     }
1347   return nb>1;
1348 }
1349
1350 DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray()
1351 {
1352   return _father->getOrCreateAndGetArray();
1353 }
1354
1355 const DataArray *MEDFileFieldPerMeshPerTypeCommon::getOrCreateAndGetArray() const
1356 {
1357   const MEDFileFieldPerMesh *fath=_father;
1358   return fath->getOrCreateAndGetArray();
1359 }
1360
1361 const std::vector<std::string>& MEDFileFieldPerMeshPerTypeCommon::getInfo() const
1362 {
1363   return _father->getInfo();
1364 }
1365
1366 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsed() const
1367 {
1368   std::vector<std::string> ret;
1369   std::set<std::string> ret2;
1370   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1371     {
1372       std::string tmp=(*it1)->getProfile();
1373       if(!tmp.empty())
1374         if(ret2.find(tmp)==ret2.end())
1375           {
1376             ret.push_back(tmp);
1377             ret2.insert(tmp);
1378           }
1379     }
1380   return ret;
1381 }
1382
1383 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsed() const
1384 {
1385   std::vector<std::string> ret;
1386   std::set<std::string> ret2;
1387   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1388     {
1389       std::string tmp=(*it1)->getLocalization();
1390       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1391         if(ret2.find(tmp)==ret2.end())
1392           {
1393             ret.push_back(tmp);
1394             ret2.insert(tmp);
1395           }
1396     }
1397   return ret;
1398 }
1399
1400 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getPflsReallyUsedMulti() const
1401 {
1402   std::vector<std::string> ret;
1403   std::set<std::string> ret2;
1404   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1405     {
1406       std::string tmp=(*it1)->getProfile();
1407       if(!tmp.empty())
1408         ret.push_back(tmp);
1409     }
1410   return ret;
1411 }
1412
1413 std::vector<std::string> MEDFileFieldPerMeshPerTypeCommon::getLocsReallyUsedMulti() const
1414 {
1415   std::vector<std::string> ret;
1416   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1417     {
1418       std::string tmp=(*it1)->getLocalization();
1419       if(!tmp.empty() && tmp!=MED_GAUSS_ELNO)
1420         ret.push_back(tmp);
1421     }
1422   return ret;
1423 }
1424
1425 void MEDFileFieldPerMeshPerTypeCommon::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1426 {
1427   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1428     (*it1)->changePflsRefsNamesGen(mapOfModif);
1429 }
1430
1431 void MEDFileFieldPerMeshPerTypeCommon::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
1432 {
1433   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it1=_field_pm_pt_pd.begin();it1!=_field_pm_pt_pd.end();it1++)
1434     (*it1)->changeLocsRefsNamesGen(mapOfModif);
1435 }
1436
1437 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId)
1438 {
1439   if(_field_pm_pt_pd.empty())
1440     {
1441       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1442       throw INTERP_KERNEL::Exception(oss.str());
1443     }
1444   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1445     return _field_pm_pt_pd[locId];
1446   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1447   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1448   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1449   return static_cast<MEDFileFieldPerMeshPerTypePerDisc*>(0);
1450 }
1451
1452 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId(int locId) const
1453 {
1454   if(_field_pm_pt_pd.empty())
1455     {
1456       std::ostringstream oss; oss << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no localizations for geotype \"" << getGeoTypeRepr() << "\" !";
1457       throw INTERP_KERNEL::Exception(oss.str());
1458     }
1459   if(locId>=0 && locId<(int)_field_pm_pt_pd.size())
1460     return _field_pm_pt_pd[locId];
1461   std::ostringstream oss2; oss2 << "MEDFileFieldPerMeshPerTypeCommon::getLeafGivenLocId : no such locId available (" << locId;
1462   oss2 << ") for geometric type \"" << getGeoTypeRepr() << "\" It should be in [0," << _field_pm_pt_pd.size() << ") !";
1463   throw INTERP_KERNEL::Exception(oss2.str().c_str());
1464   return static_cast<const MEDFileFieldPerMeshPerTypePerDisc*>(0);
1465 }
1466
1467 void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
1468 {
1469   int i=0;
1470   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1471     {
1472       (*it)->fillValues(i,startEntryId,entries);
1473     }
1474 }
1475
1476 void MEDFileFieldPerMeshPerTypeCommon::setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
1477 {
1478   _field_pm_pt_pd=leaves;
1479   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1480     (*it)->setFather(this);
1481 }
1482
1483 /*!
1484  *  \param [in,out] globalNum a global numbering counter for the renumbering. 
1485  *  \param [out] its - list of pair (start,stop) kept
1486  *  \return bool - false if the type of field \a tof is not contained in \a this.
1487  */
1488 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
1489 {
1490   bool ret(false);
1491   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd;
1492   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1493     if((*it)->getType()==tof)
1494       {
1495         newPmPtPd.push_back(*it);
1496         std::pair<int,int> bgEnd; bgEnd.first=(*it)->getStart(); bgEnd.second=(*it)->getEnd();
1497         (*it)->setNewStart(globalNum);
1498         globalNum=(*it)->getEnd();
1499         its.push_back(bgEnd);
1500         ret=true;
1501       }
1502   if(ret)
1503     _field_pm_pt_pd=newPmPtPd;
1504   return ret;
1505 }
1506
1507 /*!
1508  *  \param [in,out] globalNum a global numbering counter for the renumbering.
1509  *  \param [out] its - list of pair (start,stop) kept
1510  *  \return bool - false if the type of field \a tof is not contained in \a this.
1511  */
1512 bool MEDFileFieldPerMeshPerTypeCommon::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
1513 {
1514   if(_field_pm_pt_pd.size()<=idOfDisc)
1515     return false;
1516   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt(_field_pm_pt_pd[idOfDisc]);
1517   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > newPmPtPd(1,elt);
1518   std::pair<int,int> bgEnd; bgEnd.first=_field_pm_pt_pd[idOfDisc]->getStart(); bgEnd.second=_field_pm_pt_pd[idOfDisc]->getEnd();
1519   elt->setNewStart(globalNum);
1520   globalNum=elt->getEnd();
1521   its.push_back(bgEnd);
1522   _field_pm_pt_pd=newPmPtPd;
1523   return true;
1524 }
1525
1526 void MEDFileFieldPerMeshPerTypeCommon::loadOnlyStructureOfDataRecursively(med_idt fid, int &start, const MEDFileFieldNameScope& nasc)
1527 {
1528   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1529     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1530 }
1531
1532 void MEDFileFieldPerMeshPerTypeCommon::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1533 {
1534   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1535     (*it)->loadBigArray(fid,nasc);
1536 }
1537
1538 void MEDFileFieldPerMeshPerTypeCommon::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1539 {
1540   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1541     {
1542       (*it)->copyOptionsFrom(*this);
1543       (*it)->writeLL(fid,nasc);
1544     }
1545 }
1546
1547 med_entity_type MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType)
1548 {
1549   switch(ikType)
1550   {
1551     case ON_CELLS:
1552       medfGeoType=typmai3[(int)ikGeoType];
1553       return MED_CELL;
1554     case ON_NODES:
1555       medfGeoType=MED_NONE;
1556       return MED_NODE;
1557     case ON_GAUSS_NE:
1558       medfGeoType=typmai3[(int)ikGeoType];
1559       return MED_NODE_ELEMENT;
1560     case ON_GAUSS_PT:
1561       medfGeoType=typmai3[(int)ikGeoType];
1562       return MED_CELL;
1563     default:
1564       throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType : unexpected entity type ! internal error");
1565   }
1566   return MED_UNDEF_ENTITY_TYPE;
1567 }
1568
1569 //////////////////////////////////////////////////
1570
1571 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd)
1572 {
1573   return new MEDFileFieldPerMeshPerType(fid,fath,type,geoType,nasc,pd);
1574 }
1575
1576 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType)
1577 {
1578   return new MEDFileFieldPerMeshPerType(fath,geoType);
1579 }
1580
1581 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerType::deepCopy(MEDFileFieldPerMesh *father) const
1582 {
1583   MCAuto<MEDFileFieldPerMeshPerType> ret=new MEDFileFieldPerMeshPerType(*this);
1584   ret->setFather(father);
1585   ret->deepCopyElements();
1586   return ret.retn();
1587 }
1588
1589 void MEDFileFieldPerMeshPerType::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair<int,int> >& dads, std::vector<const DataArrayInt *>& pfls, std::vector<int>& locs, std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes) const
1590 {
1591   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1592     {
1593       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1594       if(meshDim!=(int)cm.getDimension())
1595         return ;
1596     }
1597   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
1598     (*it)->getFieldAtLevel(type,glob,dads,pfls,locs,geoTypes);
1599 }
1600
1601 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerType::getGeoType() const
1602 {
1603   return _geo_type;
1604 }
1605
1606 void MEDFileFieldPerMeshPerType::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1607 {
1608   ent=MEDFileFieldPerMeshPerTypeCommon::ConvertIntoMEDFileType(mct,_geo_type,gt);
1609 }
1610
1611 void MEDFileFieldPerMeshPerType::getDimension(int& dim) const
1612 {
1613   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1614   int curDim((int)cm.getDimension());
1615   dim=std::max(dim,curDim);
1616 }
1617
1618 void MEDFileFieldPerMeshPerType::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1619 {
1620   const char startLine[]="  ## ";
1621   std::string startLine2(bkOffset,' ');
1622   std::string startLine3(startLine2);
1623   startLine3+=startLine;
1624   if(_geo_type!=INTERP_KERNEL::NORM_ERROR)
1625     {
1626       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1627       oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry types " << cm.getRepr() << "." << std::endl;
1628     }
1629   else
1630     oss << startLine3 << "Entry geometry type #" << id << " is lying on NODES." << std::endl;
1631   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1632   int i=0;
1633   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1634     {
1635       const MEDFileFieldPerMeshPerTypePerDisc *cur=(*it);
1636       if(cur)
1637         cur->simpleRepr(bkOffset,oss,i);
1638       else
1639         {
1640           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1641         }
1642     }
1643 }
1644
1645 std::string MEDFileFieldPerMeshPerType::getGeoTypeRepr() const
1646 {
1647   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type));
1648   return std::string(cm.getRepr());
1649 }
1650
1651 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *father, INTERP_KERNEL::NormalizedCellType gt):MEDFileFieldPerMeshPerTypeCommon(father),_geo_type(gt)
1652 {
1653 }
1654
1655 MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, const MEDFileFieldNameScope& nasc, const PartDefinition *pd):MEDFileFieldPerMeshPerTypeCommon(fath),_geo_type(geoType)
1656 {
1657   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1658   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1659   med_geometry_type mgeoti;
1660   med_entity_type menti(ConvertIntoMEDFileType(type,geoType,mgeoti));
1661   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),menti,mgeoti,pflName,locName));
1662   _field_pm_pt_pd.resize(nbProfiles);
1663   for(int i=0;i<nbProfiles;i++)
1664     {
1665       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,type,i,pd);
1666     }
1667   if(type==ON_CELLS)
1668     {
1669       int nbProfiles2(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,mgeoti,pflName,locName));
1670       for(int i=0;i<nbProfiles2;i++)
1671         _field_pm_pt_pd.push_back(MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,ON_GAUSS_NE,i,pd));
1672     }
1673 }
1674
1675 MCAuto<MEDFileFieldPerMeshPerType> MEDFileFieldPerMeshPerType::Aggregate(int &start, const std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >& pms, const std::vector< std::vector< std::pair<int,int> > >& dts, INTERP_KERNEL::NormalizedCellType gt, MEDFileFieldPerMesh *father, std::vector<std::pair< int, std::pair<int,int> > >& extractInfo)
1676 {
1677   MCAuto<MEDFileFieldPerMeshPerType> ret(MEDFileFieldPerMeshPerType::New(father,gt));
1678   std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > > m;
1679   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerType *> >::const_iterator it=pms.begin();it!=pms.end();it++)
1680     {
1681       for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it2=(*it).second->_field_pm_pt_pd.begin();it2!=(*it).second->_field_pm_pt_pd.end();it2++)
1682         m[(*it2)->getType()].push_back(std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * >((*it).first,*it2));
1683     }
1684   for(std::map<TypeOfField, std::vector< std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc * > > >::const_iterator it=m.begin();it!=m.end();it++)
1685     {
1686       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> agg(MEDFileFieldPerMeshPerTypePerDisc::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
1687       ret->_field_pm_pt_pd.push_back(agg);
1688     }
1689   return ret;
1690 }
1691
1692 //////////////////////////////////////////////////
1693
1694 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc)
1695 {
1696   if(!entities)
1697     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : null pointer !");
1698   const MEDFileAllStaticEntitiesPlusDyn *entities2(dynamic_cast<const MEDFileAllStaticEntitiesPlusDyn *>(entities));
1699   if(!entities2)
1700     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeDyn::NewOnRead : invalid type of entities !");
1701   const MEDFileStructureElement *se(entities2->getWithGT(idGT));
1702   return new MEDFileFieldPerMeshPerTypeDyn(fid,fath,se,nasc);
1703 }
1704
1705 MEDFileFieldPerMeshPerTypeDyn::MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc):MEDFileFieldPerMeshPerTypeCommon(fath)
1706 {
1707   _se.takeRef(se);
1708   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1709   INTERP_KERNEL::AutoPtr<char> locName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1710   int nbProfiles(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,_se->getDynGT(),pflName,locName));
1711   _field_pm_pt_pd.resize(nbProfiles);
1712   for(int i=0;i<nbProfiles;i++)
1713     {
1714       _field_pm_pt_pd[i]=MEDFileFieldPerMeshPerTypePerDisc::NewOnRead(this,_se->getEntity(),i,NULL);
1715     }
1716 }
1717
1718 int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const
1719 {
1720   return _se->getDynGT();
1721 }
1722
1723 std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const
1724 {
1725   return _se->getName();
1726 }
1727
1728 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1729 {
1730   throw INTERP_KERNEL::Exception("not implemented yet !");
1731 }
1732
1733 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1734 {
1735   gt=getDynGT();
1736   ent=MED_STRUCT_ELEMENT;
1737 }
1738
1739 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1740 {
1741   throw INTERP_KERNEL::Exception("not implemented yet !");
1742 }
1743
1744 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1745 {
1746   const char startLine[]="  ## ";
1747   std::string startLine2(bkOffset,' ');
1748   std::string startLine3(startLine2);
1749   startLine3+=startLine;
1750   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1751   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1752   int i=0;
1753   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1754     {
1755       if((*it).isNotNull())
1756         (*it)->simpleRepr(bkOffset,oss,i);
1757       else
1758         {
1759           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1760         }
1761     }
1762 }
1763
1764 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1765 {
1766   throw INTERP_KERNEL::Exception("not implemented yet !");
1767 }
1768
1769 MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1770 {
1771   MCAuto<MEDFileFieldPerMeshPerTypeDyn> ret(new MEDFileFieldPerMeshPerTypeDyn(*this));
1772   ret->setFather(father);
1773   ret->deepCopyElements();
1774   return ret.retn();
1775 }
1776
1777 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
1778 {
1779   throw INTERP_KERNEL::Exception("not implemented yet !");
1780 }
1781
1782 //////////////////////////////////////////////////
1783
1784 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1785 {
1786   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1787 }
1788
1789 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1790 {
1791   return new MEDFileFieldPerMesh(fath,mesh);
1792 }
1793
1794 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1795 {
1796   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1797 }
1798
1799 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1800 {
1801   std::vector<const BigMemoryObject *> ret;
1802   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1803     ret.push_back(*it);
1804   return ret;
1805 }
1806
1807 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1808 {
1809   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1810   ret->_father=father;
1811   std::size_t i=0;
1812   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1813     {
1814       if((*it).isNotNull())
1815         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1816     }
1817   return ret.retn();
1818 }
1819
1820 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1821 {
1822   std::string startLine(bkOffset,' ');
1823   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1824   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1825   int i=0;
1826   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1827     {
1828       if((*it).isNotNull())
1829         (*it)->simpleRepr(bkOffset,oss,i);
1830       else
1831         {
1832           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1833         }
1834     }
1835 }
1836
1837 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1838 {
1839   _mesh_name=mesh->getName();
1840   mesh->getTime(_mesh_iteration,_mesh_order);
1841 }
1842
1843 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1844 {
1845   int nbOfTypes=code.size()/3;
1846   int offset=0;
1847   for(int i=0;i<nbOfTypes;i++)
1848     {
1849       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1850       int nbOfCells=code[3*i+1];
1851       int pos=addNewEntryIfNecessary(type);
1852       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1853       offset+=nbOfCells;
1854     }
1855 }
1856
1857 /*!
1858  * This method is the most general one. No optimization is done here.
1859  * \param [in] multiTypePfl is the end user profile specified in high level API
1860  * \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].
1861  * \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.
1862  * \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.
1863  * \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.
1864  * \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.
1865  */
1866 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)
1867 {
1868   int nbOfTypes(code.size()/3);
1869   for(int i=0;i<nbOfTypes;i++)
1870     {
1871       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1872       int pos=addNewEntryIfNecessary(type);
1873       DataArrayInt *pfl=0;
1874       if(code[3*i+2]!=-1)
1875         pfl=idsPerType[code[3*i+2]];
1876       int nbOfTupes2=code2.size()/3;
1877       int found=0;
1878       for(;found<nbOfTupes2;found++)
1879         if(code[3*i]==code2[3*found])
1880           break;
1881       if(found==nbOfTupes2)
1882         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1883       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1884     }
1885 }
1886
1887 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1888 {
1889   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1890   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1891 }
1892
1893 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1894 {
1895   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1896   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1897 }
1898
1899 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1900 {
1901   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1902     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1903 }
1904
1905 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1906 {
1907   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1908     (*it)->loadBigArraysRecursively(fid,nasc);
1909 }
1910
1911 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1912 {
1913   int nbOfTypes=_field_pm_pt.size();
1914   for(int i=0;i<nbOfTypes;i++)
1915     {
1916       _field_pm_pt[i]->copyOptionsFrom(*this);
1917       _field_pm_pt[i]->writeLL(fid,nasc);
1918     }
1919 }
1920
1921 void MEDFileFieldPerMesh::getDimension(int& dim) const
1922 {
1923   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1924     (*it)->getDimension(dim);
1925 }
1926
1927 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
1928 {
1929   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1930     if(!(*it)->isUniqueLevel(dim))
1931       return false;
1932   return true;
1933 }
1934
1935 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1936 {
1937   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1938     (*it)->fillTypesOfFieldAvailable(types);
1939 }
1940
1941 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
1942 {
1943   int sz=_field_pm_pt.size();
1944   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1945   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1946   for(int i=0;i<sz;i++)
1947     {
1948       types[i]=_field_pm_pt[i]->getGeoType();
1949       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1950     }
1951   return ret;
1952 }
1953
1954 double MEDFileFieldPerMesh::getTime() const
1955 {
1956   int tmp1,tmp2;
1957   return _father->getTime(tmp1,tmp2);
1958 }
1959
1960 int MEDFileFieldPerMesh::getIteration() const
1961 {
1962   return _father->getIteration();
1963 }
1964
1965 int MEDFileFieldPerMesh::getOrder() const
1966 {
1967   return _father->getOrder();
1968 }
1969
1970 int MEDFileFieldPerMesh::getNumberOfComponents() const
1971 {
1972   return _father->getNumberOfComponents();
1973 }
1974
1975 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1976 {
1977   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1978     {
1979       if((*it).isNull())
1980         continue;
1981       if((*it)->presenceOfMultiDiscPerGeoType())
1982         return true;
1983     }
1984   return false;
1985 }
1986
1987 bool MEDFileFieldPerMesh::presenceOfStructureElements() const
1988 {
1989   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1990     if((*it).isNotNull())
1991       {
1992         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
1993         if(pt)
1994           return true;
1995       }
1996   return false;
1997 }
1998
1999 bool MEDFileFieldPerMesh::onlyStructureElements() const
2000 {
2001   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2002     if((*it).isNotNull())
2003       {
2004         const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2005         if(!pt)
2006           return false;
2007       }
2008   return true;
2009 }
2010
2011 void MEDFileFieldPerMesh::killStructureElements()
2012 {
2013   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2014   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2015     {
2016       if((*it).isNotNull())
2017         {
2018           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2019           if(!pt)
2020             res.push_back(*it);
2021         }
2022     }
2023   _field_pm_pt=res;
2024 }
2025
2026 void MEDFileFieldPerMesh::keepOnlyStructureElements()
2027 {
2028   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2029   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2030     {
2031       if((*it).isNotNull())
2032         {
2033           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2034           if(pt)
2035             res.push_back(*it);
2036         }
2037     }
2038   _field_pm_pt=res;
2039 }
2040
2041 void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName)
2042 {
2043   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res;
2044   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2045     {
2046       if((*it).isNotNull())
2047         {
2048           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2049           if(!pt)
2050             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !");
2051           if(pt->getModelName()==seName)
2052             res.push_back(*it);
2053         }
2054     }
2055   _field_pm_pt=res;
2056 }
2057
2058 void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
2059 {
2060   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2061     {
2062       if((*it).isNotNull())
2063         {
2064           const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast<const MEDFileFieldPerMeshPerTypeDyn *>((const MEDFileFieldPerMeshPerTypeCommon *)*it));
2065           if(pt)
2066             {
2067               ps.push_back(std::pair<std::string,std::string>(getMeshName(),pt->getModelName()));
2068             }
2069           else
2070             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !");
2071         }
2072     }
2073 }
2074
2075 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
2076 {
2077   if(!_father)
2078     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2079   return _father->getOrCreateAndGetArray();
2080 }
2081
2082 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
2083 {
2084   if(!_father)
2085     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
2086   return _father->getOrCreateAndGetArray();
2087 }
2088
2089 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
2090 {
2091   return _father->getInfo();
2092 }
2093
2094 /*!
2095  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2096  * 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.
2097  * It returns 2 output vectors :
2098  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2099  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2100  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2101  */
2102 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)
2103 {
2104   int notNullPflsSz=0;
2105   int nbOfArrs=geoTypes.size();
2106   for(int i=0;i<nbOfArrs;i++)
2107     if(pfls[i])
2108       notNullPflsSz++;
2109   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2110   int nbOfDiffGeoTypes=geoTypes3.size();
2111   code.resize(3*nbOfDiffGeoTypes);
2112   notNullPfls.resize(notNullPflsSz);
2113   notNullPflsSz=0;
2114   int j=0;
2115   for(int i=0;i<nbOfDiffGeoTypes;i++)
2116     {
2117       int startZone=j;
2118       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2119       std::vector<const DataArrayInt *> notNullTmp;
2120       if(pfls[j])
2121         notNullTmp.push_back(pfls[j]);
2122       j++;
2123       for(;j<nbOfArrs;j++)
2124         if(geoTypes[j]==refType)
2125           {
2126             if(pfls[j])
2127               notNullTmp.push_back(pfls[j]);
2128           }
2129         else
2130           break;
2131       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2132       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2133       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2134       code[3*i]=(int)refType;
2135       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2136       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2137       if(notNullTmp.empty())
2138         code[3*i+2]=-1;
2139       else
2140         {
2141           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2142           code[3*i+2]=notNullPflsSz++;
2143         }
2144     }
2145 }
2146
2147 /*!
2148  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2149  */
2150 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)
2151 {
2152   int sz=dads.size();
2153   int ret=0;
2154   for(int i=0;i<sz;i++)
2155     {
2156       if(locs[i]==-1)
2157         {
2158           if(type!=ON_GAUSS_NE)
2159             ret+=dads[i].second-dads[i].first;
2160           else
2161             {
2162               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2163               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2164             }
2165         }
2166       else
2167         {
2168           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2169           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2170         }
2171     }
2172   return ret;
2173 }
2174
2175 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2176 {
2177   std::vector<std::string> ret;
2178   std::set<std::string> ret2;
2179   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2180     {
2181       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2182       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2183         if(ret2.find(*it2)==ret2.end())
2184           {
2185             ret.push_back(*it2);
2186             ret2.insert(*it2);
2187           }
2188     }
2189   return ret;
2190 }
2191
2192 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2193 {
2194   std::vector<std::string> ret;
2195   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2196     {
2197       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2198       ret.insert(ret.end(),tmp.begin(),tmp.end());
2199     }
2200   return ret;
2201 }
2202
2203 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2204 {
2205   std::vector<std::string> ret;
2206   std::set<std::string> ret2;
2207   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2208     {
2209       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2210       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2211         if(ret2.find(*it2)==ret2.end())
2212           {
2213             ret.push_back(*it2);
2214             ret2.insert(*it2);
2215           }
2216     }
2217   return ret;
2218 }
2219
2220 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2221 {
2222   std::vector<std::string> ret;
2223   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2224     {
2225       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2226       ret.insert(ret.end(),tmp.begin(),tmp.end());
2227     }
2228   return ret;
2229 }
2230
2231 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2232 {
2233   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2234     {
2235       if((*it).first==_mesh_name)
2236         {
2237           _mesh_name=(*it).second;
2238           return true;
2239         }
2240     }
2241   return false;
2242 }
2243
2244 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2245                                                       MEDFileFieldGlobsReal& glob)
2246 {
2247   if(_mesh_name!=meshName)
2248     return false;
2249   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2250   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2251   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2252   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2253   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2254   getUndergroundDataArrayExt(entries);
2255   DataArray *arr0(getOrCreateAndGetArray());//tony
2256   if(!arr0)
2257     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2258   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2259   if(!arr0)
2260     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2261   int sz=0;
2262   if(!arr)
2263     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2264   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2265     {
2266       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2267         {
2268           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2269           sz+=(*it).second.second-(*it).second.first;
2270         }
2271       else
2272         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2273     }
2274   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2275   ////////////////////
2276   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2277   int *workI2=explicitIdsOldInMesh->getPointer();
2278   int sz1=0,sz2=0,sid=1;
2279   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2280   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2281   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2282     {
2283       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2284       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2285       int *workI=explicitIdsOldInArr->getPointer();
2286       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2287         {
2288           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2289           (*itL2)->setLocId(sz2);
2290           (*itL2)->_tmp_work1=(*itL2)->getStart();
2291           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2292         }
2293       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2294     }
2295   explicitIdsOldInMesh->reAlloc(sz2);
2296   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2297   ////////////////////
2298   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2299   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2300   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2301   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2302     {
2303       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2304       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2305       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2306     }
2307   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2308   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2309   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2310     {
2311       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2312       int newStart=elt->getLocId();
2313       elt->setLocId((*it)->getGeoType());
2314       elt->setNewStart(newStart);
2315       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2316       entriesKeptNew.push_back(elt);
2317       entriesKeptNew2.push_back(elt);
2318     }
2319   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2320   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2321   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2322   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2323   bool ret=false;
2324   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2325     {
2326       sid=0;
2327       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2328         {
2329           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2330           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2331           }*/
2332       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2333                                                             glob,arr2,otherEntriesNew) || ret;
2334     }
2335   if(!ret)
2336     return false;
2337   // Assign new dispatching
2338   assignNewLeaves(otherEntriesNew);
2339   arr->deepCopyFrom(*arr2);
2340   return true;
2341 }
2342
2343 /*!
2344  * \param [in,out] globalNum a global numbering counter for the renumbering.
2345  * \param [out] its - list of pair (start,stop) kept
2346  */
2347 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2348 {
2349   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2350   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2351     {
2352       std::vector< std::pair<int,int> > its2;
2353       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2354         {
2355           ret.push_back(*it);
2356           its.insert(its.end(),its2.begin(),its2.end());
2357         }
2358     }
2359   _field_pm_pt=ret;
2360 }
2361
2362 /*!
2363  * \param [in,out] globalNum a global numbering counter for the renumbering.
2364  * \param [out] its - list of pair (start,stop) kept
2365  */
2366 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2367 {
2368   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2369   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2370     {
2371       std::vector< std::pair<int,int> > its2;
2372       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2373         {
2374           ret.push_back(*it);
2375           its.insert(its.end(),its2.begin(),its2.end());
2376         }
2377     }
2378   _field_pm_pt=ret;
2379 }
2380
2381 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2382 {
2383   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2384   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2385     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2386   //
2387   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2388   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2389   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2390   for(;it1!=types.end();it1++,it2++)
2391     {
2392       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2393       elt->setLeaves((*it1).second);
2394       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2395       *it2=elt2;
2396     }
2397   _field_pm_pt=fieldPmPt;
2398 }
2399
2400 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2401 {
2402   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2403     (*it)->changePflsRefsNamesGen(mapOfModif);
2404 }
2405
2406 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2407 {
2408   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2409     (*it)->changeLocsRefsNamesGen(mapOfModif);
2410 }
2411
2412 /*!
2413  * \param [in] mesh is the whole mesh
2414  */
2415 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2416 {
2417   if(_field_pm_pt.empty())
2418     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2419   //
2420   std::vector< std::pair<int,int> > dads;
2421   std::vector<const DataArrayInt *> pfls;
2422   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2423   std::vector<int> locs,code;
2424   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2425   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2426     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2427   // Sort by types
2428   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2429   if(code.empty())
2430     {
2431       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2432       throw INTERP_KERNEL::Exception(oss.str());
2433     }
2434   //
2435   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2436   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2437   if(type!=ON_NODES)
2438     {
2439       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2440       if(!arr)
2441         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2442       else
2443         {
2444           MCAuto<DataArrayInt> arr2(arr);
2445           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2446         }
2447     }
2448   else
2449     {
2450       if(code.size()!=3)
2451         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2452       int nb=code[1];
2453       if(code[2]==-1)
2454         {
2455           if(nb!=mesh->getNumberOfNodes())
2456             {
2457               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2458               oss << " nodes in mesh !";
2459               throw INTERP_KERNEL::Exception(oss.str());
2460             }
2461           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2462         }
2463       else
2464         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2465     }
2466 }
2467
2468 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2469 {
2470   if(_field_pm_pt.empty())
2471     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2472   //
2473   std::vector<std::pair<int,int> > dads;
2474   std::vector<const DataArrayInt *> pfls;
2475   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2476   std::vector<int> locs,code;
2477   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2478   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2479     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2480   // Sort by types
2481   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2482   if(code.empty())
2483     {
2484       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2485       throw INTERP_KERNEL::Exception(oss.str());
2486     }
2487   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2488   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2489   if(type!=ON_NODES)
2490     {
2491       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2492       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2493     }
2494   else
2495     {
2496       if(code.size()!=3)
2497         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2498       int nb=code[1];
2499       if(code[2]==-1)
2500         {
2501           if(nb!=mesh->getNumberOfNodes())
2502             {
2503               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2504               oss << " nodes in mesh !";
2505               throw INTERP_KERNEL::Exception(oss.str());
2506             }
2507         }
2508       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2509     }
2510   //
2511   return 0;
2512 }
2513
2514 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2515 {
2516   int globalSz=0;
2517   int nbOfEntries=0;
2518   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2519     {
2520       (*it)->getSizes(globalSz,nbOfEntries);
2521     }
2522   entries.resize(nbOfEntries);
2523   nbOfEntries=0;
2524   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2525     {
2526       (*it)->fillValues(nbOfEntries,entries);
2527     }
2528 }
2529
2530 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2531 {
2532   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2533     {
2534       if((*it)->getGeoType()==typ)
2535         return (*it)->getLeafGivenLocId(locId);
2536     }
2537   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2538   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2539   oss << "Possiblities are : ";
2540   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2541     {
2542       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2543       oss << "\"" << cm2.getRepr() << "\", ";
2544     }
2545   throw INTERP_KERNEL::Exception(oss.str());
2546 }
2547
2548 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2549 {
2550   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2551     {
2552       if((*it)->getGeoType()==typ)
2553         return (*it)->getLeafGivenLocId(locId);
2554     }
2555   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2556   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2557   oss << "Possiblities are : ";
2558   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2559     {
2560       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2561       oss << "\"" << cm2.getRepr() << "\", ";
2562     }
2563   throw INTERP_KERNEL::Exception(oss.str());
2564 }
2565
2566 /*!
2567  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2568  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2569  * \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.
2570  * \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.
2571  */
2572 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)
2573 {
2574   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2575   if(pms.empty())
2576     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2577   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2578     {
2579       if(!(*it).second)
2580         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2581       if(!(*it).second->getProfile().empty())
2582         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2583       if(!(*it).second->getLocalization().empty())
2584         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2585     }
2586   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2587   std::size_t i(0);
2588   std::vector< std::pair<int,int> > filteredDTS;
2589   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2590     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2591       if((*it2).first==gt)
2592         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2593   if(pms.size()!=filteredDTS.size())
2594     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2595   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2596   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2597   int zeStart(start),nval(0);
2598   for(;it1!=pms.end();it1++,it2++)
2599     {
2600       if((*it1).first!=(*it2).first)
2601         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2602       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2603       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2604       start+=e1-s1;
2605       nval+=((*it1).second)->getNumberOfVals();
2606     }
2607   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2608   return ret;
2609 }
2610
2611 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)
2612 {
2613   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2614   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2615   std::size_t i(0);
2616   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2617     {
2618       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2619       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2620         {
2621           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2622           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2623           if(!elt)
2624             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2625           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2626         }
2627     }
2628   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2629     {
2630       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2631       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2632       ret->_field_pm_pt.push_back(agg2);
2633     }
2634   return ret;
2635 }
2636
2637 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2638 {
2639   int i=0;
2640   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2641   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2642   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2643     {
2644       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2645       if(type==curType)
2646         return i;
2647       else
2648         {
2649           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2650           if(pos>pos2)
2651             it2=it+1;
2652         }
2653     }
2654   int ret=std::distance(_field_pm_pt.begin(),it2);
2655   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2656   return ret;
2657 }
2658
2659 /*!
2660  * 'dads' and 'locs' input parameters have the same number of elements
2661  * \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
2662  */
2663 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2664                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2665                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2666 {
2667   isPfl=false;
2668   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2669   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2670   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2671   const std::vector<std::string>& infos=getInfo();
2672   da->setInfoOnComponents(infos);
2673   da->setName("");
2674   if(type==ON_GAUSS_PT)
2675     {
2676       int offset=0;
2677       int nbOfArrs=dads.size();
2678       for(int i=0;i<nbOfArrs;i++)
2679         {
2680           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2681           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2682           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2683           MCAuto<DataArrayInt> di=DataArrayInt::New();
2684           di->alloc(nbOfElems,1);
2685           di->iota(offset);
2686           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2687           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2688           offset+=nbOfElems;
2689         }
2690     }
2691   arrOut=da;
2692   return ret.retn();
2693 }
2694
2695 /*!
2696  * 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.
2697  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2698  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2699  * The order of cells in the returned field is those imposed by the profile.
2700  * \param [in] mesh is the global mesh.
2701  */
2702 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2703                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2704                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2705                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2706 {
2707   if(da->isIota(mesh->getNumberOfCells()))
2708     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2709   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2710   m2->setName(mesh->getName().c_str());
2711   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2712   isPfl=true;
2713   return ret.retn();
2714 }
2715
2716 /*!
2717  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2718  */
2719 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2720                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2721                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2722 {
2723   if(da->isIota(mesh->getNumberOfNodes()))
2724     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2725   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2726   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2727   if(meshu)
2728     {
2729       if(meshu->getNodalConnectivity()==0)
2730         {
2731           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2732           int nb=da->getNbOfElems();
2733           const int *ptr=da->getConstPointer();
2734           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2735           meshuc->allocateCells(nb);
2736           for(int i=0;i<nb;i++)
2737             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2738           meshuc->finishInsertingCells();
2739           ret->setMesh(meshuc);
2740           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2741           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2742           disc->checkCoherencyBetween(meshuc,arrOut);
2743           return ret.retn();
2744         }
2745     }
2746   //
2747   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2748   isPfl=true;
2749   DataArrayInt *arr2=0;
2750   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2751   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2752   MCAuto<DataArrayInt> arr3(arr2);
2753   int nnodes=mesh2->getNumberOfNodes();
2754   if(nnodes==(int)da->getNbOfElems())
2755     {
2756       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2757       arrOut->renumberInPlace(da3->getConstPointer());
2758       mesh2->setName(mesh->getName().c_str());
2759       ret->setMesh(mesh2);
2760       return ret.retn();
2761     }
2762   else
2763     {
2764       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 !!!";
2765       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2766       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2767       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2768       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2769       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2770       throw INTERP_KERNEL::Exception(oss.str());
2771     }
2772   return 0;
2773 }
2774
2775 /*!
2776  * This method is the most light method of field retrieving.
2777  */
2778 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2779 {
2780   if(!pflIn)
2781     {
2782       pflOut=DataArrayInt::New();
2783       pflOut->alloc(nbOfElems,1);
2784       pflOut->iota(0);
2785     }
2786   else
2787     {
2788       pflOut=const_cast<DataArrayInt*>(pflIn);
2789       pflOut->incrRef();
2790     }
2791   MCAuto<DataArrayInt> safePfl(pflOut);
2792   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2793   const std::vector<std::string>& infos=getInfo();
2794   int nbOfComp=infos.size();
2795   for(int i=0;i<nbOfComp;i++)
2796     da->setInfoOnComponent(i,infos[i].c_str());
2797   safePfl->incrRef();
2798   return da.retn();
2799 }
2800
2801
2802 /// @cond INTERNAL
2803
2804 class MFFPMIter
2805 {
2806 public:
2807   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2808   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2809   virtual ~MFFPMIter() { }
2810   virtual void begin() = 0;
2811   virtual bool finished() const = 0;
2812   virtual void next() = 0;
2813   virtual int current() const = 0;
2814 };
2815
2816 class MFFPMIterSimple : public MFFPMIter
2817 {
2818 public:
2819   MFFPMIterSimple():_pos(0) { }
2820   void begin() { _pos=0; }
2821   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2822   void next() { _pos++; }
2823   int current() const { return _pos; }
2824 private:
2825   int _pos;
2826 };
2827
2828 class MFFPMIter2 : public MFFPMIter
2829 {
2830 public:
2831   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2832   void begin() { _it=_ids.begin(); }
2833   bool finished() const { return _it==_ids.end(); }
2834   void next() { _it++; }
2835   int current() const { return *_it; }
2836 private:
2837   std::vector<int> _ids;
2838   std::vector<int>::const_iterator _it;
2839 };
2840
2841 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
2842 {
2843   if(!entities)
2844     return new MFFPMIterSimple;
2845   else
2846     {
2847       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2848       if(entities2)
2849         {
2850           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2851           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2852           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2853             {
2854               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2855                 tmp.push_back((*it).second);
2856             }
2857           return new MFFPMIter2(tmp);
2858         }
2859       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
2860     }
2861 }
2862
2863 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
2864 {
2865   if(!entities)
2866     return true;
2867   else
2868     {
2869       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2870       if(entities2)
2871         {
2872           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2873           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2874             if((*it).first==ON_NODES)
2875               return true;
2876           return false;
2877         }
2878       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
2879     }
2880 }
2881
2882 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2883 {
2884   std::size_t sz(cts.size());
2885   _ids.resize(sz);
2886   for(std::size_t i=0;i<sz;i++)
2887     {
2888       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2889       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2890         _ids[i]=(int)std::distance(typmai2,loc);
2891       else
2892         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2893     }
2894 }
2895
2896 /// @endcond
2897
2898 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),
2899     _father(fath)
2900 {
2901   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2902   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2903   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2904   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2905   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2906   for(iter0->begin();!iter0->finished();iter0->next())
2907     {
2908       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2909       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2910       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2911       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2912       if(nbProfile>0 || nbProfile2>0)
2913         {
2914           const PartDefinition *pd(0);
2915           if(mmu)
2916             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2917           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2918           if(nbProfile>0)
2919             _mesh_name=name0;
2920           else
2921             _mesh_name=name1;
2922         }
2923     }
2924   if(MFFPMIter::IsPresenceOfNode(entities))
2925     {
2926       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2927       if(nbProfile>0)
2928         {
2929           const PartDefinition *pd(0);
2930           if(mmu)
2931             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2932           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2933           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2934         }
2935     }
2936   if(!entities)
2937     return ;
2938   std::vector<int> dynGT(entities->getDynGTAvail());
2939   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
2940     {
2941       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
2942       if(nbPfl>0)
2943         {
2944           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
2945           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2946         }
2947     }
2948 }
2949
2950 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2951 {
2952   copyTinyInfoFrom(mesh);
2953 }
2954
2955 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2956 {
2957   if(id>=(int)_pfls.size())
2958     _pfls.resize(id+1);
2959   _pfls[id]=DataArrayInt::New();
2960   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2961   _pfls[id]->setName(pflName);
2962   _pfls[id]->alloc(lgth,1);
2963   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2964   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2965 }
2966
2967 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2968 {
2969   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2970   int sz;
2971   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2972   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2973   if(i>=(int)_pfls.size())
2974     _pfls.resize(i+1);
2975   _pfls[i]=DataArrayInt::New();
2976   _pfls[i]->alloc(sz,1);
2977   _pfls[i]->setName(pflCpp.c_str());
2978   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2979   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2980 }
2981
2982 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2983 {
2984   int nbOfPfls=_pfls.size();
2985   for(int i=0;i<nbOfPfls;i++)
2986     {
2987       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2988       cpy->applyLin(1,1,0);
2989       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2990       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2991       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2992     }
2993   //
2994   int nbOfLocs=_locs.size();
2995   for(int i=0;i<nbOfLocs;i++)
2996     _locs[i]->writeLL(fid);
2997 }
2998
2999 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
3000 {
3001   std::vector<std::string> pfls=getPfls();
3002   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
3003     {
3004       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
3005       if(it2==pfls.end())
3006         {
3007           _pfls.push_back(*it);
3008         }
3009       else
3010         {
3011           int id=std::distance(pfls.begin(),it2);
3012           if(!(*it)->isEqual(*_pfls[id]))
3013             {
3014               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3015               throw INTERP_KERNEL::Exception(oss.str());
3016             }
3017         }
3018     }
3019   std::vector<std::string> locs=getLocs();
3020   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
3021     {
3022       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
3023       if(it2==locs.end())
3024         {
3025           _locs.push_back(*it);
3026         }
3027       else
3028         {
3029           int id=std::distance(locs.begin(),it2);
3030           if(!(*it)->isEqual(*_locs[id],eps))
3031             {
3032               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
3033               throw INTERP_KERNEL::Exception(oss.str());
3034             }
3035         }
3036     }
3037 }
3038
3039 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
3040 {
3041   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
3042     getProfile((*it).c_str());
3043 }
3044
3045 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
3046 {
3047   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
3048     getLocalization((*it).c_str());
3049 }
3050
3051 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
3052 {
3053   std::vector<std::string> profiles=real.getPflsReallyUsed();
3054   int sz=profiles.size();
3055   _pfls.resize(sz);
3056   for(int i=0;i<sz;i++)
3057     loadProfileInFile(fid,i,profiles[i].c_str());
3058   //
3059   std::vector<std::string> locs=real.getLocsReallyUsed();
3060   sz=locs.size();
3061   _locs.resize(sz);
3062   for(int i=0;i<sz;i++)
3063     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
3064 }
3065
3066 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
3067 {
3068   int nProfil=MEDnProfile(fid);
3069   for(int i=0;i<nProfil;i++)
3070     loadProfileInFile(fid,i);
3071   int sz=MEDnLocalization(fid);
3072   _locs.resize(sz);
3073   for(int i=0;i<sz;i++)
3074     {
3075       _locs[i]=MEDFileFieldLoc::New(fid,i);
3076     }
3077 }
3078
3079 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
3080 {
3081   return new MEDFileFieldGlobs(fid);
3082 }
3083
3084 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
3085 {
3086   return new MEDFileFieldGlobs;
3087 }
3088
3089 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
3090 {
3091   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
3092 }
3093
3094 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
3095 {
3096   std::vector<const BigMemoryObject *> ret;
3097   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3098     ret.push_back((const DataArrayInt *)*it);
3099   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3100     ret.push_back((const MEDFileFieldLoc *)*it);
3101   return ret;
3102 }
3103
3104 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3105 {
3106   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3107   std::size_t i=0;
3108   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3109     {
3110       if((const DataArrayInt *)*it)
3111         ret->_pfls[i]=(*it)->deepCopy();
3112     }
3113   i=0;
3114   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3115     {
3116       if((const MEDFileFieldLoc*)*it)
3117         ret->_locs[i]=(*it)->deepCopy();
3118     }
3119   return ret.retn();
3120 }
3121
3122 /*!
3123  * \throw if a profile in \a pfls in not in \a this.
3124  * \throw if a localization in \a locs in not in \a this.
3125  * \sa MEDFileFieldGlobs::deepCpyPart
3126  */
3127 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3128 {
3129   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3130   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3131     {
3132       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3133       if(!pfl)
3134         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3135       pfl->incrRef();
3136       MCAuto<DataArrayInt> pfl2(pfl);
3137       ret->_pfls.push_back(pfl2);
3138     }
3139   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3140     {
3141       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3142       if(!loc)
3143         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3144       loc->incrRef();
3145       MCAuto<MEDFileFieldLoc> loc2(loc);
3146       ret->_locs.push_back(loc2);
3147     }
3148   ret->setFileName(getFileName());
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::shallowCpyPart
3156  */
3157 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(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::deepCpyPart : internal error ! pfl null !");
3165       ret->_pfls.push_back(pfl->deepCopy());
3166     }
3167   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3168     {
3169       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3170       if(!loc)
3171         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3172       ret->_locs.push_back(loc->deepCopy());
3173     }
3174   ret->setFileName(getFileName());
3175   return ret.retn();
3176 }
3177
3178 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3179 {
3180 }
3181
3182 MEDFileFieldGlobs::MEDFileFieldGlobs()
3183 {
3184 }
3185
3186 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3187 {
3188 }
3189
3190 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3191 {
3192   oss << "Profiles :\n";
3193   std::size_t n=_pfls.size();
3194   for(std::size_t i=0;i<n;i++)
3195     {
3196       oss << "  - #" << i << " ";
3197       const DataArrayInt *pfl=_pfls[i];
3198       if(pfl)
3199         oss << "\"" << pfl->getName() << "\"\n";
3200       else
3201         oss << "EMPTY !\n";
3202     }
3203   n=_locs.size();
3204   oss << "Localizations :\n";
3205   for(std::size_t i=0;i<n;i++)
3206     {
3207       oss << "  - #" << i << " ";
3208       const MEDFileFieldLoc *loc=_locs[i];
3209       if(loc)
3210         loc->simpleRepr(oss);
3211       else
3212         oss<< "EMPTY !\n";
3213     }
3214 }
3215
3216 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3217 {
3218   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3219     {
3220       DataArrayInt *elt(*it);
3221       if(elt)
3222         {
3223           std::string name(elt->getName());
3224           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3225             {
3226               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3227                 {
3228                   elt->setName((*it2).second.c_str());
3229                   return;
3230                 }
3231             }
3232         }
3233     }
3234 }
3235
3236 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3237 {
3238   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3239     {
3240       MEDFileFieldLoc *elt(*it);
3241       if(elt)
3242         {
3243           std::string name(elt->getName());
3244           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3245             {
3246               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3247                 {
3248                   elt->setName((*it2).second.c_str());
3249                   return;
3250                 }
3251             }
3252         }
3253     }
3254 }
3255
3256 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3257 {
3258   if(locId<0 || locId>=(int)_locs.size())
3259     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3260   return _locs[locId]->getNbOfGaussPtPerCell();
3261 }
3262
3263 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3264 {
3265   return getLocalizationFromId(getLocalizationId(locName));
3266 }
3267
3268 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3269 {
3270   if(locId<0 || locId>=(int)_locs.size())
3271     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3272   return *_locs[locId];
3273 }
3274
3275 /// @cond INTERNAL
3276 namespace MEDCouplingImpl
3277 {
3278   class LocFinder
3279   {
3280   public:
3281     LocFinder(const std::string& loc):_loc(loc) { }
3282     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3283   private:
3284     const std::string &_loc;
3285   };
3286
3287   class PflFinder
3288   {
3289   public:
3290     PflFinder(const std::string& pfl):_pfl(pfl) { }
3291     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3292   private:
3293     const std::string& _pfl;
3294   };
3295 }
3296 /// @endcond
3297
3298 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3299 {
3300   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3301   if(it==_locs.end())
3302     {
3303       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3304       for(it=_locs.begin();it!=_locs.end();it++)
3305         oss << "\"" << (*it)->getName() << "\", ";
3306       throw INTERP_KERNEL::Exception(oss.str());
3307     }
3308   return std::distance(_locs.begin(),it);
3309 }
3310
3311 /*!
3312  * The returned value is never null.
3313  */
3314 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3315 {
3316   std::string pflNameCpp(pflName);
3317   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3318   if(it==_pfls.end())
3319     {
3320       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3321       for(it=_pfls.begin();it!=_pfls.end();it++)
3322         oss << "\"" << (*it)->getName() << "\", ";
3323       throw INTERP_KERNEL::Exception(oss.str());
3324     }
3325   return *it;
3326 }
3327
3328 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3329 {
3330   if(pflId<0 || pflId>=(int)_pfls.size())
3331     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3332   return _pfls[pflId];
3333 }
3334
3335 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3336 {
3337   if(locId<0 || locId>=(int)_locs.size())
3338     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3339   return *_locs[locId];
3340 }
3341
3342 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3343 {
3344   return getLocalizationFromId(getLocalizationId(locName));
3345 }
3346
3347 /*!
3348  * The returned value is never null.
3349  */
3350 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3351 {
3352   std::string pflNameCpp(pflName);
3353   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3354   if(it==_pfls.end())
3355     {
3356       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3357       for(it=_pfls.begin();it!=_pfls.end();it++)
3358         oss << "\"" << (*it)->getName() << "\", ";
3359       throw INTERP_KERNEL::Exception(oss.str());
3360     }
3361   return *it;
3362 }
3363
3364 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3365 {
3366   if(pflId<0 || pflId>=(int)_pfls.size())
3367     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3368   return _pfls[pflId];
3369 }
3370
3371 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3372 {
3373   std::vector< MCAuto<DataArrayInt> > newPfls;
3374   int i=0;
3375   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3376     {
3377       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3378         newPfls.push_back(*it);
3379     }
3380   _pfls=newPfls;
3381 }
3382
3383 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3384 {
3385   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3386   int i=0;
3387   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3388     {
3389       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3390         newLocs.push_back(*it);
3391     }
3392   _locs=newLocs;
3393 }
3394
3395 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3396 {
3397   int sz=_pfls.size();
3398   std::vector<std::string> ret(sz);
3399   for(int i=0;i<sz;i++)
3400     ret[i]=_pfls[i]->getName();
3401   return ret;
3402 }
3403
3404 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3405 {
3406   int sz=_locs.size();
3407   std::vector<std::string> ret(sz);
3408   for(int i=0;i<sz;i++)
3409     ret[i]=_locs[i]->getName();
3410   return ret;
3411 }
3412
3413 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3414 {
3415   std::vector<std::string> v=getPfls();
3416   std::string s(pflName);
3417   return std::find(v.begin(),v.end(),s)!=v.end();
3418 }
3419
3420 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3421 {
3422   std::vector<std::string> v=getLocs();
3423   std::string s(locName);
3424   return std::find(v.begin(),v.end(),s)!=v.end();
3425 }
3426
3427 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3428 {
3429   std::map<int,std::vector<int> > m;
3430   int i=0;
3431   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3432     {
3433       const DataArrayInt *tmp=(*it);
3434       if(tmp)
3435         {
3436           m[tmp->getHashCode()].push_back(i);
3437         }
3438     }
3439   std::vector< std::vector<int> > ret;
3440   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3441     {
3442       if((*it2).second.size()>1)
3443         {
3444           std::vector<int> ret0;
3445           bool equalityOrNot=false;
3446           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3447             {
3448               std::vector<int>::const_iterator it4=it3; it4++;
3449               for(;it4!=(*it2).second.end();it4++)
3450                 {
3451                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3452                     {
3453                       if(!equalityOrNot)
3454                         ret0.push_back(*it3);
3455                       ret0.push_back(*it4);
3456                       equalityOrNot=true;
3457                     }
3458                 }
3459             }
3460           if(!ret0.empty())
3461             ret.push_back(ret0);
3462         }
3463     }
3464   return ret;
3465 }
3466
3467 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3468 {
3469   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3470 }
3471
3472 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3473 {
3474   std::string name(pfl->getName());
3475   if(name.empty())
3476     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3477   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3478     if(name==(*it)->getName())
3479       {
3480         if(!pfl->isEqual(*(*it)))
3481           {
3482             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3483             throw INTERP_KERNEL::Exception(oss.str());
3484           }
3485       }
3486   pfl->incrRef();
3487   _pfls.push_back(pfl);
3488 }
3489
3490 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)
3491 {
3492   std::string name(locName);
3493   if(name.empty())
3494     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3495   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3496   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3497     if((*it)->isName(locName))
3498       {
3499         if(!(*it)->isEqual(*obj,1e-12))
3500           {
3501             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3502             throw INTERP_KERNEL::Exception(oss.str());
3503           }
3504       }
3505   _locs.push_back(obj);
3506 }
3507
3508 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3509 {
3510   std::vector<std::string> names=getPfls();
3511   return CreateNewNameNotIn("NewPfl_",names);
3512 }
3513
3514 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3515 {
3516   std::vector<std::string> names=getLocs();
3517   return CreateNewNameNotIn("NewLoc_",names);
3518 }
3519
3520 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3521 {
3522   for(std::size_t sz=0;sz<100000;sz++)
3523     {
3524       std::ostringstream tryName;
3525       tryName << prefix << sz;
3526       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3527         return tryName.str();
3528     }
3529   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3530 }
3531
3532 /*!
3533  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3534  *  \param [in] fname - the file name.
3535  */
3536 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3537 {
3538 }
3539
3540 /*!
3541  * Creates an empty MEDFileFieldGlobsReal.
3542  */
3543 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3544 {
3545 }
3546
3547 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3548 {
3549   return 0;
3550 }
3551
3552 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3553 {
3554   std::vector<const BigMemoryObject *> ret;
3555   ret.push_back((const MEDFileFieldGlobs *)_globals);
3556   return ret;
3557 }
3558
3559 /*!
3560  * Returns a string describing profiles and Gauss points held in \a this.
3561  *  \return std::string - the description string.
3562  */
3563 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3564 {
3565   const MEDFileFieldGlobs *glob=_globals;
3566   std::ostringstream oss2; oss2 << glob;
3567   std::string stars(oss2.str().length(),'*');
3568   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3569   if(glob)
3570     glob->simpleRepr(oss);
3571   else
3572     oss << "NO GLOBAL INFORMATION !\n";
3573 }
3574
3575 void MEDFileFieldGlobsReal::resetContent()
3576 {
3577   _globals=MEDFileFieldGlobs::New();
3578 }
3579
3580 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3581 {
3582 }
3583
3584 /*!
3585  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3586  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3587  */
3588 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3589 {
3590   _globals=other._globals;
3591 }
3592
3593 /*!
3594  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3595  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3596  */
3597 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3598 {
3599   const MEDFileFieldGlobs *otherg(other._globals);
3600   if(!otherg)
3601     return ;
3602   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3603 }
3604
3605 /*!
3606  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3607  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3608  */
3609 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3610 {
3611   const MEDFileFieldGlobs *otherg(other._globals);
3612   if(!otherg)
3613     return ;
3614   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3615 }
3616
3617 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3618 {
3619   _globals=other._globals;
3620   if((const MEDFileFieldGlobs *)_globals)
3621     _globals=other._globals->deepCopy();
3622 }
3623
3624 /*!
3625  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3626  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3627  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3628  *         \a this and \a other MEDFileFieldGlobsReal.
3629  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3630  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3631  */
3632 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3633 {
3634   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3635   if(thisGlobals==otherGlobals)
3636     return ;
3637   if(!thisGlobals)
3638     {
3639       _globals=other._globals;
3640       return ;
3641     }
3642   _globals->appendGlobs(*other._globals,eps);
3643 }
3644
3645 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3646 {
3647   checkGlobsPflsPartCoherency();
3648   checkGlobsLocsPartCoherency();
3649 }
3650
3651 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3652 {
3653   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3654 }
3655
3656 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3657 {
3658   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3659 }
3660
3661 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3662 {
3663   contentNotNull()->loadProfileInFile(fid,id,pflName);
3664 }
3665
3666 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3667 {
3668   contentNotNull()->loadProfileInFile(fid,id);
3669 }
3670
3671 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3672 {
3673   contentNotNull()->loadGlobals(fid,*this);
3674 }
3675
3676 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3677 {
3678   contentNotNull()->loadAllGlobals(fid);
3679 }
3680
3681 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3682 {
3683   contentNotNull()->writeGlobals(fid,opt);
3684 }
3685
3686 /*!
3687  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3688  * or getPflsReallyUsedMulti().
3689  *  \return std::vector<std::string> - a sequence of names of all profiles.
3690  */
3691 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3692 {
3693   return contentNotNull()->getPfls();
3694 }
3695
3696 /*!
3697  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3698  * or getLocsReallyUsedMulti().
3699  *  \return std::vector<std::string> - a sequence of names of all localizations.
3700  */
3701 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3702 {
3703   return contentNotNull()->getLocs();
3704 }
3705
3706 /*!
3707  * Checks if the profile with a given name exists.
3708  *  \param [in] pflName - the profile name of interest.
3709  *  \return bool - \c true if the profile named \a pflName exists.
3710  */
3711 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3712 {
3713   return contentNotNull()->existsPfl(pflName);
3714 }
3715
3716 /*!
3717  * Checks if the localization with a given name exists.
3718  *  \param [in] locName - the localization name of interest.
3719  *  \return bool - \c true if the localization named \a locName exists.
3720  */
3721 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3722 {
3723   return contentNotNull()->existsLoc(locName);
3724 }
3725
3726 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3727 {
3728   return contentNotNull()->createNewNameOfPfl();
3729 }
3730
3731 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3732 {
3733   return contentNotNull()->createNewNameOfLoc();
3734 }
3735
3736 /*!
3737  * Sets the name of a MED file.
3738  *  \param [inout] fileName - the file name.
3739  */
3740 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3741 {
3742   contentNotNull()->setFileName(fileName);
3743 }
3744
3745 /*!
3746  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3747  * in the same order.
3748  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3749  *          Each item of this sequence is a vector containing ids of equal profiles.
3750  */
3751 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3752 {
3753   return contentNotNull()->whichAreEqualProfiles();
3754 }
3755
3756 /*!
3757  * Finds equal localizations.
3758  *  \param [in] eps - a precision used to compare real values of the localizations.
3759  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3760  *          Each item of this sequence is a vector containing ids of equal localizations.
3761  */
3762 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3763 {
3764   return contentNotNull()->whichAreEqualLocs(eps);
3765 }
3766
3767 /*!
3768  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3769  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3770  *        this sequence is a pair whose 
3771  *        - the first item is a vector of profile names to replace by the second item,
3772  *        - the second item is a profile name to replace every profile name of the first item.
3773  */
3774 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3775 {
3776   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3777 }
3778
3779 /*!
3780  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3781  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3782  *        this sequence is a pair whose 
3783  *        - the first item is a vector of localization names to replace by the second item,
3784  *        - the second item is a localization name to replace every localization name of the first item.
3785  */
3786 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3787 {
3788   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3789 }
3790
3791 /*!
3792  * Replaces references to some profiles (a reference is a profile name) by references
3793  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3794  * them-selves accordingly. <br>
3795  * This method is a generalization of changePflName().
3796  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3797  *        this sequence is a pair whose 
3798  *        - the first item is a vector of profile names to replace by the second item,
3799  *        - the second item is a profile name to replace every profile of the first item.
3800  * \sa changePflsRefsNamesGen()
3801  * \sa changePflName()
3802  */
3803 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3804 {
3805   changePflsRefsNamesGen(mapOfModif);
3806   changePflsNamesInStruct(mapOfModif);
3807 }
3808
3809 /*!
3810  * Replaces references to some localizations (a reference is a localization name) by references
3811  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3812  * them-selves accordingly. <br>
3813  * This method is a generalization of changeLocName().
3814  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3815  *        this sequence is a pair whose 
3816  *        - the first item is a vector of localization names to replace by the second item,
3817  *        - the second item is a localization name to replace every localization of the first item.
3818  * \sa changeLocsRefsNamesGen()
3819  * \sa changeLocName()
3820  */
3821 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3822 {
3823   changeLocsRefsNamesGen(mapOfModif);
3824   changeLocsNamesInStruct(mapOfModif);
3825 }
3826
3827 /*!
3828  * Renames the profile having a given name and updates references to this profile.
3829  *  \param [in] oldName - the name of the profile to rename.
3830  *  \param [in] newName - a new name of the profile.
3831  * \sa changePflsNames().
3832  */
3833 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3834 {
3835   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3836   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3837   mapOfModif[0]=p;
3838   changePflsNames(mapOfModif);
3839 }
3840
3841 /*!
3842  * Renames the localization having a given name and updates references to this localization.
3843  *  \param [in] oldName - the name of the localization to rename.
3844  *  \param [in] newName - a new name of the localization.
3845  * \sa changeLocsNames().
3846  */
3847 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3848 {
3849   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3850   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3851   mapOfModif[0]=p;
3852   changeLocsNames(mapOfModif);
3853 }
3854
3855 /*!
3856  * Removes duplicated profiles. Returns a map used to update references to removed 
3857  * profiles via changePflsRefsNamesGen().
3858  * Equal profiles are found using whichAreEqualProfiles().
3859  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3860  *          a sequence describing the performed replacements of profiles. Each element of
3861  *          this sequence is a pair whose
3862  *          - the first item is a vector of profile names replaced by the second item,
3863  *          - the second item is a profile name replacing every profile of the first item.
3864  */
3865 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3866 {
3867   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3868   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3869   int i=0;
3870   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3871     {
3872       std::vector< std::string > tmp((*it).size());
3873       int j=0;
3874       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3875         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3876       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3877       ret[i]=p;
3878       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3879       killProfileIds(tmp2);
3880     }
3881   changePflsRefsNamesGen(ret);
3882   return ret;
3883 }
3884
3885 /*!
3886  * Removes duplicated localizations. Returns a map used to update references to removed 
3887  * localizations via changeLocsRefsNamesGen().
3888  * Equal localizations are found using whichAreEqualLocs().
3889  *  \param [in] eps - a precision used to compare real values of the localizations.
3890  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3891  *          a sequence describing the performed replacements of localizations. Each element of
3892  *          this sequence is a pair whose
3893  *          - the first item is a vector of localization names replaced by the second item,
3894  *          - the second item is a localization name replacing every localization of the first item.
3895  */
3896 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3897 {
3898   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3899   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3900   int i=0;
3901   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3902     {
3903       std::vector< std::string > tmp((*it).size());
3904       int j=0;
3905       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3906         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3907       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3908       ret[i]=p;
3909       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3910       killLocalizationIds(tmp2);
3911     }
3912   changeLocsRefsNamesGen(ret);
3913   return ret;
3914 }
3915
3916 /*!
3917  * Returns number of Gauss points per cell in a given localization.
3918  *  \param [in] locId - an id of the localization of interest.
3919  *  \return int - the number of the Gauss points per cell.
3920  */
3921 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3922 {
3923   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3924 }
3925
3926 /*!
3927  * Returns an id of a localization by its name.
3928  *  \param [in] loc - the localization name of interest.
3929  *  \return int - the id of the localization.
3930  *  \throw If there is no a localization named \a loc.
3931  */
3932 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3933 {
3934   return contentNotNull()->getLocalizationId(loc);
3935 }
3936
3937 /*!
3938  * Returns the name of the MED file.
3939  *  \return const std::string&  - the MED file name.
3940  */
3941 std::string MEDFileFieldGlobsReal::getFileName() const
3942 {
3943   return contentNotNull()->getFileName();
3944 }
3945
3946 /*!
3947  * Returns a localization object by its name.
3948  *  \param [in] locName - the name of the localization of interest.
3949  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3950  *  \throw If there is no a localization named \a locName.
3951  */
3952 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3953 {
3954   return contentNotNull()->getLocalization(locName);
3955 }
3956
3957 /*!
3958  * Returns a localization object by its id.
3959  *  \param [in] locId - the id of the localization of interest.
3960  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3961  *  \throw If there is no a localization with id \a locId.
3962  */
3963 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3964 {
3965   return contentNotNull()->getLocalizationFromId(locId);
3966 }
3967
3968 /*!
3969  * Returns a profile array by its name.
3970  *  \param [in] pflName - the name of the profile of interest.
3971  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3972  *  \throw If there is no a profile named \a pflName.
3973  */
3974 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3975 {
3976   return contentNotNull()->getProfile(pflName);
3977 }
3978
3979 /*!
3980  * Returns a profile array by its id.
3981  *  \param [in] pflId - the id of the profile of interest.
3982  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3983  *  \throw If there is no a profile with id \a pflId.
3984  */
3985 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3986 {
3987   return contentNotNull()->getProfileFromId(pflId);
3988 }
3989
3990 /*!
3991  * Returns a localization object, apt for modification, by its id.
3992  *  \param [in] locId - the id of the localization of interest.
3993  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3994  *          having the id \a locId.
3995  *  \throw If there is no a localization with id \a locId.
3996  */
3997 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3998 {
3999   return contentNotNull()->getLocalizationFromId(locId);
4000 }
4001
4002 /*!
4003  * Returns a localization object, apt for modification, by its name.
4004  *  \param [in] locName - the name of the localization of interest.
4005  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
4006  *          having the name \a locName.
4007  *  \throw If there is no a localization named \a locName.
4008  */
4009 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
4010 {
4011   return contentNotNull()->getLocalization(locName);
4012 }
4013
4014 /*!
4015  * Returns a profile array, apt for modification, by its name.
4016  *  \param [in] pflName - the name of the profile of interest.
4017  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
4018  *  \throw If there is no a profile named \a pflName.
4019  */
4020 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
4021 {
4022   return contentNotNull()->getProfile(pflName);
4023 }
4024
4025 /*!
4026  * Returns a profile array, apt for modification, by its id.
4027  *  \param [in] pflId - the id of the profile of interest.
4028  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
4029  *  \throw If there is no a profile with id \a pflId.
4030  */
4031 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
4032 {
4033   return contentNotNull()->getProfileFromId(pflId);
4034 }
4035
4036 /*!
4037  * Removes profiles given by their ids. No data is updated to track this removal.
4038  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
4039  */
4040 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
4041 {
4042   contentNotNull()->killProfileIds(pflIds);
4043 }
4044
4045 /*!
4046  * Removes localizations given by their ids. No data is updated to track this removal.
4047  *  \param [in] locIds - a sequence of ids of the localizations to remove.
4048  */
4049 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
4050 {
4051   contentNotNull()->killLocalizationIds(locIds);
4052 }
4053
4054 /*!
4055  * Stores a profile array.
4056  *  \param [in] pfl - the profile array to store.
4057  *  \throw If the name of \a pfl is empty.
4058  *  \throw If a profile with the same name as that of \a pfl already exists but contains
4059  *         different ids.
4060  */
4061 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
4062 {
4063   contentNotNull()->appendProfile(pfl);
4064 }
4065
4066 /*!
4067  * Adds a new localization of Gauss points.
4068  *  \param [in] locName - the name of the new localization.
4069  *  \param [in] geoType - a geometrical type of the reference cell.
4070  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
4071  *         must be \c nbOfNodesPerCell * \c dimOfType.
4072  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
4073  *         must be  _wg_.size() * \c dimOfType.
4074  *  \param [in] w - the weights of Gauss points.
4075  *  \throw If \a locName is empty.
4076  *  \throw If a localization with the name \a locName already exists but is
4077  *         different form the new one.
4078  */
4079 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)
4080 {
4081   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
4082 }
4083
4084 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
4085 {
4086   MEDFileFieldGlobs *g(_globals);
4087   if(!g)
4088     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
4089   return g;
4090 }
4091
4092 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
4093 {
4094   const MEDFileFieldGlobs *g(_globals);
4095   if(!g)
4096     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4097   return g;
4098 }
4099
4100 //= MEDFileFieldNameScope
4101
4102 MEDFileFieldNameScope::MEDFileFieldNameScope()
4103 {
4104 }
4105
4106 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
4107 {
4108 }
4109
4110 /*!
4111  * Returns the name of \a this field.
4112  *  \return std::string - a string containing the field name.
4113  */
4114 std::string MEDFileFieldNameScope::getName() const
4115 {
4116   return _name;
4117 }
4118
4119 /*!
4120  * Sets name of \a this field
4121  *  \param [in] name - the new field name.
4122  */
4123 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4124 {
4125   _name=fieldName;
4126 }
4127
4128 std::string MEDFileFieldNameScope::getDtUnit() const
4129 {
4130   return _dt_unit;
4131 }
4132
4133 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4134 {
4135   _dt_unit=dtUnit;
4136 }
4137
4138 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4139 {
4140   _name=other._name;
4141   _dt_unit=other._dt_unit;
4142 }
4143
4144 //= MEDFileAnyTypeField1TSWithoutSDA
4145
4146 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4147 {
4148   _field_per_mesh.resize(other._field_per_mesh.size());
4149   std::size_t i=0;
4150   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4151     {
4152       if((const MEDFileFieldPerMesh *)*it)
4153         _field_per_mesh[i]=(*it)->deepCopy(this);
4154     }
4155 }
4156
4157 /*!
4158  * Prints a string describing \a this field into a stream. This string is outputted 
4159  * by \c print Python command.
4160  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4161  *  \param [in,out] oss - the out stream.
4162  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4163  *          info id printed, else, not.
4164  */
4165 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4166 {
4167   std::string startOfLine(bkOffset,' ');
4168   oss << startOfLine << "Field ";
4169   if(bkOffset==0)
4170     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4171   oss << "on one time Step ";
4172   if(f1tsId>=0)
4173     oss << "(" << f1tsId << ") ";
4174   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4175   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4176   const DataArray *arr=getUndergroundDataArray();
4177   if(arr)
4178     {
4179       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4180       if(f1tsId<0)
4181         {
4182           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4183           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4184             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4185         }
4186       if(arr->isAllocated())
4187         {
4188           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4189         }
4190       else
4191         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4192     }
4193   else
4194     {
4195       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4196     }
4197   oss << startOfLine << "----------------------" << std::endl;
4198   if(!_field_per_mesh.empty())
4199     {
4200       int i=0;
4201       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4202         {
4203           const MEDFileFieldPerMesh *cur=(*it2);
4204           if(cur)
4205             cur->simpleRepr(bkOffset,oss,i);
4206           else
4207             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4208         }
4209     }
4210   else
4211     {
4212       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4213     }
4214   oss << startOfLine << "----------------------" << std::endl;
4215 }
4216
4217 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4218 {
4219   const DataArray *arr(getUndergroundDataArray());
4220   if(!arr)
4221     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4222   int nbOfCompo=arr->getNumberOfComponents();
4223   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4224   for(int i=0;i<nbOfCompo;i++)
4225     {
4226       ret[i]=deepCopy();
4227       std::vector<int> v(1,i);
4228       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4229       ret[i]->setArray(arr2);
4230     }
4231   return ret;
4232 }
4233
4234 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)
4235 {
4236 }
4237
4238 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4239 {
4240 }
4241
4242 /*!
4243  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4244  * empty. Returns -1 if this in on nodes.
4245  *  \return int - the dimension of \a this.
4246  */
4247 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4248 {
4249   int ret=-2;
4250   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4251     (*it)->getDimension(ret);
4252   return ret;
4253 }
4254
4255 /*!
4256  * Returns the mesh name.
4257  *  \return std::string - a string holding the mesh name.
4258  *  \throw If \c _field_per_mesh.empty()
4259  */
4260 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
4261 {
4262   if(_field_per_mesh.empty())
4263     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
4264   return _field_per_mesh[0]->getMeshName();
4265 }
4266
4267 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
4268 {
4269   std::string oldName(getMeshName());
4270   std::vector< std::pair<std::string,std::string> > v(1);
4271   v[0].first=oldName; v[0].second=newMeshName;
4272   changeMeshNames(v);
4273 }
4274
4275 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4276 {
4277   bool ret=false;
4278   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4279     {
4280       MEDFileFieldPerMesh *cur(*it);
4281       if(cur)
4282         ret=cur->changeMeshNames(modifTab) || ret;
4283     }
4284   return ret;
4285 }
4286
4287 /*!
4288  * Returns the number of iteration of the state of underlying mesh.
4289  *  \return int - the iteration number.
4290  *  \throw If \c _field_per_mesh.empty()
4291  */
4292 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4293 {
4294   if(_field_per_mesh.empty())
4295     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4296   return _field_per_mesh[0]->getMeshIteration();
4297 }
4298
4299 /*!
4300  * Returns the order number of iteration of the state of underlying mesh.
4301  *  \return int - the order number.
4302  *  \throw If \c _field_per_mesh.empty()
4303  */
4304 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4305 {
4306   if(_field_per_mesh.empty())
4307     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4308   return _field_per_mesh[0]->getMeshOrder();
4309 }
4310
4311 /*!
4312  * Checks if \a this field is tagged by a given iteration number and a given
4313  * iteration order number.
4314  *  \param [in] iteration - the iteration number of interest.
4315  *  \param [in] order - the iteration order number of interest.
4316  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4317  *          \a this->getOrder() == \a order.
4318  */
4319 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4320 {
4321   return iteration==_iteration && order==_order;
4322 }
4323
4324 /*!
4325  * Returns number of iteration and order number of iteration when
4326  * \a this field has been calculated.
4327  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4328  *          order number.
4329  */
4330 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4331 {
4332   std::pair<int,int> p;
4333   fillIteration(p);
4334   return p;
4335 }
4336
4337 /*!
4338  * Returns number of iteration and order number of iteration when
4339  * \a this field has been calculated.
4340  *  \param [in,out] p - a pair returning the iteration number and the iteration
4341  *          order number.
4342  */
4343 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4344 {
4345   p.first=_iteration;
4346   p.second=_order;
4347 }
4348
4349 /*!
4350  * Returns all types of spatial discretization of \a this field.
4351  *  \param [in,out] types - a sequence of types of \a this field.
4352  */
4353 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4354 {
4355   std::set<TypeOfField> types2;
4356   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4357     {
4358       (*it)->fillTypesOfFieldAvailable(types2);
4359     }
4360   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4361   std::copy(types2.begin(),types2.end(),bi);
4362 }
4363
4364 /*!
4365  * Returns all types of spatial discretization of \a this field.
4366  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4367  *          of \a this field.
4368  */
4369 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4370 {
4371   std::vector<TypeOfField> ret;
4372   fillTypesOfFieldAvailable(ret);
4373   return ret;
4374 }
4375
4376 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4377 {
4378   std::vector<std::string> ret;
4379   std::set<std::string> ret2;
4380   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4381     {
4382       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4383       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4384         if(ret2.find(*it2)==ret2.end())
4385           {
4386             ret.push_back(*it2);
4387             ret2.insert(*it2);
4388           }
4389     }
4390   return ret;
4391 }
4392
4393 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4394 {
4395   std::vector<std::string> ret;
4396   std::set<std::string> ret2;
4397   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4398     {
4399       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4400       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4401         if(ret2.find(*it2)==ret2.end())
4402           {
4403             ret.push_back(*it2);
4404             ret2.insert(*it2);
4405           }
4406     }
4407   return ret;
4408 }
4409
4410 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4411 {
4412   std::vector<std::string> ret;
4413   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4414     {
4415       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4416       ret.insert(ret.end(),tmp.begin(),tmp.end());
4417     }
4418   return ret;
4419 }
4420
4421 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4422 {
4423   std::vector<std::string> ret;
4424   std::set<std::string> ret2;
4425   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4426     {
4427       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4428       ret.insert(ret.end(),tmp.begin(),tmp.end());
4429     }
4430   return ret;
4431 }
4432
4433 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4434 {
4435   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4436     (*it)->changePflsRefsNamesGen(mapOfModif);
4437 }
4438
4439 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4440 {
4441   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4442     (*it)->changeLocsRefsNamesGen(mapOfModif);
4443 }
4444
4445 /*!
4446  * Returns all attributes of parts of \a this field lying on a given mesh.
4447  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4448  * item of every of returned sequences refers to the _i_-th part of \a this field.
4449  * Thus all sequences returned by this method are of the same length equal to number
4450  * of different types of supporting entities.<br>
4451  * A field part can include sub-parts with several different spatial discretizations,
4452  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4453  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4454  * of a nested sequence corresponds to a type of spatial discretization.<br>
4455  * This method allows for iteration over MEDFile DataStructure without any overhead.
4456  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4457  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4458  *          not checked if \a mname == \c NULL).
4459  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4460  *          a field part is returned. 
4461  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4462  *          This sequence is of the same length as \a types. 
4463  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4464  *          discretization. A profile name can be empty.
4465  *          Length of this and of nested sequences is the same as that of \a typesF.
4466  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4467  *          discretization. A localization name can be empty.
4468  *          Length of this and of nested sequences is the same as that of \a typesF.
4469  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4470  *          of ids of tuples within the data array, per each type of spatial
4471  *          discretization within one mesh entity type. 
4472  *          Length of this and of nested sequences is the same as that of \a typesF.
4473  *  \throw If no field is lying on \a mname.
4474  */
4475 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
4476 {
4477   int meshId=0;
4478   if(!mname.empty())
4479     meshId=getMeshIdFromMeshName(mname);
4480   else
4481     if(_field_per_mesh.empty())
4482       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4483   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4484 }
4485
4486 /*!
4487  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4488  * maximal absolute dimension and values returned via the out parameter \a levs are 
4489  * dimensions relative to the maximal absolute dimension. <br>
4490  * This method is designed for MEDFileField1TS instances that have a discretization
4491  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4492  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4493  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4494  * Only these 3 discretizations will be taken into account here. If \a this is
4495  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4496  * This method is useful to make the link between the dimension of the underlying mesh
4497  * and the levels of \a this, because it is possible that the highest dimension of \a this
4498  * field is not equal to the dimension of the underlying mesh.
4499  * 
4500  * Let's consider the following case:
4501  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4502  * TETRA4, HEXA8, TRI3 and SEG2.
4503  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4504  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4505  *
4506  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4507  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4508  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4509  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4510  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4511  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4512  * For example<br>
4513  * to retrieve the highest level of
4514  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4515  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4516  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4517  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4518  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4519  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4520  *          not checked if \a mname == \c NULL).
4521  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4522  *          absolute one. They are in decreasing order. This sequence is cleared before
4523  *          filling it in.
4524  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4525  *  \throw If no field is lying on \a mname.
4526  */
4527 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4528 {
4529   levs.clear();
4530   int meshId=getMeshIdFromMeshName(mname);
4531   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4532   std::vector< std::vector<TypeOfField> > typesF;
4533   std::vector< std::vector<std::string> > pfls, locs;
4534   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4535   if(types.empty())
4536     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4537   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4538   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4539     return -1;
4540   st.erase(INTERP_KERNEL::NORM_ERROR);
4541   std::set<int> ret1;
4542   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4543     {
4544       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4545       ret1.insert((int)cm.getDimension());
4546     }
4547   int ret=*std::max_element(ret1.begin(),ret1.end());
4548   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4549   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4550   return ret;
4551 }
4552
4553 /*!
4554  * \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.
4555  * \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.
4556  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4557  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4558  */
4559 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4560 {
4561   int mid=getMeshIdFromMeshName(mName);
4562   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4563 }
4564
4565 /*!
4566  * \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.
4567  * \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.
4568  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4569  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4570  */
4571 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4572 {
4573   int mid=getMeshIdFromMeshName(mName);
4574   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4575 }
4576
4577 /*!
4578  * \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.
4579  */
4580 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4581 {
4582   if(_field_per_mesh.empty())
4583     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4584   if(mName.empty())
4585     return 0;
4586   std::string mName2(mName);
4587   int ret=0;
4588   std::vector<std::string> msg;
4589   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4590     if(mName2==(*it)->getMeshName())
4591       return ret;
4592     else
4593       msg.push_back((*it)->getMeshName());
4594   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4595   oss << "Possible meshes are : ";
4596   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4597     oss << "\"" << (*it2) << "\" ";
4598   throw INTERP_KERNEL::Exception(oss.str());
4599 }
4600
4601 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4602 {
4603   if(!mesh)
4604     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4605   std::string tmp(mesh->getName());
4606   if(tmp.empty())
4607     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4608   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4609   int i=0;
4610   for(;it!=_field_per_mesh.end();it++,i++)
4611     {
4612       if((*it)->getMeshName()==tmp)
4613         return i;
4614     }
4615   int sz=_field_per_mesh.size();
4616   _field_per_mesh.resize(sz+1);
4617   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4618   return sz;
4619 }
4620
4621 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4622                                                                    MEDFileFieldGlobsReal& glob)
4623 {
4624   bool ret=false;
4625   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4626     {
4627       MEDFileFieldPerMesh *fpm(*it);
4628       if(fpm)
4629         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4630     }
4631   return ret;
4632 }
4633
4634 /*!
4635  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4636  * splitting that leads to single spatial discretization of this.
4637  *
4638  * \sa splitMultiDiscrPerGeoTypes
4639  */
4640 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4641 {
4642   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4643   std::vector< std::vector<TypeOfField> > typesF;
4644   std::vector< std::vector<std::string> > pfls,locs;
4645   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4646   std::set<TypeOfField> allEnt;
4647   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4648     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4649       allEnt.insert(*it2);
4650   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4651   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4652   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4653     {
4654       std::vector< std::pair<int,int> > its;
4655       ret[i]=shallowCpy();
4656       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4657       ret[i]->updateData(newLgth,its);
4658     }
4659   return ret;
4660 }
4661
4662 /*!
4663  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4664  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4665  *
4666  * \sa splitDiscretizations
4667  */
4668 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4669 {
4670   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4671   std::vector< std::vector<TypeOfField> > typesF;
4672   std::vector< std::vector<std::string> > pfls,locs;
4673   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4674   std::set<TypeOfField> allEnt;
4675   std::size_t nbOfMDPGT(0),ii(0);
4676   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4677     {
4678       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4679       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4680         allEnt.insert(*it2);
4681     }
4682   if(allEnt.size()!=1)
4683     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4684   if(nbOfMDPGT==0)
4685     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4686   if(nbOfMDPGT==1)
4687     {
4688       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4689       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4690       return ret0;
4691     }
4692   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4693   for(std::size_t i=0;i<nbOfMDPGT;i++)
4694     {
4695       std::vector< std::pair<int,int> > its;
4696       ret[i]=shallowCpy();
4697       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4698       ret[i]->updateData(newLgth,its);
4699     }
4700   return ret;
4701 }
4702
4703 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4704 {
4705   int globalCounter(0);
4706   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4707     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4708   return globalCounter;
4709 }
4710
4711 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4712 {
4713   int globalCounter(0);
4714   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4715     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4716   return globalCounter;
4717 }
4718
4719 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4720 {
4721   if(_nb_of_tuples_to_be_allocated>=0)
4722     {
4723       _nb_of_tuples_to_be_allocated=newLgth;
4724       const DataArray *oldArr(getUndergroundDataArray());
4725       if(oldArr)
4726         {
4727           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4728           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4729           setArray(newArr);
4730           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4731         }
4732       return ;
4733     }
4734   if(_nb_of_tuples_to_be_allocated==-1)
4735     return ;
4736   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4737     {
4738       const DataArray *oldArr(getUndergroundDataArray());
4739       if(!oldArr || !oldArr->isAllocated())
4740         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4741       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4742       newArr->alloc(newLgth,getNumberOfComponents());
4743       if(oldArr)
4744         newArr->copyStringInfoFrom(*oldArr);
4745       int pos=0;
4746       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4747         {
4748           if((*it).second<(*it).first)
4749             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4750           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4751           pos+=(*it).second-(*it).first;
4752         }
4753       setArray(newArr);
4754       return ;
4755     }
4756   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4757 }
4758
4759 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4760 {
4761   if(_field_per_mesh.empty())
4762     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4763   if(_field_per_mesh.size()>1)
4764     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4765   _field_per_mesh[0]->copyOptionsFrom(opts);
4766   _field_per_mesh[0]->writeLL(fid,nasc);
4767 }
4768
4769 /*!
4770  * 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.
4771  * If false is returned the memory allocation is not required.
4772  */
4773 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4774 {
4775   if(_nb_of_tuples_to_be_allocated>=0)
4776     {
4777       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4778       _nb_of_tuples_to_be_allocated=-2;
4779       return true;
4780     }
4781   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4782     return false;
4783   if(_nb_of_tuples_to_be_allocated==-1)
4784     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4785   if(_nb_of_tuples_to_be_allocated<-3)
4786     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4787   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4788 }
4789
4790 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4791 {
4792   med_int numdt,numit;
4793   med_float dt;
4794   med_int nmesh;
4795   med_bool localMesh;
4796   med_int meshnumdt,meshnumit;
4797   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4798   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4799   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4800   if(_iteration!=numdt || _order!=numit)
4801     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4802   _field_per_mesh.resize(nmesh);
4803   //
4804   MEDFileMesh *mm(0);
4805   if(ms)
4806     {
4807       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4808       mm=ms->getMeshWithName(meshNameCpp);
4809     }
4810   //
4811   for(int i=0;i<nmesh;i++)
4812     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4813   _nb_of_tuples_to_be_allocated=0;
4814   for(int i=0;i<nmesh;i++)
4815     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4816 }
4817
4818 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4819 {
4820   allocIfNecessaryTheArrayToReceiveDataFromFile();
4821   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4822     (*it)->loadBigArraysRecursively(fid,nasc);
4823 }
4824
4825 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4826 {
4827   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4828     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4829       (*it)->loadBigArraysRecursively(fid,nasc);
4830 }
4831
4832 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4833 {
4834   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4835   loadBigArraysRecursively(fid,nasc);
4836 }
4837
4838 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4839 {
4840   DataArray *thisArr(getUndergroundDataArray());
4841   if(thisArr && thisArr->isAllocated())
4842     {
4843       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4844       thisArr->desallocate();
4845     }
4846 }
4847
4848 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4849 {
4850   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4851 }
4852
4853 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4854 {
4855   std::vector<const BigMemoryObject *> ret;
4856   if(getUndergroundDataArray())
4857     ret.push_back(getUndergroundDataArray());
4858   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4859     ret.push_back((const MEDFileFieldPerMesh *)*it);
4860   return ret;
4861 }
4862
4863 /*!
4864  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4865  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4866  * "Sort By Type"), if not, an exception is thrown. 
4867  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4868  *  \param [in] arr - the array of values.
4869  *  \param [in,out] glob - the global data where profiles and localization present in
4870  *          \a field, if any, are added.
4871  *  \throw If the name of \a field is empty.
4872  *  \throw If the data array of \a field is not set.
4873  *  \throw If \a this->_arr is already allocated but has different number of components
4874  *         than \a field.
4875  *  \throw If the underlying mesh of \a field has no name.
4876  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4877  */
4878 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4879 {
4880   const MEDCouplingMesh *mesh=field->getMesh();
4881   //
4882   TypeOfField type=field->getTypeOfField();
4883   std::vector<DataArrayInt *> dummy;
4884   int start=copyTinyInfoFrom(field,arr);
4885   int pos=addNewEntryIfNecessary(mesh);
4886   if(type!=ON_NODES)
4887     {
4888       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4889       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4890     }
4891   else
4892     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4893 }
4894
4895 /*!
4896  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4897  * of a given mesh are used as the support of the given field (a real support is not used). 
4898  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4899  * Order of underlying mesh entities of the given field specified by \a profile parameter
4900  * is not prescribed; this method permutes field values to have them sorted by element
4901  * type as required for writing to MED file. A new profile is added only if no equal
4902  * profile is missing. 
4903  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4904  *  \param [in] arrOfVals - the values of the field \a field used.
4905  *  \param [in] mesh - the supporting mesh of \a field.
4906  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4907  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4908  *  \param [in,out] glob - the global data where profiles and localization present in
4909  *          \a field, if any, are added.
4910  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4911  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4912  *  \throw If the data array of \a field is not set.
4913  *  \throw If \a this->_arr is already allocated but has different number of components
4914  *         than \a field.
4915  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4916  *  \sa setFieldNoProfileSBT()
4917  */
4918 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4919 {
4920   if(!field)
4921     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4922   if(!arrOfVals || !arrOfVals->isAllocated())
4923     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4924   TypeOfField type=field->getTypeOfField();
4925   std::vector<DataArrayInt *> idsInPflPerType;
4926   std::vector<DataArrayInt *> idsPerType;
4927   std::vector<int> code,code2;
4928   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4929   if(type!=ON_NODES)
4930     {
4931       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4932       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4933       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4934       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4935       // start of check
4936       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4937       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4938       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4939         {
4940           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4941           throw INTERP_KERNEL::Exception(oss.str());
4942         }
4943       // end of check
4944       int start=copyTinyInfoFrom(field,arrOfVals);
4945       code2=m->getDistributionOfTypes();
4946       //
4947       int pos=addNewEntryIfNecessary(m);
4948       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4949     }
4950   else
4951     {
4952       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4953         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4954       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4955       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4956       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4957       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4958         {
4959           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4960           throw INTERP_KERNEL::Exception(oss.str());
4961         }
4962       int start=copyTinyInfoFrom(field,arrOfVals);
4963       int pos=addNewEntryIfNecessary(m);
4964       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4965     }
4966 }
4967
4968 /*!
4969  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4970  */
4971 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4972 {
4973   if(_nb_of_tuples_to_be_allocated>=0)
4974     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 !");
4975   DataArray *arr(getOrCreateAndGetArray());
4976   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4977   _nb_of_tuples_to_be_allocated=-3;
4978 }
4979
4980 /*!
4981  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4982  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4983  * larger by the size of \a field. Returns an id of the first not filled
4984  * tuple of \a this->_arr.
4985  *  \param [in] field - the field to copy the info on components and the name from.
4986  *  \return int - the id of first not initialized tuple of \a this->_arr.
4987  *  \throw If the name of \a field is empty.
4988  *  \throw If the data array of \a field is not set.
4989  *  \throw If \a this->_arr is already allocated but has different number of components
4990  *         than \a field.
4991  */
4992 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4993 {
4994   if(!field)
4995     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4996   std::string name(field->getName());
4997   setName(name.c_str());
4998   setDtUnit(field->getTimeUnit());
4999   if(name.empty())
5000     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
5001   if(!arr)
5002     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
5003   if(!arr->isAllocated())
5004     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
5005   _dt=field->getTime(_iteration,_order);
5006   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
5007   if(!getOrCreateAndGetArray()->isAllocated())
5008     {
5009       allocNotFromFile(arr->getNumberOfTuples());
5010       return 0;
5011     }
5012   else
5013     {
5014       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
5015       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
5016       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
5017       _nb_of_tuples_to_be_allocated=-3;
5018       return oldNbOfTuples;
5019     }
5020 }
5021
5022 /*!
5023  * Returns number of components in \a this field
5024  *  \return int - the number of components.
5025  */
5026 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
5027 {
5028   return getOrCreateAndGetArray()->getNumberOfComponents();
5029 }
5030
5031 /*!
5032  * Change info on components in \a this.
5033  * \throw If size of \a infos is not equal to the number of components already in \a this.
5034  */
5035 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
5036 {
5037   DataArray *arr=getOrCreateAndGetArray();
5038   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
5039 }
5040
5041 /*!
5042  * Returns info on components of \a this field.
5043  *  \return const std::vector<std::string>& - a sequence of strings each being an
5044  *          information on _i_-th component.
5045  */
5046 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
5047 {
5048   const DataArray *arr=getOrCreateAndGetArray();
5049   return arr->getInfoOnComponents();
5050 }
5051
5052 /*!
5053  * Returns a mutable info on components of \a this field.
5054  *  \return std::vector<std::string>& - a sequence of strings each being an
5055  *          information on _i_-th component.
5056  */
5057 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
5058 {
5059   DataArray *arr=getOrCreateAndGetArray();
5060   return arr->getInfoOnComponents();
5061 }
5062
5063 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
5064 {
5065   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5066     {
5067       const MEDFileFieldPerMesh *fpm(*it);
5068       if(!fpm)
5069         continue;
5070       if(fpm->presenceOfMultiDiscPerGeoType())
5071         return true;
5072     }
5073   return false;
5074 }
5075
5076 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const
5077 {
5078   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5079     if((*it).isNotNull())
5080       if((*it)->presenceOfStructureElements())
5081         return true;
5082   return false;
5083 }
5084
5085 bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const
5086 {
5087   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5088     if((*it).isNotNull())
5089       if(!(*it)->onlyStructureElements())
5090         return false;
5091   return true;
5092 }
5093
5094 void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements()
5095 {
5096   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5097     if((*it).isNotNull())
5098       (*it)->killStructureElements();
5099 }
5100
5101 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements()
5102 {
5103   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5104     if((*it).isNotNull())
5105       (*it)->keepOnlyStructureElements();
5106 }
5107
5108 void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName)
5109 {
5110   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5111     if((*it).isNotNull())
5112       (*it)->keepOnlyOnSE(seName);
5113 }
5114
5115 void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
5116 {
5117   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
5118     if((*it).isNotNull())
5119       (*it)->getMeshSENames(ps);
5120 }
5121
5122 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5123 {
5124   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 !";
5125   if(_field_per_mesh.empty())
5126     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
5127   if(_field_per_mesh.size()>1)
5128     throw INTERP_KERNEL::Exception(MSG0);
5129   if(_field_per_mesh[0].isNull())
5130     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
5131   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
5132   std::set<TypeOfField> types;
5133   pm->fillTypesOfFieldAvailable(types);
5134   if(types.size()!=1)
5135     throw INTERP_KERNEL::Exception(MSG0);
5136   TypeOfField type(*types.begin());
5137   int meshDimRelToMax(0);
5138   if(type==ON_NODES)
5139     meshDimRelToMax=0;
5140   else
5141     {
5142       int myDim(std::numeric_limits<int>::max());
5143       bool isUnique(pm->isUniqueLevel(myDim));
5144       if(!isUnique)
5145         throw INTERP_KERNEL::Exception(MSG0);
5146       meshDimRelToMax=myDim-mesh->getMeshDimension();
5147       if(meshDimRelToMax>0)
5148         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5149     }
5150   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5151 }
5152
5153 /*!
5154  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5155  *  \param [in] type - a spatial discretization of the new field.
5156  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5157  *  \param [in] mName - a name of the supporting mesh.
5158  *  \param [in] renumPol - specifies how to permute values of the result field according to
5159  *          the optional numbers of cells and nodes, if any. The valid values are
5160  *          - 0 - do not permute.
5161  *          - 1 - permute cells.
5162  *          - 2 - permute nodes.
5163  *          - 3 - permute cells and nodes.
5164  *
5165  *  \param [in] glob - the global data storing profiles and localization.
5166  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5167  *          caller is to delete this field using decrRef() as it is no more needed. 
5168  *  \throw If the MED file is not readable.
5169  *  \throw If there is no mesh named \a mName in the MED file.
5170  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5171  *  \throw If no field of \a this is lying on the mesh \a mName.
5172  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5173  */
5174 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5175 {
5176   MCAuto<MEDFileMesh> mm;
5177   if(mName.empty())
5178     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5179   else
5180     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5181   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5182 }
5183
5184 /*!
5185  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5186  *  \param [in] type - a spatial discretization of the new field.
5187  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5188  *  \param [in] renumPol - specifies how to permute values of the result field according to
5189  *          the optional numbers of cells and nodes, if any. The valid values are
5190  *          - 0 - do not permute.
5191  *          - 1 - permute cells.
5192  *          - 2 - permute nodes.
5193  *          - 3 - permute cells and nodes.
5194  *
5195  *  \param [in] glob - the global data storing profiles and localization.
5196  *  \param [in] mesh - the supporting mesh.
5197  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5198  *          caller is to delete this field using decrRef() as it is no more needed. 
5199  *  \throw If the MED file is not readable.
5200  *  \throw If no field of \a this is lying on \a mesh.
5201  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5202  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5203  */
5204 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5205 {
5206   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5207   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5208   if(meshDimRelToMax==1)
5209     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5210   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5211 }
5212
5213 /*!
5214  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5215  * given mesh. 
5216  *  \param [in] type - a spatial discretization of the new field.
5217  *  \param [in] mName - a name of the supporting mesh.
5218  *  \param [in] renumPol - specifies how to permute values of the result field according to
5219  *          the optional numbers of cells and nodes, if any. The valid values are
5220  *          - 0 - do not permute.
5221  *          - 1 - permute cells.
5222  *          - 2 - permute nodes.
5223  *          - 3 - permute cells and nodes.
5224  *
5225  *  \param [in] glob - the global data storing profiles and localization.
5226  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5227  *          caller is to delete this field using decrRef() as it is no more needed. 
5228  *  \throw If the MED file is not readable.
5229  *  \throw If there is no mesh named \a mName in the MED file.
5230  *  \throw If there are no mesh entities in the mesh.
5231  *  \throw If no field values of the given \a type are available.
5232  */
5233 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5234 {
5235   MCAuto<MEDFileMesh> mm;
5236   if(mName.empty())
5237     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5238   else
5239     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5240   int absDim=getDimension();
5241   int meshDimRelToMax=absDim-mm->getMeshDimension();
5242   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5243 }
5244
5245 /*!
5246  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5247  *  \param [in] type - a spatial discretization of the new field.
5248  *  \param [in] renumPol - specifies how to permute values of the result field according to
5249  *          the optional numbers of cells and nodes, if any. The valid values are
5250  *          - 0 - do not permute.
5251  *          - 1 - permute cells.
5252  *          - 2 - permute nodes.
5253  *          - 3 - permute cells and nodes.
5254  *
5255  *  \param [in] glob - the global data storing profiles and localization.
5256  *  \param [in] mesh - the supporting mesh.
5257  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5258  *         field according to \a renumPol.
5259  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5260  *         field according to \a renumPol.
5261  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5262  *          caller is to delete this field using decrRef() as it is no more needed. 
5263  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5264  *  \throw If no field of \a this is lying on \a mesh.
5265  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5266  */
5267 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
5268 {
5269   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5270   int meshId=getMeshIdFromMeshName(mesh->getName());
5271   bool isPfl=false;
5272   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5273   switch(renumPol)
5274   {
5275     case 0:
5276       {
5277         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5278         return ret.retn();
5279       }
5280     case 3:
5281     case 1:
5282       {
5283         if(isPfl)
5284           throw INTERP_KERNEL::Exception(msg1);
5285         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5286         if(cellRenum)
5287           {
5288             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5289               {
5290                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5291                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5292                 throw INTERP_KERNEL::Exception(oss.str());
5293               }
5294             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5295             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5296             std::vector<DataArray *> arrOut2(1,arrOut);
5297             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5298             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5299             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5300           }
5301         if(renumPol==1)
5302           return ret.retn();
5303       }
5304     case 2:
5305       {
5306         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5307         if(isPfl)
5308           throw INTERP_KERNEL::Exception(msg1);
5309         if(nodeRenum)
5310           {
5311             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5312               {
5313                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5314                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5315                 throw INTERP_KERNEL::Exception(oss.str());
5316               }
5317             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5318             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5319               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5320             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5321           }
5322         return ret.retn();
5323       }
5324     default:
5325       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5326   }
5327 }
5328
5329 /*!
5330  * Returns values and a profile of the field of a given type lying on a given support.
5331  *  \param [in] type - a spatial discretization of the field.
5332  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5333  *  \param [in] mesh - the supporting mesh.
5334  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5335  *          field of interest lies on. If the field lies on all entities of the given
5336  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5337  *          using decrRef() as it is no more needed.  
5338  *  \param [in] glob - the global data storing profiles and localization.
5339  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5340  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5341  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5342  *  \throw If no field of \a this is lying on \a mesh.
5343  *  \throw If no field values of the given \a type are available.
5344  */
5345 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5346 {
5347   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5348   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
5349   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5350   ret->setName(nasc.getName().c_str());
5351   return ret.retn();
5352 }
5353
5354 //= MEDFileField1TSWithoutSDA
5355
5356 /*!
5357  * Throws if a given value is not a valid (non-extended) relative dimension.
5358  *  \param [in] meshDimRelToMax - the relative dimension value.
5359  *  \throw If \a meshDimRelToMax > 0.
5360  */
5361 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5362 {
5363   if(meshDimRelToMax>0)
5364     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5365 }
5366
5367 /*!
5368  * Checks if elements of a given mesh are in the order suitable for writing 
5369  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5370  * vector describing types of elements and their number.
5371  *  \param [in] mesh - the mesh to check.
5372  *  \return std::vector<int> - a vector holding for each element type (1) item of
5373  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5374  *          These values are in full-interlace mode.
5375  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5376  */
5377 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5378 {
5379   if(!mesh)
5380     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5381   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5382   int nbOfTypes=geoTypes.size();
5383   std::vector<int> code(3*nbOfTypes);
5384   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5385   arr1->alloc(nbOfTypes,1);
5386   int *arrPtr=arr1->getPointer();
5387   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5388   for(int i=0;i<nbOfTypes;i++,it++)
5389     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5390   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5391   const int *arrPtr2=arr2->getConstPointer();
5392   int i=0;
5393   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5394     {
5395       int pos=arrPtr2[i];
5396       int nbCells=mesh->getNumberOfCellsWithType(*it);
5397       code[3*pos]=(int)(*it);
5398       code[3*pos+1]=nbCells;
5399       code[3*pos+2]=-1;//no profiles
5400     }
5401   std::vector<const DataArrayInt *> idsPerType;//no profiles
5402   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5403   if(da)
5404     {
5405       da->decrRef();
5406       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5407     }
5408   return code;
5409 }
5410
5411 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5412 {
5413   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5414 }
5415
5416 /*!
5417  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5418  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5419  * item of every of returned sequences refers to the _i_-th part of \a this field.
5420  * Thus all sequences returned by this method are of the same length equal to number
5421  * of different types of supporting entities.<br>
5422  * A field part can include sub-parts with several different spatial discretizations,
5423  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5424  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5425  * of a nested sequence corresponds to a type of spatial discretization.<br>
5426  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5427  * The overhead is due to selecting values into new instances of DataArrayDouble.
5428  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5429  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5430  *          not checked if \a mname == \c NULL).
5431  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5432  *          a field part is returned. 
5433  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5434  *          A field part can include sub-parts with several different spatial discretizations,
5435  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5436  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5437  *          This sequence is of the same length as \a types. 
5438  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5439  *          discretization. A profile name can be empty.
5440  *          Length of this and of nested sequences is the same as that of \a typesF.
5441  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5442  *          discretization. A localization name can be empty.
5443  *          Length of this and of nested sequences is the same as that of \a typesF.
5444  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5445  *          per each type of spatial discretization within one mesh entity type.
5446  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5447  *          Length of this and of nested sequences is the same as that of \a typesF.
5448  *  \throw If no field is lying on \a mname.
5449  */
5450 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
5451 {
5452   int meshId=0;
5453   if(!mname.empty())
5454     meshId=getMeshIdFromMeshName(mname);
5455   else
5456     if(_field_per_mesh.empty())
5457       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5458   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5459   int nbOfRet=ret0.size();
5460   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5461   for(int i=0;i<nbOfRet;i++)
5462     {
5463       const std::vector< std::pair<int,int> >& p=ret0[i];
5464       int nbOfRet1=p.size();
5465       ret[i].resize(nbOfRet1);
5466       for(int j=0;j<nbOfRet1;j++)
5467         {
5468           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5469           ret[i][j]=tmp;
5470         }
5471     }
5472   return ret;
5473 }
5474
5475 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5476 {
5477   return TYPE_STR;
5478 }
5479
5480 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5481 {
5482   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5483   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5484   ret->deepCpyLeavesFrom(*this);
5485   const DataArrayDouble *arr(_arr);
5486   if(arr)
5487     {
5488       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5489       ret->setArray(arr2);
5490     }
5491   return ret.retn();
5492 }
5493
5494 /*!
5495  * Returns a pointer to the underground DataArrayDouble instance and a
5496  * sequence describing parameters of a support of each part of \a this field. The
5497  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5498  * direct access to the field values. This method is intended for the field lying on one
5499  * mesh only.
5500  *  \param [in,out] entries - the sequence describing parameters of a support of each
5501  *         part of \a this field. Each item of this sequence consists of two parts. The
5502  *         first part describes a type of mesh entity and an id of discretization of a
5503  *         current field part. The second part describes a range of values [begin,end)
5504  *         within the returned array relating to the current field part.
5505  *  \return DataArrayDouble * - the pointer to the field values array.
5506  *  \throw If the number of underlying meshes is not equal to 1.
5507  *  \throw If no field values are available.
5508  *  \sa getUndergroundDataArray()
5509  */
5510 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5511 {
5512   if(_field_per_mesh.size()!=1)
5513     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5514   if(_field_per_mesh[0]==0)
5515     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5516   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5517   return getUndergroundDataArrayTemplate();
5518 }
5519
5520 /*!
5521  * Returns a pointer to the underground DataArrayDouble instance and a
5522  * sequence describing parameters of a support of each part of \a this field. The
5523  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5524  * direct access to the field values. This method is intended for the field lying on one
5525  * mesh only.
5526  *  \param [in,out] entries - the sequence describing parameters of a support of each
5527  *         part of \a this field. Each item of this sequence consists of two parts. The
5528  *         first part describes a type of mesh entity and an id of discretization of a
5529  *         current field part. The second part describes a range of values [begin,end)
5530  *         within the returned array relating to the current field part.
5531  *  \return DataArrayDouble * - the pointer to the field values array.
5532  *  \throw If the number of underlying meshes is not equal to 1.
5533  *  \throw If no field values are available.
5534  *  \sa getUndergroundDataArray()
5535  */
5536 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5537 {
5538   return getUndergroundDataArrayDoubleExt(entries);
5539 }
5540
5541 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,csit,iteration,order)
5542 {
5543   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5544   arr->setInfoAndChangeNbOfCompo(infos);
5545 }
5546
5547 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5548 {
5549 }
5550
5551 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5552 {
5553   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5554   ret->deepCpyLeavesFrom(*this);
5555   return ret.retn();
5556 }
5557
5558 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5559 {
5560   MCAuto<MEDFileField1TSWithoutSDA> ret(shallowCpy());
5561   if(_arr.isNotNull())
5562     ret->_arr=_arr->deepCopy();
5563   return ret.retn();
5564 }
5565
5566 //= MEDFileIntField1TSWithoutSDA
5567
5568 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5569 {
5570   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5571 }
5572
5573 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5574 {
5575 }
5576
5577 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5578                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,csit,iteration,order)
5579 {
5580   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5581   arr->setInfoAndChangeNbOfCompo(infos);
5582 }
5583
5584 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5585 {
5586   return TYPE_STR;
5587 }
5588
5589 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5590 {
5591   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5592   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5593   ret->deepCpyLeavesFrom(*this);
5594   const DataArrayInt *arr(_arr);
5595   if(arr)
5596     {
5597       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5598       ret->setArray(arr2);
5599     }
5600   return ret.retn();
5601 }
5602
5603 /*!
5604  * Returns a pointer to the underground DataArrayInt instance and a
5605  * sequence describing parameters of a support of each part of \a this field. The
5606  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5607  * direct access to the field values. This method is intended for the field lying on one
5608  * mesh only.
5609  *  \param [in,out] entries - the sequence describing parameters of a support of each
5610  *         part of \a this field. Each item of this sequence consists of two parts. The
5611  *         first part describes a type of mesh entity and an id of discretization of a
5612  *         current field part. The second part describes a range of values [begin,end)
5613  *         within the returned array relating to the current field part.
5614  *  \return DataArrayInt * - the pointer to the field values array.
5615  *  \throw If the number of underlying meshes is not equal to 1.
5616  *  \throw If no field values are available.
5617  *  \sa getUndergroundDataArray()
5618  */
5619 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5620 {
5621   return getUndergroundDataArrayIntExt(entries);
5622 }
5623
5624 /*!
5625  * Returns a pointer to the underground DataArrayInt instance and a
5626  * sequence describing parameters of a support of each part of \a this field. The
5627  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5628  * direct access to the field values. This method is intended for the field lying on one
5629  * mesh only.
5630  *  \param [in,out] entries - the sequence describing parameters of a support of each
5631  *         part of \a this field. Each item of this sequence consists of two parts. The
5632  *         first part describes a type of mesh entity and an id of discretization of a
5633  *         current field part. The second part describes a range of values [begin,end)
5634  *         within the returned array relating to the current field part.
5635  *  \return DataArrayInt * - the pointer to the field values array.
5636  *  \throw If the number of underlying meshes is not equal to 1.
5637  *  \throw If no field values are available.
5638  *  \sa getUndergroundDataArray()
5639  */
5640 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5641 {
5642   if(_field_per_mesh.size()!=1)
5643     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5644   if(_field_per_mesh[0]==0)
5645     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5646   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5647   return getUndergroundDataArrayTemplate();
5648 }
5649
5650 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5651 {
5652   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5653   ret->deepCpyLeavesFrom(*this);
5654   return ret.retn();
5655 }
5656
5657 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5658 {
5659   MCAuto<MEDFileIntField1TSWithoutSDA> ret(shallowCpy());
5660   if(_arr.isNotNull())
5661     ret->_arr=_arr->deepCopy();
5662   return ret.retn();
5663 }
5664
5665 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5666 {
5667 }
5668
5669 //= MEDFileAnyTypeField1TS
5670
5671 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5672 {
5673   med_field_type typcha;
5674   //
5675   std::vector<std::string> infos;
5676   std::string dtunit,fieldName;
5677   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
5678   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5679   switch(typcha)
5680   {
5681     case MED_FLOAT64:
5682       {
5683         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5684         break;
5685       }
5686     case MED_INT32:
5687       {
5688         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5689         break;
5690       }
5691     default:
5692       {
5693         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] !";
5694         throw INTERP_KERNEL::Exception(oss.str());
5695       }
5696   }
5697   ret->setDtUnit(dtunit.c_str());
5698   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5699   //
5700   med_int numdt,numit;
5701   med_float dt;
5702   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5703   ret->setTime(numdt,numit,dt);
5704   ret->_csit=1;
5705   if(loadAll)
5706     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5707   else
5708     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5709   return ret.retn();
5710 }
5711
5712 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5713 try:MEDFileFieldGlobsReal(fid)
5714 {
5715   _content=BuildContentFrom(fid,loadAll,ms);
5716   loadGlobals(fid);
5717 }
5718 catch(INTERP_KERNEL::Exception& e)
5719 {
5720     throw e;
5721 }
5722
5723 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5724 {
5725   med_field_type typcha;
5726   std::vector<std::string> infos;
5727   std::string dtunit;
5728   int iii=-1;
5729   int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit);
5730   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5731   switch(typcha)
5732   {
5733     case MED_FLOAT64:
5734       {
5735         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5736         break;
5737       }
5738     case MED_INT32:
5739       {
5740         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5741         break;
5742       }
5743     default:
5744       {
5745         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] !";
5746         throw INTERP_KERNEL::Exception(oss.str());
5747       }
5748   }
5749   ret->setDtUnit(dtunit.c_str());
5750   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5751   //
5752   if(nbSteps<1)
5753     {
5754       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5755       throw INTERP_KERNEL::Exception(oss.str());
5756     }
5757   //
5758   med_int numdt,numit;
5759   med_float dt;
5760   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5761   ret->setTime(numdt,numit,dt);
5762   ret->_csit=1;
5763   if(loadAll)
5764     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5765   else
5766     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5767   return ret.retn();
5768 }
5769
5770 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5771 try:MEDFileFieldGlobsReal(fid)
5772 {
5773   _content=BuildContentFrom(fid,fieldName,loadAll,ms);
5774   loadGlobals(fid);
5775 }
5776 catch(INTERP_KERNEL::Exception& e)
5777 {
5778     throw e;
5779 }
5780
5781 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
5782 {
5783   if(!c)
5784     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5785   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5786     {
5787       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
5788       ret->_content=c; c->incrRef();
5789       return ret.retn();
5790     }
5791   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5792     {
5793       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
5794       ret->_content=c; c->incrRef();
5795       return ret.retn();
5796     }
5797   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5798 }
5799
5800 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
5801 {
5802   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
5803   ret->setFileName(FileNameFromFID(fid));
5804   return ret;
5805 }
5806
5807 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5808 {
5809   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5810   return New(fid,loadAll);
5811 }
5812
5813 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
5814 {
5815   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
5816   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5817   ret->loadGlobals(fid);
5818   return ret.retn();
5819 }
5820
5821 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5822 {
5823   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5824   return New(fid,fieldName,loadAll);
5825 }
5826
5827 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
5828 {
5829   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0));
5830   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5831   ret->loadGlobals(fid);
5832   return ret.retn();
5833 }
5834
5835 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5836 {
5837   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5838   return New(fid,fieldName,iteration,order,loadAll);
5839 }
5840
5841 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
5842 {
5843   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0));
5844   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5845   ret->loadGlobals(fid);
5846   return ret.retn();
5847 }
5848
5849 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5850 {
5851   med_field_type typcha;
5852   std::vector<std::string> infos;
5853   std::string dtunit;
5854   int iii(-1);
5855   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit));
5856   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5857   switch(typcha)
5858   {
5859     case MED_FLOAT64:
5860       {
5861         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5862         break;
5863       }
5864     case MED_INT32:
5865       {
5866         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5867         break;
5868       }
5869     default:
5870       {
5871         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] !";
5872         throw INTERP_KERNEL::Exception(oss.str());
5873       }
5874   }
5875   ret->setDtUnit(dtunit.c_str());
5876   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5877   //
5878   bool found=false;
5879   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5880   for(int i=0;i<nbOfStep2 && !found;i++)
5881     {
5882       med_int numdt,numit;
5883       med_float dt;
5884       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5885       if(numdt==iteration && numit==order)
5886         {
5887           found=true;
5888           ret->_csit=i+1;
5889         }
5890       else
5891         dtits[i]=std::pair<int,int>(numdt,numit);
5892     }
5893   if(!found)
5894     {
5895       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
5896       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5897         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5898       throw INTERP_KERNEL::Exception(oss.str());
5899     }
5900   if(loadAll)
5901     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5902   else
5903     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5904   return ret.retn();
5905 }
5906
5907 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5908 try:MEDFileFieldGlobsReal(fid)
5909 {
5910   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms);
5911   loadGlobals(fid);
5912 }
5913 catch(INTERP_KERNEL::Exception& e)
5914 {
5915     throw e;
5916 }
5917
5918 /*!
5919  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5920  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5921  *
5922  * \warning this is a shallow copy constructor
5923  */
5924 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5925 {
5926   if(!shallowCopyOfContent)
5927     {
5928       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5929       otherPtr->incrRef();
5930       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5931     }
5932   else
5933     {
5934       _content=other.shallowCpy();
5935     }
5936 }
5937
5938 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)
5939 {
5940   if(checkFieldId)
5941     {
5942       int nbFields=MEDnField(fid);
5943       if(fieldIdCFormat>=nbFields)
5944         {
5945           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5946           throw INTERP_KERNEL::Exception(oss.str());
5947         }
5948     }
5949   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5950   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5951   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5952   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5953   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5954   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5955   med_bool localMesh;
5956   int nbOfStep;
5957   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5958   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5959   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5960   infos.clear(); infos.resize(ncomp);
5961   for(int j=0;j<ncomp;j++)
5962     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5963   return nbOfStep;
5964 }
5965
5966 /*!
5967  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5968  * 
5969  * \param [out]
5970  * \return in case of success the number of time steps available for the field with name \a fieldName.
5971  */
5972 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5973 {
5974   int nbFields=MEDnField(fid);
5975   bool found=false;
5976   std::vector<std::string> fns(nbFields);
5977   int nbOfStep2(-1);
5978   for(int i=0;i<nbFields && !found;i++)
5979     {
5980       std::string tmp;
5981       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut);
5982       fns[i]=tmp;
5983       found=(tmp==fieldName);
5984       if(found)
5985         posCFormat=i;
5986     }
5987   if(!found)
5988     {
5989       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
5990       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5991         oss << "\"" << *it << "\" ";
5992       throw INTERP_KERNEL::Exception(oss.str());
5993     }
5994   return nbOfStep2;
5995 }
5996
5997 /*!
5998  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5999  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
6000  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
6001  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
6002  * to keep a valid instance.
6003  * 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.
6004  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
6005  * 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.
6006  *
6007  * \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.
6008  * \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.
6009  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6010  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6011  * \param [in] newLocName is the new localization name.
6012  * \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.
6013  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
6014  */
6015 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
6016 {
6017   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6018   std::string oldPflName=disc->getProfile();
6019   std::vector<std::string> vv=getPflsReallyUsedMulti();
6020   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
6021   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
6022     {
6023       disc->setProfile(newPflName);
6024       DataArrayInt *pfl=getProfile(oldPflName.c_str());
6025       pfl->setName(newPflName);
6026     }
6027   else
6028     {
6029       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
6030       throw INTERP_KERNEL::Exception(oss.str());
6031     }
6032 }
6033
6034 /*!
6035  * This method as MEDFileField1TSW::setProfileNameOnLeaf, 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 localization 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  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
6042  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
6043  * 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.
6044  *
6045  * \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.
6046  * \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.
6047  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
6048  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
6049  * \param [in] newLocName is the new localization name.
6050  * \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.
6051  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
6052  */
6053 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
6054 {
6055   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6056   std::string oldLocName=disc->getLocalization();
6057   std::vector<std::string> vv=getLocsReallyUsedMulti();
6058   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
6059   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
6060     {
6061       disc->setLocalization(newLocName);
6062       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
6063       loc.setName(newLocName);
6064     }
6065   else
6066     {
6067       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
6068       throw INTERP_KERNEL::Exception(oss.str());
6069     }
6070 }
6071
6072 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
6073 {
6074   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6075   if(!ret)
6076     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
6077   return ret;
6078 }
6079
6080 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
6081 {
6082   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
6083   if(!ret)
6084     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
6085   return ret;
6086 }
6087
6088 /*!
6089  * This method alloc the arrays and load potentially huge arrays contained in this field.
6090  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
6091  * This method can be also called to refresh or reinit values from a file.
6092  * 
6093  * \throw If the fileName is not set or points to a non readable MED file.
6094  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6095  */
6096 void MEDFileAnyTypeField1TS::loadArrays()
6097 {
6098   if(getFileName().empty())
6099     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
6100   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6101   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
6102 }
6103
6104 /*!
6105  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
6106  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
6107  * this method does not throw if \a this does not come from file read.
6108  * 
6109  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
6110  */
6111 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
6112 {
6113   if(!getFileName().empty())
6114     {
6115       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
6116       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
6117     }
6118 }
6119
6120 /*!
6121  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
6122  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
6123  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
6124  * 
6125  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
6126  */
6127 void MEDFileAnyTypeField1TS::unloadArrays()
6128 {
6129   contentNotNullBase()->unloadArrays();
6130 }
6131
6132 /*!
6133  * 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.
6134  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
6135  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
6136  * 
6137  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
6138  */
6139 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
6140 {
6141   if(!getFileName().empty())
6142     contentNotNullBase()->unloadArrays();
6143 }
6144
6145 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6146 {
6147   int nbComp(getNumberOfComponents());
6148   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6149   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6150   for(int i=0;i<nbComp;i++)
6151     {
6152       std::string info=getInfo()[i];
6153       std::string c,u;
6154       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6155       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6156       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6157     }
6158   if(getName().empty())
6159     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6160   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6161   writeGlobals(fid,*this);
6162   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6163 }
6164
6165 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6166 {
6167   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6168 }
6169
6170 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6171 {
6172   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6173   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6174   return ret;
6175 }
6176
6177 /*!
6178  * Returns a string describing \a this field. This string is outputted 
6179  * by \c print Python command.
6180  */
6181 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6182 {
6183   std::ostringstream oss;
6184   contentNotNullBase()->simpleRepr(0,oss,-1);
6185   simpleReprGlobs(oss);
6186   return oss.str();
6187 }
6188
6189 /*!
6190  * This method returns all profiles whose name is non empty used.
6191  * \b WARNING If profile is used several times it will be reported \b only \b once.
6192  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6193  */
6194 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6195 {
6196   return contentNotNullBase()->getPflsReallyUsed2();
6197 }
6198
6199 /*!
6200  * This method returns all localizations whose name is non empty used.
6201  * \b WARNING If localization is used several times it will be reported \b only \b once.
6202  */
6203 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6204 {
6205   return contentNotNullBase()->getLocsReallyUsed2();
6206 }
6207
6208 /*!
6209  * This method returns all profiles whose name is non empty used.
6210  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6211  */
6212 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6213 {
6214   return contentNotNullBase()->getPflsReallyUsedMulti2();
6215 }
6216
6217 /*!
6218  * This method returns all localizations whose name is non empty used.
6219  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6220  */
6221 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6222 {
6223   return contentNotNullBase()->getLocsReallyUsedMulti2();
6224 }
6225
6226 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6227 {
6228   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6229 }
6230
6231 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6232 {
6233   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6234 }
6235
6236 int MEDFileAnyTypeField1TS::getDimension() const
6237 {
6238   return contentNotNullBase()->getDimension();
6239 }
6240
6241 int MEDFileAnyTypeField1TS::getIteration() const
6242 {
6243   return contentNotNullBase()->getIteration();
6244 }
6245
6246 int MEDFileAnyTypeField1TS::getOrder() const
6247 {
6248   return contentNotNullBase()->getOrder();
6249 }
6250
6251 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6252 {
6253   return contentNotNullBase()->getTime(iteration,order);
6254 }
6255
6256 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6257 {
6258   contentNotNullBase()->setTime(iteration,order,val);
6259 }
6260
6261 std::string MEDFileAnyTypeField1TS::getName() const
6262 {
6263   return contentNotNullBase()->getName();
6264 }
6265
6266 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6267 {
6268   contentNotNullBase()->setName(name);
6269 }
6270
6271 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6272 {
6273   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6274 }
6275
6276 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6277 {
6278   return contentNotNullBase()->getDtUnit();
6279 }
6280
6281 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6282 {
6283   contentNotNullBase()->setDtUnit(dtUnit);
6284 }
6285
6286 std::string MEDFileAnyTypeField1TS::getMeshName() const
6287 {
6288   return contentNotNullBase()->getMeshName();
6289 }
6290
6291 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6292 {
6293   contentNotNullBase()->setMeshName(newMeshName);
6294 }
6295
6296 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6297 {
6298   return contentNotNullBase()->changeMeshNames(modifTab);
6299 }
6300
6301 int MEDFileAnyTypeField1TS::getMeshIteration() const
6302 {
6303   return contentNotNullBase()->getMeshIteration();
6304 }
6305
6306 int MEDFileAnyTypeField1TS::getMeshOrder() const
6307 {
6308   return contentNotNullBase()->getMeshOrder();
6309 }
6310
6311 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6312 {
6313   return contentNotNullBase()->getNumberOfComponents();
6314 }
6315
6316 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6317 {
6318   return contentNotNullBase()->isDealingTS(iteration,order);
6319 }
6320
6321 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6322 {
6323   return contentNotNullBase()->getDtIt();
6324 }
6325
6326 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6327 {
6328   contentNotNullBase()->fillIteration(p);
6329 }
6330
6331 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6332 {
6333   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6334 }
6335
6336 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6337 {
6338   contentNotNullBase()->setInfo(infos);
6339 }
6340
6341 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6342 {
6343   return contentNotNullBase()->getInfo();
6344 }
6345 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6346 {
6347   return contentNotNullBase()->getInfo();
6348 }
6349
6350 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6351 {
6352   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6353 }
6354
6355 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6356 {
6357   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6358 }
6359
6360 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6361 {
6362   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6363 }
6364
6365 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6366 {
6367   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6368 }
6369
6370 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6371 {
6372   return contentNotNullBase()->getTypesOfFieldAvailable();
6373 }
6374
6375 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,
6376                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6377 {
6378   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6379 }
6380
6381 /*!
6382  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6383  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6384  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6385  */
6386 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6387 {
6388   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6389   if(!content)
6390     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6391   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6392   std::size_t sz(contentsSplit.size());
6393   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6394   for(std::size_t i=0;i<sz;i++)
6395     {
6396       ret[i]=shallowCpy();
6397       ret[i]->_content=contentsSplit[i];
6398     }
6399   return ret;
6400 }
6401
6402 /*!
6403  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6404  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6405  */
6406 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6407 {
6408   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6409   if(!content)
6410     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6411   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6412   std::size_t sz(contentsSplit.size());
6413   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6414   for(std::size_t i=0;i<sz;i++)
6415     {
6416       ret[i]=shallowCpy();
6417       ret[i]->_content=contentsSplit[i];
6418     }
6419   return ret;
6420 }
6421
6422 /*!
6423  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6424  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6425  */
6426 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6427 {
6428   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6429   if(!content)
6430     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6431   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6432   std::size_t sz(contentsSplit.size());
6433   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6434   for(std::size_t i=0;i<sz;i++)
6435     {
6436       ret[i]=shallowCpy();
6437       ret[i]->_content=contentsSplit[i];
6438     }
6439   return ret;
6440 }
6441
6442 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6443 {
6444   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6445   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6446     ret->_content=_content->deepCopy();
6447   ret->deepCpyGlobs(*this);
6448   return ret.retn();
6449 }
6450
6451 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6452 {
6453   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6454 }
6455
6456 //= MEDFileField1TS
6457
6458 /*!
6459  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6460  * the first field that has been read from a specified MED file.
6461  *  \param [in] fileName - the name of the MED file to read.
6462  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6463  *          is to delete this field using decrRef() as it is no more needed.
6464  *  \throw If reading the file fails.
6465  */
6466 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6467 {
6468   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6469   return New(fid,loadAll);
6470 }
6471
6472 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
6473 {
6474   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
6475   ret->contentNotNull();
6476   return ret.retn();
6477 }
6478
6479 /*!
6480  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6481  * a given field that has been read from a specified MED file.
6482  *  \param [in] fileName - the name of the MED file to read.
6483  *  \param [in] fieldName - the name of the field to read.
6484  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6485  *          is to delete this field using decrRef() as it is no more needed.
6486  *  \throw If reading the file fails.
6487  *  \throw If there is no field named \a fieldName in the file.
6488  */
6489 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6490 {
6491   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6492   return New(fid,fieldName,loadAll);
6493 }
6494
6495 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6496 {
6497   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
6498   ret->contentNotNull();
6499   return ret.retn();
6500 }
6501
6502 /*!
6503  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6504  * a given field that has been read from a specified MED file.
6505  *  \param [in] fileName - the name of the MED file to read.
6506  *  \param [in] fieldName - the name of the field to read.
6507  *  \param [in] iteration - the iteration number of a required time step.
6508  *  \param [in] order - the iteration order number of required time step.
6509  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6510  *          is to delete this field using decrRef() as it is no more needed.
6511  *  \throw If reading the file fails.
6512  *  \throw If there is no field named \a fieldName in the file.
6513  *  \throw If the required time step is missing from the file.
6514  */
6515 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6516 {
6517   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6518   return New(fid,fieldName,iteration,order,loadAll);
6519 }
6520
6521 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6522 {
6523   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
6524   ret->contentNotNull();
6525   return ret.retn();
6526 }
6527
6528 /*!
6529  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6530  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6531  *
6532  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6533  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6534  * \warning this is a shallow copy constructor
6535  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6536  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6537  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6538  *          is to delete this field using decrRef() as it is no more needed.
6539  */
6540 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6541 {
6542   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6543   ret->contentNotNull();
6544   return ret.retn();
6545 }
6546
6547 /*!
6548  * Returns a new empty instance of MEDFileField1TS.
6549  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6550  *          is to delete this field using decrRef() as it is no more needed.
6551  */
6552 MEDFileField1TS *MEDFileField1TS::New()
6553 {
6554   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6555   ret->contentNotNull();
6556   return ret.retn();
6557 }
6558
6559 /*!
6560  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6561  * following the given input policy.
6562  *
6563  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6564  *                            By default (true) the globals are deeply copied.
6565  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6566  */
6567 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6568 {
6569   MCAuto<MEDFileIntField1TS> ret;
6570   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6571   if(content)
6572     {
6573       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6574       if(!contc)
6575         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6576       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6577       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6578     }
6579   else
6580     ret=MEDFileIntField1TS::New();
6581   if(isDeepCpyGlobs)
6582     ret->deepCpyGlobs(*this);
6583   else
6584     ret->shallowCpyGlobs(*this);
6585   return ret.retn();
6586 }
6587
6588 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6589 {
6590   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6591   if(!pt)
6592     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6593   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6594   if(!ret)
6595     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 !");
6596   return ret;
6597 }
6598
6599 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6600 {
6601   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6602   if(!pt)
6603     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6604   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6605   if(!ret)
6606     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 !");
6607   return ret;
6608 }
6609
6610 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6611 {
6612   if(!f)
6613     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6614   if(arr.isNull())
6615     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6616   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6617   if(!arrOutC)
6618     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6619   f->setArray(arrOutC);
6620 }
6621
6622 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6623 {
6624   if(arr.isNull())
6625     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6626   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6627   if(!arrOutC)
6628     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6629   arrOutC->incrRef();
6630   return arrOutC;
6631 }
6632
6633 /*!
6634  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6635  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6636  *
6637  * \return A new object that the caller is responsible to deallocate.
6638  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6639  */
6640 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6641 {
6642   if(!mm)
6643     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6644   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6645   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6646   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6647     {
6648       if((*it0)!=ON_NODES)
6649         {
6650           std::vector<int> levs;
6651           getNonEmptyLevels(mm->getName(),levs);
6652           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6653             {
6654               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6655               if(it2!=extractDef.end())
6656                 {
6657                   MCAuto<DataArrayInt> t((*it2).second);
6658                   if(t.isNull())
6659                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6660                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6661                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6662                   ret->setFieldNoProfileSBT(fOut);
6663                 }
6664             }
6665         }
6666       else
6667         {
6668           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6669           if(it2==extractDef.end())
6670             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6671           MCAuto<DataArrayInt> t((*it2).second);
6672           if(t.isNull())
6673             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6674           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6675           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6676           DataArrayDouble *arr(f->getArray());
6677           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6678           fOut->setArray(newArr);
6679           ret->setFieldNoProfileSBT(fOut);
6680         }
6681     }
6682   return ret.retn();
6683 }
6684
6685 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6686 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6687 {
6688 }
6689 catch(INTERP_KERNEL::Exception& e)
6690 { throw e; }
6691
6692 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6693 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6694 {
6695 }
6696 catch(INTERP_KERNEL::Exception& e)
6697 { throw e; }
6698
6699 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6700 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6701 {
6702 }
6703 catch(INTERP_KERNEL::Exception& e)
6704 { throw e; }
6705
6706 /*!
6707  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6708  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6709  *
6710  * \warning this is a shallow copy constructor
6711  */
6712 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6713 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6714 {
6715 }
6716 catch(INTERP_KERNEL::Exception& e)
6717 { throw e; }
6718
6719 MEDFileField1TS::MEDFileField1TS()
6720 {
6721   _content=new MEDFileField1TSWithoutSDA;
6722 }
6723
6724 /*!
6725  * 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
6726  * method should be called (getFieldOnMeshAtLevel for example).
6727  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6728  *
6729  * \param [in] mesh - the mesh the field is lying on
6730  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6731  *          caller is to delete this field using decrRef() as it is no more needed. 
6732  */
6733 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6734 {
6735   MCAuto<DataArray> arrOut;
6736   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6737   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6738   return ret.retn();
6739 }
6740
6741 /*!
6742  * Returns a new MEDCouplingFieldDouble of a given type lying on
6743  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6744  * has not been constructed via file reading, an exception is thrown.
6745  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6746  *  \param [in] type - a spatial discretization of interest.
6747  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6748  *  \param [in] renumPol - specifies how to permute values of the result field according to
6749  *          the optional numbers of cells and nodes, if any. The valid values are
6750  *          - 0 - do not permute.
6751  *          - 1 - permute cells.
6752  *          - 2 - permute nodes.
6753  *          - 3 - permute cells and nodes.
6754  *
6755  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6756  *          caller is to delete this field using decrRef() as it is no more needed. 
6757  *  \throw If \a this field has not been constructed via file reading.
6758  *  \throw If the MED file is not readable.
6759  *  \throw If there is no mesh in the MED file.
6760  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6761  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6762  *  \sa getFieldOnMeshAtLevel()
6763  */
6764 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6765 {
6766   if(getFileName().empty())
6767     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6768   MCAuto<DataArray> arrOut;
6769   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6770   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6771   return ret.retn();
6772 }
6773
6774 /*!
6775  * Returns a new MEDCouplingFieldDouble of a given type lying on
6776  * the top level cells of the first mesh in MED file. If \a this field 
6777  * has not been constructed via file reading, an exception is thrown.
6778  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6779  *  \param [in] type - a spatial discretization of interest.
6780  *  \param [in] renumPol - specifies how to permute values of the result field according to
6781  *          the optional numbers of cells and nodes, if any. The valid values are
6782  *          - 0 - do not permute.
6783  *          - 1 - permute cells.
6784  *          - 2 - permute nodes.
6785  *          - 3 - permute cells and nodes.
6786  *
6787  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6788  *          caller is to delete this field using decrRef() as it is no more needed. 
6789  *  \throw If \a this field has not been constructed via file reading.
6790  *  \throw If the MED file is not readable.
6791  *  \throw If there is no mesh in the MED file.
6792  *  \throw If no field values of the given \a type.
6793  *  \throw If no field values lying on the top level support.
6794  *  \sa getFieldAtLevel()
6795  */
6796 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6797 {
6798   if(getFileName().empty())
6799     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6800   MCAuto<DataArray> arrOut;
6801   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6802   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6803   return ret.retn();
6804 }
6805
6806 /*!
6807  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6808  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6809  *  \param [in] type - a spatial discretization of the new field.
6810  *  \param [in] mesh - the supporting mesh.
6811  *  \param [in] renumPol - specifies how to permute values of the result field according to
6812  *          the optional numbers of cells and nodes, if any. The valid values are
6813  *          - 0 - do not permute.
6814  *          - 1 - permute cells.
6815  *          - 2 - permute nodes.
6816  *          - 3 - permute cells and nodes.
6817  *
6818  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6819  *          caller is to delete this field using decrRef() as it is no more needed. 
6820  *  \throw If no field of \a this is lying on \a mesh.
6821  *  \throw If the mesh is empty.
6822  *  \throw If no field values of the given \a type are available.
6823  *  \sa getFieldAtLevel()
6824  *  \sa getFieldOnMeshAtLevel() 
6825  */
6826 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6827 {
6828   MCAuto<DataArray> arrOut;
6829   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
6830   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6831   return ret.retn();
6832 }
6833
6834 /*!
6835  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6836  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6837  *  \param [in] type - a spatial discretization of interest.
6838  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6839  *  \param [in] mesh - the supporting mesh.
6840  *  \param [in] renumPol - specifies how to permute values of the result field according to
6841  *          the optional numbers of cells and nodes, if any. The valid values are
6842  *          - 0 - do not permute.
6843  *          - 1 - permute cells.
6844  *          - 2 - permute nodes.
6845  *          - 3 - permute cells and nodes.
6846  *
6847  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6848  *          caller is to delete this field using decrRef() as it is no more needed. 
6849  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6850  *  \throw If no field of \a this is lying on \a mesh.
6851  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6852  *  \sa getFieldAtLevel()
6853  *  \sa getFieldOnMeshAtLevel() 
6854  */
6855 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6856 {
6857   MCAuto<DataArray> arrOut;
6858   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
6859   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6860   return ret.retn();
6861 }
6862
6863 /*!
6864  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6865  * This method is called "Old" because in MED3 norm a field has only one meshName
6866  * attached, so this method is for readers of MED2 files. If \a this field 
6867  * has not been constructed via file reading, an exception is thrown.
6868  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6869  *  \param [in] type - a spatial discretization of interest.
6870  *  \param [in] mName - a name of the supporting mesh.
6871  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6872  *  \param [in] renumPol - specifies how to permute values of the result field according to
6873  *          the optional numbers of cells and nodes, if any. The valid values are
6874  *          - 0 - do not permute.
6875  *          - 1 - permute cells.
6876  *          - 2 - permute nodes.
6877  *          - 3 - permute cells and nodes.
6878  *
6879  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6880  *          caller is to delete this field using decrRef() as it is no more needed. 
6881  *  \throw If the MED file is not readable.
6882  *  \throw If there is no mesh named \a mName in the MED file.
6883  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6884  *  \throw If \a this field has not been constructed via file reading.
6885  *  \throw If no field of \a this is lying on the mesh named \a mName.
6886  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6887  *  \sa getFieldAtLevel()
6888  */
6889 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6890 {
6891   if(getFileName().empty())
6892     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6893   MCAuto<DataArray> arrOut;
6894   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
6895   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6896   return ret.retn();
6897 }
6898
6899 /*!
6900  * Returns values and a profile of the field of a given type lying on a given support.
6901  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6902  *  \param [in] type - a spatial discretization of the field.
6903  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6904  *  \param [in] mesh - the supporting mesh.
6905  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6906  *          field of interest lies on. If the field lies on all entities of the given
6907  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6908  *          using decrRef() as it is no more needed.  
6909  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6910  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6911  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6912  *  \throw If no field of \a this is lying on \a mesh.
6913  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6914  */
6915 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6916 {
6917   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6918   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6919 }
6920
6921 /*!
6922  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6923  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6924  * "Sort By Type"), if not, an exception is thrown. 
6925  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6926  *  \param [in] field - the field to add to \a this.
6927  *  \throw If the name of \a field is empty.
6928  *  \throw If the data array of \a field is not set.
6929  *  \throw If the data array is already allocated but has different number of components
6930  *         than \a field.
6931  *  \throw If the underlying mesh of \a field has no name.
6932  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6933  */
6934 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6935 {
6936   setFileName("");
6937   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6938 }
6939
6940 /*!
6941  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6942  * can be an aggregation of several MEDCouplingFieldDouble instances.
6943  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6944  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6945  * and \a profile.
6946  *
6947  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6948  * A new profile is added only if no equal profile is missing.
6949  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6950  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6951  *  \param [in] mesh - the supporting mesh of \a field.
6952  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6953  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6954  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6955  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6956  *  \throw If the data array of \a field is not set.
6957  *  \throw If the data array of \a this is already allocated but has different number of
6958  *         components than \a field.
6959  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6960  *  \sa setFieldNoProfileSBT()
6961  */
6962 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6963 {
6964   setFileName("");
6965   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6966 }
6967
6968 MEDFileField1TS *MEDFileField1TS::shallowCpy() const
6969 {
6970   return new MEDFileField1TS(*this);
6971 }
6972
6973 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6974 {
6975   return contentNotNull()->getUndergroundDataArrayTemplate();
6976 }
6977
6978 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6979 {
6980   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6981 }
6982
6983 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6984                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6985 {
6986   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6987 }
6988
6989 //= MEDFileIntField1TS
6990
6991 MEDFileIntField1TS *MEDFileIntField1TS::New()
6992 {
6993   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
6994   ret->contentNotNull();
6995   return ret.retn();
6996 }
6997
6998 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6999 {
7000   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7001   return MEDFileIntField1TS::New(fid,loadAll);
7002 }
7003
7004 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
7005 {
7006   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
7007   ret->contentNotNull();
7008   return ret.retn();
7009 }
7010
7011 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
7012 {
7013   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7014   return MEDFileIntField1TS::New(fid,fieldName,loadAll);
7015 }
7016
7017 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
7018 {
7019   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
7020   ret->contentNotNull();
7021   return ret.retn();
7022 }
7023
7024 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
7025 {
7026   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
7027   return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
7028 }
7029
7030 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
7031 {
7032   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
7033   ret->contentNotNull();
7034   return ret.retn();
7035 }
7036
7037 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
7038 {
7039   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
7040   ret->contentNotNull();
7041   return ret.retn();
7042 }
7043
7044 MEDFileIntField1TS::MEDFileIntField1TS()
7045 {
7046   _content=new MEDFileIntField1TSWithoutSDA;
7047 }
7048
7049 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
7050 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
7051 {
7052 }
7053 catch(INTERP_KERNEL::Exception& e)
7054 { throw e; }
7055
7056 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
7057 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
7058 {
7059 }
7060 catch(INTERP_KERNEL::Exception& e)
7061 { throw e; }
7062
7063 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
7064 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
7065 {
7066 }
7067 catch(INTERP_KERNEL::Exception& e)
7068 { throw e; }
7069
7070 /*!
7071  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
7072  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
7073  *
7074  * \warning this is a shallow copy constructor
7075  */
7076 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
7077 {
7078 }
7079
7080 MEDFileIntField1TS *MEDFileIntField1TS::shallowCpy() const
7081 {
7082   return new MEDFileIntField1TS(*this);
7083 }
7084
7085 /*!
7086  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
7087  * following the given input policy.
7088  *
7089  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
7090  *                            By default (true) the globals are deeply copied.
7091  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
7092  */
7093 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
7094 {
7095   MCAuto<MEDFileField1TS> ret;
7096   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
7097   if(content)
7098     {
7099       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
7100       if(!contc)
7101         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
7102       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
7103       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
7104     }
7105   else
7106     ret=MEDFileField1TS::New();
7107   if(isDeepCpyGlobs)
7108     ret->deepCpyGlobs(*this);
7109   else
7110     ret->shallowCpyGlobs(*this);
7111   return ret.retn();
7112 }
7113
7114 /*!
7115  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
7116  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
7117  * "Sort By Type"), if not, an exception is thrown. 
7118  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7119  *  \param [in] field - the field to add to \a this.
7120  *  \throw If the name of \a field is empty.
7121  *  \throw If the data array of \a field is not set.
7122  *  \throw If the data array is already allocated but has different number of components
7123  *         than \a field.
7124  *  \throw If the underlying mesh of \a field has no name.
7125  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
7126  */
7127 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
7128 {
7129   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7130   setFileName("");
7131   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
7132 }
7133
7134 /*!
7135  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
7136  * can be an aggregation of several MEDCouplingFieldDouble instances.
7137  * The mesh support of input parameter \a field is ignored here, it can be NULL.
7138  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
7139  * and \a profile.
7140  *
7141  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
7142  * A new profile is added only if no equal profile is missing.
7143  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7144  *  \param [in] field - the field to add to \a this.
7145  *  \param [in] mesh - the supporting mesh of \a field.
7146  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7147  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7148  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7149  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7150  *  \throw If the data array of \a field is not set.
7151  *  \throw If the data array of \a this is already allocated but has different number of
7152  *         components than \a field.
7153  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7154  *  \sa setFieldNoProfileSBT()
7155  */
7156 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7157 {
7158   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7159   setFileName("");
7160   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7161 }
7162
7163 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
7164 {
7165   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7166   if(!pt)
7167     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
7168   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
7169   if(!ret)
7170     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 !");
7171   return ret;
7172 }
7173
7174 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7175 {
7176   if(getFileName().empty())
7177     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7178   MCAuto<DataArray> arrOut;
7179   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7180   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7181   return ret2.retn();
7182 }
7183
7184 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
7185 {
7186   if(arr.isNull())
7187     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
7188   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
7189   if(!arrC)
7190     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
7191   arrC->incrRef();
7192   return arrC;
7193 }
7194
7195 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
7196 {
7197   int t1,t2;
7198   double t0(f->getTime(t1,t2));
7199   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
7200   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7201   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
7202   ret->setTime(t0,t1,t2); ret->setArray(arr2);
7203   return ret.retn();
7204 }
7205
7206 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
7207 {
7208   if(!f)
7209     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
7210   int t1,t2;
7211   double t0(f->getTime(t1,t2));
7212   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7213   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
7214   ret->setTime(t0,t1,t2);
7215   return ret;
7216 }
7217
7218 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
7219 {
7220   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
7221 }
7222
7223 /*!
7224  * 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
7225  * method should be called (getFieldOnMeshAtLevel for example).
7226  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
7227  *
7228  * \param [in] mesh - the mesh the field is lying on
7229  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
7230  *          caller is to delete this field using decrRef() as it is no more needed. 
7231  */
7232 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
7233 {
7234   MCAuto<DataArray> arrOut;
7235   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
7236   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7237   return ret2.retn();
7238 }
7239
7240 /*!
7241  * Returns a new MEDCouplingFieldInt of a given type lying on
7242  * the top level cells of the first mesh in MED file. If \a this field 
7243  * has not been constructed via file reading, an exception is thrown.
7244  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7245  *  \param [in] type - a spatial discretization of interest.
7246  *  \param [in] renumPol - specifies how to permute values of the result field according to
7247  *          the optional numbers of cells and nodes, if any. The valid values are
7248  *          - 0 - do not permute.
7249  *          - 1 - permute cells.
7250  *          - 2 - permute nodes.
7251  *          - 3 - permute cells and nodes.
7252  *
7253  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7254  *          caller is to delete this field using decrRef() as it is no more needed. 
7255  *  \throw If \a this field has not been constructed via file reading.
7256  *  \throw If the MED file is not readable.
7257  *  \throw If there is no mesh in the MED file.
7258  *  \throw If no field values of the given \a type.
7259  *  \throw If no field values lying on the top level support.
7260  *  \sa getFieldAtLevel()
7261  */
7262 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7263 {
7264   if(getFileName().empty())
7265     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7266   MCAuto<DataArray> arrOut;
7267   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7268   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7269   return ret2.retn();
7270 }
7271
7272 /*!
7273  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
7274  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7275  *  \param [in] type - a spatial discretization of the new field.
7276  *  \param [in] mesh - the supporting mesh.
7277  *  \param [in] renumPol - specifies how to permute values of the result field according to
7278  *          the optional numbers of cells and nodes, if any. The valid values are
7279  *          - 0 - do not permute.
7280  *          - 1 - permute cells.
7281  *          - 2 - permute nodes.
7282  *          - 3 - permute cells and nodes.
7283  *
7284  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7285  *          caller is to delete this field using decrRef() as it is no more needed. 
7286  *  \throw If no field of \a this is lying on \a mesh.
7287  *  \throw If the mesh is empty.
7288  *  \throw If no field values of the given \a type are available.
7289  *  \sa getFieldAtLevel()
7290  *  \sa getFieldOnMeshAtLevel() 
7291  */
7292 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7293 {
7294   MCAuto<DataArray> arrOut;
7295   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7296   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7297   return ret2.retn();
7298 }
7299
7300 /*!
7301  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7302  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7303  *  \param [in] type - a spatial discretization of interest.
7304  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7305  *  \param [in] mesh - the supporting mesh.
7306  *  \param [in] renumPol - specifies how to permute values of the result field according to
7307  *          the optional numbers of cells and nodes, if any. The valid values are
7308  *          - 0 - do not permute.
7309  *          - 1 - permute cells.
7310  *          - 2 - permute nodes.
7311  *          - 3 - permute cells and nodes.
7312  *
7313  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7314  *          caller is to delete this field using decrRef() as it is no more needed. 
7315  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7316  *  \throw If no field of \a this is lying on \a mesh.
7317  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7318  *  \sa getFieldAtLevel()
7319  *  \sa getFieldOnMeshAtLevel() 
7320  */
7321 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7322 {
7323   MCAuto<DataArray> arrOut;
7324   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7325   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7326   return ret2.retn();
7327 }
7328
7329 /*!
7330  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7331  * This method is called "Old" because in MED3 norm a field has only one meshName
7332  * attached, so this method is for readers of MED2 files. If \a this field 
7333  * has not been constructed via file reading, an exception is thrown.
7334  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7335  *  \param [in] type - a spatial discretization of interest.
7336  *  \param [in] mName - a name of the supporting mesh.
7337  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7338  *  \param [in] renumPol - specifies how to permute values of the result field according to
7339  *          the optional numbers of cells and nodes, if any. The valid values are
7340  *          - 0 - do not permute.
7341  *          - 1 - permute cells.
7342  *          - 2 - permute nodes.
7343  *          - 3 - permute cells and nodes.
7344  *
7345  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7346  *          caller is to delete this field using decrRef() as it is no more needed. 
7347  *  \throw If the MED file is not readable.
7348  *  \throw If there is no mesh named \a mName in the MED file.
7349  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7350  *  \throw If \a this field has not been constructed via file reading.
7351  *  \throw If no field of \a this is lying on the mesh named \a mName.
7352  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7353  *  \sa getFieldAtLevel()
7354  */
7355 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7356 {
7357   if(getFileName().empty())
7358     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7359   MCAuto<DataArray> arrOut;
7360   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7361   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7362   return ret2.retn();
7363 }
7364
7365 /*!
7366  * Returns values and a profile of the field of a given type lying on a given support.
7367  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7368  *  \param [in] type - a spatial discretization of the field.
7369  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7370  *  \param [in] mesh - the supporting mesh.
7371  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7372  *          field of interest lies on. If the field lies on all entities of the given
7373  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7374  *          using decrRef() as it is no more needed.  
7375  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7376  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7377  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7378  *  \throw If no field of \a this is lying on \a mesh.
7379  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7380  */
7381 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7382 {
7383   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7384   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7385 }
7386
7387 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7388 {
7389   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7390   if(!pt)
7391     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7392   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7393   if(!ret)
7394     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 !");
7395   return ret;
7396 }
7397
7398 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7399 {
7400   return contentNotNull()->getUndergroundDataArrayTemplate();
7401 }
7402
7403 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7404
7405 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7406 {
7407 }
7408
7409 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7410 {
7411 }
7412
7413 /*!
7414  * \param [in] fieldId field id in C mode
7415  */
7416 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7417 {
7418   med_field_type typcha;
7419   std::string dtunitOut;
7420   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut));
7421   setDtUnit(dtunitOut.c_str());
7422   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7423 }
7424
7425 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)
7426 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7427 {
7428   setDtUnit(dtunit.c_str());
7429   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7430 }
7431 catch(INTERP_KERNEL::Exception& e)
7432 {
7433     throw e;
7434 }
7435
7436 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7437 {
7438   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7439   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7440     ret+=(*it).capacity();
7441   return ret;
7442 }
7443
7444 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7445 {
7446   std::vector<const BigMemoryObject *> ret;
7447   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7448     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7449   return ret;
7450 }
7451
7452 /*!
7453  * 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
7454  * NULL.
7455  */
7456 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7457 {
7458   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7459   ret->setInfo(_infos);
7460   int sz=(int)_time_steps.size();
7461   for(const int *id=startIds;id!=endIds;id++)
7462     {
7463       if(*id>=0 && *id<sz)
7464         {
7465           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7466           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7467           if(tse)
7468             {
7469               tse->incrRef();
7470               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7471             }
7472           ret->pushBackTimeStep(tse2);
7473         }
7474       else
7475         {
7476           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7477           oss << " ! Should be in [0," << sz << ") !";
7478           throw INTERP_KERNEL::Exception(oss.str());
7479         }
7480     }
7481   if(ret->getNumberOfTS()>0)
7482     ret->synchronizeNameScope();
7483   ret->copyNameScope(*this);
7484   return ret.retn();
7485 }
7486
7487 /*!
7488  * 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
7489  * NULL.
7490  */
7491 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7492 {
7493   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7494   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7495   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7496   ret->setInfo(_infos);
7497   int sz=(int)_time_steps.size();
7498   int j=bg;
7499   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7500     {
7501       if(j>=0 && j<sz)
7502         {
7503           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7504           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7505           if(tse)
7506             {
7507               tse->incrRef();
7508               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7509             }
7510           ret->pushBackTimeStep(tse2);
7511         }
7512       else
7513         {
7514           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7515           oss << " ! Should be in [0," << sz << ") !";
7516           throw INTERP_KERNEL::Exception(oss.str());
7517         }
7518     }
7519   if(ret->getNumberOfTS()>0)
7520     ret->synchronizeNameScope();
7521   ret->copyNameScope(*this);
7522   return ret.retn();
7523 }
7524
7525 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7526 {
7527   int id=0;
7528   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7529   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7530     {
7531       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7532       if(!cur)
7533         continue;
7534       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7535       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7536         ids->pushBackSilent(id);
7537     }
7538   return buildFromTimeStepIds(ids->begin(),ids->end());
7539 }
7540
7541 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7542 {
7543   int id=0;
7544   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7545   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7546     {
7547       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7548       if(!cur)
7549         continue;
7550       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7551       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7552         ids->pushBackSilent(id);
7553     }
7554   return buildFromTimeStepIds(ids->begin(),ids->end());
7555 }
7556
7557 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const
7558 {
7559   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7560     if((*it).isNotNull())
7561       if((*it)->presenceOfStructureElements())
7562         return true;
7563   return false;
7564 }
7565
7566 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const
7567 {
7568   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7569     if((*it).isNotNull())
7570       if(!(*it)->onlyStructureElements())
7571         return false;
7572   return true;
7573 }
7574
7575 void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements()
7576 {
7577   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7578   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7579     if((*it).isNotNull())
7580       {
7581         if((*it)->presenceOfStructureElements())
7582           {
7583             if(!(*it)->onlyStructureElements())
7584               {
7585                 (*it)->killStructureElements();
7586                 ret.push_back(*it);
7587               }
7588           }
7589         else
7590           {
7591             ret.push_back(*it);
7592           }
7593       }
7594   _time_steps=ret;
7595 }
7596
7597 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements()
7598 {
7599   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7600   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7601     if((*it).isNotNull())
7602       {
7603         if((*it)->presenceOfStructureElements())
7604           {
7605             if(!(*it)->onlyStructureElements())
7606               (*it)->keepOnlyStructureElements();
7607             ret.push_back(*it);
7608           }
7609       }
7610   _time_steps=ret;
7611 }
7612
7613 void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName)
7614 {
7615   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret;
7616   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7617     if((*it).isNotNull())
7618       (*it)->keepOnlyOnSE(seName);
7619 }
7620
7621 void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
7622 {
7623   std::vector< std::pair<std::string,std::string> > ps2;
7624   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7625     if((*it).isNotNull())
7626       {
7627         (*it)->getMeshSENames(ps2);
7628         break;
7629       }
7630   if(ps2.empty())
7631     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !");
7632   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7633     if((*it).isNotNull())
7634       {
7635         std::vector< std::pair<std::string,std::string> > ps3;
7636         (*it)->getMeshSENames(ps3);
7637         if(ps2!=ps3)
7638           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !");
7639       }
7640   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=ps2.begin();it!=ps2.end();it++)
7641     {
7642       std::vector< std::pair<std::string,std::string> >::iterator it2(std::find(ps.begin(),ps.end(),*it));
7643       if(it2==ps.end())
7644         ps.push_back(*it);
7645     }
7646 }
7647
7648 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7649 {
7650   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7651     {
7652       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7653       if(!cur)
7654         continue;
7655       if(cur->presenceOfMultiDiscPerGeoType())
7656         return true;
7657     }
7658   return false;
7659 }
7660
7661 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7662 {
7663   return _infos;
7664 }
7665
7666 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7667 {
7668   _infos=info;
7669 }
7670
7671 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7672 {
7673   int ret=0;
7674   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7675     {
7676       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7677       if(pt->isDealingTS(iteration,order))
7678         return ret;
7679     }
7680   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7681   std::vector< std::pair<int,int> > vp=getIterations();
7682   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7683     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7684   throw INTERP_KERNEL::Exception(oss.str());
7685 }
7686
7687 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7688 {
7689   return *_time_steps[getTimeStepPos(iteration,order)];
7690 }
7691
7692 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7693 {
7694   return *_time_steps[getTimeStepPos(iteration,order)];
7695 }
7696
7697 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7698 {
7699   if(_time_steps.empty())
7700     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7701   return _time_steps[0]->getMeshName();
7702 }
7703
7704 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7705 {
7706   std::string oldName(getMeshName());
7707   std::vector< std::pair<std::string,std::string> > v(1);
7708   v[0].first=oldName; v[0].second=newMeshName;
7709   changeMeshNames(v);
7710 }
7711
7712 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7713 {
7714   bool ret=false;
7715   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7716     {
7717       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7718       if(cur)
7719         ret=cur->changeMeshNames(modifTab) || ret;
7720     }
7721   return ret;
7722 }
7723
7724 /*!
7725  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7726  */
7727 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7728 {
7729   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7730 }
7731
7732 /*!
7733  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7734  */
7735 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7736 {
7737   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7738 }
7739
7740 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7741                                                                        MEDFileFieldGlobsReal& glob)
7742 {
7743   bool ret=false;
7744   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7745     {
7746       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7747       if(f1ts)
7748         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7749     }
7750   return ret;
7751 }
7752
7753 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7754 {
7755   std::string startLine(bkOffset,' ');
7756   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7757   if(fmtsId>=0)
7758     oss << " (" << fmtsId << ")";
7759   oss << " has the following name: \"" << _name << "\"." << std::endl;
7760   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7761   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7762     {
7763       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7764     }
7765   int i=0;
7766   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7767     {
7768       std::string chapter(17,'0'+i);
7769       oss << startLine << chapter << std::endl;
7770       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7771       if(cur)
7772         cur->simpleRepr(bkOffset+2,oss,i);
7773       else
7774         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7775       oss << startLine << chapter << std::endl;
7776     }
7777 }
7778
7779 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7780 {
7781   std::size_t sz=_time_steps.size();
7782   std::vector< std::pair<int,int> > ret(sz);
7783   ret1.resize(sz);
7784   for(std::size_t i=0;i<sz;i++)
7785     {
7786       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7787       if(f1ts)
7788         {
7789           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7790         }
7791       else
7792         {
7793           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7794           throw INTERP_KERNEL::Exception(oss.str());
7795         }
7796     }
7797   return ret;
7798 }
7799
7800 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7801 {
7802   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7803   if(!tse2)
7804     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7805   checkCoherencyOfType(tse2);
7806   if(_time_steps.empty())
7807     {
7808       setName(tse2->getName().c_str());
7809       setInfo(tse2->getInfo());
7810     }
7811   checkThatComponentsMatch(tse2->getInfo());
7812   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7813     setDtUnit(tse->getDtUnit());
7814   _time_steps.push_back(tse);
7815 }
7816
7817 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7818 {
7819   std::size_t nbOfCompo=_infos.size();
7820   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7821     {
7822       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7823       if(cur)
7824         {
7825           if((cur->getInfo()).size()!=nbOfCompo)
7826             {
7827               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7828               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7829               throw INTERP_KERNEL::Exception(oss.str());
7830             }
7831           cur->copyNameScope(*this);
7832         }
7833     }
7834 }
7835
7836 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7837 {
7838   _time_steps.resize(nbPdt);
7839   for(int i=0;i<nbPdt;i++)
7840     {
7841       std::vector< std::pair<int,int> > ts;
7842       med_int numdt=0,numo=0;
7843       med_float dt=0.0;
7844       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7845       switch(fieldTyp)
7846       {
7847         case MED_FLOAT64:
7848           {
7849             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7850             break;
7851           }
7852         case MED_INT32:
7853           {
7854             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7855             break;
7856           }
7857         default:
7858           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7859       }
7860       if(loadAll)
7861         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7862       else
7863         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7864       synchronizeNameScope();
7865     }
7866 }
7867
7868 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7869 {
7870   if(_time_steps.empty())
7871     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7872   checkThatNbOfCompoOfTSMatchThis();
7873   std::vector<std::string> infos(getInfo());
7874   int nbComp=infos.size();
7875   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7876   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7877   for(int i=0;i<nbComp;i++)
7878     {
7879       std::string info=infos[i];
7880       std::string c,u;
7881       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7882       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7883       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7884     }
7885   if(_name.empty())
7886     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7887   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7888   int nbOfTS=_time_steps.size();
7889   for(int i=0;i<nbOfTS;i++)
7890     _time_steps[i]->writeLL(fid,opts,*this);
7891 }
7892
7893 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7894 {
7895   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7896     {
7897       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7898       if(elt)
7899         elt->loadBigArraysRecursively(fid,nasc);
7900     }
7901 }
7902
7903 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7904 {
7905   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7906     {
7907       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7908       if(elt)
7909         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7910     }
7911 }
7912
7913 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7914 {
7915   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7916     {
7917       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7918       if(elt)
7919         elt->unloadArrays();
7920     }
7921 }
7922
7923 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7924 {
7925   return _time_steps.size();
7926 }
7927
7928 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7929 {
7930   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7931   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7932     {
7933       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7934       if(tmp)
7935         newTS.push_back(*it);
7936     }
7937   _time_steps=newTS;
7938 }
7939
7940 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7941 {
7942   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7943   int maxId=(int)_time_steps.size();
7944   int ii=0;
7945   std::set<int> idsToDel;
7946   for(const int *id=startIds;id!=endIds;id++,ii++)
7947     {
7948       if(*id>=0 && *id<maxId)
7949         {
7950           idsToDel.insert(*id);
7951         }
7952       else
7953         {
7954           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7955           throw INTERP_KERNEL::Exception(oss.str());
7956         }
7957     }
7958   for(int iii=0;iii<maxId;iii++)
7959     if(idsToDel.find(iii)==idsToDel.end())
7960       newTS.push_back(_time_steps[iii]);
7961   _time_steps=newTS;
7962 }
7963
7964 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7965 {
7966   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7967   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7968   if(nbOfEntriesToKill==0)
7969     return ;
7970   std::size_t sz=_time_steps.size();
7971   std::vector<bool> b(sz,true);
7972   int j=bg;
7973   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7974     b[j]=false;
7975   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7976   for(std::size_t i=0;i<sz;i++)
7977     if(b[i])
7978       newTS.push_back(_time_steps[i]);
7979   _time_steps=newTS;
7980 }
7981
7982 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7983 {
7984   int ret=0;
7985   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7986   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7987     {
7988       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7989       if(tmp)
7990         {
7991           int it2,ord;
7992           tmp->getTime(it2,ord);
7993           if(it2==iteration && order==ord)
7994             return ret;
7995           else
7996             oss << "(" << it2 << ","  << ord << "), ";
7997         }
7998     }
7999   throw INTERP_KERNEL::Exception(oss.str());
8000 }
8001
8002 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
8003 {
8004   int ret=0;
8005   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
8006   oss.precision(15);
8007   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
8008     {
8009       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
8010       if(tmp)
8011         {
8012           int it2,ord;
8013           double ti=tmp->getTime(it2,ord);
8014           if(fabs(time-ti)<eps)
8015             return ret;
8016           else
8017             oss << ti << ", ";
8018         }
8019     }
8020   throw INTERP_KERNEL::Exception(oss.str());
8021 }
8022
8023 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
8024 {
8025   int lgth=_time_steps.size();
8026   std::vector< std::pair<int,int> > ret(lgth);
8027   for(int i=0;i<lgth;i++)
8028     _time_steps[i]->fillIteration(ret[i]);
8029   return ret;
8030 }
8031
8032 /*!
8033  * 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'
8034  * This method returns two things.
8035  * - The absolute dimension of 'this' in first parameter. 
8036  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
8037  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
8038  *
8039  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
8040  * Only these 3 discretizations will be taken into account here.
8041  *
8042  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
8043  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
8044  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
8045  *
8046  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
8047  * 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'.
8048  * 
8049  * Let's consider the typical following case :
8050  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
8051  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
8052  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
8053  *   TETRA4 and SEG2
8054  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
8055  *
8056  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
8057  * 
8058  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
8059  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
8060  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
8061  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
8062  */
8063 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8064 {
8065   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
8066 }
8067
8068 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
8069 {
8070   if(pos<0 || pos>=(int)_time_steps.size())
8071     {
8072       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8073       throw INTERP_KERNEL::Exception(oss.str());
8074     }
8075   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8076   if(item==0)
8077     {
8078       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8079       oss << "\nTry to use following method eraseEmptyTS !";
8080       throw INTERP_KERNEL::Exception(oss.str());
8081     }
8082   return item;
8083 }
8084
8085 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
8086 {
8087   if(pos<0 || pos>=(int)_time_steps.size())
8088     {
8089       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
8090       throw INTERP_KERNEL::Exception(oss.str());
8091     }
8092   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
8093   if(item==0)
8094     {
8095       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
8096       oss << "\nTry to use following method eraseEmptyTS !";
8097       throw INTERP_KERNEL::Exception(oss.str());
8098     }
8099   return item;
8100 }
8101
8102 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
8103 {
8104   std::vector<std::string> ret;
8105   std::set<std::string> ret2;
8106   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8107     {
8108       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
8109       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8110         if(ret2.find(*it2)==ret2.end())
8111           {
8112             ret.push_back(*it2);
8113             ret2.insert(*it2);
8114           }
8115     }
8116   return ret;
8117 }
8118
8119 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
8120 {
8121   std::vector<std::string> ret;
8122   std::set<std::string> ret2;
8123   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8124     {
8125       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
8126       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
8127         if(ret2.find(*it2)==ret2.end())
8128           {
8129             ret.push_back(*it2);
8130             ret2.insert(*it2);
8131           }
8132     }
8133   return ret;
8134 }
8135
8136 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
8137 {
8138   std::vector<std::string> ret;
8139   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8140     {
8141       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
8142       ret.insert(ret.end(),tmp.begin(),tmp.end());
8143     }
8144   return ret;
8145 }
8146
8147 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
8148 {
8149   std::vector<std::string> ret;
8150   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8151     {
8152       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
8153       ret.insert(ret.end(),tmp.begin(),tmp.end());
8154     }
8155   return ret;
8156 }
8157
8158 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8159 {
8160   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8161     (*it)->changePflsRefsNamesGen2(mapOfModif);
8162 }
8163
8164 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8165 {
8166   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
8167     (*it)->changeLocsRefsNamesGen2(mapOfModif);
8168 }
8169
8170 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
8171 {
8172   int lgth=_time_steps.size();
8173   std::vector< std::vector<TypeOfField> > ret(lgth);
8174   for(int i=0;i<lgth;i++)
8175     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
8176   return ret;
8177 }
8178
8179 /*!
8180  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
8181  */
8182 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
8183 {
8184   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
8185 }
8186
8187 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
8188 {
8189   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
8190   std::size_t i=0;
8191   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8192     {
8193       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
8194         ret->_time_steps[i]=(*it)->deepCopy();
8195     }
8196   return ret.retn();
8197 }
8198
8199 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
8200 {
8201   std::size_t sz(_infos.size()),sz2(_time_steps.size());
8202   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
8203   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
8204   for(std::size_t i=0;i<sz;i++)
8205     {
8206       ret[i]=shallowCpy();
8207       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
8208     }
8209   for(std::size_t i=0;i<sz2;i++)
8210     {
8211       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
8212       if(ret1.size()!=sz)
8213         {
8214           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
8215           throw INTERP_KERNEL::Exception(oss.str());
8216         }
8217       ts[i]=ret1;
8218     }
8219   for(std::size_t i=0;i<sz;i++)
8220     for(std::size_t j=0;j<sz2;j++)
8221       ret[i]->_time_steps[j]=ts[j][i];
8222   return ret;
8223 }
8224
8225 /*!
8226  * This method splits into discretization each time steps in \a this.
8227  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
8228  */
8229 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
8230 {
8231   std::size_t sz(_time_steps.size());
8232   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8233   for(std::size_t i=0;i<sz;i++)
8234     {
8235       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8236       if(!timeStep)
8237         {
8238           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
8239           throw INTERP_KERNEL::Exception(oss.str());
8240         }
8241       items[i]=timeStep->splitDiscretizations();  
8242     }
8243   //
8244   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
8245   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
8246   std::vector< TypeOfField > types;
8247   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8248     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8249       {
8250         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
8251         if(ts.size()!=1)
8252           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
8253         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
8254         if(it2==types.end())
8255           types.push_back(ts[0]);
8256       }
8257   ret.resize(types.size()); ret2.resize(types.size());
8258   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8259     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8260       {
8261         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
8262         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
8263         ret2[pos].push_back(*it1);
8264       }
8265   for(std::size_t i=0;i<types.size();i++)
8266     {
8267       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8268       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
8269         elt->pushBackTimeStep(*it1);//also updates infos in elt
8270       ret[i]=elt;
8271       elt->MEDFileFieldNameScope::operator=(*this);
8272     }
8273   return ret;
8274 }
8275
8276 /*!
8277  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
8278  */
8279 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
8280 {
8281   std::size_t sz(_time_steps.size());
8282   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8283   std::size_t szOut(std::numeric_limits<std::size_t>::max());
8284   for(std::size_t i=0;i<sz;i++)
8285     {
8286       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8287       if(!timeStep)
8288         {
8289           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
8290           throw INTERP_KERNEL::Exception(oss.str());
8291         }
8292       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
8293       if(szOut==std::numeric_limits<std::size_t>::max())
8294         szOut=items[i].size();
8295       else
8296         if(items[i].size()!=szOut)
8297           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
8298     }
8299   if(szOut==std::numeric_limits<std::size_t>::max())
8300     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
8301   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
8302   for(std::size_t i=0;i<szOut;i++)
8303     {
8304       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8305       for(std::size_t j=0;j<sz;j++)
8306         elt->pushBackTimeStep(items[j][i]);
8307       ret[i]=elt;
8308       elt->MEDFileFieldNameScope::operator=(*this);
8309     }
8310   return ret;
8311 }
8312
8313 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
8314 {
8315   _name=field->getName();
8316   if(_name.empty())
8317     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
8318   if(!arr)
8319     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
8320   _infos=arr->getInfoOnComponents();
8321 }
8322
8323 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
8324 {
8325   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
8326   if(_name!=field->getName())
8327     {
8328       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
8329       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
8330       throw INTERP_KERNEL::Exception(oss.str());
8331     }
8332   if(!arr)
8333     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
8334   checkThatComponentsMatch(arr->getInfoOnComponents());
8335 }
8336
8337 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
8338 {
8339   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
8340   if(getInfo().size()!=compos.size())
8341     {
8342       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
8343       oss << " number of components of element to append (" << compos.size() << ") !";
8344       throw INTERP_KERNEL::Exception(oss.str());
8345     }
8346   if(_infos!=compos)
8347     {
8348       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
8349       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
8350       oss << " But compo in input fields are : ";
8351       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
8352       oss << " !";
8353       throw INTERP_KERNEL::Exception(oss.str());
8354     }
8355 }
8356
8357 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
8358 {
8359   std::size_t sz=_infos.size();
8360   int j=0;
8361   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
8362     {
8363       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8364       if(elt)
8365         if(elt->getInfo().size()!=sz)
8366           {
8367             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
8368             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
8369             throw INTERP_KERNEL::Exception(oss.str());
8370           }
8371     }
8372 }
8373
8374 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8375 {
8376   if(!field)
8377     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8378   if(!_time_steps.empty())
8379     checkCoherencyOfTinyInfo(field,arr);
8380   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8381   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8382   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8383   copyTinyInfoFrom(field,arr);
8384   _time_steps.push_back(obj);
8385 }
8386
8387 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8388 {
8389   if(!field)
8390     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8391   if(!_time_steps.empty())
8392     checkCoherencyOfTinyInfo(field,arr);
8393   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8394   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8395   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8396   copyTinyInfoFrom(field,arr);
8397   _time_steps.push_back(obj);
8398 }
8399
8400 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8401 {
8402   int sz=(int)_time_steps.size();
8403   if(i<0 || i>=sz)
8404     {
8405       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8406       throw INTERP_KERNEL::Exception(oss.str());
8407     }
8408   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8409   if(tsPtr)
8410     {
8411       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8412         {
8413           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8414           throw INTERP_KERNEL::Exception(oss.str());
8415         }
8416     }
8417   _time_steps[i]=ts;
8418 }
8419
8420 //= MEDFileFieldMultiTSWithoutSDA
8421
8422 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)
8423 {
8424   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8425 }
8426
8427 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8428 {
8429 }
8430
8431 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8432 {
8433 }
8434
8435 /*!
8436  * \param [in] fieldId field id in C mode
8437  */
8438 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8439 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8440 {
8441 }
8442 catch(INTERP_KERNEL::Exception& e)
8443 { throw e; }
8444
8445 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)
8446 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8447 {
8448 }
8449 catch(INTERP_KERNEL::Exception& e)
8450 { throw e; }
8451
8452 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8453 {
8454   return new MEDFileField1TSWithoutSDA;
8455 }
8456
8457 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8458 {
8459   if(!f1ts)
8460     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8461   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8462   if(!f1tsC)
8463     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8464 }
8465
8466 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8467 {
8468   return MEDFileField1TSWithoutSDA::TYPE_STR;
8469 }
8470
8471 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8472 {
8473   return new MEDFileFieldMultiTSWithoutSDA(*this);
8474 }
8475
8476 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8477 {
8478   return new MEDFileFieldMultiTSWithoutSDA;
8479 }
8480
8481 /*!
8482  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8483  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8484  */
8485 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
8486 {
8487   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8488   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8489   if(!myF1TSC)
8490     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8491   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8492 }
8493
8494 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8495 {
8496   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8497   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8498   int i=0;
8499   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8500     {
8501       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8502       if(eltToConv)
8503         {
8504           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8505           if(!eltToConvC)
8506             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8507           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8508           ret->setIteration(i,elt);
8509         }
8510     }
8511   return ret.retn();
8512 }
8513
8514 //= MEDFileAnyTypeFieldMultiTS
8515
8516 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8517 {
8518 }
8519
8520 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8521 try:MEDFileFieldGlobsReal(fid)
8522 {
8523   _content=BuildContentFrom(fid,loadAll,ms);
8524   loadGlobals(fid);
8525 }
8526 catch(INTERP_KERNEL::Exception& e)
8527 {
8528     throw e;
8529 }
8530
8531 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8532 {
8533   med_field_type typcha;
8534   std::vector<std::string> infos;
8535   std::string dtunit;
8536   int i(-1);
8537   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit);
8538   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8539   switch(typcha)
8540   {
8541     case MED_FLOAT64:
8542       {
8543         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8544         break;
8545       }
8546     case MED_INT32:
8547       {
8548         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8549         break;
8550       }
8551     default:
8552       {
8553         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] !";
8554         throw INTERP_KERNEL::Exception(oss.str());
8555       }
8556   }
8557   ret->setDtUnit(dtunit.c_str());
8558   return ret.retn();
8559 }
8560
8561 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8562 {
8563   med_field_type typcha;
8564   //
8565   std::vector<std::string> infos;
8566   std::string dtunit,fieldName;
8567   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
8568   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8569   switch(typcha)
8570   {
8571     case MED_FLOAT64:
8572       {
8573         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8574         break;
8575       }
8576     case MED_INT32:
8577       {
8578         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8579         break;
8580       }
8581     default:
8582       {
8583         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] !";
8584         throw INTERP_KERNEL::Exception(oss.str());
8585       }
8586   }
8587   ret->setDtUnit(dtunit.c_str());
8588   return ret.retn();
8589 }
8590
8591 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8592 {
8593   if(!c)
8594     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8595   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8596     {
8597       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8598       ret->_content=c;  c->incrRef();
8599       return ret.retn();
8600     }
8601   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8602     {
8603       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8604       ret->_content=c;  c->incrRef();
8605       return ret.retn();
8606     }
8607   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8608 }
8609
8610 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8611 {
8612   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8613   std::string fileName(FileNameFromFID(fid));
8614   ret->setFileName(fileName);
8615   return ret;
8616 }
8617
8618 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8619 try:MEDFileFieldGlobsReal(fid)
8620 {
8621   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8622   loadGlobals(fid);
8623 }
8624 catch(INTERP_KERNEL::Exception& e)
8625 {
8626     throw e;
8627 }
8628
8629 //= MEDFileIntFieldMultiTSWithoutSDA
8630
8631 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)
8632 {
8633   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8634 }
8635
8636 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8637 {
8638 }
8639
8640 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8641 {
8642 }
8643
8644 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)
8645 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8646 {
8647 }
8648 catch(INTERP_KERNEL::Exception& e)
8649 { throw e; }
8650
8651 /*!
8652  * \param [in] fieldId field id in C mode
8653  */
8654 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8655 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8656 {
8657 }
8658 catch(INTERP_KERNEL::Exception& e)
8659 { throw e; }
8660
8661 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8662 {
8663   return new MEDFileIntField1TSWithoutSDA;
8664 }
8665
8666 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8667 {
8668   if(!f1ts)
8669     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8670   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8671   if(!f1tsC)
8672     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8673 }
8674
8675 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8676 {
8677   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8678 }
8679
8680 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8681 {
8682   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8683 }
8684
8685 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8686 {
8687   return new MEDFileIntFieldMultiTSWithoutSDA;
8688 }
8689
8690 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8691 {
8692   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8693   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8694   int i=0;
8695   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8696     {
8697       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8698       if(eltToConv)
8699         {
8700           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8701           if(!eltToConvC)
8702             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8703           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8704           ret->setIteration(i,elt);
8705         }
8706     }
8707   return ret.retn();
8708 }
8709
8710 //= MEDFileAnyTypeFieldMultiTS
8711
8712 /*!
8713  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8714  * that has been read from a specified MED file.
8715  *  \param [in] fileName - the name of the MED file to read.
8716  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8717  *          is to delete this field using decrRef() as it is no more needed.
8718  *  \throw If reading the file fails.
8719  */
8720 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8721 {
8722   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8723   return New(fid,loadAll);
8724 }
8725
8726 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8727 {
8728   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8729   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8730   ret->loadGlobals(fid);
8731   return ret.retn();
8732 }
8733
8734 /*!
8735  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8736  * that has been read from a specified MED file.
8737  *  \param [in] fileName - the name of the MED file to read.
8738  *  \param [in] fieldName - the name of the field to read.
8739  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8740  *          is to delete this field using decrRef() as it is no more needed.
8741  *  \throw If reading the file fails.
8742  *  \throw If there is no field named \a fieldName in the file.
8743  */
8744 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8745 {
8746   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8747   return New(fid,fieldName,loadAll);
8748 }
8749
8750 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8751 {
8752   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8753   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8754   ret->loadGlobals(fid);
8755   return ret.retn();
8756 }
8757
8758 /*!
8759  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8760  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8761  *
8762  * \warning this is a shallow copy constructor
8763  */
8764 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8765 {
8766   if(!shallowCopyOfContent)
8767     {
8768       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8769       otherPtr->incrRef();
8770       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8771     }
8772   else
8773     {
8774       _content=other.shallowCpy();
8775     }
8776 }
8777
8778 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8779 {
8780   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8781   if(!ret)
8782     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8783   return ret;
8784 }
8785
8786 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8787 {
8788   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8789   if(!ret)
8790     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8791   return ret;
8792 }
8793
8794 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8795 {
8796   return contentNotNullBase()->getPflsReallyUsed2();
8797 }
8798
8799 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8800 {
8801   return contentNotNullBase()->getLocsReallyUsed2();
8802 }
8803
8804 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8805 {
8806   return contentNotNullBase()->getPflsReallyUsedMulti2();
8807 }
8808
8809 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8810 {
8811   return contentNotNullBase()->getLocsReallyUsedMulti2();
8812 }
8813
8814 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8815 {
8816   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8817 }
8818
8819 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8820 {
8821   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8822 }
8823
8824 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8825 {
8826   return contentNotNullBase()->getNumberOfTS();
8827 }
8828
8829 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8830 {
8831   contentNotNullBase()->eraseEmptyTS();
8832 }
8833
8834 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8835 {
8836   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8837 }
8838
8839 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8840 {
8841   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8842 }
8843
8844 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8845 {
8846   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8847   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8848   ret->_content=c;
8849   return ret.retn();
8850 }
8851
8852 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8853 {
8854   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8855   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8856   ret->_content=c;
8857   return ret.retn();
8858 }
8859
8860 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8861 {
8862   return contentNotNullBase()->getIterations();
8863 }
8864
8865 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8866 {
8867   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8868     pushBackTimeStep(*it);
8869 }
8870
8871 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8872 {
8873   if(!fmts)
8874     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8875   int nbOfTS(fmts->getNumberOfTS());
8876   for(int i=0;i<nbOfTS;i++)
8877     {
8878       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8879       pushBackTimeStep(elt);
8880     }
8881 }
8882
8883 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8884 {
8885   if(!f1ts)
8886     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8887   checkCoherencyOfType(f1ts);
8888   f1ts->incrRef();
8889   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8890   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8891   c->incrRef();
8892   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8893   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8894     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8895   _content->pushBackTimeStep(cSafe);
8896   appendGlobs(*f1ts,1e-12);
8897 }
8898
8899 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8900 {
8901   contentNotNullBase()->synchronizeNameScope();
8902 }
8903
8904 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8905 {
8906   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8907 }
8908
8909 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8910 {
8911   return contentNotNullBase()->getPosGivenTime(time,eps);
8912 }
8913
8914 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8915 {
8916   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8917 }
8918
8919 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8920 {
8921   return contentNotNullBase()->getTypesOfFieldAvailable();
8922 }
8923
8924 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
8925 {
8926   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8927 }
8928
8929 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8930 {
8931   return contentNotNullBase()->getName();
8932 }
8933
8934 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8935 {
8936   contentNotNullBase()->setName(name);
8937 }
8938
8939 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8940 {
8941   return contentNotNullBase()->getDtUnit();
8942 }
8943
8944 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8945 {
8946   contentNotNullBase()->setDtUnit(dtUnit);
8947 }
8948
8949 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8950 {
8951   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8952 }
8953
8954 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8955 {
8956   return contentNotNullBase()->getTimeSteps(ret1);
8957 }
8958
8959 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8960 {
8961   return contentNotNullBase()->getMeshName();
8962 }
8963
8964 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8965 {
8966   contentNotNullBase()->setMeshName(newMeshName);
8967 }
8968
8969 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8970 {
8971   return contentNotNullBase()->changeMeshNames(modifTab);
8972 }
8973
8974 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8975 {
8976   return contentNotNullBase()->getInfo();
8977 }
8978
8979 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8980 {
8981   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8982 }
8983
8984 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8985 {
8986   return contentNotNullBase()->setInfo(info);
8987 }
8988
8989 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8990 {
8991   const std::vector<std::string> ret=getInfo();
8992   return (int)ret.size();
8993 }
8994
8995 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8996 {
8997   writeGlobals(fid,*this);
8998   contentNotNullBase()->writeLL(fid,*this);
8999 }
9000
9001 /*!
9002  * This method alloc the arrays and load potentially huge arrays contained in this field.
9003  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
9004  * This method can be also called to refresh or reinit values from a file.
9005  * 
9006  * \throw If the fileName is not set or points to a non readable MED file.
9007  */
9008 void MEDFileAnyTypeFieldMultiTS::loadArrays()
9009 {
9010   if(getFileName().empty())
9011     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
9012   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9013   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
9014 }
9015
9016 /*!
9017  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
9018  * But once data loaded once, this method does nothing.
9019  * 
9020  * \throw If the fileName is not set or points to a non readable MED file.
9021  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
9022  */
9023 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
9024 {
9025   if(!getFileName().empty())
9026     {
9027       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
9028       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
9029     }
9030 }
9031
9032 /*!
9033  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
9034  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
9035  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
9036  * 
9037  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
9038  */
9039 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
9040 {
9041   contentNotNullBase()->unloadArrays();
9042 }
9043
9044 /*!
9045  * 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.
9046  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
9047  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
9048  * 
9049  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
9050  */
9051 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
9052 {
9053   if(!getFileName().empty())
9054     contentNotNullBase()->unloadArrays();
9055 }
9056
9057 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
9058 {
9059   std::ostringstream oss;
9060   contentNotNullBase()->simpleRepr(0,oss,-1);
9061   simpleReprGlobs(oss);
9062   return oss.str();
9063 }
9064
9065 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
9066 {
9067   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
9068 }
9069
9070 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
9071 {
9072   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
9073   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
9074   return ret;
9075 }
9076
9077 /*!
9078  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
9079  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
9080  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
9081  */
9082 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
9083 {
9084   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9085   if(!content)
9086     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
9087   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
9088   std::size_t sz(contentsSplit.size());
9089   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9090   for(std::size_t i=0;i<sz;i++)
9091     {
9092       ret[i]=shallowCpy();
9093       ret[i]->_content=contentsSplit[i];
9094     }
9095   return ret;
9096 }
9097
9098 /*!
9099  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
9100  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9101  */
9102 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
9103 {
9104   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9105   if(!content)
9106     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
9107   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
9108   std::size_t sz(contentsSplit.size());
9109   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9110   for(std::size_t i=0;i<sz;i++)
9111     {
9112       ret[i]=shallowCpy();
9113       ret[i]->_content=contentsSplit[i];
9114     }
9115   return ret;
9116 }
9117
9118 /*!
9119  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
9120  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
9121  */
9122 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
9123 {
9124   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9125   if(!content)
9126     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
9127   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
9128   std::size_t sz(contentsSplit.size());
9129   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
9130   for(std::size_t i=0;i<sz;i++)
9131     {
9132       ret[i]=shallowCpy();
9133       ret[i]->_content=contentsSplit[i];
9134     }
9135   return ret;
9136 }
9137
9138 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
9139 {
9140   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
9141   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
9142     ret->_content=_content->deepCopy();
9143   ret->deepCpyGlobs(*this);
9144   return ret.retn();
9145 }
9146
9147 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
9148 {
9149   return _content;
9150 }
9151
9152 /*!
9153  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9154  *  \param [in] iteration - the iteration number of a required time step.
9155  *  \param [in] order - the iteration order number of required time step.
9156  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
9157  *          delete this field using decrRef() as it is no more needed.
9158  *  \throw If there is no required time step in \a this field.
9159  */
9160 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
9161 {
9162   int pos=getPosOfTimeStep(iteration,order);
9163   return getTimeStepAtPos(pos);
9164 }
9165
9166 /*!
9167  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
9168  *  \param [in] time - the time of the time step of interest.
9169  *  \param [in] eps - a precision used to compare time values.
9170  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9171  *          delete this field using decrRef() as it is no more needed.
9172  *  \throw If there is no required time step in \a this field.
9173  */
9174 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
9175 {
9176   int pos=getPosGivenTime(time,eps);
9177   return getTimeStepAtPos(pos);
9178 }
9179
9180 /*!
9181  * 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.
9182  * The float64 value of time attached to the pair of integers are not considered here.
9183  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
9184  *
9185  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
9186  * \throw If there is a null pointer in \a vectFMTS.
9187  */
9188 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
9189 {
9190   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
9191   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9192   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9193   while(!lstFMTS.empty())
9194     {
9195       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9196       MEDFileAnyTypeFieldMultiTS *curIt(*it);
9197       if(!curIt)
9198         throw INTERP_KERNEL::Exception(msg);
9199       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
9200       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9201       elt.push_back(curIt); it=lstFMTS.erase(it);
9202       while(it!=lstFMTS.end())
9203         {
9204           curIt=*it;
9205           if(!curIt)
9206             throw INTERP_KERNEL::Exception(msg);
9207           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
9208           if(refIts==curIts)
9209             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9210           else
9211             it++;
9212         }
9213       ret.push_back(elt);
9214     }
9215   return ret;
9216 }
9217
9218 /*!
9219  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
9220  * All returned instances in a subvector can be safely loaded, rendered along time
9221  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
9222  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
9223  * 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).
9224  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
9225  * 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.
9226  *
9227  * \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().
9228  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
9229  * \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.
9230  * \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.
9231  *
9232  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
9233  * \throw If an element in \a vectFMTS change of spatial discretization along time.
9234  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
9235  * \thorw If some elements in \a vectFMTS do not have the same times steps.
9236  * \throw If mesh is null.
9237  * \throw If an element in \a vectFMTS is null.
9238  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
9239  */
9240 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
9241 {
9242   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
9243   if(!mesh)
9244     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
9245   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9246   if(vectFMTS.empty())
9247     return ret;
9248   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
9249   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
9250   if(!frstElt)
9251     throw INTERP_KERNEL::Exception(msg);
9252   std::size_t i=0;
9253   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
9254   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
9255   for(;it!=vectFMTS.end();it++,i++)
9256     {
9257       if(!(*it))
9258         throw INTERP_KERNEL::Exception(msg);
9259       TypeOfField tof0,tof1;
9260       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
9261         {
9262           if(tof1!=ON_NODES)
9263             vectFMTSNotNodes.push_back(*it);
9264           else
9265             vectFMTSNodes.push_back(*it);
9266         }
9267       else
9268         vectFMTSNotNodes.push_back(*it);
9269     }
9270   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
9271   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
9272   ret=retCell;
9273   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
9274     {
9275       i=0;
9276       bool isFetched(false);
9277       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
9278         {
9279           if((*it0).empty())
9280             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
9281           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
9282             { ret[i].push_back(*it2); isFetched=true; }
9283         }
9284       if(!isFetched)
9285         {
9286           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
9287           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
9288           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
9289         }
9290     }
9291   fsc=cmps;
9292   return ret;
9293 }
9294
9295 /*!
9296  * 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.
9297  * \param [out] cmps - same size than the returned vector.
9298  */
9299 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
9300 {
9301   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9302   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9303   while(!lstFMTS.empty())
9304     {
9305       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9306       MEDFileAnyTypeFieldMultiTS *ref(*it);
9307       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9308       elt.push_back(ref); it=lstFMTS.erase(it);
9309       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
9310       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
9311       while(it!=lstFMTS.end())
9312         {
9313           MEDFileAnyTypeFieldMultiTS *curIt(*it);
9314           if(cmp->isEqual(curIt))
9315             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9316           else
9317             it++;
9318         }
9319       ret.push_back(elt); cmps.push_back(cmp);
9320     }
9321   return ret;
9322 }
9323
9324 /*!
9325  * 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.
9326  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
9327  *
9328  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
9329  * \throw If \a f0 or \a f1 change of spatial discretization along time.
9330  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
9331  * \thorw If \a f0 and \a f1 do not have the same times steps.
9332  * \throw If mesh is null.
9333  * \throw If \a f0 or \a f1 is null.
9334  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
9335  */
9336 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
9337 {
9338   if(!mesh)
9339     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
9340   if(!f0 || !f1)
9341     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
9342   if(f0->getMeshName()!=mesh->getName())
9343     {
9344       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9345       throw INTERP_KERNEL::Exception(oss.str());
9346     }
9347   if(f1->getMeshName()!=mesh->getName())
9348     {
9349       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9350       throw INTERP_KERNEL::Exception(oss.str());
9351     }
9352   int nts=f0->getNumberOfTS();
9353   if(nts!=f1->getNumberOfTS())
9354     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
9355   if(nts==0)
9356     return nts;
9357   for(int i=0;i<nts;i++)
9358     {
9359       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
9360       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
9361       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
9362       if(tofs0.size()!=1 || tofs1.size()!=1)
9363         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
9364       if(i!=0)
9365         {
9366           if(tof0!=tofs0[0] || tof1!=tofs1[0])
9367             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
9368         }
9369       else
9370         { tof0=tofs0[0]; tof1=tofs1[0]; }
9371       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9372         {
9373           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() << ") !";
9374           throw INTERP_KERNEL::Exception(oss.str());
9375         }
9376       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9377         {
9378           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() << ") !";
9379           throw INTERP_KERNEL::Exception(oss.str());
9380         }
9381       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9382         {
9383           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() << ") !";
9384           throw INTERP_KERNEL::Exception(oss.str());
9385         }
9386     }
9387   return nts;
9388 }
9389
9390 /*!
9391  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9392  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9393  *
9394  * \return A new object that the caller is responsible to deallocate.
9395  */
9396 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9397 {
9398   if(!mm)
9399     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9400   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9401   int nbTS(getNumberOfTS());
9402   for(int i=0;i<nbTS;i++)
9403     {
9404       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9405       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9406       fmtsOut->pushBackTimeStep(f1tsOut);
9407     }
9408   return fmtsOut.retn();
9409 }
9410
9411 template<class T>
9412 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9413 {
9414   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9415   if(f1tss.empty())
9416     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9417   std::size_t sz(f1tss.size()),i(0);
9418   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9419   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9420     {
9421       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9422       if(!elt)
9423         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9424       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9425     }
9426   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9427   if(!retc)
9428     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9429   retc->aggregate(f1tsw,dts);
9430   ret->setDtUnit(f1tss[0]->getDtUnit());
9431   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9432 }
9433
9434 template<class T>
9435 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9436 {
9437   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9438   if(fmtss.empty())
9439     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9440   std::size_t sz(fmtss.size());
9441   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9442     {
9443       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9444       if(!elt)
9445         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9446     }
9447   int nbTS(fmtss[0]->getNumberOfTS());
9448   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9449     if((*it)->getNumberOfTS()!=nbTS)
9450       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9451   for(int iterTS=0;iterTS<nbTS;iterTS++)
9452     {
9453       std::size_t i(0);
9454       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9455       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9456       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9457         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9458       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9459       ret->pushBackTimeStep(f1ts);
9460       ret->setDtUnit(f1ts->getDtUnit());
9461     }
9462   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9463 }
9464
9465 /*!
9466  * \a dts and \a ftmss are expected to have same size.
9467  */
9468 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9469 {
9470   if(fmtss.empty())
9471     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9472   std::size_t sz(fmtss.size());
9473   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9474   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9475   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9476     {
9477       if(!(*it))
9478         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9479       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9480       if(elt1)
9481         {
9482           fmtss1.push_back(elt1);
9483           continue;
9484         }
9485       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9486       if(elt2)
9487         {
9488           fmtss2.push_back(elt2);
9489           continue;
9490         }
9491       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9492     }
9493   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9494     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9495   if(fmtss1.size()==sz)
9496     return AggregateHelperFMTS<double>(fmtss1,dts);
9497   if(fmtss2.size()!=sz)
9498     return AggregateHelperFMTS<int>(fmtss2,dts);
9499   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9500 }
9501
9502 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9503 {
9504   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9505 }
9506
9507 //= MEDFileFieldMultiTS
9508
9509 /*!
9510  * Returns a new empty instance of MEDFileFieldMultiTS.
9511  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9512  *          is to delete this field using decrRef() as it is no more needed.
9513  */
9514 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9515 {
9516   return new MEDFileFieldMultiTS;
9517 }
9518
9519 /*!
9520  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9521  * that has been read from a specified MED file.
9522  *  \param [in] fileName - the name of the MED file to read.
9523  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9524  *          is to delete this field using decrRef() as it is no more needed.
9525  *  \throw If reading the file fails.
9526  */
9527 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9528 {
9529   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9530   return New(fid,loadAll);
9531 }
9532
9533 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9534 {
9535   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9536   ret->contentNotNull();//to check that content type matches with \a this type.
9537   return ret.retn();
9538 }
9539
9540 /*!
9541  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9542  * that has been read from a specified MED file.
9543  *  \param [in] fileName - the name of the MED file to read.
9544  *  \param [in] fieldName - the name of the field to read.
9545  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9546  *          is to delete this field using decrRef() as it is no more needed.
9547  *  \throw If reading the file fails.
9548  *  \throw If there is no field named \a fieldName in the file.
9549  */
9550 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9551 {
9552   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9553   return New(fid,fieldName,loadAll);
9554 }
9555
9556 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9557 {
9558   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9559   ret->contentNotNull();//to check that content type matches with \a this type.
9560   return ret.retn();
9561 }
9562
9563 /*!
9564  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9565  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9566  *
9567  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9568  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9569  * \warning this is a shallow copy constructor
9570  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9571  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9572  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9573  *          is to delete this field using decrRef() as it is no more needed.
9574  */
9575 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9576 {
9577   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9578 }
9579
9580 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9581 {
9582   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9583   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9584   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
9585   ret->contentNotNull();//to check that content type matches with \a this type.
9586   return ret.retn();
9587 }
9588
9589 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9590 {
9591   return new MEDFileFieldMultiTS(*this);
9592 }
9593
9594 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9595 {
9596   if(!f1ts)
9597     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9598   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9599   if(!f1tsC)
9600     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9601 }
9602
9603 /*!
9604  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9605  * following the given input policy.
9606  *
9607  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9608  *                            By default (true) the globals are deeply copied.
9609  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9610  */
9611 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9612 {
9613   MCAuto<MEDFileIntFieldMultiTS> ret;
9614   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9615   if(content)
9616     {
9617       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9618       if(!contc)
9619         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9620       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9621       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9622     }
9623   else
9624     ret=MEDFileIntFieldMultiTS::New();
9625   if(isDeepCpyGlobs)
9626     ret->deepCpyGlobs(*this);
9627   else
9628     ret->shallowCpyGlobs(*this);
9629   return ret.retn();
9630 }
9631
9632 /*!
9633  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9634  *  \param [in] pos - a time step id.
9635  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9636  *          delete this field using decrRef() as it is no more needed.
9637  *  \throw If \a pos is not a valid time step id.
9638  */
9639 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9640 {
9641   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9642   if(!item)
9643     {
9644       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9645       throw INTERP_KERNEL::Exception(oss.str());
9646     }
9647   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9648   if(itemC)
9649     {
9650       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9651       ret->shallowCpyGlobs(*this);
9652       return ret.retn();
9653     }
9654   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9655   throw INTERP_KERNEL::Exception(oss.str());
9656 }
9657
9658 /*!
9659  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9660  * mesh entities of a given dimension of the first mesh in MED file.
9661  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9662  *  \param [in] type - a spatial discretization of interest.
9663  *  \param [in] iteration - the iteration number of a required time step.
9664  *  \param [in] order - the iteration order number of required time step.
9665  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9666  *  \param [in] renumPol - specifies how to permute values of the result field according to
9667  *          the optional numbers of cells and nodes, if any. The valid values are
9668  *          - 0 - do not permute.
9669  *          - 1 - permute cells.
9670  *          - 2 - permute nodes.
9671  *          - 3 - permute cells and nodes.
9672  *
9673  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9674  *          caller is to delete this field using decrRef() as it is no more needed. 
9675  *  \throw If the MED file is not readable.
9676  *  \throw If there is no mesh in the MED file.
9677  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9678  *  \throw If no field values of the required parameters are available.
9679  */
9680 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9681 {
9682   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9683   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9684   if(!myF1TSC)
9685     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9686   MCAuto<DataArray> arrOut;
9687   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9688   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9689   return ret.retn();
9690 }
9691
9692 /*!
9693  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9694  * the top level cells of the first mesh in MED file.
9695  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9696  *  \param [in] type - a spatial discretization of interest.
9697  *  \param [in] iteration - the iteration number of a required time step.
9698  *  \param [in] order - the iteration order number of required time step.
9699  *  \param [in] renumPol - specifies how to permute values of the result field according to
9700  *          the optional numbers of cells and nodes, if any. The valid values are
9701  *          - 0 - do not permute.
9702  *          - 1 - permute cells.
9703  *          - 2 - permute nodes.
9704  *          - 3 - permute cells and nodes.
9705  *
9706  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9707  *          caller is to delete this field using decrRef() as it is no more needed. 
9708  *  \throw If the MED file is not readable.
9709  *  \throw If there is no mesh in the MED file.
9710  *  \throw If no field values of the required parameters are available.
9711  */
9712 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9713 {
9714   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9715   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9716   if(!myF1TSC)
9717     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9718   MCAuto<DataArray> arrOut;
9719   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9720   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9721   return ret.retn();
9722 }
9723
9724 /*!
9725  * 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
9726  * method should be called (getFieldOnMeshAtLevel for example).
9727  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9728  *
9729  * \param [in] iteration - the iteration number of a required time step.
9730  * \param [in] order - the iteration order number of required time step.
9731  * \param [in] mesh - the mesh the field is lying on
9732  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9733  *          caller is to delete this field using decrRef() as it is no more needed. 
9734  */
9735 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9736 {
9737   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9738   MCAuto<DataArray> arrOut;
9739   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9740   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9741   return ret.retn();
9742 }
9743
9744 /*!
9745  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9746  * a given support.
9747  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9748  *  \param [in] type - a spatial discretization of interest.
9749  *  \param [in] iteration - the iteration number of a required time step.
9750  *  \param [in] order - the iteration order number of required time step.
9751  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9752  *  \param [in] mesh - the supporting mesh.
9753  *  \param [in] renumPol - specifies how to permute values of the result field according to
9754  *          the optional numbers of cells and nodes, if any. The valid values are
9755  *          - 0 - do not permute.
9756  *          - 1 - permute cells.
9757  *          - 2 - permute nodes.
9758  *          - 3 - permute cells and nodes.
9759  *
9760  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9761  *          caller is to delete this field using decrRef() as it is no more needed. 
9762  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9763  *  \throw If no field of \a this is lying on \a mesh.
9764  *  \throw If no field values of the required parameters are available.
9765  */
9766 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9767 {
9768   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9769   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9770   if(!myF1TSC)
9771     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9772   MCAuto<DataArray> arrOut;
9773   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9774   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9775   return ret.retn();
9776 }
9777
9778 /*!
9779  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9780  * given support. 
9781  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9782  *  \param [in] type - a spatial discretization of the new field.
9783  *  \param [in] iteration - the iteration number of a required time step.
9784  *  \param [in] order - the iteration order number of required time step.
9785  *  \param [in] mesh - the supporting mesh.
9786  *  \param [in] renumPol - specifies how to permute values of the result field according to
9787  *          the optional numbers of cells and nodes, if any. The valid values are
9788  *          - 0 - do not permute.
9789  *          - 1 - permute cells.
9790  *          - 2 - permute nodes.
9791  *          - 3 - permute cells and nodes.
9792  *
9793  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9794  *          caller is to delete this field using decrRef() as it is no more needed. 
9795  *  \throw If no field of \a this is lying on \a mesh.
9796  *  \throw If no field values of the required parameters are available.
9797  */
9798 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9799 {
9800   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9801   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9802   if(!myF1TSC)
9803     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9804   MCAuto<DataArray> arrOut;
9805   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9806   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9807   return ret.retn();
9808 }
9809
9810 /*!
9811  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9812  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9813  * This method is useful for MED2 file format when field on different mesh was autorized.
9814  */
9815 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9816 {
9817   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9818   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9819   if(!myF1TSC)
9820     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9821   MCAuto<DataArray> arrOut;
9822   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9823   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9824   return ret.retn();
9825 }
9826
9827 /*!
9828  * Returns values and a profile of the field of a given type, of a given time step,
9829  * lying on a given support.
9830  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9831  *  \param [in] type - a spatial discretization of the field.
9832  *  \param [in] iteration - the iteration number of a required time step.
9833  *  \param [in] order - the iteration order number of required time step.
9834  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9835  *  \param [in] mesh - the supporting mesh.
9836  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9837  *          field of interest lies on. If the field lies on all entities of the given
9838  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9839  *          using decrRef() as it is no more needed.  
9840  *  \param [in] glob - the global data storing profiles and localization.
9841  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9842  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9843  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9844  *  \throw If no field of \a this is lying on \a mesh.
9845  *  \throw If no field values of the required parameters are available.
9846  */
9847 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9848 {
9849   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9850   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9851   if(!myF1TSC)
9852     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9853   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9854   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9855 }
9856
9857 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9858 {
9859   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9860   if(!pt)
9861     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9862   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9863   if(!ret)
9864     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 !");
9865   return ret;
9866 }
9867
9868 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9869 {
9870   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9871   if(!pt)
9872     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9873   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9874   if(!ret)
9875     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 !");
9876   return ret;
9877 }
9878
9879 /*!
9880  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9881  * the given field is checked if its elements are sorted suitable for writing to MED file
9882  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9883  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9884  *  \param [in] field - the field to add to \a this.
9885  *  \throw If the name of \a field is empty.
9886  *  \throw If the data array of \a field is not set.
9887  *  \throw If existing time steps have different name or number of components than \a field.
9888  *  \throw If the underlying mesh of \a field has no name.
9889  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9890  */
9891 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9892 {
9893   const DataArrayDouble *arr=0;
9894   if(field)
9895     arr=field->getArray();
9896   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9897 }
9898
9899 /*!
9900  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9901  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9902  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9903  * and \a profile.
9904  *
9905  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9906  * A new profile is added only if no equal profile is missing.
9907  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9908  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9909  *  \param [in] mesh - the supporting mesh of \a field.
9910  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9911  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9912  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9913  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9914  *  \throw If the data array of \a field is not set.
9915  *  \throw If the data array of \a this is already allocated but has different number of
9916  *         components than \a field.
9917  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9918  *  \sa setFieldNoProfileSBT()
9919  */
9920 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9921 {
9922   const DataArrayDouble *arr=0;
9923   if(field)
9924     arr=field->getArray();
9925   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9926 }
9927
9928 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9929 {
9930   _content=new MEDFileFieldMultiTSWithoutSDA;
9931 }
9932
9933 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
9934 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
9935 {
9936 }
9937 catch(INTERP_KERNEL::Exception& e)
9938 { throw e; }
9939
9940 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9941 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
9942 {
9943 }
9944 catch(INTERP_KERNEL::Exception& e)
9945 { throw e; }
9946
9947 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9948 {
9949 }
9950
9951 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
9952 {
9953   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9954 }
9955
9956 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9957 {
9958   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9959 }
9960
9961 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9962 {
9963   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9964 }
9965
9966 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
9967 {
9968   return MEDFileFieldMultiTS::New();
9969 }
9970
9971 //= MEDFileAnyTypeFieldMultiTSIterator
9972
9973 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9974 {
9975   if(fmts)
9976     {
9977       fmts->incrRef();
9978       _nb_iter=fmts->getNumberOfTS();
9979     }
9980 }
9981
9982 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9983 {
9984 }
9985
9986 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9987 {
9988   if(_iter_id<_nb_iter)
9989     {
9990       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9991       if(fmts)
9992         return fmts->getTimeStepAtPos(_iter_id++);
9993       else
9994         return 0;
9995     }
9996   else
9997     return 0;
9998 }
9999
10000 //= MEDFileIntFieldMultiTS
10001
10002 /*!
10003  * Returns a new empty instance of MEDFileFieldMultiTS.
10004  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10005  *          is to delete this field using decrRef() as it is no more needed.
10006  */
10007 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
10008 {
10009   return new MEDFileIntFieldMultiTS;
10010 }
10011
10012 /*!
10013  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
10014  * that has been read from a specified MED file.
10015  *  \param [in] fileName - the name of the MED file to read.
10016  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10017  *          is to delete this field using decrRef() as it is no more needed.
10018  *  \throw If reading the file fails.
10019  */
10020 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
10021 {
10022   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10023   return New(fid,loadAll);
10024 }
10025
10026 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
10027 {
10028   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
10029   ret->contentNotNull();//to check that content type matches with \a this type.
10030   return ret.retn();
10031 }
10032
10033 /*!
10034  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
10035  * that has been read from a specified MED file.
10036  *  \param [in] fileName - the name of the MED file to read.
10037  *  \param [in] fieldName - the name of the field to read.
10038  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10039  *          is to delete this field using decrRef() as it is no more needed.
10040  *  \throw If reading the file fails.
10041  *  \throw If there is no field named \a fieldName in the file.
10042  */
10043 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
10044 {
10045   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10046   return New(fid,fieldName,loadAll);
10047 }
10048
10049 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
10050 {
10051   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
10052   ret->contentNotNull();//to check that content type matches with \a this type.
10053   return ret.retn();
10054 }
10055
10056 /*!
10057  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
10058  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
10059  *
10060  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
10061  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
10062  * \warning this is a shallow copy constructor
10063  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
10064  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
10065  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
10066  *          is to delete this field using decrRef() as it is no more needed.
10067  */
10068 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
10069 {
10070   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
10071 }
10072
10073 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10074 {
10075   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10076   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10077   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
10078   ret->contentNotNull();//to check that content type matches with \a this type.
10079   return ret.retn();
10080 }
10081
10082 /*!
10083  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
10084  * following the given input policy.
10085  *
10086  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
10087  *                            By default (true) the globals are deeply copied.
10088  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
10089  */
10090 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
10091 {
10092   MCAuto<MEDFileFieldMultiTS> ret;
10093   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
10094   if(content)
10095     {
10096       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
10097       if(!contc)
10098         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
10099       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
10100       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
10101     }
10102   else
10103     ret=MEDFileFieldMultiTS::New();
10104   if(isDeepCpyGlobs)
10105     ret->deepCpyGlobs(*this);
10106   else
10107     ret->shallowCpyGlobs(*this);
10108   return ret.retn();
10109 }
10110
10111 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
10112 {
10113   return new MEDFileIntFieldMultiTS(*this);
10114 }
10115
10116 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
10117 {
10118   if(!f1ts)
10119     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
10120   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
10121   if(!f1tsC)
10122     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
10123 }
10124
10125 /*!
10126  * 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
10127  * method should be called (getFieldOnMeshAtLevel for example).
10128  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
10129  *
10130  * \param [in] iteration - the iteration number of a required time step.
10131  * \param [in] order - the iteration order number of required time step.
10132  * \param [in] mesh - the mesh the field is lying on
10133  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
10134  *          caller is to delete this field using decrRef() as it is no more needed. 
10135  */
10136 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
10137 {
10138   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10139   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10140   if(!myF1TSC)
10141     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
10142   MCAuto<DataArray> arrOut;
10143   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
10144   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
10145   return ret2.retn();
10146 }
10147
10148 /*!
10149  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10150  * mesh entities of a given dimension of the first mesh in MED file.
10151  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10152  *  \param [in] type - a spatial discretization of interest.
10153  *  \param [in] iteration - the iteration number of a required time step.
10154  *  \param [in] order - the iteration order number of required time step.
10155  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10156  *  \param [in] renumPol - specifies how to permute values of the result field according to
10157  *          the optional numbers of cells and nodes, if any. The valid values are
10158  *          - 0 - do not permute.
10159  *          - 1 - permute cells.
10160  *          - 2 - permute nodes.
10161  *          - 3 - permute cells and nodes.
10162  *
10163  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10164  *          caller is to delete this field using decrRef() as it is no more needed. 
10165  *  \throw If the MED file is not readable.
10166  *  \throw If there is no mesh in the MED file.
10167  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10168  *  \throw If no field values of the required parameters are available.
10169  */
10170 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
10171 {
10172   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10173   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10174   if(!myF1TSC)
10175     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
10176   MCAuto<DataArray> arr;
10177   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
10178   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10179   return ret2.retn();
10180 }
10181
10182 /*!
10183  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10184  * the top level cells of the first mesh in MED file.
10185  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10186  *  \param [in] type - a spatial discretization of interest.
10187  *  \param [in] iteration - the iteration number of a required time step.
10188  *  \param [in] order - the iteration order number of required time step.
10189  *  \param [in] renumPol - specifies how to permute values of the result field according to
10190  *          the optional numbers of cells and nodes, if any. The valid values are
10191  *          - 0 - do not permute.
10192  *          - 1 - permute cells.
10193  *          - 2 - permute nodes.
10194  *          - 3 - permute cells and nodes.
10195  *
10196  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10197  *          caller is to delete this field using decrRef() as it is no more needed. 
10198  *  \throw If the MED file is not readable.
10199  *  \throw If there is no mesh in the MED file.
10200  *  \throw If no field values of the required parameters are available.
10201  */
10202 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
10203 {
10204   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10205   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10206   if(!myF1TSC)
10207     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
10208   MCAuto<DataArray> arr;
10209   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
10210   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10211   return ret2.retn();
10212 }
10213
10214 /*!
10215  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
10216  * a given support.
10217  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10218  *  \param [in] type - a spatial discretization of interest.
10219  *  \param [in] iteration - the iteration number of a required time step.
10220  *  \param [in] order - the iteration order number of required time step.
10221  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10222  *  \param [in] mesh - the supporting mesh.
10223  *  \param [in] renumPol - specifies how to permute values of the result field according to
10224  *          the optional numbers of cells and nodes, if any. The valid values are
10225  *          - 0 - do not permute.
10226  *          - 1 - permute cells.
10227  *          - 2 - permute nodes.
10228  *          - 3 - permute cells and nodes.
10229  *
10230  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10231  *          caller is to delete this field using decrRef() as it is no more needed. 
10232  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
10233  *  \throw If no field of \a this is lying on \a mesh.
10234  *  \throw If no field values of the required parameters are available.
10235  */
10236 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10237 {
10238   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10239   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10240   if(!myF1TSC)
10241     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10242   MCAuto<DataArray> arr;
10243   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
10244   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10245   return ret2.retn();
10246 }
10247
10248 /*!
10249  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
10250  * given support. 
10251  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10252  *  \param [in] type - a spatial discretization of the new field.
10253  *  \param [in] iteration - the iteration number of a required time step.
10254  *  \param [in] order - the iteration order number of required time step.
10255  *  \param [in] mesh - the supporting mesh.
10256  *  \param [out] arrOut - the DataArrayInt containing values of field.
10257  *  \param [in] renumPol - specifies how to permute values of the result field according to
10258  *          the optional numbers of cells and nodes, if any. The valid values are
10259  *          - 0 - do not permute.
10260  *          - 1 - permute cells.
10261  *          - 2 - permute nodes.
10262  *          - 3 - permute cells and nodes.
10263  *
10264  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10265  *          caller is to delete this field using decrRef() as it is no more needed. 
10266  *  \throw If no field of \a this is lying on \a mesh.
10267  *  \throw If no field values of the required parameters are available.
10268  */
10269 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10270 {
10271   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10272   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10273   if(!myF1TSC)
10274     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10275   MCAuto<DataArray> arr;
10276   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
10277   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10278   return ret2.retn();
10279 }
10280
10281 /*!
10282  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
10283  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10284  * This method is useful for MED2 file format when field on different mesh was autorized.
10285  */
10286 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
10287 {
10288   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10289   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10290   if(!myF1TSC)
10291     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10292   MCAuto<DataArray> arr;
10293   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
10294   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10295   return ret2.retn();
10296 }
10297
10298 /*!
10299  * Returns values and a profile of the field of a given type, of a given time step,
10300  * lying on a given support.
10301  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10302  *  \param [in] type - a spatial discretization of the field.
10303  *  \param [in] iteration - the iteration number of a required time step.
10304  *  \param [in] order - the iteration order number of required time step.
10305  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10306  *  \param [in] mesh - the supporting mesh.
10307  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10308  *          field of interest lies on. If the field lies on all entities of the given
10309  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10310  *          using decrRef() as it is no more needed.  
10311  *  \param [in] glob - the global data storing profiles and localization.
10312  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
10313  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10314  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10315  *  \throw If no field of \a this is lying on \a mesh.
10316  *  \throw If no field values of the required parameters are available.
10317  */
10318 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10319 {
10320   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10321   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
10322   if(!myF1TSC)
10323     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
10324   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10325   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
10326 }
10327
10328 /*!
10329  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
10330  *  \param [in] pos - a time step id.
10331  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
10332  *          delete this field using decrRef() as it is no more needed.
10333  *  \throw If \a pos is not a valid time step id.
10334  */
10335 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
10336 {
10337   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
10338   if(!item)
10339     {
10340       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
10341       throw INTERP_KERNEL::Exception(oss.str());
10342     }
10343   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
10344   if(itemC)
10345     {
10346       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
10347       ret->shallowCpyGlobs(*this);
10348       return ret.retn();
10349     }
10350   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
10351   throw INTERP_KERNEL::Exception(oss.str());
10352 }
10353
10354 /*!
10355  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
10356  * the given field is checked if its elements are sorted suitable for writing to MED file
10357  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10358  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10359  *  \param [in] field - the field to add to \a this.
10360  *  \throw If the name of \a field is empty.
10361  *  \throw If the data array of \a field is not set.
10362  *  \throw If existing time steps have different name or number of components than \a field.
10363  *  \throw If the underlying mesh of \a field has no name.
10364  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10365  */
10366 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
10367 {
10368   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10369   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
10370 }
10371
10372 /*!
10373  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10374  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10375  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10376  * and \a profile.
10377  *
10378  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10379  * A new profile is added only if no equal profile is missing.
10380  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10381  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10382  *  \param [in] arrOfVals - the values of the field \a field used.
10383  *  \param [in] mesh - the supporting mesh of \a field.
10384  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10385  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10386  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10387  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10388  *  \throw If the data array of \a field is not set.
10389  *  \throw If the data array of \a this is already allocated but has different number of
10390  *         components than \a field.
10391  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10392  *  \sa setFieldNoProfileSBT()
10393  */
10394 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10395 {
10396   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10397   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10398 }
10399
10400 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10401 {
10402   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10403   if(!pt)
10404     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10405   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10406   if(!ret)
10407     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 !");
10408   return ret;
10409 }
10410
10411 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10412 {
10413   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10414   if(!pt)
10415     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10416   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10417   if(!ret)
10418     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 !");
10419   return ret;
10420 }
10421
10422 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10423 {
10424   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10425 }
10426
10427 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10428 {
10429 }
10430
10431 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10432 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10433 {
10434 }
10435 catch(INTERP_KERNEL::Exception& e)
10436 { throw e; }
10437
10438 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10439 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10440 {
10441 }
10442 catch(INTERP_KERNEL::Exception& e)
10443 { throw e; }
10444
10445 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10446 {
10447   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10448 }
10449
10450 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10451 {
10452   return MEDFileIntFieldMultiTS::New();
10453 }
10454
10455 //= MEDFileFields
10456
10457 MEDFileFields *MEDFileFields::New()
10458 {
10459   return new MEDFileFields;
10460 }
10461
10462 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10463 {
10464   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10465   return New(fid,loadAll);
10466 }
10467
10468 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
10469 {
10470   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10471   return NewWithDynGT(fid,se,loadAll);
10472 }
10473
10474 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
10475 {
10476   if(!se)
10477     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
10478   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
10479   return new MEDFileFields(fid,loadAll,0,entities);
10480 }
10481
10482 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10483 {
10484   return new MEDFileFields(fid,loadAll,0,0);
10485 }
10486
10487 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10488 {
10489   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10490   return new MEDFileFields(fid,loadAll,ms,0);
10491 }
10492
10493 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10494 {
10495   MEDFileUtilities::CheckFileForRead(fileName);
10496   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10497   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10498   return new MEDFileFields(fid,loadAll,0,ent);
10499 }
10500
10501 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10502 {
10503   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10504   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10505   return ret;
10506 }
10507
10508 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10509 {
10510   std::vector<const BigMemoryObject *> ret;
10511   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10512     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10513   return ret;
10514 }
10515
10516 MEDFileFields *MEDFileFields::deepCopy() const
10517 {
10518   MCAuto<MEDFileFields> ret(shallowCpy());
10519   std::size_t i(0);
10520   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10521     {
10522       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10523         ret->_fields[i]=(*it)->deepCopy();
10524     }
10525   ret->deepCpyGlobs(*this);
10526   return ret.retn();
10527 }
10528
10529 MEDFileFields *MEDFileFields::shallowCpy() const
10530 {
10531   return new MEDFileFields(*this);
10532 }
10533
10534 /*!
10535  * 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
10536  * 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.
10537  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10538  *
10539  * \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.
10540  * \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.
10541  * 
10542  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10543  */
10544 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10545 {
10546   std::set< std::pair<int,int> > s;
10547   bool firstShot=true;
10548   areThereSomeForgottenTS=false;
10549   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10550     {
10551       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10552         continue;
10553       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10554       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10555       if(firstShot)
10556         { s=s1; firstShot=false; }
10557       else
10558         {
10559           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10560           if(s!=s2)
10561             areThereSomeForgottenTS=true;
10562           s=s2;
10563         }
10564     }
10565   std::vector< std::pair<int,int> > ret;
10566   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10567   return ret;
10568 }
10569
10570 int MEDFileFields::getNumberOfFields() const
10571 {
10572   return _fields.size();
10573 }
10574
10575 std::vector<std::string> MEDFileFields::getFieldsNames() const
10576 {
10577   std::vector<std::string> ret(_fields.size());
10578   int i(0);
10579   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10580     {
10581       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10582       if(f)
10583         {
10584           ret[i]=f->getName();
10585         }
10586       else
10587         {
10588           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10589           throw INTERP_KERNEL::Exception(oss.str());
10590         }
10591     }
10592   return ret;
10593 }
10594
10595 std::vector<std::string> MEDFileFields::getMeshesNames() const
10596 {
10597   std::vector<std::string> ret;
10598   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10599     {
10600       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10601       if(cur)
10602         ret.push_back(cur->getMeshName());
10603     }
10604   return ret;
10605 }
10606
10607 std::string MEDFileFields::simpleRepr() const
10608 {
10609   std::ostringstream oss;
10610   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10611   simpleRepr(0,oss);
10612   return oss.str();
10613 }
10614
10615 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10616 {
10617   int nbOfFields(getNumberOfFields());
10618   std::string startLine(bkOffset,' ');
10619   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10620   int i=0;
10621   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10622     {
10623       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10624       if(cur)
10625         {
10626           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10627         }
10628       else
10629         {
10630           oss << startLine << "  - not defined !" << std::endl;
10631         }
10632     }
10633   i=0;
10634   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10635     {
10636       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10637       std::string chapter(17,'0'+i);
10638       oss << startLine << chapter << std::endl;
10639       if(cur)
10640         {
10641           cur->simpleRepr(bkOffset+2,oss,i);
10642         }
10643       else
10644         {
10645           oss << startLine << "  - not defined !" << std::endl;
10646         }
10647       oss << startLine << chapter << std::endl;
10648     }
10649   simpleReprGlobs(oss);
10650 }
10651
10652 MEDFileFields::MEDFileFields()
10653 {
10654 }
10655
10656 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10657 try:MEDFileFieldGlobsReal(fid)
10658 {
10659   int nbFields(MEDnField(fid));
10660   _fields.resize(nbFields);
10661   med_field_type typcha;
10662   for(int i=0;i<nbFields;i++)
10663     {
10664       std::vector<std::string> infos;
10665       std::string fieldName,dtunit;
10666       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit));
10667       switch(typcha)
10668       {
10669         case MED_FLOAT64:
10670           {
10671             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10672             break;
10673           }
10674         case MED_INT32:
10675           {
10676             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10677             break;
10678           }
10679         default:
10680           {
10681             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] !";
10682             throw INTERP_KERNEL::Exception(oss.str());
10683           }
10684       }
10685     }
10686   loadAllGlobals(fid);
10687 }
10688 catch(INTERP_KERNEL::Exception& e)
10689 {
10690     throw e;
10691 }
10692
10693 void MEDFileFields::writeLL(med_idt fid) const
10694 {
10695   int i=0;
10696   writeGlobals(fid,*this);
10697   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10698     {
10699       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10700       if(!elt)
10701         {
10702           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10703           throw INTERP_KERNEL::Exception(oss.str());
10704         }
10705       elt->writeLL(fid,*this);
10706     }
10707 }
10708
10709 /*!
10710  * This method alloc the arrays and load potentially huge arrays contained in this field.
10711  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10712  * This method can be also called to refresh or reinit values from a file.
10713  * 
10714  * \throw If the fileName is not set or points to a non readable MED file.
10715  */
10716 void MEDFileFields::loadArrays()
10717 {
10718   if(getFileName().empty())
10719     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10720   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10721   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10722     {
10723       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10724       if(elt)
10725         elt->loadBigArraysRecursively(fid,*elt);
10726     }
10727 }
10728
10729 /*!
10730  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10731  * But once data loaded once, this method does nothing.
10732  * 
10733  * \throw If the fileName is not set or points to a non readable MED file.
10734  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10735  */
10736 void MEDFileFields::loadArraysIfNecessary()
10737 {
10738   if(!getFileName().empty())
10739     {
10740       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10741       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10742         {
10743           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10744           if(elt)
10745             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10746         }
10747     }
10748 }
10749
10750 /*!
10751  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10752  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10753  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10754  * 
10755  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10756  */
10757 void MEDFileFields::unloadArrays()
10758 {
10759   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10760     {
10761       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10762       if(elt)
10763         elt->unloadArrays();
10764     }
10765 }
10766
10767 /*!
10768  * 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.
10769  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10770  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10771  * 
10772  * \sa MEDFileFields::loadArraysIfNecessary
10773  */
10774 void MEDFileFields::unloadArraysWithoutDataLoss()
10775 {
10776   if(!getFileName().empty())
10777     unloadArrays();
10778 }
10779
10780 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10781 {
10782   std::vector<std::string> ret;
10783   std::set<std::string> ret2;
10784   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10785     {
10786       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10787       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10788         if(ret2.find(*it2)==ret2.end())
10789           {
10790             ret.push_back(*it2);
10791             ret2.insert(*it2);
10792           }
10793     }
10794   return ret;
10795 }
10796
10797 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10798 {
10799   std::vector<std::string> ret;
10800   std::set<std::string> ret2;
10801   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10802     {
10803       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10804       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10805         if(ret2.find(*it2)==ret2.end())
10806           {
10807             ret.push_back(*it2);
10808             ret2.insert(*it2);
10809           }
10810     }
10811   return ret;
10812 }
10813
10814 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10815 {
10816   std::vector<std::string> ret;
10817   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10818     {
10819       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
10820       ret.insert(ret.end(),tmp.begin(),tmp.end());
10821     }
10822   return ret;
10823 }
10824
10825 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10826 {
10827   std::vector<std::string> ret;
10828   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10829     {
10830       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10831       ret.insert(ret.end(),tmp.begin(),tmp.end());
10832     }
10833   return ret;
10834 }
10835
10836 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10837 {
10838   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10839     (*it)->changePflsRefsNamesGen2(mapOfModif);
10840 }
10841
10842 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10843 {
10844   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10845     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10846 }
10847
10848 void MEDFileFields::resize(int newSize)
10849 {
10850   _fields.resize(newSize);
10851 }
10852
10853 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10854 {
10855   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10856     pushField(*it);
10857 }
10858
10859 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10860 {
10861   if(!field)
10862     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10863   _fields.push_back(field->getContent());
10864   appendGlobs(*field,1e-12);
10865 }
10866
10867 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10868 {
10869   if(!field)
10870     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10871   if(i>=(int)_fields.size())
10872     _fields.resize(i+1);
10873   _fields[i]=field->getContent();
10874   appendGlobs(*field,1e-12);
10875 }
10876
10877 void MEDFileFields::destroyFieldAtPos(int i)
10878 {
10879   destroyFieldsAtPos(&i,&i+1);
10880 }
10881
10882 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10883 {
10884   std::vector<bool> b(_fields.size(),true);
10885   for(const int *i=startIds;i!=endIds;i++)
10886     {
10887       if(*i<0 || *i>=(int)_fields.size())
10888         {
10889           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10890           throw INTERP_KERNEL::Exception(oss.str());
10891         }
10892       b[*i]=false;
10893     }
10894   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10895   std::size_t j=0;
10896   for(std::size_t i=0;i<_fields.size();i++)
10897     if(b[i])
10898       fields[j++]=_fields[i];
10899   _fields=fields;
10900 }
10901
10902 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10903 {
10904   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10905   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
10906   std::vector<bool> b(_fields.size(),true);
10907   int k=bg;
10908   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10909     {
10910       if(k<0 || k>=(int)_fields.size())
10911         {
10912           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10913           throw INTERP_KERNEL::Exception(oss.str());
10914         }
10915       b[k]=false;
10916     }
10917   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10918   std::size_t j(0);
10919   for(std::size_t i=0;i<_fields.size();i++)
10920     if(b[i])
10921       fields[j++]=_fields[i];
10922   _fields=fields;
10923 }
10924
10925 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10926 {
10927   bool ret(false);
10928   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10929     {
10930       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10931       if(cur)
10932         ret=cur->changeMeshNames(modifTab) || ret;
10933     }
10934   return ret;
10935 }
10936
10937 /*!
10938  * \param [in] meshName the name of the mesh that will be renumbered.
10939  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10940  *             This code corresponds to the distribution of types in the corresponding mesh.
10941  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10942  * \param [in] renumO2N the old to new renumber array.
10943  * \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 
10944  *         field in \a this.
10945  */
10946 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10947 {
10948   bool ret(false);
10949   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10950     {
10951       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10952       if(fmts)
10953         {
10954           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10955         }
10956     }
10957   return ret;
10958 }
10959
10960 /*!
10961  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10962  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10963  *
10964  * \return A new object that the caller is responsible to deallocate.
10965  */
10966 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10967 {
10968   if(!mm)
10969     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10970   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10971   int nbFields(getNumberOfFields());
10972   for(int i=0;i<nbFields;i++)
10973     {
10974       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
10975       if(!fmts)
10976         {
10977           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10978           throw INTERP_KERNEL::Exception(oss.str());
10979         }
10980       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10981       fsOut->pushField(fmtsOut);
10982     }
10983   return fsOut.retn();
10984 }
10985
10986 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10987 {
10988   if(i<0 || i>=(int)_fields.size())
10989     {
10990       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10991       throw INTERP_KERNEL::Exception(oss.str());
10992     }
10993   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10994   if(!fmts)
10995     return 0;
10996   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10997   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
10998   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
10999   if(fmtsC)
11000     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
11001   else if(fmtsC2)
11002     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
11003   else
11004     {
11005       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
11006       throw INTERP_KERNEL::Exception(oss.str());
11007     }
11008   ret->shallowCpyGlobs(*this);
11009   return ret.retn();
11010 }
11011
11012 /*!
11013  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
11014  * This method is accessible in python using __getitem__ with a list in input.
11015  * \return a new object that the caller should deal with.
11016  */
11017 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
11018 {
11019   MCAuto<MEDFileFields> ret=shallowCpy();
11020   std::size_t sz=std::distance(startIds,endIds);
11021   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
11022   int j=0;
11023   for(const int *i=startIds;i!=endIds;i++,j++)
11024     {
11025       if(*i<0 || *i>=(int)_fields.size())
11026         {
11027           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
11028           throw INTERP_KERNEL::Exception(oss.str());
11029         }
11030       fields[j]=_fields[*i];
11031     }
11032   ret->_fields=fields;
11033   return ret.retn();
11034 }
11035
11036 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
11037 {
11038   return getFieldAtPos(getPosFromFieldName(fieldName));
11039 }
11040
11041 /*!
11042  * This method removes, if any, fields in \a this having no time steps.
11043  * 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.
11044  * 
11045  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
11046  */
11047 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
11048 {
11049   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
11050   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11051     {
11052       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
11053       if(elt)
11054         {
11055           if(elt->getNumberOfTS()>0)
11056             newFields.push_back(*it);
11057         }
11058     }
11059   if(_fields.size()==newFields.size())
11060     return false;
11061   _fields=newFields;
11062   return true;
11063 }
11064
11065 /*!
11066  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
11067  * This method can be seen as a filter applied on \a this, that returns an object containing
11068  * 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
11069  * shallow copied from \a this.
11070  * 
11071  * \param [in] meshName - the name of the mesh on w
11072  * \return a new object that the caller should deal with.
11073  */
11074 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
11075 {
11076   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11077   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11078     {
11079       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11080       if(!cur)
11081         continue;
11082       if(cur->getMeshName()==meshName)
11083         {
11084           cur->incrRef();
11085           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
11086           ret->_fields.push_back(cur2);
11087         }
11088     }
11089   ret->shallowCpyOnlyUsedGlobs(*this);
11090   return ret.retn();
11091 }
11092
11093 /*!
11094  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
11095  * Input time steps are specified using a pair of integer (iteration, order).
11096  * 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,
11097  * but for each multitimestep only the time steps in \a timeSteps are kept.
11098  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
11099  * 
11100  * The returned object points to shallow copy of elements in \a this.
11101  * 
11102  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
11103  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
11104  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
11105  */
11106 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11107 {
11108   MCAuto<MEDFileFields> ret(MEDFileFields::New());
11109   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11110     {
11111       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11112       if(!cur)
11113         continue;
11114       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
11115       ret->_fields.push_back(elt);
11116     }
11117   ret->shallowCpyOnlyUsedGlobs(*this);
11118   return ret.retn();
11119 }
11120
11121 /*!
11122  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
11123  */
11124 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
11125 {
11126   MCAuto<MEDFileFields> ret=MEDFileFields::New();
11127   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11128     {
11129       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
11130       if(!cur)
11131         continue;
11132       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
11133       if(elt->getNumberOfTS()!=0)
11134         ret->_fields.push_back(elt);
11135     }
11136   ret->shallowCpyOnlyUsedGlobs(*this);
11137   return ret.retn();
11138 }
11139
11140 bool MEDFileFields::presenceOfStructureElements() const
11141 {
11142   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11143     if((*it).isNotNull())
11144       if((*it)->presenceOfStructureElements())
11145         return true;
11146   return false;
11147 }
11148
11149 void MEDFileFields::killStructureElements()
11150 {
11151   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11152   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11153     if((*it).isNotNull())
11154       {
11155         if((*it)->presenceOfStructureElements())
11156           {
11157             if(!(*it)->onlyStructureElements())
11158               {
11159                 (*it)->killStructureElements();
11160                 ret.push_back(*it);
11161               }
11162           }
11163         else
11164           {
11165             ret.push_back(*it);
11166           }
11167       }
11168   _fields=ret;
11169 }
11170
11171 void MEDFileFields::keepOnlyStructureElements()
11172 {
11173   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11174   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11175     if((*it).isNotNull())
11176       {
11177         if((*it)->presenceOfStructureElements())
11178           {
11179             if(!(*it)->onlyStructureElements())
11180               (*it)->keepOnlyStructureElements();
11181             ret.push_back(*it);
11182           }
11183       }
11184   _fields=ret;
11185 }
11186
11187 void MEDFileFields::keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName)
11188 {
11189   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
11190   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
11191     if((*it).isNotNull())
11192       {
11193         if((*it)->getMeshName()!=meshName)
11194           continue;
11195         std::vector< std::pair<std::string,std::string> > ps;
11196         (*it)->getMeshSENames(ps);
11197         std::pair<std::string,std::string> p(meshName,seName);
11198         if(std::find(ps.begin(),ps.end(),p)!=ps.end())
11199           (*it)->keepOnlyOnSE(seName);
11200         ret.push_back(*it);
11201       }
11202   _fields=ret;
11203 }
11204
11205 void MEDFileFields::getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const
11206 {
11207   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
11208     if((*it).isNotNull())
11209       (*it)->getMeshSENames(ps);
11210 }
11211
11212 MCAuto<MEDFileFields> MEDFileFields::partOfThisOnStructureElements() const
11213 {
11214   MCAuto<MEDFileFields> ret(deepCopy());
11215   ret->keepOnlyStructureElements();
11216   return ret;
11217 }
11218
11219 MCAuto<MEDFileFields> MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const
11220 {
11221   MCAuto<MEDFileFields> ret(deepCopy());
11222   ret->keepOnlyOnMeshSE(meshName,seName);
11223   return ret;
11224 }
11225
11226 void MEDFileFields::aggregate(const MEDFileFields& other)
11227 {
11228   int nbFieldsToAdd(other.getNumberOfFields());
11229   std::vector<std::string> fsn(getFieldsNames());
11230   for(int i=0;i<nbFieldsToAdd;i++)
11231     {
11232       MCAuto<MEDFileAnyTypeFieldMultiTS> elt(other.getFieldAtPos(i));
11233       std::string name(elt->getName());
11234       if(std::find(fsn.begin(),fsn.end(),name)!=fsn.end())
11235         {
11236           std::ostringstream oss; oss << "MEDFileFields::aggregate : name \"" << name << "\" already appears !";
11237           throw INTERP_KERNEL::Exception(oss.str());
11238         }
11239       pushField(elt);
11240     }
11241 }
11242
11243 MEDFileFieldsIterator *MEDFileFields::iterator()
11244 {
11245   return new MEDFileFieldsIterator(this);
11246 }
11247
11248 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
11249 {
11250   std::string tmp(fieldName);
11251   std::vector<std::string> poss;
11252   for(std::size_t i=0;i<_fields.size();i++)
11253     {
11254       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
11255       if(f)
11256         {
11257           std::string fname(f->getName());
11258           if(tmp==fname)
11259             return i;
11260           else
11261             poss.push_back(fname);
11262         }
11263     }
11264   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
11265   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
11266   oss << " !";
11267   throw INTERP_KERNEL::Exception(oss.str());
11268 }
11269
11270 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
11271 {
11272   if(fs)
11273     {
11274       fs->incrRef();
11275       _nb_iter=fs->getNumberOfFields();
11276     }
11277 }
11278
11279 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
11280 {
11281 }
11282
11283 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
11284 {
11285   if(_iter_id<_nb_iter)
11286     {
11287       MEDFileFields *fs(_fs);
11288       if(fs)
11289         return fs->getFieldAtPos(_iter_id++);
11290       else
11291         return 0;
11292     }
11293   else
11294     return 0;
11295 }