]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileField.cxx
Salome HOME
Field read part done. Mesh part 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 void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const
1724 {
1725   throw INTERP_KERNEL::Exception("not implemented yet !");
1726 }
1727
1728 void MEDFileFieldPerMeshPerTypeDyn::entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const
1729 {
1730   gt=getDynGT();
1731   ent=MED_STRUCT_ELEMENT;
1732 }
1733
1734 INTERP_KERNEL::NormalizedCellType MEDFileFieldPerMeshPerTypeDyn::getGeoType() const
1735 {
1736   throw INTERP_KERNEL::Exception("not implemented yet !");
1737 }
1738
1739 void MEDFileFieldPerMeshPerTypeDyn::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1740 {
1741   const char startLine[]="  ## ";
1742   std::string startLine2(bkOffset,' ');
1743   std::string startLine3(startLine2);
1744   startLine3+=startLine;
1745   oss << startLine3 << "Entry geometry type #" << id << " is lying on geometry STRUCTURE_ELEMENT type " << getDynGT() << "." << std::endl;
1746   oss << startLine3 << "Entry is defined on " <<  _field_pm_pt_pd.size() << " localizations." << std::endl;
1747   int i=0;
1748   for(std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,i++)
1749     {
1750       if((*it).isNotNull())
1751         (*it)->simpleRepr(bkOffset,oss,i);
1752       else
1753         {
1754           oss << startLine2 << "    ## " << "Localization #" << i << " is empty !" << std::endl;
1755         }
1756     }
1757 }
1758
1759 std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const
1760 {
1761   throw INTERP_KERNEL::Exception("not implemented yet !");
1762 }
1763
1764 MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const
1765 {
1766   throw INTERP_KERNEL::Exception("not implemented yet !");
1767 }
1768
1769 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
1770 {
1771   throw INTERP_KERNEL::Exception("not implemented yet !");
1772 }
1773
1774 //////////////////////////////////////////////////
1775
1776 MEDFileFieldPerMesh *MEDFileFieldPerMesh::NewOnRead(med_idt fid, MEDFileAnyTypeField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder, const MEDFileFieldNameScope& nasc, const MEDFileMesh *mm, const MEDFileEntities *entities)
1777 {
1778   return new MEDFileFieldPerMesh(fid,fath,meshCsit,meshIteration,meshOrder,nasc,mm,entities);
1779 }
1780
1781 MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh)
1782 {
1783   return new MEDFileFieldPerMesh(fath,mesh);
1784 }
1785
1786 std::size_t MEDFileFieldPerMesh::getHeapMemorySizeWithoutChildren() const
1787 {
1788   return _mesh_name.capacity()+_field_pm_pt.capacity()*sizeof(MCAuto< MEDFileFieldPerMeshPerType >);
1789 }
1790
1791 std::vector<const BigMemoryObject *> MEDFileFieldPerMesh::getDirectChildrenWithNull() const
1792 {
1793   std::vector<const BigMemoryObject *> ret;
1794   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1795     ret.push_back(*it);
1796   return ret;
1797 }
1798
1799 MEDFileFieldPerMesh *MEDFileFieldPerMesh::deepCopy(MEDFileAnyTypeField1TSWithoutSDA *father) const
1800 {
1801   MCAuto< MEDFileFieldPerMesh > ret=new MEDFileFieldPerMesh(*this);
1802   ret->_father=father;
1803   std::size_t i=0;
1804   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1805     {
1806       if((*it).isNotNull())
1807         ret->_field_pm_pt[i]=(*it)->deepCopy((MEDFileFieldPerMesh *)(ret));
1808     }
1809   return ret.retn();
1810 }
1811
1812 void MEDFileFieldPerMesh::simpleRepr(int bkOffset, std::ostream& oss, int id) const
1813 {
1814   std::string startLine(bkOffset,' ');
1815   oss << startLine << "## Field part (" << id << ") lying on mesh \"" << _mesh_name << "\", Mesh iteration=" << _mesh_iteration << ". Mesh order=" << _mesh_order << "." << std::endl;
1816   oss << startLine << "## Field is defined on " << _field_pm_pt.size() << " types." << std::endl;
1817   int i=0;
1818   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
1819     {
1820       if((*it).isNotNull())
1821         (*it)->simpleRepr(bkOffset,oss,i);
1822       else
1823         {
1824           oss << startLine << "  ## Entry geometry type #" << i << " is empty !" << std::endl;
1825         }
1826     }
1827 }
1828
1829 void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh)
1830 {
1831   _mesh_name=mesh->getName();
1832   mesh->getTime(_mesh_iteration,_mesh_order);
1833 }
1834
1835 void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vector<int>& code, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1836 {
1837   int nbOfTypes=code.size()/3;
1838   int offset=0;
1839   for(int i=0;i<nbOfTypes;i++)
1840     {
1841       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1842       int nbOfCells=code[3*i+1];
1843       int pos=addNewEntryIfNecessary(type);
1844       _field_pm_pt[pos]->assignFieldNoProfile(start,offset,nbOfCells,field,arr,glob,nasc);
1845       offset+=nbOfCells;
1846     }
1847 }
1848
1849 /*!
1850  * This method is the most general one. No optimization is done here.
1851  * \param [in] multiTypePfl is the end user profile specified in high level API
1852  * \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].
1853  * \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.
1854  * \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.
1855  * \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.
1856  * \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.
1857  */
1858 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)
1859 {
1860   int nbOfTypes(code.size()/3);
1861   for(int i=0;i<nbOfTypes;i++)
1862     {
1863       INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)code[3*i];
1864       int pos=addNewEntryIfNecessary(type);
1865       DataArrayInt *pfl=0;
1866       if(code[3*i+2]!=-1)
1867         pfl=idsPerType[code[3*i+2]];
1868       int nbOfTupes2=code2.size()/3;
1869       int found=0;
1870       for(;found<nbOfTupes2;found++)
1871         if(code[3*i]==code2[3*found])
1872           break;
1873       if(found==nbOfTupes2)
1874         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::assignFieldProfile : internal problem ! Should never happen ! Please report bug to anthony.geay@cea.fr !");
1875       _field_pm_pt[pos]->assignFieldProfile(nbOfTypes==1,start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,arr,mesh,glob,nasc);
1876     }
1877 }
1878
1879 void MEDFileFieldPerMesh::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
1880 {
1881   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1882   _field_pm_pt[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
1883 }
1884
1885 void MEDFileFieldPerMesh::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
1886 {
1887   int pos=addNewEntryIfNecessary(INTERP_KERNEL::NORM_ERROR);
1888   _field_pm_pt[pos]->assignNodeFieldProfile(start,pfl,field,arr,glob,nasc);
1889 }
1890
1891 void MEDFileFieldPerMesh::loadOnlyStructureOfDataRecursively(med_idt fid, int& start, const MEDFileFieldNameScope& nasc)
1892 {
1893   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1894     (*it)->loadOnlyStructureOfDataRecursively(fid,start,nasc);
1895 }
1896
1897 void MEDFileFieldPerMesh::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
1898 {
1899   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1900     (*it)->loadBigArraysRecursively(fid,nasc);
1901 }
1902
1903 void MEDFileFieldPerMesh::writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const
1904 {
1905   int nbOfTypes=_field_pm_pt.size();
1906   for(int i=0;i<nbOfTypes;i++)
1907     {
1908       _field_pm_pt[i]->copyOptionsFrom(*this);
1909       _field_pm_pt[i]->writeLL(fid,nasc);
1910     }
1911 }
1912
1913 void MEDFileFieldPerMesh::getDimension(int& dim) const
1914 {
1915   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1916     (*it)->getDimension(dim);
1917 }
1918
1919 bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const
1920 {
1921   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1922     if(!(*it)->isUniqueLevel(dim))
1923       return false;
1924   return true;
1925 }
1926
1927 void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set<TypeOfField>& types) const
1928 {
1929   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1930     (*it)->fillTypesOfFieldAvailable(types);
1931 }
1932
1933 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
1934 {
1935   int sz=_field_pm_pt.size();
1936   std::vector< std::vector<std::pair<int,int> > > ret(sz);
1937   types.resize(sz); typesF.resize(sz); pfls.resize(sz); locs.resize(sz);
1938   for(int i=0;i<sz;i++)
1939     {
1940       types[i]=_field_pm_pt[i]->getGeoType();
1941       _field_pm_pt[i]->fillFieldSplitedByType(ret[i],typesF[i],pfls[i],locs[i]);
1942     }
1943   return ret;
1944 }
1945
1946 double MEDFileFieldPerMesh::getTime() const
1947 {
1948   int tmp1,tmp2;
1949   return _father->getTime(tmp1,tmp2);
1950 }
1951
1952 int MEDFileFieldPerMesh::getIteration() const
1953 {
1954   return _father->getIteration();
1955 }
1956
1957 int MEDFileFieldPerMesh::getOrder() const
1958 {
1959   return _father->getOrder();
1960 }
1961
1962 int MEDFileFieldPerMesh::getNumberOfComponents() const
1963 {
1964   return _father->getNumberOfComponents();
1965 }
1966
1967 bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const
1968 {
1969   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
1970     {
1971       if((*it).isNull())
1972         continue;
1973       if((*it)->presenceOfMultiDiscPerGeoType())
1974         return true;
1975     }
1976   return false;
1977 }
1978
1979 DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray()
1980 {
1981   if(!_father)
1982     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1983   return _father->getOrCreateAndGetArray();
1984 }
1985
1986 const DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() const
1987 {
1988   if(!_father)
1989     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getOrCreateAndGetArray : no father ! internal error !");
1990   return _father->getOrCreateAndGetArray();
1991 }
1992
1993 const std::vector<std::string>& MEDFileFieldPerMesh::getInfo() const
1994 {
1995   return _father->getInfo();
1996 }
1997
1998 /*!
1999  * type,geoTypes,dads,pfls,locs are input parameters. They should have the same size.
2000  * 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.
2001  * It returns 2 output vectors :
2002  * - 'code' of size 3*sz where sz is the number of different values into 'geoTypes'
2003  * - 'notNullPfls' contains sz2 values that are extracted from 'pfls' in which null profiles have been removed.
2004  * 'code' and 'notNullPfls' are in MEDCouplingUMesh::checkTypeConsistencyAndContig format.
2005  */
2006 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)
2007 {
2008   int notNullPflsSz=0;
2009   int nbOfArrs=geoTypes.size();
2010   for(int i=0;i<nbOfArrs;i++)
2011     if(pfls[i])
2012       notNullPflsSz++;
2013   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes3(geoTypes.begin(),geoTypes.end());
2014   int nbOfDiffGeoTypes=geoTypes3.size();
2015   code.resize(3*nbOfDiffGeoTypes);
2016   notNullPfls.resize(notNullPflsSz);
2017   notNullPflsSz=0;
2018   int j=0;
2019   for(int i=0;i<nbOfDiffGeoTypes;i++)
2020     {
2021       int startZone=j;
2022       INTERP_KERNEL::NormalizedCellType refType=geoTypes[j];
2023       std::vector<const DataArrayInt *> notNullTmp;
2024       if(pfls[j])
2025         notNullTmp.push_back(pfls[j]);
2026       j++;
2027       for(;j<nbOfArrs;j++)
2028         if(geoTypes[j]==refType)
2029           {
2030             if(pfls[j])
2031               notNullTmp.push_back(pfls[j]);
2032           }
2033         else
2034           break;
2035       std::vector< std::pair<int,int> > tmpDads(dads.begin()+startZone,dads.begin()+j);
2036       std::vector<const DataArrayInt *> tmpPfls(pfls.begin()+startZone,pfls.begin()+j);
2037       std::vector<int> tmpLocs(locs.begin()+startZone,locs.begin()+j);
2038       code[3*i]=(int)refType;
2039       std::vector<INTERP_KERNEL::NormalizedCellType> refType2(1,refType);
2040       code[3*i+1]=ComputeNbOfElems(glob,type,refType2,tmpDads,tmpLocs);
2041       if(notNullTmp.empty())
2042         code[3*i+2]=-1;
2043       else
2044         {
2045           notNullPfls[notNullPflsSz]=DataArrayInt::Aggregate(notNullTmp);
2046           code[3*i+2]=notNullPflsSz++;
2047         }
2048     }
2049 }
2050
2051 /*!
2052  * 'dads' 'geoTypes' and 'locs' are input parameters that should have same size sz. sz should be >=1.
2053  */
2054 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)
2055 {
2056   int sz=dads.size();
2057   int ret=0;
2058   for(int i=0;i<sz;i++)
2059     {
2060       if(locs[i]==-1)
2061         {
2062           if(type!=ON_GAUSS_NE)
2063             ret+=dads[i].second-dads[i].first;
2064           else
2065             {
2066               const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(geoTypes[i]);
2067               ret+=(dads[i].second-dads[i].first)/cm.getNumberOfNodes();
2068             }
2069         }
2070       else
2071         {
2072           int nbOfGaussPtPerCell=glob->getNbOfGaussPtPerCell(locs[i]);
2073           ret+=(dads[i].second-dads[i].first)/nbOfGaussPtPerCell;
2074         }
2075     }
2076   return ret;
2077 }
2078
2079 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsed() const
2080 {
2081   std::vector<std::string> ret;
2082   std::set<std::string> ret2;
2083   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2084     {
2085       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
2086       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2087         if(ret2.find(*it2)==ret2.end())
2088           {
2089             ret.push_back(*it2);
2090             ret2.insert(*it2);
2091           }
2092     }
2093   return ret;
2094 }
2095
2096 std::vector<std::string> MEDFileFieldPerMesh::getPflsReallyUsedMulti() const
2097 {
2098   std::vector<std::string> ret;
2099   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2100     {
2101       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
2102       ret.insert(ret.end(),tmp.begin(),tmp.end());
2103     }
2104   return ret;
2105 }
2106
2107 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsed() const
2108 {
2109   std::vector<std::string> ret;
2110   std::set<std::string> ret2;
2111   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2112     {
2113       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
2114       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
2115         if(ret2.find(*it2)==ret2.end())
2116           {
2117             ret.push_back(*it2);
2118             ret2.insert(*it2);
2119           }
2120     }
2121   return ret;
2122 }
2123
2124 std::vector<std::string> MEDFileFieldPerMesh::getLocsReallyUsedMulti() const
2125 {
2126   std::vector<std::string> ret;
2127   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2128     {
2129       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
2130       ret.insert(ret.end(),tmp.begin(),tmp.end());
2131     }
2132   return ret;
2133 }
2134
2135 bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
2136 {
2137   for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
2138     {
2139       if((*it).first==_mesh_name)
2140         {
2141           _mesh_name=(*it).second;
2142           return true;
2143         }
2144     }
2145   return false;
2146 }
2147
2148 bool MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
2149                                                       MEDFileFieldGlobsReal& glob)
2150 {
2151   if(_mesh_name!=meshName)
2152     return false;
2153   std::set<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2154   for(std::size_t i=0;i<oldCode.size()/3;i++) typesToKeep.insert((INTERP_KERNEL::NormalizedCellType)oldCode[3*i]);
2155   std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > > entries;
2156   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKept;
2157   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> otherEntries;
2158   getUndergroundDataArrayExt(entries);
2159   DataArray *arr0(getOrCreateAndGetArray());//tony
2160   if(!arr0)
2161     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values of field is null !");
2162   DataArrayDouble *arr(dynamic_cast<DataArrayDouble *>(arr0));//tony
2163   if(!arr0)
2164     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArray storing values is double ! Not managed for the moment !");
2165   int sz=0;
2166   if(!arr)
2167     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::renumberEntitiesLyingOnMesh : DataArrayDouble storing values of field is null !");
2168   for(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >::const_iterator it=entries.begin();it!=entries.end();it++)
2169     {
2170       if(typesToKeep.find((*it).first.first)!=typesToKeep.end())
2171         {
2172           entriesKept.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2173           sz+=(*it).second.second-(*it).second.first;
2174         }
2175       else
2176         otherEntries.push_back(getLeafGivenTypeAndLocId((*it).first.first,(*it).first.second));
2177     }
2178   MCAuto<DataArrayInt> renumDefrag=DataArrayInt::New(); renumDefrag->alloc(arr->getNumberOfTuples(),1); renumDefrag->fillWithZero();
2179   ////////////////////
2180   MCAuto<DataArrayInt> explicitIdsOldInMesh=DataArrayInt::New(); explicitIdsOldInMesh->alloc(sz,1);//sz is a majorant of the real size. A realloc will be done after
2181   int *workI2=explicitIdsOldInMesh->getPointer();
2182   int sz1=0,sz2=0,sid=1;
2183   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptML=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKept);
2184   // std::vector<int> tupleIdOfStartOfNewChuncksV(entriesKeptML.size());
2185   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator itL1=entriesKeptML.begin();itL1!=entriesKeptML.end();itL1++,sid++)
2186     {
2187       //  tupleIdOfStartOfNewChuncksV[sid-1]=sz2;
2188       MCAuto<DataArrayInt> explicitIdsOldInArr=DataArrayInt::New(); explicitIdsOldInArr->alloc(sz,1);
2189       int *workI=explicitIdsOldInArr->getPointer();
2190       for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*itL1).begin();itL2!=(*itL1).end();itL2++)
2191         {
2192           int delta1=(*itL2)->fillTupleIds(workI); workI+=delta1; sz1+=delta1;
2193           (*itL2)->setLocId(sz2);
2194           (*itL2)->_tmp_work1=(*itL2)->getStart();
2195           int delta2=(*itL2)->fillEltIdsFromCode(sz2,oldCode,glob,workI2); workI2+=delta2; sz2+=delta2;
2196         }
2197       renumDefrag->setPartOfValuesSimple3(sid,explicitIdsOldInArr->begin(),explicitIdsOldInArr->end(),0,1,1);
2198     }
2199   explicitIdsOldInMesh->reAlloc(sz2);
2200   int tupleIdOfStartOfNewChuncks=arr->getNumberOfTuples()-sz2;
2201   ////////////////////
2202   MCAuto<DataArrayInt> permArrDefrag=renumDefrag->buildPermArrPerLevel(); renumDefrag=0;
2203   // perform redispatching of non concerned MEDFileFieldPerMeshPerTypePerDisc
2204   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > otherEntriesNew;
2205   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=otherEntries.begin();it!=otherEntries.end();it++)
2206     {
2207       otherEntriesNew.push_back(MEDFileFieldPerMeshPerTypePerDisc::New(*(*it)));
2208       otherEntriesNew.back()->setNewStart(permArrDefrag->getIJ((*it)->getStart(),0));
2209       otherEntriesNew.back()->setLocId((*it)->getGeoType());
2210     }
2211   std::vector< MCAuto<MEDFileFieldPerMeshPerTypePerDisc> > entriesKeptNew;
2212   std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> entriesKeptNew2;
2213   for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator it=entriesKept.begin();it!=entriesKept.end();it++)
2214     {
2215       MCAuto<MEDFileFieldPerMeshPerTypePerDisc> elt=MEDFileFieldPerMeshPerTypePerDisc::New(*(*it));
2216       int newStart=elt->getLocId();
2217       elt->setLocId((*it)->getGeoType());
2218       elt->setNewStart(newStart);
2219       elt->_tmp_work1=permArrDefrag->getIJ(elt->_tmp_work1,0);
2220       entriesKeptNew.push_back(elt);
2221       entriesKeptNew2.push_back(elt);
2222     }
2223   MCAuto<DataArrayDouble> arr2=arr->renumber(permArrDefrag->getConstPointer());
2224   // perform redispatching of concerned MEDFileFieldPerMeshPerTypePerDisc -> values are in arr2
2225   MCAuto<DataArrayInt> explicitIdsNewInMesh=renumO2N->selectByTupleId(explicitIdsOldInMesh->begin(),explicitIdsOldInMesh->end());
2226   std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> > entriesKeptPerDisc=MEDFileFieldPerMeshPerTypePerDisc::SplitPerDiscretization(entriesKeptNew2);
2227   bool ret=false;
2228   for(std::vector< std::vector< const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it4=entriesKeptPerDisc.begin();it4!=entriesKeptPerDisc.end();it4++)
2229     {
2230       sid=0;
2231       /*for(std::vector< const MEDFileFieldPerMeshPerTypePerDisc *>::const_iterator itL2=(*it4).begin();itL2!=(*it4).end();itL2++)
2232         {
2233           MEDFileFieldPerMeshPerTypePerDisc *curNC=const_cast<MEDFileFieldPerMeshPerTypePerDisc *>(*itL2);
2234           curNC->setNewStart(permArrDefrag->getIJ((*itL2)->getStart(),0)-tupleIdOfStartOfNewChuncks+tupleIdOfStartOfNewChuncksV[sid]);
2235           }*/
2236       ret=MEDFileFieldPerMeshPerTypePerDisc::RenumberChunks(tupleIdOfStartOfNewChuncks,*it4,explicitIdsNewInMesh,newCode,
2237                                                             glob,arr2,otherEntriesNew) || ret;
2238     }
2239   if(!ret)
2240     return false;
2241   // Assign new dispatching
2242   assignNewLeaves(otherEntriesNew);
2243   arr->deepCopyFrom(*arr2);
2244   return true;
2245 }
2246
2247 /*!
2248  * \param [in,out] globalNum a global numbering counter for the renumbering.
2249  * \param [out] its - list of pair (start,stop) kept
2250  */
2251 void MEDFileFieldPerMesh::keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair<int,int> >& its)
2252 {
2253   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2254   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2255     {
2256       std::vector< std::pair<int,int> > its2;
2257       if((*it)->keepOnlySpatialDiscretization(tof,globalNum,its2))
2258         {
2259           ret.push_back(*it);
2260           its.insert(its.end(),its2.begin(),its2.end());
2261         }
2262     }
2263   _field_pm_pt=ret;
2264 }
2265
2266 /*!
2267  * \param [in,out] globalNum a global numbering counter for the renumbering.
2268  * \param [out] its - list of pair (start,stop) kept
2269  */
2270 void MEDFileFieldPerMesh::keepOnlyGaussDiscretization(std::size_t idOfDisc, int &globalNum, std::vector< std::pair<int,int> >& its)
2271 {
2272   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > ret;
2273   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2274     {
2275       std::vector< std::pair<int,int> > its2;
2276       if((*it)->keepOnlyGaussDiscretization(idOfDisc,globalNum,its2))
2277         {
2278           ret.push_back(*it);
2279           its.insert(its.end(),its2.begin(),its2.end());
2280         }
2281     }
2282   _field_pm_pt=ret;
2283 }
2284
2285 void MEDFileFieldPerMesh::assignNewLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves)
2286 {
2287   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > > types;
2288   for( std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >::const_iterator it=leaves.begin();it!=leaves.end();it++)
2289     types[(INTERP_KERNEL::NormalizedCellType)(*it)->getLocId()].push_back(*it);
2290   //
2291   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > fieldPmPt(types.size());
2292   std::map<INTERP_KERNEL::NormalizedCellType,std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc> > >::const_iterator it1=types.begin();
2293   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=fieldPmPt.begin();
2294   for(;it1!=types.end();it1++,it2++)
2295     {
2296       MCAuto<MEDFileFieldPerMeshPerType> elt=MEDFileFieldPerMeshPerType::New(this,(INTERP_KERNEL::NormalizedCellType)((*it1).second[0]->getLocId()));
2297       elt->setLeaves((*it1).second);
2298       MCAuto<MEDFileFieldPerMeshPerTypeCommon> elt2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(elt));
2299       *it2=elt2;
2300     }
2301   _field_pm_pt=fieldPmPt;
2302 }
2303
2304 void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2305 {
2306   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2307     (*it)->changePflsRefsNamesGen(mapOfModif);
2308 }
2309
2310 void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
2311 {
2312   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2313     (*it)->changeLocsRefsNamesGen(mapOfModif);
2314 }
2315
2316 /*!
2317  * \param [in] mesh is the whole mesh
2318  */
2319 MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2320 {
2321   if(_field_pm_pt.empty())
2322     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2323   //
2324   std::vector< std::pair<int,int> > dads;
2325   std::vector<const DataArrayInt *> pfls;
2326   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2327   std::vector<int> locs,code;
2328   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2329   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2330     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2331   // Sort by types
2332   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2333   if(code.empty())
2334     {
2335       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2336       throw INTERP_KERNEL::Exception(oss.str());
2337     }
2338   //
2339   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2340   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2341   if(type!=ON_NODES)
2342     {
2343       DataArrayInt *arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2344       if(!arr)
2345         return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2346       else
2347         {
2348           MCAuto<DataArrayInt> arr2(arr);
2349           return finishField2(type,glob,dads,locs,geoTypes,mesh,arr,isPfl,arrOut,nasc);
2350         }
2351     }
2352   else
2353     {
2354       if(code.size()!=3)
2355         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2356       int nb=code[1];
2357       if(code[2]==-1)
2358         {
2359           if(nb!=mesh->getNumberOfNodes())
2360             {
2361               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2362               oss << " nodes in mesh !";
2363               throw INTERP_KERNEL::Exception(oss.str());
2364             }
2365           return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2366         }
2367       else
2368         return finishFieldNode2(glob,dads,locs,mesh,notNullPflsPerGeoType3[0],isPfl,arrOut,nasc);
2369     }
2370 }
2371
2372 DataArray *MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl(TypeOfField type, const MEDCouplingMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
2373 {
2374   if(_field_pm_pt.empty())
2375     throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : no types field set !");
2376   //
2377   std::vector<std::pair<int,int> > dads;
2378   std::vector<const DataArrayInt *> pfls;
2379   std::vector<DataArrayInt *> notNullPflsPerGeoType;
2380   std::vector<int> locs,code;
2381   std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2382   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2383     (*it)->getFieldAtLevel(mesh->getMeshDimension(),type,glob,dads,pfls,locs,geoTypes);
2384   // Sort by types
2385   SortArraysPerType(glob,type,geoTypes,dads,pfls,locs,code,notNullPflsPerGeoType);
2386   if(code.empty())
2387     {
2388       std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevelWithPfl : " << "The field \"" << nasc.getName() << "\" exists but not with such spatial discretization or such dimension specified !";
2389       throw INTERP_KERNEL::Exception(oss.str());
2390     }
2391   std::vector< MCAuto<DataArrayInt> > notNullPflsPerGeoType2(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2392   std::vector< const DataArrayInt *> notNullPflsPerGeoType3(notNullPflsPerGeoType.begin(),notNullPflsPerGeoType.end());
2393   if(type!=ON_NODES)
2394     {
2395       MCAuto<DataArrayInt> arr=mesh->checkTypeConsistencyAndContig(code,notNullPflsPerGeoType3);
2396       return finishField4(dads,arr,mesh->getNumberOfCells(),pfl);
2397     }
2398   else
2399     {
2400       if(code.size()!=3)
2401         throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getFieldOnMeshAtLevel : internal error #1 !");
2402       int nb=code[1];
2403       if(code[2]==-1)
2404         {
2405           if(nb!=mesh->getNumberOfNodes())
2406             {
2407               std::ostringstream oss; oss << "MEDFileFieldPerMesh::getFieldOnMeshAtLevel : There is a problem there is " << nb << " nodes in field whereas there is " << mesh->getNumberOfNodes();
2408               oss << " nodes in mesh !";
2409               throw INTERP_KERNEL::Exception(oss.str());
2410             }
2411         }
2412       return finishField4(dads,code[2]==-1?0:notNullPflsPerGeoType3[0],mesh->getNumberOfNodes(),pfl);
2413     }
2414   //
2415   return 0;
2416 }
2417
2418 void MEDFileFieldPerMesh::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
2419 {
2420   int globalSz=0;
2421   int nbOfEntries=0;
2422   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2423     {
2424       (*it)->getSizes(globalSz,nbOfEntries);
2425     }
2426   entries.resize(nbOfEntries);
2427   nbOfEntries=0;
2428   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2429     {
2430       (*it)->fillValues(nbOfEntries,entries);
2431     }
2432 }
2433
2434 MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId)
2435 {
2436   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2437     {
2438       if((*it)->getGeoType()==typ)
2439         return (*it)->getLeafGivenLocId(locId);
2440     }
2441   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2442   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2443   oss << "Possiblities are : ";
2444   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2445     {
2446       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2447       oss << "\"" << cm2.getRepr() << "\", ";
2448     }
2449   throw INTERP_KERNEL::Exception(oss.str());
2450 }
2451
2452 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMesh::getLeafGivenTypeAndLocId(INTERP_KERNEL::NormalizedCellType typ, int locId) const
2453 {
2454   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2455     {
2456       if((*it)->getGeoType()==typ)
2457         return (*it)->getLeafGivenLocId(locId);
2458     }
2459   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(typ);
2460   std::ostringstream oss; oss << "MEDFileFieldPerMesh::getLeafGivenTypeAndLocId : no such geometric type \"" << cm.getRepr() << "\" in this !" << std::endl;
2461   oss << "Possiblities are : ";
2462   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
2463     {
2464       const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel((*it)->getGeoType());
2465       oss << "\"" << cm2.getRepr() << "\", ";
2466     }
2467   throw INTERP_KERNEL::Exception(oss.str());
2468 }
2469
2470 /*!
2471  * \param [in,out] start - Integer that gives the current position in the final aggregated array
2472  * \param [in] pms - list of elements to aggregate. integer gives the mesh id 
2473  * \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.
2474  * \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.
2475  */
2476 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)
2477 {
2478   MCAuto<MEDFileFieldPerMeshPerTypePerDisc> ret(new MEDFileFieldPerMeshPerTypePerDisc(father,tof));
2479   if(pms.empty())
2480     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : empty input vector !");
2481   for(std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it=pms.begin();it!=pms.end();it++)
2482     {
2483       if(!(*it).second)
2484         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : presence of null pointer !");
2485       if(!(*it).second->getProfile().empty())
2486         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for profiles !");
2487       if(!(*it).second->getLocalization().empty())
2488         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for gauss pts !");
2489     }
2490   INTERP_KERNEL::NormalizedCellType gt(pms[0].second->getGeoType());
2491   std::size_t i(0);
2492   std::vector< std::pair<int,int> > filteredDTS;
2493   for(std::vector< std::vector< std::pair<int,int> > >::const_iterator it=dts.begin();it!=dts.end();it++,i++)
2494     for(std::vector< std::pair<int,int> >::const_iterator it2=(*it).begin();it2!=(*it).end();it2++)
2495       if((*it2).first==gt)
2496         filteredDTS.push_back(std::pair<int,int>(i,(*it2).second));
2497   if(pms.size()!=filteredDTS.size())
2498     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles !");
2499   std::vector<std::pair<int,const MEDFileFieldPerMeshPerTypePerDisc *> >::const_iterator it1(pms.begin());
2500   std::vector< std::pair<int,int> >::const_iterator it2(filteredDTS.begin());
2501   int zeStart(start),nval(0);
2502   for(;it1!=pms.end();it1++,it2++)
2503     {
2504       if((*it1).first!=(*it2).first)
2505         throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::Aggregate : not implemented yet for generated profiles 2 !");
2506       int s1((*it1).second->getStart()),e1((*it1).second->getEnd());
2507       extractInfo.push_back(std::pair<int, std::pair<int,int> >((*it1).first,std::pair<int,int>(s1,e1)));
2508       start+=e1-s1;
2509       nval+=((*it1).second)->getNumberOfVals();
2510     }
2511   ret->_start=zeStart; ret->_end=start; ret->_nval=nval;
2512   return ret;
2513 }
2514
2515 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)
2516 {
2517   MCAuto<MEDFileFieldPerMesh> ret(new MEDFileFieldPerMesh(father,pms[0]->getMeshName(),pms[0]->getMeshIteration(),pms[0]->getMeshOrder()));
2518   std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > > m;
2519   std::size_t i(0);
2520   for(std::vector<const MEDFileFieldPerMesh *>::const_iterator it=pms.begin();it!=pms.end();it++,i++)
2521     {
2522       const std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >& v((*it)->_field_pm_pt);
2523       for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it2=v.begin();it2!=v.end();it2++)
2524         {
2525           INTERP_KERNEL::NormalizedCellType gt((*it2)->getGeoType());
2526           const MEDFileFieldPerMeshPerType *elt(dynamic_cast<const MEDFileFieldPerMeshPerType *>((const MEDFileFieldPerMeshPerTypeCommon *)(*it2)));
2527           if(!elt)
2528             throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::Aggregate : not managed for structelement !");
2529           m[gt].push_back(std::pair<int,const MEDFileFieldPerMeshPerType *>(i,elt));
2530         }
2531     }
2532   for(std::map<INTERP_KERNEL::NormalizedCellType, std::vector< std::pair<int,const MEDFileFieldPerMeshPerType *> > >::const_iterator it=m.begin();it!=m.end();it++)
2533     {
2534       MCAuto<MEDFileFieldPerMeshPerType> agg(MEDFileFieldPerMeshPerType::Aggregate(start,(*it).second,dts,(*it).first,ret,extractInfo));
2535       MCAuto<MEDFileFieldPerMeshPerTypeCommon> agg2(DynamicCast<MEDFileFieldPerMeshPerType,MEDFileFieldPerMeshPerTypeCommon>(agg));
2536       ret->_field_pm_pt.push_back(agg2);
2537     }
2538   return ret;
2539 }
2540
2541 int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellType type)
2542 {
2543   int i=0;
2544   int pos=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,type));
2545   std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it2=_field_pm_pt.begin();
2546   for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++,i++)
2547     {
2548       INTERP_KERNEL::NormalizedCellType curType=(*it)->getGeoType();
2549       if(type==curType)
2550         return i;
2551       else
2552         {
2553           int pos2=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,curType));
2554           if(pos>pos2)
2555             it2=it+1;
2556         }
2557     }
2558   int ret=std::distance(_field_pm_pt.begin(),it2);
2559   _field_pm_pt.insert(it2,MEDFileFieldPerMeshPerType::New(this,type));
2560   return ret;
2561 }
2562
2563 /*!
2564  * 'dads' and 'locs' input parameters have the same number of elements
2565  * \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
2566  */
2567 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2568                                                          const std::vector< std::pair<int,int> >& dads, const std::vector<int>& locs,
2569                                                          const MEDCouplingMesh *mesh, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2570 {
2571   isPfl=false;
2572   MCAuto<MEDCouplingFieldDouble> ret=MEDCouplingFieldDouble::New(type,ONE_TIME);
2573   ret->setMesh(mesh); ret->setName(nasc.getName().c_str()); ret->setTime(getTime(),getIteration(),getOrder()); ret->setTimeUnit(nasc.getDtUnit().c_str());
2574   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2575   const std::vector<std::string>& infos=getInfo();
2576   da->setInfoOnComponents(infos);
2577   da->setName("");
2578   if(type==ON_GAUSS_PT)
2579     {
2580       int offset=0;
2581       int nbOfArrs=dads.size();
2582       for(int i=0;i<nbOfArrs;i++)
2583         {
2584           std::vector<std::pair<int,int> > dads2(1,dads[i]); const std::vector<int> locs2(1,locs[i]);
2585           const std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes2(1,INTERP_KERNEL::NORM_ERROR);
2586           int nbOfElems=ComputeNbOfElems(glob,type,geoTypes2,dads2,locs2);
2587           MCAuto<DataArrayInt> di=DataArrayInt::New();
2588           di->alloc(nbOfElems,1);
2589           di->iota(offset);
2590           const MEDFileFieldLoc& fl=glob->getLocalizationFromId(locs[i]);
2591           ret->setGaussLocalizationOnCells(di->getConstPointer(),di->getConstPointer()+nbOfElems,fl.getRefCoords(),fl.getGaussCoords(),fl.getGaussWeights());
2592           offset+=nbOfElems;
2593         }
2594     }
2595   arrOut=da;
2596   return ret.retn();
2597 }
2598
2599 /*!
2600  * 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.
2601  * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements.
2602  * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support.
2603  * The order of cells in the returned field is those imposed by the profile.
2604  * \param [in] mesh is the global mesh.
2605  */
2606 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob,
2607                                                           const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2608                                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& geoTypes,
2609                                                           const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2610 {
2611   if(da->isIota(mesh->getNumberOfCells()))
2612     return finishField(type,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2613   MCAuto<MEDCouplingMesh> m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2614   m2->setName(mesh->getName().c_str());
2615   MCAuto<MEDCouplingFieldDouble> ret=finishField(type,glob,dads,locs,m2,isPfl,arrOut,nasc);
2616   isPfl=true;
2617   return ret.retn();
2618 }
2619
2620 /*!
2621  * This method is the complement of MEDFileFieldPerMesh::finishField2 method except that this method works for node profiles.
2622  */
2623 MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishFieldNode2(const MEDFileFieldGlobsReal *glob,
2624                                                               const std::vector<std::pair<int,int> >& dads, const std::vector<int>& locs,
2625                                                               const MEDCouplingMesh *mesh, const DataArrayInt *da, bool& isPfl, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
2626 {
2627   if(da->isIota(mesh->getNumberOfNodes()))
2628     return finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2629   // Treatment of particular case where nodal field on pfl is requested with a meshDimRelToMax=1.
2630   const MEDCouplingUMesh *meshu=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2631   if(meshu)
2632     {
2633       if(meshu->getNodalConnectivity()==0)
2634         {
2635           MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_CELLS,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2636           int nb=da->getNbOfElems();
2637           const int *ptr=da->getConstPointer();
2638           MEDCouplingUMesh *meshuc=const_cast<MEDCouplingUMesh *>(meshu);
2639           meshuc->allocateCells(nb);
2640           for(int i=0;i<nb;i++)
2641             meshuc->insertNextCell(INTERP_KERNEL::NORM_POINT1,1,ptr+i);
2642           meshuc->finishInsertingCells();
2643           ret->setMesh(meshuc);
2644           const MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
2645           if(!disc) throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::finishFieldNode2 : internal error, no discretization on field !");
2646           disc->checkCoherencyBetween(meshuc,arrOut);
2647           return ret.retn();
2648         }
2649     }
2650   //
2651   MCAuto<MEDCouplingFieldDouble> ret=finishField(ON_NODES,glob,dads,locs,mesh,isPfl,arrOut,nasc);
2652   isPfl=true;
2653   DataArrayInt *arr2=0;
2654   MCAuto<DataArrayInt> cellIds=mesh->getCellIdsFullyIncludedInNodeIds(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems());
2655   MCAuto<MEDCouplingMesh> mesh2=mesh->buildPartAndReduceNodes(cellIds->getConstPointer(),cellIds->getConstPointer()+cellIds->getNbOfElems(),arr2);
2656   MCAuto<DataArrayInt> arr3(arr2);
2657   int nnodes=mesh2->getNumberOfNodes();
2658   if(nnodes==(int)da->getNbOfElems())
2659     {
2660       MCAuto<DataArrayInt> da3=da->transformWithIndArrR(arr2->begin(),arr2->end());
2661       arrOut->renumberInPlace(da3->getConstPointer());
2662       mesh2->setName(mesh->getName().c_str());
2663       ret->setMesh(mesh2);
2664       return ret.retn();
2665     }
2666   else
2667     {
2668       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 !!!";
2669       oss << "So it is impossible to return a well definied MEDCouplingFieldDouble instance on specified mesh on a specified meshDim !" << std::endl;
2670       oss << "To retrieve correctly such a field you have 3 possibilities :" << std::endl;
2671       oss << " - use an another meshDim compatible with the field on nodes (MED file does not have such information)" << std::endl;
2672       oss << " - use an another a meshDimRelToMax equal to 1 -> it will return a mesh with artificial cell POINT1 containing the profile !" << std::endl;
2673       oss << " - if definitely the node profile has no link with mesh connectivity use MEDFileField1TS::getFieldWithProfile or MEDFileFieldMultiTS::getFieldWithProfile methods instead !";
2674       throw INTERP_KERNEL::Exception(oss.str());
2675     }
2676   return 0;
2677 }
2678
2679 /*!
2680  * This method is the most light method of field retrieving.
2681  */
2682 DataArray *MEDFileFieldPerMesh::finishField4(const std::vector<std::pair<int,int> >& dads, const DataArrayInt *pflIn, int nbOfElems, DataArrayInt *&pflOut) const
2683 {
2684   if(!pflIn)
2685     {
2686       pflOut=DataArrayInt::New();
2687       pflOut->alloc(nbOfElems,1);
2688       pflOut->iota(0);
2689     }
2690   else
2691     {
2692       pflOut=const_cast<DataArrayInt*>(pflIn);
2693       pflOut->incrRef();
2694     }
2695   MCAuto<DataArrayInt> safePfl(pflOut);
2696   MCAuto<DataArray> da=getOrCreateAndGetArray()->selectByTupleRanges(dads);
2697   const std::vector<std::string>& infos=getInfo();
2698   int nbOfComp=infos.size();
2699   for(int i=0;i<nbOfComp;i++)
2700     da->setInfoOnComponent(i,infos[i].c_str());
2701   safePfl->incrRef();
2702   return da.retn();
2703 }
2704
2705
2706 /// @cond INTERNAL
2707
2708 class MFFPMIter
2709 {
2710 public:
2711   static MFFPMIter *NewCell(const MEDFileEntities *entities);
2712   static bool IsPresenceOfNode(const MEDFileEntities *entities);
2713   virtual ~MFFPMIter() { }
2714   virtual void begin() = 0;
2715   virtual bool finished() const = 0;
2716   virtual void next() = 0;
2717   virtual int current() const = 0;
2718 };
2719
2720 class MFFPMIterSimple : public MFFPMIter
2721 {
2722 public:
2723   MFFPMIterSimple():_pos(0) { }
2724   void begin() { _pos=0; }
2725   bool finished() const { return _pos>=MED_N_CELL_FIXED_GEO; }
2726   void next() { _pos++; }
2727   int current() const { return _pos; }
2728 private:
2729   int _pos;
2730 };
2731
2732 class MFFPMIter2 : public MFFPMIter
2733 {
2734 public:
2735   MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts);
2736   void begin() { _it=_ids.begin(); }
2737   bool finished() const { return _it==_ids.end(); }
2738   void next() { _it++; }
2739   int current() const { return *_it; }
2740 private:
2741   std::vector<int> _ids;
2742   std::vector<int>::const_iterator _it;
2743 };
2744
2745 MFFPMIter *MFFPMIter::NewCell(const MEDFileEntities *entities)
2746 {
2747   if(!entities)
2748     return new MFFPMIterSimple;
2749   else
2750     {
2751       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2752       if(entities2)
2753         {
2754           std::vector<INTERP_KERNEL::NormalizedCellType> tmp;
2755           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2756           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2757             {
2758               if((*it).first==ON_CELLS || (*it).first==ON_GAUSS_NE || (*it).first==ON_GAUSS_PT)
2759                 tmp.push_back((*it).second);
2760             }
2761           return new MFFPMIter2(tmp);
2762         }
2763       return new MFFPMIterSimple;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn cells are in
2764     }
2765 }
2766
2767 bool MFFPMIter::IsPresenceOfNode(const MEDFileEntities *entities)
2768 {
2769   if(!entities)
2770     return true;
2771   else
2772     {
2773       const MEDFileStaticEntities *entities2(dynamic_cast<const MEDFileStaticEntities *>(entities));
2774       if(entities2)
2775         {
2776           const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& myEnt(entities2->getEntries());
2777           for(std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >::const_iterator it=myEnt.begin();it!=myEnt.end();it++)
2778             if((*it).first==ON_NODES)
2779               return true;
2780           return false;
2781         }
2782       return true;// for MEDFileAllStaticEntites and MEDFileAllStaticEntitiesPlusDyn nodes are in
2783     }
2784 }
2785
2786 MFFPMIter2::MFFPMIter2(const std::vector<INTERP_KERNEL::NormalizedCellType>& cts)
2787 {
2788   std::size_t sz(cts.size());
2789   _ids.resize(sz);
2790   for(std::size_t i=0;i<sz;i++)
2791     {
2792       INTERP_KERNEL::NormalizedCellType *loc(std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,cts[i]));
2793       if(loc!=typmai2+MED_N_CELL_FIXED_GEO)
2794         _ids[i]=(int)std::distance(typmai2,loc);
2795       else
2796         throw INTERP_KERNEL::Exception("MFFPMIter2 : The specified geo type does not exists !");
2797     }
2798 }
2799
2800 /// @endcond
2801
2802 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),
2803     _father(fath)
2804 {
2805   INTERP_KERNEL::AutoPtr<char> meshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2806   INTERP_KERNEL::AutoPtr<char> pflName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2807   INTERP_KERNEL::AutoPtr<char> locName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2808   const MEDFileUMesh *mmu(dynamic_cast<const MEDFileUMesh *>(mm));
2809   INTERP_KERNEL::AutoCppPtr<MFFPMIter> iter0(MFFPMIter::NewCell(entities));
2810   for(iter0->begin();!iter0->finished();iter0->next())
2811     {
2812       int nbProfile (MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_CELL        ,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2813       std::string name0(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2814       int nbProfile2(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[iter0->current()],meshCsit+1,meshName,pflName,locName));
2815       std::string name1(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
2816       if(nbProfile>0 || nbProfile2>0)
2817         {
2818           const PartDefinition *pd(0);
2819           if(mmu)
2820             pd=mmu->getPartDefAtLevel(mmu->getRelativeLevOnGeoType(typmai2[iter0->current()]),typmai2[iter0->current()]);
2821           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_CELLS,typmai2[iter0->current()],nasc,pd));
2822           if(nbProfile>0)
2823             _mesh_name=name0;
2824           else
2825             _mesh_name=name1;
2826         }
2827     }
2828   if(MFFPMIter::IsPresenceOfNode(entities))
2829     {
2830       int nbProfile(MEDfield23nProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,meshCsit+1,meshName,pflName,locName));
2831       if(nbProfile>0)
2832         {
2833           const PartDefinition *pd(0);
2834           if(mmu)
2835             pd=mmu->getPartDefAtLevel(1,INTERP_KERNEL::NORM_ERROR);
2836           _field_pm_pt.push_back(MEDFileFieldPerMeshPerType::NewOnRead(fid,this,ON_NODES,INTERP_KERNEL::NORM_ERROR,nasc,pd));
2837           _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1);
2838         }
2839     }
2840   if(!entities)
2841     return ;
2842   std::vector<int> dynGT(entities->getDynGTAvail());
2843   for(std::vector<int>::const_iterator it=dynGT.begin();it!=dynGT.end();it++)
2844     {
2845       int nbPfl(MEDfieldnProfile(fid,nasc.getName().c_str(),getIteration(),getOrder(),MED_STRUCT_ELEMENT,*it,pflName,locName));
2846       if(nbPfl>0)
2847         {
2848           _field_pm_pt.push_back(MEDFileFieldPerMeshPerTypeDyn::NewOnRead(fid,this,entities,*it,nasc));
2849         }
2850     }
2851 }
2852
2853 MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileAnyTypeField1TSWithoutSDA *fath, const MEDCouplingMesh *mesh):_father(fath)
2854 {
2855   copyTinyInfoFrom(mesh);
2856 }
2857
2858 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
2859 {
2860   if(id>=(int)_pfls.size())
2861     _pfls.resize(id+1);
2862   _pfls[id]=DataArrayInt::New();
2863   int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
2864   _pfls[id]->setName(pflName);
2865   _pfls[id]->alloc(lgth,1);
2866   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
2867   _pfls[id]->applyLin(1,-1,0);//Converting into C format
2868 }
2869
2870 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
2871 {
2872   INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2873   int sz;
2874   MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
2875   std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
2876   if(i>=(int)_pfls.size())
2877     _pfls.resize(i+1);
2878   _pfls[i]=DataArrayInt::New();
2879   _pfls[i]->alloc(sz,1);
2880   _pfls[i]->setName(pflCpp.c_str());
2881   MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
2882   _pfls[i]->applyLin(1,-1,0);//Converting into C format
2883 }
2884
2885 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
2886 {
2887   int nbOfPfls=_pfls.size();
2888   for(int i=0;i<nbOfPfls;i++)
2889     {
2890       MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
2891       cpy->applyLin(1,1,0);
2892       INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2893       MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
2894       MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
2895     }
2896   //
2897   int nbOfLocs=_locs.size();
2898   for(int i=0;i<nbOfLocs;i++)
2899     _locs[i]->writeLL(fid);
2900 }
2901
2902 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
2903 {
2904   std::vector<std::string> pfls=getPfls();
2905   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
2906     {
2907       std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
2908       if(it2==pfls.end())
2909         {
2910           _pfls.push_back(*it);
2911         }
2912       else
2913         {
2914           int id=std::distance(pfls.begin(),it2);
2915           if(!(*it)->isEqual(*_pfls[id]))
2916             {
2917               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2918               throw INTERP_KERNEL::Exception(oss.str());
2919             }
2920         }
2921     }
2922   std::vector<std::string> locs=getLocs();
2923   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
2924     {
2925       std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
2926       if(it2==locs.end())
2927         {
2928           _locs.push_back(*it);
2929         }
2930       else
2931         {
2932           int id=std::distance(locs.begin(),it2);
2933           if(!(*it)->isEqual(*_locs[id],eps))
2934             {
2935               std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
2936               throw INTERP_KERNEL::Exception(oss.str());
2937             }
2938         }
2939     }
2940 }
2941
2942 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
2943 {
2944   for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
2945     getProfile((*it).c_str());
2946 }
2947
2948 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
2949 {
2950   for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
2951     getLocalization((*it).c_str());
2952 }
2953
2954 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
2955 {
2956   std::vector<std::string> profiles=real.getPflsReallyUsed();
2957   int sz=profiles.size();
2958   _pfls.resize(sz);
2959   for(int i=0;i<sz;i++)
2960     loadProfileInFile(fid,i,profiles[i].c_str());
2961   //
2962   std::vector<std::string> locs=real.getLocsReallyUsed();
2963   sz=locs.size();
2964   _locs.resize(sz);
2965   for(int i=0;i<sz;i++)
2966     _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
2967 }
2968
2969 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid)
2970 {
2971   int nProfil=MEDnProfile(fid);
2972   for(int i=0;i<nProfil;i++)
2973     loadProfileInFile(fid,i);
2974   int sz=MEDnLocalization(fid);
2975   _locs.resize(sz);
2976   for(int i=0;i<sz;i++)
2977     {
2978       _locs[i]=MEDFileFieldLoc::New(fid,i);
2979     }
2980 }
2981
2982 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
2983 {
2984   return new MEDFileFieldGlobs(fid);
2985 }
2986
2987 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
2988 {
2989   return new MEDFileFieldGlobs;
2990 }
2991
2992 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
2993 {
2994   return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
2995 }
2996
2997 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
2998 {
2999   std::vector<const BigMemoryObject *> ret;
3000   for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3001     ret.push_back((const DataArrayInt *)*it);
3002   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3003     ret.push_back((const MEDFileFieldLoc *)*it);
3004   return ret;
3005 }
3006
3007 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
3008 {
3009   MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
3010   std::size_t i=0;
3011   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3012     {
3013       if((const DataArrayInt *)*it)
3014         ret->_pfls[i]=(*it)->deepCopy();
3015     }
3016   i=0;
3017   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3018     {
3019       if((const MEDFileFieldLoc*)*it)
3020         ret->_locs[i]=(*it)->deepCopy();
3021     }
3022   return ret.retn();
3023 }
3024
3025 /*!
3026  * \throw if a profile in \a pfls in not in \a this.
3027  * \throw if a localization in \a locs in not in \a this.
3028  * \sa MEDFileFieldGlobs::deepCpyPart
3029  */
3030 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3031 {
3032   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3033   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3034     {
3035       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3036       if(!pfl)
3037         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
3038       pfl->incrRef();
3039       MCAuto<DataArrayInt> pfl2(pfl);
3040       ret->_pfls.push_back(pfl2);
3041     }
3042   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3043     {
3044       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3045       if(!loc)
3046         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
3047       loc->incrRef();
3048       MCAuto<MEDFileFieldLoc> loc2(loc);
3049       ret->_locs.push_back(loc2);
3050     }
3051   ret->setFileName(getFileName());
3052   return ret.retn();
3053 }
3054
3055 /*!
3056  * \throw if a profile in \a pfls in not in \a this.
3057  * \throw if a localization in \a locs in not in \a this.
3058  * \sa MEDFileFieldGlobs::shallowCpyPart
3059  */
3060 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
3061 {
3062   MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
3063   for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
3064     {
3065       DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
3066       if(!pfl)
3067         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
3068       ret->_pfls.push_back(pfl->deepCopy());
3069     }
3070   for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
3071     {
3072       MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
3073       if(!loc)
3074         throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
3075       ret->_locs.push_back(loc->deepCopy());
3076     }
3077   ret->setFileName(getFileName());
3078   return ret.retn();
3079 }
3080
3081 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
3082 {
3083 }
3084
3085 MEDFileFieldGlobs::MEDFileFieldGlobs()
3086 {
3087 }
3088
3089 MEDFileFieldGlobs::~MEDFileFieldGlobs()
3090 {
3091 }
3092
3093 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
3094 {
3095   oss << "Profiles :\n";
3096   std::size_t n=_pfls.size();
3097   for(std::size_t i=0;i<n;i++)
3098     {
3099       oss << "  - #" << i << " ";
3100       const DataArrayInt *pfl=_pfls[i];
3101       if(pfl)
3102         oss << "\"" << pfl->getName() << "\"\n";
3103       else
3104         oss << "EMPTY !\n";
3105     }
3106   n=_locs.size();
3107   oss << "Localizations :\n";
3108   for(std::size_t i=0;i<n;i++)
3109     {
3110       oss << "  - #" << i << " ";
3111       const MEDFileFieldLoc *loc=_locs[i];
3112       if(loc)
3113         loc->simpleRepr(oss);
3114       else
3115         oss<< "EMPTY !\n";
3116     }
3117 }
3118
3119 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3120 {
3121   for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
3122     {
3123       DataArrayInt *elt(*it);
3124       if(elt)
3125         {
3126           std::string name(elt->getName());
3127           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3128             {
3129               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3130                 {
3131                   elt->setName((*it2).second.c_str());
3132                   return;
3133                 }
3134             }
3135         }
3136     }
3137 }
3138
3139 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3140 {
3141   for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
3142     {
3143       MEDFileFieldLoc *elt(*it);
3144       if(elt)
3145         {
3146           std::string name(elt->getName());
3147           for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
3148             {
3149               if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
3150                 {
3151                   elt->setName((*it2).second.c_str());
3152                   return;
3153                 }
3154             }
3155         }
3156     }
3157 }
3158
3159 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
3160 {
3161   if(locId<0 || locId>=(int)_locs.size())
3162     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
3163   return _locs[locId]->getNbOfGaussPtPerCell();
3164 }
3165
3166 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
3167 {
3168   return getLocalizationFromId(getLocalizationId(locName));
3169 }
3170
3171 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
3172 {
3173   if(locId<0 || locId>=(int)_locs.size())
3174     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3175   return *_locs[locId];
3176 }
3177
3178 /// @cond INTERNAL
3179 namespace MEDCouplingImpl
3180 {
3181   class LocFinder
3182   {
3183   public:
3184     LocFinder(const std::string& loc):_loc(loc) { }
3185     bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
3186   private:
3187     const std::string &_loc;
3188   };
3189
3190   class PflFinder
3191   {
3192   public:
3193     PflFinder(const std::string& pfl):_pfl(pfl) { }
3194     bool operator() (const MCAuto<DataArrayInt>& pfl) { return _pfl==pfl->getName(); }
3195   private:
3196     const std::string& _pfl;
3197   };
3198 }
3199 /// @endcond
3200
3201 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
3202 {
3203   std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
3204   if(it==_locs.end())
3205     {
3206       std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
3207       for(it=_locs.begin();it!=_locs.end();it++)
3208         oss << "\"" << (*it)->getName() << "\", ";
3209       throw INTERP_KERNEL::Exception(oss.str());
3210     }
3211   return std::distance(_locs.begin(),it);
3212 }
3213
3214 /*!
3215  * The returned value is never null.
3216  */
3217 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
3218 {
3219   std::string pflNameCpp(pflName);
3220   std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3221   if(it==_pfls.end())
3222     {
3223       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3224       for(it=_pfls.begin();it!=_pfls.end();it++)
3225         oss << "\"" << (*it)->getName() << "\", ";
3226       throw INTERP_KERNEL::Exception(oss.str());
3227     }
3228   return *it;
3229 }
3230
3231 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
3232 {
3233   if(pflId<0 || pflId>=(int)_pfls.size())
3234     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3235   return _pfls[pflId];
3236 }
3237
3238 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
3239 {
3240   if(locId<0 || locId>=(int)_locs.size())
3241     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
3242   return *_locs[locId];
3243 }
3244
3245 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
3246 {
3247   return getLocalizationFromId(getLocalizationId(locName));
3248 }
3249
3250 /*!
3251  * The returned value is never null.
3252  */
3253 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
3254 {
3255   std::string pflNameCpp(pflName);
3256   std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
3257   if(it==_pfls.end())
3258     {
3259       std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
3260       for(it=_pfls.begin();it!=_pfls.end();it++)
3261         oss << "\"" << (*it)->getName() << "\", ";
3262       throw INTERP_KERNEL::Exception(oss.str());
3263     }
3264   return *it;
3265 }
3266
3267 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
3268 {
3269   if(pflId<0 || pflId>=(int)_pfls.size())
3270     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
3271   return _pfls[pflId];
3272 }
3273
3274 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
3275 {
3276   std::vector< MCAuto<DataArrayInt> > newPfls;
3277   int i=0;
3278   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3279     {
3280       if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
3281         newPfls.push_back(*it);
3282     }
3283   _pfls=newPfls;
3284 }
3285
3286 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
3287 {
3288   std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
3289   int i=0;
3290   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
3291     {
3292       if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
3293         newLocs.push_back(*it);
3294     }
3295   _locs=newLocs;
3296 }
3297
3298 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
3299 {
3300   int sz=_pfls.size();
3301   std::vector<std::string> ret(sz);
3302   for(int i=0;i<sz;i++)
3303     ret[i]=_pfls[i]->getName();
3304   return ret;
3305 }
3306
3307 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
3308 {
3309   int sz=_locs.size();
3310   std::vector<std::string> ret(sz);
3311   for(int i=0;i<sz;i++)
3312     ret[i]=_locs[i]->getName();
3313   return ret;
3314 }
3315
3316 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
3317 {
3318   std::vector<std::string> v=getPfls();
3319   std::string s(pflName);
3320   return std::find(v.begin(),v.end(),s)!=v.end();
3321 }
3322
3323 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
3324 {
3325   std::vector<std::string> v=getLocs();
3326   std::string s(locName);
3327   return std::find(v.begin(),v.end(),s)!=v.end();
3328 }
3329
3330 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
3331 {
3332   std::map<int,std::vector<int> > m;
3333   int i=0;
3334   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
3335     {
3336       const DataArrayInt *tmp=(*it);
3337       if(tmp)
3338         {
3339           m[tmp->getHashCode()].push_back(i);
3340         }
3341     }
3342   std::vector< std::vector<int> > ret;
3343   for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
3344     {
3345       if((*it2).second.size()>1)
3346         {
3347           std::vector<int> ret0;
3348           bool equalityOrNot=false;
3349           for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
3350             {
3351               std::vector<int>::const_iterator it4=it3; it4++;
3352               for(;it4!=(*it2).second.end();it4++)
3353                 {
3354                   if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
3355                     {
3356                       if(!equalityOrNot)
3357                         ret0.push_back(*it3);
3358                       ret0.push_back(*it4);
3359                       equalityOrNot=true;
3360                     }
3361                 }
3362             }
3363           if(!ret0.empty())
3364             ret.push_back(ret0);
3365         }
3366     }
3367   return ret;
3368 }
3369
3370 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
3371 {
3372   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
3373 }
3374
3375 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
3376 {
3377   std::string name(pfl->getName());
3378   if(name.empty())
3379     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
3380   for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
3381     if(name==(*it)->getName())
3382       {
3383         if(!pfl->isEqual(*(*it)))
3384           {
3385             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
3386             throw INTERP_KERNEL::Exception(oss.str());
3387           }
3388       }
3389   pfl->incrRef();
3390   _pfls.push_back(pfl);
3391 }
3392
3393 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)
3394 {
3395   std::string name(locName);
3396   if(name.empty())
3397     throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
3398   MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
3399   for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
3400     if((*it)->isName(locName))
3401       {
3402         if(!(*it)->isEqual(*obj,1e-12))
3403           {
3404             std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
3405             throw INTERP_KERNEL::Exception(oss.str());
3406           }
3407       }
3408   _locs.push_back(obj);
3409 }
3410
3411 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
3412 {
3413   std::vector<std::string> names=getPfls();
3414   return CreateNewNameNotIn("NewPfl_",names);
3415 }
3416
3417 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
3418 {
3419   std::vector<std::string> names=getLocs();
3420   return CreateNewNameNotIn("NewLoc_",names);
3421 }
3422
3423 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
3424 {
3425   for(std::size_t sz=0;sz<100000;sz++)
3426     {
3427       std::ostringstream tryName;
3428       tryName << prefix << sz;
3429       if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
3430         return tryName.str();
3431     }
3432   throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
3433 }
3434
3435 /*!
3436  * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
3437  *  \param [in] fname - the file name.
3438  */
3439 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
3440 {
3441 }
3442
3443 /*!
3444  * Creates an empty MEDFileFieldGlobsReal.
3445  */
3446 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
3447 {
3448 }
3449
3450 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
3451 {
3452   return 0;
3453 }
3454
3455 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
3456 {
3457   std::vector<const BigMemoryObject *> ret;
3458   ret.push_back((const MEDFileFieldGlobs *)_globals);
3459   return ret;
3460 }
3461
3462 /*!
3463  * Returns a string describing profiles and Gauss points held in \a this.
3464  *  \return std::string - the description string.
3465  */
3466 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
3467 {
3468   const MEDFileFieldGlobs *glob=_globals;
3469   std::ostringstream oss2; oss2 << glob;
3470   std::string stars(oss2.str().length(),'*');
3471   oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars  << "\n\n";
3472   if(glob)
3473     glob->simpleRepr(oss);
3474   else
3475     oss << "NO GLOBAL INFORMATION !\n";
3476 }
3477
3478 void MEDFileFieldGlobsReal::resetContent()
3479 {
3480   _globals=MEDFileFieldGlobs::New();
3481 }
3482
3483 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
3484 {
3485 }
3486
3487 /*!
3488  * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
3489  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3490  */
3491 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
3492 {
3493   _globals=other._globals;
3494 }
3495
3496 /*!
3497  * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3498  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3499  */
3500 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3501 {
3502   const MEDFileFieldGlobs *otherg(other._globals);
3503   if(!otherg)
3504     return ;
3505   _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3506 }
3507
3508 /*!
3509  * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
3510  *  \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
3511  */
3512 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
3513 {
3514   const MEDFileFieldGlobs *otherg(other._globals);
3515   if(!otherg)
3516     return ;
3517   _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
3518 }
3519
3520 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
3521 {
3522   _globals=other._globals;
3523   if((const MEDFileFieldGlobs *)_globals)
3524     _globals=other._globals->deepCopy();
3525 }
3526
3527 /*!
3528  * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
3529  *  \param [in] other - the MEDFileFieldGlobsReal to copy data from.
3530  *  \param [in] eps - a precision used to compare Gauss points with same name held by
3531  *         \a this and \a other MEDFileFieldGlobsReal.
3532  *  \throw If \a this and \a other hold profiles with equal names but different ids.
3533  *  \throw If  \a this and \a other hold different Gauss points with equal names.
3534  */
3535 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
3536 {
3537   const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
3538   if(thisGlobals==otherGlobals)
3539     return ;
3540   if(!thisGlobals)
3541     {
3542       _globals=other._globals;
3543       return ;
3544     }
3545   _globals->appendGlobs(*other._globals,eps);
3546 }
3547
3548 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
3549 {
3550   checkGlobsPflsPartCoherency();
3551   checkGlobsLocsPartCoherency();
3552 }
3553
3554 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
3555 {
3556   contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
3557 }
3558
3559 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
3560 {
3561   contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
3562 }
3563
3564 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
3565 {
3566   contentNotNull()->loadProfileInFile(fid,id,pflName);
3567 }
3568
3569 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
3570 {
3571   contentNotNull()->loadProfileInFile(fid,id);
3572 }
3573
3574 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
3575 {
3576   contentNotNull()->loadGlobals(fid,*this);
3577 }
3578
3579 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid)
3580 {
3581   contentNotNull()->loadAllGlobals(fid);
3582 }
3583
3584 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
3585 {
3586   contentNotNull()->writeGlobals(fid,opt);
3587 }
3588
3589 /*!
3590  * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
3591  * or getPflsReallyUsedMulti().
3592  *  \return std::vector<std::string> - a sequence of names of all profiles.
3593  */
3594 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
3595 {
3596   return contentNotNull()->getPfls();
3597 }
3598
3599 /*!
3600  * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
3601  * or getLocsReallyUsedMulti().
3602  *  \return std::vector<std::string> - a sequence of names of all localizations.
3603  */
3604 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
3605 {
3606   return contentNotNull()->getLocs();
3607 }
3608
3609 /*!
3610  * Checks if the profile with a given name exists.
3611  *  \param [in] pflName - the profile name of interest.
3612  *  \return bool - \c true if the profile named \a pflName exists.
3613  */
3614 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
3615 {
3616   return contentNotNull()->existsPfl(pflName);
3617 }
3618
3619 /*!
3620  * Checks if the localization with a given name exists.
3621  *  \param [in] locName - the localization name of interest.
3622  *  \return bool - \c true if the localization named \a locName exists.
3623  */
3624 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
3625 {
3626   return contentNotNull()->existsLoc(locName);
3627 }
3628
3629 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
3630 {
3631   return contentNotNull()->createNewNameOfPfl();
3632 }
3633
3634 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
3635 {
3636   return contentNotNull()->createNewNameOfLoc();
3637 }
3638
3639 /*!
3640  * Sets the name of a MED file.
3641  *  \param [inout] fileName - the file name.
3642  */
3643 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
3644 {
3645   contentNotNull()->setFileName(fileName);
3646 }
3647
3648 /*!
3649  * Finds equal profiles. Two profiles are considered equal if they contain the same ids
3650  * in the same order.
3651  *  \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
3652  *          Each item of this sequence is a vector containing ids of equal profiles.
3653  */
3654 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
3655 {
3656   return contentNotNull()->whichAreEqualProfiles();
3657 }
3658
3659 /*!
3660  * Finds equal localizations.
3661  *  \param [in] eps - a precision used to compare real values of the localizations.
3662  *  \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
3663  *          Each item of this sequence is a vector containing ids of equal localizations.
3664  */
3665 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
3666 {
3667   return contentNotNull()->whichAreEqualLocs(eps);
3668 }
3669
3670 /*!
3671  * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
3672  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3673  *        this sequence is a pair whose 
3674  *        - the first item is a vector of profile names to replace by the second item,
3675  *        - the second item is a profile name to replace every profile name of the first item.
3676  */
3677 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3678 {
3679   contentNotNull()->changePflsNamesInStruct(mapOfModif);
3680 }
3681
3682 /*!
3683  * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
3684  * \param [in] mapOfModif - a sequence describing required renaming. Each element of
3685  *        this sequence is a pair whose 
3686  *        - the first item is a vector of localization names to replace by the second item,
3687  *        - the second item is a localization name to replace every localization name of the first item.
3688  */
3689 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3690 {
3691   contentNotNull()->changeLocsNamesInStruct(mapOfModif);
3692 }
3693
3694 /*!
3695  * Replaces references to some profiles (a reference is a profile name) by references
3696  * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
3697  * them-selves accordingly. <br>
3698  * This method is a generalization of changePflName().
3699  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3700  *        this sequence is a pair whose 
3701  *        - the first item is a vector of profile names to replace by the second item,
3702  *        - the second item is a profile name to replace every profile of the first item.
3703  * \sa changePflsRefsNamesGen()
3704  * \sa changePflName()
3705  */
3706 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3707 {
3708   changePflsRefsNamesGen(mapOfModif);
3709   changePflsNamesInStruct(mapOfModif);
3710 }
3711
3712 /*!
3713  * Replaces references to some localizations (a reference is a localization name) by references
3714  * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
3715  * them-selves accordingly. <br>
3716  * This method is a generalization of changeLocName().
3717  * \param [in] mapOfModif - a sequence describing required replacements. Each element of
3718  *        this sequence is a pair whose 
3719  *        - the first item is a vector of localization names to replace by the second item,
3720  *        - the second item is a localization name to replace every localization of the first item.
3721  * \sa changeLocsRefsNamesGen()
3722  * \sa changeLocName()
3723  */
3724 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
3725 {
3726   changeLocsRefsNamesGen(mapOfModif);
3727   changeLocsNamesInStruct(mapOfModif);
3728 }
3729
3730 /*!
3731  * Renames the profile having a given name and updates references to this profile.
3732  *  \param [in] oldName - the name of the profile to rename.
3733  *  \param [in] newName - a new name of the profile.
3734  * \sa changePflsNames().
3735  */
3736 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
3737 {
3738   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3739   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3740   mapOfModif[0]=p;
3741   changePflsNames(mapOfModif);
3742 }
3743
3744 /*!
3745  * Renames the localization having a given name and updates references to this localization.
3746  *  \param [in] oldName - the name of the localization to rename.
3747  *  \param [in] newName - a new name of the localization.
3748  * \sa changeLocsNames().
3749  */
3750 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
3751 {
3752   std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
3753   std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
3754   mapOfModif[0]=p;
3755   changeLocsNames(mapOfModif);
3756 }
3757
3758 /*!
3759  * Removes duplicated profiles. Returns a map used to update references to removed 
3760  * profiles via changePflsRefsNamesGen().
3761  * Equal profiles are found using whichAreEqualProfiles().
3762  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3763  *          a sequence describing the performed replacements of profiles. Each element of
3764  *          this sequence is a pair whose
3765  *          - the first item is a vector of profile names replaced by the second item,
3766  *          - the second item is a profile name replacing every profile of the first item.
3767  */
3768 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
3769 {
3770   std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
3771   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3772   int i=0;
3773   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3774     {
3775       std::vector< std::string > tmp((*it).size());
3776       int j=0;
3777       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3778         tmp[j]=std::string(getProfileFromId(*it2)->getName());
3779       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3780       ret[i]=p;
3781       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3782       killProfileIds(tmp2);
3783     }
3784   changePflsRefsNamesGen(ret);
3785   return ret;
3786 }
3787
3788 /*!
3789  * Removes duplicated localizations. Returns a map used to update references to removed 
3790  * localizations via changeLocsRefsNamesGen().
3791  * Equal localizations are found using whichAreEqualLocs().
3792  *  \param [in] eps - a precision used to compare real values of the localizations.
3793  *  \return std::vector< std::pair<std::vector<std::string>, std::string > > - 
3794  *          a sequence describing the performed replacements of localizations. Each element of
3795  *          this sequence is a pair whose
3796  *          - the first item is a vector of localization names replaced by the second item,
3797  *          - the second item is a localization name replacing every localization of the first item.
3798  */
3799 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
3800 {
3801   std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
3802   std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
3803   int i=0;
3804   for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
3805     {
3806       std::vector< std::string > tmp((*it).size());
3807       int j=0;
3808       for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
3809         tmp[j]=std::string(getLocalizationFromId(*it2).getName());
3810       std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
3811       ret[i]=p;
3812       std::vector<int> tmp2((*it).begin()+1,(*it).end());
3813       killLocalizationIds(tmp2);
3814     }
3815   changeLocsRefsNamesGen(ret);
3816   return ret;
3817 }
3818
3819 /*!
3820  * Returns number of Gauss points per cell in a given localization.
3821  *  \param [in] locId - an id of the localization of interest.
3822  *  \return int - the number of the Gauss points per cell.
3823  */
3824 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
3825 {
3826   return contentNotNull()->getNbOfGaussPtPerCell(locId);
3827 }
3828
3829 /*!
3830  * Returns an id of a localization by its name.
3831  *  \param [in] loc - the localization name of interest.
3832  *  \return int - the id of the localization.
3833  *  \throw If there is no a localization named \a loc.
3834  */
3835 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
3836 {
3837   return contentNotNull()->getLocalizationId(loc);
3838 }
3839
3840 /*!
3841  * Returns the name of the MED file.
3842  *  \return const std::string&  - the MED file name.
3843  */
3844 std::string MEDFileFieldGlobsReal::getFileName() const
3845 {
3846   return contentNotNull()->getFileName();
3847 }
3848
3849 /*!
3850  * Returns a localization object by its name.
3851  *  \param [in] locName - the name of the localization of interest.
3852  *  \return const MEDFileFieldLoc& - the localization object having the name \a locName.
3853  *  \throw If there is no a localization named \a locName.
3854  */
3855 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
3856 {
3857   return contentNotNull()->getLocalization(locName);
3858 }
3859
3860 /*!
3861  * Returns a localization object by its id.
3862  *  \param [in] locId - the id of the localization of interest.
3863  *  \return const MEDFileFieldLoc& - the localization object having the id \a locId.
3864  *  \throw If there is no a localization with id \a locId.
3865  */
3866 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
3867 {
3868   return contentNotNull()->getLocalizationFromId(locId);
3869 }
3870
3871 /*!
3872  * Returns a profile array by its name.
3873  *  \param [in] pflName - the name of the profile of interest.
3874  *  \return const DataArrayInt * - the profile array having the name \a pflName.
3875  *  \throw If there is no a profile named \a pflName.
3876  */
3877 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
3878 {
3879   return contentNotNull()->getProfile(pflName);
3880 }
3881
3882 /*!
3883  * Returns a profile array by its id.
3884  *  \param [in] pflId - the id of the profile of interest.
3885  *  \return const DataArrayInt * - the profile array having the id \a pflId.
3886  *  \throw If there is no a profile with id \a pflId.
3887  */
3888 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
3889 {
3890   return contentNotNull()->getProfileFromId(pflId);
3891 }
3892
3893 /*!
3894  * Returns a localization object, apt for modification, by its id.
3895  *  \param [in] locId - the id of the localization of interest.
3896  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3897  *          having the id \a locId.
3898  *  \throw If there is no a localization with id \a locId.
3899  */
3900 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
3901 {
3902   return contentNotNull()->getLocalizationFromId(locId);
3903 }
3904
3905 /*!
3906  * Returns a localization object, apt for modification, by its name.
3907  *  \param [in] locName - the name of the localization of interest.
3908  *  \return MEDFileFieldLoc& - a non-const reference to the localization object
3909  *          having the name \a locName.
3910  *  \throw If there is no a localization named \a locName.
3911  */
3912 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
3913 {
3914   return contentNotNull()->getLocalization(locName);
3915 }
3916
3917 /*!
3918  * Returns a profile array, apt for modification, by its name.
3919  *  \param [in] pflName - the name of the profile of interest.
3920  *  \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
3921  *  \throw If there is no a profile named \a pflName.
3922  */
3923 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
3924 {
3925   return contentNotNull()->getProfile(pflName);
3926 }
3927
3928 /*!
3929  * Returns a profile array, apt for modification, by its id.
3930  *  \param [in] pflId - the id of the profile of interest.
3931  *  \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
3932  *  \throw If there is no a profile with id \a pflId.
3933  */
3934 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
3935 {
3936   return contentNotNull()->getProfileFromId(pflId);
3937 }
3938
3939 /*!
3940  * Removes profiles given by their ids. No data is updated to track this removal.
3941  *  \param [in] pflIds - a sequence of ids of the profiles to remove.
3942  */
3943 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
3944 {
3945   contentNotNull()->killProfileIds(pflIds);
3946 }
3947
3948 /*!
3949  * Removes localizations given by their ids. No data is updated to track this removal.
3950  *  \param [in] locIds - a sequence of ids of the localizations to remove.
3951  */
3952 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
3953 {
3954   contentNotNull()->killLocalizationIds(locIds);
3955 }
3956
3957 /*!
3958  * Stores a profile array.
3959  *  \param [in] pfl - the profile array to store.
3960  *  \throw If the name of \a pfl is empty.
3961  *  \throw If a profile with the same name as that of \a pfl already exists but contains
3962  *         different ids.
3963  */
3964 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
3965 {
3966   contentNotNull()->appendProfile(pfl);
3967 }
3968
3969 /*!
3970  * Adds a new localization of Gauss points.
3971  *  \param [in] locName - the name of the new localization.
3972  *  \param [in] geoType - a geometrical type of the reference cell.
3973  *  \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
3974  *         must be \c nbOfNodesPerCell * \c dimOfType.
3975  *  \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
3976  *         must be  _wg_.size() * \c dimOfType.
3977  *  \param [in] w - the weights of Gauss points.
3978  *  \throw If \a locName is empty.
3979  *  \throw If a localization with the name \a locName already exists but is
3980  *         different form the new one.
3981  */
3982 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)
3983 {
3984   contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
3985 }
3986
3987 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
3988 {
3989   MEDFileFieldGlobs *g(_globals);
3990   if(!g)
3991     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
3992   return g;
3993 }
3994
3995 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
3996 {
3997   const MEDFileFieldGlobs *g(_globals);
3998   if(!g)
3999     throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
4000   return g;
4001 }
4002
4003 //= MEDFileFieldNameScope
4004
4005 MEDFileFieldNameScope::MEDFileFieldNameScope()
4006 {
4007 }
4008
4009 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName):_name(fieldName)
4010 {
4011 }
4012
4013 /*!
4014  * Returns the name of \a this field.
4015  *  \return std::string - a string containing the field name.
4016  */
4017 std::string MEDFileFieldNameScope::getName() const
4018 {
4019   return _name;
4020 }
4021
4022 /*!
4023  * Sets name of \a this field
4024  *  \param [in] name - the new field name.
4025  */
4026 void MEDFileFieldNameScope::setName(const std::string& fieldName)
4027 {
4028   _name=fieldName;
4029 }
4030
4031 std::string MEDFileFieldNameScope::getDtUnit() const
4032 {
4033   return _dt_unit;
4034 }
4035
4036 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
4037 {
4038   _dt_unit=dtUnit;
4039 }
4040
4041 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
4042 {
4043   _name=other._name;
4044   _dt_unit=other._dt_unit;
4045 }
4046
4047 //= MEDFileAnyTypeField1TSWithoutSDA
4048
4049 void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other)
4050 {
4051   _field_per_mesh.resize(other._field_per_mesh.size());
4052   std::size_t i=0;
4053   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++)
4054     {
4055       if((const MEDFileFieldPerMesh *)*it)
4056         _field_per_mesh[i]=(*it)->deepCopy(this);
4057     }
4058 }
4059
4060 /*!
4061  * Prints a string describing \a this field into a stream. This string is outputted 
4062  * by \c print Python command.
4063  *  \param [in] bkOffset - number of white spaces printed at the beginning of each line.
4064  *  \param [in,out] oss - the out stream.
4065  *  \param [in] f1tsId - the field index within a MED file. If \a f1tsId < 0, the tiny
4066  *          info id printed, else, not.
4067  */
4068 void MEDFileAnyTypeField1TSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
4069 {
4070   std::string startOfLine(bkOffset,' ');
4071   oss << startOfLine << "Field ";
4072   if(bkOffset==0)
4073     oss << "[Type=" << getTypeStr() << "] with name \"" << getName() << "\" ";
4074   oss << "on one time Step ";
4075   if(f1tsId>=0)
4076     oss << "(" << f1tsId << ") ";
4077   oss << "on iteration=" << _iteration << " order=" << _order << "." << std::endl;
4078   oss << startOfLine << "Time attached is : " << _dt << " [" << _dt_unit << "]." << std::endl;
4079   const DataArray *arr=getUndergroundDataArray();
4080   if(arr)
4081     {
4082       const std::vector<std::string> &comps=arr->getInfoOnComponents();
4083       if(f1tsId<0)
4084         {
4085           oss << startOfLine << "Field has " << comps.size() << " components with the following infos :" << std::endl;
4086           for(std::vector<std::string>::const_iterator it=comps.begin();it!=comps.end();it++)
4087             oss << startOfLine << "  -  \"" << (*it) << "\"" << std::endl;
4088         }
4089       if(arr->isAllocated())
4090         {
4091           oss << startOfLine << "Whole field contains " << arr->getNumberOfTuples() << " tuples." << std::endl;
4092         }
4093       else
4094         oss << startOfLine << "The array of the current field has not allocated yet !" << std::endl;
4095     }
4096   else
4097     {
4098       oss << startOfLine << "Field infos are empty ! Not defined yet !" << std::endl;
4099     }
4100   oss << startOfLine << "----------------------" << std::endl;
4101   if(!_field_per_mesh.empty())
4102     {
4103       int i=0;
4104       for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it2=_field_per_mesh.begin();it2!=_field_per_mesh.end();it2++,i++)
4105         {
4106           const MEDFileFieldPerMesh *cur=(*it2);
4107           if(cur)
4108             cur->simpleRepr(bkOffset,oss,i);
4109           else
4110             oss << startOfLine << "Field per mesh #" << i << " is not defined !" << std::endl;
4111         }
4112     }
4113   else
4114     {
4115       oss << startOfLine << "Field is not defined on any meshes !" << std::endl;
4116     }
4117   oss << startOfLine << "----------------------" << std::endl;
4118 }
4119
4120 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitComponents() const
4121 {
4122   const DataArray *arr(getUndergroundDataArray());
4123   if(!arr)
4124     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitComponents : no array defined !");
4125   int nbOfCompo=arr->getNumberOfComponents();
4126   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfCompo);
4127   for(int i=0;i<nbOfCompo;i++)
4128     {
4129       ret[i]=deepCopy();
4130       std::vector<int> v(1,i);
4131       MCAuto<DataArray> arr2=arr->keepSelectedComponents(v);
4132       ret[i]->setArray(arr2);
4133     }
4134   return ret;
4135 }
4136
4137 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)
4138 {
4139 }
4140
4141 MEDFileAnyTypeField1TSWithoutSDA::MEDFileAnyTypeField1TSWithoutSDA():_iteration(-1),_order(-1),_dt(0.),_csit(-1),_nb_of_tuples_to_be_allocated(-1)
4142 {
4143 }
4144
4145 /*!
4146  * Returns the maximal dimension of supporting elements. Returns -2 if \a this is
4147  * empty. Returns -1 if this in on nodes.
4148  *  \return int - the dimension of \a this.
4149  */
4150 int MEDFileAnyTypeField1TSWithoutSDA::getDimension() const
4151 {
4152   int ret=-2;
4153   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4154     (*it)->getDimension(ret);
4155   return ret;
4156 }
4157
4158 /*!
4159  * Returns the mesh name.
4160  *  \return std::string - a string holding the mesh name.
4161  *  \throw If \c _field_per_mesh.empty()
4162  */
4163 std::string MEDFileAnyTypeField1TSWithoutSDA::getMeshName() const
4164 {
4165   if(_field_per_mesh.empty())
4166     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshName : No field set !");
4167   return _field_per_mesh[0]->getMeshName();
4168 }
4169
4170 void MEDFileAnyTypeField1TSWithoutSDA::setMeshName(const std::string& newMeshName)
4171 {
4172   std::string oldName(getMeshName());
4173   std::vector< std::pair<std::string,std::string> > v(1);
4174   v[0].first=oldName; v[0].second=newMeshName;
4175   changeMeshNames(v);
4176 }
4177
4178 bool MEDFileAnyTypeField1TSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
4179 {
4180   bool ret=false;
4181   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4182     {
4183       MEDFileFieldPerMesh *cur(*it);
4184       if(cur)
4185         ret=cur->changeMeshNames(modifTab) || ret;
4186     }
4187   return ret;
4188 }
4189
4190 /*!
4191  * Returns the number of iteration of the state of underlying mesh.
4192  *  \return int - the iteration number.
4193  *  \throw If \c _field_per_mesh.empty()
4194  */
4195 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIteration() const
4196 {
4197   if(_field_per_mesh.empty())
4198     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshIteration : No field set !");
4199   return _field_per_mesh[0]->getMeshIteration();
4200 }
4201
4202 /*!
4203  * Returns the order number of iteration of the state of underlying mesh.
4204  *  \return int - the order number.
4205  *  \throw If \c _field_per_mesh.empty()
4206  */
4207 int MEDFileAnyTypeField1TSWithoutSDA::getMeshOrder() const
4208 {
4209   if(_field_per_mesh.empty())
4210     throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::getMeshOrder : No field set !");
4211   return _field_per_mesh[0]->getMeshOrder();
4212 }
4213
4214 /*!
4215  * Checks if \a this field is tagged by a given iteration number and a given
4216  * iteration order number.
4217  *  \param [in] iteration - the iteration number of interest.
4218  *  \param [in] order - the iteration order number of interest.
4219  *  \return bool - \c true if \a this->getIteration() == \a iteration && 
4220  *          \a this->getOrder() == \a order.
4221  */
4222 bool MEDFileAnyTypeField1TSWithoutSDA::isDealingTS(int iteration, int order) const
4223 {
4224   return iteration==_iteration && order==_order;
4225 }
4226
4227 /*!
4228  * Returns number of iteration and order number of iteration when
4229  * \a this field has been calculated.
4230  *  \return std::pair<int,int> - a pair of the iteration number and the iteration
4231  *          order number.
4232  */
4233 std::pair<int,int> MEDFileAnyTypeField1TSWithoutSDA::getDtIt() const
4234 {
4235   std::pair<int,int> p;
4236   fillIteration(p);
4237   return p;
4238 }
4239
4240 /*!
4241  * Returns number of iteration and order number of iteration when
4242  * \a this field has been calculated.
4243  *  \param [in,out] p - a pair returning the iteration number and the iteration
4244  *          order number.
4245  */
4246 void MEDFileAnyTypeField1TSWithoutSDA::fillIteration(std::pair<int,int>& p) const
4247 {
4248   p.first=_iteration;
4249   p.second=_order;
4250 }
4251
4252 /*!
4253  * Returns all types of spatial discretization of \a this field.
4254  *  \param [in,out] types - a sequence of types of \a this field.
4255  */
4256 void MEDFileAnyTypeField1TSWithoutSDA::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
4257 {
4258   std::set<TypeOfField> types2;
4259   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4260     {
4261       (*it)->fillTypesOfFieldAvailable(types2);
4262     }
4263   std::back_insert_iterator< std::vector<TypeOfField> > bi(types);
4264   std::copy(types2.begin(),types2.end(),bi);
4265 }
4266
4267 /*!
4268  * Returns all types of spatial discretization of \a this field.
4269  *  \return std::vector<TypeOfField> - a sequence of types of spatial discretization
4270  *          of \a this field.
4271  */
4272 std::vector<TypeOfField> MEDFileAnyTypeField1TSWithoutSDA::getTypesOfFieldAvailable() const
4273 {
4274   std::vector<TypeOfField> ret;
4275   fillTypesOfFieldAvailable(ret);
4276   return ret;
4277 }
4278
4279 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsed2() const
4280 {
4281   std::vector<std::string> ret;
4282   std::set<std::string> ret2;
4283   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4284     {
4285       std::vector<std::string> tmp=(*it)->getPflsReallyUsed();
4286       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4287         if(ret2.find(*it2)==ret2.end())
4288           {
4289             ret.push_back(*it2);
4290             ret2.insert(*it2);
4291           }
4292     }
4293   return ret;
4294 }
4295
4296 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsed2() const
4297 {
4298   std::vector<std::string> ret;
4299   std::set<std::string> ret2;
4300   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4301     {
4302       std::vector<std::string> tmp=(*it)->getLocsReallyUsed();
4303       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
4304         if(ret2.find(*it2)==ret2.end())
4305           {
4306             ret.push_back(*it2);
4307             ret2.insert(*it2);
4308           }
4309     }
4310   return ret;
4311 }
4312
4313 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getPflsReallyUsedMulti2() const
4314 {
4315   std::vector<std::string> ret;
4316   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4317     {
4318       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti();
4319       ret.insert(ret.end(),tmp.begin(),tmp.end());
4320     }
4321   return ret;
4322 }
4323
4324 std::vector<std::string> MEDFileAnyTypeField1TSWithoutSDA::getLocsReallyUsedMulti2() const
4325 {
4326   std::vector<std::string> ret;
4327   std::set<std::string> ret2;
4328   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4329     {
4330       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti();
4331       ret.insert(ret.end(),tmp.begin(),tmp.end());
4332     }
4333   return ret;
4334 }
4335
4336 void MEDFileAnyTypeField1TSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4337 {
4338   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4339     (*it)->changePflsRefsNamesGen(mapOfModif);
4340 }
4341
4342 void MEDFileAnyTypeField1TSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
4343 {
4344   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4345     (*it)->changeLocsRefsNamesGen(mapOfModif);
4346 }
4347
4348 /*!
4349  * Returns all attributes of parts of \a this field lying on a given mesh.
4350  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
4351  * item of every of returned sequences refers to the _i_-th part of \a this field.
4352  * Thus all sequences returned by this method are of the same length equal to number
4353  * of different types of supporting entities.<br>
4354  * A field part can include sub-parts with several different spatial discretizations,
4355  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
4356  * for example. Hence, some of the returned sequences contains nested sequences, and an item
4357  * of a nested sequence corresponds to a type of spatial discretization.<br>
4358  * This method allows for iteration over MEDFile DataStructure without any overhead.
4359  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4360  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4361  *          not checked if \a mname == \c NULL).
4362  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
4363  *          a field part is returned. 
4364  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
4365  *          This sequence is of the same length as \a types. 
4366  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
4367  *          discretization. A profile name can be empty.
4368  *          Length of this and of nested sequences is the same as that of \a typesF.
4369  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
4370  *          discretization. A localization name can be empty.
4371  *          Length of this and of nested sequences is the same as that of \a typesF.
4372  *  \return std::vector< std::vector< std::pair<int,int> > > - a sequence holding a range
4373  *          of ids of tuples within the data array, per each type of spatial
4374  *          discretization within one mesh entity type. 
4375  *          Length of this and of nested sequences is the same as that of \a typesF.
4376  *  \throw If no field is lying on \a mname.
4377  */
4378 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
4379 {
4380   int meshId=0;
4381   if(!mname.empty())
4382     meshId=getMeshIdFromMeshName(mname);
4383   else
4384     if(_field_per_mesh.empty())
4385       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
4386   return _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4387 }
4388
4389 /*!
4390  * Returns dimensions of mesh elements \a this field lies on. The returned value is a
4391  * maximal absolute dimension and values returned via the out parameter \a levs are 
4392  * dimensions relative to the maximal absolute dimension. <br>
4393  * This method is designed for MEDFileField1TS instances that have a discretization
4394  * \ref MEDCoupling::ON_CELLS "ON_CELLS", 
4395  * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT", 
4396  * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
4397  * Only these 3 discretizations will be taken into account here. If \a this is
4398  * \ref MEDCoupling::ON_NODES "ON_NODES", -1 is returned and \a levs are empty.<br>
4399  * This method is useful to make the link between the dimension of the underlying mesh
4400  * and the levels of \a this, because it is possible that the highest dimension of \a this
4401  * field is not equal to the dimension of the underlying mesh.
4402  * 
4403  * Let's consider the following case:
4404  * - mesh \a m1 has a meshDimension 3 and has non empty levels [0,-1,-2] with elements
4405  * TETRA4, HEXA8, TRI3 and SEG2.
4406  * - field \a f1 lies on \a m1 and is defined on 3D and 1D elements TETRA4 and SEG2.
4407  * - field \a f2 lies on \a m1 and is defined on 2D and 1D elements TRI3 and SEG2.
4408  *
4409  * In this case \a f1->getNonEmptyLevels() returns (3,[0,-2]) and \a
4410  * f2->getNonEmptyLevels() returns (2,[0,-1]). <br>
4411  * The returned values can be used for example to retrieve a MEDCouplingFieldDouble lying
4412  * on elements of a certain relative level by calling getFieldAtLevel(). \a meshDimRelToMax
4413  * parameter of getFieldAtLevel() is computed basing on the returned values as this:
4414  * <em> meshDimRelToMax = absDim - meshDim + relativeLev </em>.
4415  * For example<br>
4416  * to retrieve the highest level of
4417  * \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+0 ); // absDim - meshDim + relativeLev</em><br> 
4418  * to retrieve the lowest level of \a f1: <em>f1->getFieldAtLevel( ON_CELLS, 3-3+(-2) );</em><br>
4419  * to retrieve the highest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+0 );</em><br>
4420  * to retrieve the lowest level of \a f2: <em>f2->getFieldAtLevel( ON_CELLS, 2-3+(-1) )</em>.
4421  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
4422  *          for the case with only one underlying mesh. (Actually, the number of meshes is
4423  *          not checked if \a mname == \c NULL).
4424  *  \param [in,out] levs - a sequence returning the dimensions relative to the maximal
4425  *          absolute one. They are in decreasing order. This sequence is cleared before
4426  *          filling it in.
4427  *  \return int - the maximal absolute dimension of elements \a this fields lies on.
4428  *  \throw If no field is lying on \a mname.
4429  */
4430 int MEDFileAnyTypeField1TSWithoutSDA::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
4431 {
4432   levs.clear();
4433   int meshId=getMeshIdFromMeshName(mname);
4434   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4435   std::vector< std::vector<TypeOfField> > typesF;
4436   std::vector< std::vector<std::string> > pfls, locs;
4437   _field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
4438   if(types.empty())
4439     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getNonEmptyLevels : 'this' is empty !");
4440   std::set<INTERP_KERNEL::NormalizedCellType> st(types.begin(),types.end());
4441   if(st.size()==1 && (*st.begin())==INTERP_KERNEL::NORM_ERROR)
4442     return -1;
4443   st.erase(INTERP_KERNEL::NORM_ERROR);
4444   std::set<int> ret1;
4445   for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=st.begin();it!=st.end();it++)
4446     {
4447       const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(*it);
4448       ret1.insert((int)cm.getDimension());
4449     }
4450   int ret=*std::max_element(ret1.begin(),ret1.end());
4451   std::copy(ret1.rbegin(),ret1.rend(),std::back_insert_iterator<std::vector<int> >(levs));
4452   std::transform(levs.begin(),levs.end(),levs.begin(),std::bind2nd(std::plus<int>(),-ret));
4453   return ret;
4454 }
4455
4456 /*!
4457  * \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.
4458  * \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.
4459  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4460  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4461  */
4462 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
4463 {
4464   int mid=getMeshIdFromMeshName(mName);
4465   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4466 }
4467
4468 /*!
4469  * \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.
4470  * \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.
4471  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
4472  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
4473  */
4474 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TSWithoutSDA::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
4475 {
4476   int mid=getMeshIdFromMeshName(mName);
4477   return _field_per_mesh[mid]->getLeafGivenTypeAndLocId(typ,locId);
4478 }
4479
4480 /*!
4481  * \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.
4482  */
4483 int MEDFileAnyTypeField1TSWithoutSDA::getMeshIdFromMeshName(const std::string& mName) const
4484 {
4485   if(_field_per_mesh.empty())
4486     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No field set !");
4487   if(mName.empty())
4488     return 0;
4489   std::string mName2(mName);
4490   int ret=0;
4491   std::vector<std::string> msg;
4492   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,ret++)
4493     if(mName2==(*it)->getMeshName())
4494       return ret;
4495     else
4496       msg.push_back((*it)->getMeshName());
4497   std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getMeshIdFromMeshName : No such mesh \"" << mName2 << "\" as underlying mesh of field \"" << getName() << "\" !\n";
4498   oss << "Possible meshes are : ";
4499   for(std::vector<std::string>::const_iterator it2=msg.begin();it2!=msg.end();it2++)
4500     oss << "\"" << (*it2) << "\" ";
4501   throw INTERP_KERNEL::Exception(oss.str());
4502 }
4503
4504 int MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary(const MEDCouplingMesh *mesh)
4505 {
4506   if(!mesh)
4507     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::addNewEntryIfNecessary : input mesh is NULL !");
4508   std::string tmp(mesh->getName());
4509   if(tmp.empty())
4510     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::addNewEntryIfNecessary : empty mesh name ! unsupported by MED file !");
4511   std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();
4512   int i=0;
4513   for(;it!=_field_per_mesh.end();it++,i++)
4514     {
4515       if((*it)->getMeshName()==tmp)
4516         return i;
4517     }
4518   int sz=_field_per_mesh.size();
4519   _field_per_mesh.resize(sz+1);
4520   _field_per_mesh[sz]=MEDFileFieldPerMesh::New(this,mesh);
4521   return sz;
4522 }
4523
4524 bool MEDFileAnyTypeField1TSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
4525                                                                    MEDFileFieldGlobsReal& glob)
4526 {
4527   bool ret=false;
4528   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4529     {
4530       MEDFileFieldPerMesh *fpm(*it);
4531       if(fpm)
4532         ret=fpm->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
4533     }
4534   return ret;
4535 }
4536
4537 /*!
4538  * This method splits \a this into several sub-parts so that each sub parts have exactly one spatial discretization. This method implements the minimal
4539  * splitting that leads to single spatial discretization of this.
4540  *
4541  * \sa splitMultiDiscrPerGeoTypes
4542  */
4543 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations() const
4544 {
4545   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4546   std::vector< std::vector<TypeOfField> > typesF;
4547   std::vector< std::vector<std::string> > pfls,locs;
4548   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4549   std::set<TypeOfField> allEnt;
4550   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++)
4551     for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4552       allEnt.insert(*it2);
4553   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(allEnt.size());
4554   std::set<TypeOfField>::const_iterator it3(allEnt.begin());
4555   for(std::size_t i=0;i<allEnt.size();i++,it3++)
4556     {
4557       std::vector< std::pair<int,int> > its;
4558       ret[i]=shallowCpy();
4559       int newLgth(ret[i]->keepOnlySpatialDiscretization(*it3,its));
4560       ret[i]->updateData(newLgth,its);
4561     }
4562   return ret;
4563 }
4564
4565 /*!
4566  * This method performs a sub splitting as splitDiscretizations does but finer. This is the finest spliting level that can be done.
4567  * This method implements the minimal splitting so that each returned elements are mono Gauss discretization per geometric type.
4568  *
4569  * \sa splitDiscretizations
4570  */
4571 std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes() const
4572 {
4573   std::vector<INTERP_KERNEL::NormalizedCellType> types;
4574   std::vector< std::vector<TypeOfField> > typesF;
4575   std::vector< std::vector<std::string> > pfls,locs;
4576   std::vector< std::vector<std::pair<int,int> > > bgEnd(getFieldSplitedByType(getMeshName().c_str(),types,typesF,pfls,locs));
4577   std::set<TypeOfField> allEnt;
4578   std::size_t nbOfMDPGT(0),ii(0);
4579   for(std::vector< std::vector<TypeOfField> >::const_iterator it1=typesF.begin();it1!=typesF.end();it1++,ii++)
4580     {
4581       nbOfMDPGT=std::max(nbOfMDPGT,locs[ii].size());
4582       for(std::vector<TypeOfField>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
4583         allEnt.insert(*it2);
4584     }
4585   if(allEnt.size()!=1)
4586     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : this field is expected to be defined only on one spatial discretization !");
4587   if(nbOfMDPGT==0)
4588     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
4589   if(nbOfMDPGT==1)
4590     {
4591       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret0(1);
4592       ret0[0]=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(this); this->incrRef();
4593       return ret0;
4594     }
4595   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret(nbOfMDPGT);
4596   for(std::size_t i=0;i<nbOfMDPGT;i++)
4597     {
4598       std::vector< std::pair<int,int> > its;
4599       ret[i]=shallowCpy();
4600       int newLgth(ret[i]->keepOnlyGaussDiscretization(i,its));
4601       ret[i]->updateData(newLgth,its);
4602     }
4603   return ret;
4604 }
4605
4606 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlySpatialDiscretization(TypeOfField tof, std::vector< std::pair<int,int> >& its)
4607 {
4608   int globalCounter(0);
4609   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4610     (*it)->keepOnlySpatialDiscretization(tof,globalCounter,its);
4611   return globalCounter;
4612 }
4613
4614 int MEDFileAnyTypeField1TSWithoutSDA::keepOnlyGaussDiscretization(std::size_t idOfDisc, std::vector< std::pair<int,int> >& its)
4615 {
4616   int globalCounter(0);
4617   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4618     (*it)->keepOnlyGaussDiscretization(idOfDisc,globalCounter,its);
4619   return globalCounter;
4620 }
4621
4622 void MEDFileAnyTypeField1TSWithoutSDA::updateData(int newLgth, const std::vector< std::pair<int,int> >& oldStartStops)
4623 {
4624   if(_nb_of_tuples_to_be_allocated>=0)
4625     {
4626       _nb_of_tuples_to_be_allocated=newLgth;
4627       const DataArray *oldArr(getUndergroundDataArray());
4628       if(oldArr)
4629         {
4630           MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4631           newArr->setInfoAndChangeNbOfCompo(oldArr->getInfoOnComponents());
4632           setArray(newArr);
4633           _nb_of_tuples_to_be_allocated=newLgth;//force the _nb_of_tuples_to_be_allocated because setArray has been used specialy
4634         }
4635       return ;
4636     }
4637   if(_nb_of_tuples_to_be_allocated==-1)
4638     return ;
4639   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4640     {
4641       const DataArray *oldArr(getUndergroundDataArray());
4642       if(!oldArr || !oldArr->isAllocated())
4643         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 1 !");
4644       MCAuto<DataArray> newArr(createNewEmptyDataArrayInstance());
4645       newArr->alloc(newLgth,getNumberOfComponents());
4646       if(oldArr)
4647         newArr->copyStringInfoFrom(*oldArr);
4648       int pos=0;
4649       for(std::vector< std::pair<int,int> >::const_iterator it=oldStartStops.begin();it!=oldStartStops.end();it++)
4650         {
4651           if((*it).second<(*it).first)
4652             throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : the range in the leaves was invalid !");
4653           newArr->setContigPartOfSelectedValuesSlice(pos,oldArr,(*it).first,(*it).second,1);
4654           pos+=(*it).second-(*it).first;
4655         }
4656       setArray(newArr);
4657       return ;
4658     }
4659   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::updateData : internal error 2 !");
4660 }
4661
4662 void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const
4663 {
4664   if(_field_per_mesh.empty())
4665     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : empty field !");
4666   if(_field_per_mesh.size()>1)
4667     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !");
4668   _field_per_mesh[0]->copyOptionsFrom(opts);
4669   _field_per_mesh[0]->writeLL(fid,nasc);
4670 }
4671
4672 /*!
4673  * 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.
4674  * If false is returned the memory allocation is not required.
4675  */
4676 bool MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile()
4677 {
4678   if(_nb_of_tuples_to_be_allocated>=0)
4679     {
4680       getOrCreateAndGetArray()->alloc(_nb_of_tuples_to_be_allocated,getNumberOfComponents());
4681       _nb_of_tuples_to_be_allocated=-2;
4682       return true;
4683     }
4684   if(_nb_of_tuples_to_be_allocated==-2 || _nb_of_tuples_to_be_allocated==-3)
4685     return false;
4686   if(_nb_of_tuples_to_be_allocated==-1)
4687     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : trying to read from a file an empty instance ! Need to prepare the structure before !");
4688   if(_nb_of_tuples_to_be_allocated<-3)
4689     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4690   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::allocIfNecessaryTheArrayToReceiveDataFromFile : internal error !");
4691 }
4692
4693 void MEDFileAnyTypeField1TSWithoutSDA::loadOnlyStructureOfDataRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4694 {
4695   med_int numdt,numit;
4696   med_float dt;
4697   med_int nmesh;
4698   med_bool localMesh;
4699   med_int meshnumdt,meshnumit;
4700   INTERP_KERNEL::AutoPtr<char> meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
4701   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&_dt));
4702   MEDFILESAFECALLERRD0(MEDfield23ComputingStepMeshInfo,(fid,nasc.getName().c_str(),_csit,&numdt,&numit,&dt,&nmesh,meshName,&localMesh,&meshnumdt,&meshnumit));
4703   if(_iteration!=numdt || _order!=numit)
4704     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively : unexpected exception internal error !");
4705   _field_per_mesh.resize(nmesh);
4706   //
4707   MEDFileMesh *mm(0);
4708   if(ms)
4709     {
4710       std::string meshNameCpp(MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1));
4711       mm=ms->getMeshWithName(meshNameCpp);
4712     }
4713   //
4714   for(int i=0;i<nmesh;i++)
4715     _field_per_mesh[i]=MEDFileFieldPerMesh::NewOnRead(fid,this,i,meshnumdt,meshnumit,nasc,mm,entities);
4716   _nb_of_tuples_to_be_allocated=0;
4717   for(int i=0;i<nmesh;i++)
4718     _field_per_mesh[i]->loadOnlyStructureOfDataRecursively(fid,_nb_of_tuples_to_be_allocated,nasc);
4719 }
4720
4721 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
4722 {
4723   allocIfNecessaryTheArrayToReceiveDataFromFile();
4724   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4725     (*it)->loadBigArraysRecursively(fid,nasc);
4726 }
4727
4728 void MEDFileAnyTypeField1TSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
4729 {
4730   if(allocIfNecessaryTheArrayToReceiveDataFromFile())
4731     for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4732       (*it)->loadBigArraysRecursively(fid,nasc);
4733 }
4734
4735 void MEDFileAnyTypeField1TSWithoutSDA::loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities)
4736 {
4737   loadOnlyStructureOfDataRecursively(fid,nasc,ms,entities);
4738   loadBigArraysRecursively(fid,nasc);
4739 }
4740
4741 void MEDFileAnyTypeField1TSWithoutSDA::unloadArrays()
4742 {
4743   DataArray *thisArr(getUndergroundDataArray());
4744   if(thisArr && thisArr->isAllocated())
4745     {
4746       _nb_of_tuples_to_be_allocated=thisArr->getNumberOfTuples();
4747       thisArr->desallocate();
4748     }
4749 }
4750
4751 std::size_t MEDFileAnyTypeField1TSWithoutSDA::getHeapMemorySizeWithoutChildren() const
4752 {
4753   return _dt_unit.capacity()+_field_per_mesh.capacity()*sizeof(MCAuto< MEDFileFieldPerMesh >);
4754 }
4755
4756 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TSWithoutSDA::getDirectChildrenWithNull() const
4757 {
4758   std::vector<const BigMemoryObject *> ret;
4759   if(getUndergroundDataArray())
4760     ret.push_back(getUndergroundDataArray());
4761   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4762     ret.push_back((const MEDFileFieldPerMesh *)*it);
4763   return ret;
4764 }
4765
4766 /*!
4767  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
4768  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
4769  * "Sort By Type"), if not, an exception is thrown. 
4770  *  \param [in] field - the field to add to \a this. The array of field \a field is ignored
4771  *  \param [in] arr - the array of values.
4772  *  \param [in,out] glob - the global data where profiles and localization present in
4773  *          \a field, if any, are added.
4774  *  \throw If the name of \a field is empty.
4775  *  \throw If the data array of \a field is not set.
4776  *  \throw If \a this->_arr is already allocated but has different number of components
4777  *         than \a field.
4778  *  \throw If the underlying mesh of \a field has no name.
4779  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
4780  */
4781 void MEDFileAnyTypeField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4782 {
4783   const MEDCouplingMesh *mesh=field->getMesh();
4784   //
4785   TypeOfField type=field->getTypeOfField();
4786   std::vector<DataArrayInt *> dummy;
4787   int start=copyTinyInfoFrom(field,arr);
4788   int pos=addNewEntryIfNecessary(mesh);
4789   if(type!=ON_NODES)
4790     {
4791       std::vector<int> code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh);
4792       _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,arr,glob,nasc);
4793     }
4794   else
4795     _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,arr,glob);
4796 }
4797
4798 /*!
4799  * Adds a MEDCouplingFieldDouble to \a this. Specified entities of a given dimension
4800  * of a given mesh are used as the support of the given field (a real support is not used). 
4801  * Elements of the given mesh must be sorted suitable for writing to MED file. 
4802  * Order of underlying mesh entities of the given field specified by \a profile parameter
4803  * is not prescribed; this method permutes field values to have them sorted by element
4804  * type as required for writing to MED file. A new profile is added only if no equal
4805  * profile is missing. 
4806  *  \param [in] field - the field to add to \a this. The field double values are ignored.
4807  *  \param [in] arrOfVals - the values of the field \a field used.
4808  *  \param [in] mesh - the supporting mesh of \a field.
4809  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on.
4810  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
4811  *  \param [in,out] glob - the global data where profiles and localization present in
4812  *          \a field, if any, are added.
4813  *  \throw If either \a field or \a mesh or \a profile has an empty name.
4814  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
4815  *  \throw If the data array of \a field is not set.
4816  *  \throw If \a this->_arr is already allocated but has different number of components
4817  *         than \a field.
4818  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
4819  *  \sa setFieldNoProfileSBT()
4820  */
4821 void MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob, const MEDFileFieldNameScope& nasc)
4822 {
4823   if(!field)
4824     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input field is null !");
4825   if(!arrOfVals || !arrOfVals->isAllocated())
4826     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input array is null or not allocated !");
4827   TypeOfField type=field->getTypeOfField();
4828   std::vector<DataArrayInt *> idsInPflPerType;
4829   std::vector<DataArrayInt *> idsPerType;
4830   std::vector<int> code,code2;
4831   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
4832   if(type!=ON_NODES)
4833     {
4834       m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType);
4835       std::vector< MCAuto<DataArrayInt> > idsInPflPerType2(idsInPflPerType.size()); std::copy(idsInPflPerType.begin(),idsInPflPerType.end(),idsInPflPerType2.begin());
4836       std::vector< MCAuto<DataArrayInt> > idsPerType2(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType2.begin()); 
4837       std::vector<const DataArrayInt *> idsPerType3(idsPerType.size()); std::copy(idsPerType.begin(),idsPerType.end(),idsPerType3.begin());
4838       // start of check
4839       MCAuto<MEDCouplingFieldDouble> field2=field->clone(false);
4840       int nbOfTuplesExp=field2->getNumberOfTuplesExpectedRegardingCode(code,idsPerType3);
4841       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4842         {
4843           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : The array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4844           throw INTERP_KERNEL::Exception(oss.str());
4845         }
4846       // end of check
4847       int start=copyTinyInfoFrom(field,arrOfVals);
4848       code2=m->getDistributionOfTypes();
4849       //
4850       int pos=addNewEntryIfNecessary(m);
4851       _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,arrOfVals,m,glob,nasc);
4852     }
4853   else
4854     {
4855       if(!profile || !profile->isAllocated() || profile->getNumberOfComponents()!=1)
4856         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : input profile is null, not allocated or with number of components != 1 !");
4857       std::vector<int> v(3); v[0]=-1; v[1]=profile->getNumberOfTuples(); v[2]=0;
4858       std::vector<const DataArrayInt *> idsPerType3(1); idsPerType3[0]=profile;
4859       int nbOfTuplesExp=field->getNumberOfTuplesExpectedRegardingCode(v,idsPerType3);
4860       if(nbOfTuplesExp!=arrOfVals->getNumberOfTuples())
4861         {
4862           std::ostringstream oss; oss << "MEDFileAnyTypeField1TSWithoutSDA::setFieldProfile : For node field, the array is expected to have " << nbOfTuplesExp << " tuples ! It has " << arrOfVals->getNumberOfTuples() << " !";
4863           throw INTERP_KERNEL::Exception(oss.str());
4864         }
4865       int start=copyTinyInfoFrom(field,arrOfVals);
4866       int pos=addNewEntryIfNecessary(m);
4867       _field_per_mesh[pos]->assignNodeFieldProfile(start,profile,field,arrOfVals,glob,nasc);
4868     }
4869 }
4870
4871 /*!
4872  * \param [in] newNbOfTuples - The new nb of tuples to be allocated.
4873  */
4874 void MEDFileAnyTypeField1TSWithoutSDA::allocNotFromFile(int newNbOfTuples)
4875 {
4876   if(_nb_of_tuples_to_be_allocated>=0)
4877     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 !");
4878   DataArray *arr(getOrCreateAndGetArray());
4879   arr->alloc(newNbOfTuples,arr->getNumberOfComponents());
4880   _nb_of_tuples_to_be_allocated=-3;
4881 }
4882
4883 /*!
4884  * Copies tiny info and allocates \a this->_arr instance of DataArrayDouble to
4885  * append data of a given MEDCouplingFieldDouble. So that the size of \a this->_arr becomes
4886  * larger by the size of \a field. Returns an id of the first not filled
4887  * tuple of \a this->_arr.
4888  *  \param [in] field - the field to copy the info on components and the name from.
4889  *  \return int - the id of first not initialized tuple of \a this->_arr.
4890  *  \throw If the name of \a field is empty.
4891  *  \throw If the data array of \a field is not set.
4892  *  \throw If \a this->_arr is already allocated but has different number of components
4893  *         than \a field.
4894  */
4895 int MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
4896 {
4897   if(!field)
4898     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::copyTinyInfoFrom : input field is NULL !");
4899   std::string name(field->getName());
4900   setName(name.c_str());
4901   setDtUnit(field->getTimeUnit());
4902   if(name.empty())
4903     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
4904   if(!arr)
4905     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : no array set !");
4906   if(!arr->isAllocated())
4907     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::copyTinyInfoFrom : array is not allocated !");
4908   _dt=field->getTime(_iteration,_order);
4909   getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(arr->getInfoOnComponents());
4910   if(!getOrCreateAndGetArray()->isAllocated())
4911     {
4912       allocNotFromFile(arr->getNumberOfTuples());
4913       return 0;
4914     }
4915   else
4916     {
4917       int oldNbOfTuples=getOrCreateAndGetArray()->getNumberOfTuples();
4918       int newNbOfTuples=oldNbOfTuples+arr->getNumberOfTuples();
4919       getOrCreateAndGetArray()->reAlloc(newNbOfTuples);
4920       _nb_of_tuples_to_be_allocated=-3;
4921       return oldNbOfTuples;
4922     }
4923 }
4924
4925 /*!
4926  * Returns number of components in \a this field
4927  *  \return int - the number of components.
4928  */
4929 int MEDFileAnyTypeField1TSWithoutSDA::getNumberOfComponents() const
4930 {
4931   return getOrCreateAndGetArray()->getNumberOfComponents();
4932 }
4933
4934 /*!
4935  * Change info on components in \a this.
4936  * \throw If size of \a infos is not equal to the number of components already in \a this.
4937  */
4938 void MEDFileAnyTypeField1TSWithoutSDA::setInfo(const std::vector<std::string>& infos)
4939 {
4940   DataArray *arr=getOrCreateAndGetArray();
4941   arr->setInfoOnComponents(infos);//will throw an exception if number of components mimatches
4942 }
4943
4944 /*!
4945  * Returns info on components of \a this field.
4946  *  \return const std::vector<std::string>& - a sequence of strings each being an
4947  *          information on _i_-th component.
4948  */
4949 const std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo() const
4950 {
4951   const DataArray *arr=getOrCreateAndGetArray();
4952   return arr->getInfoOnComponents();
4953 }
4954
4955 /*!
4956  * Returns a mutable info on components of \a this field.
4957  *  \return std::vector<std::string>& - a sequence of strings each being an
4958  *          information on _i_-th component.
4959  */
4960 std::vector<std::string>& MEDFileAnyTypeField1TSWithoutSDA::getInfo()
4961 {
4962   DataArray *arr=getOrCreateAndGetArray();
4963   return arr->getInfoOnComponents();
4964 }
4965
4966 bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const
4967 {
4968   for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++)
4969     {
4970       const MEDFileFieldPerMesh *fpm(*it);
4971       if(!fpm)
4972         continue;
4973       if(fpm->presenceOfMultiDiscPerGeoType())
4974         return true;
4975     }
4976   return false;
4977 }
4978
4979 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
4980 {
4981   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 !";
4982   if(_field_per_mesh.empty())
4983     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !");
4984   if(_field_per_mesh.size()>1)
4985     throw INTERP_KERNEL::Exception(MSG0);
4986   if(_field_per_mesh[0].isNull())
4987     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !");
4988   const MEDFileFieldPerMesh *pm(_field_per_mesh[0]);
4989   std::set<TypeOfField> types;
4990   pm->fillTypesOfFieldAvailable(types);
4991   if(types.size()!=1)
4992     throw INTERP_KERNEL::Exception(MSG0);
4993   TypeOfField type(*types.begin());
4994   int meshDimRelToMax(0);
4995   if(type==ON_NODES)
4996     meshDimRelToMax=0;
4997   else
4998     {
4999       int myDim(std::numeric_limits<int>::max());
5000       bool isUnique(pm->isUniqueLevel(myDim));
5001       if(!isUnique)
5002         throw INTERP_KERNEL::Exception(MSG0);
5003       meshDimRelToMax=myDim-mesh->getMeshDimension();
5004       if(meshDimRelToMax>0)
5005         throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !");
5006     }
5007   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc);
5008 }
5009
5010 /*!
5011  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5012  *  \param [in] type - a spatial discretization of the new field.
5013  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5014  *  \param [in] mName - a name of the supporting mesh.
5015  *  \param [in] renumPol - specifies how to permute values of the result field according to
5016  *          the optional numbers of cells and nodes, if any. The valid values are
5017  *          - 0 - do not permute.
5018  *          - 1 - permute cells.
5019  *          - 2 - permute nodes.
5020  *          - 3 - permute cells and nodes.
5021  *
5022  *  \param [in] glob - the global data storing profiles and localization.
5023  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5024  *          caller is to delete this field using decrRef() as it is no more needed. 
5025  *  \throw If the MED file is not readable.
5026  *  \throw If there is no mesh named \a mName in the MED file.
5027  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5028  *  \throw If no field of \a this is lying on the mesh \a mName.
5029  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5030  */
5031 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5032 {
5033   MCAuto<MEDFileMesh> mm;
5034   if(mName.empty())
5035     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5036   else
5037     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5038   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5039 }
5040
5041 /*!
5042  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5043  *  \param [in] type - a spatial discretization of the new field.
5044  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5045  *  \param [in] renumPol - specifies how to permute values of the result field according to
5046  *          the optional numbers of cells and nodes, if any. The valid values are
5047  *          - 0 - do not permute.
5048  *          - 1 - permute cells.
5049  *          - 2 - permute nodes.
5050  *          - 3 - permute cells and nodes.
5051  *
5052  *  \param [in] glob - the global data storing profiles and localization.
5053  *  \param [in] mesh - the supporting mesh.
5054  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5055  *          caller is to delete this field using decrRef() as it is no more needed. 
5056  *  \throw If the MED file is not readable.
5057  *  \throw If no field of \a this is lying on \a mesh.
5058  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5059  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5060  */
5061 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5062 {
5063   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax,false));
5064   const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1));
5065   if(meshDimRelToMax==1)
5066     (static_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)m))->setMeshDimension(0);
5067   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc);
5068 }
5069
5070 /*!
5071  * Returns a new MEDCouplingFieldDouble of a given type lying on the top level cells of a
5072  * given mesh. 
5073  *  \param [in] type - a spatial discretization of the new field.
5074  *  \param [in] mName - a name of the supporting mesh.
5075  *  \param [in] renumPol - specifies how to permute values of the result field according to
5076  *          the optional numbers of cells and nodes, if any. The valid values are
5077  *          - 0 - do not permute.
5078  *          - 1 - permute cells.
5079  *          - 2 - permute nodes.
5080  *          - 3 - permute cells and nodes.
5081  *
5082  *  \param [in] glob - the global data storing profiles and localization.
5083  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5084  *          caller is to delete this field using decrRef() as it is no more needed. 
5085  *  \throw If the MED file is not readable.
5086  *  \throw If there is no mesh named \a mName in the MED file.
5087  *  \throw If there are no mesh entities in the mesh.
5088  *  \throw If no field values of the given \a type are available.
5089  */
5090 MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto<DataArray>& arrOut, const MEDFileFieldNameScope& nasc) const
5091 {
5092   MCAuto<MEDFileMesh> mm;
5093   if(mName.empty())
5094     mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),getMeshIteration(),getMeshOrder());
5095   else
5096     mm=MEDFileMesh::New(glob->getFileName(),mName,getMeshIteration(),getMeshOrder());
5097   int absDim=getDimension();
5098   int meshDimRelToMax=absDim-mm->getMeshDimension();
5099   return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm,arrOut,nasc);
5100 }
5101
5102 /*!
5103  * Returns a new MEDCouplingFieldDouble of given type lying on a given support.
5104  *  \param [in] type - a spatial discretization of the new field.
5105  *  \param [in] renumPol - specifies how to permute values of the result field according to
5106  *          the optional numbers of cells and nodes, if any. The valid values are
5107  *          - 0 - do not permute.
5108  *          - 1 - permute cells.
5109  *          - 2 - permute nodes.
5110  *          - 3 - permute cells and nodes.
5111  *
5112  *  \param [in] glob - the global data storing profiles and localization.
5113  *  \param [in] mesh - the supporting mesh.
5114  *  \param [in] cellRenum - the cell numbers array used for permutation of the result
5115  *         field according to \a renumPol.
5116  *  \param [in] nodeRenum - the node numbers array used for permutation of the result
5117  *         field according to \a renumPol.
5118  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
5119  *          caller is to delete this field using decrRef() as it is no more needed. 
5120  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
5121  *  \throw If no field of \a this is lying on \a mesh.
5122  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
5123  */
5124 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
5125 {
5126   static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !";
5127   int meshId=getMeshIdFromMeshName(mesh->getName());
5128   bool isPfl=false;
5129   MCAuto<MEDCouplingFieldDouble> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevel(type,glob,mesh,isPfl,arrOut,nasc);
5130   switch(renumPol)
5131   {
5132     case 0:
5133       {
5134         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5135         return ret.retn();
5136       }
5137     case 3:
5138     case 1:
5139       {
5140         if(isPfl)
5141           throw INTERP_KERNEL::Exception(msg1);
5142         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5143         if(cellRenum)
5144           {
5145             if((int)cellRenum->getNbOfElems()!=mesh->getNumberOfCells())
5146               {
5147                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5148                 oss << "\"" << getName() << "\" has partial renumbering (some geotype has no renumber) !";
5149                 throw INTERP_KERNEL::Exception(oss.str());
5150               }
5151             MEDCouplingFieldDiscretization *disc=ret->getDiscretization();
5152             if(!disc) throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel : internal error, no discretization on field !");
5153             std::vector<DataArray *> arrOut2(1,arrOut);
5154             // 2 following lines replace ret->renumberCells(cellRenum->getConstPointer()) if not DataArrayDouble
5155             disc->renumberArraysForCell(ret->getMesh(),arrOut2,cellRenum->getConstPointer(),true);
5156             (const_cast<MEDCouplingMesh*>(ret->getMesh()))->renumberCells(cellRenum->getConstPointer(),true);
5157           }
5158         if(renumPol==1)
5159           return ret.retn();
5160       }
5161     case 2:
5162       {
5163         //no need to test _field_per_mesh.empty() because geMeshName has already done it
5164         if(isPfl)
5165           throw INTERP_KERNEL::Exception(msg1);
5166         if(nodeRenum)
5167           {
5168             if((int)nodeRenum->getNbOfElems()!=mesh->getNumberOfNodes())
5169               {
5170                 std::ostringstream oss; oss << "MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : Request of simple renumbering but it seems that underlying mesh \"" << mesh->getName() << "\" of requested field ";
5171                 oss << "\"" << nasc.getName() << "\" not defined on all nodes !";
5172                 throw INTERP_KERNEL::Exception(oss.str());
5173               }
5174             MCAuto<DataArrayInt> nodeRenumSafe=nodeRenum->checkAndPreparePermutation();
5175             if(!dynamic_cast<DataArrayDouble *>((DataArray *)arrOut))
5176               throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : node renumbering not implemented for not double DataArrays !");
5177             ret->renumberNodes(nodeRenumSafe->getConstPointer());
5178           }
5179         return ret.retn();
5180       }
5181     default:
5182       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : unsupported renum policy ! Dealing with policy 0 1 2 and 3 !");
5183   }
5184 }
5185
5186 /*!
5187  * Returns values and a profile of the field of a given type lying on a given support.
5188  *  \param [in] type - a spatial discretization of the field.
5189  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
5190  *  \param [in] mesh - the supporting mesh.
5191  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
5192  *          field of interest lies on. If the field lies on all entities of the given
5193  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
5194  *          using decrRef() as it is no more needed.  
5195  *  \param [in] glob - the global data storing profiles and localization.
5196  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
5197  *          field. The caller is to delete this array using decrRef() as it is no more needed.
5198  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
5199  *  \throw If no field of \a this is lying on \a mesh.
5200  *  \throw If no field values of the given \a type are available.
5201  */
5202 DataArray *MEDFileAnyTypeField1TSWithoutSDA::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl, const MEDFileFieldGlobsReal *glob, const MEDFileFieldNameScope& nasc) const
5203 {
5204   MCAuto<MEDCouplingMesh> m(mesh->getMeshAtLevel(meshDimRelToMax));
5205   int meshId=getMeshIdFromMeshName(mesh->getName().c_str());
5206   MCAuto<DataArray> ret=_field_per_mesh[meshId]->getFieldOnMeshAtLevelWithPfl(type,m,pfl,glob,nasc);
5207   ret->setName(nasc.getName().c_str());
5208   return ret.retn();
5209 }
5210
5211 //= MEDFileField1TSWithoutSDA
5212
5213 /*!
5214  * Throws if a given value is not a valid (non-extended) relative dimension.
5215  *  \param [in] meshDimRelToMax - the relative dimension value.
5216  *  \throw If \a meshDimRelToMax > 0.
5217  */
5218 void MEDFileField1TSWithoutSDA::CheckMeshDimRel(int meshDimRelToMax)
5219 {
5220   if(meshDimRelToMax>0)
5221     throw INTERP_KERNEL::Exception("CheckMeshDimRel : This is a meshDimRel not a meshDimRelExt ! So value should be <=0 !");
5222 }
5223
5224 /*!
5225  * Checks if elements of a given mesh are in the order suitable for writing 
5226  * to the MED file. If this is not so, an exception is thrown. In a case of success, returns a
5227  * vector describing types of elements and their number.
5228  *  \param [in] mesh - the mesh to check.
5229  *  \return std::vector<int> - a vector holding for each element type (1) item of
5230  *          INTERP_KERNEL::NormalizedCellType, (2) number of elements, (3) -1. 
5231  *          These values are in full-interlace mode.
5232  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
5233  */
5234 std::vector<int> MEDFileField1TSWithoutSDA::CheckSBTMesh(const MEDCouplingMesh *mesh)
5235 {
5236   if(!mesh)
5237     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : input mesh is NULL !");
5238   std::set<INTERP_KERNEL::NormalizedCellType> geoTypes=mesh->getAllGeoTypes();
5239   int nbOfTypes=geoTypes.size();
5240   std::vector<int> code(3*nbOfTypes);
5241   MCAuto<DataArrayInt> arr1=DataArrayInt::New();
5242   arr1->alloc(nbOfTypes,1);
5243   int *arrPtr=arr1->getPointer();
5244   std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator it=geoTypes.begin();
5245   for(int i=0;i<nbOfTypes;i++,it++)
5246     arrPtr[i]=std::distance(typmai2,std::find(typmai2,typmai2+MED_N_CELL_FIXED_GEO,*it));
5247   MCAuto<DataArrayInt> arr2=arr1->checkAndPreparePermutation();
5248   const int *arrPtr2=arr2->getConstPointer();
5249   int i=0;
5250   for(it=geoTypes.begin();it!=geoTypes.end();it++,i++)
5251     {
5252       int pos=arrPtr2[i];
5253       int nbCells=mesh->getNumberOfCellsWithType(*it);
5254       code[3*pos]=(int)(*it);
5255       code[3*pos+1]=nbCells;
5256       code[3*pos+2]=-1;//no profiles
5257     }
5258   std::vector<const DataArrayInt *> idsPerType;//no profiles
5259   DataArrayInt *da=mesh->checkTypeConsistencyAndContig(code,idsPerType);
5260   if(da)
5261     {
5262       da->decrRef();
5263       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::CheckSBTMesh : underlying mesh is not sorted by type as MED file expects !");
5264     }
5265   return code;
5266 }
5267
5268 MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5269 {
5270   return new MEDFileField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5271 }
5272
5273 /*!
5274  * Returns all attributes and values of parts of \a this field lying on a given mesh.
5275  * Each part differs from other ones by a type of supporting mesh entity. The _i_-th
5276  * item of every of returned sequences refers to the _i_-th part of \a this field.
5277  * Thus all sequences returned by this method are of the same length equal to number
5278  * of different types of supporting entities.<br>
5279  * A field part can include sub-parts with several different spatial discretizations,
5280  * \ref MEDCoupling::ON_CELLS "ON_CELLS" and \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT"
5281  * for example. Hence, some of the returned sequences contains nested sequences, and an item
5282  * of a nested sequence corresponds to a type of spatial discretization.<br>
5283  * This method allows for iteration over MEDFile DataStructure with a reduced overhead.
5284  * The overhead is due to selecting values into new instances of DataArrayDouble.
5285  *  \param [in] mname - a name of a mesh of interest. It can be \c NULL, which is valid
5286  *          for the case with only one underlying mesh. (Actually, the number of meshes is
5287  *          not checked if \a mname == \c NULL).
5288  *  \param [in,out] types - a sequence of types of underlying mesh entities. A type per
5289  *          a field part is returned. 
5290  *  \param [in,out] typesF - a sequence of sequences of types of spatial discretizations.
5291  *          A field part can include sub-parts with several different spatial discretizations,
5292  *          \ref MEDCoupling::ON_CELLS "ON_CELLS" and 
5293  *          \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" for example.
5294  *          This sequence is of the same length as \a types. 
5295  *  \param [in,out] pfls - a sequence returning a profile name per each type of spatial
5296  *          discretization. A profile name can be empty.
5297  *          Length of this and of nested sequences is the same as that of \a typesF.
5298  *  \param [in,out] locs - a sequence returning a localization name per each type of spatial
5299  *          discretization. A localization name can be empty.
5300  *          Length of this and of nested sequences is the same as that of \a typesF.
5301  *  \return std::vector< std::vector<DataArrayDouble *> > - a sequence holding arrays of values
5302  *          per each type of spatial discretization within one mesh entity type.
5303  *          The caller is to delete each DataArrayDouble using decrRef() as it is no more needed.
5304  *          Length of this and of nested sequences is the same as that of \a typesF.
5305  *  \throw If no field is lying on \a mname.
5306  */
5307 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
5308 {
5309   int meshId=0;
5310   if(!mname.empty())
5311     meshId=getMeshIdFromMeshName(mname);
5312   else
5313     if(_field_per_mesh.empty())
5314       throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getFieldSplitedByType : This is empty !");
5315   std::vector< std::vector< std::pair<int,int> > > ret0=_field_per_mesh[meshId]->getFieldSplitedByType(types,typesF,pfls,locs);
5316   int nbOfRet=ret0.size();
5317   std::vector< std::vector<DataArrayDouble *> > ret(nbOfRet);
5318   for(int i=0;i<nbOfRet;i++)
5319     {
5320       const std::vector< std::pair<int,int> >& p=ret0[i];
5321       int nbOfRet1=p.size();
5322       ret[i].resize(nbOfRet1);
5323       for(int j=0;j<nbOfRet1;j++)
5324         {
5325           DataArrayDouble *tmp=_arr->selectByTupleIdSafeSlice(p[j].first,p[j].second,1);
5326           ret[i][j]=tmp;
5327         }
5328     }
5329   return ret;
5330 }
5331
5332 const char *MEDFileField1TSWithoutSDA::getTypeStr() const
5333 {
5334   return TYPE_STR;
5335 }
5336
5337 MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const
5338 {
5339   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA);
5340   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5341   ret->deepCpyLeavesFrom(*this);
5342   const DataArrayDouble *arr(_arr);
5343   if(arr)
5344     {
5345       MCAuto<DataArrayInt> arr2(arr->convertToIntArr());
5346       ret->setArray(arr2);
5347     }
5348   return ret.retn();
5349 }
5350
5351 /*!
5352  * Returns a pointer to the underground DataArrayDouble instance and a
5353  * sequence describing parameters of a support of each part of \a this field. The
5354  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5355  * direct access to the field values. This method is intended for the field lying on one
5356  * mesh only.
5357  *  \param [in,out] entries - the sequence describing parameters of a support of each
5358  *         part of \a this field. Each item of this sequence consists of two parts. The
5359  *         first part describes a type of mesh entity and an id of discretization of a
5360  *         current field part. The second part describes a range of values [begin,end)
5361  *         within the returned array relating to the current field part.
5362  *  \return DataArrayDouble * - the pointer to the field values array.
5363  *  \throw If the number of underlying meshes is not equal to 1.
5364  *  \throw If no field values are available.
5365  *  \sa getUndergroundDataArray()
5366  */
5367 DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayDoubleExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5368 {
5369   if(_field_per_mesh.size()!=1)
5370     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5371   if(_field_per_mesh[0]==0)
5372     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5373   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5374   return getUndergroundDataArrayTemplate();
5375 }
5376
5377 /*!
5378  * Returns a pointer to the underground DataArrayDouble instance and a
5379  * sequence describing parameters of a support of each part of \a this field. The
5380  * caller should not decrRef() the returned DataArrayDouble. This method allows for a
5381  * direct access to the field values. This method is intended for the field lying on one
5382  * mesh only.
5383  *  \param [in,out] entries - the sequence describing parameters of a support of each
5384  *         part of \a this field. Each item of this sequence consists of two parts. The
5385  *         first part describes a type of mesh entity and an id of discretization of a
5386  *         current field part. The second part describes a range of values [begin,end)
5387  *         within the returned array relating to the current field part.
5388  *  \return DataArrayDouble * - the pointer to the field values array.
5389  *  \throw If the number of underlying meshes is not equal to 1.
5390  *  \throw If no field values are available.
5391  *  \sa getUndergroundDataArray()
5392  */
5393 DataArray *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5394 {
5395   return getUndergroundDataArrayDoubleExt(entries);
5396 }
5397
5398 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<double>(fieldName,csit,iteration,order)
5399 {
5400   DataArrayDouble *arr(getOrCreateAndGetArrayTemplate());
5401   arr->setInfoAndChangeNbOfCompo(infos);
5402 }
5403
5404 MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<double>()
5405 {
5406 }
5407
5408 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const
5409 {
5410   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA(*this));
5411   ret->deepCpyLeavesFrom(*this);
5412   return ret.retn();
5413 }
5414
5415 MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const
5416 {
5417   MCAuto<MEDFileField1TSWithoutSDA> ret=static_cast<MEDFileField1TSWithoutSDA *>(shallowCpy());
5418   if((const DataArrayDouble *)_arr)
5419     ret->_arr=_arr->deepCopy();
5420   return ret.retn();
5421 }
5422
5423 //= MEDFileIntField1TSWithoutSDA
5424
5425 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::string& fieldName, int csit, int iteration, int order, const std::vector<std::string>& infos)
5426 {
5427   return new MEDFileIntField1TSWithoutSDA(fieldName,csit,iteration,order,infos);
5428 }
5429
5430 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA<int>()
5431 {
5432 }
5433
5434 MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order,
5435                                                            const std::vector<std::string>& infos):MEDFileField1TSTemplateWithoutSDA<int>(fieldName,csit,iteration,order)
5436 {
5437   DataArrayInt *arr(getOrCreateAndGetArrayTemplate());
5438   arr->setInfoAndChangeNbOfCompo(infos);
5439 }
5440
5441 const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const
5442 {
5443   return TYPE_STR;
5444 }
5445
5446 MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const
5447 {
5448   MCAuto<MEDFileField1TSWithoutSDA> ret(new MEDFileField1TSWithoutSDA);
5449   ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this);
5450   ret->deepCpyLeavesFrom(*this);
5451   const DataArrayInt *arr(_arr);
5452   if(arr)
5453     {
5454       MCAuto<DataArrayDouble> arr2(arr->convertToDblArr());
5455       ret->setArray(arr2);
5456     }
5457   return ret.retn();
5458 }
5459
5460 /*!
5461  * Returns a pointer to the underground DataArrayInt instance and a
5462  * sequence describing parameters of a support of each part of \a this field. The
5463  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5464  * direct access to the field values. This method is intended for the field lying on one
5465  * mesh only.
5466  *  \param [in,out] entries - the sequence describing parameters of a support of each
5467  *         part of \a this field. Each item of this sequence consists of two parts. The
5468  *         first part describes a type of mesh entity and an id of discretization of a
5469  *         current field part. The second part describes a range of values [begin,end)
5470  *         within the returned array relating to the current field part.
5471  *  \return DataArrayInt * - the pointer to the field values array.
5472  *  \throw If the number of underlying meshes is not equal to 1.
5473  *  \throw If no field values are available.
5474  *  \sa getUndergroundDataArray()
5475  */
5476 DataArray *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5477 {
5478   return getUndergroundDataArrayIntExt(entries);
5479 }
5480
5481 /*!
5482  * Returns a pointer to the underground DataArrayInt instance and a
5483  * sequence describing parameters of a support of each part of \a this field. The
5484  * caller should not decrRef() the returned DataArrayInt. This method allows for a
5485  * direct access to the field values. This method is intended for the field lying on one
5486  * mesh only.
5487  *  \param [in,out] entries - the sequence describing parameters of a support of each
5488  *         part of \a this field. Each item of this sequence consists of two parts. The
5489  *         first part describes a type of mesh entity and an id of discretization of a
5490  *         current field part. The second part describes a range of values [begin,end)
5491  *         within the returned array relating to the current field part.
5492  *  \return DataArrayInt * - the pointer to the field values array.
5493  *  \throw If the number of underlying meshes is not equal to 1.
5494  *  \throw If no field values are available.
5495  *  \sa getUndergroundDataArray()
5496  */
5497 DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
5498 {
5499   if(_field_per_mesh.size()!=1)
5500     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !");
5501   if(_field_per_mesh[0]==0)
5502     throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !");
5503   _field_per_mesh[0]->getUndergroundDataArrayExt(entries);
5504   return getUndergroundDataArrayTemplate();
5505 }
5506
5507 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const
5508 {
5509   MCAuto<MEDFileIntField1TSWithoutSDA> ret(new MEDFileIntField1TSWithoutSDA(*this));
5510   ret->deepCpyLeavesFrom(*this);
5511   return ret.retn();
5512 }
5513
5514 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const
5515 {
5516   MCAuto<MEDFileIntField1TSWithoutSDA> ret=static_cast<MEDFileIntField1TSWithoutSDA *>(shallowCpy());
5517   if((const DataArrayInt *)_arr)
5518     ret->_arr=_arr->deepCopy();
5519   return ret.retn();
5520 }
5521
5522 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS()
5523 {
5524 }
5525
5526 //= MEDFileAnyTypeField1TS
5527
5528 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5529 {
5530   med_field_type typcha;
5531   //
5532   std::vector<std::string> infos;
5533   std::string dtunit,fieldName;
5534   LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
5535   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5536   switch(typcha)
5537   {
5538     case MED_FLOAT64:
5539       {
5540         ret=MEDFileField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5541         break;
5542       }
5543     case MED_INT32:
5544       {
5545         ret=MEDFileIntField1TSWithoutSDA::New(fieldName.c_str(),-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5546         break;
5547       }
5548     default:
5549       {
5550         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] !";
5551         throw INTERP_KERNEL::Exception(oss.str());
5552       }
5553   }
5554   ret->setDtUnit(dtunit.c_str());
5555   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5556   //
5557   med_int numdt,numit;
5558   med_float dt;
5559   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5560   ret->setTime(numdt,numit,dt);
5561   ret->_csit=1;
5562   if(loadAll)
5563     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5564   else
5565     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5566   return ret.retn();
5567 }
5568
5569 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
5570 try:MEDFileFieldGlobsReal(fid)
5571 {
5572   _content=BuildContentFrom(fid,loadAll,ms);
5573   loadGlobals(fid);
5574 }
5575 catch(INTERP_KERNEL::Exception& e)
5576 {
5577     throw e;
5578 }
5579
5580 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5581 {
5582   med_field_type typcha;
5583   std::vector<std::string> infos;
5584   std::string dtunit;
5585   int iii=-1;
5586   int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit);
5587   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5588   switch(typcha)
5589   {
5590     case MED_FLOAT64:
5591       {
5592         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5593         break;
5594       }
5595     case MED_INT32:
5596       {
5597         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
5598         break;
5599       }
5600     default:
5601       {
5602         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] !";
5603         throw INTERP_KERNEL::Exception(oss.str());
5604       }
5605   }
5606   ret->setDtUnit(dtunit.c_str());
5607   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5608   //
5609   if(nbSteps<1)
5610     {
5611       std::ostringstream oss; oss << "MEDFileField1TS(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but there is no time steps on it !";
5612       throw INTERP_KERNEL::Exception(oss.str());
5613     }
5614   //
5615   med_int numdt,numit;
5616   med_float dt;
5617   MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),1,&numdt,&numit,&dt));
5618   ret->setTime(numdt,numit,dt);
5619   ret->_csit=1;
5620   if(loadAll)
5621     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5622   else
5623     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5624   return ret.retn();
5625 }
5626
5627 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
5628 try:MEDFileFieldGlobsReal(fid)
5629 {
5630   _content=BuildContentFrom(fid,fieldName,loadAll,ms);
5631   loadGlobals(fid);
5632 }
5633 catch(INTERP_KERNEL::Exception& e)
5634 {
5635     throw e;
5636 }
5637
5638 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c)
5639 {
5640   if(!c)
5641     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
5642   if(dynamic_cast<const MEDFileField1TSWithoutSDA *>(c))
5643     {
5644       MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
5645       ret->_content=c; c->incrRef();
5646       return ret.retn();
5647     }
5648   if(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(c))
5649     {
5650       MCAuto<MEDFileIntField1TS> ret(MEDFileIntField1TS::New());
5651       ret->_content=c; c->incrRef();
5652       return ret.retn();
5653     }
5654   throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
5655 }
5656
5657 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
5658 {
5659   MEDFileAnyTypeField1TS *ret(BuildNewInstanceFromContent(c));
5660   ret->setFileName(FileNameFromFID(fid));
5661   return ret;
5662 }
5663
5664 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, bool loadAll)
5665 {
5666   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5667   return New(fid,loadAll);
5668 }
5669
5670 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, bool loadAll)
5671 {
5672   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
5673   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5674   ret->loadGlobals(fid);
5675   return ret.retn();
5676 }
5677
5678 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
5679 {
5680   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5681   return New(fid,fieldName,loadAll);
5682 }
5683
5684 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
5685 {
5686   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0));
5687   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5688   ret->loadGlobals(fid);
5689   return ret.retn();
5690 }
5691
5692 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
5693 {
5694   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
5695   return New(fid,fieldName,iteration,order,loadAll);
5696 }
5697
5698 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
5699 {
5700   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> c(BuildContentFrom(fid,fieldName,iteration,order,loadAll,0));
5701   MCAuto<MEDFileAnyTypeField1TS> ret(BuildNewInstanceFromContent(c,fid));
5702   ret->loadGlobals(fid);
5703   return ret.retn();
5704 }
5705
5706 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5707 {
5708   med_field_type typcha;
5709   std::vector<std::string> infos;
5710   std::string dtunit;
5711   int iii(-1);
5712   int nbOfStep2(LocateField(fid,fieldName,iii,typcha,infos,dtunit));
5713   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ret;
5714   switch(typcha)
5715   {
5716     case MED_FLOAT64:
5717       {
5718         ret=MEDFileField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5719         break;
5720       }
5721     case MED_INT32:
5722       {
5723         ret=MEDFileIntField1TSWithoutSDA::New(fieldName,-1,iteration,order,std::vector<std::string>());
5724         break;
5725       }
5726     default:
5727       {
5728         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] !";
5729         throw INTERP_KERNEL::Exception(oss.str());
5730       }
5731   }
5732   ret->setDtUnit(dtunit.c_str());
5733   ret->getOrCreateAndGetArray()->setInfoAndChangeNbOfCompo(infos);
5734   //
5735   bool found=false;
5736   std::vector< std::pair<int,int> > dtits(nbOfStep2);
5737   for(int i=0;i<nbOfStep2 && !found;i++)
5738     {
5739       med_int numdt,numit;
5740       med_float dt;
5741       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,fieldName.c_str(),i+1,&numdt,&numit,&dt));
5742       if(numdt==iteration && numit==order)
5743         {
5744           found=true;
5745           ret->_csit=i+1;
5746         }
5747       else
5748         dtits[i]=std::pair<int,int>(numdt,numit);
5749     }
5750   if(!found)
5751     {
5752       std::ostringstream oss; oss << "No such iteration (" << iteration << "," << order << ") in existing field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available iterations are : ";
5753       for(std::vector< std::pair<int,int> >::const_iterator iter=dtits.begin();iter!=dtits.end();iter++)
5754         oss << "(" << (*iter).first << "," << (*iter).second << "), ";
5755       throw INTERP_KERNEL::Exception(oss.str());
5756     }
5757   if(loadAll)
5758     ret->loadStructureAndBigArraysRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5759   else
5760     ret->loadOnlyStructureOfDataRecursively(fid,*((const MEDFileAnyTypeField1TSWithoutSDA*)ret),ms,0);
5761   return ret.retn();
5762 }
5763
5764 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
5765 try:MEDFileFieldGlobsReal(fid)
5766 {
5767   _content=BuildContentFrom(fid,fieldName,iteration,order,loadAll,ms);
5768   loadGlobals(fid);
5769 }
5770 catch(INTERP_KERNEL::Exception& e)
5771 {
5772     throw e;
5773 }
5774
5775 /*!
5776  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
5777  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
5778  *
5779  * \warning this is a shallow copy constructor
5780  */
5781 MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS(const MEDFileAnyTypeField1TSWithoutSDA& other, bool shallowCopyOfContent)
5782 {
5783   if(!shallowCopyOfContent)
5784     {
5785       const MEDFileAnyTypeField1TSWithoutSDA *otherPtr(&other);
5786       otherPtr->incrRef();
5787       _content=const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(otherPtr);
5788     }
5789   else
5790     {
5791       _content=other.shallowCpy();
5792     }
5793 }
5794
5795 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)
5796 {
5797   if(checkFieldId)
5798     {
5799       int nbFields=MEDnField(fid);
5800       if(fieldIdCFormat>=nbFields)
5801         {
5802           std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::LocateField2(fileName) : in file \'" << FileNameFromFID(fid) << "\' number of fields is " << nbFields << " ! Trying to request for id " << fieldIdCFormat << " !";
5803           throw INTERP_KERNEL::Exception(oss.str());
5804         }
5805     }
5806   int ncomp(MEDfieldnComponent(fid,fieldIdCFormat+1));
5807   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5808   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
5809   INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
5810   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5811   INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
5812   med_bool localMesh;
5813   int nbOfStep;
5814   MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,fieldIdCFormat+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep));
5815   fieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE);
5816   dtunitOut=MEDLoaderBase::buildStringFromFortran(dtunit,MED_LNAME_SIZE);
5817   infos.clear(); infos.resize(ncomp);
5818   for(int j=0;j<ncomp;j++)
5819     infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+j*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
5820   return nbOfStep;
5821 }
5822
5823 /*!
5824  * This method throws an INTERP_KERNEL::Exception if \a fieldName field is not in file pointed by \a fid and with name \a fileName.
5825  * 
5826  * \param [out]
5827  * \return in case of success the number of time steps available for the field with name \a fieldName.
5828  */
5829 int MEDFileAnyTypeField1TS::LocateField(med_idt fid, const std::string& fieldName, int& posCFormat, med_field_type& typcha, std::vector<std::string>& infos, std::string& dtunitOut)
5830 {
5831   int nbFields=MEDnField(fid);
5832   bool found=false;
5833   std::vector<std::string> fns(nbFields);
5834   int nbOfStep2(-1);
5835   for(int i=0;i<nbFields && !found;i++)
5836     {
5837       std::string tmp;
5838       nbOfStep2=LocateField2(fid,i,false,tmp,typcha,infos,dtunitOut);
5839       fns[i]=tmp;
5840       found=(tmp==fieldName);
5841       if(found)
5842         posCFormat=i;
5843     }
5844   if(!found)
5845     {
5846       std::ostringstream oss; oss << "No such field '" << fieldName << "' in file '" << FileNameFromFID(fid) << "' ! Available fields are : ";
5847       for(std::vector<std::string>::const_iterator it=fns.begin();it!=fns.end();it++)
5848         oss << "\"" << *it << "\" ";
5849       throw INTERP_KERNEL::Exception(oss.str());
5850     }
5851   return nbOfStep2;
5852 }
5853
5854 /*!
5855  * This method as MEDFileField1TSW::setLocNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5856  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5857  * This method changes the attribute (here it's profile name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5858  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5859  * to keep a valid instance.
5860  * 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.
5861  * If \b newPflName profile name does not already exist the profile with old name will be renamed with name \b newPflName.
5862  * 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.
5863  *
5864  * \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.
5865  * \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.
5866  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5867  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5868  * \param [in] newLocName is the new localization name.
5869  * \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.
5870  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newPflName
5871  */
5872 void MEDFileAnyTypeField1TS::setProfileNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newPflName, bool forceRenameOnGlob)
5873 {
5874   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5875   std::string oldPflName=disc->getProfile();
5876   std::vector<std::string> vv=getPflsReallyUsedMulti();
5877   int nbOfOcc=std::count(vv.begin(),vv.end(),oldPflName);
5878   if(forceRenameOnGlob || (!existsPfl(newPflName) && nbOfOcc==1))
5879     {
5880       disc->setProfile(newPflName);
5881       DataArrayInt *pfl=getProfile(oldPflName.c_str());
5882       pfl->setName(newPflName);
5883     }
5884   else
5885     {
5886       std::ostringstream oss; oss << "MEDFileField1TS::setProfileNameOnLeaf : Profile \"" << newPflName << "\" already exists or referenced more than one !";
5887       throw INTERP_KERNEL::Exception(oss.str());
5888     }
5889 }
5890
5891 /*!
5892  * This method as MEDFileField1TSW::setProfileNameOnLeaf, is dedicated for advanced user that a want a very fine control on their data structure
5893  * without overhead. This method can be called only regarding information returned by MEDFileField1TSWithoutSDA::getFieldSplitedByType or MEDFileField1TSWithoutSDA::getFieldSplitedByType2.
5894  * This method changes the attribute (here it's localization name) of the leaf datastructure (MEDFileFieldPerMeshPerTypePerDisc instance).
5895  * It is the responsability of the caller to invoke MEDFileFieldGlobs::appendProfile or MEDFileFieldGlobs::getProfile
5896  * to keep a valid instance.
5897  * 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.
5898  * This method is an extension of MEDFileField1TSWithoutSDA::setProfileNameOnLeafExt method because it performs a modification of global info.
5899  * If \b newLocName profile name does not already exist the localization with old name will be renamed with name \b newLocName.
5900  * 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.
5901  *
5902  * \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.
5903  * \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.
5904  * \param [in] locId is the localization id to find the right MEDFileFieldPerMeshPerTypePerDisc instance to set. It corresponds to the position of 
5905  *             \c pfls[std::distance(types.begin(),std::find(types.begin(),typ)] vector in MEDFileField1TSWithoutSDA::getFieldSplitedByType. For non gausspoints field users, the value is 0.
5906  * \param [in] newLocName is the new localization name.
5907  * \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.
5908  *             If false, an exception will be thrown to force user to change previously the name of the profile with name \b newLocName
5909  */
5910 void MEDFileAnyTypeField1TS::setLocNameOnLeaf(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId, const std::string& newLocName, bool forceRenameOnGlob)
5911 {
5912   MEDFileFieldPerMeshPerTypePerDisc *disc=getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
5913   std::string oldLocName=disc->getLocalization();
5914   std::vector<std::string> vv=getLocsReallyUsedMulti();
5915   int nbOfOcc=std::count(vv.begin(),vv.end(),oldLocName);
5916   if(forceRenameOnGlob || (!existsLoc(newLocName) && nbOfOcc==1))
5917     {
5918       disc->setLocalization(newLocName);
5919       MEDFileFieldLoc& loc=getLocalization(oldLocName.c_str());
5920       loc.setName(newLocName);
5921     }
5922   else
5923     {
5924       std::ostringstream oss; oss << "MEDFileField1TS::setLocNameOnLeaf : Localization \"" << newLocName << "\" already exists or referenced more than one !";
5925       throw INTERP_KERNEL::Exception(oss.str());
5926     }
5927 }
5928
5929 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase()
5930 {
5931   MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5932   if(!ret)
5933     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : content is expected to be not null !");
5934   return ret;
5935 }
5936
5937 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::contentNotNullBase() const
5938 {
5939   const MEDFileAnyTypeField1TSWithoutSDA *ret=_content;
5940   if(!ret)
5941     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS : const content is expected to be not null !");
5942   return ret;
5943 }
5944
5945 /*!
5946  * This method alloc the arrays and load potentially huge arrays contained in this field.
5947  * This method should be called when a MEDFileAnyTypeField1TS::New constructor has been with false as the last parameter.
5948  * This method can be also called to refresh or reinit values from a file.
5949  * 
5950  * \throw If the fileName is not set or points to a non readable MED file.
5951  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5952  */
5953 void MEDFileAnyTypeField1TS::loadArrays()
5954 {
5955   if(getFileName().empty())
5956     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::loadArrays : the structure does not come from a file !");
5957   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
5958   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
5959 }
5960
5961 /*!
5962  * This method behaves as MEDFileAnyTypeField1TS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
5963  * But once data loaded once, this method does nothing. Contrary to MEDFileAnyTypeField1TS::loadArrays and MEDFileAnyTypeField1TS::unloadArrays
5964  * this method does not throw if \a this does not come from file read.
5965  * 
5966  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::unloadArrays
5967  */
5968 void MEDFileAnyTypeField1TS::loadArraysIfNecessary()
5969 {
5970   if(!getFileName().empty())
5971     {
5972       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
5973       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
5974     }
5975 }
5976
5977 /*!
5978  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
5979  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
5980  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss instead.
5981  * 
5982  * \sa MEDFileAnyTypeField1TS::loadArrays, MEDFileAnyTypeField1TS::loadArraysIfNecessary, MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss
5983  */
5984 void MEDFileAnyTypeField1TS::unloadArrays()
5985 {
5986   contentNotNullBase()->unloadArrays();
5987 }
5988
5989 /*!
5990  * 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.
5991  * This method is the symetrical method of MEDFileAnyTypeField1TS::loadArraysIfNecessary.
5992  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
5993  * 
5994  * \sa MEDFileAnyTypeField1TS::loadArraysIfNecessary
5995  */
5996 void MEDFileAnyTypeField1TS::unloadArraysWithoutDataLoss()
5997 {
5998   if(!getFileName().empty())
5999     contentNotNullBase()->unloadArrays();
6000 }
6001
6002 void MEDFileAnyTypeField1TS::writeLL(med_idt fid) const
6003 {
6004   int nbComp(getNumberOfComponents());
6005   INTERP_KERNEL::AutoPtr<char> comp(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6006   INTERP_KERNEL::AutoPtr<char> unit(MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE));
6007   for(int i=0;i<nbComp;i++)
6008     {
6009       std::string info=getInfo()[i];
6010       std::string c,u;
6011       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6012       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,_too_long_str);
6013       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,_too_long_str);
6014     }
6015   if(getName().empty())
6016     throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !");
6017   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,getName().c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
6018   writeGlobals(fid,*this);
6019   contentNotNullBase()->writeLL(fid,*this,*contentNotNullBase());
6020 }
6021
6022 std::size_t MEDFileAnyTypeField1TS::getHeapMemorySizeWithoutChildren() const
6023 {
6024   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
6025 }
6026
6027 std::vector<const BigMemoryObject *> MEDFileAnyTypeField1TS::getDirectChildrenWithNull() const
6028 {
6029   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
6030   ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)_content);
6031   return ret;
6032 }
6033
6034 /*!
6035  * Returns a string describing \a this field. This string is outputted 
6036  * by \c print Python command.
6037  */
6038 std::string MEDFileAnyTypeField1TS::simpleRepr() const
6039 {
6040   std::ostringstream oss;
6041   contentNotNullBase()->simpleRepr(0,oss,-1);
6042   simpleReprGlobs(oss);
6043   return oss.str();
6044 }
6045
6046 /*!
6047  * This method returns all profiles whose name is non empty used.
6048  * \b WARNING If profile is used several times it will be reported \b only \b once.
6049  * To get non empty name profiles as time as they appear in \b this call MEDFileField1TS::getPflsReallyUsedMulti instead.
6050  */
6051 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsed() const
6052 {
6053   return contentNotNullBase()->getPflsReallyUsed2();
6054 }
6055
6056 /*!
6057  * This method returns all localizations whose name is non empty used.
6058  * \b WARNING If localization is used several times it will be reported \b only \b once.
6059  */
6060 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsed() const
6061 {
6062   return contentNotNullBase()->getLocsReallyUsed2();
6063 }
6064
6065 /*!
6066  * This method returns all profiles whose name is non empty used.
6067  * \b WARNING contrary to MEDFileField1TS::getPflsReallyUsed, if profile is used several times it will be reported as time as it appears.
6068  */
6069 std::vector<std::string> MEDFileAnyTypeField1TS::getPflsReallyUsedMulti() const
6070 {
6071   return contentNotNullBase()->getPflsReallyUsedMulti2();
6072 }
6073
6074 /*!
6075  * This method returns all localizations whose name is non empty used.
6076  * \b WARNING contrary to MEDFileField1TS::getLocsReallyUsed if localization is used several times it will be reported as time as it appears.
6077  */
6078 std::vector<std::string> MEDFileAnyTypeField1TS::getLocsReallyUsedMulti() const
6079 {
6080   return contentNotNullBase()->getLocsReallyUsedMulti2();
6081 }
6082
6083 void MEDFileAnyTypeField1TS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6084 {
6085   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
6086 }
6087
6088 void MEDFileAnyTypeField1TS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
6089 {
6090   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
6091 }
6092
6093 int MEDFileAnyTypeField1TS::getDimension() const
6094 {
6095   return contentNotNullBase()->getDimension();
6096 }
6097
6098 int MEDFileAnyTypeField1TS::getIteration() const
6099 {
6100   return contentNotNullBase()->getIteration();
6101 }
6102
6103 int MEDFileAnyTypeField1TS::getOrder() const
6104 {
6105   return contentNotNullBase()->getOrder();
6106 }
6107
6108 double MEDFileAnyTypeField1TS::getTime(int& iteration, int& order) const
6109 {
6110   return contentNotNullBase()->getTime(iteration,order);
6111 }
6112
6113 void MEDFileAnyTypeField1TS::setTime(int iteration, int order, double val)
6114 {
6115   contentNotNullBase()->setTime(iteration,order,val);
6116 }
6117
6118 std::string MEDFileAnyTypeField1TS::getName() const
6119 {
6120   return contentNotNullBase()->getName();
6121 }
6122
6123 void MEDFileAnyTypeField1TS::setName(const std::string& name)
6124 {
6125   contentNotNullBase()->setName(name);
6126 }
6127
6128 void MEDFileAnyTypeField1TS::simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const
6129 {
6130   contentNotNullBase()->simpleRepr(bkOffset,oss,f1tsId);
6131 }
6132
6133 std::string MEDFileAnyTypeField1TS::getDtUnit() const
6134 {
6135   return contentNotNullBase()->getDtUnit();
6136 }
6137
6138 void MEDFileAnyTypeField1TS::setDtUnit(const std::string& dtUnit)
6139 {
6140   contentNotNullBase()->setDtUnit(dtUnit);
6141 }
6142
6143 std::string MEDFileAnyTypeField1TS::getMeshName() const
6144 {
6145   return contentNotNullBase()->getMeshName();
6146 }
6147
6148 void MEDFileAnyTypeField1TS::setMeshName(const std::string& newMeshName)
6149 {
6150   contentNotNullBase()->setMeshName(newMeshName);
6151 }
6152
6153 bool MEDFileAnyTypeField1TS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6154 {
6155   return contentNotNullBase()->changeMeshNames(modifTab);
6156 }
6157
6158 int MEDFileAnyTypeField1TS::getMeshIteration() const
6159 {
6160   return contentNotNullBase()->getMeshIteration();
6161 }
6162
6163 int MEDFileAnyTypeField1TS::getMeshOrder() const
6164 {
6165   return contentNotNullBase()->getMeshOrder();
6166 }
6167
6168 int MEDFileAnyTypeField1TS::getNumberOfComponents() const
6169 {
6170   return contentNotNullBase()->getNumberOfComponents();
6171 }
6172
6173 bool MEDFileAnyTypeField1TS::isDealingTS(int iteration, int order) const
6174 {
6175   return contentNotNullBase()->isDealingTS(iteration,order);
6176 }
6177
6178 std::pair<int,int> MEDFileAnyTypeField1TS::getDtIt() const
6179 {
6180   return contentNotNullBase()->getDtIt();
6181 }
6182
6183 void MEDFileAnyTypeField1TS::fillIteration(std::pair<int,int>& p) const
6184 {
6185   contentNotNullBase()->fillIteration(p);
6186 }
6187
6188 void MEDFileAnyTypeField1TS::fillTypesOfFieldAvailable(std::vector<TypeOfField>& types) const
6189 {
6190   contentNotNullBase()->fillTypesOfFieldAvailable(types);
6191 }
6192
6193 void MEDFileAnyTypeField1TS::setInfo(const std::vector<std::string>& infos)
6194 {
6195   contentNotNullBase()->setInfo(infos);
6196 }
6197
6198 const std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo() const
6199 {
6200   return contentNotNullBase()->getInfo();
6201 }
6202 std::vector<std::string>& MEDFileAnyTypeField1TS::getInfo()
6203 {
6204   return contentNotNullBase()->getInfo();
6205 }
6206
6207 bool MEDFileAnyTypeField1TS::presenceOfMultiDiscPerGeoType() const
6208 {
6209   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
6210 }
6211
6212 MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId)
6213 {
6214   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6215 }
6216
6217 const MEDFileFieldPerMeshPerTypePerDisc *MEDFileAnyTypeField1TS::getLeafGivenMeshAndTypeAndLocId(const std::string& mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const
6218 {
6219   return contentNotNullBase()->getLeafGivenMeshAndTypeAndLocId(mName,typ,locId);
6220 }
6221
6222 int MEDFileAnyTypeField1TS::getNonEmptyLevels(const std::string& mname, std::vector<int>& levs) const
6223 {
6224   return contentNotNullBase()->getNonEmptyLevels(mname,levs);
6225 }
6226
6227 std::vector<TypeOfField> MEDFileAnyTypeField1TS::getTypesOfFieldAvailable() const
6228 {
6229   return contentNotNullBase()->getTypesOfFieldAvailable();
6230 }
6231
6232 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,
6233                                                                                               std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6234 {
6235   return contentNotNullBase()->getFieldSplitedByType(mname,types,typesF,pfls,locs);
6236 }
6237
6238 /*!
6239  * This method returns as MEDFileAnyTypeField1TS new instances as number of components in \a this.
6240  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
6241  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
6242  */
6243 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitComponents() const
6244 {
6245   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6246   if(!content)
6247     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitComponents : no content in this ! Unable to split components !");
6248   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit=content->splitComponents();
6249   std::size_t sz(contentsSplit.size());
6250   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6251   for(std::size_t i=0;i<sz;i++)
6252     {
6253       ret[i]=shallowCpy();
6254       ret[i]->_content=contentsSplit[i];
6255     }
6256   return ret;
6257 }
6258
6259 /*!
6260  * This method returns as MEDFileAnyTypeField1TS new instances as number of spatial discretizations in \a this.
6261  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6262  */
6263 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitDiscretizations() const
6264 {
6265   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6266   if(!content)
6267     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitDiscretizations : no content in this ! Unable to split discretization !");
6268   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitDiscretizations());
6269   std::size_t sz(contentsSplit.size());
6270   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6271   for(std::size_t i=0;i<sz;i++)
6272     {
6273       ret[i]=shallowCpy();
6274       ret[i]->_content=contentsSplit[i];
6275     }
6276   return ret;
6277 }
6278
6279 /*!
6280  * This method returns as MEDFileAnyTypeField1TS new instances as number of maximal number of discretization in \a this.
6281  * The returned instances are shallowed copied of \a this except that for globals that are share with those contained in \a this.
6282  */
6283 std::vector< MCAuto< MEDFileAnyTypeField1TS > > MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes() const
6284 {
6285   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6286   if(!content)
6287     throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretization !");
6288   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
6289   std::size_t sz(contentsSplit.size());
6290   std::vector< MCAuto< MEDFileAnyTypeField1TS > > ret(sz);
6291   for(std::size_t i=0;i<sz;i++)
6292     {
6293       ret[i]=shallowCpy();
6294       ret[i]->_content=contentsSplit[i];
6295     }
6296   return ret;
6297 }
6298
6299 MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::deepCopy() const
6300 {
6301   MCAuto<MEDFileAnyTypeField1TS> ret=shallowCpy();
6302   if((const MEDFileAnyTypeField1TSWithoutSDA *)_content)
6303     ret->_content=_content->deepCopy();
6304   ret->deepCpyGlobs(*this);
6305   return ret.retn();
6306 }
6307
6308 int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
6309 {
6310   return contentNotNullBase()->copyTinyInfoFrom(field,arr);
6311 }
6312
6313 //= MEDFileField1TS
6314
6315 /*!
6316  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6317  * the first field that has been read from a specified MED file.
6318  *  \param [in] fileName - the name of the MED file to read.
6319  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6320  *          is to delete this field using decrRef() as it is no more needed.
6321  *  \throw If reading the file fails.
6322  */
6323 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll)
6324 {
6325   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6326   return New(fid,loadAll);
6327 }
6328
6329 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll)
6330 {
6331   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,loadAll,0));
6332   ret->contentNotNull();
6333   return ret.retn();
6334 }
6335
6336 /*!
6337  * Returns a new instance of MEDFileField1TS holding data of the first time step of 
6338  * a given field that has been read from a specified MED file.
6339  *  \param [in] fileName - the name of the MED file to read.
6340  *  \param [in] fieldName - the name of the field to read.
6341  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6342  *          is to delete this field using decrRef() as it is no more needed.
6343  *  \throw If reading the file fails.
6344  *  \throw If there is no field named \a fieldName in the file.
6345  */
6346 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6347 {
6348   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6349   return New(fid,fieldName,loadAll);
6350 }
6351
6352 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6353 {
6354   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,loadAll,0));
6355   ret->contentNotNull();
6356   return ret.retn();
6357 }
6358
6359 /*!
6360  * Returns a new instance of MEDFileField1TS holding data of a given time step of 
6361  * a given field that has been read from a specified MED file.
6362  *  \param [in] fileName - the name of the MED file to read.
6363  *  \param [in] fieldName - the name of the field to read.
6364  *  \param [in] iteration - the iteration number of a required time step.
6365  *  \param [in] order - the iteration order number of required time step.
6366  *  \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller
6367  *          is to delete this field using decrRef() as it is no more needed.
6368  *  \throw If reading the file fails.
6369  *  \throw If there is no field named \a fieldName in the file.
6370  *  \throw If the required time step is missing from the file.
6371  */
6372 MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6373 {
6374   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6375   return New(fid,fieldName,iteration,order,loadAll);
6376 }
6377
6378 MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6379 {
6380   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0));
6381   ret->contentNotNull();
6382   return ret.retn();
6383 }
6384
6385 /*!
6386  * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6387  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6388  *
6389  * Returns a new instance of MEDFileField1TS holding either a shallow copy
6390  * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself.
6391  * \warning this is a shallow copy constructor
6392  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
6393  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
6394  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6395  *          is to delete this field using decrRef() as it is no more needed.
6396  */
6397 MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6398 {
6399   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS(other,shallowCopyOfContent));
6400   ret->contentNotNull();
6401   return ret.retn();
6402 }
6403
6404 /*!
6405  * Returns a new empty instance of MEDFileField1TS.
6406  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller
6407  *          is to delete this field using decrRef() as it is no more needed.
6408  */
6409 MEDFileField1TS *MEDFileField1TS::New()
6410 {
6411   MCAuto<MEDFileField1TS> ret(new MEDFileField1TS);
6412   ret->contentNotNull();
6413   return ret.retn();
6414 }
6415
6416 /*!
6417  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
6418  * following the given input policy.
6419  *
6420  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6421  *                            By default (true) the globals are deeply copied.
6422  * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field.
6423  */
6424 MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const
6425 {
6426   MCAuto<MEDFileIntField1TS> ret;
6427   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6428   if(content)
6429     {
6430       const MEDFileField1TSWithoutSDA *contc=dynamic_cast<const MEDFileField1TSWithoutSDA *>(content);
6431       if(!contc)
6432         throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
6433       MCAuto<MEDFileIntField1TSWithoutSDA> newc(contc->convertToInt());
6434       ret=static_cast<MEDFileIntField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc));
6435     }
6436   else
6437     ret=MEDFileIntField1TS::New();
6438   if(isDeepCpyGlobs)
6439     ret->deepCpyGlobs(*this);
6440   else
6441     ret->shallowCpyGlobs(*this);
6442   return ret.retn();
6443 }
6444
6445 const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const
6446 {
6447   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6448   if(!pt)
6449     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !");
6450   const MEDFileField1TSWithoutSDA *ret=dynamic_cast<const MEDFileField1TSWithoutSDA *>(pt);
6451   if(!ret)
6452     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 !");
6453   return ret;
6454 }
6455
6456 MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull()
6457 {
6458   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
6459   if(!pt)
6460     throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !");
6461   MEDFileField1TSWithoutSDA *ret=dynamic_cast<MEDFileField1TSWithoutSDA *>(pt);
6462   if(!ret)
6463     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 !");
6464   return ret;
6465 }
6466
6467 void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
6468 {
6469   if(!f)
6470     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : input field is NULL !");
6471   if(arr.isNull())
6472     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : no array !");
6473   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6474   if(!arrOutC)
6475     throw INTERP_KERNEL::Exception("MEDFileField1TS::SetDataArrayDoubleInField : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6476   f->setArray(arrOutC);
6477 }
6478
6479 DataArrayDouble *MEDFileField1TS::ReturnSafelyDataArrayDouble(MCAuto<DataArray>& arr)
6480 {
6481   if(arr.isNull())
6482     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : no array !");
6483   DataArrayDouble *arrOutC(dynamic_cast<DataArrayDouble *>((DataArray*)arr));
6484   if(!arrOutC)
6485     throw INTERP_KERNEL::Exception("MEDFileField1TS::ReturnSafelyDataArrayDouble : mismatch between dataArrays type and MEDFileField1TS ! Expected double !");
6486   arrOutC->incrRef();
6487   return arrOutC;
6488 }
6489
6490 /*!
6491  * Return an extraction of \a this using \a extractDef map to specify the extraction.
6492  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
6493  *
6494  * \return A new object that the caller is responsible to deallocate.
6495  * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart , MEDFileUMesh::extractPart
6496  */
6497 MEDFileField1TS *MEDFileField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
6498 {
6499   if(!mm)
6500     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : input mesh is NULL !");
6501   MCAuto<MEDFileField1TS> ret(MEDFileField1TS::New());
6502   std::vector<TypeOfField> tof(getTypesOfFieldAvailable());
6503   for(std::vector<TypeOfField>::const_iterator it0=tof.begin();it0!=tof.end();it0++)
6504     {
6505       if((*it0)!=ON_NODES)
6506         {
6507           std::vector<int> levs;
6508           getNonEmptyLevels(mm->getName(),levs);
6509           for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
6510             {
6511               std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(*lev));
6512               if(it2!=extractDef.end())
6513                 {
6514                   MCAuto<DataArrayInt> t((*it2).second);
6515                   if(t.isNull())
6516                     throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6517                   MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_CELLS,(*lev),mm));
6518                   MCAuto<MEDCouplingFieldDouble> fOut(f->buildSubPart(t));
6519                   ret->setFieldNoProfileSBT(fOut);
6520                 }
6521             }
6522         }
6523       else
6524         {
6525           std::map<int, MCAuto<DataArrayInt> >::const_iterator it2(extractDef.find(1));
6526           if(it2==extractDef.end())
6527             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a NODE field and no extract array available for NODE !");
6528           MCAuto<DataArrayInt> t((*it2).second);
6529           if(t.isNull())
6530             throw INTERP_KERNEL::Exception("MEDFileField1TS::extractPart : presence of a value with null pointer 1 !");
6531           MCAuto<MEDCouplingFieldDouble> f(getFieldOnMeshAtLevel(ON_NODES,0,mm));
6532           MCAuto<MEDCouplingFieldDouble> fOut(f->deepCopy());
6533           DataArrayDouble *arr(f->getArray());
6534           MCAuto<DataArrayDouble> newArr(arr->selectByTupleIdSafe(t->begin(),t->end()));
6535           fOut->setArray(newArr);
6536           ret->setFieldNoProfileSBT(fOut);
6537         }
6538     }
6539   return ret.retn();
6540 }
6541
6542 MEDFileField1TS::MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6543 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6544 {
6545 }
6546 catch(INTERP_KERNEL::Exception& e)
6547 { throw e; }
6548
6549 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6550 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6551 {
6552 }
6553 catch(INTERP_KERNEL::Exception& e)
6554 { throw e; }
6555
6556 MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6557 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6558 {
6559 }
6560 catch(INTERP_KERNEL::Exception& e)
6561 { throw e; }
6562
6563 /*!
6564  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6565  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6566  *
6567  * \warning this is a shallow copy constructor
6568  */
6569 MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent)
6570 try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6571 {
6572 }
6573 catch(INTERP_KERNEL::Exception& e)
6574 { throw e; }
6575
6576 MEDFileField1TS::MEDFileField1TS()
6577 {
6578   _content=new MEDFileField1TSWithoutSDA;
6579 }
6580
6581 /*!
6582  * 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
6583  * method should be called (getFieldOnMeshAtLevel for example).
6584  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
6585  *
6586  * \param [in] mesh - the mesh the field is lying on
6587  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6588  *          caller is to delete this field using decrRef() as it is no more needed. 
6589  */
6590 MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const
6591 {
6592   MCAuto<DataArray> arrOut;
6593   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
6594   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6595   return ret.retn();
6596 }
6597
6598 /*!
6599  * Returns a new MEDCouplingFieldDouble of a given type lying on
6600  * mesh entities of a given dimension of the first mesh in MED file. If \a this field 
6601  * has not been constructed via file reading, an exception is thrown.
6602  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6603  *  \param [in] type - a spatial discretization of interest.
6604  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6605  *  \param [in] renumPol - specifies how to permute values of the result field according to
6606  *          the optional numbers of cells and nodes, if any. The valid values are
6607  *          - 0 - do not permute.
6608  *          - 1 - permute cells.
6609  *          - 2 - permute nodes.
6610  *          - 3 - permute cells and nodes.
6611  *
6612  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6613  *          caller is to delete this field using decrRef() as it is no more needed. 
6614  *  \throw If \a this field has not been constructed via file reading.
6615  *  \throw If the MED file is not readable.
6616  *  \throw If there is no mesh in the MED file.
6617  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6618  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6619  *  \sa getFieldOnMeshAtLevel()
6620  */
6621 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
6622 {
6623   if(getFileName().empty())
6624     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6625   MCAuto<DataArray> arrOut;
6626   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
6627   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6628   return ret.retn();
6629 }
6630
6631 /*!
6632  * Returns a new MEDCouplingFieldDouble of a given type lying on
6633  * the top level cells of the first mesh in MED file. If \a this field 
6634  * has not been constructed via file reading, an exception is thrown.
6635  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6636  *  \param [in] type - a spatial discretization of interest.
6637  *  \param [in] renumPol - specifies how to permute values of the result field according to
6638  *          the optional numbers of cells and nodes, if any. The valid values are
6639  *          - 0 - do not permute.
6640  *          - 1 - permute cells.
6641  *          - 2 - permute nodes.
6642  *          - 3 - permute cells and nodes.
6643  *
6644  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6645  *          caller is to delete this field using decrRef() as it is no more needed. 
6646  *  \throw If \a this field has not been constructed via file reading.
6647  *  \throw If the MED file is not readable.
6648  *  \throw If there is no mesh in the MED file.
6649  *  \throw If no field values of the given \a type.
6650  *  \throw If no field values lying on the top level support.
6651  *  \sa getFieldAtLevel()
6652  */
6653 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
6654 {
6655   if(getFileName().empty())
6656     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
6657   MCAuto<DataArray> arrOut;
6658   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
6659   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6660   return ret.retn();
6661 }
6662
6663 /*!
6664  * Returns a new MEDCouplingFieldDouble of given type lying on a given mesh.
6665  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6666  *  \param [in] type - a spatial discretization of the new field.
6667  *  \param [in] mesh - the supporting mesh.
6668  *  \param [in] renumPol - specifies how to permute values of the result field according to
6669  *          the optional numbers of cells and nodes, if any. The valid values are
6670  *          - 0 - do not permute.
6671  *          - 1 - permute cells.
6672  *          - 2 - permute nodes.
6673  *          - 3 - permute cells and nodes.
6674  *
6675  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6676  *          caller is to delete this field using decrRef() as it is no more needed. 
6677  *  \throw If no field of \a this is lying on \a mesh.
6678  *  \throw If the mesh is empty.
6679  *  \throw If no field values of the given \a type are available.
6680  *  \sa getFieldAtLevel()
6681  *  \sa getFieldOnMeshAtLevel() 
6682  */
6683 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
6684 {
6685   MCAuto<DataArray> arrOut;
6686   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
6687   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6688   return ret.retn();
6689 }
6690
6691 /*!
6692  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6693  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6694  *  \param [in] type - a spatial discretization of interest.
6695  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6696  *  \param [in] mesh - the supporting mesh.
6697  *  \param [in] renumPol - specifies how to permute values of the result field according to
6698  *          the optional numbers of cells and nodes, if any. The valid values are
6699  *          - 0 - do not permute.
6700  *          - 1 - permute cells.
6701  *          - 2 - permute nodes.
6702  *          - 3 - permute cells and nodes.
6703  *
6704  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6705  *          caller is to delete this field using decrRef() as it is no more needed. 
6706  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6707  *  \throw If no field of \a this is lying on \a mesh.
6708  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6709  *  \sa getFieldAtLevel()
6710  *  \sa getFieldOnMeshAtLevel() 
6711  */
6712 MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
6713 {
6714   MCAuto<DataArray> arrOut;
6715   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
6716   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6717   return ret.retn();
6718 }
6719
6720 /*!
6721  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
6722  * This method is called "Old" because in MED3 norm a field has only one meshName
6723  * attached, so this method is for readers of MED2 files. If \a this field 
6724  * has not been constructed via file reading, an exception is thrown.
6725  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6726  *  \param [in] type - a spatial discretization of interest.
6727  *  \param [in] mName - a name of the supporting mesh.
6728  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6729  *  \param [in] renumPol - specifies how to permute values of the result field according to
6730  *          the optional numbers of cells and nodes, if any. The valid values are
6731  *          - 0 - do not permute.
6732  *          - 1 - permute cells.
6733  *          - 2 - permute nodes.
6734  *          - 3 - permute cells and nodes.
6735  *
6736  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
6737  *          caller is to delete this field using decrRef() as it is no more needed. 
6738  *  \throw If the MED file is not readable.
6739  *  \throw If there is no mesh named \a mName in the MED file.
6740  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
6741  *  \throw If \a this field has not been constructed via file reading.
6742  *  \throw If no field of \a this is lying on the mesh named \a mName.
6743  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6744  *  \sa getFieldAtLevel()
6745  */
6746 MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
6747 {
6748   if(getFileName().empty())
6749     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
6750   MCAuto<DataArray> arrOut;
6751   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()));
6752   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
6753   return ret.retn();
6754 }
6755
6756 /*!
6757  * Returns values and a profile of the field of a given type lying on a given support.
6758  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6759  *  \param [in] type - a spatial discretization of the field.
6760  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
6761  *  \param [in] mesh - the supporting mesh.
6762  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
6763  *          field of interest lies on. If the field lies on all entities of the given
6764  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
6765  *          using decrRef() as it is no more needed.  
6766  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
6767  *          field. The caller is to delete this array using decrRef() as it is no more needed.
6768  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6769  *  \throw If no field of \a this is lying on \a mesh.
6770  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
6771  */
6772 DataArrayDouble *MEDFileField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
6773 {
6774   MCAuto<DataArray> ret=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
6775   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
6776 }
6777
6778 /*!
6779  * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is
6780  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6781  * "Sort By Type"), if not, an exception is thrown. 
6782  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6783  *  \param [in] field - the field to add to \a this.
6784  *  \throw If the name of \a field is empty.
6785  *  \throw If the data array of \a field is not set.
6786  *  \throw If the data array is already allocated but has different number of components
6787  *         than \a field.
6788  *  \throw If the underlying mesh of \a field has no name.
6789  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6790  */
6791 void MEDFileField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
6792 {
6793   setFileName("");
6794   contentNotNull()->setFieldNoProfileSBT(field,field->getArray(),*this,*contentNotNull());
6795 }
6796
6797 /*!
6798  * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6799  * can be an aggregation of several MEDCouplingFieldDouble instances.
6800  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6801  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6802  * and \a profile.
6803  *
6804  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6805  * A new profile is added only if no equal profile is missing.
6806  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6807  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
6808  *  \param [in] mesh - the supporting mesh of \a field.
6809  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
6810  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
6811  *  \throw If either \a field or \a mesh or \a profile has an empty name.
6812  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
6813  *  \throw If the data array of \a field is not set.
6814  *  \throw If the data array of \a this is already allocated but has different number of
6815  *         components than \a field.
6816  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
6817  *  \sa setFieldNoProfileSBT()
6818  */
6819 void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
6820 {
6821   setFileName("");
6822   contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
6823 }
6824
6825 MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const
6826 {
6827   return new MEDFileField1TS(*this);
6828 }
6829
6830 DataArrayDouble *MEDFileField1TS::getUndergroundDataArray() const
6831 {
6832   return contentNotNull()->getUndergroundDataArrayTemplate();
6833 }
6834
6835 DataArrayDouble *MEDFileField1TS::getUndergroundDataArrayExt(std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
6836 {
6837   return contentNotNull()->getUndergroundDataArrayDoubleExt(entries);
6838 }
6839
6840 std::vector< std::vector<DataArrayDouble *> > MEDFileField1TS::getFieldSplitedByType2(const std::string& mname, std::vector<INTERP_KERNEL::NormalizedCellType>& types, std::vector< std::vector<TypeOfField> >& typesF,
6841                                                                                       std::vector< std::vector<std::string> >& pfls, std::vector< std::vector<std::string> >& locs) const
6842 {
6843   return contentNotNull()->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
6844 }
6845
6846 //= MEDFileIntField1TS
6847
6848 MEDFileIntField1TS *MEDFileIntField1TS::New()
6849 {
6850   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS);
6851   ret->contentNotNull();
6852   return ret.retn();
6853 }
6854
6855 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll)
6856 {
6857   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6858   return MEDFileIntField1TS::New(fid,loadAll);
6859 }
6860
6861 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll)
6862 {
6863   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,loadAll,0));
6864   ret->contentNotNull();
6865   return ret.retn();
6866 }
6867
6868 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
6869 {
6870   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6871   return MEDFileIntField1TS::New(fid,fieldName,loadAll);
6872 }
6873
6874 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll)
6875 {
6876   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0));
6877   ret->contentNotNull();
6878   return ret.retn();
6879 }
6880
6881 MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll)
6882 {
6883   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
6884   return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll);
6885 }
6886
6887 MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll)
6888 {
6889   MCAuto<MEDFileIntField1TS> ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0));
6890   ret->contentNotNull();
6891   return ret.retn();
6892 }
6893
6894 MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent)
6895 {
6896   MCAuto<MEDFileIntField1TS> ret=new MEDFileIntField1TS(other,shallowCopyOfContent);
6897   ret->contentNotNull();
6898   return ret.retn();
6899 }
6900
6901 MEDFileIntField1TS::MEDFileIntField1TS()
6902 {
6903   _content=new MEDFileIntField1TSWithoutSDA;
6904 }
6905
6906 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
6907 try:MEDFileAnyTypeField1TS(fid,loadAll,ms)
6908 {
6909 }
6910 catch(INTERP_KERNEL::Exception& e)
6911 { throw e; }
6912
6913 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms)
6914 try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms)
6915 {
6916 }
6917 catch(INTERP_KERNEL::Exception& e)
6918 { throw e; }
6919
6920 MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms)
6921 try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms)
6922 {
6923 }
6924 catch(INTERP_KERNEL::Exception& e)
6925 { throw e; }
6926
6927 /*!
6928  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
6929  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
6930  *
6931  * \warning this is a shallow copy constructor
6932  */
6933 MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent)
6934 {
6935 }
6936
6937 MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const
6938 {
6939   return new MEDFileIntField1TS(*this);
6940 }
6941
6942 /*!
6943  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
6944  * following the given input policy.
6945  *
6946  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
6947  *                            By default (true) the globals are deeply copied.
6948  * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field.
6949  */
6950 MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool isDeepCpyGlobs) const
6951 {
6952   MCAuto<MEDFileField1TS> ret;
6953   const MEDFileAnyTypeField1TSWithoutSDA *content(_content);
6954   if(content)
6955     {
6956       const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(content);
6957       if(!contc)
6958         throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
6959       MCAuto<MEDFileField1TSWithoutSDA> newc(contc->convertToDouble());
6960       ret=static_cast<MEDFileField1TS *>(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc));
6961     }
6962   else
6963     ret=MEDFileField1TS::New();
6964   if(isDeepCpyGlobs)
6965     ret->deepCpyGlobs(*this);
6966   else
6967     ret->shallowCpyGlobs(*this);
6968   return ret.retn();
6969 }
6970
6971 /*!
6972  * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is
6973  * checked if its elements are sorted suitable for writing to MED file ("STB" stands for
6974  * "Sort By Type"), if not, an exception is thrown. 
6975  * For more info, see \ref AdvMEDLoaderAPIFieldRW
6976  *  \param [in] field - the field to add to \a this.
6977  *  \throw If the name of \a field is empty.
6978  *  \throw If the data array of \a field is not set.
6979  *  \throw If the data array is already allocated but has different number of components
6980  *         than \a field.
6981  *  \throw If the underlying mesh of \a field has no name.
6982  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
6983  */
6984 void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field)
6985 {
6986   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
6987   setFileName("");
6988   contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull());
6989 }
6990
6991 /*!
6992  * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense
6993  * can be an aggregation of several MEDCouplingFieldDouble instances.
6994  * The mesh support of input parameter \a field is ignored here, it can be NULL.
6995  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
6996  * and \a profile.
6997  *
6998  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
6999  * A new profile is added only if no equal profile is missing.
7000  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7001  *  \param [in] field - the field to add to \a this.
7002  *  \param [in] mesh - the supporting mesh of \a field.
7003  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
7004  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
7005  *  \throw If either \a field or \a mesh or \a profile has an empty name.
7006  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7007  *  \throw If the data array of \a field is not set.
7008  *  \throw If the data array of \a this is already allocated but has different number of
7009  *         components than \a field.
7010  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
7011  *  \sa setFieldNoProfileSBT()
7012  */
7013 void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
7014 {
7015   MCAuto<MEDCouplingFieldDouble> field2(ConvertFieldIntToFieldDouble(field));
7016   setFileName("");
7017   contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull());
7018 }
7019
7020 const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const
7021 {
7022   const MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7023   if(!pt)
7024     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !");
7025   const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(pt);
7026   if(!ret)
7027     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 !");
7028   return ret;
7029 }
7030
7031 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const
7032 {
7033   if(getFileName().empty())
7034     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7035   MCAuto<DataArray> arrOut;
7036   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()));
7037   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7038   return ret2.retn();
7039 }
7040
7041 DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto<DataArray>& arr)
7042 {
7043   if(arr.isNull())
7044     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !");
7045   DataArrayInt *arrC(dynamic_cast<DataArrayInt *>((DataArray *)arr));
7046   if(!arrC)
7047     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !");
7048   arrC->incrRef();
7049   return arrC;
7050 }
7051
7052 MCAuto<MEDCouplingFieldInt> MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto<DataArray>& arr)
7053 {
7054   int t1,t2;
7055   double t0(f->getTime(t1,t2));
7056   MCAuto<DataArrayInt> arr2(DynamicCastSafe<DataArray,DataArrayInt>(arr));
7057   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7058   MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*ft));
7059   ret->setTime(t0,t1,t2); ret->setArray(arr2);
7060   return ret.retn();
7061 }
7062
7063 MCAuto<MEDCouplingFieldDouble> MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f)
7064 {
7065   if(!f)
7066     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !");
7067   int t1,t2;
7068   double t0(f->getTime(t1,t2));
7069   MCAuto<MEDCouplingFieldTemplate> ft(MEDCouplingFieldTemplate::New(*f));
7070   MCAuto<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(*ft));
7071   ret->setTime(t0,t1,t2);
7072   return ret;
7073 }
7074
7075 MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
7076 {
7077   throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !");
7078 }
7079
7080 /*!
7081  * 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
7082  * method should be called (getFieldOnMeshAtLevel for example).
7083  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
7084  *
7085  * \param [in] mesh - the mesh the field is lying on
7086  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
7087  *          caller is to delete this field using decrRef() as it is no more needed. 
7088  */
7089 MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const
7090 {
7091   MCAuto<DataArray> arrOut;
7092   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull()));
7093   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7094   return ret2.retn();
7095 }
7096
7097 /*!
7098  * Returns a new MEDCouplingFieldInt of a given type lying on
7099  * the top level cells of the first mesh in MED file. If \a this field 
7100  * has not been constructed via file reading, an exception is thrown.
7101  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7102  *  \param [in] type - a spatial discretization of interest.
7103  *  \param [in] renumPol - specifies how to permute values of the result field according to
7104  *          the optional numbers of cells and nodes, if any. The valid values are
7105  *          - 0 - do not permute.
7106  *          - 1 - permute cells.
7107  *          - 2 - permute nodes.
7108  *          - 3 - permute cells and nodes.
7109  *
7110  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7111  *          caller is to delete this field using decrRef() as it is no more needed. 
7112  *  \throw If \a this field has not been constructed via file reading.
7113  *  \throw If the MED file is not readable.
7114  *  \throw If there is no mesh in the MED file.
7115  *  \throw If no field values of the given \a type.
7116  *  \throw If no field values lying on the top level support.
7117  *  \sa getFieldAtLevel()
7118  */
7119 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtTopLevel(TypeOfField type, int renumPol) const
7120 {
7121   if(getFileName().empty())
7122     throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !");
7123   MCAuto<DataArray> arrOut;
7124   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()));
7125   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7126   return ret2.retn();
7127 }
7128
7129 /*!
7130  * Returns a new MEDCouplingFieldInt of given type lying on a given mesh.
7131  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7132  *  \param [in] type - a spatial discretization of the new field.
7133  *  \param [in] mesh - the supporting mesh.
7134  *  \param [in] renumPol - specifies how to permute values of the result field according to
7135  *          the optional numbers of cells and nodes, if any. The valid values are
7136  *          - 0 - do not permute.
7137  *          - 1 - permute cells.
7138  *          - 2 - permute nodes.
7139  *          - 3 - permute cells and nodes.
7140  *
7141  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7142  *          caller is to delete this field using decrRef() as it is no more needed. 
7143  *  \throw If no field of \a this is lying on \a mesh.
7144  *  \throw If the mesh is empty.
7145  *  \throw If no field values of the given \a type are available.
7146  *  \sa getFieldAtLevel()
7147  *  \sa getFieldOnMeshAtLevel() 
7148  */
7149 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const
7150 {
7151   MCAuto<DataArray> arrOut;
7152   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()));
7153   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7154   return ret2.retn();
7155 }
7156
7157 /*!
7158  * Returns a new MEDCouplingFieldInt of a given type lying on a given support.
7159  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7160  *  \param [in] type - a spatial discretization of interest.
7161  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7162  *  \param [in] mesh - the supporting mesh.
7163  *  \param [in] renumPol - specifies how to permute values of the result field according to
7164  *          the optional numbers of cells and nodes, if any. The valid values are
7165  *          - 0 - do not permute.
7166  *          - 1 - permute cells.
7167  *          - 2 - permute nodes.
7168  *          - 3 - permute cells and nodes.
7169  *
7170  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7171  *          caller is to delete this field using decrRef() as it is no more needed. 
7172  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7173  *  \throw If no field of \a this is lying on \a mesh.
7174  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7175  *  \sa getFieldAtLevel()
7176  *  \sa getFieldOnMeshAtLevel() 
7177  */
7178 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
7179 {
7180   MCAuto<DataArray> arrOut;
7181   MCAuto<MEDCouplingFieldDouble> ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()));
7182   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7183   return ret2.retn();
7184 }
7185
7186 /*!
7187  * Returns a new MEDCouplingFieldDouble of a given type lying on a given support.
7188  * This method is called "Old" because in MED3 norm a field has only one meshName
7189  * attached, so this method is for readers of MED2 files. If \a this field 
7190  * has not been constructed via file reading, an exception is thrown.
7191  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7192  *  \param [in] type - a spatial discretization of interest.
7193  *  \param [in] mName - a name of the supporting mesh.
7194  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7195  *  \param [in] renumPol - specifies how to permute values of the result field according to
7196  *          the optional numbers of cells and nodes, if any. The valid values are
7197  *          - 0 - do not permute.
7198  *          - 1 - permute cells.
7199  *          - 2 - permute nodes.
7200  *          - 3 - permute cells and nodes.
7201  *
7202  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
7203  *          caller is to delete this field using decrRef() as it is no more needed. 
7204  *  \throw If the MED file is not readable.
7205  *  \throw If there is no mesh named \a mName in the MED file.
7206  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
7207  *  \throw If \a this field has not been constructed via file reading.
7208  *  \throw If no field of \a this is lying on the mesh named \a mName.
7209  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7210  *  \sa getFieldAtLevel()
7211  */
7212 MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, int renumPol) const
7213 {
7214   if(getFileName().empty())
7215     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !");
7216   MCAuto<DataArray> arrOut;
7217   MCAuto<MEDCouplingFieldDouble> ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull());
7218   MCAuto<MEDCouplingFieldInt> ret2(SetDataArrayDoubleInIntField(ret,arrOut));
7219   return ret2.retn();
7220 }
7221
7222 /*!
7223  * Returns values and a profile of the field of a given type lying on a given support.
7224  * For more info, see \ref AdvMEDLoaderAPIFieldRW
7225  *  \param [in] type - a spatial discretization of the field.
7226  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
7227  *  \param [in] mesh - the supporting mesh.
7228  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
7229  *          field of interest lies on. If the field lies on all entities of the given
7230  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
7231  *          using decrRef() as it is no more needed.  
7232  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
7233  *          field. The caller is to delete this array using decrRef() as it is no more needed.
7234  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
7235  *  \throw If no field of \a this is lying on \a mesh.
7236  *  \throw If no field values of the given \a type or given \a meshDimRelToMax are available.
7237  */
7238 DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
7239 {
7240   MCAuto<DataArray> arr=contentNotNull()->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNull());
7241   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr);
7242 }
7243
7244 MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull()
7245 {
7246   MEDFileAnyTypeField1TSWithoutSDA *pt(_content);
7247   if(!pt)
7248     throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !");
7249   MEDFileIntField1TSWithoutSDA *ret=dynamic_cast<MEDFileIntField1TSWithoutSDA *>(pt);
7250   if(!ret)
7251     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 !");
7252   return ret;
7253 }
7254
7255 DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const
7256 {
7257   return contentNotNull()->getUndergroundDataArrayTemplate();
7258 }
7259
7260 //= MEDFileAnyTypeFieldMultiTSWithoutSDA
7261
7262 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA()
7263 {
7264 }
7265
7266 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileFieldNameScope(fieldName)
7267 {
7268 }
7269
7270 /*!
7271  * \param [in] fieldId field id in C mode
7272  */
7273 MEDFileAnyTypeFieldMultiTSWithoutSDA::MEDFileAnyTypeFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7274 {
7275   med_field_type typcha;
7276   std::string dtunitOut;
7277   int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,fieldId,false,_name,typcha,_infos,dtunitOut));
7278   setDtUnit(dtunitOut.c_str());
7279   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,typcha,loadAll,ms,entities);
7280 }
7281
7282 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)
7283 try:MEDFileFieldNameScope(fieldName),_infos(infos)
7284 {
7285   setDtUnit(dtunit.c_str());
7286   loadStructureOrStructureAndBigArraysRecursively(fid,nbOfStep,fieldTyp,loadAll,ms,entities);
7287 }
7288 catch(INTERP_KERNEL::Exception& e)
7289 {
7290     throw e;
7291 }
7292
7293 std::size_t MEDFileAnyTypeFieldMultiTSWithoutSDA::getHeapMemorySizeWithoutChildren() const
7294 {
7295   std::size_t ret(_name.capacity()+_infos.capacity()*sizeof(std::string)+_time_steps.capacity()*sizeof(MCAuto<MEDFileField1TSWithoutSDA>));
7296   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7297     ret+=(*it).capacity();
7298   return ret;
7299 }
7300
7301 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTSWithoutSDA::getDirectChildrenWithNull() const
7302 {
7303   std::vector<const BigMemoryObject *> ret;
7304   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7305     ret.push_back((const MEDFileAnyTypeField1TSWithoutSDA *)*it);
7306   return ret;
7307 }
7308
7309 /*!
7310  * 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
7311  * NULL.
7312  */
7313 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds(const int *startIds, const int *endIds) const
7314 {
7315   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7316   ret->setInfo(_infos);
7317   int sz=(int)_time_steps.size();
7318   for(const int *id=startIds;id!=endIds;id++)
7319     {
7320       if(*id>=0 && *id<sz)
7321         {
7322           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[*id];
7323           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7324           if(tse)
7325             {
7326               tse->incrRef();
7327               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7328             }
7329           ret->pushBackTimeStep(tse2);
7330         }
7331       else
7332         {
7333           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << std::distance(startIds,id) << " value is " << *id;
7334           oss << " ! Should be in [0," << sz << ") !";
7335           throw INTERP_KERNEL::Exception(oss.str());
7336         }
7337     }
7338   if(ret->getNumberOfTS()>0)
7339     ret->synchronizeNameScope();
7340   ret->copyNameScope(*this);
7341   return ret.retn();
7342 }
7343
7344 /*!
7345  * 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
7346  * NULL.
7347  */
7348 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2(int bg, int end, int step) const
7349 {
7350   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds2";
7351   int nbOfEntriesToKeep=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7352   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=createNew();
7353   ret->setInfo(_infos);
7354   int sz=(int)_time_steps.size();
7355   int j=bg;
7356   for(int i=0;i<nbOfEntriesToKeep;i++,j+=step)
7357     {
7358       if(j>=0 && j<sz)
7359         {
7360           const MEDFileAnyTypeField1TSWithoutSDA *tse=_time_steps[j];
7361           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> tse2;
7362           if(tse)
7363             {
7364               tse->incrRef();
7365               tse2=(const_cast<MEDFileAnyTypeField1TSWithoutSDA *>(tse));
7366             }
7367           ret->pushBackTimeStep(tse2);
7368         }
7369       else
7370         {
7371           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::buildFromTimeStepIds : At pos #" << i << " value is " << j;
7372           oss << " ! Should be in [0," << sz << ") !";
7373           throw INTERP_KERNEL::Exception(oss.str());
7374         }
7375     }
7376   if(ret->getNumberOfTS()>0)
7377     ret->synchronizeNameScope();
7378   ret->copyNameScope(*this);
7379   return ret.retn();
7380 }
7381
7382 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7383 {
7384   int id=0;
7385   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7386   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7387     {
7388       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7389       if(!cur)
7390         continue;
7391       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7392       if(std::find(timeSteps.begin(),timeSteps.end(),p)!=timeSteps.end())
7393         ids->pushBackSilent(id);
7394     }
7395   return buildFromTimeStepIds(ids->begin(),ids->end());
7396 }
7397
7398 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
7399 {
7400   int id=0;
7401   MCAuto<DataArrayInt> ids=DataArrayInt::New(); ids->alloc(0,1);
7402   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,id++)
7403     {
7404       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7405       if(!cur)
7406         continue;
7407       std::pair<int,int> p(cur->getIteration(),cur->getOrder());
7408       if(std::find(timeSteps.begin(),timeSteps.end(),p)==timeSteps.end())
7409         ids->pushBackSilent(id);
7410     }
7411   return buildFromTimeStepIds(ids->begin(),ids->end());
7412 }
7413
7414 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const
7415 {
7416   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7417     {
7418       const MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7419       if(!cur)
7420         continue;
7421       if(cur->presenceOfMultiDiscPerGeoType())
7422         return true;
7423     }
7424   return false;
7425 }
7426
7427 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTSWithoutSDA::getInfo() const
7428 {
7429   return _infos;
7430 }
7431
7432 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setInfo(const std::vector<std::string>& info)
7433 {
7434   _infos=info;
7435 }
7436
7437 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepPos(int iteration, int order) const
7438 {
7439   int ret=0;
7440   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7441     {
7442       const MEDFileAnyTypeField1TSWithoutSDA *pt(*it);
7443       if(pt->isDealingTS(iteration,order))
7444         return ret;
7445     }
7446   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepPos : Muli timestep field on time (" << iteration << "," << order << ") does not exist ! Available (iteration,order) are :\n";
7447   std::vector< std::pair<int,int> > vp=getIterations();
7448   for(std::vector< std::pair<int,int> >::const_iterator it2=vp.begin();it2!=vp.end();it2++)
7449     oss << "(" << (*it2).first << "," << (*it2).second << ") ";
7450   throw INTERP_KERNEL::Exception(oss.str());
7451 }
7452
7453 const MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order) const
7454 {
7455   return *_time_steps[getTimeStepPos(iteration,order)];
7456 }
7457
7458 MEDFileAnyTypeField1TSWithoutSDA& MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepEntry(int iteration, int order)
7459 {
7460   return *_time_steps[getTimeStepPos(iteration,order)];
7461 }
7462
7463 std::string MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshName() const
7464 {
7465   if(_time_steps.empty())
7466     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getMeshName : not time steps !");
7467   return _time_steps[0]->getMeshName();
7468 }
7469
7470 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setMeshName(const std::string& newMeshName)
7471 {
7472   std::string oldName(getMeshName());
7473   std::vector< std::pair<std::string,std::string> > v(1);
7474   v[0].first=oldName; v[0].second=newMeshName;
7475   changeMeshNames(v);
7476 }
7477
7478 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
7479 {
7480   bool ret=false;
7481   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7482     {
7483       MEDFileAnyTypeField1TSWithoutSDA *cur(*it);
7484       if(cur)
7485         ret=cur->changeMeshNames(modifTab) || ret;
7486     }
7487   return ret;
7488 }
7489
7490 /*!
7491  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArray
7492  */
7493 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArray(int iteration, int order) const
7494 {
7495   return getTimeStepEntry(iteration,order).getUndergroundDataArray();
7496 }
7497
7498 /*!
7499  * See doc at MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt
7500  */
7501 DataArray *MEDFileAnyTypeFieldMultiTSWithoutSDA::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
7502 {
7503   return getTimeStepEntry(iteration,order).getUndergroundDataArrayExt(entries);
7504 }
7505
7506 bool MEDFileAnyTypeFieldMultiTSWithoutSDA::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N,
7507                                                                        MEDFileFieldGlobsReal& glob)
7508 {
7509   bool ret=false;
7510   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7511     {
7512       MEDFileAnyTypeField1TSWithoutSDA *f1ts(*it);
7513       if(f1ts)
7514         ret=f1ts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,glob) || ret;
7515     }
7516   return ret;
7517 }
7518
7519 void MEDFileAnyTypeFieldMultiTSWithoutSDA::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
7520 {
7521   std::string startLine(bkOffset,' ');
7522   oss << startLine << "Field multi time steps [Type=" << getTypeStr() << "]";
7523   if(fmtsId>=0)
7524     oss << " (" << fmtsId << ")";
7525   oss << " has the following name: \"" << _name << "\"." << std::endl;
7526   oss << startLine << "Field multi time steps has " << _infos.size() << " components with the following infos :" << std::endl;
7527   for(std::vector<std::string>::const_iterator it=_infos.begin();it!=_infos.end();it++)
7528     {
7529       oss << startLine << "  -  \"" << *it << "\"" << std::endl;
7530     }
7531   int i=0;
7532   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7533     {
7534       std::string chapter(17,'0'+i);
7535       oss << startLine << chapter << std::endl;
7536       const MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7537       if(cur)
7538         cur->simpleRepr(bkOffset+2,oss,i);
7539       else
7540         oss << startLine << "  Field on one time step #" << i << " is not defined !" << std::endl;
7541       oss << startLine << chapter << std::endl;
7542     }
7543 }
7544
7545 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeSteps(std::vector<double>& ret1) const
7546 {
7547   std::size_t sz=_time_steps.size();
7548   std::vector< std::pair<int,int> > ret(sz);
7549   ret1.resize(sz);
7550   for(std::size_t i=0;i<sz;i++)
7551     {
7552       const MEDFileAnyTypeField1TSWithoutSDA *f1ts=_time_steps[i];
7553       if(f1ts)
7554         {
7555           ret1[i]=f1ts->getTime(ret[i].first,ret[i].second);
7556         }
7557       else
7558         {
7559           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !";
7560           throw INTERP_KERNEL::Exception(oss.str());
7561         }
7562     }
7563   return ret;
7564 }
7565
7566 void MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep(MCAuto<MEDFileAnyTypeField1TSWithoutSDA>& tse)
7567 {
7568   MEDFileAnyTypeField1TSWithoutSDA *tse2(tse);
7569   if(!tse2)
7570     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input content object is null !");
7571   checkCoherencyOfType(tse2);
7572   if(_time_steps.empty())
7573     {
7574       setName(tse2->getName().c_str());
7575       setInfo(tse2->getInfo());
7576     }
7577   checkThatComponentsMatch(tse2->getInfo());
7578   if(getDtUnit().empty() && !tse->getDtUnit().empty())
7579     setDtUnit(tse->getDtUnit());
7580   _time_steps.push_back(tse);
7581 }
7582
7583 void MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope()
7584 {
7585   std::size_t nbOfCompo=_infos.size();
7586   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7587     {
7588       MEDFileAnyTypeField1TSWithoutSDA *cur=(*it);
7589       if(cur)
7590         {
7591           if((cur->getInfo()).size()!=nbOfCompo)
7592             {
7593               std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::synchronizeNameScope : Mismatch in the number of components of parts ! Should be " << nbOfCompo;
7594               oss << " ! but the field at iteration=" << cur->getIteration() << " order=" << cur->getOrder() << " has " << (cur->getInfo()).size() << " components !";
7595               throw INTERP_KERNEL::Exception(oss.str());
7596             }
7597           cur->copyNameScope(*this);
7598         }
7599     }
7600 }
7601
7602 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively(med_idt fid, int nbPdt, med_field_type fieldTyp, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
7603 {
7604   _time_steps.resize(nbPdt);
7605   for(int i=0;i<nbPdt;i++)
7606     {
7607       std::vector< std::pair<int,int> > ts;
7608       med_int numdt=0,numo=0;
7609       med_float dt=0.0;
7610       MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,_name.c_str(),i+1,&numdt,&numo,&dt));
7611       switch(fieldTyp)
7612       {
7613         case MED_FLOAT64:
7614           {
7615             _time_steps[i]=MEDFileField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7616             break;
7617           }
7618         case MED_INT32:
7619           {
7620             _time_steps[i]=MEDFileIntField1TSWithoutSDA::New(_name.c_str(),i+1,numdt,numo,_infos);
7621             break;
7622           }
7623         default:
7624           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::loadStructureOrStructureAndBigArraysRecursively : managed field type are : FLOAT64, INT32 !");
7625       }
7626       if(loadAll)
7627         _time_steps[i]->loadStructureAndBigArraysRecursively(fid,*this,ms,entities);
7628       else
7629         _time_steps[i]->loadOnlyStructureOfDataRecursively(fid,*this,ms,entities);
7630       synchronizeNameScope();
7631     }
7632 }
7633
7634 void MEDFileAnyTypeFieldMultiTSWithoutSDA::writeLL(med_idt fid, const MEDFileWritable& opts) const
7635 {
7636   if(_time_steps.empty())
7637     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::writeLL : no time steps set !");
7638   checkThatNbOfCompoOfTSMatchThis();
7639   std::vector<std::string> infos(getInfo());
7640   int nbComp=infos.size();
7641   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7642   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
7643   for(int i=0;i<nbComp;i++)
7644     {
7645       std::string info=infos[i];
7646       std::string c,u;
7647       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
7648       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,comp+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7649       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,opts.getTooLongStrPolicy());
7650     }
7651   if(_name.empty())
7652     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::write : MED file does not accept field with empty name !");
7653   MEDFILESAFECALLERWR0(MEDfieldCr,(fid,_name.c_str(),getMEDFileFieldType(),nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()));
7654   int nbOfTS=_time_steps.size();
7655   for(int i=0;i<nbOfTS;i++)
7656     _time_steps[i]->writeLL(fid,opts,*this);
7657 }
7658
7659 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc)
7660 {
7661   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7662     {
7663       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7664       if(elt)
7665         elt->loadBigArraysRecursively(fid,nasc);
7666     }
7667 }
7668
7669 void MEDFileAnyTypeFieldMultiTSWithoutSDA::loadBigArraysRecursivelyIfNecessary(med_idt fid, const MEDFileFieldNameScope& nasc)
7670 {
7671   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7672     {
7673       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7674       if(elt)
7675         elt->loadBigArraysRecursivelyIfNecessary(fid,nasc);
7676     }
7677 }
7678
7679 void MEDFileAnyTypeFieldMultiTSWithoutSDA::unloadArrays()
7680 {
7681   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7682     {
7683       MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
7684       if(elt)
7685         elt->unloadArrays();
7686     }
7687 }
7688
7689 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNumberOfTS() const
7690 {
7691   return _time_steps.size();
7692 }
7693
7694 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseEmptyTS()
7695 {
7696   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  > newTS;
7697   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7698     {
7699       const MEDFileAnyTypeField1TSWithoutSDA *tmp=(*it);
7700       if(tmp)
7701         newTS.push_back(*it);
7702     }
7703   _time_steps=newTS;
7704 }
7705
7706 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds(const int *startIds, const int *endIds)
7707 {
7708   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7709   int maxId=(int)_time_steps.size();
7710   int ii=0;
7711   std::set<int> idsToDel;
7712   for(const int *id=startIds;id!=endIds;id++,ii++)
7713     {
7714       if(*id>=0 && *id<maxId)
7715         {
7716           idsToDel.insert(*id);
7717         }
7718       else
7719         {
7720           std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::eraseTimeStepIds : At pos #" << ii << " request for id=" << *id << " not in [0," << maxId << ") !";
7721           throw INTERP_KERNEL::Exception(oss.str());
7722         }
7723     }
7724   for(int iii=0;iii<maxId;iii++)
7725     if(idsToDel.find(iii)==idsToDel.end())
7726       newTS.push_back(_time_steps[iii]);
7727   _time_steps=newTS;
7728 }
7729
7730 void MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2(int bg, int end, int step)
7731 {
7732   static const char msg[]="MEDFileAnyTypeFieldMultiTSWithoutSDA::eraseTimeStepIds2";
7733   int nbOfEntriesToKill=DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg);
7734   if(nbOfEntriesToKill==0)
7735     return ;
7736   std::size_t sz=_time_steps.size();
7737   std::vector<bool> b(sz,true);
7738   int j=bg;
7739   for(int i=0;i<nbOfEntriesToKill;i++,j+=step)
7740     b[j]=false;
7741   std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > newTS;
7742   for(std::size_t i=0;i<sz;i++)
7743     if(b[i])
7744       newTS.push_back(_time_steps[i]);
7745   _time_steps=newTS;
7746 }
7747
7748 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) const
7749 {
7750   int ret=0;
7751   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; 
7752   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7753     {
7754       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7755       if(tmp)
7756         {
7757           int it2,ord;
7758           tmp->getTime(it2,ord);
7759           if(it2==iteration && order==ord)
7760             return ret;
7761           else
7762             oss << "(" << it2 << ","  << ord << "), ";
7763         }
7764     }
7765   throw INTERP_KERNEL::Exception(oss.str());
7766 }
7767
7768 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) const
7769 {
7770   int ret=0;
7771   std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutSDA::getPosGivenTime : No such time step " << time << "! \nPossibilities are : ";
7772   oss.precision(15);
7773   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA>  >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++)
7774     {
7775       const MEDFileAnyTypeField1TSWithoutSDA *tmp(*it);
7776       if(tmp)
7777         {
7778           int it2,ord;
7779           double ti=tmp->getTime(it2,ord);
7780           if(fabs(time-ti)<eps)
7781             return ret;
7782           else
7783             oss << ti << ", ";
7784         }
7785     }
7786   throw INTERP_KERNEL::Exception(oss.str());
7787 }
7788
7789 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getIterations() const
7790 {
7791   int lgth=_time_steps.size();
7792   std::vector< std::pair<int,int> > ret(lgth);
7793   for(int i=0;i<lgth;i++)
7794     _time_steps[i]->fillIteration(ret[i]);
7795   return ret;
7796 }
7797
7798 /*!
7799  * 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'
7800  * This method returns two things.
7801  * - The absolute dimension of 'this' in first parameter. 
7802  * - The available ext levels relative to the absolute dimension returned in first parameter. These relative levels are relative
7803  *   to the first output parameter. The values in 'levs' will be returned in decreasing order.
7804  *
7805  * This method is designed for MEDFileFieldMultiTS instances that have a discritization ON_CELLS, ON_GAUSS_NE and ON_GAUSS.
7806  * Only these 3 discretizations will be taken into account here.
7807  *
7808  * If 'this' is empty this method will throw an INTERP_KERNEL::Exception.
7809  * If there is \b only node fields defined in 'this' -1 is returned and 'levs' output parameter will be empty. In this
7810  * case the caller has to know the underlying mesh it refers to. By defaut it is the level 0 of the corresponding mesh.
7811  *
7812  * This method is usefull to make the link between meshDimension of the underlying mesh in 'this' and the levels on 'this'.
7813  * 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'.
7814  * 
7815  * Let's consider the typical following case :
7816  * - a mesh 'm1' has a meshDimension 3 and has the following non empty levels
7817  * [0,-1,-2] for example 'm1' lies on TETRA4, HEXA8 TRI3 and SEG2
7818  * - 'f1' lies on 'm1' and is defined on 3D and 1D cells for example
7819  *   TETRA4 and SEG2
7820  * - 'f2' lies on 'm1' too and is defined on 2D and 1D cells for example TRI3 and SEG2
7821  *
7822  * In this case f1->getNonEmptyLevelsExt will return (3,[0,-2]) and f2->getNonEmptyLevelsExt will return (2,[0,-1])
7823  * 
7824  * To retrieve the highest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+0);//absDim-meshDim+relativeLev
7825  * To retrieve the lowest level of f1 it should be done, f1->getFieldAtLevel(ON_CELLS,3-3+(-2));//absDim-meshDim+relativeLev
7826  * To retrieve the highest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+0);//absDim-meshDim+relativeLev
7827  * To retrieve the lowest level of f2 it should be done, f1->getFieldAtLevel(ON_CELLS,2-3+(-1));//absDim-meshDim+relativeLev
7828  */
7829 int MEDFileAnyTypeFieldMultiTSWithoutSDA::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
7830 {
7831   return getTimeStepEntry(iteration,order).getNonEmptyLevels(mname,levs);
7832 }
7833
7834 const MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos) const
7835 {
7836   if(pos<0 || pos>=(int)_time_steps.size())
7837     {
7838       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7839       throw INTERP_KERNEL::Exception(oss.str());
7840     }
7841   const MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7842   if(item==0)
7843     {
7844       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7845       oss << "\nTry to use following method eraseEmptyTS !";
7846       throw INTERP_KERNEL::Exception(oss.str());
7847     }
7848   return item;
7849 }
7850
7851 MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2(int pos)
7852 {
7853   if(pos<0 || pos>=(int)_time_steps.size())
7854     {
7855       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !";
7856       throw INTERP_KERNEL::Exception(oss.str());
7857     }
7858   MEDFileAnyTypeField1TSWithoutSDA *item=_time_steps[pos];
7859   if(item==0)
7860     {
7861       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::getTimeStepAtPos2 : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !";
7862       oss << "\nTry to use following method eraseEmptyTS !";
7863       throw INTERP_KERNEL::Exception(oss.str());
7864     }
7865   return item;
7866 }
7867
7868 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsed2() const
7869 {
7870   std::vector<std::string> ret;
7871   std::set<std::string> ret2;
7872   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7873     {
7874       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
7875       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7876         if(ret2.find(*it2)==ret2.end())
7877           {
7878             ret.push_back(*it2);
7879             ret2.insert(*it2);
7880           }
7881     }
7882   return ret;
7883 }
7884
7885 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsed2() const
7886 {
7887   std::vector<std::string> ret;
7888   std::set<std::string> ret2;
7889   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7890     {
7891       std::vector<std::string> tmp=(*it)->getLocsReallyUsed2();
7892       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
7893         if(ret2.find(*it2)==ret2.end())
7894           {
7895             ret.push_back(*it2);
7896             ret2.insert(*it2);
7897           }
7898     }
7899   return ret;
7900 }
7901
7902 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getPflsReallyUsedMulti2() const
7903 {
7904   std::vector<std::string> ret;
7905   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7906     {
7907       std::vector<std::string> tmp=(*it)->getPflsReallyUsedMulti2();
7908       ret.insert(ret.end(),tmp.begin(),tmp.end());
7909     }
7910   return ret;
7911 }
7912
7913 std::vector<std::string> MEDFileAnyTypeFieldMultiTSWithoutSDA::getLocsReallyUsedMulti2() const
7914 {
7915   std::vector<std::string> ret;
7916   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7917     {
7918       std::vector<std::string> tmp=(*it)->getLocsReallyUsedMulti2();
7919       ret.insert(ret.end(),tmp.begin(),tmp.end());
7920     }
7921   return ret;
7922 }
7923
7924 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changePflsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7925 {
7926   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7927     (*it)->changePflsRefsNamesGen2(mapOfModif);
7928 }
7929
7930 void MEDFileAnyTypeFieldMultiTSWithoutSDA::changeLocsRefsNamesGen2(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
7931 {
7932   for(std::vector< MCAuto< MEDFileAnyTypeField1TSWithoutSDA > >::iterator it=_time_steps.begin();it!=_time_steps.end();it++)
7933     (*it)->changeLocsRefsNamesGen2(mapOfModif);
7934 }
7935
7936 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTSWithoutSDA::getTypesOfFieldAvailable() const
7937 {
7938   int lgth=_time_steps.size();
7939   std::vector< std::vector<TypeOfField> > ret(lgth);
7940   for(int i=0;i<lgth;i++)
7941     _time_steps[i]->fillTypesOfFieldAvailable(ret[i]);
7942   return ret;
7943 }
7944
7945 /*!
7946  * entry point for users that want to iterate into MEDFile DataStructure without any overhead.
7947  */
7948 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
7949 {
7950   return getTimeStepEntry(iteration,order).getFieldSplitedByType(mname,types,typesF,pfls,locs);
7951 }
7952
7953 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::deepCopy() const
7954 {
7955   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret=shallowCpy();
7956   std::size_t i=0;
7957   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
7958     {
7959       if((const MEDFileAnyTypeField1TSWithoutSDA *)*it)
7960         ret->_time_steps[i]=(*it)->deepCopy();
7961     }
7962   return ret.retn();
7963 }
7964
7965 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents() const
7966 {
7967   std::size_t sz(_infos.size()),sz2(_time_steps.size());
7968   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(sz);
7969   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ts(sz2);
7970   for(std::size_t i=0;i<sz;i++)
7971     {
7972       ret[i]=shallowCpy();
7973       ret[i]->_infos.resize(1); ret[i]->_infos[0]=_infos[i];
7974     }
7975   for(std::size_t i=0;i<sz2;i++)
7976     {
7977       std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > ret1=_time_steps[i]->splitComponents();
7978       if(ret1.size()!=sz)
7979         {
7980           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitComponents : At rank #" << i << " number of components is " << ret1.size() << " whereas it should be for all time steps " << sz << " !";
7981           throw INTERP_KERNEL::Exception(oss.str());
7982         }
7983       ts[i]=ret1;
7984     }
7985   for(std::size_t i=0;i<sz;i++)
7986     for(std::size_t j=0;j<sz2;j++)
7987       ret[i]->_time_steps[j]=ts[j][i];
7988   return ret;
7989 }
7990
7991 /*!
7992  * This method splits into discretization each time steps in \a this.
7993  * ** WARNING ** the returned instances are not compulsary defined on the same time steps series !
7994  */
7995 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations() const
7996 {
7997   std::size_t sz(_time_steps.size());
7998   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
7999   for(std::size_t i=0;i<sz;i++)
8000     {
8001       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8002       if(!timeStep)
8003         {
8004           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : time step #" << i << " is null !"; 
8005           throw INTERP_KERNEL::Exception(oss.str());
8006         }
8007       items[i]=timeStep->splitDiscretizations();  
8008     }
8009   //
8010   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret;
8011   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > ret2;
8012   std::vector< TypeOfField > types;
8013   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8014     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8015       {
8016         std::vector<TypeOfField> ts=(*it1)->getTypesOfFieldAvailable();
8017         if(ts.size()!=1)
8018           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitDiscretizations : it appears that the splitting of MEDFileAnyTypeField1TSWithoutSDA::splitDiscretizations has returned invalid result !");
8019         std::vector< TypeOfField >::iterator it2=std::find(types.begin(),types.end(),ts[0]);
8020         if(it2==types.end())
8021           types.push_back(ts[0]);
8022       }
8023   ret.resize(types.size()); ret2.resize(types.size());
8024   for(std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > >::const_iterator it0=items.begin();it0!=items.end();it0++)
8025     for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
8026       {
8027         TypeOfField typ=(*it1)->getTypesOfFieldAvailable()[0];
8028         std::size_t pos=std::distance(types.begin(),std::find(types.begin(),types.end(),typ));
8029         ret2[pos].push_back(*it1);
8030       }
8031   for(std::size_t i=0;i<types.size();i++)
8032     {
8033       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8034       for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::iterator it1=ret2[i].begin();it1!=ret2[i].end();it1++)
8035         elt->pushBackTimeStep(*it1);//also updates infos in elt
8036       ret[i]=elt;
8037       elt->MEDFileFieldNameScope::operator=(*this);
8038     }
8039   return ret;
8040 }
8041
8042 /*!
8043  * Contrary to splitDiscretizations method this method makes the hypothesis that the times series are **NOT** impacted by the splitting of multi discretization.
8044  */
8045 std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes() const
8046 {
8047   std::size_t sz(_time_steps.size());
8048   std::vector< std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> > > items(sz);
8049   std::size_t szOut(std::numeric_limits<std::size_t>::max());
8050   for(std::size_t i=0;i<sz;i++)
8051     {
8052       const MEDFileAnyTypeField1TSWithoutSDA *timeStep(_time_steps[i]);
8053       if(!timeStep)
8054         {
8055           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : time step #" << i << " is null !";
8056           throw INTERP_KERNEL::Exception(oss.str());
8057         }
8058       items[i]=timeStep->splitMultiDiscrPerGeoTypes();
8059       if(szOut==std::numeric_limits<std::size_t>::max())
8060         szOut=items[i].size();
8061       else
8062         if(items[i].size()!=szOut)
8063           throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : The splitting per discretization is expected to be same among time steps !");
8064     }
8065   if(szOut==std::numeric_limits<std::size_t>::max())
8066     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::splitMultiDiscrPerGeoTypes : empty field !");
8067   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > ret(szOut);
8068   for(std::size_t i=0;i<szOut;i++)
8069     {
8070       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt(createNew());
8071       for(std::size_t j=0;j<sz;j++)
8072         elt->pushBackTimeStep(items[j][i]);
8073       ret[i]=elt;
8074       elt->MEDFileFieldNameScope::operator=(*this);
8075     }
8076   return ret;
8077 }
8078
8079 void MEDFileAnyTypeFieldMultiTSWithoutSDA::copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr)
8080 {
8081   _name=field->getName();
8082   if(_name.empty())
8083     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : unsupported fields with no name in MED file !");
8084   if(!arr)
8085     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::copyTinyInfoFrom : no array set !");
8086   _infos=arr->getInfoOnComponents();
8087 }
8088
8089 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field, const DataArray *arr) const
8090 {
8091   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : invalid ";
8092   if(_name!=field->getName())
8093     {
8094       std::ostringstream oss; oss << MSG << "name ! should be \"" << _name;
8095       oss << "\" and it is set in input field to \"" << field->getName() << "\" !";
8096       throw INTERP_KERNEL::Exception(oss.str());
8097     }
8098   if(!arr)
8099     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfTinyInfo : no array set !");
8100   checkThatComponentsMatch(arr->getInfoOnComponents());
8101 }
8102
8103 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatComponentsMatch(const std::vector<std::string>& compos) const
8104 {
8105   static const char MSG[]="MEDFileFieldMultiTSWithoutSDA::checkThatComponentsMatch : ";
8106   if(getInfo().size()!=compos.size())
8107     {
8108       std::ostringstream oss; oss << MSG << "mismatch of number of components between this (" << getInfo().size() << ") and ";
8109       oss << " number of components of element to append (" << compos.size() << ") !";
8110       throw INTERP_KERNEL::Exception(oss.str());
8111     }
8112   if(_infos!=compos)
8113     {
8114       std::ostringstream oss; oss << MSG << "components have same size but are different ! should be \"";
8115       std::copy(_infos.begin(),_infos.end(),std::ostream_iterator<std::string>(oss,", "));
8116       oss << " But compo in input fields are : ";
8117       std::copy(compos.begin(),compos.end(),std::ostream_iterator<std::string>(oss,", "));
8118       oss << " !";
8119       throw INTERP_KERNEL::Exception(oss.str());
8120     }
8121 }
8122
8123 void MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis() const
8124 {
8125   std::size_t sz=_infos.size();
8126   int j=0;
8127   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,j++)
8128     {
8129       const MEDFileAnyTypeField1TSWithoutSDA *elt(*it);
8130       if(elt)
8131         if(elt->getInfo().size()!=sz)
8132           {
8133             std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::checkThatNbOfCompoOfTSMatchThis : At pos #" << j << " the number of components is equal to ";
8134             oss << elt->getInfo().size() << " whereas it is expected to be equal to " << sz << " !";
8135             throw INTERP_KERNEL::Exception(oss.str());
8136           }
8137     }
8138 }
8139
8140 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArray *arr, MEDFileFieldGlobsReal& glob)
8141 {
8142   if(!field)
8143     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8144   if(!_time_steps.empty())
8145     checkCoherencyOfTinyInfo(field,arr);
8146   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8147   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8148   objC->setFieldNoProfileSBT(field,arr,glob,*this);
8149   copyTinyInfoFrom(field,arr);
8150   _time_steps.push_back(obj);
8151 }
8152
8153 void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArray *arr, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile, MEDFileFieldGlobsReal& glob)
8154 {
8155   if(!field)
8156     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::appendFieldNoProfileSBT : input field is NULL !");
8157   if(!_time_steps.empty())
8158     checkCoherencyOfTinyInfo(field,arr);
8159   MEDFileAnyTypeField1TSWithoutSDA *objC=createNew1TSWithoutSDAEmptyInstance();
8160   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> obj(objC);
8161   objC->setFieldProfile(field,arr,mesh,meshDimRelToMax,profile,glob,*this);
8162   copyTinyInfoFrom(field,arr);
8163   _time_steps.push_back(obj);
8164 }
8165
8166 void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MCAuto<MEDFileAnyTypeField1TSWithoutSDA> ts)
8167 {
8168   int sz=(int)_time_steps.size();
8169   if(i<0 || i>=sz)
8170     {
8171       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !";
8172       throw INTERP_KERNEL::Exception(oss.str());
8173     }
8174   const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts);
8175   if(tsPtr)
8176     {
8177       if(tsPtr->getNumberOfComponents()!=(int)_infos.size())
8178         {
8179           std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() <<  " !";
8180           throw INTERP_KERNEL::Exception(oss.str());
8181         }
8182     }
8183   _time_steps[i]=ts;
8184 }
8185
8186 //= MEDFileFieldMultiTSWithoutSDA
8187
8188 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)
8189 {
8190   return new MEDFileFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8191 }
8192
8193 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA()
8194 {
8195 }
8196
8197 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8198 {
8199 }
8200
8201 /*!
8202  * \param [in] fieldId field id in C mode
8203  */
8204 MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8205 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8206 {
8207 }
8208 catch(INTERP_KERNEL::Exception& e)
8209 { throw e; }
8210
8211 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)
8212 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8213 {
8214 }
8215 catch(INTERP_KERNEL::Exception& e)
8216 { throw e; }
8217
8218 MEDFileAnyTypeField1TSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8219 {
8220   return new MEDFileField1TSWithoutSDA;
8221 }
8222
8223 void MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8224 {
8225   if(!f1ts)
8226     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8227   const MEDFileField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(f1ts);
8228   if(!f1tsC)
8229     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
8230 }
8231
8232 const char *MEDFileFieldMultiTSWithoutSDA::getTypeStr() const
8233 {
8234   return MEDFileField1TSWithoutSDA::TYPE_STR;
8235 }
8236
8237 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::shallowCpy() const
8238 {
8239   return new MEDFileFieldMultiTSWithoutSDA(*this);
8240 }
8241
8242 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::createNew() const
8243 {
8244   return new MEDFileFieldMultiTSWithoutSDA;
8245 }
8246
8247 /*!
8248  * entry point for users that want to iterate into MEDFile DataStructure with a reduced overhead because output arrays are extracted (created) specially
8249  * for the call of this method. That's why the DataArrayDouble instance in returned vector of vector should be dealed by the caller.
8250  */
8251 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
8252 {
8253   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=getTimeStepEntry(iteration,order);
8254   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
8255   if(!myF1TSC)
8256     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::getFieldSplitedByType2 : mismatch of type of field expecting FLOAT64 !");
8257   return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs);
8258 }
8259
8260 MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const
8261 {
8262   MCAuto<MEDFileIntFieldMultiTSWithoutSDA> ret(new MEDFileIntFieldMultiTSWithoutSDA);
8263   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8264   int i=0;
8265   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8266     {
8267       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8268       if(eltToConv)
8269         {
8270           const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(eltToConv);
8271           if(!eltToConvC)
8272             throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !");
8273           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToInt();
8274           ret->setIteration(i,elt);
8275         }
8276     }
8277   return ret.retn();
8278 }
8279
8280 //= MEDFileAnyTypeFieldMultiTS
8281
8282 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS()
8283 {
8284 }
8285
8286 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8287 try:MEDFileFieldGlobsReal(fid)
8288 {
8289   _content=BuildContentFrom(fid,loadAll,ms);
8290   loadGlobals(fid);
8291 }
8292 catch(INTERP_KERNEL::Exception& e)
8293 {
8294     throw e;
8295 }
8296
8297 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8298 {
8299   med_field_type typcha;
8300   std::vector<std::string> infos;
8301   std::string dtunit;
8302   int i(-1);
8303   MEDFileAnyTypeField1TS::LocateField(fid,fieldName,i,typcha,infos,dtunit);
8304   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8305   switch(typcha)
8306   {
8307     case MED_FLOAT64:
8308       {
8309         ret=new MEDFileFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8310         break;
8311       }
8312     case MED_INT32:
8313       {
8314         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
8315         break;
8316       }
8317     default:
8318       {
8319         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] !";
8320         throw INTERP_KERNEL::Exception(oss.str());
8321       }
8322   }
8323   ret->setDtUnit(dtunit.c_str());
8324   return ret.retn();
8325 }
8326
8327 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
8328 {
8329   med_field_type typcha;
8330   //
8331   std::vector<std::string> infos;
8332   std::string dtunit,fieldName;
8333   MEDFileAnyTypeField1TS::LocateField2(fid,0,true,fieldName,typcha,infos,dtunit);
8334   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> ret;
8335   switch(typcha)
8336   {
8337     case MED_FLOAT64:
8338       {
8339         ret=new MEDFileFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8340         break;
8341       }
8342     case MED_INT32:
8343       {
8344         ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
8345         break;
8346       }
8347     default:
8348       {
8349         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] !";
8350         throw INTERP_KERNEL::Exception(oss.str());
8351       }
8352   }
8353   ret->setDtUnit(dtunit.c_str());
8354   return ret.retn();
8355 }
8356
8357 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c)
8358 {
8359   if(!c)
8360     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : empty content in input : unable to build a new instance !");
8361   if(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(c))
8362     {
8363       MCAuto<MEDFileFieldMultiTS> ret(MEDFileFieldMultiTS::New());
8364       ret->_content=c;  c->incrRef();
8365       return ret.retn();
8366     }
8367   if(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(c))
8368     {
8369       MCAuto<MEDFileIntFieldMultiTS> ret(MEDFileIntFieldMultiTS::New());
8370       ret->_content=c;  c->incrRef();
8371       return ret.retn();
8372     }
8373   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
8374 }
8375
8376 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
8377 {
8378   MEDFileAnyTypeFieldMultiTS *ret(BuildNewInstanceFromContent(c));
8379   std::string fileName(FileNameFromFID(fid));
8380   ret->setFileName(fileName);
8381   return ret;
8382 }
8383
8384 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8385 try:MEDFileFieldGlobsReal(fid)
8386 {
8387   _content=BuildContentFrom(fid,fieldName,loadAll,ms,entities);
8388   loadGlobals(fid);
8389 }
8390 catch(INTERP_KERNEL::Exception& e)
8391 {
8392     throw e;
8393 }
8394
8395 //= MEDFileIntFieldMultiTSWithoutSDA
8396
8397 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)
8398 {
8399   return new MEDFileIntFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities);
8400 }
8401
8402 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA()
8403 {
8404 }
8405
8406 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(const std::string& fieldName):MEDFileAnyTypeFieldMultiTSWithoutSDA(fieldName)
8407 {
8408 }
8409
8410 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)
8411 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities)
8412 {
8413 }
8414 catch(INTERP_KERNEL::Exception& e)
8415 { throw e; }
8416
8417 /*!
8418  * \param [in] fieldId field id in C mode
8419  */
8420 MEDFileIntFieldMultiTSWithoutSDA::MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, int fieldId, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
8421 try:MEDFileAnyTypeFieldMultiTSWithoutSDA(fid,fieldId,loadAll,ms,entities)
8422 {
8423 }
8424 catch(INTERP_KERNEL::Exception& e)
8425 { throw e; }
8426
8427 MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew1TSWithoutSDAEmptyInstance() const
8428 {
8429   return new MEDFileIntField1TSWithoutSDA;
8430 }
8431
8432 void MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType(const MEDFileAnyTypeField1TSWithoutSDA *f1ts) const
8433 {
8434   if(!f1ts)
8435     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
8436   const MEDFileIntField1TSWithoutSDA *f1tsC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(f1ts);
8437   if(!f1tsC)
8438     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::checkCoherencyOfType : the input field1TS is not a INT32 type !");
8439 }
8440
8441 const char *MEDFileIntFieldMultiTSWithoutSDA::getTypeStr() const
8442 {
8443   return MEDFileIntField1TSWithoutSDA::TYPE_STR;
8444 }
8445
8446 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::shallowCpy() const
8447 {
8448   return new MEDFileIntFieldMultiTSWithoutSDA(*this);
8449 }
8450
8451 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNew() const
8452 {
8453   return new MEDFileIntFieldMultiTSWithoutSDA;
8454 }
8455
8456 MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const
8457 {
8458   MCAuto<MEDFileFieldMultiTSWithoutSDA> ret(new MEDFileFieldMultiTSWithoutSDA);
8459   ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this);
8460   int i=0;
8461   for(std::vector< MCAuto<MEDFileAnyTypeField1TSWithoutSDA> >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++)
8462     {
8463       const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it);
8464       if(eltToConv)
8465         {
8466           const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(eltToConv);
8467           if(!eltToConvC)
8468             throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !");
8469           MCAuto<MEDFileAnyTypeField1TSWithoutSDA> elt=eltToConvC->convertToDouble();
8470           ret->setIteration(i,elt);
8471         }
8472     }
8473   return ret.retn();
8474 }
8475
8476 //= MEDFileAnyTypeFieldMultiTS
8477
8478 /*!
8479  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of the first field
8480  * that has been read from a specified MED file.
8481  *  \param [in] fileName - the name of the MED file to read.
8482  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8483  *          is to delete this field using decrRef() as it is no more needed.
8484  *  \throw If reading the file fails.
8485  */
8486 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, bool loadAll)
8487 {
8488   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8489   return New(fid,loadAll);
8490 }
8491
8492 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, bool loadAll)
8493 {
8494   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,loadAll,0));
8495   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8496   ret->loadGlobals(fid);
8497   return ret.retn();
8498 }
8499
8500 /*!
8501  * Returns a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS holding data of a given field
8502  * that has been read from a specified MED file.
8503  *  \param [in] fileName - the name of the MED file to read.
8504  *  \param [in] fieldName - the name of the field to read.
8505  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS or MEDFileIntFieldMultiTS. The caller
8506  *          is to delete this field using decrRef() as it is no more needed.
8507  *  \throw If reading the file fails.
8508  *  \throw If there is no field named \a fieldName in the file.
8509  */
8510 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
8511 {
8512   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
8513   return New(fid,fieldName,loadAll);
8514 }
8515
8516 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
8517 {
8518   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c(BuildContentFrom(fid,fieldName,loadAll,0,0));
8519   MCAuto<MEDFileAnyTypeFieldMultiTS> ret(BuildNewInstanceFromContent(c,fid));
8520   ret->loadGlobals(fid);
8521   return ret.retn();
8522 }
8523
8524 /*!
8525  * This constructor is a shallow copy constructor. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
8526  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
8527  *
8528  * \warning this is a shallow copy constructor
8529  */
8530 MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS(const MEDFileAnyTypeFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
8531 {
8532   if(!shallowCopyOfContent)
8533     {
8534       const MEDFileAnyTypeFieldMultiTSWithoutSDA *otherPtr(&other);
8535       otherPtr->incrRef();
8536       _content=const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(otherPtr);
8537     }
8538   else
8539     {
8540       _content=other.shallowCpy();
8541     }
8542 }
8543
8544 MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase()
8545 {
8546   MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8547   if(!ret)
8548     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : content is expected to be not null !");
8549   return ret;
8550 }
8551
8552 const MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTS::contentNotNullBase() const
8553 {
8554   const MEDFileAnyTypeFieldMultiTSWithoutSDA *ret=_content;
8555   if(!ret)
8556     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS : const content is expected to be not null !");
8557   return ret;
8558 }
8559
8560 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsed() const
8561 {
8562   return contentNotNullBase()->getPflsReallyUsed2();
8563 }
8564
8565 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsed() const
8566 {
8567   return contentNotNullBase()->getLocsReallyUsed2();
8568 }
8569
8570 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getPflsReallyUsedMulti() const
8571 {
8572   return contentNotNullBase()->getPflsReallyUsedMulti2();
8573 }
8574
8575 std::vector<std::string> MEDFileAnyTypeFieldMultiTS::getLocsReallyUsedMulti() const
8576 {
8577   return contentNotNullBase()->getLocsReallyUsedMulti2();
8578 }
8579
8580 void MEDFileAnyTypeFieldMultiTS::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8581 {
8582   contentNotNullBase()->changePflsRefsNamesGen2(mapOfModif);
8583 }
8584
8585 void MEDFileAnyTypeFieldMultiTS::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
8586 {
8587   contentNotNullBase()->changeLocsRefsNamesGen2(mapOfModif);
8588 }
8589
8590 int MEDFileAnyTypeFieldMultiTS::getNumberOfTS() const
8591 {
8592   return contentNotNullBase()->getNumberOfTS();
8593 }
8594
8595 void MEDFileAnyTypeFieldMultiTS::eraseEmptyTS()
8596 {
8597   contentNotNullBase()->eraseEmptyTS();
8598 }
8599
8600 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds(const int *startIds, const int *endIds)
8601 {
8602   contentNotNullBase()->eraseTimeStepIds(startIds,endIds);
8603 }
8604
8605 void MEDFileAnyTypeFieldMultiTS::eraseTimeStepIds2(int bg, int end, int step)
8606 {
8607   contentNotNullBase()->eraseTimeStepIds2(bg,end,step);
8608 }
8609
8610 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPart(const int *startIds, const int *endIds) const
8611 {
8612   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds(startIds,endIds);
8613   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8614   ret->_content=c;
8615   return ret.retn();
8616 }
8617
8618 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::buildSubPartSlice(int bg, int end, int step) const
8619 {
8620   MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> c=contentNotNullBase()->buildFromTimeStepIds2(bg,end,step);
8621   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8622   ret->_content=c;
8623   return ret.retn();
8624 }
8625
8626 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getIterations() const
8627 {
8628   return contentNotNullBase()->getIterations();
8629 }
8630
8631 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(const std::vector<MEDFileAnyTypeField1TS *>& f1ts)
8632 {
8633   for(std::vector<MEDFileAnyTypeField1TS *>::const_iterator it=f1ts.begin();it!=f1ts.end();it++)
8634     pushBackTimeStep(*it);
8635 }
8636
8637 void MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps(MEDFileAnyTypeFieldMultiTS *fmts)
8638 {
8639   if(!fmts)
8640     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::pushBackTimeSteps : Input fmts is NULL !");
8641   int nbOfTS(fmts->getNumberOfTS());
8642   for(int i=0;i<nbOfTS;i++)
8643     {
8644       MCAuto<MEDFileAnyTypeField1TS> elt(fmts->getTimeStepAtPos(i));
8645       pushBackTimeStep(elt);
8646     }
8647 }
8648
8649 void MEDFileAnyTypeFieldMultiTS::pushBackTimeStep(MEDFileAnyTypeField1TS *f1ts)
8650 {
8651   if(!f1ts)
8652     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : input pointer is NULL !");
8653   checkCoherencyOfType(f1ts);
8654   f1ts->incrRef();
8655   MCAuto<MEDFileAnyTypeField1TS> f1tsSafe(f1ts);
8656   MEDFileAnyTypeField1TSWithoutSDA *c=f1ts->contentNotNullBase();
8657   c->incrRef();
8658   MCAuto<MEDFileAnyTypeField1TSWithoutSDA> cSafe(c);
8659   if(!((MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content))
8660     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::pushBackTimeStep : no content in this !");
8661   _content->pushBackTimeStep(cSafe);
8662   appendGlobs(*f1ts,1e-12);
8663 }
8664
8665 void MEDFileAnyTypeFieldMultiTS::synchronizeNameScope()
8666 {
8667   contentNotNullBase()->synchronizeNameScope();
8668 }
8669
8670 int MEDFileAnyTypeFieldMultiTS::getPosOfTimeStep(int iteration, int order) const
8671 {
8672   return contentNotNullBase()->getPosOfTimeStep(iteration,order);
8673 }
8674
8675 int MEDFileAnyTypeFieldMultiTS::getPosGivenTime(double time, double eps) const
8676 {
8677   return contentNotNullBase()->getPosGivenTime(time,eps);
8678 }
8679
8680 int MEDFileAnyTypeFieldMultiTS::getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector<int>& levs) const
8681 {
8682   return contentNotNullBase()->getNonEmptyLevels(iteration,order,mname,levs);
8683 }
8684
8685 std::vector< std::vector<TypeOfField> > MEDFileAnyTypeFieldMultiTS::getTypesOfFieldAvailable() const
8686 {
8687   return contentNotNullBase()->getTypesOfFieldAvailable();
8688 }
8689
8690 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
8691 {
8692   return contentNotNullBase()->getFieldSplitedByType(iteration,order,mname,types,typesF,pfls,locs);
8693 }
8694
8695 std::string MEDFileAnyTypeFieldMultiTS::getName() const
8696 {
8697   return contentNotNullBase()->getName();
8698 }
8699
8700 void MEDFileAnyTypeFieldMultiTS::setName(const std::string& name)
8701 {
8702   contentNotNullBase()->setName(name);
8703 }
8704
8705 std::string MEDFileAnyTypeFieldMultiTS::getDtUnit() const
8706 {
8707   return contentNotNullBase()->getDtUnit();
8708 }
8709
8710 void MEDFileAnyTypeFieldMultiTS::setDtUnit(const std::string& dtUnit)
8711 {
8712   contentNotNullBase()->setDtUnit(dtUnit);
8713 }
8714
8715 void MEDFileAnyTypeFieldMultiTS::simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const
8716 {
8717   contentNotNullBase()->simpleRepr(bkOffset,oss,fmtsId);
8718 }
8719
8720 std::vector< std::pair<int,int> > MEDFileAnyTypeFieldMultiTS::getTimeSteps(std::vector<double>& ret1) const
8721 {
8722   return contentNotNullBase()->getTimeSteps(ret1);
8723 }
8724
8725 std::string MEDFileAnyTypeFieldMultiTS::getMeshName() const
8726 {
8727   return contentNotNullBase()->getMeshName();
8728 }
8729
8730 void MEDFileAnyTypeFieldMultiTS::setMeshName(const std::string& newMeshName)
8731 {
8732   contentNotNullBase()->setMeshName(newMeshName);
8733 }
8734
8735 bool MEDFileAnyTypeFieldMultiTS::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
8736 {
8737   return contentNotNullBase()->changeMeshNames(modifTab);
8738 }
8739
8740 const std::vector<std::string>& MEDFileAnyTypeFieldMultiTS::getInfo() const
8741 {
8742   return contentNotNullBase()->getInfo();
8743 }
8744
8745 bool MEDFileAnyTypeFieldMultiTS::presenceOfMultiDiscPerGeoType() const
8746 {
8747   return contentNotNullBase()->presenceOfMultiDiscPerGeoType();
8748 }
8749
8750 void MEDFileAnyTypeFieldMultiTS::setInfo(const std::vector<std::string>& info)
8751 {
8752   return contentNotNullBase()->setInfo(info);
8753 }
8754
8755 int MEDFileAnyTypeFieldMultiTS::getNumberOfComponents() const
8756 {
8757   const std::vector<std::string> ret=getInfo();
8758   return (int)ret.size();
8759 }
8760
8761 void MEDFileAnyTypeFieldMultiTS::writeLL(med_idt fid) const
8762 {
8763   writeGlobals(fid,*this);
8764   contentNotNullBase()->writeLL(fid,*this);
8765 }
8766
8767 /*!
8768  * This method alloc the arrays and load potentially huge arrays contained in this field.
8769  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
8770  * This method can be also called to refresh or reinit values from a file.
8771  * 
8772  * \throw If the fileName is not set or points to a non readable MED file.
8773  */
8774 void MEDFileAnyTypeFieldMultiTS::loadArrays()
8775 {
8776   if(getFileName().empty())
8777     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::loadArrays : the structure does not come from a file !");
8778   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8779   contentNotNullBase()->loadBigArraysRecursively(fid,*contentNotNullBase());
8780 }
8781
8782 /*!
8783  * This method behaves as MEDFileAnyTypeFieldMultiTS::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
8784  * But once data loaded once, this method does nothing.
8785  * 
8786  * \throw If the fileName is not set or points to a non readable MED file.
8787  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::unloadArrays
8788  */
8789 void MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary()
8790 {
8791   if(!getFileName().empty())
8792     {
8793       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
8794       contentNotNullBase()->loadBigArraysRecursivelyIfNecessary(fid,*contentNotNullBase());
8795     }
8796 }
8797
8798 /*!
8799  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
8800  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
8801  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss instead.
8802  * 
8803  * \sa MEDFileAnyTypeFieldMultiTS::loadArrays, MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary, MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss
8804  */
8805 void MEDFileAnyTypeFieldMultiTS::unloadArrays()
8806 {
8807   contentNotNullBase()->unloadArrays();
8808 }
8809
8810 /*!
8811  * 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.
8812  * This method is the symetrical method of MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary.
8813  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
8814  * 
8815  * \sa MEDFileAnyTypeFieldMultiTS::loadArraysIfNecessary
8816  */
8817 void MEDFileAnyTypeFieldMultiTS::unloadArraysWithoutDataLoss()
8818 {
8819   if(!getFileName().empty())
8820     contentNotNullBase()->unloadArrays();
8821 }
8822
8823 std::string MEDFileAnyTypeFieldMultiTS::simpleRepr() const
8824 {
8825   std::ostringstream oss;
8826   contentNotNullBase()->simpleRepr(0,oss,-1);
8827   simpleReprGlobs(oss);
8828   return oss.str();
8829 }
8830
8831 std::size_t MEDFileAnyTypeFieldMultiTS::getHeapMemorySizeWithoutChildren() const
8832 {
8833   return MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren();
8834 }
8835
8836 std::vector<const BigMemoryObject *> MEDFileAnyTypeFieldMultiTS::getDirectChildrenWithNull() const
8837 {
8838   std::vector<const BigMemoryObject *> ret(MEDFileFieldGlobsReal::getDirectChildrenWithNull());
8839   ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content);
8840   return ret;
8841 }
8842
8843 /*!
8844  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of components in \a this.
8845  * The returned instances are deep copy of \a this except that for globals that are share with those contained in \a this.
8846  * ** WARNING ** do no forget to rename the ouput instances to avoid to write n-times in the same MED file field !
8847  */
8848 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitComponents() const
8849 {
8850   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8851   if(!content)
8852     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitComponents : no content in this ! Unable to split components !");
8853   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit=content->splitComponents();
8854   std::size_t sz(contentsSplit.size());
8855   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8856   for(std::size_t i=0;i<sz;i++)
8857     {
8858       ret[i]=shallowCpy();
8859       ret[i]->_content=contentsSplit[i];
8860     }
8861   return ret;
8862 }
8863
8864 /*!
8865  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of discretizations over time steps in \a this.
8866  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8867  */
8868 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitDiscretizations() const
8869 {
8870   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8871   if(!content)
8872     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitDiscretizations : no content in this ! Unable to split discretizations !");
8873   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitDiscretizations());
8874   std::size_t sz(contentsSplit.size());
8875   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8876   for(std::size_t i=0;i<sz;i++)
8877     {
8878       ret[i]=shallowCpy();
8879       ret[i]->_content=contentsSplit[i];
8880     }
8881   return ret;
8882 }
8883
8884 /*!
8885  * This method returns as MEDFileAnyTypeFieldMultiTS new instances as number of sub-discretizations over time steps in \a this.
8886  * The returned instances are shallow copied of \a this included globals that are share with those contained in \a this.
8887  */
8888 std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes() const
8889 {
8890   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
8891   if(!content)
8892     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::splitMultiDiscrPerGeoTypes : no content in this ! Unable to split discretizations !");
8893   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > contentsSplit(content->splitMultiDiscrPerGeoTypes());
8894   std::size_t sz(contentsSplit.size());
8895   std::vector< MCAuto< MEDFileAnyTypeFieldMultiTS > > ret(sz);
8896   for(std::size_t i=0;i<sz;i++)
8897     {
8898       ret[i]=shallowCpy();
8899       ret[i]->_content=contentsSplit[i];
8900     }
8901   return ret;
8902 }
8903
8904 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::deepCopy() const
8905 {
8906   MCAuto<MEDFileAnyTypeFieldMultiTS> ret=shallowCpy();
8907   if((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)_content)
8908     ret->_content=_content->deepCopy();
8909   ret->deepCpyGlobs(*this);
8910   return ret.retn();
8911 }
8912
8913 MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> MEDFileAnyTypeFieldMultiTS::getContent()
8914 {
8915   return _content;
8916 }
8917
8918 /*!
8919  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8920  *  \param [in] iteration - the iteration number of a required time step.
8921  *  \param [in] order - the iteration order number of required time step.
8922  *  \return MEDFileField1TS * or MEDFileIntField1TS *- a new instance of MEDFileField1TS or MEDFileIntField1TS. The caller is to
8923  *          delete this field using decrRef() as it is no more needed.
8924  *  \throw If there is no required time step in \a this field.
8925  */
8926 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStep(int iteration, int order) const
8927 {
8928   int pos=getPosOfTimeStep(iteration,order);
8929   return getTimeStepAtPos(pos);
8930 }
8931
8932 /*!
8933  * Returns a new MEDFileField1TS or MEDFileIntField1TS holding data of a given time step of \a this field.
8934  *  \param [in] time - the time of the time step of interest.
8935  *  \param [in] eps - a precision used to compare time values.
8936  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
8937  *          delete this field using decrRef() as it is no more needed.
8938  *  \throw If there is no required time step in \a this field.
8939  */
8940 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double time, double eps) const
8941 {
8942   int pos=getPosGivenTime(time,eps);
8943   return getTimeStepAtPos(pos);
8944 }
8945
8946 /*!
8947  * 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.
8948  * The float64 value of time attached to the pair of integers are not considered here.
8949  * WARNING the returned pointers are not incremented. The caller is \b not responsible to deallocate them ! This method only reorganizes entries in \a vectFMTS.
8950  *
8951  * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer.
8952  * \throw If there is a null pointer in \a vectFMTS.
8953  */
8954 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS)
8955 {
8956   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !";
8957   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
8958   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
8959   while(!lstFMTS.empty())
8960     {
8961       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
8962       MEDFileAnyTypeFieldMultiTS *curIt(*it);
8963       if(!curIt)
8964         throw INTERP_KERNEL::Exception(msg);
8965       std::vector< std::pair<int,int> > refIts=curIt->getIterations();
8966       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
8967       elt.push_back(curIt); it=lstFMTS.erase(it);
8968       while(it!=lstFMTS.end())
8969         {
8970           curIt=*it;
8971           if(!curIt)
8972             throw INTERP_KERNEL::Exception(msg);
8973           std::vector< std::pair<int,int> > curIts=curIt->getIterations();
8974           if(refIts==curIts)
8975             { elt.push_back(curIt); it=lstFMTS.erase(it); }
8976           else
8977             it++;
8978         }
8979       ret.push_back(elt);
8980     }
8981   return ret;
8982 }
8983
8984 /*!
8985  * This method splits the input list \a vectFMTS considering the aspect of the geometrical support over time.
8986  * All returned instances in a subvector can be safely loaded, rendered along time
8987  * All items must be defined on the same time step ids ( see MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries method ).
8988  * Each item in \a vectFMTS is expected to have one and exactly one spatial discretization along time.
8989  * 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).
8990  * All items in \a vectFMTS whose spatial discretization is not ON_NODES will appear once.
8991  * 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.
8992  *
8993  * \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().
8994  * \param [in] mesh - the mesh shared by all items in \a vectFMTS across time.
8995  * \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.
8996  * \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.
8997  *
8998  * \throw If an element in \a vectFMTS has not only one spatial discretization set.
8999  * \throw If an element in \a vectFMTS change of spatial discretization along time.
9000  * \throw If an element in \a vectFMTS lies on a mesh with meshname different from those in \a mesh.
9001  * \thorw If some elements in \a vectFMTS do not have the same times steps.
9002  * \throw If mesh is null.
9003  * \throw If an element in \a vectFMTS is null.
9004  * \sa MEDFileAnyTypeFieldMultiTS::AreOnSameSupportAcrossTime
9005  */
9006 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& fsc)
9007 {
9008   static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : presence of a null instance in the input vector !";
9009   if(!mesh)
9010     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : input mesh is null !");
9011   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9012   if(vectFMTS.empty())
9013     return ret;
9014   std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it(vectFMTS.begin());
9015   MEDFileAnyTypeFieldMultiTS *frstElt(*it);
9016   if(!frstElt)
9017     throw INTERP_KERNEL::Exception(msg);
9018   std::size_t i=0;
9019   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNotNodes;
9020   std::vector<MEDFileAnyTypeFieldMultiTS *> vectFMTSNodes;
9021   for(;it!=vectFMTS.end();it++,i++)
9022     {
9023       if(!(*it))
9024         throw INTERP_KERNEL::Exception(msg);
9025       TypeOfField tof0,tof1;
9026       if(CheckSupportAcrossTime(frstElt,*it,mesh,tof0,tof1)>0)
9027         {
9028           if(tof1!=ON_NODES)
9029             vectFMTSNotNodes.push_back(*it);
9030           else
9031             vectFMTSNodes.push_back(*it);
9032         }
9033       else
9034         vectFMTSNotNodes.push_back(*it);
9035     }
9036   std::vector< MCAuto<MEDFileFastCellSupportComparator> > cmps;
9037   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > retCell=SplitPerCommonSupportNotNodesAlg(vectFMTSNotNodes,mesh,cmps);
9038   ret=retCell;
9039   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++)
9040     {
9041       i=0;
9042       bool isFetched(false);
9043       for(std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++)
9044         {
9045           if((*it0).empty())
9046             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport : internal error !");
9047           if(cmps[i]->isCompatibleWithNodesDiscr(*it2))
9048             { ret[i].push_back(*it2); isFetched=true; }
9049         }
9050       if(!isFetched)
9051         {
9052           std::vector<MEDFileAnyTypeFieldMultiTS *> tmp(1,*it2);
9053           MCAuto<MEDFileMeshStruct> tmp2(MEDFileMeshStruct::New(mesh));
9054           ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2));
9055         }
9056     }
9057   fsc=cmps;
9058   return ret;
9059 }
9060
9061 /*!
9062  * 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.
9063  * \param [out] cmps - same size than the returned vector.
9064  */
9065 std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupportNotNodesAlg(const std::vector<MEDFileAnyTypeFieldMultiTS *>& vectFMTS, const MEDFileMesh *mesh, std::vector< MCAuto<MEDFileFastCellSupportComparator> >& cmps)
9066 {
9067   std::vector< std::vector<MEDFileAnyTypeFieldMultiTS *> > ret;
9068   std::list<MEDFileAnyTypeFieldMultiTS *> lstFMTS(vectFMTS.begin(),vectFMTS.end());
9069   while(!lstFMTS.empty())
9070     {
9071       std::list<MEDFileAnyTypeFieldMultiTS *>::iterator it(lstFMTS.begin());
9072       MEDFileAnyTypeFieldMultiTS *ref(*it);
9073       std::vector<MEDFileAnyTypeFieldMultiTS *> elt;
9074       elt.push_back(ref); it=lstFMTS.erase(it);
9075       MCAuto<MEDFileMeshStruct> mst(MEDFileMeshStruct::New(mesh));
9076       MCAuto<MEDFileFastCellSupportComparator> cmp(MEDFileFastCellSupportComparator::New(mst,ref));
9077       while(it!=lstFMTS.end())
9078         {
9079           MEDFileAnyTypeFieldMultiTS *curIt(*it);
9080           if(cmp->isEqual(curIt))
9081             { elt.push_back(curIt); it=lstFMTS.erase(it); }
9082           else
9083             it++;
9084         }
9085       ret.push_back(elt); cmps.push_back(cmp);
9086     }
9087   return ret;
9088 }
9089
9090 /*!
9091  * 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.
9092  * \a f0 and \a f1 must be defined each only on a same spatial discretization even if this can be different each other.
9093  *
9094  * \throw If \a f0 or \a f1 has not only one spatial discretization set.
9095  * \throw If \a f0 or \a f1 change of spatial discretization along time.
9096  * \throw If \a f0 or \a f1 on a mesh with meshname different from those in \a mesh.
9097  * \thorw If \a f0 and \a f1 do not have the same times steps.
9098  * \throw If mesh is null.
9099  * \throw If \a f0 or \a f1 is null.
9100  * \sa MEDFileAnyTypeFieldMultiTS::SplitPerCommonSupport
9101  */
9102 int MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime(MEDFileAnyTypeFieldMultiTS *f0, MEDFileAnyTypeFieldMultiTS *f1, const MEDFileMesh *mesh, TypeOfField& tof0, TypeOfField& tof1)
9103 {
9104   if(!mesh)
9105     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : input mesh is null !");
9106   if(!f0 || !f1)
9107     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : presence of null instance in fields over time !");
9108   if(f0->getMeshName()!=mesh->getName())
9109     {
9110       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : first field points to mesh \""<< f0->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9111       throw INTERP_KERNEL::Exception(oss.str());
9112     }
9113   if(f1->getMeshName()!=mesh->getName())
9114     {
9115       std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : second field points to mesh \""<< f1->getMeshName() << "\" and input mesh to compare has name \"" << mesh->getName() << "\" !";
9116       throw INTERP_KERNEL::Exception(oss.str());
9117     }
9118   int nts=f0->getNumberOfTS();
9119   if(nts!=f1->getNumberOfTS())
9120     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : number of time steps are not the same !");
9121   if(nts==0)
9122     return nts;
9123   for(int i=0;i<nts;i++)
9124     {
9125       MCAuto<MEDFileAnyTypeField1TS> f0cur=f0->getTimeStepAtPos(i);
9126       MCAuto<MEDFileAnyTypeField1TS> f1cur=f1->getTimeStepAtPos(i);
9127       std::vector<TypeOfField> tofs0(f0cur->getTypesOfFieldAvailable()),tofs1(f1cur->getTypesOfFieldAvailable());
9128       if(tofs0.size()!=1 || tofs1.size()!=1)
9129         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : All time steps must be defined on only one spatial discretization !");
9130       if(i!=0)
9131         {
9132           if(tof0!=tofs0[0] || tof1!=tofs1[0])
9133             throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::CheckSupportAcrossTime : Across times steps MEDFileAnyTypeFieldMultiTS instances have to keep the same unique spatial discretization !");
9134         }
9135       else
9136         { tof0=tofs0[0]; tof1=tofs1[0]; }
9137       if(f0cur->getMeshIteration()!=mesh->getIteration() || f0cur->getMeshOrder()!=mesh->getOrder())
9138         {
9139           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() << ") !";
9140           throw INTERP_KERNEL::Exception(oss.str());
9141         }
9142       if(f1cur->getMeshIteration()!=mesh->getIteration() || f1cur->getMeshOrder()!=mesh->getOrder())
9143         {
9144           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() << ") !";
9145           throw INTERP_KERNEL::Exception(oss.str());
9146         }
9147       if(f0cur->getIteration()!=f1cur->getIteration() || f0cur->getOrder()!=f1cur->getOrder())
9148         {
9149           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() << ") !";
9150           throw INTERP_KERNEL::Exception(oss.str());
9151         }
9152     }
9153   return nts;
9154 }
9155
9156 /*!
9157  * Return an extraction of \a this using \a extractDef map to specify the extraction.
9158  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
9159  *
9160  * \return A new object that the caller is responsible to deallocate.
9161  */
9162 MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
9163 {
9164   if(!mm)
9165     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::extractPart : mesh is null !");
9166   MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(buildNewEmpty());
9167   int nbTS(getNumberOfTS());
9168   for(int i=0;i<nbTS;i++)
9169     {
9170       MCAuto<MEDFileAnyTypeField1TS> f1ts(getTimeStepAtPos(i));
9171       MCAuto<MEDFileAnyTypeField1TS> f1tsOut(f1ts->extractPart(extractDef,mm));
9172       fmtsOut->pushBackTimeStep(f1tsOut);
9173     }
9174   return fmtsOut.retn();
9175 }
9176
9177 template<class T>
9178 MCAuto<MEDFileAnyTypeField1TS> AggregateHelperF1TS(const std::vector< typename MLFieldTraits<T>::F1TSType const *>& f1tss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9179 {
9180   MCAuto< typename MLFieldTraits<T>::F1TSType > ret(MLFieldTraits<T>::F1TSType::New());
9181   if(f1tss.empty())
9182     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : empty vector !");
9183   std::size_t sz(f1tss.size()),i(0);
9184   std::vector< typename MLFieldTraits<T>::F1TSWSDAType const *> f1tsw(sz);
9185   for(typename std::vector< typename MLFieldTraits<T>::F1TSType const *>::const_iterator it=f1tss.begin();it!=f1tss.end();it++,i++)
9186     {
9187       typename MLFieldTraits<T>::F1TSType const *elt(*it);
9188       if(!elt)
9189         throw INTERP_KERNEL::Exception("AggregateHelperF1TS : presence of a null pointer !");
9190       f1tsw[i]=dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType const *>(elt->contentNotNullBase());
9191     }
9192   typename MLFieldTraits<T>::F1TSWSDAType *retc(dynamic_cast<typename MLFieldTraits<T>::F1TSWSDAType *>(ret->contentNotNullBase()));
9193   if(!retc)
9194     throw INTERP_KERNEL::Exception("AggregateHelperF1TS : internal error 1 !");
9195   retc->aggregate(f1tsw,dts);
9196   ret->setDtUnit(f1tss[0]->getDtUnit());
9197   return DynamicCast<typename MLFieldTraits<T>::F1TSType , MEDFileAnyTypeField1TS>(ret);
9198 }
9199
9200 template<class T>
9201 MCAuto< MEDFileAnyTypeFieldMultiTS > AggregateHelperFMTS(const std::vector< typename MLFieldTraits<T>::FMTSType const *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9202 {
9203   MCAuto< typename MLFieldTraits<T>::FMTSType > ret(MLFieldTraits<T>::FMTSType::New());
9204   if(fmtss.empty())
9205     throw INTERP_KERNEL::Exception("AggregateHelperFMTS : empty vector !");
9206   std::size_t sz(fmtss.size());
9207   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9208     {
9209       typename MLFieldTraits<T>::FMTSType const *elt(*it);
9210       if(!elt)
9211         throw INTERP_KERNEL::Exception("AggregateHelperFMTS : presence of null pointer !");
9212     }
9213   int nbTS(fmtss[0]->getNumberOfTS());
9214   for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9215     if((*it)->getNumberOfTS()!=nbTS)
9216       throw INTERP_KERNEL::Exception("AggregateHelperFMTS : all fields must have the same number of TS !");
9217   for(int iterTS=0;iterTS<nbTS;iterTS++)
9218     {
9219       std::size_t i(0);
9220       std::vector< typename MLFieldTraits<T>::F1TSType const *> f1tss(sz);
9221       std::vector< MCAuto<typename MLFieldTraits<T>::F1TSType> > f1tss2(sz);
9222       for(typename std::vector< typename MLFieldTraits<T>::FMTSType const *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++,i++)
9223         { f1tss2[i]=(*it)->getTimeStepAtPos(iterTS); f1tss[i]=f1tss2[i]; }
9224       MCAuto<MEDFileAnyTypeField1TS> f1ts(AggregateHelperF1TS<T>(f1tss,dts));
9225       ret->pushBackTimeStep(f1ts);
9226       ret->setDtUnit(f1ts->getDtUnit());
9227     }
9228   return DynamicCast<typename MLFieldTraits<T>::FMTSType , MEDFileAnyTypeFieldMultiTS>(ret);
9229 }
9230
9231 /*!
9232  * \a dts and \a ftmss are expected to have same size.
9233  */
9234 MCAuto<MEDFileAnyTypeFieldMultiTS> MEDFileAnyTypeFieldMultiTS::Aggregate(const std::vector<const MEDFileAnyTypeFieldMultiTS *>& fmtss, const std::vector< std::vector< std::pair<int,int> > >& dts)
9235 {
9236   if(fmtss.empty())
9237     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : input vector is empty !");
9238   std::size_t sz(fmtss.size());
9239   std::vector<const MEDFileFieldMultiTS *> fmtss1;
9240   std::vector<const MEDFileIntFieldMultiTS *> fmtss2;
9241   for(std::vector<const MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fmtss.begin();it!=fmtss.end();it++)
9242     {
9243       if(!(*it))
9244         throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : presence of null instance in input vector !");
9245       const MEDFileFieldMultiTS *elt1(dynamic_cast<const MEDFileFieldMultiTS *>(*it));
9246       if(elt1)
9247         {
9248           fmtss1.push_back(elt1);
9249           continue;
9250         }
9251       const MEDFileIntFieldMultiTS *elt2(dynamic_cast<const MEDFileIntFieldMultiTS *>(*it));
9252       if(elt2)
9253         {
9254           fmtss2.push_back(elt2);
9255           continue;
9256         }
9257       throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not recognized type !");
9258     }
9259   if(fmtss1.size()!=sz && fmtss2.size()!=sz)
9260     throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : type of data is not homogeneous !");
9261   if(fmtss1.size()==sz)
9262     return AggregateHelperFMTS<double>(fmtss1,dts);
9263   if(fmtss2.size()!=sz)
9264     return AggregateHelperFMTS<int>(fmtss2,dts);
9265   throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::Aggregate : not implemented yet !");
9266 }
9267
9268 MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator()
9269 {
9270   return new MEDFileAnyTypeFieldMultiTSIterator(this);
9271 }
9272
9273 //= MEDFileFieldMultiTS
9274
9275 /*!
9276  * Returns a new empty instance of MEDFileFieldMultiTS.
9277  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9278  *          is to delete this field using decrRef() as it is no more needed.
9279  */
9280 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New()
9281 {
9282   return new MEDFileFieldMultiTS;
9283 }
9284
9285 /*!
9286  * Returns a new instance of MEDFileFieldMultiTS holding data of the first field
9287  * that has been read from a specified MED file.
9288  *  \param [in] fileName - the name of the MED file to read.
9289  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9290  *          is to delete this field using decrRef() as it is no more needed.
9291  *  \throw If reading the file fails.
9292  */
9293 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, bool loadAll)
9294 {
9295   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9296   return New(fid,loadAll);
9297 }
9298
9299 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, bool loadAll)
9300 {
9301   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,loadAll,0));
9302   ret->contentNotNull();//to check that content type matches with \a this type.
9303   return ret.retn();
9304 }
9305
9306 /*!
9307  * Returns a new instance of MEDFileFieldMultiTS holding data of a given field
9308  * that has been read from a specified MED file.
9309  *  \param [in] fileName - the name of the MED file to read.
9310  *  \param [in] fieldName - the name of the field to read.
9311  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9312  *          is to delete this field using decrRef() as it is no more needed.
9313  *  \throw If reading the file fails.
9314  *  \throw If there is no field named \a fieldName in the file.
9315  */
9316 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9317 {
9318   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9319   return New(fid,fieldName,loadAll);
9320 }
9321
9322 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9323 {
9324   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0));
9325   ret->contentNotNull();//to check that content type matches with \a this type.
9326   return ret.retn();
9327 }
9328
9329 /*!
9330  * Returns a new instance of MEDFileFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9331  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9332  *
9333  * Returns a new instance of MEDFileFieldMultiTS holding either a shallow copy
9334  * of a given MEDFileFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9335  * \warning this is a shallow copy constructor
9336  *  \param [in] other - a MEDFileField1TSWithoutSDA to copy.
9337  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9338  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileFieldMultiTS. The caller
9339  *          is to delete this field using decrRef() as it is no more needed.
9340  */
9341 MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9342 {
9343   return new MEDFileFieldMultiTS(other,shallowCopyOfContent);
9344 }
9345
9346 MEDFileFieldMultiTS *MEDFileFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9347 {
9348   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9349   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9350   MCAuto<MEDFileFieldMultiTS> ret(new MEDFileFieldMultiTS(fid,fieldName,loadAll,0,ent));
9351   ret->contentNotNull();//to check that content type matches with \a this type.
9352   return ret.retn();
9353 }
9354
9355 MEDFileAnyTypeFieldMultiTS *MEDFileFieldMultiTS::shallowCpy() const
9356 {
9357   return new MEDFileFieldMultiTS(*this);
9358 }
9359
9360 void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9361 {
9362   if(!f1ts)
9363     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9364   const MEDFileField1TS *f1tsC=dynamic_cast<const MEDFileField1TS *>(f1ts);
9365   if(!f1tsC)
9366     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !");
9367 }
9368
9369 /*!
9370  * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied
9371  * following the given input policy.
9372  *
9373  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9374  *                            By default (true) the globals are deeply copied.
9375  * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field.
9376  */
9377 MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool isDeepCpyGlobs) const
9378 {
9379   MCAuto<MEDFileIntFieldMultiTS> ret;
9380   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9381   if(content)
9382     {
9383       const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(content);
9384       if(!contc)
9385         throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !");
9386       MCAuto<MEDFileIntFieldMultiTSWithoutSDA> newc(contc->convertToInt());
9387       ret=static_cast<MEDFileIntFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc));
9388     }
9389   else
9390     ret=MEDFileIntFieldMultiTS::New();
9391   if(isDeepCpyGlobs)
9392     ret->deepCpyGlobs(*this);
9393   else
9394     ret->shallowCpyGlobs(*this);
9395   return ret.retn();
9396 }
9397
9398 /*!
9399  * Returns a new MEDFileField1TS holding data of a given time step of \a this field.
9400  *  \param [in] pos - a time step id.
9401  *  \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller is to
9402  *          delete this field using decrRef() as it is no more needed.
9403  *  \throw If \a pos is not a valid time step id.
9404  */
9405 MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const
9406 {
9407   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
9408   if(!item)
9409     {
9410       std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
9411       throw INTERP_KERNEL::Exception(oss.str());
9412     }
9413   const MEDFileField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(item);
9414   if(itemC)
9415     {
9416       MCAuto<MEDFileField1TS> ret=MEDFileField1TS::New(*itemC,false);
9417       ret->shallowCpyGlobs(*this);
9418       return ret.retn();
9419     }
9420   std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not FLOAT64 !";
9421   throw INTERP_KERNEL::Exception(oss.str());
9422 }
9423
9424 /*!
9425  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9426  * mesh entities of a given dimension of the first mesh in MED file.
9427  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9428  *  \param [in] type - a spatial discretization of interest.
9429  *  \param [in] iteration - the iteration number of a required time step.
9430  *  \param [in] order - the iteration order number of required time step.
9431  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9432  *  \param [in] renumPol - specifies how to permute values of the result field according to
9433  *          the optional numbers of cells and nodes, if any. The valid values are
9434  *          - 0 - do not permute.
9435  *          - 1 - permute cells.
9436  *          - 2 - permute nodes.
9437  *          - 3 - permute cells and nodes.
9438  *
9439  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9440  *          caller is to delete this field using decrRef() as it is no more needed. 
9441  *  \throw If the MED file is not readable.
9442  *  \throw If there is no mesh in the MED file.
9443  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9444  *  \throw If no field values of the required parameters are available.
9445  */
9446 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9447 {
9448   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9449   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9450   if(!myF1TSC)
9451     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting FLOAT64 !");
9452   MCAuto<DataArray> arrOut;
9453   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9454   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9455   return ret.retn();
9456 }
9457
9458 /*!
9459  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9460  * the top level cells of the first mesh in MED file.
9461  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9462  *  \param [in] type - a spatial discretization of interest.
9463  *  \param [in] iteration - the iteration number of a required time step.
9464  *  \param [in] order - the iteration order number of required time step.
9465  *  \param [in] renumPol - specifies how to permute values of the result field according to
9466  *          the optional numbers of cells and nodes, if any. The valid values are
9467  *          - 0 - do not permute.
9468  *          - 1 - permute cells.
9469  *          - 2 - permute nodes.
9470  *          - 3 - permute cells and nodes.
9471  *
9472  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9473  *          caller is to delete this field using decrRef() as it is no more needed. 
9474  *  \throw If the MED file is not readable.
9475  *  \throw If there is no mesh in the MED file.
9476  *  \throw If no field values of the required parameters are available.
9477  */
9478 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9479 {
9480   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9481   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9482   if(!myF1TSC)
9483     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtTopLevel : mismatch of type of field !");
9484   MCAuto<DataArray> arrOut;
9485   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNullBase());
9486   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9487   return ret.retn();
9488 }
9489
9490 /*!
9491  * 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
9492  * method should be called (getFieldOnMeshAtLevel for example).
9493  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9494  *
9495  * \param [in] iteration - the iteration number of a required time step.
9496  * \param [in] order - the iteration order number of required time step.
9497  * \param [in] mesh - the mesh the field is lying on
9498  * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9499  *          caller is to delete this field using decrRef() as it is no more needed. 
9500  */
9501 MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9502 {
9503   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9504   MCAuto<DataArray> arrOut;
9505   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9506   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9507   return ret.retn();
9508 }
9509
9510 /*!
9511  * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on
9512  * a given support.
9513  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9514  *  \param [in] type - a spatial discretization of interest.
9515  *  \param [in] iteration - the iteration number of a required time step.
9516  *  \param [in] order - the iteration order number of required time step.
9517  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9518  *  \param [in] mesh - the supporting mesh.
9519  *  \param [in] renumPol - specifies how to permute values of the result field according to
9520  *          the optional numbers of cells and nodes, if any. The valid values are
9521  *          - 0 - do not permute.
9522  *          - 1 - permute cells.
9523  *          - 2 - permute nodes.
9524  *          - 3 - permute cells and nodes.
9525  *
9526  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9527  *          caller is to delete this field using decrRef() as it is no more needed. 
9528  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9529  *  \throw If no field of \a this is lying on \a mesh.
9530  *  \throw If no field values of the required parameters are available.
9531  */
9532 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
9533 {
9534   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9535   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9536   if(!myF1TSC)
9537     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9538   MCAuto<DataArray> arrOut;
9539   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNullBase());
9540   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9541   return ret.retn();
9542 }
9543
9544 /*!
9545  * Returns a new MEDCouplingFieldDouble of given type, of a given time step, lying on a
9546  * given support. 
9547  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9548  *  \param [in] type - a spatial discretization of the new field.
9549  *  \param [in] iteration - the iteration number of a required time step.
9550  *  \param [in] order - the iteration order number of required time step.
9551  *  \param [in] mesh - the supporting mesh.
9552  *  \param [in] renumPol - specifies how to permute values of the result field according to
9553  *          the optional numbers of cells and nodes, if any. The valid values are
9554  *          - 0 - do not permute.
9555  *          - 1 - permute cells.
9556  *          - 2 - permute nodes.
9557  *          - 3 - permute cells and nodes.
9558  *
9559  *  \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
9560  *          caller is to delete this field using decrRef() as it is no more needed. 
9561  *  \throw If no field of \a this is lying on \a mesh.
9562  *  \throw If no field values of the required parameters are available.
9563  */
9564 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
9565 {
9566   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9567   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9568   if(!myF1TSC)
9569     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !");
9570   MCAuto<DataArray> arrOut;
9571   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNullBase());
9572   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9573   return ret.retn();
9574 }
9575
9576 /*!
9577  * This method has a close behaviour than MEDFileFieldMultiTS::getFieldAtLevel.
9578  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
9579  * This method is useful for MED2 file format when field on different mesh was autorized.
9580  */
9581 MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtLevelOld(TypeOfField type, const std::string& mname, int iteration, int order, int meshDimRelToMax, int renumPol) const
9582 {
9583   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9584   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9585   if(!myF1TSC)
9586     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldAtLevelOld : mismatch of type of field !");
9587   MCAuto<DataArray> arrOut;
9588   MCAuto<MEDCouplingFieldDouble> ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNullBase());
9589   MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut);
9590   return ret.retn();
9591 }
9592
9593 /*!
9594  * Returns values and a profile of the field of a given type, of a given time step,
9595  * lying on a given support.
9596  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9597  *  \param [in] type - a spatial discretization of the field.
9598  *  \param [in] iteration - the iteration number of a required time step.
9599  *  \param [in] order - the iteration order number of required time step.
9600  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9601  *  \param [in] mesh - the supporting mesh.
9602  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
9603  *          field of interest lies on. If the field lies on all entities of the given
9604  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
9605  *          using decrRef() as it is no more needed.  
9606  *  \param [in] glob - the global data storing profiles and localization.
9607  *  \return DataArrayDouble * - a new instance of DataArrayDouble holding values of the
9608  *          field. The caller is to delete this array using decrRef() as it is no more needed.
9609  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9610  *  \throw If no field of \a this is lying on \a mesh.
9611  *  \throw If no field values of the required parameters are available.
9612  */
9613 DataArrayDouble *MEDFileFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
9614 {
9615   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
9616   const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileField1TSWithoutSDA *>(&myF1TS);
9617   if(!myF1TSC)
9618     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldWithProfile : mismatch of type of field !");
9619   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
9620   return MEDFileField1TS::ReturnSafelyDataArrayDouble(ret);
9621 }
9622
9623 const MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull() const
9624 {
9625   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9626   if(!pt)
9627     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the content pointer is null !");
9628   const MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(pt);
9629   if(!ret)
9630     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 !");
9631   return ret;
9632 }
9633
9634 MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTS::contentNotNull()
9635 {
9636   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
9637   if(!pt)
9638     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::contentNotNull : the non const content pointer is null !");
9639   MEDFileFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileFieldMultiTSWithoutSDA *>(pt);
9640   if(!ret)
9641     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 !");
9642   return ret;
9643 }
9644
9645 /*!
9646  * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of
9647  * the given field is checked if its elements are sorted suitable for writing to MED file
9648  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
9649  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9650  *  \param [in] field - the field to add to \a this.
9651  *  \throw If the name of \a field is empty.
9652  *  \throw If the data array of \a field is not set.
9653  *  \throw If existing time steps have different name or number of components than \a field.
9654  *  \throw If the underlying mesh of \a field has no name.
9655  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
9656  */
9657 void MEDFileFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field)
9658 {
9659   const DataArrayDouble *arr=0;
9660   if(field)
9661     arr=field->getArray();
9662   contentNotNull()->appendFieldNoProfileSBT(field,arr,*this);
9663 }
9664
9665 /*!
9666  * Adds a MEDCouplingFieldDouble to \a this as another time step.
9667  * The mesh support of input parameter \a field is ignored here, it can be NULL.
9668  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
9669  * and \a profile.
9670  *
9671  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
9672  * A new profile is added only if no equal profile is missing.
9673  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9674  *  \param [in] field - the field to add to \a this. The mesh support of field is ignored.
9675  *  \param [in] mesh - the supporting mesh of \a field.
9676  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
9677  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
9678  *  \throw If either \a field or \a mesh or \a profile has an empty name.
9679  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
9680  *  \throw If the data array of \a field is not set.
9681  *  \throw If the data array of \a this is already allocated but has different number of
9682  *         components than \a field.
9683  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
9684  *  \sa setFieldNoProfileSBT()
9685  */
9686 void MEDFileFieldMultiTS::appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
9687 {
9688   const DataArrayDouble *arr=0;
9689   if(field)
9690     arr=field->getArray();
9691   contentNotNull()->appendFieldProfile(field,arr,mesh,meshDimRelToMax,profile,*this);
9692 }
9693
9694 MEDFileFieldMultiTS::MEDFileFieldMultiTS()
9695 {
9696   _content=new MEDFileFieldMultiTSWithoutSDA;
9697 }
9698
9699 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
9700 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
9701 {
9702 }
9703 catch(INTERP_KERNEL::Exception& e)
9704 { throw e; }
9705
9706 MEDFileFieldMultiTS::MEDFileFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
9707 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
9708 {
9709 }
9710 catch(INTERP_KERNEL::Exception& e)
9711 { throw e; }
9712
9713 MEDFileFieldMultiTS::MEDFileFieldMultiTS(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
9714 {
9715 }
9716
9717 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
9718 {
9719   return contentNotNull()->getFieldSplitedByType2(iteration,order,mname,types,typesF,pfls,locs);
9720 }
9721
9722 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
9723 {
9724   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArray(iteration,order));
9725 }
9726
9727 DataArrayDouble *MEDFileFieldMultiTS::getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair<std::pair<INTERP_KERNEL::NormalizedCellType,int>,std::pair<int,int> > >& entries) const
9728 {
9729   return static_cast<DataArrayDouble *>(contentNotNull()->getUndergroundDataArrayExt(iteration,order,entries));
9730 }
9731
9732 MEDFileFieldMultiTS *MEDFileFieldMultiTS::buildNewEmpty() const
9733 {
9734   return MEDFileFieldMultiTS::New();
9735 }
9736
9737 //= MEDFileAnyTypeFieldMultiTSIterator
9738
9739 MEDFileAnyTypeFieldMultiTSIterator::MEDFileAnyTypeFieldMultiTSIterator(MEDFileAnyTypeFieldMultiTS *fmts):_fmts(fmts),_iter_id(0),_nb_iter(0)
9740 {
9741   if(fmts)
9742     {
9743       fmts->incrRef();
9744       _nb_iter=fmts->getNumberOfTS();
9745     }
9746 }
9747
9748 MEDFileAnyTypeFieldMultiTSIterator::~MEDFileAnyTypeFieldMultiTSIterator() 
9749 {
9750 }
9751
9752 MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTSIterator::nextt()
9753 {
9754   if(_iter_id<_nb_iter)
9755     {
9756       MEDFileAnyTypeFieldMultiTS *fmts(_fmts);
9757       if(fmts)
9758         return fmts->getTimeStepAtPos(_iter_id++);
9759       else
9760         return 0;
9761     }
9762   else
9763     return 0;
9764 }
9765
9766 //= MEDFileIntFieldMultiTS
9767
9768 /*!
9769  * Returns a new empty instance of MEDFileFieldMultiTS.
9770  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9771  *          is to delete this field using decrRef() as it is no more needed.
9772  */
9773 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New()
9774 {
9775   return new MEDFileIntFieldMultiTS;
9776 }
9777
9778 /*!
9779  * Returns a new instance of MEDFileIntFieldMultiTS holding data of the first field
9780  * that has been read from a specified MED file.
9781  *  \param [in] fileName - the name of the MED file to read.
9782  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9783  *          is to delete this field using decrRef() as it is no more needed.
9784  *  \throw If reading the file fails.
9785  */
9786 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, bool loadAll)
9787 {
9788   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9789   return New(fid,loadAll);
9790 }
9791
9792 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, bool loadAll)
9793 {
9794   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,loadAll,0));
9795   ret->contentNotNull();//to check that content type matches with \a this type.
9796   return ret.retn();
9797 }
9798
9799 /*!
9800  * Returns a new instance of MEDFileIntFieldMultiTS holding data of a given field
9801  * that has been read from a specified MED file.
9802  *  \param [in] fileName - the name of the MED file to read.
9803  *  \param [in] fieldName - the name of the field to read.
9804  *  \return MEDFileFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9805  *          is to delete this field using decrRef() as it is no more needed.
9806  *  \throw If reading the file fails.
9807  *  \throw If there is no field named \a fieldName in the file.
9808  */
9809 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const std::string& fileName, const std::string& fieldName, bool loadAll)
9810 {
9811   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9812   return New(fid,fieldName,loadAll);
9813 }
9814
9815 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(med_idt fid, const std::string& fieldName, bool loadAll)
9816 {
9817   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0));
9818   ret->contentNotNull();//to check that content type matches with \a this type.
9819   return ret.retn();
9820 }
9821
9822 /*!
9823  * Returns a new instance of MEDFileIntFieldMultiTS. If \a shallowCopyOfContent is true the content of \a other is shallow copied.
9824  * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this.
9825  *
9826  * Returns a new instance of MEDFileIntFieldMultiTS holding either a shallow copy
9827  * of a given MEDFileIntFieldMultiTSWithoutSDA ( \a other ) or \a other itself.
9828  * \warning this is a shallow copy constructor
9829  *  \param [in] other - a MEDFileIntField1TSWithoutSDA to copy.
9830  *  \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created.
9831  *  \return MEDFileIntFieldMultiTS * - a new instance of MEDFileIntFieldMultiTS. The caller
9832  *          is to delete this field using decrRef() as it is no more needed.
9833  */
9834 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent)
9835 {
9836   return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent);
9837 }
9838
9839 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::LoadSpecificEntities(const std::string& fileName, const std::string& fieldName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
9840 {
9841   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
9842   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
9843   MCAuto<MEDFileIntFieldMultiTS> ret(new MEDFileIntFieldMultiTS(fid,fieldName,loadAll,0,ent));
9844   ret->contentNotNull();//to check that content type matches with \a this type.
9845   return ret.retn();
9846 }
9847
9848 /*!
9849  * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied
9850  * following the given input policy.
9851  *
9852  * \param [in] isDeepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations)
9853  *                            By default (true) the globals are deeply copied.
9854  * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field.
9855  */
9856 MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool isDeepCpyGlobs) const
9857 {
9858   MCAuto<MEDFileFieldMultiTS> ret;
9859   const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content);
9860   if(content)
9861     {
9862       const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(content);
9863       if(!contc)
9864         throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !");
9865       MCAuto<MEDFileFieldMultiTSWithoutSDA> newc(contc->convertToDouble());
9866       ret=static_cast<MEDFileFieldMultiTS *>(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc));
9867     }
9868   else
9869     ret=MEDFileFieldMultiTS::New();
9870   if(isDeepCpyGlobs)
9871     ret->deepCpyGlobs(*this);
9872   else
9873     ret->shallowCpyGlobs(*this);
9874   return ret.retn();
9875 }
9876
9877 MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const
9878 {
9879   return new MEDFileIntFieldMultiTS(*this);
9880 }
9881
9882 void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const
9883 {
9884   if(!f1ts)
9885     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : input field1TS is NULL ! Impossible to check !");
9886   const MEDFileIntField1TS *f1tsC=dynamic_cast<const MEDFileIntField1TS *>(f1ts);
9887   if(!f1tsC)
9888     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !");
9889 }
9890
9891 /*!
9892  * 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
9893  * method should be called (getFieldOnMeshAtLevel for example).
9894  * But for normal usage of field in MED file world this method is the most efficient to fetch data.
9895  *
9896  * \param [in] iteration - the iteration number of a required time step.
9897  * \param [in] order - the iteration order number of required time step.
9898  * \param [in] mesh - the mesh the field is lying on
9899  * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The
9900  *          caller is to delete this field using decrRef() as it is no more needed. 
9901  */
9902 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const
9903 {
9904   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9905   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9906   if(!myF1TSC)
9907     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::field : mismatch of type of field expecting INT32 !");
9908   MCAuto<DataArray> arrOut;
9909   MCAuto<MEDCouplingFieldDouble> ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase()));
9910   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut));
9911   return ret2.retn();
9912 }
9913
9914 /*!
9915  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9916  * mesh entities of a given dimension of the first mesh in MED file.
9917  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9918  *  \param [in] type - a spatial discretization of interest.
9919  *  \param [in] iteration - the iteration number of a required time step.
9920  *  \param [in] order - the iteration order number of required time step.
9921  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9922  *  \param [in] renumPol - specifies how to permute values of the result field according to
9923  *          the optional numbers of cells and nodes, if any. The valid values are
9924  *          - 0 - do not permute.
9925  *          - 1 - permute cells.
9926  *          - 2 - permute nodes.
9927  *          - 3 - permute cells and nodes.
9928  *
9929  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9930  *          caller is to delete this field using decrRef() as it is no more needed. 
9931  *  \throw If the MED file is not readable.
9932  *  \throw If there is no mesh in the MED file.
9933  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9934  *  \throw If no field values of the required parameters are available.
9935  */
9936 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol) const
9937 {
9938   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9939   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9940   if(!myF1TSC)
9941     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !");
9942   MCAuto<DataArray> arr;
9943   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()));
9944   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9945   return ret2.retn();
9946 }
9947
9948 /*!
9949  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9950  * the top level cells of the first mesh in MED file.
9951  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9952  *  \param [in] type - a spatial discretization of interest.
9953  *  \param [in] iteration - the iteration number of a required time step.
9954  *  \param [in] order - the iteration order number of required time step.
9955  *  \param [in] renumPol - specifies how to permute values of the result field according to
9956  *          the optional numbers of cells and nodes, if any. The valid values are
9957  *          - 0 - do not permute.
9958  *          - 1 - permute cells.
9959  *          - 2 - permute nodes.
9960  *          - 3 - permute cells and nodes.
9961  *
9962  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9963  *          caller is to delete this field using decrRef() as it is no more needed. 
9964  *  \throw If the MED file is not readable.
9965  *  \throw If there is no mesh in the MED file.
9966  *  \throw If no field values of the required parameters are available.
9967  */
9968 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol) const
9969 {
9970   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
9971   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
9972   if(!myF1TSC)
9973     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtTopLevel : mismatch of type of field ! INT32 expected !");
9974   MCAuto<DataArray> arr;
9975   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtTopLevel(type,std::string(),renumPol,this,arr,*contentNotNullBase()));
9976   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
9977   return ret2.retn();
9978 }
9979
9980 /*!
9981  * Returns a new MEDCouplingFieldInt of a given type, of a given time step, lying on
9982  * a given support.
9983  * For more info, see \ref AdvMEDLoaderAPIFieldRW
9984  *  \param [in] type - a spatial discretization of interest.
9985  *  \param [in] iteration - the iteration number of a required time step.
9986  *  \param [in] order - the iteration order number of required time step.
9987  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
9988  *  \param [in] mesh - the supporting mesh.
9989  *  \param [in] renumPol - specifies how to permute values of the result field according to
9990  *          the optional numbers of cells and nodes, if any. The valid values are
9991  *          - 0 - do not permute.
9992  *          - 1 - permute cells.
9993  *          - 2 - permute nodes.
9994  *          - 3 - permute cells and nodes.
9995  *
9996  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
9997  *          caller is to delete this field using decrRef() as it is no more needed. 
9998  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in the mesh.
9999  *  \throw If no field of \a this is lying on \a mesh.
10000  *  \throw If no field values of the required parameters are available.
10001  */
10002 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const
10003 {
10004   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10005   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10006   if(!myF1TSC)
10007     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10008   MCAuto<DataArray> arr;
10009   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arr,*contentNotNullBase()));
10010   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10011   return ret2.retn();
10012 }
10013
10014 /*!
10015  * Returns a new MEDCouplingFieldInt of given type, of a given time step, lying on a
10016  * given support. 
10017  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10018  *  \param [in] type - a spatial discretization of the new field.
10019  *  \param [in] iteration - the iteration number of a required time step.
10020  *  \param [in] order - the iteration order number of required time step.
10021  *  \param [in] mesh - the supporting mesh.
10022  *  \param [out] arrOut - the DataArrayInt containing values of field.
10023  *  \param [in] renumPol - specifies how to permute values of the result field according to
10024  *          the optional numbers of cells and nodes, if any. The valid values are
10025  *          - 0 - do not permute.
10026  *          - 1 - permute cells.
10027  *          - 2 - permute nodes.
10028  *          - 3 - permute cells and nodes.
10029  *
10030  *  \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldDouble. The
10031  *          caller is to delete this field using decrRef() as it is no more needed. 
10032  *  \throw If no field of \a this is lying on \a mesh.
10033  *  \throw If no field values of the required parameters are available.
10034  */
10035 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, const MEDCouplingMesh *mesh, int renumPol) const
10036 {
10037   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10038   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10039   if(!myF1TSC)
10040     throw INTERP_KERNEL::Exception("MEDFileFieldIntMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10041   MCAuto<DataArray> arr;
10042   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arr,*contentNotNullBase()));
10043   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10044   return ret2.retn();
10045 }
10046
10047 /*!
10048  * This method has a close behaviour than MEDFileIntFieldMultiTS::getFieldAtLevel.
10049  * This method is called 'old' because the user should give the mesh name he wants to use for it's field.
10050  * This method is useful for MED2 file format when field on different mesh was autorized.
10051  */
10052 MEDCouplingFieldInt *MEDFileIntFieldMultiTS::getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, int renumPol) const
10053 {
10054   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order));
10055   const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS));
10056   if(!myF1TSC)
10057     throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field ! INT32 expected !");
10058   MCAuto<DataArray> arr;
10059   MCAuto<MEDCouplingFieldDouble> ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arr,*contentNotNullBase()));
10060   MCAuto<MEDCouplingFieldInt> ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arr));
10061   return ret2.retn();
10062 }
10063
10064 /*!
10065  * Returns values and a profile of the field of a given type, of a given time step,
10066  * lying on a given support.
10067  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10068  *  \param [in] type - a spatial discretization of the field.
10069  *  \param [in] iteration - the iteration number of a required time step.
10070  *  \param [in] order - the iteration order number of required time step.
10071  *  \param [in] meshDimRelToMax - a relative dimension of the supporting mesh entities.
10072  *  \param [in] mesh - the supporting mesh.
10073  *  \param [out] pfl - a new instance of DataArrayInt holding ids of mesh entities the
10074  *          field of interest lies on. If the field lies on all entities of the given
10075  *          dimension, all ids in \a pfl are zero. The caller is to delete this array
10076  *          using decrRef() as it is no more needed.  
10077  *  \param [in] glob - the global data storing profiles and localization.
10078  *  \return DataArrayInt * - a new instance of DataArrayInt holding values of the
10079  *          field. The caller is to delete this array using decrRef() as it is no more needed.
10080  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10081  *  \throw If no field of \a this is lying on \a mesh.
10082  *  \throw If no field values of the required parameters are available.
10083  */
10084 DataArrayInt *MEDFileIntFieldMultiTS::getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const
10085 {
10086   const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order);
10087   const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(&myF1TS);
10088   if(!myF1TSC)
10089     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldWithProfile : mismatch of type of field ! INT32 expected !");
10090   MCAuto<DataArray> ret=myF1TSC->getFieldWithProfile(type,meshDimRelToMax,mesh,pfl,this,*contentNotNullBase());
10091   return MEDFileIntField1TS::ReturnSafelyDataArrayInt(ret);
10092 }
10093
10094 /*!
10095  * Returns a new MEDFileIntField1TS holding data of a given time step of \a this field.
10096  *  \param [in] pos - a time step id.
10097  *  \return MEDFileIntField1TS * - a new instance of MEDFileIntField1TS. The caller is to
10098  *          delete this field using decrRef() as it is no more needed.
10099  *  \throw If \a pos is not a valid time step id.
10100  */
10101 MEDFileIntField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const
10102 {
10103   const MEDFileAnyTypeField1TSWithoutSDA *item=contentNotNullBase()->getTimeStepAtPos2(pos);
10104   if(!item)
10105     {
10106       std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : field at pos #" << pos << " is null !";
10107       throw INTERP_KERNEL::Exception(oss.str());
10108     }
10109   const MEDFileIntField1TSWithoutSDA *itemC=dynamic_cast<const MEDFileIntField1TSWithoutSDA *>(item);
10110   if(itemC)
10111     {
10112       MCAuto<MEDFileIntField1TS> ret=MEDFileIntField1TS::New(*itemC,false);
10113       ret->shallowCpyGlobs(*this);
10114       return ret.retn();
10115     }
10116   std::ostringstream oss; oss << "MEDFileIntFieldMultiTS::getTimeStepAtPos : type of field at pos #" << pos << " is not INT32 !";
10117   throw INTERP_KERNEL::Exception(oss.str());
10118 }
10119
10120 /*!
10121  * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of
10122  * the given field is checked if its elements are sorted suitable for writing to MED file
10123  * ("STB" stands for "Sort By Type"), if not, an exception is thrown. 
10124  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10125  *  \param [in] field - the field to add to \a this.
10126  *  \throw If the name of \a field is empty.
10127  *  \throw If the data array of \a field is not set.
10128  *  \throw If existing time steps have different name or number of components than \a field.
10129  *  \throw If the underlying mesh of \a field has no name.
10130  *  \throw If elements in the mesh are not in the order suitable for writing to the MED file.
10131  */
10132 void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field)
10133 {
10134   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10135   contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this);
10136 }
10137
10138 /*!
10139  * Adds a MEDCouplingFieldDouble to \a this as another time step. 
10140  * The mesh support of input parameter \a field is ignored here, it can be NULL.
10141  * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax,
10142  * and \a profile.
10143  *
10144  * This method will check that the field based on the computed support is coherent. If not an exception will be thrown.
10145  * A new profile is added only if no equal profile is missing.
10146  * For more info, see \ref AdvMEDLoaderAPIFieldRW
10147  *  \param [in] field - the field to add to \a this. The field double values and mesh support are ignored.
10148  *  \param [in] arrOfVals - the values of the field \a field used.
10149  *  \param [in] mesh - the supporting mesh of \a field.
10150  *  \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES).
10151  *  \param [in] profile - ids of mesh entities on which corresponding field values lie.
10152  *  \throw If either \a field or \a mesh or \a profile has an empty name.
10153  *  \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh.
10154  *  \throw If the data array of \a field is not set.
10155  *  \throw If the data array of \a this is already allocated but has different number of
10156  *         components than \a field.
10157  *  \throw If elements in \a mesh are not in the order suitable for writing to the MED file.
10158  *  \sa setFieldNoProfileSBT()
10159  */
10160 void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile)
10161 {
10162   MCAuto<MEDCouplingFieldDouble> field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field));
10163   contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this);
10164 }
10165
10166 const MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull() const
10167 {
10168   const MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10169   if(!pt)
10170     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the content pointer is null !");
10171   const MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10172   if(!ret)
10173     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 !");
10174   return ret;
10175 }
10176
10177 MEDFileIntFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTS::contentNotNull()
10178 {
10179   MEDFileAnyTypeFieldMultiTSWithoutSDA *pt(_content);
10180   if(!pt)
10181     throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::contentNotNull : the non const content pointer is null !");
10182   MEDFileIntFieldMultiTSWithoutSDA *ret=dynamic_cast<MEDFileIntFieldMultiTSWithoutSDA *>(pt);
10183   if(!ret)
10184     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 !");
10185   return ret;
10186 }
10187
10188 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS()
10189 {
10190   _content=new MEDFileIntFieldMultiTSWithoutSDA;
10191 }
10192
10193 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(const MEDFileIntFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeFieldMultiTS(other,shallowCopyOfContent)
10194 {
10195 }
10196
10197 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, bool loadAll, const MEDFileMeshes *ms)
10198 try:MEDFileAnyTypeFieldMultiTS(fid,loadAll,ms)
10199 {
10200 }
10201 catch(INTERP_KERNEL::Exception& e)
10202 { throw e; }
10203
10204 MEDFileIntFieldMultiTS::MEDFileIntFieldMultiTS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10205 try:MEDFileAnyTypeFieldMultiTS(fid,fieldName,loadAll,ms,entities)
10206 {
10207 }
10208 catch(INTERP_KERNEL::Exception& e)
10209 { throw e; }
10210
10211 DataArrayInt *MEDFileIntFieldMultiTS::getUndergroundDataArray(int iteration, int order) const
10212 {
10213   return static_cast<DataArrayInt *>(contentNotNull()->getUndergroundDataArray(iteration,order));
10214 }
10215
10216 MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::buildNewEmpty() const
10217 {
10218   return MEDFileIntFieldMultiTS::New();
10219 }
10220
10221 //= MEDFileFields
10222
10223 MEDFileFields *MEDFileFields::New()
10224 {
10225   return new MEDFileFields;
10226 }
10227
10228 MEDFileFields *MEDFileFields::New(const std::string& fileName, bool loadAll)
10229 {
10230   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10231   return New(fid,loadAll);
10232 }
10233
10234 MEDFileFields *MEDFileFields::NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll)
10235 {
10236   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10237   return NewWithDynGT(fid,se,loadAll);
10238 }
10239
10240 MEDFileFields *MEDFileFields::NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll)
10241 {
10242   if(!se)
10243     throw INTERP_KERNEL::Exception("MEDFileFields::NewWithDynGT : null struct element pointer !");
10244   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> entities(MEDFileEntities::BuildFrom(*se));
10245   return new MEDFileFields(fid,loadAll,0,entities);
10246 }
10247
10248 MEDFileFields *MEDFileFields::New(med_idt fid, bool loadAll)
10249 {
10250   return new MEDFileFields(fid,loadAll,0,0);
10251 }
10252
10253 MEDFileFields *MEDFileFields::LoadPartOf(const std::string& fileName, bool loadAll, const MEDFileMeshes *ms)
10254 {
10255   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10256   return new MEDFileFields(fid,loadAll,ms,0);
10257 }
10258
10259 MEDFileFields *MEDFileFields::LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll)
10260 {
10261   MEDFileUtilities::CheckFileForRead(fileName);
10262   INTERP_KERNEL::AutoCppPtr<MEDFileEntities> ent(new MEDFileStaticEntities(entities));
10263   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
10264   return new MEDFileFields(fid,loadAll,0,ent);
10265 }
10266
10267 std::size_t MEDFileFields::getHeapMemorySizeWithoutChildren() const
10268 {
10269   std::size_t ret(MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren());
10270   ret+=_fields.capacity()*sizeof(MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA>);
10271   return ret;
10272 }
10273
10274 std::vector<const BigMemoryObject *> MEDFileFields::getDirectChildrenWithNull() const
10275 {
10276   std::vector<const BigMemoryObject *> ret;
10277   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10278     ret.push_back((const MEDFileAnyTypeFieldMultiTSWithoutSDA *)*it);
10279   return ret;
10280 }
10281
10282 MEDFileFields *MEDFileFields::deepCopy() const
10283 {
10284   MCAuto<MEDFileFields> ret(shallowCpy());
10285   std::size_t i(0);
10286   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10287     {
10288       if((const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10289         ret->_fields[i]=(*it)->deepCopy();
10290     }
10291   ret->deepCpyGlobs(*this);
10292   return ret.retn();
10293 }
10294
10295 MEDFileFields *MEDFileFields::shallowCpy() const
10296 {
10297   return new MEDFileFields(*this);
10298 }
10299
10300 /*!
10301  * 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
10302  * 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.
10303  * If \a areThereSomeForgottenTS is set to true, only the sorted intersection of time steps present for all fields in \a this will be returned.
10304  *
10305  * \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.
10306  * \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.
10307  * 
10308  * \sa MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10309  */
10310 std::vector< std::pair<int,int> > MEDFileFields::getCommonIterations(bool& areThereSomeForgottenTS) const
10311 {
10312   std::set< std::pair<int,int> > s;
10313   bool firstShot=true;
10314   areThereSomeForgottenTS=false;
10315   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10316     {
10317       if(!(const MEDFileAnyTypeFieldMultiTSWithoutSDA*)*it)
10318         continue;
10319       std::vector< std::pair<int,int> > v=(*it)->getIterations();
10320       std::set< std::pair<int,int> > s1; std::copy(v.begin(),v.end(),std::inserter(s1,s1.end()));
10321       if(firstShot)
10322         { s=s1; firstShot=false; }
10323       else
10324         {
10325           std::set< std::pair<int,int> > s2; std::set_intersection(s.begin(),s.end(),s1.begin(),s1.end(),std::inserter(s2,s2.end()));
10326           if(s!=s2)
10327             areThereSomeForgottenTS=true;
10328           s=s2;
10329         }
10330     }
10331   std::vector< std::pair<int,int> > ret;
10332   std::copy(s.begin(),s.end(),std::back_insert_iterator< std::vector< std::pair<int,int> > >(ret));
10333   return ret;
10334 }
10335
10336 int MEDFileFields::getNumberOfFields() const
10337 {
10338   return _fields.size();
10339 }
10340
10341 std::vector<std::string> MEDFileFields::getFieldsNames() const
10342 {
10343   std::vector<std::string> ret(_fields.size());
10344   int i(0);
10345   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10346     {
10347       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f=(*it);
10348       if(f)
10349         {
10350           ret[i]=f->getName();
10351         }
10352       else
10353         {
10354           std::ostringstream oss; oss << "MEDFileFields::getFieldsNames : At rank #" << i << " field is not defined !";
10355           throw INTERP_KERNEL::Exception(oss.str());
10356         }
10357     }
10358   return ret;
10359 }
10360
10361 std::vector<std::string> MEDFileFields::getMeshesNames() const
10362 {
10363   std::vector<std::string> ret;
10364   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10365     {
10366       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10367       if(cur)
10368         ret.push_back(cur->getMeshName());
10369     }
10370   return ret;
10371 }
10372
10373 std::string MEDFileFields::simpleRepr() const
10374 {
10375   std::ostringstream oss;
10376   oss << "(*****************)\n(* MEDFileFields *)\n(*****************)\n\n";
10377   simpleRepr(0,oss);
10378   return oss.str();
10379 }
10380
10381 void MEDFileFields::simpleRepr(int bkOffset, std::ostream& oss) const
10382 {
10383   int nbOfFields(getNumberOfFields());
10384   std::string startLine(bkOffset,' ');
10385   oss << startLine << "There are " << nbOfFields << " fields in this :" << std::endl;
10386   int i=0;
10387   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10388     {
10389       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10390       if(cur)
10391         {
10392           oss << startLine << "  - # "<< i << " has the following name : \"" << cur->getName() << "\"." << std::endl;
10393         }
10394       else
10395         {
10396           oss << startLine << "  - not defined !" << std::endl;
10397         }
10398     }
10399   i=0;
10400   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10401     {
10402       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur=(*it);
10403       std::string chapter(17,'0'+i);
10404       oss << startLine << chapter << std::endl;
10405       if(cur)
10406         {
10407           cur->simpleRepr(bkOffset+2,oss,i);
10408         }
10409       else
10410         {
10411           oss << startLine << "  - not defined !" << std::endl;
10412         }
10413       oss << startLine << chapter << std::endl;
10414     }
10415   simpleReprGlobs(oss);
10416 }
10417
10418 MEDFileFields::MEDFileFields()
10419 {
10420 }
10421
10422 MEDFileFields::MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities)
10423 try:MEDFileFieldGlobsReal(fid)
10424 {
10425   int nbFields(MEDnField(fid));
10426   _fields.resize(nbFields);
10427   med_field_type typcha;
10428   for(int i=0;i<nbFields;i++)
10429     {
10430       std::vector<std::string> infos;
10431       std::string fieldName,dtunit;
10432       int nbOfStep(MEDFileAnyTypeField1TS::LocateField2(fid,i,false,fieldName,typcha,infos,dtunit));
10433       switch(typcha)
10434       {
10435         case MED_FLOAT64:
10436           {
10437             _fields[i]=MEDFileFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10438             break;
10439           }
10440         case MED_INT32:
10441           {
10442             _fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName.c_str(),typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
10443             break;
10444           }
10445         default:
10446           {
10447             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] !";
10448             throw INTERP_KERNEL::Exception(oss.str());
10449           }
10450       }
10451     }
10452   loadAllGlobals(fid);
10453 }
10454 catch(INTERP_KERNEL::Exception& e)
10455 {
10456     throw e;
10457 }
10458
10459 void MEDFileFields::writeLL(med_idt fid) const
10460 {
10461   int i=0;
10462   writeGlobals(fid,*this);
10463   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
10464     {
10465       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt=*it;
10466       if(!elt)
10467         {
10468           std::ostringstream oss; oss << "MEDFileFields::write : at rank #" << i << "/" << _fields.size() << " field is empty !";
10469           throw INTERP_KERNEL::Exception(oss.str());
10470         }
10471       elt->writeLL(fid,*this);
10472     }
10473 }
10474
10475 /*!
10476  * This method alloc the arrays and load potentially huge arrays contained in this field.
10477  * This method should be called when a MEDFileAnyTypeFieldMultiTS::New constructor has been with false as the last parameter.
10478  * This method can be also called to refresh or reinit values from a file.
10479  * 
10480  * \throw If the fileName is not set or points to a non readable MED file.
10481  */
10482 void MEDFileFields::loadArrays()
10483 {
10484   if(getFileName().empty())
10485     throw INTERP_KERNEL::Exception("MEDFileFields::loadArrays : the structure does not come from a file !");
10486   MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10487   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10488     {
10489       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10490       if(elt)
10491         elt->loadBigArraysRecursively(fid,*elt);
10492     }
10493 }
10494
10495 /*!
10496  * This method behaves as MEDFileFields::loadArrays does, the first call, if \a this was built using a file without loading big arrays.
10497  * But once data loaded once, this method does nothing.
10498  * 
10499  * \throw If the fileName is not set or points to a non readable MED file.
10500  * \sa MEDFileFields::loadArrays, MEDFileFields::unloadArrays
10501  */
10502 void MEDFileFields::loadArraysIfNecessary()
10503 {
10504   if(!getFileName().empty())
10505     {
10506       MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(getFileName()));
10507       for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10508         {
10509           MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10510           if(elt)
10511             elt->loadBigArraysRecursivelyIfNecessary(fid,*elt);
10512         }
10513     }
10514 }
10515
10516 /*!
10517  * This method releases potentially big data arrays and so returns to the same heap memory than status loaded with 'loadAll' parameter set to false.
10518  * \b WARNING, this method does release arrays even if \a this does not come from a load of a MED file.
10519  * So this method can lead to a loss of data. If you want to unload arrays safely call MEDFileFields::unloadArraysWithoutDataLoss instead.
10520  * 
10521  * \sa MEDFileFields::loadArrays, MEDFileFields::loadArraysIfNecessary, MEDFileFields::unloadArraysWithoutDataLoss
10522  */
10523 void MEDFileFields::unloadArrays()
10524 {
10525   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10526     {
10527       MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10528       if(elt)
10529         elt->unloadArrays();
10530     }
10531 }
10532
10533 /*!
10534  * 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.
10535  * This method is the symetrical method of MEDFileFields::loadArraysIfNecessary.
10536  * This method is useful to reduce \b safely amount of heap memory necessary for \a this by using MED file as database.
10537  * 
10538  * \sa MEDFileFields::loadArraysIfNecessary
10539  */
10540 void MEDFileFields::unloadArraysWithoutDataLoss()
10541 {
10542   if(!getFileName().empty())
10543     unloadArrays();
10544 }
10545
10546 std::vector<std::string> MEDFileFields::getPflsReallyUsed() const
10547 {
10548   std::vector<std::string> ret;
10549   std::set<std::string> ret2;
10550   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10551     {
10552       std::vector<std::string> tmp=(*it)->getPflsReallyUsed2();
10553       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10554         if(ret2.find(*it2)==ret2.end())
10555           {
10556             ret.push_back(*it2);
10557             ret2.insert(*it2);
10558           }
10559     }
10560   return ret;
10561 }
10562
10563 std::vector<std::string> MEDFileFields::getLocsReallyUsed() const
10564 {
10565   std::vector<std::string> ret;
10566   std::set<std::string> ret2;
10567   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10568     {
10569       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10570       for(std::vector<std::string>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
10571         if(ret2.find(*it2)==ret2.end())
10572           {
10573             ret.push_back(*it2);
10574             ret2.insert(*it2);
10575           }
10576     }
10577   return ret;
10578 }
10579
10580 std::vector<std::string> MEDFileFields::getPflsReallyUsedMulti() const
10581 {
10582   std::vector<std::string> ret;
10583   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10584     {
10585       std::vector<std::string> tmp((*it)->getPflsReallyUsedMulti2());
10586       ret.insert(ret.end(),tmp.begin(),tmp.end());
10587     }
10588   return ret;
10589 }
10590
10591 std::vector<std::string> MEDFileFields::getLocsReallyUsedMulti() const
10592 {
10593   std::vector<std::string> ret;
10594   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10595     {
10596       std::vector<std::string> tmp((*it)->getLocsReallyUsed2());
10597       ret.insert(ret.end(),tmp.begin(),tmp.end());
10598     }
10599   return ret;
10600 }
10601
10602 void MEDFileFields::changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10603 {
10604   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10605     (*it)->changePflsRefsNamesGen2(mapOfModif);
10606 }
10607
10608 void MEDFileFields::changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
10609 {
10610   for(std::vector< MCAuto< MEDFileAnyTypeFieldMultiTSWithoutSDA > >::iterator it=_fields.begin();it!=_fields.end();it++)
10611     (*it)->changeLocsRefsNamesGen2(mapOfModif);
10612 }
10613
10614 void MEDFileFields::resize(int newSize)
10615 {
10616   _fields.resize(newSize);
10617 }
10618
10619 void MEDFileFields::pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields)
10620 {
10621   for(std::vector<MEDFileAnyTypeFieldMultiTS *>::const_iterator it=fields.begin();it!=fields.end();it++)
10622     pushField(*it);
10623 }
10624
10625 void MEDFileFields::pushField(MEDFileAnyTypeFieldMultiTS *field)
10626 {
10627   if(!field)
10628     throw INTERP_KERNEL::Exception("MEDFileFields::pushMesh : invalid input pointer ! should be different from 0 !");
10629   _fields.push_back(field->getContent());
10630   appendGlobs(*field,1e-12);
10631 }
10632
10633 void MEDFileFields::setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field)
10634 {
10635   if(!field)
10636     throw INTERP_KERNEL::Exception("MEDFileFields::setFieldAtPos : invalid input pointer ! should be different from 0 !");
10637   if(i>=(int)_fields.size())
10638     _fields.resize(i+1);
10639   _fields[i]=field->getContent();
10640   appendGlobs(*field,1e-12);
10641 }
10642
10643 void MEDFileFields::destroyFieldAtPos(int i)
10644 {
10645   destroyFieldsAtPos(&i,&i+1);
10646 }
10647
10648 void MEDFileFields::destroyFieldsAtPos(const int *startIds, const int *endIds)
10649 {
10650   std::vector<bool> b(_fields.size(),true);
10651   for(const int *i=startIds;i!=endIds;i++)
10652     {
10653       if(*i<0 || *i>=(int)_fields.size())
10654         {
10655           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10656           throw INTERP_KERNEL::Exception(oss.str());
10657         }
10658       b[*i]=false;
10659     }
10660   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10661   std::size_t j=0;
10662   for(std::size_t i=0;i<_fields.size();i++)
10663     if(b[i])
10664       fields[j++]=_fields[i];
10665   _fields=fields;
10666 }
10667
10668 void MEDFileFields::destroyFieldsAtPos2(int bg, int end, int step)
10669 {
10670   static const char msg[]="MEDFileFields::destroyFieldsAtPos2";
10671   int nbOfEntriesToKill(DataArrayInt::GetNumberOfItemGivenBESRelative(bg,end,step,msg));
10672   std::vector<bool> b(_fields.size(),true);
10673   int k=bg;
10674   for(int i=0;i<nbOfEntriesToKill;i++,k+=step)
10675     {
10676       if(k<0 || k>=(int)_fields.size())
10677         {
10678           std::ostringstream oss; oss << "MEDFileFields::destroyFieldsAtPos2 : Invalid given id in input (" << k << ") should be in [0," << _fields.size() << ") !";
10679           throw INTERP_KERNEL::Exception(oss.str());
10680         }
10681       b[k]=false;
10682     }
10683   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(std::count(b.begin(),b.end(),true));
10684   std::size_t j(0);
10685   for(std::size_t i=0;i<_fields.size();i++)
10686     if(b[i])
10687       fields[j++]=_fields[i];
10688   _fields=fields;
10689 }
10690
10691 bool MEDFileFields::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
10692 {
10693   bool ret(false);
10694   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10695     {
10696       MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10697       if(cur)
10698         ret=cur->changeMeshNames(modifTab) || ret;
10699     }
10700   return ret;
10701 }
10702
10703 /*!
10704  * \param [in] meshName the name of the mesh that will be renumbered.
10705  * \param [in] oldCode is of format returned by MEDCouplingUMesh::getDistributionOfTypes. And for each *i* oldCode[3*i+2] gives the position (MEDFileUMesh::PutInThirdComponentOfCodeOffset).
10706  *             This code corresponds to the distribution of types in the corresponding mesh.
10707  * \param [in] newCode idem to param \a oldCode except that here the new distribution is given.
10708  * \param [in] renumO2N the old to new renumber array.
10709  * \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 
10710  *         field in \a this.
10711  */
10712 bool MEDFileFields::renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N)
10713 {
10714   bool ret(false);
10715   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::iterator it=_fields.begin();it!=_fields.end();it++)
10716     {
10717       MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts(*it);
10718       if(fmts)
10719         {
10720           ret=fmts->renumberEntitiesLyingOnMesh(meshName,oldCode,newCode,renumO2N,*this) || ret;
10721         }
10722     }
10723   return ret;
10724 }
10725
10726 /*!
10727  * Return an extraction of \a this using \a extractDef map to specify the extraction.
10728  * The keys of \a extractDef is level relative to max ext of \a mm mesh.
10729  *
10730  * \return A new object that the caller is responsible to deallocate.
10731  */
10732 MEDFileFields *MEDFileFields::extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const
10733 {
10734   if(!mm)
10735     throw INTERP_KERNEL::Exception("MEDFileFields::extractPart : input mesh is NULL !");
10736   MCAuto<MEDFileFields> fsOut(MEDFileFields::New());
10737   int nbFields(getNumberOfFields());
10738   for(int i=0;i<nbFields;i++)
10739     {
10740       MCAuto<MEDFileAnyTypeFieldMultiTS> fmts(getFieldAtPos(i));
10741       if(!fmts)
10742         {
10743           std::ostringstream oss; oss << "MEDFileFields::extractPart : at pos #" << i << " field is null !";
10744           throw INTERP_KERNEL::Exception(oss.str());
10745         }
10746       MCAuto<MEDFileAnyTypeFieldMultiTS> fmtsOut(fmts->extractPart(extractDef,mm));
10747       fsOut->pushField(fmtsOut);
10748     }
10749   return fsOut.retn();
10750 }
10751
10752 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const
10753 {
10754   if(i<0 || i>=(int)_fields.size())
10755     {
10756       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : Invalid given id in input (" << i << ") should be in [0," << _fields.size() << ") !";
10757       throw INTERP_KERNEL::Exception(oss.str());
10758     }
10759   const MEDFileAnyTypeFieldMultiTSWithoutSDA *fmts=_fields[i];
10760   if(!fmts)
10761     return 0;
10762   MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
10763   const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
10764   const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
10765   if(fmtsC)
10766     ret=MEDFileFieldMultiTS::New(*fmtsC,false);
10767   else if(fmtsC2)
10768     ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
10769   else
10770     {
10771       std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
10772       throw INTERP_KERNEL::Exception(oss.str());
10773     }
10774   ret->shallowCpyGlobs(*this);
10775   return ret.retn();
10776 }
10777
10778 /*!
10779  * Return a shallow copy of \a this reduced to the fields ids defined in [ \a startIds , endIds ).
10780  * This method is accessible in python using __getitem__ with a list in input.
10781  * \return a new object that the caller should deal with.
10782  */
10783 MEDFileFields *MEDFileFields::buildSubPart(const int *startIds, const int *endIds) const
10784 {
10785   MCAuto<MEDFileFields> ret=shallowCpy();
10786   std::size_t sz=std::distance(startIds,endIds);
10787   std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > fields(sz);
10788   int j=0;
10789   for(const int *i=startIds;i!=endIds;i++,j++)
10790     {
10791       if(*i<0 || *i>=(int)_fields.size())
10792         {
10793           std::ostringstream oss; oss << "MEDFileFields::buildSubPart : Invalid given id in input (" << *i << ") should be in [0," << _fields.size() << ") !";
10794           throw INTERP_KERNEL::Exception(oss.str());
10795         }
10796       fields[j]=_fields[*i];
10797     }
10798   ret->_fields=fields;
10799   return ret.retn();
10800 }
10801
10802 MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& fieldName) const
10803 {
10804   return getFieldAtPos(getPosFromFieldName(fieldName));
10805 }
10806
10807 /*!
10808  * This method removes, if any, fields in \a this having no time steps.
10809  * 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.
10810  * 
10811  * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const.
10812  */
10813 bool MEDFileFields::removeFieldsWithoutAnyTimeStep()
10814 {
10815   std::vector<MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > newFields;
10816   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10817     {
10818       const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it);
10819       if(elt)
10820         {
10821           if(elt->getNumberOfTS()>0)
10822             newFields.push_back(*it);
10823         }
10824     }
10825   if(_fields.size()==newFields.size())
10826     return false;
10827   _fields=newFields;
10828   return true;
10829 }
10830
10831 /*!
10832  * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName.
10833  * This method can be seen as a filter applied on \a this, that returns an object containing
10834  * 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
10835  * shallow copied from \a this.
10836  * 
10837  * \param [in] meshName - the name of the mesh on w
10838  * \return a new object that the caller should deal with.
10839  */
10840 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const
10841 {
10842   MCAuto<MEDFileFields> ret(MEDFileFields::New());
10843   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10844     {
10845       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10846       if(!cur)
10847         continue;
10848       if(cur->getMeshName()==meshName)
10849         {
10850           cur->incrRef();
10851           MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> cur2(const_cast<MEDFileAnyTypeFieldMultiTSWithoutSDA *>(cur));
10852           ret->_fields.push_back(cur2);
10853         }
10854     }
10855   ret->shallowCpyOnlyUsedGlobs(*this);
10856   return ret.retn();
10857 }
10858
10859 /*!
10860  * This method returns a new object containing part of \a this fields lying ** exactly ** on the time steps specified by input parameter \a timeSteps.
10861  * Input time steps are specified using a pair of integer (iteration, order).
10862  * 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,
10863  * but for each multitimestep only the time steps in \a timeSteps are kept.
10864  * Typically the input parameter \a timeSteps comes from the call of MEDFileFields::getCommonIterations.
10865  * 
10866  * The returned object points to shallow copy of elements in \a this.
10867  * 
10868  * \param [in] timeSteps - the time steps given by a vector of pair of integers (iteration,order)
10869  * \throw If there is a field in \a this that is \b not defined on a time step in the input \a timeSteps.
10870  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps
10871  */
10872 MEDFileFields *MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10873 {
10874   MCAuto<MEDFileFields> ret(MEDFileFields::New());
10875   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10876     {
10877       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10878       if(!cur)
10879         continue;
10880       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisLyingOnSpecifiedTimeSteps(timeSteps);
10881       ret->_fields.push_back(elt);
10882     }
10883   ret->shallowCpyOnlyUsedGlobs(*this);
10884   return ret.retn();
10885 }
10886
10887 /*!
10888  * \sa MEDFileFields::getCommonIterations, MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps
10889  */
10890 MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const
10891 {
10892   MCAuto<MEDFileFields> ret=MEDFileFields::New();
10893   for(std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> >::const_iterator it=_fields.begin();it!=_fields.end();it++)
10894     {
10895       const MEDFileAnyTypeFieldMultiTSWithoutSDA *cur(*it);
10896       if(!cur)
10897         continue;
10898       MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> elt=cur->partOfThisNotLyingOnSpecifiedTimeSteps(timeSteps);
10899       if(elt->getNumberOfTS()!=0)
10900         ret->_fields.push_back(elt);
10901     }
10902   ret->shallowCpyOnlyUsedGlobs(*this);
10903   return ret.retn();
10904 }
10905
10906 MEDFileFieldsIterator *MEDFileFields::iterator()
10907 {
10908   return new MEDFileFieldsIterator(this);
10909 }
10910
10911 int MEDFileFields::getPosFromFieldName(const std::string& fieldName) const
10912 {
10913   std::string tmp(fieldName);
10914   std::vector<std::string> poss;
10915   for(std::size_t i=0;i<_fields.size();i++)
10916     {
10917       const MEDFileAnyTypeFieldMultiTSWithoutSDA *f(_fields[i]);
10918       if(f)
10919         {
10920           std::string fname(f->getName());
10921           if(tmp==fname)
10922             return i;
10923           else
10924             poss.push_back(fname);
10925         }
10926     }
10927   std::ostringstream oss; oss << "MEDFileFields::getPosFromFieldName : impossible to find field '" << tmp << "' in this ! Possibilities are : ";
10928   std::copy(poss.begin(),poss.end(),std::ostream_iterator<std::string>(oss,", "));
10929   oss << " !";
10930   throw INTERP_KERNEL::Exception(oss.str());
10931 }
10932
10933 MEDFileFieldsIterator::MEDFileFieldsIterator(MEDFileFields *fs):_fs(fs),_iter_id(0),_nb_iter(0)
10934 {
10935   if(fs)
10936     {
10937       fs->incrRef();
10938       _nb_iter=fs->getNumberOfFields();
10939     }
10940 }
10941
10942 MEDFileFieldsIterator::~MEDFileFieldsIterator() 
10943 {
10944 }
10945
10946 MEDFileAnyTypeFieldMultiTS *MEDFileFieldsIterator::nextt()
10947 {
10948   if(_iter_id<_nb_iter)
10949     {
10950       MEDFileFields *fs(_fs);
10951       if(fs)
10952         return fs->getFieldAtPos(_iter_id++);
10953       else
10954         return 0;
10955     }
10956   else
10957     return 0;
10958 }